]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Convert string_replace_allocate() to return 0/errno
authorVolker Lendecke <vl@samba.org>
Tue, 28 Jan 2025 10:51:41 +0000 (11:51 +0100)
committerJeremy Allison <jra@samba.org>
Wed, 5 Feb 2025 00:07:30 +0000 (00:07 +0000)
This is only used in the VFS, which is still in large parts
errno-based.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/adouble.c
source3/lib/string_replace.c
source3/lib/string_replace.h
source3/modules/vfs_catia.c

index a669f05ce497e494cf3b557e2d99ce365bed4905..78544fecd960add6a5f6851d26c57a8ceb52d3cb 100644 (file)
@@ -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;
        }
index f66f5488667cd07b639db53d96055b3d0b1f2601..fb0f599efef21ee55ab87d6170fd53454e76bc89 100644 (file)
@@ -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 =
index 012b1aa8f2ee2b4bd3ce28ef13b91c7a258f3e40..671dbf87852859097f36ddafe8720d119d88d2e8 100644 (file)
@@ -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;
index 935d978d7a303bae680f5750c77950c75764e6b3..0b6b0aa01f378c6e8a6f809cf4822f5ca300f0aa 100644 (file)
@@ -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,