*/
#include "includes.h"
+#include "smbd/globals.h"
+#include "mangle.h"
/* -------------------------------------------------------------------------- **
* Other stuff...
*
*/
-static char magic_char = '~';
-
-static const char basechars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
+static const char basechars[43]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
#define MANGLE_BASE (sizeof(basechars)/sizeof(char)-1)
-static unsigned char *chartest;
-
#define mangle(V) ((char)(basechars[(V) % MANGLE_BASE]))
#define BASECHAR_MASK 0xf0
#define isbasechar(C) ( (chartest[ ((C) & 0xff) ]) & BASECHAR_MASK )
-static TDB_CONTEXT *tdb_mangled_cache;
-
/* -------------------------------------------------------------------- */
static NTSTATUS has_valid_83_chars(const smb_ucs2_t *s, bool allow_wildcards)
smb_ucs2_t *ucs2name;
NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
size_t size;
+ char magic_char;
magic_char = lp_magicchar(p);
if (strlen(f) > 12)
return False;
- size = push_ucs2_allocate(&ucs2name, f);
- if (size == (size_t)-1) {
- DEBUG(0,("is_8_3: internal error push_ucs2_allocate() failed!\n"));
+ if (!push_ucs2_talloc(NULL, &ucs2name, f, &size)) {
+ DEBUG(0,("is_8_3: internal error push_ucs2_talloc() failed!\n"));
goto done;
}
ret = is_8_3_w(ucs2name, allow_wildcards);
done:
- SAFE_FREE(ucs2name);
+ TALLOC_FREE(ucs2name);
if (!NT_STATUS_IS_OK(ret)) {
return False;
chartest = SMB_MALLOC_ARRAY(unsigned char, 256);
SMB_ASSERT(chartest != NULL);
+ memset(chartest, '\0', 256);
for( s = (const unsigned char *)basechars; *s; s++ ) {
chartest[*s] |= BASECHAR_MASK;
static bool is_mangled(const char *s, const struct share_params *p)
{
char *magic;
+ char magic_char;
magic_char = lp_magicchar(p);
{
TDB_DATA data_val;
char mangled_name_key[13];
- char *s1;
- char *s2;
+ char *s1 = NULL;
+ char *s2 = NULL;
/* If the cache isn't initialized, give up. */
if( !tdb_mangled_cache )
if( !s1[i] && !s2[i] ) {
/* Truncate at the '.' */
*s1 = '\0';
+ /*
+ * DANGER WILL ROBINSON - this
+ * is changing a const string via
+ * an aliased pointer ! Remember to
+ * put it back once we've used it.
+ * JRA
+ */
*s2 = '\0';
}
}
} else {
DEBUG(5,("cache_mangled_name: Stored entry %s -> %s\n", mangled_name_key, raw_name));
}
+ /* Restore the change we made to the const string. */
+ if (s2) {
+ *s2 = '.';
+ }
}
/* ************************************************************************** **
TDB_DATA data_val;
char *saved_ext = NULL;
char *s = talloc_strdup(ctx, in);
+ char magic_char;
magic_char = lp_magicchar(p);
Do the actual mangling to 8.3 format.
*****************************************************************************/
-static bool to_8_3(const char *in, char out[13], int default_case)
+static bool to_8_3(char magic_char, const char *in, char out[13], int default_case)
{
int csum;
char *p;
{
smb_ucs2_t *name_ucs2 = NULL;
NTSTATUS status;
+ size_t converted_size;
+ char magic_char;
+
magic_char = lp_magicchar(p);
- if (push_ucs2_allocate(&name_ucs2, name) == (size_t)-1) {
- DEBUG(0, ("push_ucs2_allocate failed!\n"));
+ if (!push_ucs2_talloc(NULL, &name_ucs2, name, &converted_size)) {
+ DEBUG(0, ("push_ucs2_talloc failed!\n"));
return False;
}
status = is_valid_name(name_ucs2, False, False);
- SAFE_FREE(name_ucs2);
- return NT_STATUS_IS_OK(status);
+ TALLOC_FREE(name_ucs2);
+ /* We return true if we *must* mangle, so if it's
+ * a valid name (status == OK) then we must return
+ * false. Bug #6939. */
+ return !NT_STATUS_IS_OK(status);
}
/*****************************************************************************
const struct share_params *p)
{
smb_ucs2_t *in_ucs2 = NULL;
+ size_t converted_size;
+ char magic_char;
+
magic_char = lp_magicchar(p);
DEBUG(5,("hash_name_to_8_3( %s, cache83 = %s)\n", in,
cache83 ? "True" : "False"));
- if (push_ucs2_allocate(&in_ucs2, in) == (size_t)-1) {
- DEBUG(0, ("push_ucs2_allocate failed!\n"));
+ if (!push_ucs2_talloc(NULL, &in_ucs2, in, &converted_size)) {
+ DEBUG(0, ("push_ucs2_talloc failed!\n"));
return False;
}
/* If it's already 8.3, just copy. */
if (NT_STATUS_IS_OK(is_valid_name(in_ucs2, False, False)) &&
NT_STATUS_IS_OK(is_8_3_w(in_ucs2, False))) {
- SAFE_FREE(in_ucs2);
+ TALLOC_FREE(in_ucs2);
safe_strcpy(out, in, 12);
return True;
}
- SAFE_FREE(in_ucs2);
- if (!to_8_3(in, out, default_case)) {
+ TALLOC_FREE(in_ucs2);
+ if (!to_8_3(magic_char, in, out, default_case)) {
return False;
}
the following provides the abstraction layer to make it easier
to drop in an alternative mangling implementation
*/
-static struct mangle_fns mangle_fns = {
+static const struct mangle_fns mangle_hash_fns = {
mangle_reset,
is_mangled,
must_mangle,
};
/* return the methods for this mangling implementation */
-struct mangle_fns *mangle_hash_init(void)
+const struct mangle_fns *mangle_hash_init(void)
{
mangle_reset();
tdb_mangled_cache = tdb_open_ex("mangled_cache", 1031, TDB_INTERNAL,
(O_RDWR|O_CREAT), 0644, NULL, fast_string_hash);
- return &mangle_fns;
+ return &mangle_hash_fns;
}