s3: smbd: msdfs: Factor out the code to create a msdfs:referral,list into a separate...
authorJeremy Allison <jra@samba.org>
Fri, 13 Dec 2019 19:48:05 +0000 (11:48 -0800)
committerRalph Boehme <slow@samba.org>
Mon, 16 Dec 2019 15:32:08 +0000 (15:32 +0000)
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 <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Mon Dec 16 15:32:08 UTC 2019 on sn-devel-184

source3/smbd/msdfs.c
source3/smbd/proto.h

index da9b847b96d315ff82643376e46fd42319dae301..0fc7a6313a2a0bf9e4bba9bc1c1ca6e633d867bd 100644 (file)
@@ -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; i<jucn->referral_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",
index 378c5d04918456bc453aa779911aaf9398886897..8d491c24bf3abf1b63f1f915948aeb37203d0899 100644 (file)
@@ -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);