From: Jeremy Allison Date: Fri, 13 Dec 2019 19:48:05 +0000 (-0800) Subject: s3: smbd: msdfs: Factor out the code to create a msdfs:referral,list into a separate... X-Git-Tag: ldb-2.1.0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2d54bfce8e389473cdb546155dc58d547011f9;p=thirdparty%2Fsamba.git s3: smbd: msdfs: Factor out the code to create a msdfs:referral,list into a separate function. This will allow it to be called from other places once the get/set_msdfs calls are moved into being first class VFS functions. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Mon Dec 16 15:32:08 UTC 2019 on sn-devel-184 --- diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index da9b847b96d..0fc7a6313a2 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -1357,38 +1357,38 @@ static bool junction_to_local_path_tos(const struct junction_map *jucn, return True; } -bool create_msdfs_link(const struct junction_map *jucn) +/* + * Create a msdfs string in Samba format we can store + * in a filesystem object (currently a symlink). + */ + +char *msdfs_link_string(TALLOC_CTX *ctx, + const struct referral *reflist, + size_t referral_count) { - TALLOC_CTX *frame = talloc_stackframe(); - char *path = NULL; + char *refpath = NULL; + bool insert_comma = false; char *msdfs_link = NULL; - connection_struct *conn; - size_t i = 0; - bool insert_comma = False; - bool ret = False; - struct smb_filename *smb_fname = NULL; - bool ok; - int retval; - - ok = junction_to_local_path_tos(jucn, &path, &conn); - if (!ok) { - TALLOC_FREE(frame); - return False; - } + size_t i; /* Form the msdfs_link contents */ - msdfs_link = talloc_strdup(conn, "msdfs:"); - if (!msdfs_link) { - goto out; + msdfs_link = talloc_strdup(ctx, "msdfs:"); + if (msdfs_link == NULL) { + goto err; } - for(i=0; ireferral_count; i++) { - char *refpath = jucn->referral_list[i].alternate_path; + + for( i= 0; i < referral_count; i++) { + refpath = talloc_strdup(ctx, reflist[i].alternate_path); + + if (refpath == NULL) { + goto err; + } /* Alternate paths always use Windows separators. */ trim_char(refpath, '\\', '\\'); - if(*refpath == '\0') { + if (*refpath == '\0') { if (i == 0) { - insert_comma = False; + insert_comma = false; } continue; } @@ -1402,12 +1402,49 @@ bool create_msdfs_link(const struct junction_map *jucn) refpath); } - if (!msdfs_link) { - goto out; + if (msdfs_link == NULL) { + goto err; } + if (!insert_comma) { - insert_comma = True; + insert_comma = true; } + + TALLOC_FREE(refpath); + } + + return msdfs_link; + + err: + + TALLOC_FREE(refpath); + TALLOC_FREE(msdfs_link); + return NULL; +} + +bool create_msdfs_link(const struct junction_map *jucn) +{ + TALLOC_CTX *frame = talloc_stackframe(); + char *path = NULL; + char *msdfs_link = NULL; + connection_struct *conn; + bool ret = False; + struct smb_filename *smb_fname = NULL; + bool ok; + int retval; + + ok = junction_to_local_path_tos(jucn, &path, &conn); + if (!ok) { + TALLOC_FREE(frame); + return False; + } + + /* Form the msdfs_link contents */ + msdfs_link = msdfs_link_string(frame, + jucn->referral_list, + jucn->referral_count); + if (msdfs_link == NULL) { + goto out; } DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n", diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 378c5d04918..8d491c24bf3 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -486,6 +486,10 @@ bool create_junction(TALLOC_CTX *ctx, const char *dfs_path, bool allow_broken_path, struct junction_map *jucn); +struct referral; +char *msdfs_link_string(TALLOC_CTX *ctx, + const struct referral *reflist, + size_t referral_count); bool create_msdfs_link(const struct junction_map *jucn); bool remove_msdfs_link(const struct junction_map *jucn); struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx, size_t *p_num_jn);