]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify msdfs_link_string()
authorVolker Lendecke <vl@samba.org>
Wed, 15 Jul 2026 10:12:21 +0000 (12:12 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 30 Jul 2026 13:11:31 +0000 (13:11 +0000)
Use talloc_asprintf_addsep()

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/smbd/msdfs.c

index ca50a285bd7fc5f8a6875d9f1abf631c176e82e5..e6a46432825b7b7999bb290c144ac999c1cfd16c 100644 (file)
@@ -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: