From: Volker Lendecke Date: Tue, 28 Jan 2025 10:51:41 +0000 (+0100) Subject: lib: Convert string_replace_allocate() to return 0/errno X-Git-Tag: tdb-1.4.13~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8293a0b4f176d5398a1b0c78071a8db398feff0;p=thirdparty%2Fsamba.git lib: Convert string_replace_allocate() to return 0/errno This is only used in the VFS, which is still in large parts errno-based. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c index a669f05ce49..78544fecd96 100644 --- a/source3/lib/adouble.c +++ b/source3/lib/adouble.c @@ -1185,16 +1185,15 @@ static bool ad_convert_xattr(vfs_handle_struct *handle, files_struct *fsp = NULL; ssize_t nwritten; - status = string_replace_allocate(handle->conn, - e->adx_name, - string_replace_cmaps, - talloc_tos(), - &mapped_name, - vfs_translate_to_windows); - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) - { - DBG_ERR("string_replace_allocate failed\n"); + rc = string_replace_allocate(handle->conn, + e->adx_name, + string_replace_cmaps, + talloc_tos(), + &mapped_name, + vfs_translate_to_windows); + if (rc != 0) { + DBG_ERR("string_replace_allocate failed: %s\n", + strerror(rc)); ok = false; goto fail; } @@ -1746,6 +1745,7 @@ static bool ad_collect_one_stream(struct vfs_handle_struct *handle, ssize_t nread; NTSTATUS status; bool ok; + int rc; sname = synthetic_smb_fname(ad, smb_fname->base_name, @@ -1901,16 +1901,14 @@ static bool ad_collect_one_stream(struct vfs_handle_struct *handle, *p = '\0'; } - status = string_replace_allocate(handle->conn, - e->adx_name, - cmaps, - ad, - &mapped_name, - vfs_translate_to_unix); - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) - { - DBG_ERR("string_replace_allocate failed\n"); + rc = string_replace_allocate(handle->conn, + e->adx_name, + cmaps, + ad, + &mapped_name, + vfs_translate_to_unix); + if (rc != 0) { + DBG_ERR("string_replace_allocate failed: %s\n", strerror(rc)); ok = false; goto out; } diff --git a/source3/lib/string_replace.c b/source3/lib/string_replace.c index f66f5488667..fb0f599efef 100644 --- a/source3/lib/string_replace.c +++ b/source3/lib/string_replace.c @@ -135,12 +135,12 @@ struct char_mappings **string_replace_init_map(TALLOC_CTX *mem_ctx, return cmaps; } -NTSTATUS string_replace_allocate(connection_struct *conn, - const char *name_in, - struct char_mappings **cmaps, - TALLOC_CTX *mem_ctx, - char **mapped_name, - enum vfs_translate_direction direction) +int string_replace_allocate(connection_struct *conn, + const char *name_in, + struct char_mappings **cmaps, + TALLOC_CTX *mem_ctx, + char **mapped_name, + enum vfs_translate_direction direction) { static smb_ucs2_t *tmpbuf = NULL; smb_ucs2_t *ptr = NULL; @@ -151,7 +151,7 @@ NTSTATUS string_replace_allocate(connection_struct *conn, ok = push_ucs2_talloc(talloc_tos(), &tmpbuf, name_in, &converted_size); if (!ok) { - return map_nt_error_from_unix(errno); + return errno; } for (ptr = tmpbuf; *ptr; ptr++) { @@ -172,11 +172,15 @@ NTSTATUS string_replace_allocate(connection_struct *conn, ok = pull_ucs2_talloc(mem_ctx, mapped_name, tmpbuf, &converted_size); - TALLOC_FREE(tmpbuf); + { + int err = errno; + TALLOC_FREE(tmpbuf); + errno = err; + } if (!ok) { - return map_nt_error_from_unix(errno); + return errno; } - return NT_STATUS_OK; + return 0; } const char *macos_string_replace_map = diff --git a/source3/lib/string_replace.h b/source3/lib/string_replace.h index 012b1aa8f2e..671dbf87852 100644 --- a/source3/lib/string_replace.h +++ b/source3/lib/string_replace.h @@ -25,11 +25,11 @@ struct char_mappings; struct char_mappings **string_replace_init_map(TALLOC_CTX *mem_ctx, const char **mappings); -NTSTATUS string_replace_allocate(connection_struct *conn, - const char *name_in, - struct char_mappings **cmaps, - TALLOC_CTX *mem_ctx, - char **mapped_name, - enum vfs_translate_direction direction); +int string_replace_allocate(connection_struct *conn, + const char *name_in, + struct char_mappings **cmaps, + TALLOC_CTX *mem_ctx, + char **mapped_name, + enum vfs_translate_direction direction); extern const char *macos_string_replace_map; diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 935d978d7a3..0b6b0aa01f3 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -137,7 +137,7 @@ static NTSTATUS catia_string_replace_allocate(connection_struct *conn, enum vfs_translate_direction direction) { struct share_mapping_entry *selected; - NTSTATUS status; + int ret; if (!init_mappings(conn, &selected)) { /* No mappings found. Just use the old name */ @@ -149,13 +149,16 @@ static NTSTATUS catia_string_replace_allocate(connection_struct *conn, return NT_STATUS_OK; } - status = string_replace_allocate(conn, - name_in, - selected->mappings, - talloc_tos(), - mapped_name, - direction); - return status; + ret = string_replace_allocate(conn, + name_in, + selected->mappings, + talloc_tos(), + mapped_name, + direction); + if (ret != 0) { + return map_nt_error_from_unix(ret); + } + return NT_STATUS_OK; } static int catia_connect(struct vfs_handle_struct *handle,