VFS: Modify chown to take a const struct smb_filename * instead of const char *
[kai/samba-autobuild/.git] / source3 / modules / vfs_fake_acls.c
index a6e01b061ef187c9a9cd908dee6229ef1bbf2206..cb907d0ca9875fabbb8c450c4622e2a4159b0385 100644 (file)
@@ -115,8 +115,16 @@ static int fake_acls_stat(vfs_handle_struct *handle,
        if (ret == 0) {
                TALLOC_CTX *frame = talloc_stackframe();
                char *path;
+               struct smb_filename smb_fname_base = {
+                       .base_name = smb_fname->base_name
+               };
                NTSTATUS status;
-               status = get_full_smb_filename(frame, smb_fname, &path);
+               /*
+                * As we're calling getxattr directly here
+                * we need to use only the base_name, not
+                * the full name containing any stream name.
+                */
+               status = get_full_smb_filename(frame, &smb_fname_base, &path);
                if (!NT_STATUS_IS_OK(status)) {
                        errno = map_errno_from_nt_status(status);
                        TALLOC_FREE(frame);
@@ -148,8 +156,16 @@ static int fake_acls_lstat(vfs_handle_struct *handle,
        if (ret == 0) {
                TALLOC_CTX *frame = talloc_stackframe();
                char *path;
+               struct smb_filename smb_fname_base = {
+                       .base_name = smb_fname->base_name
+               };
                NTSTATUS status;
-               status = get_full_smb_filename(frame, smb_fname, &path);
+               /*
+                * As we're calling getxattr directly here
+                * we need to use only the base_name, not
+                * the full name containing any stream name.
+                */
+               status = get_full_smb_filename(frame, &smb_fname_base, &path);
                if (!NT_STATUS_IS_OK(status)) {
                        errno = map_errno_from_nt_status(status);
                        TALLOC_FREE(frame);
@@ -299,71 +315,6 @@ static SMB_ACL_T fake_acls_sys_acl_get_fd(struct vfs_handle_struct *handle,
 }
 
 
-static int fake_acls_sys_acl_blob_get_file(struct vfs_handle_struct *handle, const char *path, SMB_ACL_TYPE_T type, TALLOC_CTX *mem_ctx, 
-                                          char **blob_description, DATA_BLOB *blob)
-{
-       ssize_t length;
-       const char *name = NULL;
-       switch (type) {
-       case SMB_ACL_TYPE_ACCESS:
-               name = FAKE_ACL_ACCESS_XATTR;
-               break;
-       case SMB_ACL_TYPE_DEFAULT:
-               name = FAKE_ACL_DEFAULT_XATTR;
-               break;
-       }
-
-       *blob_description = talloc_strdup(mem_ctx, "fake_acls");
-       if (!*blob_description) {
-               errno = ENOMEM;
-               return -1;
-       }
-
-       *blob = data_blob_null;
-       do {
-               blob->length += 1000;
-               blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length);
-               if (!blob->data) {
-                       errno = ENOMEM;
-                       return -1;
-               }
-               length = SMB_VFS_NEXT_GETXATTR(handle, path, name, blob->data, blob->length);
-               blob->length = length;
-       } while (length == -1 && errno == ERANGE);
-       if (length == -1) {
-               return -1;
-       }
-       return 0;
-}
-
-static int fake_acls_sys_acl_blob_get_fd(struct vfs_handle_struct *handle, files_struct *fsp, TALLOC_CTX *mem_ctx, 
-                                        char **blob_description, DATA_BLOB *blob)
-{
-       ssize_t length;
-       const char *name = FAKE_ACL_ACCESS_XATTR;
-               
-       *blob_description = talloc_strdup(mem_ctx, "fake_acls");
-       if (!*blob_description) {
-               errno = ENOMEM;
-               return -1;
-       }
-       *blob = data_blob_null;
-       do {
-               blob->length += 1000;
-               blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length);
-               if (!blob->data) {
-                       errno = ENOMEM;
-                       return -1;
-               }
-               length = SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, blob->data, blob->length);
-               blob->length = length;
-       } while (length == -1 && errno == ERANGE);
-       if (length == -1) {
-               return -1;
-       }
-       return 0;
-}
-
 static int fake_acls_sys_acl_set_file(vfs_handle_struct *handle, const char *path, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
 {
        int ret;
@@ -411,12 +362,12 @@ static int fake_acls_sys_acl_delete_def_file(vfs_handle_struct *handle, const ch
        int ret;
        const char *name = FAKE_ACL_DEFAULT_XATTR;
        TALLOC_CTX *frame = talloc_stackframe();
-       struct smb_filename *smb_fname = NULL;
-       NTSTATUS status = create_synthetic_smb_fname_split(frame, path, NULL,
-                                                 &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
+       struct smb_filename *smb_fname;
+
+       smb_fname = synthetic_smb_fname(frame, path, NULL, NULL);
+       if (smb_fname == NULL) {
                TALLOC_FREE(frame);
+               errno = ENOMEM;
                return -1;
        }
 
@@ -442,20 +393,33 @@ static int fake_acls_sys_acl_delete_def_file(vfs_handle_struct *handle, const ch
        return ret;
 }
 
-static int fake_acls_chown(vfs_handle_struct *handle,  const char *path, uid_t uid, gid_t gid)
+static int fake_acls_chown(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        int ret;
        uint8_t id_buf[4];
        if (uid != -1) {
                SIVAL(id_buf, 0, uid);
-               ret = SMB_VFS_NEXT_SETXATTR(handle, path, FAKE_UID, id_buf, sizeof(id_buf), 0);
+               ret = SMB_VFS_NEXT_SETXATTR(handle,
+                               smb_fname->base_name,
+                               FAKE_UID,
+                               id_buf,
+                               sizeof(id_buf),
+                               0);
                if (ret != 0) {
                        return ret;
                }
        }
        if (gid != -1) {
                SIVAL(id_buf, 0, gid);
-               ret = SMB_VFS_NEXT_SETXATTR(handle, path, FAKE_GID, id_buf, sizeof(id_buf), 0);
+               ret = SMB_VFS_NEXT_SETXATTR(handle,
+                               smb_fname->base_name,
+                               FAKE_GID,
+                               id_buf,
+                               sizeof(id_buf),
+                               0);
                if (ret != 0) {
                        return ret;
                }
@@ -463,7 +427,7 @@ static int fake_acls_chown(vfs_handle_struct *handle,  const char *path, uid_t u
        return 0;
 }
 
-static int fake_acls_lchown(vfs_handle_struct *handle,  const char *path, uid_t uid, gid_t gid)
+static int fake_acls_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
 {
        int ret;
        uint8_t id_buf[4];
@@ -520,8 +484,8 @@ static struct vfs_fn_pointers vfs_fake_acls_fns = {
        .fstat_fn = fake_acls_fstat,
        .sys_acl_get_file_fn = fake_acls_sys_acl_get_file,
        .sys_acl_get_fd_fn = fake_acls_sys_acl_get_fd,
-       .sys_acl_blob_get_file_fn = fake_acls_sys_acl_blob_get_file,
-       .sys_acl_blob_get_fd_fn = fake_acls_sys_acl_blob_get_fd,
+       .sys_acl_blob_get_file_fn = posix_sys_acl_blob_get_file,
+       .sys_acl_blob_get_fd_fn = posix_sys_acl_blob_get_fd,
        .sys_acl_set_file_fn = fake_acls_sys_acl_set_file,
        .sys_acl_set_fd_fn = fake_acls_sys_acl_set_fd,
        .sys_acl_delete_def_file_fn = fake_acls_sys_acl_delete_def_file,