TODO test it s3:smbd: optimize unix_convert() for the wildcard case
authorStefan Metzmacher <metze@samba.org>
Thu, 9 Sep 2010 11:55:26 +0000 (13:55 +0200)
committerStefan Metzmacher <metze@samba.org>
Mon, 18 Apr 2011 15:59:23 +0000 (17:59 +0200)
metze

source3/smbd/filename.c

index 7178f82fcef86e1b5e236fc9e4a76d7b44f29486..58a267111e786b225f10b7394919a1a3f666633a 100644 (file)
@@ -217,8 +217,8 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
         * Ensure saved_last_component is valid even if file exists.
         */
 
+       end = strrchr_m(name, '/');
        if(pp_saved_last_component) {
-               end = strrchr_m(name, '/');
                if (end) {
                        *pp_saved_last_component = talloc_strdup(ctx, end + 1);
                } else {
@@ -307,6 +307,34 @@ NTSTATUS unix_convert(TALLOC_CTX *ctx,
                        *pst = st;
                        goto done;
                }
+       } else if (end) {
+               *end = '\0';
+               if (posix_pathnames) {
+                       ret = SMB_VFS_LSTAT(conn,name,&st);
+               } else {
+                       ret = SMB_VFS_STAT(conn,name,&st);
+               }
+
+               if (ret == 0) {
+                       /* Ensure we catch all names with in "/."
+                          this is disallowed under Windows. */
+                       const char *p = strstr(name, "/."); /* mb safe. */
+                       *end = '/';
+                       if (p) {
+                               if (p[2] == '/') {
+                                       /* Error code within a pathname. */
+                                       result = NT_STATUS_OBJECT_PATH_NOT_FOUND;
+                                       goto fail;
+                               } else if (p[2] == '\0') {
+                                       /* Error code at the end of a pathname. */
+                                       result = NT_STATUS_OBJECT_NAME_INVALID;
+                                       goto fail;
+                               }
+                       }
+                       DEBUG(5,("conversion finished %s -> %s\n",orig_path, name));
+                       goto done;
+               }
+               *end = '/';
        }
 
        DEBUG(5,("unix_convert begin: name = %s, dirpath = %s, start = %s\n",