r24453: Remove the read and write bmpx calls
[samba.git] / source3 / smbd / mangle.c
index 20b2b419cf1eb921e24634422ae4583ff0eb13fe..fce86903f2427b99ef6f04ed7b7e2683a68ce2d3 100644 (file)
@@ -5,7 +5,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 static struct mangle_fns *mangle_fns;
 
 /* this allows us to add more mangling backends */
-static struct {
-       char *name;
+static const struct {
+       const char *name;
        struct mangle_fns *(*init_fn)(void);
 } mangle_backends[] = {
        { "hash", mangle_hash_init },
        { "hash2", mangle_hash2_init },
+       { "posix", posix_mangle_init },
+       /*{ "tdb", mangle_tdb_init }, */
        { NULL, NULL }
 };
 
@@ -38,13 +39,14 @@ static struct {
 static void mangle_init(void)
 {
        int i;
-       char *method;
+       const char *method;
 
-       if (mangle_fns) return;
+       if (mangle_fns)
+               return;
 
        method = lp_mangling_method();
 
-       /* find the first mangling method that manages to initialise and 
+       /* find the first mangling method that manages to initialise and
           matches the "mangling method" parameter */
        for (i=0; mangle_backends[i].name && !mangle_fns; i++) {
                if (!method || !*method || strcmp(method, mangle_backends[i].name) == 0) {
@@ -65,24 +67,37 @@ static void mangle_init(void)
 void mangle_reset_cache(void)
 {
        mangle_init();
-
        mangle_fns->reset();
 }
 
+void mangle_change_to_posix(void)
+{
+       mangle_fns = NULL;
+       lp_set_mangling_method("posix");
+       mangle_reset_cache();
+}
+
 /*
   see if a filename has come out of our mangling code
 */
-BOOL mangle_is_mangled(const char *s)
+BOOL mangle_is_mangled(const char *s, const struct share_params *p)
 {
-       return mangle_fns->is_mangled(s);
+       return mangle_fns->is_mangled(s, p);
 }
 
 /*
   see if a filename matches the rules of a 8.3 filename
 */
-BOOL mangle_is_8_3(const char *fname, BOOL check_case)
+BOOL mangle_is_8_3(const char *fname, BOOL check_case,
+                  const struct share_params *p)
+{
+       return mangle_fns->is_8_3(fname, check_case, False, p);
+}
+
+BOOL mangle_is_8_3_wildcards(const char *fname, BOOL check_case,
+                            const struct share_params *p)
 {
-       return mangle_fns->is_8_3(fname, check_case);
+       return mangle_fns->is_8_3(fname, check_case, True, p);
 }
 
 /*
@@ -91,27 +106,44 @@ BOOL mangle_is_8_3(const char *fname, BOOL check_case)
   looking for a matching name if it doesn't. It should succeed most of the time
   or there will be a huge performance penalty
 */
-BOOL mangle_check_cache(char *s)
+BOOL mangle_check_cache(char *s, size_t maxlen,
+                       const struct share_params *p)
 {
-       return mangle_fns->check_cache(s);
+       return mangle_fns->check_cache(s, maxlen, p);
+}
+
+BOOL mangle_check_cache_alloc(const char *name, char **presult,
+                             const struct share_params *p)
+{
+       pstring tmp;
+       char *result;
+       pstrcpy(tmp, name);
+
+       if (!mangle_check_cache(tmp, sizeof(pstring)-1, p)
+           || !(result = SMB_STRDUP(tmp))) {
+               return False;
+       }
+       *presult = result;
+       return True;
 }
 
 /* 
    map a long filename to a 8.3 name. 
  */
-BOOL mangle_map(char *OutName, BOOL need83, BOOL cache83, int snum)
+
+void mangle_map(pstring OutName, BOOL need83, BOOL cache83,
+               const struct share_params *p)
 {
        /* name mangling can be disabled for speed, in which case
           we just truncate the string */
-       if (!lp_manglednames(snum)) {
+       if (!lp_manglednames(p)) {
                if (need83) {
                        string_truncate(OutName, 12);
                }
-               return True;
+               return;
        }
 
        /* invoke the inane "mangled map" code */
-       mangle_map_filename(OutName, snum);
-
-       return mangle_fns->name_map(OutName, need83, cache83);
+       mangle_map_filename(OutName, p);
+       mangle_fns->name_map(OutName, need83, cache83, lp_defaultcase(p->service), p);
 }