From b9e00c047357237f0f90dc46b08a09c6aa33350f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 14:42:49 -0800 Subject: [PATCH 01/23] s3: VFS: Implement create_dfs_pathat() in catia. Now we use this instead of symlinks to create DFS links, it's needed in catia. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit fa2f83e13aa92a12bd8d0113576a04a1e4431a44) --- source3/modules/vfs_catia.c | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 23246c72be2..1739fd77d5b 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -2365,6 +2365,45 @@ static NTSTATUS catia_set_dos_attributes(struct vfs_handle_struct *handle, return status; } +static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + const struct referral *reflist, + size_t referral_count) +{ + char *mapped_name = NULL; + const char *path = smb_fname->base_name; + struct smb_filename *mapped_smb_fname = NULL; + NTSTATUS status; + + status = catia_string_replace_allocate(handle->conn, + path, + &mapped_name, + vfs_translate_to_unix); + if (!NT_STATUS_IS_OK(status)) { + errno = map_errno_from_nt_status(status); + return status; + } + mapped_smb_fname = synthetic_smb_fname(talloc_tos(), + mapped_name, + NULL, + &smb_fname->st, + smb_fname->flags); + if (mapped_smb_fname == NULL) { + TALLOC_FREE(mapped_name); + return NT_STATUS_NO_MEMORY; + } + + status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle, + dirfsp, + mapped_smb_fname, + reflist, + referral_count); + TALLOC_FREE(mapped_name); + TALLOC_FREE(mapped_smb_fname); + return status; +} + static struct vfs_fn_pointers vfs_catia_fns = { .connect_fn = catia_connect, @@ -2415,6 +2454,7 @@ static struct vfs_fn_pointers vfs_catia_fns = { .fget_dos_attributes_fn = catia_fget_dos_attributes, .get_compression_fn = catia_get_compression, .set_compression_fn = catia_set_compression, + .create_dfs_pathat_fn = catia_create_dfs_pathat, /* NT ACL operations. */ .get_nt_acl_fn = catia_get_nt_acl, -- 2.25.0.265.gbab2e86ba0-goog From 8bb45c3704df23ed906b42487686d51d592945bd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 14:59:46 -0800 Subject: [PATCH 02/23] s3: VFS: Implement create_dfs_pathat() in cap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now we use this instead of symlinks to create DFS links, it's needed in cap. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Thu Jan 30 18:21:47 UTC 2020 on sn-devel-184 (cherry picked from commit 042249d95ff59d304cf37914860ee0c4d1f546f8) --- source3/modules/vfs_cap.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c index f1ec5807b49..bc6daeccca7 100644 --- a/source3/modules/vfs_cap.c +++ b/source3/modules/vfs_cap.c @@ -976,6 +976,38 @@ static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp, co return SMB_VFS_NEXT_FSETXATTR(handle, fsp, cappath, value, size, flags); } +static NTSTATUS cap_create_dfs_pathat(vfs_handle_struct *handle, + files_struct *dirfsp, + const struct smb_filename *smb_fname, + const struct referral *reflist, + size_t referral_count) +{ + char *cappath = capencode(talloc_tos(), smb_fname->base_name); + struct smb_filename *cap_smb_fname = NULL; + NTSTATUS status; + + if (cappath == NULL) { + return NT_STATUS_NO_MEMORY; + } + cap_smb_fname = synthetic_smb_fname(talloc_tos(), + cappath, + NULL, + NULL, + smb_fname->flags); + if (cap_smb_fname == NULL) { + TALLOC_FREE(cappath); + return NT_STATUS_NO_MEMORY; + } + status = SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle, + dirfsp, + cap_smb_fname, + reflist, + referral_count); + TALLOC_FREE(cappath); + TALLOC_FREE(cap_smb_fname); + return status; +} + static struct vfs_fn_pointers vfs_cap_fns = { .disk_free_fn = cap_disk_free, .get_quota_fn = cap_get_quota, @@ -1007,7 +1039,8 @@ static struct vfs_fn_pointers vfs_cap_fns = { .removexattr_fn = cap_removexattr, .fremovexattr_fn = cap_fremovexattr, .setxattr_fn = cap_setxattr, - .fsetxattr_fn = cap_fsetxattr + .fsetxattr_fn = cap_fsetxattr, + .create_dfs_pathat_fn = cap_create_dfs_pathat }; static_decl_vfs; -- 2.25.0.265.gbab2e86ba0-goog From 761886ad061ce09730d4d2a6b8723d0637807393 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jan 2020 16:29:46 -0800 Subject: [PATCH 03/23] s3: smbd: dfs: Cleanup, reformat calls to parse_msdfs_symlink() Make parameter easier to change. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit d22b0d907252939c2ded9d73cc67dbbf8bb57fb7) --- source3/smbd/msdfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 8f355d3a2c9..debc38a5307 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -1099,7 +1099,11 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, return NT_STATUS_NO_MEMORY; } - if (!parse_msdfs_symlink(ctx, snum, tmp, &ref, &refcount)) { + if (!parse_msdfs_symlink(ctx, + snum, + tmp, + &ref, + &refcount)) { TALLOC_FREE(frame); return NT_STATUS_INVALID_PARAMETER; } @@ -1170,7 +1174,9 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, } /* We know this is a valid dfs link. Parse the targetpath. */ - if (!parse_msdfs_symlink(ctx, snum, targetpath, + if (!parse_msdfs_symlink(ctx, + snum, + targetpath, &jucn->referral_list, &jucn->referral_count)) { DEBUG(3,("get_referred_path: failed to parse symlink " @@ -1763,7 +1769,8 @@ static int form_junctions(TALLOC_CTX *ctx, if (is_msdfs_link_internal(ctx, conn, smb_dname, &link_target)) { - if (parse_msdfs_symlink(ctx, snum, + if (parse_msdfs_symlink(ctx, + snum, link_target, &jucn[cnt].referral_list, &jucn[cnt].referral_count)) { -- 2.25.0.265.gbab2e86ba0-goog From e879fc3c361f472917289b626aa7fe2964be0974 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jan 2020 16:31:52 -0800 Subject: [PATCH 04/23] s3: smbd: dfs: Move lp_msdfs_shuffle_referrals() call out of parse_msdfs_symlink(). Removes dependency on snum for what is text parsing code. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 028c33e09ab52b55f33f83e26a12498f57918334) --- source3/smbd/msdfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index debc38a5307..8a682aad499 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -524,7 +524,7 @@ static void shuffle_strlist(char **list, int count) **********************************************************************/ static bool parse_msdfs_symlink(TALLOC_CTX *ctx, - int snum, + bool shuffle_referrals, const char *target, struct referral **preflist, size_t *refcount) @@ -558,7 +558,7 @@ static bool parse_msdfs_symlink(TALLOC_CTX *ctx, } /* shuffle alternate paths */ - if (lp_msdfs_shuffle_referrals(snum)) { + if (shuffle_referrals) { shuffle_strlist(alt_path, count); } @@ -1100,7 +1100,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, } if (!parse_msdfs_symlink(ctx, - snum, + lp_msdfs_shuffle_referrals(snum), tmp, &ref, &refcount)) { @@ -1175,7 +1175,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, /* We know this is a valid dfs link. Parse the targetpath. */ if (!parse_msdfs_symlink(ctx, - snum, + lp_msdfs_shuffle_referrals(snum), targetpath, &jucn->referral_list, &jucn->referral_count)) { @@ -1770,7 +1770,7 @@ static int form_junctions(TALLOC_CTX *ctx, conn, smb_dname, &link_target)) { if (parse_msdfs_symlink(ctx, - snum, + lp_msdfs_shuffle_referrals(snum), link_target, &jucn[cnt].referral_list, &jucn[cnt].referral_count)) { -- 2.25.0.265.gbab2e86ba0-goog From 9254e50b79c6b0fffec941226074e0db79edcce7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jan 2020 16:35:25 -0800 Subject: [PATCH 05/23] s3: smbd: dfs: Make parse_msdfs_symlink() external. So it can be called by a future new VFS call. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 012b812188f636d9b8cf0edee34df5d43d2ac0a8) --- source3/smbd/msdfs.c | 10 +++++----- source3/smbd/proto.h | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 8a682aad499..0ba9810d097 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -523,11 +523,11 @@ static void shuffle_strlist(char **list, int count) server we're referring to understands posix paths. **********************************************************************/ -static bool parse_msdfs_symlink(TALLOC_CTX *ctx, - bool shuffle_referrals, - const char *target, - struct referral **preflist, - size_t *refcount) +bool parse_msdfs_symlink(TALLOC_CTX *ctx, + bool shuffle_referrals, + const char *target, + struct referral **preflist, + size_t *refcount) { char *temp = NULL; char *prot; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index de4a53c6187..96d574023a5 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -477,6 +477,11 @@ void reply_sendend(struct smb_request *req); /* The following definitions come from smbd/msdfs.c */ +bool parse_msdfs_symlink(TALLOC_CTX *ctx, + bool shuffle_referrals, + const char *target, + struct referral **preflist, + size_t *refcount); bool is_msdfs_link(connection_struct *conn, struct smb_filename *smb_fname); struct junction_map; -- 2.25.0.265.gbab2e86ba0-goog From 1b70c47f29e0d0044271003b59119779a304a403 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jan 2020 16:42:11 -0800 Subject: [PATCH 06/23] s3: smbd: dfs: Apply some README.Coding to parse_msdfs_symlink(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit a211c640878d856e859ab2fdfbbe61036240b8eb) --- source3/smbd/msdfs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 0ba9810d097..2d784430ebf 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -538,17 +538,17 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, temp = talloc_strdup(ctx, target); if (!temp) { - return False; + return false; } prot = strtok_r(temp, ":", &saveptr); if (!prot) { DEBUG(0,("parse_msdfs_symlink: invalid path !\n")); - return False; + return false; } alt_path = talloc_array(ctx, char *, MAX_REFERRAL_COUNT); if (!alt_path) { - return False; + return false; } /* parse out the alternate paths */ @@ -569,7 +569,7 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, struct referral, count); if(reflist == NULL) { TALLOC_FREE(alt_path); - return False; + return false; } } else { reflist = *preflist = NULL; @@ -592,19 +592,19 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, "\\%s", p); if (!reflist[i].alternate_path) { - return False; + return false; } reflist[i].proximity = 0; reflist[i].ttl = REFERRAL_TTL; - DEBUG(10, ("parse_msdfs_symlink: Created alt path: %s\n", - reflist[i].alternate_path)); + DBG_DEBUG("Created alt path: %s\n", + reflist[i].alternate_path); } *refcount = count; TALLOC_FREE(alt_path); - return True; + return true; } /********************************************************************** -- 2.25.0.265.gbab2e86ba0-goog From a9ee5ab76b4062987bdbd162fb5b2d7e690fb8a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jan 2020 16:45:20 -0800 Subject: [PATCH 07/23] s3: smbd: dfs: Allow parse_msdfs_symlink() to be called with NULL pointers. In case we don't want all the data. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 4e4afc52e6f63fa4058310c6b0a0314b8f73c189) --- source3/smbd/msdfs.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 2d784430ebf..4df881bd87e 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -565,14 +565,14 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, DBG_DEBUG("count=%zu\n", count); if (count) { - reflist = *preflist = talloc_zero_array(ctx, + reflist = talloc_zero_array(ctx, struct referral, count); if(reflist == NULL) { TALLOC_FREE(alt_path); return false; } } else { - reflist = *preflist = NULL; + reflist = NULL; } for(i=0;i Date: Tue, 28 Jan 2020 09:28:30 -0800 Subject: [PATCH 08/23] s3: smbd: dfs: Make parameter names consistent. Initialize reflist to NULL. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit ed527dc1d8bd21d942bc14677d83363144e5f46b) --- source3/smbd/msdfs.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 4df881bd87e..f4c847a645a 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -526,14 +526,14 @@ static void shuffle_strlist(char **list, int count) bool parse_msdfs_symlink(TALLOC_CTX *ctx, bool shuffle_referrals, const char *target, - struct referral **preflist, - size_t *refcount) + struct referral **ppreflist, + size_t *prefcount) { char *temp = NULL; char *prot; char **alt_path = NULL; size_t count = 0, i; - struct referral *reflist; + struct referral *reflist = NULL; char *saveptr; temp = talloc_strdup(ctx, target); @@ -601,11 +601,11 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, reflist[i].alternate_path); } - if (preflist != NULL) { - *preflist = reflist; + if (ppreflist != NULL) { + *ppreflist = reflist; } - if (refcount != NULL) { - *refcount = count; + if (prefcount != NULL) { + *prefcount = count; } TALLOC_FREE(alt_path); return true; -- 2.25.0.265.gbab2e86ba0-goog From c003a927f220bf080605dc9bfaafbb7db3eb3ba2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 09:36:26 -0800 Subject: [PATCH 09/23] s3: smbd: dfs: Clean up exits / talloc heirarchy in parse_msdfs_symlink(). Ensure on error or clean return we don't leave memory on mem_ctx. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 74b47bf578dab9ce94a9f2439fa672e51afe809e) --- source3/smbd/msdfs.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index f4c847a645a..d48b8952d38 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -543,11 +543,13 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, prot = strtok_r(temp, ":", &saveptr); if (!prot) { DEBUG(0,("parse_msdfs_symlink: invalid path !\n")); + TALLOC_FREE(temp); return false; } alt_path = talloc_array(ctx, char *, MAX_REFERRAL_COUNT); if (!alt_path) { + TALLOC_FREE(temp); return false; } @@ -568,6 +570,7 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, reflist = talloc_zero_array(ctx, struct referral, count); if(reflist == NULL) { + TALLOC_FREE(temp); TALLOC_FREE(alt_path); return false; } @@ -588,10 +591,13 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, p++; } - reflist[i].alternate_path = talloc_asprintf(ctx, + reflist[i].alternate_path = talloc_asprintf(reflist, "\\%s", p); if (!reflist[i].alternate_path) { + TALLOC_FREE(temp); + TALLOC_FREE(alt_path); + TALLOC_FREE(reflist); return false; } @@ -603,10 +609,13 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, if (ppreflist != NULL) { *ppreflist = reflist; + } else { + TALLOC_FREE(reflist); } if (prefcount != NULL) { *prefcount = count; } + TALLOC_FREE(temp); TALLOC_FREE(alt_path); return true; } -- 2.25.0.265.gbab2e86ba0-goog From 1b165a2302036729be2d8f1387ed8332d574f88d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 09:51:17 -0800 Subject: [PATCH 10/23] s3: VFS: Add SMB_VFS_READ_DFS_PATHAT(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 96bc3298fc025d1d76fc06833fece6c62faa5e1a) --- examples/VFS/skel_opaque.c | 11 +++ examples/VFS/skel_transparent.c | 16 ++++ source3/include/vfs.h | 19 +++++ source3/include/vfs_macros.h | 14 ++++ source3/modules/vfs_default.c | 103 ++++++++++++++++++++++++++ source3/modules/vfs_not_implemented.c | 11 +++ source3/smbd/vfs.c | 16 ++++ 7 files changed, 190 insertions(+) diff --git a/examples/VFS/skel_opaque.c b/examples/VFS/skel_opaque.c index 71c34de8013..c1b5923b752 100644 --- a/examples/VFS/skel_opaque.c +++ b/examples/VFS/skel_opaque.c @@ -112,6 +112,16 @@ static NTSTATUS skel_create_dfs_pathat(struct vfs_handle_struct *handle, return NT_STATUS_NOT_IMPLEMENTED; } +static NTSTATUS skel_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + static DIR *skel_opendir(vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, @@ -1042,6 +1052,7 @@ static struct vfs_fn_pointers skel_opaque_fns = { .fs_capabilities_fn = skel_fs_capabilities, .get_dfs_referrals_fn = skel_get_dfs_referrals, .create_dfs_pathat_fn = skel_create_dfs_pathat, + .read_dfs_pathat_fn = skel_read_dfs_pathat, .snap_check_path_fn = skel_snap_check_path, .snap_create_fn = skel_snap_create, .snap_delete_fn = skel_snap_delete, diff --git a/examples/VFS/skel_transparent.c b/examples/VFS/skel_transparent.c index 4b91f64f15e..d2d05673fb4 100644 --- a/examples/VFS/skel_transparent.c +++ b/examples/VFS/skel_transparent.c @@ -113,6 +113,21 @@ static NTSTATUS skel_create_dfs_pathat(struct vfs_handle_struct *handle, referral_count); } +static NTSTATUS skel_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + return SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + smb_fname, + ppreflist, + preferral_count); +} + static DIR *skel_opendir(vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, @@ -1344,6 +1359,7 @@ static struct vfs_fn_pointers skel_transparent_fns = { .fs_capabilities_fn = skel_fs_capabilities, .get_dfs_referrals_fn = skel_get_dfs_referrals, .create_dfs_pathat_fn = skel_create_dfs_pathat, + .read_dfs_pathat_fn = skel_read_dfs_pathat, .snap_check_path_fn = skel_snap_check_path, .snap_create_fn = skel_snap_create, .snap_delete_fn = skel_snap_delete, diff --git a/source3/include/vfs.h b/source3/include/vfs.h index 656fad8b5ee..fec38f20644 100644 --- a/source3/include/vfs.h +++ b/source3/include/vfs.h @@ -289,6 +289,7 @@ /* Version 42 - Remove struct write_cache *wcp from files_struct */ /* Version 42 - SMB_VFS_NTIMES() receives null times based on UTIMES_OMIT */ /* Version 42 - Add SMB_VFS_CREATE_DFS_PATHAT() */ +/* Version 42 - Add SMB_VFS_READ_DFS_PATHAT() */ #define SMB_VFS_INTERFACE_VERSION 42 @@ -716,6 +717,12 @@ struct vfs_fn_pointers { const struct smb_filename *smb_fname, const struct referral *reflist, size_t referral_count); + NTSTATUS (*read_dfs_pathat_fn)(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); /* Directory operations */ @@ -1224,6 +1231,12 @@ NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, const struct referral *reflist, size_t referral_count); +NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, @@ -1666,6 +1679,12 @@ NTSTATUS vfs_not_implemented_create_dfs_pathat(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, const struct referral *reflist, size_t referral_count); +NTSTATUS vfs_not_implemented_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count); DIR *vfs_not_implemented_opendir(vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, diff --git a/source3/include/vfs_macros.h b/source3/include/vfs_macros.h index d4ccb8f5c73..112169ab83b 100644 --- a/source3/include/vfs_macros.h +++ b/source3/include/vfs_macros.h @@ -90,6 +90,20 @@ (smb_fname), \ (reflist), \ (count)) +#define SMB_VFS_READ_DFS_PATHAT(conn, mem_ctx, dirfsp, smb_fname, ppreflist, pcount) \ + smb_vfs_call_read_dfs_pathat((conn)->vfs_handles, \ + (mem_ctx), \ + (dirfsp), \ + (smb_fname), \ + (ppreflist), \ + (pcount)) +#define SMB_VFS_NEXT_READ_DFS_PATHAT(handle, mem_ctx, dirfsp, smb_fname, ppreflist, pcount) \ + smb_vfs_call_read_dfs_pathat((handle)->next, \ + (mem_ctx), \ + (dirfsp), \ + (smb_fname), \ + (ppreflist), \ + (pcount)) /* Directory operations */ #define SMB_VFS_OPENDIR(conn, smb_fname, mask, attr) \ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index f0c92f873e4..37b59d8c3c0 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -404,6 +404,108 @@ static NTSTATUS vfswrap_create_dfs_pathat(struct vfs_handle_struct *handle, return status; } +/* + * Read and return the contents of a DFS redirect given a + * pathname. A caller can pass in NULL for ppreflist and + * preferral_count but still determine if this was a + * DFS redirect point by getting NT_STATUS_OK back + * without incurring the overhead of reading and parsing + * the referral contents. + */ + +static NTSTATUS vfswrap_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + NTSTATUS status = NT_STATUS_NO_MEMORY; + size_t bufsize; + char *link_target = NULL; + int referral_len; + bool ok; +#if defined(HAVE_BROKEN_READLINK) + char link_target_buf[PATH_MAX]; +#else + char link_target_buf[7]; +#endif + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + if (ppreflist == NULL && preferral_count == NULL) { + /* + * We're only checking if this is a DFS + * redirect. We don't need to return data. + */ + bufsize = sizeof(link_target_buf); + link_target = link_target_buf; + } else { + bufsize = PATH_MAX; + link_target = talloc_array(mem_ctx, char, bufsize); + if (!link_target) { + goto err; + } + } + + referral_len = readlinkat(dirfsp->fh->fd, + smb_fname->base_name, + link_target, + bufsize - 1); + if (referral_len == -1) { + if (errno == EINVAL) { + /* + * If the path isn't a link, readlinkat + * returns EINVAL. Allow the caller to + * detect this. + */ + DBG_INFO("%s is not a link.\n", smb_fname->base_name); + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + } else { + status = map_nt_error_from_unix(errno); + DBG_ERR("Error reading " + "msdfs link %s: %s\n", + smb_fname->base_name, + strerror(errno)); + } + goto err; + } + link_target[referral_len] = '\0'; + + DBG_INFO("%s -> %s\n", + smb_fname->base_name, + link_target); + + if (!strnequal(link_target, "msdfs:", 6)) { + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + goto err; + } + + if (ppreflist == NULL && preferral_count == NULL) { + /* Early return for checking if this is a DFS link. */ + return NT_STATUS_OK; + } + + ok = parse_msdfs_symlink(mem_ctx, + lp_msdfs_shuffle_referrals(SNUM(handle->conn)), + link_target, + ppreflist, + preferral_count); + + if (ok) { + status = NT_STATUS_OK; + } else { + status = NT_STATUS_NO_MEMORY; + } + + err: + + if (link_target != link_target_buf) { + TALLOC_FREE(link_target); + } + return status; +} + static NTSTATUS vfswrap_snap_check_path(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, const char *service_path, @@ -3517,6 +3619,7 @@ static struct vfs_fn_pointers vfs_default_fns = { .fs_capabilities_fn = vfswrap_fs_capabilities, .get_dfs_referrals_fn = vfswrap_get_dfs_referrals, .create_dfs_pathat_fn = vfswrap_create_dfs_pathat, + .read_dfs_pathat_fn = vfswrap_read_dfs_pathat, .snap_check_path_fn = vfswrap_snap_check_path, .snap_create_fn = vfswrap_snap_create, .snap_delete_fn = vfswrap_snap_delete, diff --git a/source3/modules/vfs_not_implemented.c b/source3/modules/vfs_not_implemented.c index 2bdab503d2c..5861e20d88d 100644 --- a/source3/modules/vfs_not_implemented.c +++ b/source3/modules/vfs_not_implemented.c @@ -106,6 +106,16 @@ NTSTATUS vfs_not_implemented_create_dfs_pathat(struct vfs_handle_struct *handle, return NT_STATUS_NOT_IMPLEMENTED; } +NTSTATUS vfs_not_implemented_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + DIR *vfs_not_implemented_opendir(vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, @@ -1047,6 +1057,7 @@ static struct vfs_fn_pointers vfs_not_implemented_fns = { .fs_capabilities_fn = vfs_not_implemented_fs_capabilities, .get_dfs_referrals_fn = vfs_not_implemented_get_dfs_referrals, .create_dfs_pathat_fn = vfs_not_implemented_create_dfs_pathat, + .read_dfs_pathat_fn = vfs_not_implemented_read_dfs_pathat, .snap_check_path_fn = vfs_not_implemented_snap_check_path, .snap_create_fn = vfs_not_implemented_snap_create, .snap_delete_fn = vfs_not_implemented_snap_delete, diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index e007a57fa01..7dc15158ccb 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -1577,6 +1577,22 @@ NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle, referral_count); } +NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + VFS_FIND(read_dfs_pathat); + return handle->fns->read_dfs_pathat_fn(handle, + mem_ctx, + dirfsp, + smb_fname, + ppreflist, + preferral_count); +} + DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle, const struct smb_filename *smb_fname, const char *mask, -- 2.25.0.265.gbab2e86ba0-goog From dfc23709d687560812bdb1d97653d4fd80d55670 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 10:18:04 -0800 Subject: [PATCH 11/23] s3: VFS: ceph: Add vfswrap_ceph_read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit e52e2135dd9b8bd2e65261c210e7b8d36a727396) --- source3/modules/vfs_ceph.c | 100 +++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c index 3526cbe0f6d..76393a84152 100644 --- a/source3/modules/vfs_ceph.c +++ b/source3/modules/vfs_ceph.c @@ -1331,6 +1331,105 @@ static NTSTATUS cephwrap_create_dfs_pathat(struct vfs_handle_struct *handle, return status; } +/* + * Read and return the contents of a DFS redirect given a + * pathname. A caller can pass in NULL for ppreflist and + * preferral_count but still determine if this was a + * DFS redirect point by getting NT_STATUS_OK back + * without incurring the overhead of reading and parsing + * the referral contents. + */ + +static NTSTATUS cephwrap_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + NTSTATUS status = NT_STATUS_NO_MEMORY; + size_t bufsize; + char *link_target = NULL; + int referral_len; + bool ok; +#if defined(HAVE_BROKEN_READLINK) + char link_target_buf[PATH_MAX]; +#else + char link_target_buf[7]; +#endif + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + if (ppreflist == NULL && preferral_count == NULL) { + /* + * We're only checking if this is a DFS + * redirect. We don't need to return data. + */ + bufsize = sizeof(link_target_buf); + link_target = link_target_buf; + } else { + bufsize = PATH_MAX; + link_target = talloc_array(mem_ctx, char, bufsize); + if (!link_target) { + goto err; + } + } + + referral_len = ceph_readlink(handle->data, + smb_fname->base_name, + link_target, + bufsize - 1); + if (referral_len < 0) { + /* ceph errors are -errno. */ + if (-referral_len == EINVAL) { + DBG_INFO("%s is not a link.\n", + smb_fname->base_name); + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + } else { + status = map_nt_error_from_unix(-referral_len); + DBG_ERR("Error reading " + "msdfs link %s: %s\n", + smb_fname->base_name, + strerror(errno)); + } + goto err; + } + link_target[referral_len] = '\0'; + + DBG_INFO("%s -> %s\n", + smb_fname->base_name, + link_target); + + if (!strnequal(link_target, "msdfs:", 6)) { + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + goto err; + } + + if (ppreflist == NULL && preferral_count == NULL) { + /* Early return for checking if this is a DFS link. */ + return NT_STATUS_OK; + } + + ok = parse_msdfs_symlink(mem_ctx, + lp_msdfs_shuffle_referrals(SNUM(handle->conn)), + link_target, + ppreflist, + preferral_count); + + if (ok) { + status = NT_STATUS_OK; + } else { + status = NT_STATUS_NO_MEMORY; + } + + err: + + if (link_target != link_target_buf) { + TALLOC_FREE(link_target); + } + return status; +} + static struct vfs_fn_pointers ceph_fns = { /* Disk operations */ @@ -1356,6 +1455,7 @@ static struct vfs_fn_pointers ceph_fns = { /* File operations */ .create_dfs_pathat_fn = cephwrap_create_dfs_pathat, + .read_dfs_pathat_fn = cephwrap_read_dfs_pathat, .open_fn = cephwrap_open, .close_fn = cephwrap_close, .pread_fn = cephwrap_pread, -- 2.25.0.265.gbab2e86ba0-goog From 258127999e6a5d79eba9d91c7b27b7d990b25e31 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 10:46:43 -0800 Subject: [PATCH 12/23] s3: VFS: gluster: Add vfs_gluster_read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 018af49b93f8e9a2cbc0d40cc68b8202e5c95c9a) --- source3/modules/vfs_glusterfs.c | 98 +++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/source3/modules/vfs_glusterfs.c b/source3/modules/vfs_glusterfs.c index 059aeb42ab5..d4b68fba376 100644 --- a/source3/modules/vfs_glusterfs.c +++ b/source3/modules/vfs_glusterfs.c @@ -1933,6 +1933,103 @@ static NTSTATUS vfs_gluster_create_dfs_pathat(struct vfs_handle_struct *handle, return status; } +/* + * Read and return the contents of a DFS redirect given a + * pathname. A caller can pass in NULL for ppreflist and + * preferral_count but still determine if this was a + * DFS redirect point by getting NT_STATUS_OK back + * without incurring the overhead of reading and parsing + * the referral contents. + */ + +static NTSTATUS vfs_gluster_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + NTSTATUS status = NT_STATUS_NO_MEMORY; + size_t bufsize; + char *link_target = NULL; + int referral_len; + bool ok; +#if defined(HAVE_BROKEN_READLINK) + char link_target_buf[PATH_MAX]; +#else + char link_target_buf[7]; +#endif + + SMB_ASSERT(dirfsp == dirfsp->conn->cwd_fsp); + + if (ppreflist == NULL && preferral_count == NULL) { + /* + * We're only checking if this is a DFS + * redirect. We don't need to return data. + */ + bufsize = sizeof(link_target_buf); + link_target = link_target_buf; + } else { + bufsize = PATH_MAX; + link_target = talloc_array(mem_ctx, char, bufsize); + if (!link_target) { + goto err; + } + } + + referral_len = glfs_readlink(handle->data, + smb_fname->base_name, + link_target, + bufsize - 1); + if (referral_len < 0) { + if (errno == EINVAL) { + DBG_INFO("%s is not a link.\n", smb_fname->base_name); + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + } else { + status = map_nt_error_from_unix(errno); + DBG_ERR("Error reading " + "msdfs link %s: %s\n", + smb_fname->base_name, + strerror(errno)); + } + goto err; + } + link_target[referral_len] = '\0'; + + DBG_INFO("%s -> %s\n", + smb_fname->base_name, + link_target); + + if (!strnequal(link_target, "msdfs:", 6)) { + status = NT_STATUS_OBJECT_TYPE_MISMATCH; + goto err; + } + + if (ppreflist == NULL && preferral_count == NULL) { + /* Early return for checking if this is a DFS link. */ + return NT_STATUS_OK; + } + + ok = parse_msdfs_symlink(mem_ctx, + lp_msdfs_shuffle_referrals(SNUM(handle->conn)), + link_target, + ppreflist, + preferral_count); + + if (ok) { + status = NT_STATUS_OK; + } else { + status = NT_STATUS_NO_MEMORY; + } + + err: + + if (link_target != link_target_buf) { + TALLOC_FREE(link_target); + } + return status; +} + static struct vfs_fn_pointers glusterfs_fns = { /* Disk Operations */ @@ -2007,6 +2104,7 @@ static struct vfs_fn_pointers glusterfs_fns = { .get_real_filename_fn = vfs_gluster_get_real_filename, .connectpath_fn = vfs_gluster_connectpath, .create_dfs_pathat_fn = vfs_gluster_create_dfs_pathat, + .read_dfs_pathat_fn = vfs_gluster_read_dfs_pathat, .brl_lock_windows_fn = NULL, .brl_unlock_windows_fn = NULL, -- 2.25.0.265.gbab2e86ba0-goog From 92c231e1f84ba9daac4ff4ca36fb028174a9f614 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 28 Jan 2020 12:12:09 -0800 Subject: [PATCH 13/23] s3: VFS: shadow_copy2: Add shadow_copy2_read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 9e92d46b757d6a4cdd0f956c24b30df89adf2798) --- source3/modules/vfs_shadow_copy2.c | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index 143f92959ff..c9b8d80e7f4 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -2467,6 +2467,60 @@ static NTSTATUS shadow_copy2_create_dfs_pathat(struct vfs_handle_struct *handle, referral_count); } +static NTSTATUS shadow_copy2_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + time_t timestamp = 0; + char *stripped = NULL; + struct smb_filename *conv = NULL; + NTSTATUS status; + + if (!shadow_copy2_strip_snapshot(mem_ctx, + handle, + smb_fname->base_name, + ×tamp, + &stripped)) { + return NT_STATUS_NO_MEMORY; + } + if (timestamp == 0) { + return SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + smb_fname, + ppreflist, + preferral_count); + } + + conv = cp_smb_filename(mem_ctx, smb_fname); + if (conv == NULL) { + TALLOC_FREE(stripped); + return NT_STATUS_NO_MEMORY; + } + conv->base_name = shadow_copy2_convert(conv, + handle, + stripped, + timestamp); + TALLOC_FREE(stripped); + if (conv->base_name == NULL) { + TALLOC_FREE(conv); + return NT_STATUS_NO_MEMORY; + } + + status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + conv, + ppreflist, + preferral_count); + + TALLOC_FREE(conv); + return status; +} + static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle, const char *path, const char *name, @@ -3149,6 +3203,7 @@ static struct vfs_fn_pointers vfs_shadow_copy2_fns = { .disk_free_fn = shadow_copy2_disk_free, .get_quota_fn = shadow_copy2_get_quota, .create_dfs_pathat_fn = shadow_copy2_create_dfs_pathat, + .read_dfs_pathat_fn = shadow_copy2_read_dfs_pathat, .renameat_fn = shadow_copy2_renameat, .linkat_fn = shadow_copy2_linkat, .symlinkat_fn = shadow_copy2_symlinkat, -- 2.25.0.265.gbab2e86ba0-goog From 357e2b6a8a66feb364c729fbbaca1e65721f6397 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Feb 2020 09:48:05 -0800 Subject: [PATCH 14/23] s3: VFS: cap: Add cap_read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 9f6c01b2cd82963bfa05552aa41dfafcb0bf7637) --- source3/modules/vfs_cap.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/source3/modules/vfs_cap.c b/source3/modules/vfs_cap.c index bc6daeccca7..e67cb750e0f 100644 --- a/source3/modules/vfs_cap.c +++ b/source3/modules/vfs_cap.c @@ -1008,6 +1008,41 @@ static NTSTATUS cap_create_dfs_pathat(vfs_handle_struct *handle, return status; } +static NTSTATUS cap_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + char *cappath = capencode(talloc_tos(), smb_fname->base_name); + struct smb_filename *cap_smb_fname = NULL; + NTSTATUS status; + + if (cappath == NULL) { + return NT_STATUS_NO_MEMORY; + } + cap_smb_fname = synthetic_smb_fname(talloc_tos(), + cappath, + NULL, + NULL, + smb_fname->flags); + if (cap_smb_fname == NULL) { + TALLOC_FREE(cappath); + return NT_STATUS_NO_MEMORY; + } + + status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + cap_smb_fname, + ppreflist, + preferral_count); + TALLOC_FREE(cappath); + TALLOC_FREE(cap_smb_fname); + return status; +} + static struct vfs_fn_pointers vfs_cap_fns = { .disk_free_fn = cap_disk_free, .get_quota_fn = cap_get_quota, @@ -1040,7 +1075,8 @@ static struct vfs_fn_pointers vfs_cap_fns = { .fremovexattr_fn = cap_fremovexattr, .setxattr_fn = cap_setxattr, .fsetxattr_fn = cap_fsetxattr, - .create_dfs_pathat_fn = cap_create_dfs_pathat + .create_dfs_pathat_fn = cap_create_dfs_pathat, + .read_dfs_pathat_fn = cap_read_dfs_pathat }; static_decl_vfs; -- 2.25.0.265.gbab2e86ba0-goog From 451823976cdcfaab88ff76ec31f7ddc801b679f9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Feb 2020 10:02:00 -0800 Subject: [PATCH 15/23] s3: VFS: catia: Add read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 16acdc348db71a29bec93d62073ca30a4a920389) --- source3/modules/vfs_catia.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/source3/modules/vfs_catia.c b/source3/modules/vfs_catia.c index 1739fd77d5b..5bb55cf89f6 100644 --- a/source3/modules/vfs_catia.c +++ b/source3/modules/vfs_catia.c @@ -2404,6 +2404,47 @@ static NTSTATUS catia_create_dfs_pathat(struct vfs_handle_struct *handle, return status; } +static NTSTATUS catia_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + char *mapped_name = NULL; + const char *path = smb_fname->base_name; + struct smb_filename *mapped_smb_fname = NULL; + NTSTATUS status; + + status = catia_string_replace_allocate(handle->conn, + path, + &mapped_name, + vfs_translate_to_unix); + if (!NT_STATUS_IS_OK(status)) { + errno = map_errno_from_nt_status(status); + return status; + } + mapped_smb_fname = synthetic_smb_fname(talloc_tos(), + mapped_name, + NULL, + &smb_fname->st, + smb_fname->flags); + if (mapped_smb_fname == NULL) { + TALLOC_FREE(mapped_name); + return NT_STATUS_NO_MEMORY; + } + + status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + mapped_smb_fname, + ppreflist, + preferral_count); + TALLOC_FREE(mapped_name); + TALLOC_FREE(mapped_smb_fname); + return status; +} + static struct vfs_fn_pointers vfs_catia_fns = { .connect_fn = catia_connect, @@ -2455,6 +2496,7 @@ static struct vfs_fn_pointers vfs_catia_fns = { .get_compression_fn = catia_get_compression, .set_compression_fn = catia_set_compression, .create_dfs_pathat_fn = catia_create_dfs_pathat, + .read_dfs_pathat_fn = catia_read_dfs_pathat, /* NT ACL operations. */ .get_nt_acl_fn = catia_get_nt_acl, -- 2.25.0.265.gbab2e86ba0-goog From e71a0ee8e5f8083a3e7923316e52b7cce713dc6a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Feb 2020 10:02:18 -0800 Subject: [PATCH 16/23] s3: VFS: vfs_full_audit: Add read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 263df988831a40ba751b19c1715277e80095818c) --- source3/modules/vfs_full_audit.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/source3/modules/vfs_full_audit.c b/source3/modules/vfs_full_audit.c index 1e4a641d0a4..5c8267dea9f 100644 --- a/source3/modules/vfs_full_audit.c +++ b/source3/modules/vfs_full_audit.c @@ -102,6 +102,7 @@ typedef enum _vfs_op_type { SMB_VFS_OP_FS_CAPABILITIES, SMB_VFS_OP_GET_DFS_REFERRALS, SMB_VFS_OP_CREATE_DFS_PATHAT, + SMB_VFS_OP_READ_DFS_PATHAT, /* Directory operations */ @@ -251,6 +252,7 @@ static struct { { SMB_VFS_OP_FS_CAPABILITIES, "fs_capabilities" }, { SMB_VFS_OP_GET_DFS_REFERRALS, "get_dfs_referrals" }, { SMB_VFS_OP_CREATE_DFS_PATHAT, "create_dfs_pathat" }, + { SMB_VFS_OP_READ_DFS_PATHAT, "read_dfs_pathat" }, { SMB_VFS_OP_OPENDIR, "opendir" }, { SMB_VFS_OP_FDOPENDIR, "fdopendir" }, { SMB_VFS_OP_READDIR, "readdir" }, @@ -915,6 +917,31 @@ static NTSTATUS smb_full_audit_create_dfs_pathat(struct vfs_handle_struct *handl return status; } +static NTSTATUS smb_full_audit_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + NTSTATUS status; + + status = SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + smb_fname, + ppreflist, + preferral_count); + + do_log(SMB_VFS_OP_READ_DFS_PATHAT, + NT_STATUS_IS_OK(status), + handle, + "%s", + smb_fname_str_do_log(handle->conn, smb_fname)); + + return status; +} + static NTSTATUS smb_full_audit_snap_check_path(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, const char *service_path, @@ -2961,6 +2988,7 @@ static struct vfs_fn_pointers vfs_full_audit_fns = { .fs_capabilities_fn = smb_full_audit_fs_capabilities, .get_dfs_referrals_fn = smb_full_audit_get_dfs_referrals, .create_dfs_pathat_fn = smb_full_audit_create_dfs_pathat, + .read_dfs_pathat_fn = smb_full_audit_read_dfs_pathat, .opendir_fn = smb_full_audit_opendir, .fdopendir_fn = smb_full_audit_fdopendir, .readdir_fn = smb_full_audit_readdir, -- 2.25.0.265.gbab2e86ba0-goog From 69aff156ac291ef6bb86fde53978f073b78dfaaf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Feb 2020 13:08:04 -0800 Subject: [PATCH 17/23] s3: VFS: vfs_time_audit: Add read_dfs_pathat(). Not yet used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 0528584482f798753d636675da778917f50ca845) --- source3/modules/vfs_time_audit.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/source3/modules/vfs_time_audit.c b/source3/modules/vfs_time_audit.c index 9f20fc5234a..5548f771fa5 100644 --- a/source3/modules/vfs_time_audit.c +++ b/source3/modules/vfs_time_audit.c @@ -349,6 +349,34 @@ static NTSTATUS smb_time_audit_create_dfs_pathat(struct vfs_handle_struct *handl return result; } +static NTSTATUS smb_time_audit_read_dfs_pathat(struct vfs_handle_struct *handle, + TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + struct referral **ppreflist, + size_t *preferral_count) +{ + NTSTATUS result; + struct timespec ts1,ts2; + double timediff; + + clock_gettime_mono(&ts1); + result = SMB_VFS_NEXT_READ_DFS_PATHAT(handle, + mem_ctx, + dirfsp, + smb_fname, + ppreflist, + preferral_count); + clock_gettime_mono(&ts2); + timediff = nsec_time_diff(&ts2,&ts1)*1.0e-9; + + if (timediff > audit_timeout) { + smb_time_audit_log("read_dfs_pathat", timediff); + } + + return result; +} + static NTSTATUS smb_time_audit_snap_check_path(struct vfs_handle_struct *handle, TALLOC_CTX *mem_ctx, const char *service_path, @@ -2834,6 +2862,7 @@ static struct vfs_fn_pointers vfs_time_audit_fns = { .fs_capabilities_fn = smb_time_audit_fs_capabilities, .get_dfs_referrals_fn = smb_time_audit_get_dfs_referrals, .create_dfs_pathat_fn = smb_time_audit_create_dfs_pathat, + .read_dfs_pathat_fn = smb_time_audit_read_dfs_pathat, .opendir_fn = smb_time_audit_opendir, .fdopendir_fn = smb_time_audit_fdopendir, .readdir_fn = smb_time_audit_readdir, -- 2.25.0.265.gbab2e86ba0-goog From a7310a2d729e041576e3e1602abd1b9101511e18 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Feb 2020 13:35:53 -0800 Subject: [PATCH 18/23] s3: DFS: Change simple is_msdfs_link() call to use SMB_VFS_READ_DFS_PATHAT(). This will need an extra dirfsp parameter in future, but this is the easiest change for now. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 07a3cd56cddfc0e27a75ca76e556e2fdb18c3291) --- source3/smbd/msdfs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index d48b8952d38..fa8272f73bb 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -699,10 +699,13 @@ static bool is_msdfs_link_internal(TALLOC_CTX *ctx, bool is_msdfs_link(connection_struct *conn, struct smb_filename *smb_fname) { - return is_msdfs_link_internal(talloc_tos(), - conn, + NTSTATUS status = SMB_VFS_READ_DFS_PATHAT(conn, + talloc_tos(), + conn->cwd_fsp, smb_fname, + NULL, NULL); + return (NT_STATUS_IS_OK(status)); } /***************************************************************** -- 2.25.0.265.gbab2e86ba0-goog From af1eb776dd581aada5f3d18f46385b8678fddd45 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Feb 2020 14:21:12 -0800 Subject: [PATCH 19/23] s3: DFS: Parse the returned target path in dfs_path_lookup(). Currently unused, but this will ease the transition to using SMB_VFS_READ_DFS_PATHAT(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 1ffc52abedae9787f745795a4f502c26b4c005d1) --- source3/smbd/msdfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index fa8272f73bb..ada261651cb 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -855,6 +855,31 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, status = NT_STATUS_OK; out: + + if (NT_STATUS_EQUAL(status, NT_STATUS_PATH_NOT_COVERED)) { + /* + * We're returning a DFS redirect. If we have + * the targetpath, parse it here. This will ease + * the code transition to SMB_VFS_READ_DFS_PATHAT(). + * (which will make this code redundent). + */ + if (pp_targetpath != NULL) { + struct referral *preflist = NULL; + size_t referral_count = 0; + + bool ok = parse_msdfs_symlink(ctx, + lp_msdfs_shuffle_referrals(SNUM(conn)), + *pp_targetpath, + &preflist, + &referral_count); + TALLOC_FREE(preflist); + if (!ok) { + status = NT_STATUS_NO_MEMORY; + } + } + + } + TALLOC_FREE(smb_fname); return status; } -- 2.25.0.265.gbab2e86ba0-goog From 13a42849d231d8a67492caabec53c6709973f6d4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Feb 2020 13:17:51 -0800 Subject: [PATCH 20/23] s3: DFS: Change dfs_path_lookup() to return struct referral list and count directly. Remove external parse of returned link targetpath, expose the parsing previously added to dfs_path_lookup(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 1668c9ee15b421093756ac9d709f55ce3e808791) --- source3/smbd/msdfs.c | 56 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index ada261651cb..681b170f527 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -730,7 +730,8 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, server+share+extrapath. */ uint32_t ucf_flags, int *consumedcntp, - char **pp_targetpath) + struct referral **ppreflist, + size_t *preferral_count) { char *p = NULL; char *q = NULL; @@ -738,6 +739,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, struct smb_filename *smb_fname = NULL; char *canon_dfspath = NULL; /* Canonicalized dfs path. (only '/' components). */ + char *targetpath = NULL; DEBUG(10,("dfs_path_lookup: Conn path = %s reqpath = %s\n", conn->connectpath, pdp->reqpath)); @@ -764,7 +766,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, /* Optimization - check if we can redirect the whole path. */ - if (is_msdfs_link_internal(ctx, conn, smb_fname, pp_targetpath)) { + if (is_msdfs_link_internal(ctx, conn, smb_fname, &targetpath)) { /* XX_ALLOW_WCARD_XXX is called from search functions. */ if (ucf_flags & (UCF_COND_ALLOW_WCARD_LCOMP| @@ -777,7 +779,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, DEBUG(6,("dfs_path_lookup: %s resolves to a " "valid dfs link %s.\n", dfspath, - pp_targetpath ? *pp_targetpath : "")); + targetpath != NULL ? targetpath : "")); if (consumedcntp) { *consumedcntp = strlen(dfspath); @@ -827,7 +829,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, } if (is_msdfs_link_internal(ctx, conn, - smb_fname, pp_targetpath)) { + smb_fname, &targetpath)) { DEBUG(4, ("dfs_path_lookup: Redirecting %s because " "parent %s is dfs link\n", dfspath, smb_fname_str_dbg(smb_fname))); @@ -863,16 +865,12 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, * the code transition to SMB_VFS_READ_DFS_PATHAT(). * (which will make this code redundent). */ - if (pp_targetpath != NULL) { - struct referral *preflist = NULL; - size_t referral_count = 0; - + if (targetpath != NULL) { bool ok = parse_msdfs_symlink(ctx, lp_msdfs_shuffle_referrals(SNUM(conn)), - *pp_targetpath, - &preflist, - &referral_count); - TALLOC_FREE(preflist); + targetpath, + ppreflist, + preferral_count); if (!ok) { status = NT_STATUS_NO_MEMORY; } @@ -880,6 +878,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, } + TALLOC_FREE(targetpath); TALLOC_FREE(smb_fname); return status; } @@ -971,8 +970,14 @@ static NTSTATUS dfs_redirect(TALLOC_CTX *ctx, return NT_STATUS_OBJECT_PATH_NOT_FOUND; } - status = dfs_path_lookup(ctx, conn, path_in, pdp, - ucf_flags, NULL, NULL); + status = dfs_path_lookup(ctx, + conn, + path_in, + pdp, + ucf_flags, + NULL, /* int *consumedcntp */ + NULL, /* struct referral **ppreflist */ + NULL); /* size_t *preferral_count */ if (!NT_STATUS_IS_OK(status)) { if (NT_STATUS_EQUAL(status, NT_STATUS_PATH_NOT_COVERED)) { DEBUG(3,("dfs_redirect: Redirecting %s\n", path_in)); @@ -1051,7 +1056,6 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, loadparm_s3_global_substitution(); struct conn_struct_tos *c = NULL; struct connection_struct *conn = NULL; - char *targetpath = NULL; int snum; NTSTATUS status = NT_STATUS_NOT_FOUND; bool dummy; @@ -1192,8 +1196,14 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, /* If this is a DFS path dfs_lookup should return * NT_STATUS_PATH_NOT_COVERED. */ - status = dfs_path_lookup(ctx, conn, dfs_path, pdp, - 0, consumedcntp, &targetpath); + status = dfs_path_lookup(ctx, + conn, + dfs_path, + pdp, + 0, /* ucf_flags */ + consumedcntp, + &jucn->referral_list, + &jucn->referral_count); if (!NT_STATUS_EQUAL(status, NT_STATUS_PATH_NOT_COVERED)) { DEBUG(3,("get_referred_path: No valid referrals for path %s\n", @@ -1214,18 +1224,6 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx, goto err_exit; } - /* We know this is a valid dfs link. Parse the targetpath. */ - if (!parse_msdfs_symlink(ctx, - lp_msdfs_shuffle_referrals(snum), - targetpath, - &jucn->referral_list, - &jucn->referral_count)) { - DEBUG(3,("get_referred_path: failed to parse symlink " - "target %s\n", targetpath )); - status = NT_STATUS_NOT_FOUND; - goto err_exit; - } - status = NT_STATUS_OK; err_exit: TALLOC_FREE(frame); -- 2.25.0.265.gbab2e86ba0-goog From 6c03da672c5632ac408cd3e226a3a16d20d61eec Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Feb 2020 13:41:56 -0800 Subject: [PATCH 21/23] s3: DFS: Replace calls to is_msdfs_link_internal() inside dfs_path_lookup() with SMB_VFS_READ_DFS_PATHAT(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 3c77a9e7116bc3f1e3c9bf89c28a32bdb6cdffe1) --- source3/smbd/msdfs.c | 53 ++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 681b170f527..023800ce97d 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -739,7 +739,6 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, struct smb_filename *smb_fname = NULL; char *canon_dfspath = NULL; /* Canonicalized dfs path. (only '/' components). */ - char *targetpath = NULL; DEBUG(10,("dfs_path_lookup: Conn path = %s reqpath = %s\n", conn->connectpath, pdp->reqpath)); @@ -766,7 +765,14 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, /* Optimization - check if we can redirect the whole path. */ - if (is_msdfs_link_internal(ctx, conn, smb_fname, &targetpath)) { + status = SMB_VFS_READ_DFS_PATHAT(conn, + ctx, + conn->cwd_fsp, + smb_fname, + ppreflist, + preferral_count); + + if (NT_STATUS_IS_OK(status)) { /* XX_ALLOW_WCARD_XXX is called from search functions. */ if (ucf_flags & (UCF_COND_ALLOW_WCARD_LCOMP| @@ -777,9 +783,8 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, goto out; } - DEBUG(6,("dfs_path_lookup: %s resolves to a " - "valid dfs link %s.\n", dfspath, - targetpath != NULL ? targetpath : "")); + DBG_INFO("%s resolves to a valid dfs link\n", + dfspath); if (consumedcntp) { *consumedcntp = strlen(dfspath); @@ -828,11 +833,18 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, *q = '\0'; } - if (is_msdfs_link_internal(ctx, conn, - smb_fname, &targetpath)) { - DEBUG(4, ("dfs_path_lookup: Redirecting %s because " - "parent %s is dfs link\n", dfspath, - smb_fname_str_dbg(smb_fname))); + status = SMB_VFS_READ_DFS_PATHAT(conn, + ctx, + conn->cwd_fsp, + smb_fname, + ppreflist, + preferral_count); + + if (NT_STATUS_IS_OK(status)) { + DBG_INFO("Redirecting %s because " + "parent %s is a dfs link\n", + dfspath, + smb_fname_str_dbg(smb_fname)); if (consumedcntp) { *consumedcntp = strlen(canon_dfspath); @@ -858,27 +870,6 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, status = NT_STATUS_OK; out: - if (NT_STATUS_EQUAL(status, NT_STATUS_PATH_NOT_COVERED)) { - /* - * We're returning a DFS redirect. If we have - * the targetpath, parse it here. This will ease - * the code transition to SMB_VFS_READ_DFS_PATHAT(). - * (which will make this code redundent). - */ - if (targetpath != NULL) { - bool ok = parse_msdfs_symlink(ctx, - lp_msdfs_shuffle_referrals(SNUM(conn)), - targetpath, - ppreflist, - preferral_count); - if (!ok) { - status = NT_STATUS_NO_MEMORY; - } - } - - } - - TALLOC_FREE(targetpath); TALLOC_FREE(smb_fname); return status; } -- 2.25.0.265.gbab2e86ba0-goog From 14b29eb1a47f72f8150d793fe1a4029307d41f60 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Feb 2020 13:52:58 -0800 Subject: [PATCH 22/23] s3: DFS: Change the last use of is_msdfs_link_internal() -> SMB_VFS_READ_DFS_PATHAT() inside form_junctions(). is_msdfs_link_internal() is no longer used. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme (cherry picked from commit 94068b5438013479b0426fea7f83bbd7f8f935e9) --- source3/smbd/msdfs.c | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 023800ce97d..6a6ee3fd5f2 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -620,6 +620,7 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, return true; } +#if 0 /********************************************************************** Returns true if the unix path is a valid msdfs symlink and also returns the target string from inside the link. @@ -691,6 +692,7 @@ static bool is_msdfs_link_internal(TALLOC_CTX *ctx, } return False; } +#endif /********************************************************************** Returns true if the unix path is a valid msdfs symlink. @@ -1778,7 +1780,6 @@ static int form_junctions(TALLOC_CTX *ctx, while ((dname = vfs_readdirname(conn, dirp, NULL, &talloced)) != NULL) { - char *link_target = NULL; struct smb_filename *smb_dname = NULL; if (cnt >= jn_remain) { @@ -1796,28 +1797,24 @@ static int form_junctions(TALLOC_CTX *ctx, TALLOC_FREE(talloced); goto out; } - if (is_msdfs_link_internal(ctx, - conn, - smb_dname, &link_target)) { - if (parse_msdfs_symlink(ctx, - lp_msdfs_shuffle_referrals(snum), - link_target, - &jucn[cnt].referral_list, - &jucn[cnt].referral_count)) { - - jucn[cnt].service_name = talloc_strdup(ctx, - service_name); - jucn[cnt].volume_name = talloc_strdup(ctx, - dname); - if (!jucn[cnt].service_name || - !jucn[cnt].volume_name) { - TALLOC_FREE(talloced); - goto out; - } - jucn[cnt].comment = ""; - cnt++; + + status = SMB_VFS_READ_DFS_PATHAT(conn, + ctx, + conn->cwd_fsp, + smb_dname, + &jucn[cnt].referral_list, + &jucn[cnt].referral_count); + + if (NT_STATUS_IS_OK(status)) { + jucn[cnt].service_name = talloc_strdup(ctx, + service_name); + jucn[cnt].volume_name = talloc_strdup(ctx, dname); + if (!jucn[cnt].service_name || !jucn[cnt].volume_name) { + TALLOC_FREE(talloced); + goto out; } - TALLOC_FREE(link_target); + jucn[cnt].comment = ""; + cnt++; } TALLOC_FREE(talloced); TALLOC_FREE(smb_dname); -- 2.25.0.265.gbab2e86ba0-goog From 950c3b304ef1e2ab937bbc70d40313396014116d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 12 Feb 2020 13:54:08 -0800 Subject: [PATCH 23/23] s3: DFS: Remove is_msdfs_link_internal() - no longer used. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All DFS links are now read through the VFS and not via symlink calls. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14282 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Tue Feb 18 22:34:16 UTC 2020 on sn-devel-184 (cherry picked from commit 9ee1320049cf148a2bb102bbdee4a4bcc24c0de1) --- source3/smbd/msdfs.c | 74 -------------------------------------------- 1 file changed, 74 deletions(-) diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 6a6ee3fd5f2..cc32ebc9d29 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -620,80 +620,6 @@ bool parse_msdfs_symlink(TALLOC_CTX *ctx, return true; } -#if 0 -/********************************************************************** - Returns true if the unix path is a valid msdfs symlink and also - returns the target string from inside the link. -**********************************************************************/ - -static bool is_msdfs_link_internal(TALLOC_CTX *ctx, - connection_struct *conn, - struct smb_filename *smb_fname, - char **pp_link_target) -{ - int referral_len = 0; -#if defined(HAVE_BROKEN_READLINK) - char link_target_buf[PATH_MAX]; -#else - char link_target_buf[7]; -#endif - size_t bufsize = 0; - char *link_target = NULL; - - if (pp_link_target) { - bufsize = 1024; - link_target = talloc_array(ctx, char, bufsize); - if (!link_target) { - return False; - } - *pp_link_target = link_target; - } else { - bufsize = sizeof(link_target_buf); - link_target = link_target_buf; - } - - if (SMB_VFS_LSTAT(conn, smb_fname) != 0) { - DEBUG(5,("is_msdfs_link_read_target: %s does not exist.\n", - smb_fname->base_name)); - goto err; - } - if (!S_ISLNK(smb_fname->st.st_ex_mode)) { - DEBUG(5,("is_msdfs_link_read_target: %s is not a link.\n", - smb_fname->base_name)); - goto err; - } - - referral_len = SMB_VFS_READLINKAT(conn, - conn->cwd_fsp, - smb_fname, - link_target, - bufsize - 1); - - if (referral_len == -1) { - DEBUG(0,("is_msdfs_link_read_target: Error reading " - "msdfs link %s: %s\n", - smb_fname->base_name, strerror(errno))); - goto err; - } - link_target[referral_len] = '\0'; - - DEBUG(5,("is_msdfs_link_internal: %s -> %s\n", smb_fname->base_name, - link_target)); - - if (!strnequal(link_target, "msdfs:", 6)) { - goto err; - } - return True; - - err: - - if (link_target != link_target_buf) { - TALLOC_FREE(link_target); - } - return False; -} -#endif - /********************************************************************** Returns true if the unix path is a valid msdfs symlink. **********************************************************************/ -- 2.25.0.265.gbab2e86ba0-goog