1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

s3: VFS: Change SMB_VFS_MKNOD to use const struct smb_filename * instead of const char *.

We need to migrate all pathname based VFS calls to use a struct
to finish modernising the VFS with extra timestamp and flags parameters.

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Richard Sharpe <realrichardsharpe@gmail.com>
This commit is contained in:
Jeremy Allison 2017-05-19 15:01:52 -07:00
parent fed54ca01d
commit c3d45216dd
18 changed files with 154 additions and 76 deletions

View File

@ -492,7 +492,9 @@ static int skel_link(vfs_handle_struct *handle, const char *oldpath,
return -1;
}
static int skel_mknod(vfs_handle_struct *handle, const char *path, mode_t mode,
static int skel_mknod(vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
errno = ENOSYS;

View File

@ -583,10 +583,12 @@ static int skel_link(vfs_handle_struct *handle, const char *oldpath,
return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
}
static int skel_mknod(vfs_handle_struct *handle, const char *path, mode_t mode,
static int skel_mknod(vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
}
static char *skel_realpath(vfs_handle_struct *handle, const char *path)

View File

@ -213,6 +213,7 @@
to const struct smb_filename * */
/* Version 37 - Change getxattr from const char *
to const struct smb_filename * */
/* Version 37 - Change mknod from const char * to const struct smb_filename * */
#define SMB_VFS_INTERFACE_VERSION 37
@ -728,7 +729,10 @@ struct vfs_fn_pointers {
int (*symlink_fn)(struct vfs_handle_struct *handle, const char *oldpath, const char *newpath);
int (*readlink_fn)(struct vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz);
int (*link_fn)(struct vfs_handle_struct *handle, const char *oldpath, const char *newpath);
int (*mknod_fn)(struct vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev);
int (*mknod_fn)(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev);
char *(*realpath_fn)(struct vfs_handle_struct *handle, const char *path);
int (*chflags_fn)(struct vfs_handle_struct *handle, const char *path, unsigned int flags);
struct file_id (*file_id_create_fn)(struct vfs_handle_struct *handle,
@ -1222,8 +1226,10 @@ int smb_vfs_call_readlink(struct vfs_handle_struct *handle,
const char *path, char *buf, size_t bufsiz);
int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
const char *newpath);
int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
mode_t mode, SMB_DEV_T dev);
int smb_vfs_call_mknod(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev);
char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path);
int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
unsigned int flags);

View File

@ -326,10 +326,10 @@
#define SMB_VFS_NEXT_LINK(handle, oldpath, newpath) \
smb_vfs_call_link((handle)->next, (oldpath), (newpath))
#define SMB_VFS_MKNOD(conn, path, mode, dev) \
smb_vfs_call_mknod((conn)->vfs_handles, (path), (mode), (dev))
#define SMB_VFS_NEXT_MKNOD(handle, path, mode, dev) \
smb_vfs_call_mknod((handle)->next, (path), (mode), (dev))
#define SMB_VFS_MKNOD(conn, smb_fname, mode, dev) \
smb_vfs_call_mknod((conn)->vfs_handles, (smb_fname), (mode), (dev))
#define SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev) \
smb_vfs_call_mknod((handle)->next, (smb_fname), (mode), (dev))
#define SMB_VFS_REALPATH(conn, path) \
smb_vfs_call_realpath((conn)->vfs_handles, (path))

View File

@ -488,15 +488,40 @@ static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *
return SMB_VFS_NEXT_LINK(handle, capold, capnew);
}
static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev)
static int cap_mknod(vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
char *cappath = capencode(talloc_tos(), path);
struct smb_filename *cap_smb_fname = NULL;
char *cappath = capencode(talloc_tos(), smb_fname->base_name);
int ret;
int saved_errno = 0;
if (!cappath) {
errno = ENOMEM;
return -1;
}
return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
cap_smb_fname = synthetic_smb_fname(talloc_tos(),
cappath,
NULL,
NULL,
smb_fname->flags);
if (cap_smb_fname == NULL) {
TALLOC_FREE(cappath);
errno = ENOMEM;
return -1;
}
ret = SMB_VFS_NEXT_MKNOD(handle, cap_smb_fname, mode, dev);
if (ret == -1) {
saved_errno = errno;
}
TALLOC_FREE(cappath);
TALLOC_FREE(cap_smb_fname);
if (saved_errno != 0) {
errno = saved_errno;
}
return ret;
}
static char *cap_realpath(vfs_handle_struct *handle, const char *path)

View File

@ -1145,11 +1145,14 @@ static int cephwrap_link(struct vfs_handle_struct *handle, const char *oldpath,
WRAP_RETURN(result);
}
static int cephwrap_mknod(struct vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev)
static int cephwrap_mknod(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int result = -1;
DBG_DEBUG("[CEPH] mknod(%p, %s)\n", handle, pathname);
result = ceph_mknod(handle->data, pathname, mode, dev);
DBG_DEBUG("[CEPH] mknod(%p, %s)\n", handle, smb_fname->base_name);
result = ceph_mknod(handle->data, smb_fname->base_name, mode, dev);
DBG_DEBUG("[CEPH] mknod(...) = %d\n", result);
WRAP_RETURN(result);
}

View File

@ -2442,12 +2442,15 @@ static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const ch
return result;
}
static int vfswrap_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev)
static int vfswrap_mknod(vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int result;
START_PROFILE(syscall_mknod);
result = sys_mknod(pathname, mode, dev);
result = sys_mknod(smb_fname->base_name, mode, dev);
END_PROFILE(syscall_mknod);
return result;
}

View File

@ -1659,13 +1659,16 @@ static int smb_full_audit_link(vfs_handle_struct *handle,
}
static int smb_full_audit_mknod(vfs_handle_struct *handle,
const char *pathname, mode_t mode, SMB_DEV_T dev)
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int result;
result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s", pathname);
do_log(SMB_VFS_OP_MKNOD, (result >= 0), handle, "%s",
smb_fname->base_name);
return result;
}

View File

@ -1248,10 +1248,12 @@ static int vfs_gluster_link(struct vfs_handle_struct *handle,
return glfs_link(handle->data, oldpath, newpath);
}
static int vfs_gluster_mknod(struct vfs_handle_struct *handle, const char *path,
mode_t mode, SMB_DEV_T dev)
static int vfs_gluster_mknod(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
return glfs_mknod(handle->data, path, mode, dev);
return glfs_mknod(handle->data, smb_fname->base_name, mode, dev);
}
static int vfs_gluster_chflags(struct vfs_handle_struct *handle,

View File

@ -1853,34 +1853,31 @@ out:
* Failure: set errno, return -1
*/
static int mh_mknod(vfs_handle_struct *handle,
const char *pathname,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int status;
char *clientPath;
struct smb_filename *clientFname = NULL;
TALLOC_CTX *ctx;
DEBUG(MH_INFO_DEBUG, ("Entering mh_mknod\n"));
if (!is_in_media_files(pathname))
{
status = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
if (!is_in_media_files(smb_fname->base_name)) {
status = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
goto out;
}
clientPath = NULL;
ctx = talloc_tos();
if ((status = alloc_get_client_path(handle, ctx,
pathname,
&clientPath)))
{
if ((status = alloc_get_client_smb_fname(handle, ctx,
smb_fname,
&clientFname))) {
goto err;
}
status = SMB_VFS_NEXT_MKNOD(handle, clientPath, mode, dev);
status = SMB_VFS_NEXT_MKNOD(handle, clientFname, mode, dev);
err:
TALLOC_FREE(clientPath);
TALLOC_FREE(clientFname);
out:
return status;
}

View File

@ -1656,24 +1656,33 @@ static int shadow_copy2_readlink(vfs_handle_struct *handle,
}
static int shadow_copy2_mknod(vfs_handle_struct *handle,
const char *fname, mode_t mode, SMB_DEV_T dev)
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
time_t timestamp = 0;
char *stripped = NULL;
int saved_errno = 0;
int ret;
char *conv;
struct smb_filename *conv = NULL;
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
smb_fname->base_name,
&timestamp, &stripped)) {
return -1;
}
if (timestamp == 0) {
return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
}
conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
TALLOC_FREE(stripped);
conv = cp_smb_filename(talloc_tos(), smb_fname);
if (conv == NULL) {
errno = ENOMEM;
return -1;
}
conv->base_name = shadow_copy2_convert(
conv, handle, stripped, timestamp);
TALLOC_FREE(stripped);
if (conv->base_name == NULL) {
return -1;
}
ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);

View File

@ -2417,29 +2417,42 @@ static int snapper_gmt_readlink(vfs_handle_struct *handle,
}
static int snapper_gmt_mknod(vfs_handle_struct *handle,
const char *fname, mode_t mode, SMB_DEV_T dev)
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
time_t timestamp;
char *stripped;
int ret, saved_errno;
char *conv;
time_t timestamp = (time_t)0;
char *stripped = NULL;
int ret, saved_errno = 0;
struct smb_filename *conv_smb_fname = NULL;
if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname,
if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
smb_fname->base_name,
&timestamp, &stripped)) {
return -1;
}
if (timestamp == 0) {
return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
}
conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
TALLOC_FREE(stripped);
if (conv == NULL) {
conv_smb_fname = cp_smb_filename(talloc_tos(), smb_fname);
if (conv_smb_fname == NULL) {
errno = ENOMEM;
return -1;
}
ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
conv_smb_fname->base_name = snapper_gmt_convert(conv_smb_fname, handle,
stripped, timestamp);
TALLOC_FREE(stripped);
if (conv_smb_fname->base_name == NULL) {
return -1;
}
ret = SMB_VFS_NEXT_MKNOD(handle, conv_smb_fname, mode, dev);
if (ret == -1) {
saved_errno = errno;
TALLOC_FREE(conv);
}
TALLOC_FREE(conv_smb_fname);
if (saved_errno != 0) {
errno = saved_errno;
}
return ret;
}

View File

@ -212,9 +212,12 @@ static int syncops_unlink(vfs_handle_struct *handle,
}
static int syncops_mknod(vfs_handle_struct *handle,
const char *fname, mode_t mode, SMB_DEV_T dev)
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
SYNCOPS_NEXT(MKNOD, fname, (handle, fname, mode, dev));
SYNCOPS_NEXT_SMB_FNAME(MKNOD,
smb_fname, (handle, smb_fname, mode, dev));
}
static int syncops_mkdir(vfs_handle_struct *handle,

View File

@ -1472,7 +1472,8 @@ static int smb_time_audit_link(vfs_handle_struct *handle,
}
static int smb_time_audit_mknod(vfs_handle_struct *handle,
const char *pathname, mode_t mode,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int result;
@ -1480,12 +1481,12 @@ static int smb_time_audit_mknod(vfs_handle_struct *handle,
double timediff;
clock_gettime_mono(&ts1);
result = SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
result = SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
clock_gettime_mono(&ts2);
timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
if (timediff > audit_timeout) {
smb_time_audit_log_fname("mknod", timediff, pathname);
smb_time_audit_log_smb_fname("mknod", timediff, smb_fname);
}
return result;

View File

@ -1412,28 +1412,28 @@ err:
}
static int um_mknod(vfs_handle_struct *handle,
const char *pathname,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
int status;
char *client_path = NULL;
struct smb_filename *client_fname = NULL;
DEBUG(10, ("Entering um_mknod\n"));
if (!is_in_media_files(pathname)) {
return SMB_VFS_NEXT_MKNOD(handle, pathname, mode, dev);
if (!is_in_media_files(smb_fname->base_name)) {
return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
}
status = alloc_get_client_path(handle, talloc_tos(),
pathname, &client_path);
status = alloc_get_client_smb_fname(handle, talloc_tos(),
smb_fname, &client_fname);
if (status != 0) {
goto err;
}
status = SMB_VFS_NEXT_MKNOD(handle, client_path, mode, dev);
status = SMB_VFS_NEXT_MKNOD(handle, client_fname, mode, dev);
err:
TALLOC_FREE(client_path);
TALLOC_FREE(client_fname);
return status;
}

View File

@ -7580,7 +7580,7 @@ static NTSTATUS smb_unix_mknod(connection_struct *conn,
(unsigned int)unixmode, smb_fname_str_dbg(smb_fname)));
/* Ok - do the mknod. */
if (SMB_VFS_MKNOD(conn, smb_fname->base_name, unixmode, dev) != 0) {
if (SMB_VFS_MKNOD(conn, smb_fname, unixmode, dev) != 0) {
return map_nt_error_from_unix(errno);
}

View File

@ -2167,11 +2167,13 @@ int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
return handle->fns->link_fn(handle, oldpath, newpath);
}
int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
mode_t mode, SMB_DEV_T dev)
int smb_vfs_call_mknod(struct vfs_handle_struct *handle,
const struct smb_filename *smb_fname,
mode_t mode,
SMB_DEV_T dev)
{
VFS_FIND(mknod);
return handle->fns->mknod_fn(handle, path, mode, dev);
return handle->fns->mknod_fn(handle, smb_fname, mode, dev);
}
char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path)

View File

@ -1260,6 +1260,7 @@ static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
mode_t mode;
unsigned int dev_val;
SMB_DEV_T dev;
struct smb_filename *smb_fname = NULL;
if (argc != 4) {
printf("Usage: mknod <path> <mode> <dev>\n");
@ -1279,7 +1280,13 @@ static NTSTATUS cmd_mknod(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc,
}
dev = (SMB_DEV_T)dev_val;
if (SMB_VFS_MKNOD(vfs->conn, argv[1], mode, dev) == -1) {
smb_fname = synthetic_smb_fname_split(mem_ctx,
argv[1],
lp_posix_pathnames());
if (smb_fname == NULL) {
return NT_STATUS_NO_MEMORY;
}
if (SMB_VFS_MKNOD(vfs->conn, smb_fname, mode, dev) == -1) {
printf("mknod: error=%d (%s)\n", errno, strerror(errno));
return NT_STATUS_UNSUCCESSFUL;
}