smbd/mangle.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    Name mangling interface
00004    Copyright (C) Andrew Tridgell 2002
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 #include "includes.h"
00022 
00023 static struct mangle_fns *mangle_fns;
00024 
00025 /* this allows us to add more mangling backends */
00026 static const struct {
00027         const char *name;
00028         struct mangle_fns *(*init_fn)(void);
00029 } mangle_backends[] = {
00030         { "hash", mangle_hash_init },
00031         { "hash2", mangle_hash2_init },
00032         { "posix", posix_mangle_init },
00033         /*{ "tdb", mangle_tdb_init }, */
00034         { NULL, NULL }
00035 };
00036 
00037 /*
00038   initialise the mangling subsystem
00039 */
00040 static void mangle_init(void)
00041 {
00042         int i;
00043         const char *method;
00044 
00045         if (mangle_fns)
00046                 return;
00047 
00048         method = lp_mangling_method();
00049 
00050         /* find the first mangling method that manages to initialise and
00051            matches the "mangling method" parameter */
00052         for (i=0; mangle_backends[i].name && !mangle_fns; i++) {
00053                 if (!method || !*method || strcmp(method, mangle_backends[i].name) == 0) {
00054                         mangle_fns = mangle_backends[i].init_fn();
00055                 }
00056         }
00057 
00058         if (!mangle_fns) {
00059                 DEBUG(0,("Failed to initialise mangling system '%s'\n", method));
00060                 exit_server("mangling init failed");
00061         }
00062 }
00063 
00064 
00065 /*
00066   reset the cache. This is called when smb.conf has been reloaded
00067 */
00068 void mangle_reset_cache(void)
00069 {
00070         mangle_init();
00071         mangle_fns->reset();
00072 }
00073 
00074 void mangle_change_to_posix(void)
00075 {
00076         mangle_fns = NULL;
00077         lp_set_mangling_method("posix");
00078         mangle_reset_cache();
00079 }
00080 
00081 /*
00082   see if a filename has come out of our mangling code
00083 */
00084 BOOL mangle_is_mangled(const char *s, const struct share_params *p)
00085 {
00086         return mangle_fns->is_mangled(s, p);
00087 }
00088 
00089 /*
00090   see if a filename matches the rules of a 8.3 filename
00091 */
00092 BOOL mangle_is_8_3(const char *fname, BOOL check_case,
00093                    const struct share_params *p)
00094 {
00095         return mangle_fns->is_8_3(fname, check_case, False, p);
00096 }
00097 
00098 BOOL mangle_is_8_3_wildcards(const char *fname, BOOL check_case,
00099                              const struct share_params *p)
00100 {
00101         return mangle_fns->is_8_3(fname, check_case, True, p);
00102 }
00103 
00104 /*
00105   try to reverse map a 8.3 name to the original filename. This doesn't have to 
00106   always succeed, as the directory handling code in smbd will scan the directory
00107   looking for a matching name if it doesn't. It should succeed most of the time
00108   or there will be a huge performance penalty
00109 */
00110 BOOL mangle_check_cache(char *s, size_t maxlen,
00111                         const struct share_params *p)
00112 {
00113         return mangle_fns->check_cache(s, maxlen, p);
00114 }
00115 
00116 /* 
00117    map a long filename to a 8.3 name. 
00118  */
00119 
00120 void mangle_map(pstring OutName, BOOL need83, BOOL cache83,
00121                 const struct share_params *p)
00122 {
00123         /* name mangling can be disabled for speed, in which case
00124            we just truncate the string */
00125         if (!lp_manglednames(p)) {
00126                 if (need83) {
00127                         string_truncate(OutName, 12);
00128                 }
00129                 return;
00130         }
00131 
00132         /* invoke the inane "mangled map" code */
00133         mangle_map_filename(OutName, p);
00134         mangle_fns->name_map(OutName, need83, cache83, lp_defaultcase(p->service), p);
00135 }

Sambaに対してSat Aug 29 21:23:24 2009に生成されました。  doxygen 1.4.7