for simplicity, we only allow ascii characters in 8.3 names
*/
- /* hash alghorithm changed to FNV1 by idra@samba.org (Simo Sorce).
+ /* hash algorithm changed to FNV1 by idra@samba.org (Simo Sorce).
* see http://www.isthe.com/chongo/tech/comp/fnv/index.html for a
* discussion on Fowler / Noll / Vo (FNV) Hash by one of it's authors
*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "smbd/globals.h"
+#include "../lib/util/memcache.h"
+#include "mangle.h"
#if 1
#define M_DEBUG(level, x) DEBUG(level, x)
#define FLAG_POSSIBLE3 64
#define FLAG_POSSIBLE4 128
-/* by default have a max of 4096 entries in the cache. */
-#ifndef MANGLE_CACHE_SIZE
-#define MANGLE_CACHE_SIZE 4096
-#endif
-
#define FNV1_PRIME 0x01000193
/*the following number is a fnv1 of the string: idra@samba.org 2002 */
#define FNV1_INIT 0xa6b93095
/* the list of reserved dos names - all of these are illegal */
static const char * const reserved_names[] =
-{ "AUX", "LOCK$", "CON", "COM1", "COM2", "COM3", "COM4",
- "LPT1", "LPT2", "LPT3", "NUL", "PRN", NULL };
+{ "AUX", "CON",
+ "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9",
+ "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
+ "NUL", "PRN", NULL };
#define DYNAMIC_MANGLE_TABLES 0
char_flags[c2] |= FLAG_POSSIBLE2;
char_flags[c3] |= FLAG_POSSIBLE3;
char_flags[c4] |= FLAG_POSSIBLE4;
- char_flags[tolower_ascii(c1)] |= FLAG_POSSIBLE1;
- char_flags[tolower_ascii(c2)] |= FLAG_POSSIBLE2;
- char_flags[tolower_ascii(c3)] |= FLAG_POSSIBLE3;
- char_flags[tolower_ascii(c4)] |= FLAG_POSSIBLE4;
+ char_flags[tolower_m(c1)] |= FLAG_POSSIBLE1;
+ char_flags[tolower_m(c2)] |= FLAG_POSSIBLE2;
+ char_flags[tolower_m(c3)] |= FLAG_POSSIBLE3;
+ char_flags[tolower_m(c4)] |= FLAG_POSSIBLE4;
char_flags[(unsigned char)'.'] |= FLAG_POSSIBLE4;
}
#endif
}
-#else
+#else /* DYNAMIC_MANGLE_TABLES */
/*
* These tables were initialized by a single run of the above
* initializers, but I'll leave it in: less surprise.
*/
-static uint8_t char_flags[256] = {
+static const uint8_t char_flags[256] = {
0x80, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-static uint8_t base_reverse[256] = {
+static const uint8_t base_reverse[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
-#endif
+#endif /* DYNAMIC_MANGLE_TABLES */
/*
hash a string of the specified length. The string does not need to be
length = MIN(length,sizeof(fstring)-1);
strncpy(str, key, length);
str[length] = 0;
- strupper_m(str);
+ (void)strupper_m(str);
/* the length of a multi-byte string can change after a strupper_m */
length = strlen(str);
get larger when converted from UNIX to DOS formats)
*/
-static char force_shortname_chars[] = " +,[];=";
+static const char force_shortname_chars[] = " +,[];=";
static bool is_8_3(const char *name, bool check_case, bool allow_wildcards, const struct share_params *p)
{
char *dot_p;
/* as a special case, the names '.' and '..' are allowable 8.3 names */
- if (name[0] == '.') {
- if (!name[1] || (name[1] == '.' && !name[2])) {
- return True;
- }
+ if (ISDOT(name) || (ISDOTDOT(name))) {
+ return true;
}
/* the simplest test is on the overall length of the
TALLOC_FREE(prefix);
if (!*pp_out) {
- M_DEBUG(0,("talloc_fail"));
+ M_DEBUG(0,("talloc_fail\n"));
return False;
}
while (*name) {
if (((unsigned int)name[0]) > 128 && (name[1] != 0)) {
/* Possible start of mb character. */
- char mbc[2];
+ size_t size = 0;
+ (void)next_codepoint(name, &size);
/*
- * Note that if CH_UNIX is utf8 a string may be 3
- * bytes, but this is ok as mb utf8 characters don't
- * contain embedded ascii bytes. We are really checking
- * for mb UNIX asian characters like Japanese (SJIS) here.
- * JRA.
+ * Note that we're only looking for multibyte
+ * encoding here. No encoding with a length > 1
+ * contains invalid characters.
*/
- if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2, False) == 2) {
- /* Was a good mb string. */
- name += 2;
+ if (size > 1) {
+ /* Was a mb string. */
+ name += size;
continue;
}
}
/* if the name is already a valid 8.3 name then we don't need to
* change anything */
if (is_legal_name(name) && is_8_3(name, False, False, p)) {
- safe_strcpy(new_name, name, 12);
+ strlcpy(new_name, name, 13);
return True;
}
}
if (! FLAG_CHECK(lead_chars[i], FLAG_ASCII)) {
lead_chars[i] = '_';
}
- lead_chars[i] = toupper_ascii(lead_chars[i]);
+ lead_chars[i] = toupper_m(lead_chars[i]);
}
for (;i<mangle_prefix;i++) {
lead_chars[i] = '_';
char c = dot_p[i];
if (FLAG_CHECK(c, FLAG_ASCII)) {
extension[extension_length++] =
- toupper_ascii(c);
+ toupper_m(c);
}
}
}