vfs_acl_xattr: factor out fetching of an extended attribute
authorUri Simchoni <uri@samba.org>
Sat, 8 Apr 2017 21:40:44 +0000 (00:40 +0300)
committerJeremy Allison <jra@samba.org>
Mon, 17 Apr 2017 22:43:20 +0000 (00:43 +0200)
Pure refactoring - add a function that fetches an extended attribute
based on either the file descriptor or the file name.

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

Signed-off-by: Uri Simchoni <uri@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/modules/vfs_acl_xattr.c

index e1f90fff281b0d87f5557cd0c6eba8469502d147..85b9a0d660a57bbbced5637c0d4a38fcb16946d4 100644 (file)
  Pull a security descriptor into a DATA_BLOB from a xattr.
 *******************************************************************/
 
+static ssize_t getxattr_do(vfs_handle_struct *handle,
+                          files_struct *fsp,
+                          const struct smb_filename *smb_fname,
+                          const char *xattr_name,
+                          uint8_t *val,
+                          size_t size)
+{
+       ssize_t sizeret;
+       int saved_errno = 0;
+
+       become_root();
+       if (fsp && fsp->fh->fd != -1) {
+               sizeret = SMB_VFS_FGETXATTR(fsp, xattr_name, val, size);
+       } else {
+               sizeret = SMB_VFS_GETXATTR(handle->conn, smb_fname->base_name,
+                                          XATTR_NTACL_NAME, val, size);
+       }
+       if (sizeret == -1) {
+               saved_errno = errno;
+       }
+       unbecome_root();
+
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+
+       return sizeret;
+}
+
 static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
                        vfs_handle_struct *handle,
                        files_struct *fsp,
@@ -47,7 +76,6 @@ static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
        uint8_t *val = NULL;
        uint8_t *tmp;
        ssize_t sizeret;
-       int saved_errno = 0;
 
        ZERO_STRUCTP(pblob);
 
@@ -60,21 +88,11 @@ static NTSTATUS get_acl_blob(TALLOC_CTX *ctx,
        }
        val = tmp;
 
-       become_root();
-       if (fsp && fsp->fh->fd != -1) {
-               sizeret = SMB_VFS_FGETXATTR(fsp, XATTR_NTACL_NAME, val, size);
-       } else {
-               sizeret = SMB_VFS_GETXATTR(handle->conn, smb_fname->base_name,
-                                       XATTR_NTACL_NAME, val, size);
-       }
-       if (sizeret == -1) {
-               saved_errno = errno;
-       }
-       unbecome_root();
+       sizeret =
+           getxattr_do(handle, fsp, smb_fname, XATTR_NTACL_NAME, val, size);
 
        /* Max ACL size is 65536 bytes. */
        if (sizeret == -1) {
-               errno = saved_errno;
                if ((errno == ERANGE) && (size != 65536)) {
                        /* Too small, try again. */
                        size = 65536;