s3:utils: let smbstatus report anonymous signing/encryption explicitly
[samba.git] / source3 / modules / posixacl_xattr.c
index e88c6cecacec366f67decc5354340d9168037c2a..5d0516cf7541c0a460f2368a629e02b7e76454fa 100644 (file)
@@ -226,14 +226,14 @@ static int posixacl_xattr_entry_compare(const void *left, const void *right)
        tag_left = SVAL(left, 0);
        tag_right = SVAL(right, 0);
 
-       ret = (tag_left - tag_right);
-       if (!ret) {
+       ret = NUMERIC_CMP(tag_left, tag_right);
+       if (ret == 0) {
                /* ID is the third element in the entry, after two short
                   integers (tag and perm), i.e at offset 4.
                */
                id_left = IVAL(left, 4);
                id_right = IVAL(right, 4);
-               ret = id_left - id_right;
+               ret = NUMERIC_CMP(id_left, id_right);
        }
 
        return ret;
@@ -335,14 +335,14 @@ static int smb_acl_to_posixacl_xattr(SMB_ACL_T theacl, char *buf, size_t len)
        return size;
 }
 
-SMB_ACL_T posixacl_xattr_acl_get_file(vfs_handle_struct *handle,
-                                     const struct smb_filename *smb_fname,
-                                     SMB_ACL_TYPE_T type,
-                                     TALLOC_CTX *mem_ctx)
+SMB_ACL_T posixacl_xattr_acl_get_fd(vfs_handle_struct *handle,
+                                   files_struct *fsp,
+                                   SMB_ACL_TYPE_T type,
+                                   TALLOC_CTX *mem_ctx)
 {
        int ret;
-       int size;
-       char *buf;
+       int size = ACL_EA_SIZE(20);
+       char *buf = alloca(size);
        const char *name;
 
        if (type == SMB_ACL_TYPE_ACCESS) {
@@ -354,80 +354,19 @@ SMB_ACL_T posixacl_xattr_acl_get_file(vfs_handle_struct *handle,
                return NULL;
        }
 
-       size = ACL_EA_SIZE(20);
-       buf = alloca(size);
-       if (!buf) {
-               return NULL;
-       }
-
-       ret = SMB_VFS_GETXATTR(handle->conn, smb_fname,
-                               name, buf, size);
-       if (ret < 0 && errno == ERANGE) {
-               size = SMB_VFS_GETXATTR(handle->conn, smb_fname,
-                                       name, NULL, 0);
-               if (size > 0) {
-                       buf = alloca(size);
-                       if (!buf) {
-                               return NULL;
-                       }
-                       ret = SMB_VFS_GETXATTR(handle->conn,
-                                               smb_fname, name,
-                                               buf, size);
-               }
-       }
-
-       if (ret > 0) {
-               return posixacl_xattr_to_smb_acl(buf, ret, mem_ctx);
-       }
-       if (ret == 0 || errno == ENOATTR) {
-               mode_t mode = 0;
-               TALLOC_CTX *frame = talloc_stackframe();
-               struct smb_filename *smb_fname_tmp =
-                       cp_smb_filename_nostream(frame, smb_fname);
-               if (smb_fname_tmp == NULL) {
-                       errno = ENOMEM;
-                       ret = -1;
-               } else {
-                       ret = SMB_VFS_STAT(handle->conn, smb_fname_tmp);
-                       if (ret == 0) {
-                               mode = smb_fname_tmp->st.st_ex_mode;
-                       }
-               }
-               TALLOC_FREE(frame);
-               if (ret == 0) {
-                       if (type == SMB_ACL_TYPE_ACCESS) {
-                               return mode_to_smb_acl(mode, mem_ctx);
-                       }
-                       if (S_ISDIR(mode)) {
-                               return sys_acl_init(mem_ctx);
-                       }
-                       errno = EACCES;
-               }
-       }
-       return NULL;
-}
-
-SMB_ACL_T posixacl_xattr_acl_get_fd(vfs_handle_struct *handle,
-                                   files_struct *fsp,
-                                   TALLOC_CTX *mem_ctx)
-{
-       int ret;
-       int size = ACL_EA_SIZE(20);
-       char *buf = alloca(size);
-
        if (!buf) {
                return NULL;
        }
 
-       ret = SMB_VFS_FGETXATTR(fsp, ACL_EA_ACCESS, buf, size);
+       ret = SMB_VFS_FGETXATTR(fsp, name, buf, size);
        if (ret < 0 && errno == ERANGE) {
-               size = SMB_VFS_FGETXATTR(fsp, ACL_EA_ACCESS, NULL, 0);
+               size = SMB_VFS_FGETXATTR(fsp, name, NULL, 0);
                if (size > 0) {
                        buf = alloca(size);
                        if (!buf) {
                                return NULL;
                        }
-                       ret = SMB_VFS_FGETXATTR(fsp, ACL_EA_ACCESS, buf, size);
+                       ret = SMB_VFS_FGETXATTR(fsp, name, buf, size);
                }
        }
 
@@ -443,28 +382,16 @@ SMB_ACL_T posixacl_xattr_acl_get_fd(vfs_handle_struct *handle,
        return NULL;
 }
 
-int posixacl_xattr_acl_set_file(vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname,
-                               SMB_ACL_TYPE_T type,
-                               SMB_ACL_T theacl)
+int posixacl_xattr_acl_set_fd(vfs_handle_struct *handle,
+                             files_struct *fsp,
+                             SMB_ACL_TYPE_T type,
+                             SMB_ACL_T theacl)
 {
-       const char *name;
+       const char *name = NULL;
        char *buf;
        ssize_t size;
        int ret;
 
-       size = smb_acl_to_posixacl_xattr(theacl, NULL, 0);
-       buf = alloca(size);
-       if (!buf) {
-               return -1;
-       }
-
-       ret = smb_acl_to_posixacl_xattr(theacl, buf, size);
-       if (ret < 0) {
-               errno = -ret;
-               return -1;
-       }
-
        if (type == SMB_ACL_TYPE_ACCESS) {
                name = ACL_EA_ACCESS;
        } else if (type == SMB_ACL_TYPE_DEFAULT) {
@@ -474,19 +401,6 @@ int posixacl_xattr_acl_set_file(vfs_handle_struct *handle,
                return -1;
        }
 
-       return SMB_VFS_SETXATTR(handle->conn, smb_fname,
-                       name, buf, size, 0);
-}
-
-int posixacl_xattr_acl_set_fd(vfs_handle_struct *handle,
-                             files_struct *fsp,
-                             SMB_ACL_TYPE_T type,
-                             SMB_ACL_T theacl)
-{
-       char *buf;
-       ssize_t size;
-       int ret;
-
        size = smb_acl_to_posixacl_xattr(theacl, NULL, 0);
        buf = alloca(size);
        if (!buf) {
@@ -499,13 +413,11 @@ int posixacl_xattr_acl_set_fd(vfs_handle_struct *handle,
                return -1;
        }
 
-       return SMB_VFS_FSETXATTR(fsp, ACL_EA_ACCESS, buf, size, 0);
+       return SMB_VFS_FSETXATTR(fsp, name, buf, size, 0);
 }
 
-int posixacl_xattr_acl_delete_def_file(vfs_handle_struct *handle,
-                               const struct smb_filename *smb_fname)
+int posixacl_xattr_acl_delete_def_fd(vfs_handle_struct *handle,
+                               files_struct *fsp)
 {
-       return SMB_VFS_REMOVEXATTR(handle->conn,
-                       smb_fname,
-                       ACL_EA_DEFAULT);
+       return SMB_VFS_FREMOVEXATTR(fsp, ACL_EA_DEFAULT);
 }