1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-19 10:03:58 +03:00
Andrew Bartlett 6d66fb308a BIG patch...
This patch makes Samba compile cleanly with -Wwrite-strings.
 - That is, all string literals are marked as 'const'.  These strings are
always read only, this just marks them as such for passing to other functions.

What is most supprising is that I didn't need to change more than a few lines of code (all
in 'net', which got a small cleanup of net.h and extern variables).  The rest
is just adding a lot of 'const'.

As far as I can tell, I have not added any new warnings - apart from making all
of tdbutil.c's function const (so they warn for adding that const string to
struct).

Andrew Bartlett
(This used to be commit 92a777d0eaa4fb3a1c7835816f93c6bdd456816d)
2003-01-02 09:07:17 +00:00

125 lines
3.1 KiB
C

/*
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 2 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, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
static struct mangle_fns *mangle_fns;
/* this allows us to add more mangling backends */
static const struct {
const char *name;
struct mangle_fns *(*init_fn)(void);
} mangle_backends[] = {
{ "hash", mangle_hash_init },
{ "hash2", mangle_hash2_init },
/*{ "tdb", mangle_tdb_init }, */
{ NULL, NULL }
};
/*
initialise the mangling subsystem
*/
static void mangle_init(void)
{
int i;
char *method;
if (mangle_fns)
return;
method = lp_mangling_method();
/* 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) {
mangle_fns = mangle_backends[i].init_fn();
}
}
if (!mangle_fns) {
DEBUG(0,("Failed to initialise mangling system '%s'\n", method));
exit_server("mangling init failed");
}
}
/*
reset the cache. This is called when smb.conf has been reloaded
*/
void mangle_reset_cache(void)
{
mangle_init();
mangle_fns->reset();
}
/*
see if a filename has come out of our mangling code
*/
BOOL mangle_is_mangled(const char *s)
{
return mangle_fns->is_mangled(s);
}
/*
see if a filename matches the rules of a 8.3 filename
*/
BOOL mangle_is_8_3(const char *fname, BOOL check_case)
{
return mangle_fns->is_8_3(fname, check_case, False);
}
BOOL mangle_is_8_3_wildcards(const char *fname, BOOL check_case)
{
return mangle_fns->is_8_3(fname, check_case, True);
}
/*
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)
{
return mangle_fns->check_cache(s);
}
/*
map a long filename to a 8.3 name.
*/
void mangle_map(char *OutName, BOOL need83, BOOL cache83, int snum)
{
/* name mangling can be disabled for speed, in which case
we just truncate the string */
if (!lp_manglednames(snum)) {
if (need83) {
string_truncate(OutName, 12);
}
return;
}
/* invoke the inane "mangled map" code */
mangle_map_filename(OutName, snum);
mangle_fns->name_map(OutName, need83, cache83);
}