s3: VFS: Change SMB_VFS_LINK to use const struct smb_filename * instead of const...
authorJeremy Allison <jra@samba.org>
Fri, 2 Jun 2017 21:21:54 +0000 (14:21 -0700)
committerJeremy Allison <jra@samba.org>
Sun, 18 Jun 2017 00:49:25 +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>
17 files changed:
examples/VFS/skel_opaque.c
examples/VFS/skel_transparent.c
source3/include/vfs.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 7dd258f15287cde108ef2623d07dd950b8073837..371caef4818f43fff1ae2467be731302a44c7a51 100644 (file)
@@ -489,8 +489,9 @@ static int skel_vfs_readlink(vfs_handle_struct *handle, const char *path,
        return -1;
 }
 
-static int skel_link(vfs_handle_struct *handle, const char *oldpath,
-                    const char *newpath)
+static int skel_link(vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
        errno = ENOSYS;
        return -1;
index 5e66be49d425daac2880ce9ec0f15adf31a92f5a..bcd4a44e51da77bda330d50195ee2e90e959bddd 100644 (file)
@@ -581,10 +581,11 @@ static int skel_vfs_readlink(vfs_handle_struct *handle, const char *path,
        return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
 }
 
-static int skel_link(vfs_handle_struct *handle, const char *oldpath,
-                    const char *newpath)
+static int skel_link(vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
-       return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
+       return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
 }
 
 static int skel_mknod(vfs_handle_struct *handle,
index a0eca7730f93e9710e607d3c21b17308e32303d9..f54d9ea93b24d10cd6b8f0b70e2862880aab6f13 100644 (file)
                to const struct smb_filename * */
 /* Version 37 - Change get_quota from const char *
                to const struct smb_filename * */
+/* Version 37 - Change link from const char *
+               to const struct smb_filename * */
 
 #define SMB_VFS_INTERFACE_VERSION 37
 
@@ -739,7 +741,9 @@ struct vfs_fn_pointers {
        bool (*getlock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
        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 (*link_fn)(struct vfs_handle_struct *handle,
+                               const struct smb_filename *old_smb_fname,
+                               const struct smb_filename *new_smb_fname);
        int (*mknod_fn)(struct vfs_handle_struct *handle,
                                const struct smb_filename *smb_fname,
                                mode_t mode,
@@ -1241,8 +1245,9 @@ int smb_vfs_call_symlink(struct vfs_handle_struct *handle, const char *oldpath,
                         const char *newpath);
 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_link(struct vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname);
 int smb_vfs_call_mknod(struct vfs_handle_struct *handle,
                        const struct smb_filename *smb_fname,
                        mode_t mode,
index cfb02cbdf62dfe74ba781abe2b5614414d3f364e..7e89c0917f645c8a92eb54aa83646822b2058031 100644 (file)
@@ -504,16 +504,56 @@ static int cap_readlink(vfs_handle_struct *handle, const char *path,
        return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz);
 }
 
-static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
+static int cap_link(vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
-       char *capold = capencode(talloc_tos(), oldpath);
-       char *capnew = capencode(talloc_tos(), newpath);
+       char *capold = capencode(talloc_tos(), old_smb_fname->base_name);
+       char *capnew = capencode(talloc_tos(), new_smb_fname->base_name);
+       struct smb_filename *old_cap_smb_fname = NULL;
+       struct smb_filename *new_cap_smb_fname = NULL;
+       int saved_errno = 0;
+       int ret;
 
        if (!capold || !capnew) {
                errno = ENOMEM;
                return -1;
        }
-       return SMB_VFS_NEXT_LINK(handle, capold, capnew);
+       old_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capold,
+                                       NULL,
+                                       NULL,
+                                       old_smb_fname->flags);
+       if (old_cap_smb_fname == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               errno = ENOMEM;
+               return -1;
+       }
+       new_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       capnew,
+                                       NULL,
+                                       NULL,
+                                       new_smb_fname->flags);
+       if (new_cap_smb_fname == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               TALLOC_FREE(old_cap_smb_fname);
+               errno = ENOMEM;
+               return -1;
+       }
+       ret = SMB_VFS_NEXT_LINK(handle, old_cap_smb_fname, new_cap_smb_fname);
+       if (ret == -1) {
+               saved_errno = errno;
+       }
+       TALLOC_FREE(capold);
+       TALLOC_FREE(capnew);
+       TALLOC_FREE(old_cap_smb_fname);
+       TALLOC_FREE(new_cap_smb_fname);
+       if (saved_errno != 0) {
+               errno = saved_errno;
+       }
+       return ret;
 }
 
 static int cap_mknod(vfs_handle_struct *handle,
index 5f7440473dff29c7be3d3cb43a28eca15ccb7dc8..1d9bf13a28922ff396011c612ffd5b46055455d3 100644 (file)
@@ -1141,11 +1141,17 @@ static int cephwrap_readlink(struct vfs_handle_struct *handle,  const char *path
        WRAP_RETURN(result);
 }
 
-static int cephwrap_link(struct vfs_handle_struct *handle,  const char *oldpath, const char *newpath)
+static int cephwrap_link(struct vfs_handle_struct *handle,
+               const struct smb_filename *old_smb_fname,
+               const struct smb_filename *new_smb_fname)
 {
        int result = -1;
-       DBG_DEBUG("[CEPH] link(%p, %s, %s)\n", handle, oldpath, newpath);
-       result = ceph_link(handle->data, oldpath, newpath);
+       DBG_DEBUG("[CEPH] link(%p, %s, %s)\n", handle,
+                       old_smb_fname->base_name,
+                       new_smb_fname->base_name);
+       result = ceph_link(handle->data,
+                               old_smb_fname->base_name,
+                               new_smb_fname->base_name);
        DBG_DEBUG("[CEPH] link(...) = %d\n", result);
        WRAP_RETURN(result);
 }
index 664da956c7c66d24669135fdc3e588e1b458b44d..0aba405c374604f7b884262fec39141489fd02dd 100644 (file)
@@ -2436,12 +2436,14 @@ static int vfswrap_readlink(vfs_handle_struct *handle, const char *path, char *b
        return result;
 }
 
-static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
+static int vfswrap_link(vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
        int result;
 
        START_PROFILE(syscall_link);
-       result = link(oldpath, newpath);
+       result = link(old_smb_fname->base_name, new_smb_fname->base_name);
        END_PROFILE(syscall_link);
        return result;
 }
index 01cea1aaee495a1a8efb85e4591a304969a8467a..15ab13f859f6761c0aaf34c5927c51e3d05778f9 100644 (file)
@@ -1651,14 +1651,15 @@ static int smb_full_audit_readlink(vfs_handle_struct *handle,
 }
 
 static int smb_full_audit_link(vfs_handle_struct *handle,
-                     const char *oldpath, const char *newpath)
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
        int result;
 
-       result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
+       result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
 
        do_log(SMB_VFS_OP_LINK, (result >= 0), handle,
-              "%s|%s", oldpath, newpath);
+              "%s|%s", old_smb_fname->base_name, new_smb_fname->base_name);
 
        return result;
 }
index 3d28381eaf4b1599eda6c92642ea79471cd8c1ea..870983ea8fc5f247551ad8a9dab2f2eb2849b682 100644 (file)
@@ -1246,9 +1246,12 @@ static int vfs_gluster_readlink(struct vfs_handle_struct *handle,
 }
 
 static int vfs_gluster_link(struct vfs_handle_struct *handle,
-                           const char *oldpath, const char *newpath)
+                               const struct smb_filename *old_smb_fname,
+                               const struct smb_filename *new_smb_fname)
 {
-       return glfs_link(handle->data, oldpath, newpath);
+       return glfs_link(handle->data,
+                       old_smb_fname->base_name,
+                       new_smb_fname->base_name);
 }
 
 static int vfs_gluster_mknod(struct vfs_handle_struct *handle,
index 37b396a5bea8a8713c57e91f6bb2cbdedda1c2d4..2659b29c498e6f86cc2a0f6e2b13ce2e8f260ee4 100644 (file)
@@ -1807,43 +1807,37 @@ out:
  * Failure: set errno, return -1
  */
 static int mh_link(vfs_handle_struct *handle,
-               const char *oldpath,
-               const char *newpath)
+               const struct smb_filename *old_smb_fname,
+               const struct smb_filename *new_smb_fname)
 {
        int status;
-       char *oldClientPath;
-       char *newClientPath;
-       TALLOC_CTX *ctx;
+       struct smb_filename *oldclientFname = NULL;
+       struct smb_filename *newclientFname = NULL;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_link\n"));
-       if (!is_in_media_files(oldpath) && !is_in_media_files(newpath))
-       {
-               status = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
+       if (!is_in_media_files(old_smb_fname->base_name) &&
+                       !is_in_media_files(new_smb_fname->base_name)) {
+               status = SMB_VFS_NEXT_LINK(handle,
+                               old_smb_fname,
+                               new_smb_fname);
                goto out;
        }
 
-       oldClientPath = NULL;
-       newClientPath = NULL;
-       ctx = talloc_tos();
-
-       if ((status = alloc_get_client_path(handle, ctx,
-                               oldpath,
-                               &oldClientPath)))
-       {
+       if ((status = alloc_get_client_smb_fname(handle, talloc_tos(),
+                               old_smb_fname,
+                               &oldclientFname))) {
                goto err;
        }
-
-       if ((status = alloc_get_client_path(handle, ctx,
-                               newpath,
-                               &newClientPath)))
-       {
+       if ((status = alloc_get_client_smb_fname(handle, talloc_tos(),
+                               new_smb_fname,
+                               &newclientFname))) {
                goto err;
        }
 
-       status = SMB_VFS_NEXT_LINK(handle, oldClientPath, newClientPath);
+       status = SMB_VFS_NEXT_LINK(handle, oldclientFname, newclientFname);
 err:
-       TALLOC_FREE(newClientPath);
-       TALLOC_FREE(oldClientPath);
+       TALLOC_FREE(newclientFname);
+       TALLOC_FREE(oldclientFname);
 out:
        return status;
 }
index faacc4591463a04d0b0770fa5836e1ef2da8d610..5481eda0e254abff28f6172ef28e17883f9f155e 100644 (file)
@@ -1180,19 +1180,28 @@ static int shadow_copy2_symlink(vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_link(vfs_handle_struct *handle,
-                            const char *oldname, const char *newname)
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
        time_t timestamp_old = 0;
        time_t timestamp_new = 0;
        char *snappath_old = NULL;
        char *snappath_new = NULL;
 
-       if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, oldname,
-                                        &timestamp_old, NULL, &snappath_old)) {
+       if (!shadow_copy2_strip_snapshot_internal(talloc_tos(),
+                               handle,
+                               old_smb_fname->base_name,
+                               &timestamp_old,
+                               NULL,
+                               &snappath_old)) {
                return -1;
        }
-       if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, newname,
-                                        &timestamp_new, NULL, &snappath_new)) {
+       if (!shadow_copy2_strip_snapshot_internal(talloc_tos(),
+                               handle,
+                               new_smb_fname->base_name,
+                               &timestamp_new,
+                               NULL,
+                               &snappath_new)) {
                return -1;
        }
        if ((timestamp_old != 0) || (timestamp_new != 0)) {
@@ -1206,7 +1215,7 @@ static int shadow_copy2_link(vfs_handle_struct *handle,
                errno = EROFS;
                return -1;
        }
-       return SMB_VFS_NEXT_LINK(handle, oldname, newname);
+       return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
 }
 
 static int shadow_copy2_stat(vfs_handle_struct *handle,
index 41800bf7a3aca1ecd66cb6a930046ce7d1a6de23..ec0c680124ea69e67334070e8a7b00a5cadec721 100644 (file)
@@ -2057,23 +2057,31 @@ static int snapper_gmt_symlink(vfs_handle_struct *handle,
 }
 
 static int snapper_gmt_link(vfs_handle_struct *handle,
-                           const char *oldname, const char *newname)
+                               const struct smb_filename *old_smb_fname,
+                               const struct smb_filename *new_smb_fname)
 {
-       time_t timestamp_old, timestamp_new;
+       time_t timestamp_old = 0;
+       time_t timestamp_new = 0;
 
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, oldname,
-                                       &timestamp_old, NULL)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               old_smb_fname->base_name,
+                               &timestamp_old,
+                               NULL)) {
                return -1;
        }
-       if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, newname,
-                                       &timestamp_new, NULL)) {
+       if (!snapper_gmt_strip_snapshot(talloc_tos(),
+                               handle,
+                               new_smb_fname->base_name,
+                               &timestamp_new,
+                               NULL)) {
                return -1;
        }
        if ((timestamp_old != 0) || (timestamp_new != 0)) {
                errno = EROFS;
                return -1;
        }
-       return SMB_VFS_NEXT_LINK(handle, oldname, newname);
+       return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
 }
 
 static int snapper_gmt_stat(vfs_handle_struct *handle,
index 8c20af3bd06fb970943dcf9180f5faabf300e753..725bd1072e42833f774ebcef80b4843e1e3e04f9 100644 (file)
@@ -192,9 +192,22 @@ static int syncops_symlink(vfs_handle_struct *handle,
 }
 
 static int syncops_link(vfs_handle_struct *handle,
-                        const char *oldname, const char *newname)
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
-       SYNCOPS_NEXT(LINK, newname, (handle, oldname, newname));
+       int ret;
+       struct syncops_config_data *config;
+
+       SMB_VFS_HANDLE_GET_DATA(handle, config,
+                               struct syncops_config_data,
+                               return -1);
+
+       ret = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
+       if (ret == 0 && config->onmeta && !config->disable) {
+               syncops_two_names(old_smb_fname->base_name,
+                                 new_smb_fname->base_name);
+       }
+       return ret;
 }
 
 static int syncops_open(vfs_handle_struct *handle,
index ebfcb8df655e4ec3fb5c4d7c6874e60c5651c06b..f07bd29f5e349ffb117320c871db3be594089d16 100644 (file)
@@ -1461,19 +1461,21 @@ static int smb_time_audit_readlink(vfs_handle_struct *handle,
 }
 
 static int smb_time_audit_link(vfs_handle_struct *handle,
-                              const char *oldpath, const char *newpath)
+                               const struct smb_filename *old_smb_fname,
+                               const struct smb_filename *new_smb_fname)
 {
        int result;
        struct timespec ts1,ts2;
        double timediff;
 
        clock_gettime_mono(&ts1);
-       result = SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
+       result = SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
        clock_gettime_mono(&ts2);
        timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9;
 
        if (timediff > audit_timeout) {
-               smb_time_audit_log_fname("link", timediff, newpath);
+               smb_time_audit_log_fname("link", timediff,
+                       new_smb_fname->base_name);
        }
 
        return result;
index aa06ea361fac4b0018cbefcd047cb333d83215ce..aefe2b37ab1076ea42247d43c4215948a52709d6 100644 (file)
@@ -1379,35 +1379,35 @@ err:
 }
 
 static int um_link(vfs_handle_struct *handle,
-                  const char *oldpath,
-                  const char *newpath)
+                   const struct smb_filename *old_smb_fname,
+                   const struct smb_filename *new_smb_fname)
 {
        int status;
-       char *old_client_path = NULL;
-       char *new_client_path = NULL;
+       struct smb_filename *old_client_fname = NULL;
+       struct smb_filename *new_client_fname = NULL;
 
        DEBUG(10, ("Entering um_link\n"));
-       if (!is_in_media_files(oldpath) && !is_in_media_files(newpath)) {
-               return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
+       if (!is_in_media_files(old_smb_fname->base_name) &&
+                               !is_in_media_files(new_smb_fname->base_name)) {
+               return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
        }
 
-       status = alloc_get_client_path(handle, talloc_tos(),
-                                      oldpath, &old_client_path);
+       status = alloc_get_client_smb_fname(handle, talloc_tos(),
+                                           old_smb_fname, &old_client_fname);
        if (status != 0) {
                goto err;
        }
-
-       status = alloc_get_client_path(handle, talloc_tos(),
-                                      newpath, &new_client_path);
+       status = alloc_get_client_smb_fname(handle, talloc_tos(),
+                                           new_smb_fname, &new_client_fname);
        if (status != 0) {
                goto err;
        }
 
-       status = SMB_VFS_NEXT_LINK(handle, old_client_path, new_client_path);
+       status = SMB_VFS_NEXT_LINK(handle, old_client_fname, new_client_fname);
 
 err:
-       TALLOC_FREE(new_client_path);
-       TALLOC_FREE(old_client_path);
+       TALLOC_FREE(old_client_fname);
+       TALLOC_FREE(new_client_fname);
        return status;
 }
 
index 3e1cfa8ca968c9023e57b376fbc98a9cfcca00d2..33908f0e7e27fb4e3a7c7945cb16623bc55c5cb1 100644 (file)
@@ -6149,8 +6149,7 @@ NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
        DEBUG(10,("hardlink_internals: doing hard link %s -> %s\n",
                  smb_fname_old->base_name, smb_fname_new->base_name));
 
-       if (SMB_VFS_LINK(conn, smb_fname_old->base_name,
-                        smb_fname_new->base_name) != 0) {
+       if (SMB_VFS_LINK(conn, smb_fname_old, smb_fname_new) != 0) {
                status = map_nt_error_from_unix(errno);
                DEBUG(3,("hardlink_internals: Error %s hard link %s -> %s\n",
                         nt_errstr(status), smb_fname_old->base_name,
index 7177f882a0c0090ab1dbbe16e2237a384d70e0e4..c747bde5569110fa5df70a2c78a37229f562e248 100644 (file)
@@ -2165,11 +2165,12 @@ int smb_vfs_call_readlink(struct vfs_handle_struct *handle,
        return handle->fns->readlink_fn(handle, path, buf, bufsiz);
 }
 
-int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
-                     const char *newpath)
+int smb_vfs_call_link(struct vfs_handle_struct *handle,
+                       const struct smb_filename *old_smb_fname,
+                       const struct smb_filename *new_smb_fname)
 {
        VFS_FIND(link);
-       return handle->fns->link_fn(handle, oldpath, newpath);
+       return handle->fns->link_fn(handle, old_smb_fname, new_smb_fname);
 }
 
 int smb_vfs_call_mknod(struct vfs_handle_struct *handle,
index 8d7d2a7f17504eced18c6cf30cd88646d54ff2b3..38d87464c421017b366968a132e8448c2675e7fd 100644 (file)
@@ -1251,12 +1251,28 @@ static NTSTATUS cmd_readlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int arg
 
 static NTSTATUS cmd_link(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv)
 {
+       struct smb_filename *old_smb_fname = NULL;
+       struct smb_filename *new_smb_fname = NULL;
+
        if (argc != 3) {
                printf("Usage: link <path> <link>\n");
                return NT_STATUS_OK;
        }
 
-       if (SMB_VFS_LINK(vfs->conn, argv[1], argv[2]) == -1) {
+       old_smb_fname = synthetic_smb_fname_split(mem_ctx,
+                                       argv[1],
+                                       lp_posix_pathnames());
+       if (old_smb_fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       new_smb_fname = synthetic_smb_fname_split(mem_ctx,
+                                       argv[2],
+                                       lp_posix_pathnames());
+       if (new_smb_fname == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (SMB_VFS_LINK(vfs->conn, old_smb_fname, new_smb_fname) == -1) {
                printf("link: error=%d (%s)\n", errno, strerror(errno));
                return NT_STATUS_UNSUCCESSFUL;
        }