]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Make fsp_set_smb_fname() return bool
authorVolker Lendecke <vl@samba.org>
Thu, 23 Oct 2025 18:00:08 +0000 (20:00 +0200)
committerVolker Lendecke <vl@samba.org>
Mon, 17 Nov 2025 08:33:11 +0000 (08:33 +0000)
There's only the ENOMEM failure condition

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/smbd/durable.c
source3/smbd/fake_file.c
source3/smbd/files.c
source3/smbd/open.c
source3/smbd/proto.h
source3/smbd/smb1_utils.c
source3/smbd/smb2_pipes.c
source3/smbd/smb2_reply.c

index 57416e506ebbde8a04f0514745c407378d22777e..69a83b593b497a839911b851895545f5fd84eab8 100644 (file)
@@ -801,6 +801,7 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        struct file_id file_id;
        NTSTATUS status;
        enum ndr_err_code ndr_err;
+       bool ok;
 
        *result = NULL;
        *new_cookie = data_blob_null;
@@ -889,12 +890,11 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
        state.fsp->fnum = op->local_id;
        fh_set_gen_id(state.fsp->fh, op->global->open_global_id);
 
-       status = fsp_set_smb_fname(state.fsp, smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_ERR("fsp_set_smb_fname failed: %s\n",
-                         nt_errstr(status));
+       ok = fsp_set_smb_fname(state.fsp, smb_fname);
+       if (!ok) {
+               DBG_ERR("fsp_set_smb_fname failed\n");
                file_free(smb1req, state.fsp);
-               return status;
+               return NT_STATUS_NO_MEMORY;
        }
 
        /*
index 32f2595191f9586a888d260fcd54a945de9820a4..7e56181476963ed2d22c5747d08a599b3f31440b 100644 (file)
@@ -145,6 +145,7 @@ NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
                loadparm_s3_global_substitution();
        files_struct *fsp = NULL;
        NTSTATUS status;
+       bool ok;
 
        /* access check */
        if (geteuid() != sec_initial_uid()) {
@@ -172,8 +173,8 @@ NTSTATUS open_fake_file(struct smb_request *req, connection_struct *conn,
        fh_set_pos(fsp->fh, -1);
        fsp->fsp_flags.can_lock = false; /* Should this be true ? - No, JRA */
        fsp->access_mask = access_mask;
-       status = fsp_set_smb_fname(fsp, smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
+       ok = fsp_set_smb_fname(fsp, smb_fname);
+       if (!ok) {
                file_free(req, fsp);
                return NT_STATUS_NO_MEMORY;
        }
index 9737c26e33bf594aea4cf91559d2730c92ef738f..86b95169e58fadf7a01ca50269c9145f00ebfce0 100644 (file)
@@ -195,16 +195,17 @@ NTSTATUS create_internal_fsp(connection_struct *conn,
 {
        struct files_struct *fsp = NULL;
        NTSTATUS status;
+       bool ok;
 
        status = file_new(NULL, conn, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
-       status = fsp_set_smb_fname(fsp, smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
+       ok = fsp_set_smb_fname(fsp, smb_fname);
+       if (!ok) {
                file_free(NULL, fsp);
-               return status;
+               return NT_STATUS_NO_MEMORY;
        }
 
        *_fsp = fsp;
@@ -591,6 +592,7 @@ NTSTATUS open_rootdir_pathref_fsp(connection_struct *conn,
        struct files_struct *fsp = NULL;
        NTSTATUS status;
        int fd;
+       bool ok;
 
        status = fsp_new(conn, conn, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
@@ -600,8 +602,9 @@ NTSTATUS open_rootdir_pathref_fsp(connection_struct *conn,
        ZERO_STRUCT(conn->sconn->fsp_fi_cache);
        fsp->fsp_flags.is_pathref = true;
 
-       status = fsp_set_smb_fname(fsp, &slash);
-       if (!NT_STATUS_IS_OK(status)) {
+       ok = fsp_set_smb_fname(fsp, &slash);
+       if (!ok) {
+               status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
 
@@ -1417,11 +1420,10 @@ done:
        fsp->fsp_flags.is_pathref = true;
        fsp->fsp_name = NULL;
 
-       status = fsp_set_smb_fname(fsp, &full_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("fsp_set_smb_fname() failed: %s\n",
-                         nt_errstr(status));
-               goto fail;
+       ok = fsp_set_smb_fname(fsp, &full_fname);
+       if (!ok) {
+               DBG_DEBUG("fsp_set_smb_fname() failed\n");
+               goto nomem;
        }
 
        status = vfs_stat_fsp(fsp);
@@ -1604,11 +1606,11 @@ NTSTATUS openat_pathref_fsp_lcomp(struct files_struct *dirfsp,
                        return NT_STATUS_NO_MEMORY;
                }
 
-               status = fsp_set_smb_fname(fsp, &new_fullname);
-               if (!NT_STATUS_IS_OK(status)) {
+               ok = fsp_set_smb_fname(fsp, &new_fullname);
+               if (!ok) {
                        fd_close(fsp);
                        file_free(NULL, fsp);
-                       return status;
+                       return NT_STATUS_NO_MEMORY;
                }
        }
 
@@ -2587,8 +2589,8 @@ static bool fsp_attach_smb_fname(struct files_struct *fsp,
 /**
  * The only way that the fsp->fsp_name field should ever be set.
  */
-NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
-                          const struct smb_filename *smb_fname_in)
+bool fsp_set_smb_fname(struct files_struct *fsp,
+                      const struct smb_filename *smb_fname_in)
 {
        struct smb_filename *smb_fname_old = fsp->fsp_name;
        struct smb_filename *smb_fname_new = NULL;
@@ -2596,13 +2598,13 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
 
        smb_fname_new = cp_smb_filename(fsp, smb_fname_in);
        if (smb_fname_new == NULL) {
-               return NT_STATUS_NO_MEMORY;
+               return false;
        }
 
        ok = fsp_attach_smb_fname(fsp, &smb_fname_new);
        if (!ok) {
                TALLOC_FREE(smb_fname_new);
-               return NT_STATUS_NO_MEMORY;
+               return false;
        }
 
        if (smb_fname_old != NULL) {
@@ -2610,7 +2612,7 @@ NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
                TALLOC_FREE(smb_fname_old);
        }
 
-       return NT_STATUS_OK;
+       return true;
 }
 
 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen)
index c730adf11ad9fa3c845c4b26dc550af51175001c..26d305a97e98271a25e090019db2930a9507f4b5 100644 (file)
@@ -5326,7 +5326,8 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx,
 
        if (strcmp(fsp->conn->connectpath, msg->servicepath) == 0) {
                SMB_STRUCT_STAT fsp_orig_sbuf;
-               NTSTATUS status;
+               bool ok;
+
                DBG_DEBUG("renaming file %s from %s -> %s\n",
                          fsp_fnum_dbg(fsp),
                          fsp_str_dbg(fsp),
@@ -5349,10 +5350,9 @@ void msg_file_was_renamed(struct messaging_context *msg_ctx,
                 * any of this metadata to the client anyway.
                 */
                fsp_orig_sbuf = fsp->fsp_name->st;
-               status = fsp_set_smb_fname(fsp, smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DBG_DEBUG("fsp_set_smb_fname failed: %s\n",
-                                 nt_errstr(status));
+               ok = fsp_set_smb_fname(fsp, smb_fname);
+               if (!ok) {
+                       DBG_DEBUG("fsp_set_smb_fname failed\n");
                }
                fsp->fsp_name->st = fsp_orig_sbuf;
        } else {
@@ -6377,6 +6377,8 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                        file_free(NULL, tmp_base_fsp);
                }
        } else {
+               bool ok;
+
                /*
                 * No fsp passed in that we can use, create one
                 */
@@ -6386,9 +6388,9 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                }
                free_fsp_on_error = true;
 
-               status = fsp_set_smb_fname(fsp, smb_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       goto fail;
+               ok = fsp_set_smb_fname(fsp, smb_fname);
+               if (!ok) {
+                       goto nomem;
                }
        }
 
@@ -6415,6 +6417,8 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                        goto fail;
                }
        } else {
+               bool ok;
+
                /*
                 * Get a pathref on the parent. We can re-use this for
                 * multiple calls to check parent ACLs etc. to avoid
@@ -6430,9 +6434,9 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
                }
 
                dirfsp = parent_dir_fname->fsp;
-               status = fsp_set_smb_fname(dirfsp, parent_dir_fname);
-               if (!NT_STATUS_IS_OK(status)) {
-                       goto fail;
+               ok = fsp_set_smb_fname(dirfsp, parent_dir_fname);
+               if (!ok) {
+                       goto nomem;
                }
        }
 
@@ -6612,7 +6616,9 @@ static NTSTATUS create_file_unixpath(connection_struct *conn,
 
        return NT_STATUS_OK;
 
- fail:
+nomem:
+       status = NT_STATUS_NO_MEMORY;
+fail:
        DEBUG(10, ("create_file_unixpath: %s\n", nt_errstr(status)));
 
        if (fsp != NULL) {
index 1fee322dad65a8ba63202d1d15c1ad717b1c7723..45e2b3f510931f3302a5269ee906f4c928f308b3 100644 (file)
@@ -350,8 +350,8 @@ struct files_struct *file_fsp_get(struct smbd_smb2_request *smb2req,
 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
                                   uint64_t persistent_id,
                                   uint64_t volatile_id);
-NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
-                          const struct smb_filename *smb_fname_in);
+bool fsp_set_smb_fname(struct files_struct *fsp,
+                      const struct smb_filename *smb_fname_in);
 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen);
 void fsp_set_base_fsp(struct files_struct *fsp, struct files_struct *base_fsp);
 bool fsp_is_alternate_stream(const struct files_struct *fsp);
index 059f1bcc12a3f68c3cc056d807aea3f9f00b8b5d..5c45d526d05abf40df91ec79dfe688c615cb9310 100644 (file)
@@ -44,6 +44,7 @@ struct files_struct *fcb_or_dos_open(
        struct files_struct *fsp = NULL, *new_fsp = NULL;
        size_t new_refcount;
        NTSTATUS status;
+       bool ok;
 
        if ((private_flags &
             (NTCREATEX_FLAG_DENY_DOS|
@@ -125,10 +126,10 @@ struct files_struct *fcb_or_dos_open(
                new_fsp->fsp_flags.can_write = false;
        }
 
-       status = fsp_set_smb_fname(new_fsp, fsp->fsp_name);
+       ok = fsp_set_smb_fname(new_fsp, fsp->fsp_name);
 
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("fsp_set_smb_fname failed: %s\n", nt_errstr(status));
+       if (!ok) {
+               DBG_DEBUG("fsp_set_smb_fname failed\n");
                file_free(req, new_fsp);
                return NULL;
        }
index ef5acc2c2a8868b0e5dfe5b07513bfa7b0322657..5cdd10056b55803fac1dd53c3c47ef94fd751e84 100644 (file)
@@ -42,6 +42,7 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
        struct smb_filename *smb_fname = NULL;
        struct auth_session_info *session_info = conn->session_info;
        NTSTATUS status;
+       bool ok;
 
        status = file_new(smb_req, conn, &fsp);
        if (!NT_STATUS_IS_OK(status)) {
@@ -60,11 +61,11 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
                file_free(smb_req, fsp);
                return NT_STATUS_NO_MEMORY;
        }
-       status = fsp_set_smb_fname(fsp, smb_fname);
+       ok = fsp_set_smb_fname(fsp, smb_fname);
        TALLOC_FREE(smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
+       if (!ok) {
                file_free(smb_req, fsp);
-               return status;
+               return NT_STATUS_NO_MEMORY;
        }
 
        if (smb_req->smb2req != NULL && smb_req->smb2req->was_encrypted) {
@@ -74,7 +75,6 @@ NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
                uint16_t cipher = xconn->smb2.server.cipher;
                struct dom_sid smb3_sid = global_sid_Samba_SMB3;
                size_t num_smb3_sids;
-               bool ok;
 
                session_info = copy_session_info(fsp, conn->session_info);
                if (session_info == NULL) {
index 069d447b51c037b03681af3b7847a880b40597a3..4aef08e3e1e9f89a34ad99e63c84522494d4445a 100644 (file)
@@ -1185,13 +1185,14 @@ static void rename_open_files(connection_struct *conn,
 {
        files_struct *fsp;
        bool did_rename = False;
-       NTSTATUS status;
        uint32_t new_name_hash = 0;
 
        for(fsp = file_find_di_first(conn->sconn, id, false); fsp;
            fsp = file_find_di_next(fsp, false)) {
                SMB_STRUCT_STAT fsp_orig_sbuf;
                struct file_id_buf idbuf;
+               bool ok;
+
                /* fsp_name is a relative path under the fsp. To change this for other
                   sharepaths we need to manipulate relative paths. */
                /* TODO - create the absolute path and manipulate the newname
@@ -1221,8 +1222,8 @@ static void rename_open_files(connection_struct *conn,
                 * any of this metadata to the client anyway.
                 */
                fsp_orig_sbuf = fsp->fsp_name->st;
-               status = fsp_set_smb_fname(fsp, smb_fname_dst);
-               if (NT_STATUS_IS_OK(status)) {
+               ok = fsp_set_smb_fname(fsp, smb_fname_dst);
+               if (ok) {
                        did_rename = True;
                        new_name_hash = fsp->name_hash;
                        /* Restore existing stat. */