]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify smb_set_posix_acl()
authorVolker Lendecke <vl@samba.org>
Wed, 4 Dec 2024 08:01:15 +0000 (09:01 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 17 Dec 2024 12:30:30 +0000 (12:30 +0000)
Call get_posix_fsp() in the caller, this removes if-conditions in
smb_set_posix_acl() itself

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
source3/smbd/smb1_trans2.c

index dbabf1541a1080990605e82560135da545f4a687..ec7ae083a4db17abae2a70c3fcd25f610b27d720 100644 (file)
@@ -4242,7 +4242,6 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
        NTSTATUS status;
        unsigned int size_needed;
        unsigned int total_data;
-       bool close_fsp = false;
        bool refuse;
 
        if (total_data_in < 0) {
@@ -4304,32 +4303,6 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
                goto out;
        }
 
-       /*
-        * Ensure we always operate on a file descriptor, not just
-        * the filename.
-        */
-       if (fsp == NULL || !fsp->fsp_flags.is_fsa) {
-               uint32_t access_mask = SEC_STD_WRITE_OWNER|
-                                       SEC_STD_WRITE_DAC|
-                                       SEC_STD_READ_CONTROL|
-                                       FILE_READ_ATTRIBUTES|
-                                       FILE_WRITE_ATTRIBUTES;
-
-               status = get_posix_fsp(conn,
-                                       req,
-                                       smb_fname,
-                                       access_mask,
-                                       &fsp);
-
-               if (!NT_STATUS_IS_OK(status)) {
-                       goto out;
-               }
-               close_fsp = true;
-       }
-
-       /* Here we know fsp != NULL */
-       SMB_ASSERT(fsp != NULL);
-
        refuse = refuse_symlink_fsp(fsp);
        if (refuse) {
                status = NT_STATUS_ACCESS_DENIED;
@@ -4379,10 +4352,6 @@ static NTSTATUS smb_set_posix_acl(connection_struct *conn,
        status = NT_STATUS_OK;
 
   out:
-
-       if (close_fsp) {
-               (void)close_file_free(req, &fsp, NORMAL_CLOSE);
-       }
        return status;
 #endif
 }
@@ -4543,11 +4512,28 @@ static void call_trans2setpathinfo(
                                                 smb_fname->fsp,
                                                 smb_fname);
                break;
-       case SMB_SET_POSIX_ACL:
+       case SMB_SET_POSIX_ACL: {
+               struct files_struct *posix_fsp = NULL;
+
+               status = get_posix_fsp(conn,
+                                      req,
+                                      smb_fname,
+                                      SEC_STD_WRITE_OWNER |
+                                              SEC_STD_WRITE_DAC |
+                                              SEC_STD_READ_CONTROL |
+                                              FILE_READ_ATTRIBUTES |
+                                              FILE_WRITE_ATTRIBUTES,
+                                      &posix_fsp);
+               if (!NT_STATUS_IS_OK(status)) {
+                       break;
+               }
+
                status = smb_set_posix_acl(
-                       conn, req, *ppdata, total_data, NULL, smb_fname);
+                       conn, req, *ppdata, total_data, posix_fsp, smb_fname);
+               (void)close_file_free(req, &posix_fsp, NORMAL_CLOSE);
                break;
        }
+       }
 
        if (info_level_handled) {
                goto done;