From: Volker Lendecke Date: Thu, 23 Oct 2025 18:00:08 +0000 (+0200) Subject: smbd: Make fsp_set_smb_fname() return bool X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e9dc025613d99e0f9922c621e07484838ace810;p=thirdparty%2Fsamba.git smbd: Make fsp_set_smb_fname() return bool 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 57416e506eb..69a83b593b4 100644 --- a/source3/smbd/durable.c +++ b/source3/smbd/durable.c @@ -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; } /* diff --git a/source3/smbd/fake_file.c b/source3/smbd/fake_file.c index 32f2595191f..7e561814769 100644 --- a/source3/smbd/fake_file.c +++ b/source3/smbd/fake_file.c @@ -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; } diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 9737c26e33b..86b95169e58 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -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) diff --git a/source3/smbd/open.c b/source3/smbd/open.c index c730adf11ad..26d305a97e9 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -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) { diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 1fee322dad6..45e2b3f5109 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -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); diff --git a/source3/smbd/smb1_utils.c b/source3/smbd/smb1_utils.c index 059f1bcc12a..5c45d526d05 100644 --- a/source3/smbd/smb1_utils.c +++ b/source3/smbd/smb1_utils.c @@ -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; } diff --git a/source3/smbd/smb2_pipes.c b/source3/smbd/smb2_pipes.c index ef5acc2c2a8..5cdd10056b5 100644 --- a/source3/smbd/smb2_pipes.c +++ b/source3/smbd/smb2_pipes.c @@ -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) { diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index 069d447b51c..4aef08e3e1e 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -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. */