r24498: More extra code into a function, reply_openerror.
authorJeremy Allison <jra@samba.org>
Thu, 16 Aug 2007 17:42:34 +0000 (17:42 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:29:52 +0000 (12:29 -0500)
Jeremy.
(This used to be commit 43ddfb8c918bd27e2efd3b54077db815da80a53a)

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

index 74029a2b05cf51af8ac89aac4381505ff8f74c6e..143417dce361e929eb7003c0d9936036525c6759 100644 (file)
@@ -179,3 +179,20 @@ void reply_unix_error(struct smb_request *req, uint8 defclass, uint32 defcode,
        error_packet_set((char *)req->outbuf, eclass, ecode, ntstatus,
                         line, file);
 }
+
+void reply_openerror(struct smb_request *req, NTSTATUS status)
+{
+       if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
+               /*
+                * We hit an existing file, and if we're returning DOS
+                * error codes OBJECT_NAME_COLLISION would map to
+                * ERRDOS/183, we need to return ERRDOS/80, see bug
+                * 4852.
+                */
+               reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
+                       ERRDOS, ERRfilexists);
+       } else {
+               reply_nterror(req, status);
+       }
+}
+
index 23905181cdca3b9d681ff77fd72eea68f6e8f4e4..907176c161eb681f56137e5403e0e1c0d3dd1d69 100644 (file)
@@ -816,51 +816,50 @@ void reply_ntcreate_and_X(connection_struct *conn,
                                        oplock_request,
                                        &info, &fsp);
 
-               if (!NT_STATUS_IS_OK(status)) { 
-                       /* We cheat here. There are two cases we
-                        * care about. One is a directory rename,
-                        * where the NT client will attempt to
-                        * open the source directory for
-                        * DELETE access. Note that when the
-                        * NT client does this it does *not*
-                        * set the directory bit in the
-                        * request packet. This is translated
-                        * into a read/write open
-                        * request. POSIX states that any open
-                        * for write request on a directory
-                        * will generate an EISDIR error, so
-                        * we can catch this here and open a
-                        * pseudo handle that is flagged as a
-                        * directory. The second is an open
-                        * for a permissions read only, which
-                        * we handle in the open_file_stat case. JRA.
-                        */
+               /* We cheat here. There are two cases we
+                * care about. One is a directory rename,
+                * where the NT client will attempt to
+                * open the source directory for
+                * DELETE access. Note that when the
+                * NT client does this it does *not*
+                * set the directory bit in the
+                * request packet. This is translated
+                * into a read/write open
+                * request. POSIX states that any open
+                * for write request on a directory
+                * will generate an EISDIR error, so
+                * we can catch this here and open a
+                * pseudo handle that is flagged as a
+                * directory. The second is an open
+                * for a permissions read only, which
+                * we handle in the open_file_stat case. JRA.
+                */
 
-                       if (NT_STATUS_EQUAL(status,
-                                           NT_STATUS_FILE_IS_A_DIRECTORY)) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
 
-                               /*
-                                * Fail the open if it was explicitly a non-directory file.
-                                */
+                       /*
+                        * Fail the open if it was explicitly a non-directory
+                        * file.
+                        */
 
-                               if (create_options & FILE_NON_DIRECTORY_FILE) {
-                                       TALLOC_FREE(case_state);
-                                       reply_force_nterror(req, NT_STATUS_FILE_IS_A_DIRECTORY);
-                                       END_PROFILE(SMBntcreateX);
-                                       return;
-                               }
+                       if (create_options & FILE_NON_DIRECTORY_FILE) {
+                               TALLOC_FREE(case_state);
+                               reply_force_nterror(req,
+                                               NT_STATUS_FILE_IS_A_DIRECTORY);
+                               END_PROFILE(SMBntcreateX);
+                               return;
+                       }
 
-                               oplock_request = 0;
-                               status = open_directory(conn, req, fname,
-                                                       &sbuf,
-                                                       access_mask,
-                                                       share_access,
-                                                       create_disposition,
-                                                       create_options,
-                                                       file_attributes,
-                                                       &info, &fsp);
+                       oplock_request = 0;
+                       status = open_directory(conn, req, fname,
+                                               &sbuf,
+                                               access_mask,
+                                               share_access,
+                                               create_disposition,
+                                               create_options,
+                                               file_attributes,
+                                               &info, &fsp);
 
-                       }
                }
        }
 
@@ -872,18 +871,7 @@ void reply_ntcreate_and_X(connection_struct *conn,
                        /* We have re-scheduled this call. */
                        return;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       /*
-                        * We hit an existing file, and if we're returning DOS
-                        * error codes OBJECT_NAME_COLLISION would map to
-                        * ERRDOS/183, we need to return ERRDOS/80, see bug
-                        * 4852.
-                        */
-                       reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
-                               ERRDOS, ERRfilexists);
-                       return;
-               }
-               reply_nterror(req, status);
+               reply_openerror(req, status);
                return;
        }
 
@@ -1532,12 +1520,6 @@ static void call_nt_transact_create(connection_struct *conn,
                                        create_options,
                                        file_attributes,
                                        &info, &fsp);
-               if(!NT_STATUS_IS_OK(status)) {
-                       TALLOC_FREE(case_state);
-                       reply_nterror(req, status);
-                       return;
-               }
-
        } else {
 
                /*
@@ -1553,46 +1535,41 @@ static void call_nt_transact_create(connection_struct *conn,
                                        oplock_request,
                                        &info, &fsp);
 
-               if (!NT_STATUS_IS_OK(status)) { 
-                       if (NT_STATUS_EQUAL(status,
-                                           NT_STATUS_FILE_IS_A_DIRECTORY)) {
+               if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) {
 
-                               /*
-                                * Fail the open if it was explicitly a non-directory file.
-                                */
+                       /*
+                        * Fail the open if it was explicitly a non-directory file.
+                        */
 
-                               if (create_options & FILE_NON_DIRECTORY_FILE) {
-                                       TALLOC_FREE(case_state);
-                                       reply_force_nterror(
-                                               req,
-                                               NT_STATUS_FILE_IS_A_DIRECTORY);
-                                       return;
-                               }
-       
-                               oplock_request = 0;
-                               status = open_directory(conn, req, fname,
-                                                       &sbuf,
-                                                       access_mask,
-                                                       share_access,
-                                                       create_disposition,
-                                                       create_options,
-                                                       file_attributes,
-                                                       &info, &fsp);
-                               if(!NT_STATUS_IS_OK(status)) {
-                                       TALLOC_FREE(case_state);
-                                       reply_nterror(req, status);
-                                       return;
-                               }
-                       } else {
+                       if (create_options & FILE_NON_DIRECTORY_FILE) {
                                TALLOC_FREE(case_state);
-                               if (open_was_deferred(req->mid)) {
-                                       /* We have re-scheduled this call. */
-                                       return;
-                               }
-                               reply_nterror(req, status);
+                               reply_force_nterror(
+                                       req,
+                                       NT_STATUS_FILE_IS_A_DIRECTORY);
                                return;
                        }
-               } 
+
+                       oplock_request = 0;
+                       status = open_directory(conn, req, fname,
+                                               &sbuf,
+                                               access_mask,
+                                               share_access,
+                                               create_disposition,
+                                               create_options,
+                                               file_attributes,
+                                               &info, &fsp);
+               }
+       }
+
+       TALLOC_FREE(case_state);
+
+       if(!NT_STATUS_IS_OK(status)) {
+               if (open_was_deferred(req->mid)) {
+                       /* We have re-scheduled this call. */
+                       return;
+               }
+               reply_openerror(req, status);
+               return;
        }
 
        /*
index 1b0785285dff52d0647ea356fb93b296c0a62ef2..a2ea35b115618e161851781a68f486d10b10b5fe 100644 (file)
@@ -1556,18 +1556,7 @@ void reply_open(connection_struct *conn, struct smb_request *req)
                        /* We have re-scheduled this call. */
                        return;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       /*
-                        * We hit an existing file, and if we're returning DOS
-                        * error codes OBJECT_NAME_COLLISION would map to
-                        * ERRDOS/183, we need to return ERRDOS/80, see bug
-                        * 4852.
-                        */
-                       reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
-                                       ERRDOS, ERRfilexists);
-                       return;
-               }
-               reply_nterror(req, status);
+               reply_openerror(req, status);
                return;
        }
 
@@ -1723,25 +1712,14 @@ void reply_open_and_X(connection_struct *conn, struct smb_request *req)
                        smb_attr,
                        oplock_request,
                        &smb_action, &fsp);
-      
+
        if (!NT_STATUS_IS_OK(status)) {
                END_PROFILE(SMBopenX);
                if (open_was_deferred(req->mid)) {
                        /* We have re-scheduled this call. */
                        return;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       /*
-                        * We hit an existing file, and if we're returning DOS
-                        * error codes OBJECT_NAME_COLLISION would map to
-                        * ERRDOS/183, we need to return ERRDOS/80, see bug
-                        * 4852.
-                        */
-                       reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
-                                       ERRDOS, ERRfilexists);
-                       return;
-               }
-               reply_nterror(req, status);
+               reply_openerror(req, status);
                return;
        }
 
@@ -2087,18 +2065,7 @@ void reply_ctemp(connection_struct *conn, struct smb_request *req)
                        /* We have re-scheduled this call. */
                        return;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       /*
-                        * We hit an existing file, and if we're returning DOS
-                        * error codes OBJECT_NAME_COLLISION would map to
-                        * ERRDOS/183, we need to return ERRDOS/80, see bug
-                        * 4852.
-                        */
-                       reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
-                                       ERRDOS, ERRfilexists);
-                       return;
-               }
-               reply_nterror(req, status);
+               reply_openerror(req, status);
                return;
        }
 
@@ -4678,7 +4645,7 @@ void reply_mkdir(connection_struct *conn, struct smb_request *req)
                END_PROFILE(SMBmkdir);
                return;
        }
-  
+
        status = create_directory(conn, directory);
 
        DEBUG(5, ("create_directory returned %s\n", nt_errstr(status)));
index dbbb2faba98215256c90af93fb2f8442e97b7179..36fb2eee76ee1e6c3647b76d8675ae4927a82a20 100644 (file)
@@ -913,18 +913,7 @@ static void call_trans2open(connection_struct *conn,
                        /* We have re-scheduled this call. */
                        return;
                }
-               if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                       /*
-                        * We hit an existing file, and if we're returning DOS
-                        * error codes OBJECT_NAME_COLLISION would map to
-                        * ERRDOS/183, we need to return ERRDOS/80, see bug
-                        * 4852.
-                        */
-                       reply_botherror(req, NT_STATUS_OBJECT_NAME_COLLISION,
-                               ERRDOS, ERRfilexists);
-                       return;
-               }
-               reply_nterror(req, status);
+               reply_openerror(req, status);
                return;
        }
 
@@ -6515,18 +6504,9 @@ static void call_trans2setfilepathinfo(connection_struct *conn,
                                        ERRSRV, ERRbadpath);
                        return;
                }
-               if (info_level == SMB_POSIX_PATH_OPEN &&
-                       NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
-                               /*
-                                * We hit an existing file, and if we're returning DOS
-                                * error codes OBJECT_NAME_COLLISION would map to
-                                * ERRDOS/183, we need to return ERRDOS/80, see bug
-                                * 4852.
-                                */
-                               reply_botherror(req,
-                                       NT_STATUS_OBJECT_NAME_COLLISION,
-                                       ERRDOS, ERRfilexists);
-                               return;
+               if (info_level == SMB_POSIX_PATH_OPEN) {
+                       reply_openerror(req, status);
+                       return;
                }
 
                reply_nterror(req, status);