I always had to look up the sequence of NULLs and 0s. Save lines.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Mon Nov 10 14:33:28 UTC 2025 on atb-devel-224
const struct smb_filename *in);
struct smb_filename *cp_smb_filename_nostream(TALLOC_CTX *mem_ctx,
const struct smb_filename *in);
+struct smb_filename *cp_smb_basename(TALLOC_CTX *mem_ctx, const char *fname);
bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname);
bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname);
bool is_named_stream(const struct smb_filename *smb_fname);
return cp_smb_filename(mem_ctx, &smb_fname_loc);
}
+struct smb_filename *cp_smb_basename(TALLOC_CTX *mem_ctx, const char *fname)
+{
+ return synthetic_smb_fname(mem_ctx, fname, NULL, NULL, 0, 0);
+}
+
/**
* Utility function used by VFS calls that must *NOT* operate
* on a stream filename, only the base_name.
{
const char *cwd = ceph_getcwd(handle->data);
DBG_DEBUG("[CEPH] getwd(%p) = %s\n", handle, cwd);
- return synthetic_smb_fname(ctx, cwd, NULL, NULL, 0, 0);
+ return cp_smb_basename(ctx, cwd);
}
static int strict_allocate_ftruncate(struct vfs_handle_struct *handle,
}
DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle, path, result);
- result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0, 0);
+ result_fname = cp_smb_basename(ctx, result);
TALLOC_FREE(result);
return result_fname;
}
cwd = config->ceph_getcwd_fn(config->mount);
DBG_DEBUG("[CEPH] getwd: handle=%p cwd=%s\n", handle, cwd);
END_PROFILE_X(syscall_getwd);
- return synthetic_smb_fname(ctx, cwd, NULL, NULL, 0, 0);
+ return cp_smb_basename(ctx, cwd);
}
static int strict_allocate_ftruncate(struct vfs_handle_struct *handle,
}
DBG_DEBUG("[CEPH] realpath(%p, %s) = %s\n", handle, path, result);
- result_fname = synthetic_smb_fname(ctx, result, NULL, NULL, 0, 0);
+ result_fname = cp_smb_basename(ctx, result);
TALLOC_FREE(result);
out:
END_PROFILE_X(syscall_realpath);
return -EINVAL;
}
- smb_fname = synthetic_smb_fname(tmp_ctx,
- snap_path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(tmp_ctx, snap_path);
if (smb_fname == NULL) {
return -ENOMEM;
}
goto err_out;
}
- smb_fname = synthetic_smb_fname(tmp_ctx,
- _converted_buf,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(tmp_ctx, _converted_buf);
if (smb_fname == NULL) {
ret = -ENOMEM;
goto err_out;
if (result == NULL) {
return NULL;
}
- smb_fname = synthetic_smb_fname(ctx,
- result,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(ctx, result);
/*
* sys_getwd() *always* returns malloced memory.
* We must free here to avoid leaks:
result = sys_realpath(smb_fname->base_name);
END_PROFILE_X(syscall_realpath);
if (result) {
- result_fname = synthetic_smb_fname(ctx,
- result,
- NULL,
- NULL,
- 0,
- 0);
+ result_fname = cp_smb_basename(ctx, result);
SAFE_FREE(result);
}
return result_fname;
}
}
- fname = synthetic_smb_fname(frame,
- fullpath,
- NULL,
- NULL,
- 0,
- 0);
+ fname = cp_smb_basename(frame, fullpath);
if (fname == NULL) {
- DBG_ERR("synthetic_smb_fname(%s) failed - %s\n",
- fullpath, strerror(errno));
+ DBG_ERR("cp_smb_basename(%s) failed - %s\n",
+ fullpath,
+ strerror(errno));
TALLOC_FREE(frame);
return -1;
}
goto out;
}
- smb_fname = synthetic_smb_fname(talloc_tos(),
- plist,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(talloc_tos(), plist);
if (smb_fname == NULL) {
ok = false;
goto out;
return false;
}
- bands_dir = synthetic_smb_fname(talloc_tos(),
- path,
- NULL,
- NULL,
- 0,
- 0);
+ bands_dir = cp_smb_basename(talloc_tos(), path);
TALLOC_FREE(path);
if (bands_dir == NULL) {
return false;
if (ret == NULL) {
return NULL;
}
- smb_fname = synthetic_smb_fname(ctx,
- ret,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(ctx, ret);
return smb_fname;
}
smb_fname->base_name,
resolved_path);
if (result != NULL) {
- result_fname = synthetic_smb_fname(ctx,
- result,
- NULL,
- NULL,
- 0,
- 0);
+ result_fname = cp_smb_basename(ctx, result);
}
SAFE_FREE(resolved_path);
DEBUG(5, ("recycle: creating new dir %s\n", new_dir));
- smb_fname = synthetic_smb_fname(talloc_tos(),
- new_dir,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(talloc_tos(), new_dir);
if (smb_fname == NULL) {
goto done;
}
const char *dname = NULL;
char *talloced = NULL;
NTSTATUS status;
- struct smb_filename *smb_fname = synthetic_smb_fname(talloc_tos(),
- fsp->conn->connectpath,
- NULL,
- NULL,
- 0,
- 0);
+ struct smb_filename *smb_fname = cp_smb_basename(
+ talloc_tos(), fsp->conn->connectpath);
if (smb_fname == NULL) {
errno = ENOMEM;
return -1;
dev_t dev;
char *p;
- smb_fname_cpath = synthetic_smb_fname(mem_ctx,
- handle->conn->connectpath,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname_cpath = cp_smb_basename(mem_ctx, handle->conn->connectpath);
if (smb_fname_cpath == NULL) {
errno = ENOMEM;
return NULL;
DBG_INFO("quarantine: creating new dir %s\n", new_dir);
- smb_fname = synthetic_smb_fname(talloc_tos(),
- new_dir,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(talloc_tos(), new_dir);
if (smb_fname == NULL) {
goto done;
}
/* getwd before chdir. See note 1b above. */
return SMB_VFS_NEXT_GETWD(handle, ctx);
}
- return synthetic_smb_fname(ctx,
- config->cwd,
- NULL,
- NULL,
- 0,
- 0);
+ return cp_smb_basename(ctx, config->cwd);
}
static struct smb_filename *widelinks_realpath(vfs_handle_struct *handle,
pathname,
resolved_pathname);
- smb_fname = synthetic_smb_fname(ctx,
- resolved_pathname,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(ctx, resolved_pathname);
TALLOC_FREE(pathname);
TALLOC_FREE(resolved_pathname);
return smb_fname;
TALLOC_CTX *frame = talloc_stackframe();
struct smb_filename *smb_fname;
- smb_fname = synthetic_smb_fname(frame,
- path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(frame, path);
if (smb_fname == NULL) {
TALLOC_FREE(frame);
errno = ENOMEM;
}
/* setup a full fsp */
- fsp->fsp_name = synthetic_smb_fname(fsp,
- pf->filename,
- NULL,
- NULL,
- 0,
- 0);
+ fsp->fsp_name = cp_smb_basename(fsp, pf->filename);
if (fsp->fsp_name == NULL) {
status = NT_STATUS_NO_MEMORY;
goto done;
goto out;
}
- smb_fname = synthetic_smb_fname(service,
- sc->sc_path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(service, sc->sc_path);
if (smb_fname == NULL) {
goto out;
}
if (conn->cwd_fsp == NULL) {
goto nomem;
}
- conn->cwd_fsp->fsp_name = synthetic_smb_fname(conn->cwd_fsp,
- ".",
- NULL,
- NULL,
- 0,
- 0);
+ conn->cwd_fsp->fsp_name = cp_smb_basename(conn->cwd_fsp, ".");
if (conn->cwd_fsp->fsp_name == NULL) {
goto nomem;
}
struct smb_filename *atname = NULL;
int ret;
- atname = synthetic_smb_fname(talloc_tos(),
- n,
- NULL,
- NULL,
- 0,
- 0);
+ atname = cp_smb_basename(talloc_tos(), n);
if (atname == NULL) {
TALLOC_FREE(talloced);
continue;
* few NULL checks, so make sure it's initialized with something. to
* be safe until an audit can be done.
*/
- fsp->fsp_name = synthetic_smb_fname(fsp,
- "",
- NULL,
- NULL,
- 0,
- 0);
+ fsp->fsp_name = cp_smb_basename(fsp, "");
if (fsp->fsp_name == NULL) {
file_free(NULL, fsp);
return NT_STATUS_NO_MEMORY;
goto out;
}
- smb_fname = synthetic_smb_fname(frame,
- path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(frame, path);
if (smb_fname == NULL) {
goto out;
}
return false;
}
- smb_fname = synthetic_smb_fname(frame,
- path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(frame, path);
if (smb_fname == NULL) {
TALLOC_FREE(frame);
errno = ENOMEM;
goto out;
}
- smb_fname = synthetic_smb_fname(frame,
- ".",
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(frame, ".");
if (smb_fname == NULL) {
goto out;
}
}
while ((dname = ReadDirName(dir_hnd, &talloced)) != NULL) {
- struct smb_filename *smb_dname =
- synthetic_smb_fname(frame,
- dname,
- NULL,
- NULL,
- 0,
- 0);
+ struct smb_filename *smb_dname = cp_smb_basename(frame, dname);
if (smb_dname == NULL) {
goto out;
}
goto out;
}
- smb_fname = synthetic_smb_fname(frame,
- ".",
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(frame, ".");
if (smb_fname == NULL) {
goto out;
}
TALLOC_FREE(talloced);
goto out;
}
- smb_dname = synthetic_smb_fname(talloc_tos(),
- dname,
- NULL,
- NULL,
- 0,
- 0);
+ smb_dname = cp_smb_basename(talloc_tos(), dname);
if (smb_dname == NULL) {
TALLOC_FREE(talloced);
goto out;
return NT_STATUS_NO_SUCH_USER;
}
- smb_fname_cwd = synthetic_smb_fname(talloc_tos(),
- ".",
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname_cwd = cp_smb_basename(talloc_tos(), ".");
if (smb_fname_cwd == NULL) {
return NT_STATUS_NO_MEMORY;
}
return NULL;
}
- smb_fname = synthetic_smb_fname(talloc_tos(),
- canonicalize_path(talloc_tos(),
- conn,
- fname),
- NULL,
- NULL,
- 0,
- 0);
-
+ smb_fname = cp_smb_basename(
+ talloc_tos(), canonicalize_path(talloc_tos(), conn, fname));
if (smb_fname == NULL) {
TALLOC_FREE(frame);
return NULL;
fsp->fsp_flags.can_lock = false;
fsp->access_mask = FILE_READ_DATA | FILE_WRITE_DATA;
- smb_fname = synthetic_smb_fname(talloc_tos(),
- name,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(talloc_tos(), name);
if (smb_fname == NULL) {
file_free(smb_req, fsp);
return NT_STATUS_NO_MEMORY;
* start as conn->connectpath.
*/
TALLOC_FREE(conn->cwd_fsp->fsp_name);
- conn->cwd_fsp->fsp_name = synthetic_smb_fname(conn,
- conn->connectpath,
- NULL,
- NULL,
- 0,
- 0);
+ conn->cwd_fsp->fsp_name = cp_smb_basename(conn, conn->connectpath);
if (conn->cwd_fsp->fsp_name == NULL) {
return false;
}
goto nocache;
}
- smb_fname_dot = synthetic_smb_fname(ctx,
- ".",
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname_dot = cp_smb_basename(ctx, ".");
if (smb_fname_dot == NULL) {
errno = ENOMEM;
goto out;
return NT_STATUS_NO_MEMORY;
}
- fsp->fsp_name = synthetic_smb_fname(fsp, ".", NULL, NULL, 0, 0);
+ fsp->fsp_name = cp_smb_basename(fsp, ".");
if (fsp->fsp_name == NULL) {
TALLOC_FREE(fsp);
return NT_STATUS_NO_MEMORY;
struct vfs_statvfs_struct statbuf = {};
int ret;
- smb_fname_cpath = synthetic_smb_fname(talloc_tos(),
- conn->connectpath,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname_cpath = cp_smb_basename(talloc_tos(), conn->connectpath);
if (smb_fname_cpath == NULL) {
return caps;
}
}
path = argv[1];
- smb_fname = synthetic_smb_fname(state.mem_ctx,
- path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(state.mem_ctx, path);
if (smb_fname == NULL) {
goto done;
}
}
}
- smb_fname = synthetic_smb_fname(state.mem_ctx,
- path,
- NULL,
- NULL,
- 0,
- 0);
+ smb_fname = cp_smb_basename(state.mem_ctx, path);
if (smb_fname == NULL) {
return false;
}