smbd: vfs: convert link_contents arg of SMB_VFS_SYMLINKAT() to struct smb_filename
authorRalph Boehme <slow@samba.org>
Thu, 30 Apr 2020 17:30:50 +0000 (19:30 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 5 May 2020 19:18:41 +0000 (19:18 +0000)
Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
19 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_ceph_snapshots.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_not_implemented.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 bab1d34469cd3cff689ee9aa1f0dc28246a2784f..cc3aa7eae6ba7f02e64ead44fe2efb4ef154fa8e 100644 (file)
@@ -462,7 +462,7 @@ static bool skel_getlock(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 static int skel_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
index 92f9e8a8123e3bd5b091381012137d3feb77012c..235d4533df33753a1882a260ed141f1222a12153 100644 (file)
@@ -587,7 +587,7 @@ static bool skel_getlock(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 static int skel_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
index 5e4190adc307ce8ebc506301f8977d67a2b392f0..3e133a58f434ac15cf53877b2835c1ec275590ea 100644 (file)
  *              changed to bitfields.
  * Version 43 - convert SMB_VFS_GET_REAL_FILENAME() arg path
  *              to be a struct smb_filename
+ * Version 43 - convert link_contents arg of SMB_VFS_SYMLINKAT()
+ *              to struct smb_filename
  */
 
 #define SMB_VFS_INTERFACE_VERSION 43
@@ -843,7 +845,7 @@ struct vfs_fn_pointers {
        int (*linux_setlease_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, int leasetype);
        bool (*getlock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
        int (*symlinkat_fn)(struct vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname);
        int (*readlinkat_fn)(struct vfs_handle_struct *handle,
@@ -1384,7 +1386,7 @@ bool smb_vfs_call_getlock(struct vfs_handle_struct *handle,
                          struct files_struct *fsp, off_t *poffset,
                          off_t *pcount, int *ptype, pid_t *ppid);
 int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname);
 int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle,
@@ -1824,7 +1826,7 @@ bool vfs_not_implemented_getlock(vfs_handle_struct *handle, files_struct *fsp,
                                 off_t *poffset, off_t *pcount, int *ptype,
                                 pid_t *ppid);
 int vfs_not_implemented_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname);
 int vfs_not_implemented_vfs_readlinkat(vfs_handle_struct *handle,
index 03f73f5b658a85ad5bf74bfa17688801132f884c..ab84c3143cc57398d093be101088ba12da8b24b1 100644 (file)
@@ -440,12 +440,13 @@ static int cap_ntimes(vfs_handle_struct *handle,
 }
 
 static int cap_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
-       char *capold = capencode(talloc_tos(), link_contents);
+       char *capold = capencode(talloc_tos(), link_contents->base_name);
        char *capnew = capencode(talloc_tos(), new_smb_fname->base_name);
+       struct smb_filename *new_link_target = NULL;
        struct smb_filename *new_cap_smb_fname = NULL;
        int saved_errno = 0;
        int ret;
@@ -454,6 +455,20 @@ static int cap_symlinkat(vfs_handle_struct *handle,
                errno = ENOMEM;
                return -1;
        }
+
+       new_link_target = synthetic_smb_fname(talloc_tos(),
+                                             capold,
+                                             NULL,
+                                             NULL,
+                                             new_smb_fname->twrp,
+                                             new_smb_fname->flags);
+       if (new_link_target == NULL) {
+               TALLOC_FREE(capold);
+               TALLOC_FREE(capnew);
+               errno = ENOMEM;
+               return -1;
+       }
+
        new_cap_smb_fname = synthetic_smb_fname(talloc_tos(),
                                        capnew,
                                        NULL,
@@ -463,11 +478,12 @@ static int cap_symlinkat(vfs_handle_struct *handle,
        if (new_cap_smb_fname == NULL) {
                TALLOC_FREE(capold);
                TALLOC_FREE(capnew);
+               TALLOC_FREE(new_link_target);
                errno = ENOMEM;
                return -1;
        }
        ret = SMB_VFS_NEXT_SYMLINKAT(handle,
-                       capold,
+                       new_link_target,
                        dirfsp,
                        new_cap_smb_fname);
        if (ret == -1) {
@@ -475,6 +491,7 @@ static int cap_symlinkat(vfs_handle_struct *handle,
        }
        TALLOC_FREE(capold);
        TALLOC_FREE(capnew);
+       TALLOC_FREE(new_link_target);
        TALLOC_FREE(new_cap_smb_fname);
        if (saved_errno != 0) {
                errno = saved_errno;
index 5bc8f37a87d76f0221204627788552a977dc8011..d28b48e648d5a50eec3385c1f07ddcda9958ea31 100644 (file)
@@ -1014,19 +1014,19 @@ static int cephwrap_linux_setlease(struct vfs_handle_struct *handle, files_struc
 }
 
 static int cephwrap_symlinkat(struct vfs_handle_struct *handle,
-               const char *link_target,
+               const struct smb_filename *link_target,
                struct files_struct *dirfsp,
                const struct smb_filename *new_smb_fname)
 {
        int result = -1;
        DBG_DEBUG("[CEPH] symlink(%p, %s, %s)\n", handle,
-                       link_target,
+                       link_target->base_name,
                        new_smb_fname->base_name);
 
        SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
 
        result = ceph_symlink(handle->data,
-                       link_target,
+                       link_target->base_name,
                        new_smb_fname->base_name);
        DBG_DEBUG("[CEPH] symlink(...) = %d\n", result);
        WRAP_RETURN(result);
index 4472f9717a1f22b8455cd386e23fc96d960318b2..e75c0bd87cedc6cf55a0c98ce88f0b4b3652c4a8 100644 (file)
@@ -772,7 +772,7 @@ static int ceph_snap_gmt_renameat(vfs_handle_struct *handle,
 
 /* block links from writeable shares to snapshots for now, like other modules */
 static int ceph_snap_gmt_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
@@ -781,7 +781,7 @@ static int ceph_snap_gmt_symlinkat(vfs_handle_struct *handle,
        time_t timestamp_new = 0;
 
        ret = ceph_snap_gmt_strip_snapshot(handle,
-                               link_contents,
+                               link_contents->base_name,
                                &timestamp_old,
                                NULL, 0);
        if (ret < 0) {
index 578eb34180ae59e4c230269f0a18256665ff5844..2ac2a9953b1129811ddc0f67abf14b5766505e57 100644 (file)
@@ -2835,7 +2835,7 @@ static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 static int vfswrap_symlinkat(vfs_handle_struct *handle,
-                       const char *link_target,
+                       const struct smb_filename *link_target,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
@@ -2845,7 +2845,7 @@ static int vfswrap_symlinkat(vfs_handle_struct *handle,
 
        SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
 
-       result = symlinkat(link_target,
+       result = symlinkat(link_target->base_name,
                        dirfsp->fh->fd,
                        new_smb_fname->base_name);
        END_PROFILE(syscall_symlinkat);
index fad8a14e24535aae4273d2481d1071c8f25b7b64..b7edf3c13a32fc48a59f3dd6f561e1c4f3bc7bc4 100644 (file)
@@ -1787,7 +1787,7 @@ static bool smb_full_audit_getlock(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
@@ -1802,7 +1802,7 @@ static int smb_full_audit_symlinkat(vfs_handle_struct *handle,
               (result >= 0),
               handle,
               "%s|%s",
-              link_contents,
+              link_contents->base_name,
               smb_fname_str_do_log(handle->conn, new_smb_fname));
 
        return result;
index d8f39bd9a969799173a7ce2d0fc46a30d67643b3..c1124ec108d7e334dba693c01de8c2fc1c3bba23 100644 (file)
@@ -1672,7 +1672,7 @@ static bool vfs_gluster_getlock(struct vfs_handle_struct *handle,
 }
 
 static int vfs_gluster_symlinkat(struct vfs_handle_struct *handle,
-                               const char *link_target,
+                               const struct smb_filename *link_target,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
@@ -1681,7 +1681,7 @@ static int vfs_gluster_symlinkat(struct vfs_handle_struct *handle,
        START_PROFILE(syscall_symlinkat);
        SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp);
        ret = glfs_symlink(handle->data,
-                       link_target,
+                       link_target->base_name,
                        new_smb_fname->base_name);
        END_PROFILE(syscall_symlinkat);
 
index 4c5d98f917032bc32b118c33e7c54ef7d1f0c5dc..f07ebdd6c3d7846d2fbab80814dccccb89fc1972 100644 (file)
@@ -1600,16 +1600,16 @@ out:
  */
 
 static int mh_symlinkat(vfs_handle_struct *handle,
-               const char *link_contents,
+               const struct smb_filename *link_contents,
                struct files_struct *dirfsp,
                const struct smb_filename *new_smb_fname)
 {
        int status = -1;
-       char *client_link_contents = NULL;
+       struct smb_filename *new_link_target = NULL;
        struct smb_filename *newclientFname = NULL;
 
        DEBUG(MH_INFO_DEBUG, ("Entering mh_symlinkat\n"));
-       if (!is_in_media_files(link_contents) &&
+       if (!is_in_media_files(link_contents->base_name) &&
                        !is_in_media_files(new_smb_fname->base_name)) {
                status = SMB_VFS_NEXT_SYMLINKAT(handle,
                                link_contents,
@@ -1618,9 +1618,9 @@ static int mh_symlinkat(vfs_handle_struct *handle,
                goto out;
        }
 
-       if ((status = alloc_get_client_path(handle, talloc_tos(),
+       if ((status = alloc_get_client_smb_fname(handle, talloc_tos(),
                                link_contents,
-                               &client_link_contents))) {
+                               &new_link_target))) {
                goto err;
        }
        if ((status = alloc_get_client_smb_fname(handle, talloc_tos(),
@@ -1630,11 +1630,11 @@ static int mh_symlinkat(vfs_handle_struct *handle,
        }
 
        status = SMB_VFS_NEXT_SYMLINKAT(handle,
-                               client_link_contents,
+                               new_link_target,
                                dirfsp,
                                newclientFname);
 err:
-       TALLOC_FREE(client_link_contents);
+       TALLOC_FREE(new_link_target);
        TALLOC_FREE(newclientFname);
 out:
        return status;
index f5cd002d897a0a3e3f09a32889390a3d77f4c9a2..d734502c7f8aa93016284b0ac879076a71e8b095 100644 (file)
@@ -461,7 +461,7 @@ bool vfs_not_implemented_getlock(vfs_handle_struct *handle, files_struct *fsp,
 }
 
 int vfs_not_implemented_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
index f405c8a80e203e1438bb68bda5a9301e6b30be12..207347c217cc4994278c65128af1611f1a64cf59 100644 (file)
@@ -1137,7 +1137,7 @@ static int shadow_copy2_renameat(vfs_handle_struct *handle,
 }
 
 static int shadow_copy2_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
@@ -1148,7 +1148,7 @@ static int shadow_copy2_symlinkat(vfs_handle_struct *handle,
 
        if (!shadow_copy2_strip_snapshot_internal(talloc_tos(),
                                handle,
-                               link_contents,
+                               link_contents->base_name,
                                &timestamp_old,
                                NULL,
                                &snappath_old,
index b98289b90eb610315e038ef63a3d4aab8952bcc6..0c240e83ce2206b9117ce4b3fec40c5c0c885166 100644 (file)
@@ -1997,7 +1997,7 @@ static int snapper_gmt_renameat(vfs_handle_struct *handle,
 }
 
 static int snapper_gmt_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
@@ -2006,7 +2006,7 @@ static int snapper_gmt_symlinkat(vfs_handle_struct *handle,
 
        if (!snapper_gmt_strip_snapshot(talloc_tos(),
                                handle,
-                               link_contents,
+                               link_contents->base_name,
                                &timestamp_old,
                                NULL)) {
                return -1;
index f375c359d6fdfbd649382d57a321d324743ee6dc..2c4c386e23f28074633a4bb678ebf9c9581647a8 100644 (file)
@@ -167,7 +167,7 @@ static int syncops_renameat(vfs_handle_struct *handle,
 } while (0)
 
 static int syncops_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
@@ -184,7 +184,7 @@ static int syncops_symlinkat(vfs_handle_struct *handle,
                                new_smb_fname);
 
        if (ret == 0 && config->onmeta && !config->disable) {
-               syncops_two_names(link_contents,
+               syncops_two_names(link_contents->base_name,
                                  new_smb_fname->base_name);
        }
        return ret;
index 8b7be9660c44cf2ac3a1b97be6f2549158751d8a..ee1d0341c7f946cafceaf3cea9235cb09b444629 100644 (file)
@@ -1403,7 +1403,7 @@ static bool smb_time_audit_getlock(vfs_handle_struct *handle,
 }
 
 static int smb_time_audit_symlinkat(vfs_handle_struct *handle,
-                               const char *link_contents,
+                               const struct smb_filename *link_contents,
                                struct files_struct *dirfsp,
                                const struct smb_filename *new_smb_fname)
 {
index 98c6a9eab95ebe179e3cd160a26e85f219cdddb5..56d1ff3451f2574438854c39cb5d23a858dbe8ec 100644 (file)
@@ -1234,17 +1234,17 @@ err:
 }
 
 static int um_symlinkat(vfs_handle_struct *handle,
-                       const char *link_contents,
+                       const struct smb_filename *link_contents,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
        int status;
-       char *client_link_contents = NULL;
+       struct smb_filename *new_link_target = NULL;
        struct smb_filename *new_client_fname = NULL;
 
        DEBUG(10, ("Entering um_symlinkat\n"));
 
-       if (!is_in_media_files(link_contents) &&
+       if (!is_in_media_files(link_contents->base_name) &&
                        !is_in_media_files(new_smb_fname->base_name)) {
                return SMB_VFS_NEXT_SYMLINKAT(handle,
                                link_contents,
@@ -1252,8 +1252,8 @@ static int um_symlinkat(vfs_handle_struct *handle,
                                new_smb_fname);
        }
 
-       status = alloc_get_client_path(handle, talloc_tos(),
-                               link_contents, &client_link_contents);
+       status = alloc_get_client_smb_fname(handle, talloc_tos(),
+                               link_contents, &new_link_target);
        if (status != 0) {
                goto err;
        }
@@ -1264,12 +1264,12 @@ static int um_symlinkat(vfs_handle_struct *handle,
        }
 
        status = SMB_VFS_NEXT_SYMLINKAT(handle,
-                                       client_link_contents,
+                                       new_link_target,
                                        dirfsp,
                                        new_client_fname);
 
 err:
-       TALLOC_FREE(client_link_contents);
+       TALLOC_FREE(new_link_target);
        TALLOC_FREE(new_client_fname);
        return status;
 }
index fa77cb4c6e0c646c3298276be4e55dd567819ddd..0af680e327f055c2b2ea45adad3d6d7d96098401 100644 (file)
@@ -7019,7 +7019,7 @@ static NTSTATUS smb_set_file_unix_link(connection_struct *conn,
                        new_smb_fname->base_name, link_target ));
 
        ret = SMB_VFS_SYMLINKAT(conn,
-                       target_fname.base_name,
+                       &target_fname,
                        conn->cwd_fsp,
                        new_smb_fname);
        if (ret != 0) {
index 89180e46e1e7d529cdc3edb5cc6264e225e24b2a..5bc3911b4e07386d4cbdf7cb93a4d5494003310c 100644 (file)
@@ -2135,7 +2135,7 @@ int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
 }
 
 int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle,
-                       const char *link_target,
+                       const struct smb_filename *link_target,
                        struct files_struct *dirfsp,
                        const struct smb_filename *new_smb_fname)
 {
index e33c886388315398090d5c16f92cbc63a5253874..ab0e451e77b30a491039afa6d97eb75048a9c2f1 100644 (file)
@@ -1178,7 +1178,7 @@ static NTSTATUS cmd_symlink(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc
        }
 
        ret = SMB_VFS_SYMLINKAT(vfs->conn,
-                       target_fname.base_name,
+                       &target_fname,
                        vfs->conn->cwd_fsp,
                        new_smb_fname);
        if (ret == -1) {