smbd: Slightly simplify downgrade_lease()
[samba.git] / source3 / smbd / mangle_hash2.c
index 298f348661dd1e6b158ee582b1f99a72b4a37ed4..ac1f4b0f4fb40748e77dc8e774b57bd157a03e3e 100644 (file)
 
 
 #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)
@@ -170,10 +173,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;
        }
@@ -288,7 +291,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);
@@ -623,17 +626,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 +701,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 +733,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 +754,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);
                        }
                }
        }