From: Volker Lendecke Date: Thu, 23 Oct 2025 18:11:35 +0000 (+0200) Subject: smbd: Make fsp_new() return a files_struct X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f150382db3bcb3cdcc222efac2691fa1a0fef1c2;p=thirdparty%2Fsamba.git smbd: Make fsp_new() return a files_struct There's only the ENOMEM failure condition Signed-off-by: Volker Lendecke Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/durable.c b/source3/smbd/durable.c index 69a83b593b4..fe6dd00b64a 100644 --- a/source3/smbd/durable.c +++ b/source3/smbd/durable.c @@ -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; diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 86b95169e58..cc6ae87fa5c 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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); diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 45e2b3f5109..cd1a9e08906 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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);