Fixed the error bad path for recursive mkdir so mkdir \a\b\c\d works.
authorJeremy Allison <jra@samba.org>
Tue, 2 Apr 2002 19:34:36 +0000 (19:34 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 2 Apr 2002 19:34:36 +0000 (19:34 +0000)
Forward ported some of the code tidyups from 2.2.
Jeremy.
(This used to be commit 2475c09b354cc7b5f4ce384e4497207d30f619bb)

source3/smbd/nttrans.c
source3/smbd/reply.c
source3/smbd/trans2.c

index ba6fd3eb44ffa0bfe3281785bc67511be64fea16..2c0955c834ddcdb342ec0a80518c141da89a419b 100644 (file)
@@ -685,10 +685,7 @@ int reply_ntcreate_and_X(connection_struct *conn,
                restore_case_semantics(file_attributes);
 
                if(!fsp) {
-                       if((errno == ENOENT) && bad_path) {
-                               unix_ERR_class = ERRDOS;
-                               unix_ERR_code = ERRbadpath;
-                       }
+                       set_bad_path_error(errno, bad_path);
                        END_PROFILE(SMBntcreateX);
                        return(UNIXERROR(ERRDOS,ERRnoaccess));
                }
@@ -755,22 +752,14 @@ int reply_ntcreate_and_X(connection_struct *conn,
                                
                                if(!fsp) {
                                        restore_case_semantics(file_attributes);
-                                       if((errno == ENOENT) && bad_path) {
-                                               unix_ERR_class = ERRDOS;
-                                               unix_ERR_code = ERRbadpath;
-                                       }
+                                       set_bad_path_error(errno, bad_path);
                                        END_PROFILE(SMBntcreateX);
                                        return(UNIXERROR(ERRDOS,ERRnoaccess));
                                }
                        } else {
 
-                               if((errno == ENOENT) && bad_path) {
-                                       unix_ERR_class = ERRDOS;
-                                       unix_ERR_code = ERRbadpath;
-                               }
-                               
                                restore_case_semantics(file_attributes);
-                               
+                               set_bad_path_error(errno, bad_path);
                                END_PROFILE(SMBntcreateX);
                                return(UNIXERROR(ERRDOS,ERRnoaccess));
                        }
@@ -1180,10 +1169,7 @@ static int call_nt_transact_create(connection_struct *conn,
 
     if(!fsp) {
       restore_case_semantics(file_attributes);
-      if((errno == ENOENT) && bad_path) {
-        unix_ERR_class = ERRDOS;
-        unix_ERR_code = ERRbadpath;
-      }
+      set_bad_path_error(errno, bad_path);
       return(UNIXERROR(ERRDOS,ERRnoaccess));
     }
 
@@ -1217,21 +1203,13 @@ static int call_nt_transact_create(connection_struct *conn,
                                
                        if(!fsp) {
                                restore_case_semantics(file_attributes);
-                               if((errno == ENOENT) && bad_path) {
-                                       unix_ERR_class = ERRDOS;
-                                       unix_ERR_code = ERRbadpath;
-                               }
+                               set_bad_path_error(errno, bad_path);
                                return(UNIXERROR(ERRDOS,ERRnoaccess));
                        }
                } else {
 
-                       if((errno == ENOENT) && bad_path) {
-                               unix_ERR_class = ERRDOS;
-                               unix_ERR_code = ERRbadpath;
-                       }
-
                        restore_case_semantics(file_attributes);
-
+                       set_bad_path_error(errno, bad_path);
                        return(UNIXERROR(ERRDOS,ERRnoaccess));
                }
       } 
index 06f068dcccf028f7ad6d9319a2c17aafa8b068b0..af582f1a41c917be0a7fdddfe95175c430b08596 100644 (file)
@@ -463,12 +463,7 @@ int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
-
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBgetatr);
     return(UNIXERROR(ERRDOS,ERRbadfile));
   }
@@ -527,12 +522,7 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
-
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBsetatr);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -678,12 +668,8 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
       {
         if(dptr_num == -2)
         {
-          if((errno == ENOENT) && bad_path)
-          {
-            unix_ERR_class = ERRDOS;
-            unix_ERR_code = ERRbadpath;
-          }
-                END_PROFILE(SMBsearch);
+          set_bad_path_error(errno, bad_path);
+          END_PROFILE(SMBsearch);
           return (UNIXERROR(ERRDOS,ERRnofids));
         }
                END_PROFILE(SMBsearch);
@@ -857,11 +843,7 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
 
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBopen);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -951,11 +933,7 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
       
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBopenX);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -1090,11 +1068,7 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path) 
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBcreate);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -1164,11 +1138,8 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   /* close fd from smb_mkstemp() */
   close(tmpfd);
 
-       if (!fsp) {
-               if((errno == ENOENT) && bad_path) {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+  if (!fsp) {
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBctemp);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -2724,6 +2695,9 @@ NTSTATUS mkdir_internal(connection_struct *conn, pstring directory)
                ret = vfs_mkdir(conn,directory,unix_mode(conn,aDIR,directory));
        
        if (ret == -1) {
+               NTSTATUS nterr = set_bad_path_error(errno, bad_path);
+               if (!NT_STATUS_IS_OK(nterr))
+                       return nterr;
                return map_nt_error_from_unix(errno);
        }
        
@@ -2916,11 +2890,7 @@ int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBrmdir);
     return(UNIXERROR(ERRDOS,ERRbadpath));
   }
index aca7e47d4812ff9cf757721b9cb96a3c1ac520c8..ca8ad5fa797a7fdf3dbe06fe43309c2673ad7f3b 100644 (file)
@@ -1412,6 +1412,20 @@ static int call_trans2setfsinfo(connection_struct *conn,
   return outsize;
 }
 
+/****************************************************************************
+ *  Utility function to set bad path error.
+ ****************************************************************************/
+
+NTSTATUS set_bad_path_error(int err, BOOL bad_path)
+{
+       if((err == ENOENT) && bad_path) {
+               unix_ERR_class = ERRDOS;
+               unix_ERR_code = ERRbadpath;
+               return NT_STATUS_OBJECT_PATH_NOT_FOUND;
+       }
+       return NT_STATUS_OK;
+}
+
 /****************************************************************************
  Reply to a TRANS2_QFILEPATHINFO or TRANSACT2_QFILEINFO (query file info by
  file name or file id).