From: Volker Lendecke Date: Wed, 15 Jul 2026 10:12:21 +0000 (+0200) Subject: smbd: Simplify msdfs_link_string() X-Git-Tag: tevent-0.17.2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=119603c8e87ea985bde24703ae0dc54afc78a176;p=thirdparty%2Fsamba.git smbd: Simplify msdfs_link_string() Use talloc_asprintf_addsep() Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index ca50a285bd7..e6a46432825 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -1069,15 +1069,11 @@ char *msdfs_link_string(TALLOC_CTX *ctx, size_t referral_count) { char *refpath = NULL; - bool insert_comma = false; char *msdfs_link = NULL; + char *referrals = NULL; size_t i; - /* Form the msdfs_link contents */ - msdfs_link = talloc_strdup(ctx, "msdfs:"); - if (msdfs_link == NULL) { - goto err; - } + referrals = talloc_strdup(ctx, ""); for( i= 0; i < referral_count; i++) { refpath = talloc_strdup(ctx, reflist[i].alternate_path); @@ -1089,30 +1085,19 @@ char *msdfs_link_string(TALLOC_CTX *ctx, /* Alternate paths always use Windows separators. */ trim_char(refpath, '\\', '\\'); if (*refpath == '\0') { - if (i == 0) { - insert_comma = false; - } continue; } - if (i > 0 && insert_comma) { - msdfs_link = talloc_asprintf_append_buffer(msdfs_link, - ",%s", - refpath); - } else { - msdfs_link = talloc_asprintf_append_buffer(msdfs_link, - "%s", - refpath); - } - - if (msdfs_link == NULL) { - goto err; - } - - insert_comma = true; + talloc_asprintf_addsep(&referrals, ",", "%s", refpath); TALLOC_FREE(refpath); } + if (referrals == NULL) { + goto err; + } + + msdfs_link = talloc_asprintf(ctx, "msdfs:%s", referrals); + TALLOC_FREE(referrals); return msdfs_link; err: