]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:smbd: remove one indentation level in close_directory()
authorStefan Metzmacher <metze@samba.org>
Mon, 12 Sep 2022 17:41:25 +0000 (19:41 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 20 Sep 2022 00:34:36 +0000 (00:34 +0000)
We now use a goto done in order to skip the deletion part.

This means the code flow is now almost idential compared to
close_remove_share_mode().

It prepares to split common code to be shared by
close_remove_share_mode() and close_directory().

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/close.c

index 79264c74e81f09e374dc77b0b569c35b6ddd2562..a120f02e90d4e40c0e67692423cd0cbca9f02866 100644 (file)
@@ -1442,63 +1442,66 @@ static NTSTATUS close_directory(struct smb_request *req, files_struct *fsp,
                delete_dir = false;
        }
 
-       if (delete_dir) {
+       if (!delete_dir) {
+               status = NT_STATUS_OK;
+               goto done;
+       }
 
-               /*
-                * Ok, we have to delete the directory
-                */
+       /*
+        * Ok, we have to delete the directory
+        */
 
-               DBG_INFO("dir %s. Delete on close was set - deleting directory.\n",
-                        fsp_str_dbg(fsp));
+       DBG_INFO("dir %s. Delete on close was set - deleting directory.\n",
+                fsp_str_dbg(fsp));
 
-               got_tokens = get_delete_on_close_token(lck, fsp->name_hash,
-                                               &del_nt_token, &del_token);
-               SMB_ASSERT(got_tokens);
+       got_tokens = get_delete_on_close_token(lck, fsp->name_hash,
+                                       &del_nt_token, &del_token);
+       SMB_ASSERT(got_tokens);
 
-               /* Become the user who requested the delete. */
+       /* Become the user who requested the delete. */
 
-               if (!push_sec_ctx()) {
-                       smb_panic("close_directory: failed to push sec_ctx.\n");
-               }
+       if (!push_sec_ctx()) {
+               smb_panic("close_directory: failed to push sec_ctx.\n");
+       }
 
-               set_sec_ctx(del_token->uid,
-                               del_token->gid,
-                               del_token->ngroups,
-                               del_token->groups,
-                               del_nt_token);
+       set_sec_ctx(del_token->uid,
+                       del_token->gid,
+                       del_token->ngroups,
+                       del_token->groups,
+                       del_nt_token);
 
-               if ((fsp->conn->fs_capabilities & FILE_NAMED_STREAMS)
-                   && !is_ntfs_stream_smb_fname(fsp->fsp_name)) {
+       if ((fsp->conn->fs_capabilities & FILE_NAMED_STREAMS)
+           && !is_ntfs_stream_smb_fname(fsp->fsp_name)) {
 
-                       status = delete_all_streams(fsp->conn, fsp->fsp_name);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               DEBUG(5, ("delete_all_streams failed: %s\n",
-                                         nt_errstr(status)));
-                               /* unbecome user. */
-                               pop_sec_ctx();
-                               return status;
-                       }
+               status = delete_all_streams(fsp->conn, fsp->fsp_name);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(5, ("delete_all_streams failed: %s\n",
+                                 nt_errstr(status)));
+                       /* unbecome user. */
+                       pop_sec_ctx();
+                       return status;
                }
+       }
 
-               status = rmdir_internals(talloc_tos(), fsp);
+       status = rmdir_internals(talloc_tos(), fsp);
 
-               DEBUG(5,("close_directory: %s. Delete on close was set - "
-                        "deleting directory returned %s.\n",
-                        fsp_str_dbg(fsp), nt_errstr(status)));
+       DEBUG(5,("close_directory: %s. Delete on close was set - "
+                "deleting directory returned %s.\n",
+                fsp_str_dbg(fsp), nt_errstr(status)));
 
-               /* unbecome user. */
-               pop_sec_ctx();
+       /* unbecome user. */
+       pop_sec_ctx();
 
-               /*
-                * Ensure we remove any change notify requests that would
-                * now fail as the directory has been deleted.
-                */
+       /*
+        * Ensure we remove any change notify requests that would
+        * now fail as the directory has been deleted.
+        */
 
-               if (NT_STATUS_IS_OK(status)) {
-                       notify_status = NT_STATUS_DELETE_PENDING;
-               }
+       if (NT_STATUS_IS_OK(status)) {
+               notify_status = NT_STATUS_DELETE_PENDING;
        }
 
+done:
        if (!del_share_mode(lck, fsp)) {
                DEBUG(0, ("close_directory: Could not delete share entry for "
                          "%s\n", fsp_str_dbg(fsp)));