1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-14 12:23:52 +03:00
Files
samba-mirror/source/smbd/mangle.c
Jeremy Allison ea6ef36889 r23844: Add patch series from Volker (after review and consultation).
0001-Save-a-strdup-in-stat_cache_add.patch
0002-Use-ISDOT-and-ISDOTDOT.patch
0003-Move-fname_equal-around.patch
0004-unix_convert-pstring-dirpath-char.patch
0005-Ignore-.o-files.patch
0006-Get-rid-of-pstrings-inside-unix_convert.patch
0007-revert-pstring-unix_convert.patch
0008-Make-name-an-allocated-pstring-inside-unix_convert.patch
0009-Pass-explicit-pstring-to-mangle_check_cache.patch
0010-Don-t-overwrite-orig_path-unnecessarily.patch
0011-Defer-allocating-name.patch
0012-Make-sure-dirpath-is-always-correctly-allocated.patch
0013-Remove-one-pstring-dependency-in-unix_convert.patch
0014-Remove-more-name-pstring-dependencies.patch
0015-Hide-the-nasty-API-of-mangle_check_cache-in-mangle_c.patch
0016-name-does-not-need-to-be-pstring-size-anymore.patch
0017-Make-use-of-ISDOT-and-ISDOTDOT.patch
0018-Remove-pstring-from-stat_cache_lookup.patch
0019-Add-my-copyright.patch

To remove pstrings from statcache and unix_convert.

Jeremy.
2007-10-10 12:28:34 -05:00

150 lines
3.7 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 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;
/* 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 },
{ "posix", posix_mangle_init },
/*{ "tdb", mangle_tdb_init }, */
{ NULL, NULL }
};
/*
initialise the mangling subsystem
*/
static void mangle_init(void)
{
int i;
const 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();
}
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, const struct share_params *p)
{
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,
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, True, p);
}
/*
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,
const struct share_params *p)
{
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), p)
|| !(result = SMB_STRDUP(tmp))) {
return False;
}
*presult = result;
return True;
}
/*
map a long filename to a 8.3 name.
*/
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(p)) {
if (need83) {
string_truncate(OutName, 12);
}
return;
}
/* invoke the inane "mangled map" code */
mangle_map_filename(OutName, p);
mangle_fns->name_map(OutName, need83, cache83, lp_defaultcase(p->service), p);
}