winbindd: create the messaging conntext earlier
[Samba.git] / source / smbd / mangle.c
blob360692c54627ab74d64068f0f382211323256b80
1 /*
2 Unix SMB/CIFS implementation.
3 Name mangling interface
4 Copyright (C) Andrew Tridgell 2002
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
22 static struct mangle_fns *mangle_fns;
24 /* this allows us to add more mangling backends */
25 static const struct {
26 const char *name;
27 struct mangle_fns *(*init_fn)(void);
28 } mangle_backends[] = {
29 { "hash", mangle_hash_init },
30 { "hash2", mangle_hash2_init },
31 { "posix", posix_mangle_init },
32 /*{ "tdb", mangle_tdb_init }, */
33 { NULL, NULL }
37 initialise the mangling subsystem
39 static void mangle_init(void)
41 int i;
42 const char *method;
44 if (mangle_fns)
45 return;
47 method = lp_mangling_method();
49 /* find the first mangling method that manages to initialise and
50 matches the "mangling method" parameter */
51 for (i=0; mangle_backends[i].name && !mangle_fns; i++) {
52 if (!method || !*method || strcmp(method, mangle_backends[i].name) == 0) {
53 mangle_fns = mangle_backends[i].init_fn();
57 if (!mangle_fns) {
58 DEBUG(0,("Failed to initialise mangling system '%s'\n", method));
59 exit_server("mangling init failed");
65 reset the cache. This is called when smb.conf has been reloaded
67 void mangle_reset_cache(void)
69 mangle_init();
70 mangle_fns->reset();
73 void mangle_change_to_posix(void)
75 mangle_fns = NULL;
76 lp_set_mangling_method("posix");
77 mangle_reset_cache();
81 see if a filename has come out of our mangling code
83 bool mangle_is_mangled(const char *s, const struct share_params *p)
85 return mangle_fns->is_mangled(s, p);
89 see if a filename matches the rules of a 8.3 filename
91 bool mangle_is_8_3(const char *fname, bool check_case,
92 const struct share_params *p)
94 return mangle_fns->is_8_3(fname, check_case, False, p);
97 bool mangle_is_8_3_wildcards(const char *fname, bool check_case,
98 const struct share_params *p)
100 return mangle_fns->is_8_3(fname, check_case, True, p);
103 bool mangle_must_mangle(const char *fname,
104 const struct share_params *p)
106 if (!lp_manglednames(p)) {
107 return False;
109 return mangle_fns->must_mangle(fname, p);
113 try to reverse map a 8.3 name to the original filename. This doesn't have to
114 always succeed, as the directory handling code in smbd will scan the directory
115 looking for a matching name if it doesn't. It should succeed most of the time
116 or there will be a huge performance penalty
118 bool mangle_lookup_name_from_8_3(TALLOC_CTX *ctx,
119 const char *in,
120 char **out, /* talloced on the given context. */
121 const struct share_params *p)
123 return mangle_fns->lookup_name_from_8_3(ctx, in, out, p);
127 mangle a long filename to a 8.3 name.
128 Return True if we did mangle the name (ie. out is filled in).
129 False on error.
130 JRA.
133 bool name_to_8_3(const char *in,
134 char out[13],
135 bool cache83,
136 const struct share_params *p)
138 memset(out,'\0',13);
140 /* name mangling can be disabled for speed, in which case
141 we just truncate the string */
142 if (!lp_manglednames(p)) {
143 safe_strcpy(out,in,12);
144 return True;
147 return mangle_fns->name_to_8_3(in,
148 out,
149 cache83,
150 lp_defaultcase(p->service),