s3: VFS: Change SMB_VFS_MKNOD to use const struct smb_filename * instead of const...
authorJeremy Allison <jra@samba.org>
Fri, 19 May 2017 22:01:52 +0000 (15:01 -0700)
committerJeremy Allison <jra@samba.org>
Sun, 18 Jun 2017 00:49:24 +0000 (02:49 +0200)
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>
18 files changed:
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.h
source3/include/vfs_macros.h
source3/modules/vfs_cap.c
source3/modules/vfs_ceph.c
source3/modules/vfs_default.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_glusterfs.c
source3/modules/vfs_media_harmony.c
source3/modules/vfs_shadow_copy2.c
source3/modules/vfs_snapper.c
source3/modules/vfs_syncops.c
source3/modules/vfs_time_audit.c
source3/modules/vfs_unityed_media.c
source3/smbd/trans2.c
source3/smbd/vfs.c
source3/torture/cmd_vfs.c

index c5d4359d8b2dc42d6cfca816813f91bdd4835b4d..ae0d4dc2b621da26fde90389a06429867ec6c2ce 100644 (file)
@@ -492,8 +492,10 @@ 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,
-                     SMB_DEV_T dev)
+static int skel_mknod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode,
+                       SMB_DEV_T dev)
 {
        errno = ENOSYS;
        return -1;
index 91ea5c6a6a774c438b161a7b81c85437091831aa..30f2b4e6f03641f8bab413ef7387d72dcecfc890 100644 (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,
-                     SMB_DEV_T dev)
+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)
index f7cfd3303190ade387dd5e77285a630b95580cc0..ec7f0d0a731d99bfaf1b6ad1bb679d0ceae9085c 100644 (file)
                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);
index 0ebd4698f48d08875a17de6c069c94cbb60b4f6e..30271a6fc3a30d4e24571fc09dcb6f24c73c99d9 100644 (file)
 #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))
index c124592af934cadb662239fa0cc215c1bf2d8b65..eba58961926f3d743a784bb014a24303957e802b 100644 (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)
index 428aa978e80ae27c4ca751f02400ef1a4b4d72c5..d88ceacee334ae6461abd172a99c722ba93607f1 100644 (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);
 }
index 5a4be7e216c674c8a1bcecb34215ffc941aabb56..6de5d641c3e1bf7bfde926b83f5dca4723c4be62 100644 (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;
 }
index fd8c8c14173ec5e8203313626f4664ed38d30725..af165dd4b697db23bec1aec8af1ccfd73f8003ec 100644 (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;
 }
index c6489732b756cdcd68db27ace1fadb4618369ba2..7c727773a6445db0f666b3be9c449eced06ef7e6 100644 (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,
index 422ca3dfcebe566a5c6baf37b06496cd342a14f6..99a5e9b6979bb74f3bf48ba56f48dece856678e0 100644 (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;
 }
index dba164efe0e221f0681f0cfa9c3a77d8d06bbd4e..1fb492ba71eb7aaf1bbbd8deaa121ba93a43d6f0 100644 (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);
index 2274a56a61ad3474758f1a51986376bdff65350b..61e7496f95ed0e885329010b60fd69694e44ec0d 100644 (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);
+       conv_smb_fname = cp_smb_filename(talloc_tos(), smb_fname);
+       if (conv_smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+       conv_smb_fname->base_name = snapper_gmt_convert(conv_smb_fname, handle,
+                                             stripped, timestamp);
        TALLOC_FREE(stripped);
-       if (conv == NULL) {
+       if (conv_smb_fname->base_name == NULL) {
                return -1;
        }
-       ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
-       saved_errno = errno;
-       TALLOC_FREE(conv);
-       errno = saved_errno;
+       ret = SMB_VFS_NEXT_MKNOD(handle, conv_smb_fname, mode, dev);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(conv_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
        return ret;
 }
 
index 381b80bf87e7735d77f4141e03758fcf7232aa9d..8c20af3bd06fb970943dcf9180f5faabf300e753 100644 (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,
index 761711b7423109acc08721210c59744b9de61371..3bbe2d961498ecc8e91cb05b23631041af62c2eb 100644 (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;
index 7c8bee05861818c8229d90efe9db6002f5e6f017..cda6ad635a8ac8f5a5810ea20246b959126bfb79 100644 (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;
 }
 
index a35297c25230f4bc3107a8d3a7a13e2d3fd75427..758644bc2304f526cebf9294e0ab959b1016aa62 100644 (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);
        }
 
index 9873f7fa2e551ad7b5a6e800033d42a11b84dfb1..b129bb1ce0539d45d93909f3ef681f55065a885f 100644 (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)
index 0e04a88b7e28206f5bcfe5dc748e596cc564e057..68def35277656399b07fed383f9ffbc779c1b17f 100644 (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;
        }