]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Make fsp_new() return a files_struct
authorVolker Lendecke <vl@samba.org>
Thu, 23 Oct 2025 18:11:35 +0000 (20:11 +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/files.c
source3/smbd/proto.h

index 69a83b593b497a839911b851895545f5fd84eab8..fe6dd00b64a9e22b0c85aae82f63bf2633fddc3e 100644 (file)
@@ -878,11 +878,10 @@ NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
        }
 
-       status = fsp_new(conn, conn, &state.fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_ERR("failed to create new fsp: %s\n",
-                       nt_errstr(status));
-               return status;
+       state.fsp = fsp_new(conn, conn);
+       if (state.fsp == NULL) {
+               DBG_ERR("failed to create new fsp\n");
+               return NT_STATUS_NO_MEMORY;
        }
        state.fsp->file_id = file_id;
        state.fsp->file_pid = smb1req->smbpid;
index 86b95169e58fadf7a01ca50269c9145f00ebfce0..cc6ae87fa5c662a5b835ae215cc320636819816b 100644 (file)
@@ -36,10 +36,9 @@ static bool fsp_attach_smb_fname(struct files_struct *fsp,
 /**
  * create new fsp to be used for file_new or a durable handle reconnect
  */
-NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
-                files_struct **result)
+struct files_struct *fsp_new(TALLOC_CTX *mem_ctx,
+                            struct connection_struct *conn)
 {
-       NTSTATUS status = NT_STATUS_NO_MEMORY;
        files_struct *fsp = NULL;
        struct smbd_server_connection *sconn = conn->sconn;
 
@@ -78,8 +77,7 @@ NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
        DBG_INFO("allocated files structure (%u used)\n",
                (unsigned int)sconn->num_files);
 
-       *result = fsp;
-       return NT_STATUS_OK;
+       return fsp;
 
 fail:
        if (fsp != NULL) {
@@ -87,7 +85,7 @@ fail:
        }
        TALLOC_FREE(fsp);
 
-       return status;
+       return NULL;
 }
 
 void fsp_set_gen_id(files_struct *fsp)
@@ -152,9 +150,9 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
        files_struct *fsp;
        NTSTATUS status;
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               return NT_STATUS_NO_MEMORY;
        }
 
        GetTimeOfDay(&fsp->open_time);
@@ -416,9 +414,9 @@ static NTSTATUS openat_pathref_fullname(
 
        SMB_ASSERT(smb_fname->fsp == NULL);
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               return NT_STATUS_NO_MEMORY;
        }
 
        GetTimeOfDay(&fsp->open_time);
@@ -594,9 +592,9 @@ NTSTATUS open_rootdir_pathref_fsp(connection_struct *conn,
        int fd;
        bool ok;
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               return NT_STATUS_NO_MEMORY;
        }
        GetTimeOfDay(&fsp->open_time);
        ZERO_STRUCT(conn->sconn->fsp_fi_cache);
@@ -674,9 +672,9 @@ NTSTATUS open_stream_pathref_fsp(
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               goto fail;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               goto nomem;
        }
 
        GetTimeOfDay(&fsp->open_time);
@@ -1074,10 +1072,10 @@ NTSTATUS openat_pathref_fsp_nosymlink(
 
        DBG_DEBUG("path_in=%s\n", path_in);
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("fsp_new() failed: %s\n", nt_errstr(status));
-               goto fail;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               DBG_DEBUG("fsp_new() failed\n");
+               goto nomem;
        }
 
        GetTimeOfDay(&fsp->open_time);
@@ -1392,11 +1390,10 @@ next:
                dirfsp = fsp;
 
                if (tmp == in_dirfsp) {
-                       status = fsp_new(conn, conn, &fsp);
-                       if (!NT_STATUS_IS_OK(status)) {
-                               DBG_DEBUG("fsp_new() failed: %s\n",
-                                         nt_errstr(status));
-                               goto fail;
+                       fsp = fsp_new(conn, conn);
+                       if (fsp == NULL) {
+                               DBG_DEBUG("fsp_new() failed\n");
+                               goto nomem;
                        }
                        fsp->fsp_name = &full_fname;
                } else {
@@ -1544,10 +1541,10 @@ NTSTATUS openat_pathref_fsp_lcomp(struct files_struct *dirfsp,
                return NT_STATUS_NETWORK_OPEN_RESTRICTION;
        }
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("fsp_new() failed: %s\n", nt_errstr(status));
-               return status;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               DBG_DEBUG("fsp_new() failed\n");
+               return NT_STATUS_NO_MEMORY;
        }
 
        GetTimeOfDay(&fsp->open_time);
@@ -1689,10 +1686,10 @@ NTSTATUS openat_pathref_fsp_dot(TALLOC_CTX *mem_ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       status = fsp_new(conn, conn, &fsp);
-       if (!NT_STATUS_IS_OK(status)) {
-               DBG_DEBUG("fsp_new() failed: %s\n", nt_errstr(status));
-               return status;
+       fsp = fsp_new(conn, conn);
+       if (fsp == NULL) {
+               DBG_DEBUG("fsp_new() failed\n");
+               return NT_STATUS_NO_MEMORY;
        }
 
        GetTimeOfDay(&fsp->open_time);
index 45e2b3f510931f3302a5269ee906f4c928f308b3..cd1a9e08906df28677f0195dc3aaf9a56ee9545e 100644 (file)
@@ -315,8 +315,8 @@ NTSTATUS get_real_filename_at(struct files_struct *dirfsp,
 
 /* The following definitions come from smbd/files.c  */
 
-NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
-                files_struct **result);
+struct files_struct *fsp_new(TALLOC_CTX *mem_ctx,
+                            struct connection_struct *conn);
 void fsp_set_gen_id(files_struct *fsp);
 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
                  files_struct **result);