unix_msg: Use struct initializers
[kamenim/samba-autobuild/.git] / source3 / smbd / mangle.c
index fce86903f2427b99ef6f04ed7b7e2683a68ce2d3..a8988f0219987e805a9ddd05a8eade9f01823dba 100644 (file)
@@ -1,30 +1,31 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Name mangling interface
    Copyright (C) Andrew Tridgell 2002
-   
+
    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 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    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, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
-
-static struct mangle_fns *mangle_fns;
+#include "smbd/smbd.h"
+#include "smbd/globals.h"
+#include "mangle.h"
 
 /* this allows us to add more mangling backends */
 static const struct {
        const char *name;
-       struct mangle_fns *(*init_fn)(void);
+       const struct mangle_fns *(*init_fn)(void);
 } mangle_backends[] = {
        { "hash", mangle_hash_init },
        { "hash2", mangle_hash2_init },
@@ -44,7 +45,7 @@ static void mangle_init(void)
        if (mangle_fns)
                return;
 
-       method = lp_mangling_method();
+       method = lp_mangling_method(talloc_tos());
 
        /* find the first mangling method that manages to initialise and
           matches the "mangling method" parameter */
@@ -80,7 +81,7 @@ void mangle_change_to_posix(void)
 /*
   see if a filename has come out of our mangling code
 */
-BOOL mangle_is_mangled(const char *s, const struct share_params *p)
+bool mangle_is_mangled(const char *s, const struct share_params *p)
 {
        return mangle_fns->is_mangled(s, p);
 }
@@ -88,62 +89,65 @@ BOOL mangle_is_mangled(const char *s, const struct share_params *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,
+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, True, p);
 }
 
+bool mangle_must_mangle(const char *fname,
+                  const struct share_params *p)
+{
+       if (!lp_mangled_names(p)) {
+               return False;
+       }
+       return mangle_fns->must_mangle(fname, p);
+}
+
 /*
-  try to reverse map a 8.3 name to the original filename. This doesn't have to 
+  try to reverse map a 8.3 name to the original filename. This doesn't have to
   always succeed, as the directory handling code in smbd will scan the directory
   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, size_t maxlen,
+bool mangle_lookup_name_from_8_3(TALLOC_CTX *ctx,
+                       const char *in,
+                       char **out, /* talloced on the given context. */
                        const struct share_params *p)
 {
-       return mangle_fns->check_cache(s, maxlen, p);
+       return mangle_fns->lookup_name_from_8_3(ctx, in, out, 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. 
+/*
+   mangle a long filename to a 8.3 name.
+   Return True if we did mangle the name (ie. out is filled in).
+   False on error.
+   JRA.
  */
 
-void mangle_map(pstring OutName, BOOL need83, BOOL cache83,
+bool name_to_8_3(const char *in,
+               char out[13],
+               bool cache83,
                const struct share_params *p)
 {
+       memset(out,'\0',13);
+
        /* name mangling can be disabled for speed, in which case
           we just truncate the string */
-       if (!lp_manglednames(p)) {
-               if (need83) {
-                       string_truncate(OutName, 12);
-               }
-               return;
+       if (!lp_mangled_names(p)) {
+               strlcpy(out, in, 13);
+               return True;
        }
 
-       /* invoke the inane "mangled map" code */
-       mangle_map_filename(OutName, p);
-       mangle_fns->name_map(OutName, need83, cache83, lp_defaultcase(p->service), p);
+       return mangle_fns->name_to_8_3(in,
+                               out,
+                               cache83,
+                               lp_default_case(p->service),
+                               p);
 }