smbd: Add reparse tag to smb3_posix_cc_info
[samba.git] / source3 / smbd / mangle_hash2.c
index 298f348661dd1e6b158ee582b1f99a72b4a37ed4..0075d3bfcba4dab08f70d18197b032212602216e 100644 (file)
@@ -30,7 +30,7 @@
   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
@@ -103,8 +101,10 @@ static const char basechars[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
 /* 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
 
@@ -170,10 +170,10 @@ static void init_tables(void)
                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;
        }
@@ -187,7 +187,7 @@ static void init_tables(void)
 #endif
 }
 
-#else
+#else /* DYNAMIC_MANGLE_TABLES */
 
 /*
  * These tables were initialized by a single run of the above
@@ -197,7 +197,7 @@ static void init_tables(void)
  * 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,
@@ -232,7 +232,7 @@ static uint8_t char_flags[256] = {
        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,
@@ -267,7 +267,7 @@ static uint8_t base_reverse[256] = {
        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
@@ -288,7 +288,7 @@ static unsigned int mangle_hash(const char *key, unsigned int length)
        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);
@@ -435,7 +435,7 @@ static bool is_mangled(const char *name, const struct share_params *parm)
    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)
 {
@@ -443,10 +443,8 @@ static bool is_8_3(const char *name, bool check_case, bool allow_wildcards, cons
        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
@@ -577,7 +575,7 @@ static bool lookup_name_from_8_3(TALLOC_CTX *ctx,
        TALLOC_FREE(prefix);
 
        if (!*pp_out) {
-               M_DEBUG(0,("talloc_fail"));
+               M_DEBUG(0,("talloc_fail\n"));
                return False;
        }
 
@@ -623,17 +621,16 @@ static bool is_legal_name(const char *name)
        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;
                        }
                }
@@ -699,7 +696,7 @@ static bool hash2_name_to_8_3(const char *name,
                /* 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;
                }
        }
@@ -731,7 +728,7 @@ static bool hash2_name_to_8_3(const char *name,
                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] = '_';
@@ -752,7 +749,7 @@ static bool hash2_name_to_8_3(const char *name,
                        char c = dot_p[i];
                        if (FLAG_CHECK(c, FLAG_ASCII)) {
                                extension[extension_length++] =
-                                       toupper_ascii(c);
+                                       toupper_m(c);
                        }
                }
        }