r2928: - fixed the handling of reserved names (rejecting them with ACCESS_DENIED)
authorAndrew Tridgell <tridge@samba.org>
Tue, 12 Oct 2004 05:33:05 +0000 (05:33 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:59:49 +0000 (12:59 -0500)
- don't check for '.' specially in checking for legal names. Longhorn
  doesn't do this any more, and its a real pain. Longhorn allows for
  filenames ending in '.', and with as many '.' elements as you like.

source/ntvfs/posix/pvfs_resolve.c
source/ntvfs/posix/pvfs_shortname.c
source/ntvfs/posix/vfs_posix.h

index 5b1a5680ae98ab8ef105d4d6cbafc47caf559cfc..01f6b13ec2dcca1b85b6de002188587dffeef257 100644 (file)
@@ -84,6 +84,9 @@ static NTSTATUS pvfs_case_search(struct pvfs_state *pvfs, struct pvfs_filename *
                components[i] = p;
                p = strchr(p, '/');
                if (p) *p++ = 0;
+               if (pvfs_is_reserved_name(pvfs, components[i])) {
+                       return NT_STATUS_ACCESS_DENIED;
+               }
        }
 
        partial_name = talloc_strdup(name, components[0]);
index 818c285fbc8388315bd24ea1fa1a712e7e248dc7..c3c33fbc981708d2f8783b629cf2f1ce2eb78c17 100644 (file)
 
 #define FLAG_CHECK(c, flag) (ctx->char_flags[(uint8_t)(c)] & (flag))
 
+static const char *reserved_names[] = 
+{ "AUX", "CON", "COM1", "COM2", "COM3", "COM4",
+  "LPT1", "LPT2", "LPT3", "NUL", "PRN", NULL };
+
 
 /* 
    hash a string of the specified length. The string does not need to be
@@ -367,11 +371,8 @@ static BOOL is_reserved_name(struct pvfs_mangle_context *ctx, const char *name)
            FLAG_CHECK(name[3], FLAG_POSSIBLE4)) {
                /* a likely match, scan the lot */
                int i;
-               for (i=0; ctx->reserved_names[i]; i++) {
-                       int len = strlen(ctx->reserved_names[i]);
-                       /* note that we match on COM1 as well as COM1.foo */
-                       if (strncasecmp(name, ctx->reserved_names[i], len) == 0 &&
-                           (name[len] == '.' || name[len] == 0)) {
+               for (i=0; reserved_names[i]; i++) {
+                       if (strcasecmp(name, reserved_names[i]) == 0) {
                                return True;
                        }
                }
@@ -387,10 +388,6 @@ static BOOL is_reserved_name(struct pvfs_mangle_context *ctx, const char *name)
 */
 static BOOL is_legal_name(struct pvfs_mangle_context *ctx, const char *name)
 {
-       const char *dot_pos = NULL;
-       BOOL alldots = True;
-       size_t numdots = 0;
-
        while (*name) {
                size_t c_size;
                codepoint_t c = next_codepoint(name, &c_size);
@@ -405,25 +402,9 @@ static BOOL is_legal_name(struct pvfs_mangle_context *ctx, const char *name)
                if (FLAG_CHECK(c, FLAG_ILLEGAL)) {
                        return False;
                }
-               if (name[0] == '.') {
-                       dot_pos = name;
-                       numdots++;
-               } else {
-                       alldots = False;
-               }
-
                name += c_size;
        }
 
-       if (dot_pos) {
-               if (alldots && (numdots == 1 || numdots == 2))
-                       return True; /* . or .. is a valid name */
-
-               /* A valid long name cannot end in '.' */
-               if (dot_pos[1] == '\0')
-                       return False;
-       }
-
        return True;
 }
 
@@ -567,10 +548,6 @@ static void init_tables(struct pvfs_mangle_context *ctx)
        const char *basechars = MANGLE_BASECHARS;
        int i;
        /* the list of reserved dos names - all of these are illegal */
-       const char *reserved_names[] = 
-               { "AUX", "LOCK$", "CON", "COM1", "COM2", "COM3", "COM4",
-                 "LPT1", "LPT2", "LPT3", "NUL", "PRN", NULL };
-
 
        ZERO_STRUCT(ctx->char_flags);
 
@@ -598,17 +575,15 @@ static void init_tables(struct pvfs_mangle_context *ctx)
                ctx->base_reverse[(uint8_t)basechars[i]] = i;
        }       
 
-       ctx->reserved_names = reserved_names;
-
        /* fill in the reserved names flags. These are used as a very
           fast filter for finding possible DOS reserved filenames */
-       for (i=0; ctx->reserved_names[i]; i++) {
+       for (i=0; reserved_names[i]; i++) {
                unsigned char c1, c2, c3, c4;
 
-               c1 = (unsigned char)ctx->reserved_names[i][0];
-               c2 = (unsigned char)ctx->reserved_names[i][1];
-               c3 = (unsigned char)ctx->reserved_names[i][2];
-               c4 = (unsigned char)ctx->reserved_names[i][3];
+               c1 = (unsigned char)reserved_names[i][0];
+               c2 = (unsigned char)reserved_names[i][1];
+               c3 = (unsigned char)reserved_names[i][2];
+               c4 = (unsigned char)reserved_names[i][3];
 
                ctx->char_flags[c1] |= FLAG_POSSIBLE1;
                ctx->char_flags[c2] |= FLAG_POSSIBLE2;
@@ -702,3 +677,12 @@ char *pvfs_mangled_lookup(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
        }
        return NULL;
 }
+
+
+/*
+  look for a DOS reserved name
+*/
+BOOL pvfs_is_reserved_name(struct pvfs_state *pvfs, const char *name)
+{
+       return is_reserved_name(pvfs->mangle_ctx, name);
+}
index f6faf718be42f16c25a69a0e9d86aa7c20b8e055..38e55fd887020941a0411f79e5b9e5e106442da2 100644 (file)
@@ -138,8 +138,6 @@ struct pvfs_mangle_context {
 
        /* this is used to reverse the base 36 mapping */
        unsigned char base_reverse[256];
-
-       const char **reserved_names;
 };