From: Volker Lendecke Date: Wed, 9 Oct 2024 09:07:11 +0000 (+0200) Subject: smbd: Convert get_ea_value_fsp() to return 0/errno X-Git-Tag: tdb-1.4.13~545 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7430831f8831a9a6eee83376c10027ca7cb449d6;p=thirdparty%2Fsamba.git smbd: Convert get_ea_value_fsp() to return 0/errno Avoid a map_errno_from_nt_status() Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c index 4cc69b42a8a..572bd2960ba 100644 --- a/source3/modules/vfs_streams_xattr.c +++ b/source3/modules/vfs_streams_xattr.c @@ -48,15 +48,12 @@ struct stream_io { static ssize_t get_xattr_size_fsp(struct files_struct *fsp, const char *xattr_name) { - NTSTATUS status; + int ret; struct ea_struct ea; ssize_t result; - status = get_ea_value_fsp(talloc_tos(), - fsp, - xattr_name, - &ea); - if (!NT_STATUS_IS_OK(status)) { + ret = get_ea_value_fsp(talloc_tos(), fsp, xattr_name, &ea); + if (ret != 0) { return -1; } @@ -352,12 +349,11 @@ static int streams_xattr_openat(struct vfs_handle_struct *handle, goto fail; } - status = get_ea_value_fsp(talloc_tos(), - fsp->base_fsp, - xattr_name, - &ea); - - DBG_DEBUG("get_ea_value_fsp returned %s\n", nt_errstr(status)); + ret = get_ea_value_fsp(talloc_tos(), fsp->base_fsp, xattr_name, &ea); + if (ret != 0) { + DBG_DEBUG("get_ea_value_fsp returned %s\n", strerror(ret)); + status = map_nt_error_from_unix(ret); + } if (!NT_STATUS_IS_OK(status)) { if (!NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) { @@ -629,12 +625,12 @@ static int streams_xattr_renameat(vfs_handle_struct *handle, } /* Read the old stream from the base file fsp. */ - status = get_ea_value_fsp(talloc_tos(), - pathref_src->fsp, - src_xattr_name, - &ea); - if (!NT_STATUS_IS_OK(status)) { - errno = map_errno_from_nt_status(status); + ret = get_ea_value_fsp(talloc_tos(), + pathref_src->fsp, + src_xattr_name, + &ea); + if (ret != 0) { + errno = ret; goto fail; } @@ -716,6 +712,7 @@ static NTSTATUS walk_xattr_streams(vfs_handle_struct *handle, for (i=0; ifsp, - names[i], - &ea); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(10, ("Could not get ea %s for file %s: %s\n", - names[i], - smb_fname->base_name, - nt_errstr(status))); + ret = get_ea_value_fsp(names, smb_fname->fsp, names[i], &ea); + if (ret != 0) { + DBG_DEBUG("Could not get ea %s for file %s: %s\n", + names[i], + smb_fname->base_name, + strerror(ret)); continue; } @@ -922,7 +916,6 @@ static ssize_t streams_xattr_pwrite(vfs_handle_struct *handle, struct stream_io *sio = (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp); struct ea_struct ea; - NTSTATUS status; int ret; DEBUG(10, ("streams_xattr_pwrite called for %d bytes\n", (int)n)); @@ -956,11 +949,12 @@ static ssize_t streams_xattr_pwrite(vfs_handle_struct *handle, return -1; } - status = get_ea_value_fsp(talloc_tos(), - fsp->base_fsp, - sio->xattr_name, - &ea); - if (!NT_STATUS_IS_OK(status)) { + ret = get_ea_value_fsp(talloc_tos(), + fsp->base_fsp, + sio->xattr_name, + &ea); + if (ret != 0) { + errno = ret; return -1; } @@ -1003,7 +997,7 @@ static ssize_t streams_xattr_pread(vfs_handle_struct *handle, struct stream_io *sio = (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp); struct ea_struct ea; - NTSTATUS status; + int ret; size_t length, overlap; DEBUG(10, ("streams_xattr_pread: offset=%d, size=%d\n", @@ -1017,11 +1011,12 @@ static ssize_t streams_xattr_pread(vfs_handle_struct *handle, return -1; } - status = get_ea_value_fsp(talloc_tos(), - fsp->base_fsp, - sio->xattr_name, - &ea); - if (!NT_STATUS_IS_OK(status)) { + ret = get_ea_value_fsp(talloc_tos(), + fsp->base_fsp, + sio->xattr_name, + &ea); + if (ret != 0) { + errno = ret; return -1; } @@ -1209,7 +1204,6 @@ static int streams_xattr_ftruncate(struct vfs_handle_struct *handle, int ret; uint8_t *tmp; struct ea_struct ea; - NTSTATUS status; struct stream_io *sio = (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp); @@ -1224,11 +1218,12 @@ static int streams_xattr_ftruncate(struct vfs_handle_struct *handle, return -1; } - status = get_ea_value_fsp(talloc_tos(), - fsp->base_fsp, - sio->xattr_name, - &ea); - if (!NT_STATUS_IS_OK(status)) { + ret = get_ea_value_fsp(talloc_tos(), + fsp->base_fsp, + sio->xattr_name, + &ea); + if (ret != 0) { + errno = ret; return -1; } diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index d9a771960aa..5791d21d8b1 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1066,10 +1066,10 @@ NTSTATUS check_any_access_fsp(struct files_struct *fsp, uint32_t access_requested); uint64_t smb_roundup(connection_struct *conn, uint64_t val); bool samba_private_attr_name(const char *unix_ea_name); -NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, - files_struct *fsp, - const char *ea_name, - struct ea_struct *pea); +int get_ea_value_fsp(TALLOC_CTX *mem_ctx, + files_struct *fsp, + const char *ea_name, + struct ea_struct *pea); NTSTATUS get_ea_names_from_fsp(TALLOC_CTX *mem_ctx, files_struct *fsp, char ***pnames, diff --git a/source3/smbd/smb2_trans2.c b/source3/smbd/smb2_trans2.c index c9bd4c25e47..442515af377 100644 --- a/source3/smbd/smb2_trans2.c +++ b/source3/smbd/smb2_trans2.c @@ -184,10 +184,10 @@ bool samba_private_attr_name(const char *unix_ea_name) Get one EA value. Fill in a struct ea_struct. ****************************************************************************/ -NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, - files_struct *fsp, - const char *ea_name, - struct ea_struct *pea) +int get_ea_value_fsp(TALLOC_CTX *mem_ctx, + files_struct *fsp, + const char *ea_name, + struct ea_struct *pea) { /* Get the value of this xattr. Max size is 64k. */ size_t attr_size = 256; @@ -197,11 +197,11 @@ NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, bool refuse; if (fsp == NULL) { - return NT_STATUS_INVALID_HANDLE; + return EINVAL; } refuse = refuse_symlink_fsp(fsp); if (refuse) { - return NT_STATUS_ACCESS_DENIED; + return EACCES; } max_xattr_size = lp_smbd_max_xattr_size(SNUM(fsp->conn)); @@ -210,7 +210,7 @@ NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, val = talloc_realloc(mem_ctx, val, char, attr_size); if (!val) { - return NT_STATUS_NO_MEMORY; + return ENOMEM; } sizeret = SMB_VFS_FGETXATTR(fsp, ea_name, val, attr_size); @@ -220,7 +220,7 @@ NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, } if (sizeret == -1) { - return map_nt_error_from_unix(errno); + return errno; } DBG_DEBUG("EA %s is of length %zd\n", ea_name, sizeret); @@ -234,11 +234,11 @@ NTSTATUS get_ea_value_fsp(TALLOC_CTX *mem_ctx, } if (pea->name == NULL) { TALLOC_FREE(val); - return NT_STATUS_NO_MEMORY; + return ENOMEM; } pea->value.data = (unsigned char *)val; pea->value.length = (size_t)sizeret; - return NT_STATUS_OK; + return 0; } NTSTATUS get_ea_names_from_fsp(TALLOC_CTX *mem_ctx, @@ -410,6 +410,7 @@ static NTSTATUS get_ea_list_from_fsp(TALLOC_CTX *mem_ctx, for (i=0; iea); + ret = get_ea_value_fsp(listp, fsp, names[i], &listp->ea); - if (!NT_STATUS_IS_OK(status)) { + if (ret != 0) { TALLOC_FREE(listp); - return status; + return map_nt_error_from_unix(ret); } if (listp->ea.value.length == 0) {