[SCM] Samba Shared Repository - branch master updated

Ralph Böhme slow at samba.org
Mon Dec 16 15:33:02 UTC 2019


The branch, master has been updated
       via  af2d54bfce8 s3: smbd: msdfs: Factor out the code to create a msdfs:referral,list into a separate function.
       via  cc1ec0a9f13 s3: smbd: cleanup. Change 'int referral_count' -> 'size_t referral_count' in struct junction_map.
       via  2048ff3adc4 s3: smbd: msdfs: Cleanup, don't mix int and size_t types for a count variable.
      from  48ed60d7fd0 lib/replace: work around an API conflict between ncurses and XFS xattr API

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit af2d54bfce8e389473cdb546155dc58d547011f9
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 13 11:48:05 2019 -0800

    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 <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    
    Autobuild-User(master): Ralph Böhme <slow at samba.org>
    Autobuild-Date(master): Mon Dec 16 15:32:08 UTC 2019 on sn-devel-184

commit cc1ec0a9f135ec32c05ae04d0b3bd47fdef5d47d
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 13 09:52:31 2019 -0800

    s3: smbd: cleanup. Change 'int referral_count' -> 'size_t referral_count' in struct junction_map.
    
    This is a non-negative count. Fix remaing code to not mix int and size_t.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2048ff3adc4dbff659dfb5d747f0cb93baad06ee
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Dec 13 09:39:55 2019 -0800

    s3: smbd: msdfs: Cleanup, don't mix int and size_t types for a count variable.
    
    Add integer wrap check.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/include/msdfs.h             |   2 +-
 source3/modules/vfs_default.c       |   2 +-
 source3/rpc_server/dfs/srv_dfs_nt.c |  10 ++--
 source3/smbd/msdfs.c                | 103 +++++++++++++++++++++++++-----------
 source3/smbd/proto.h                |   4 ++
 5 files changed, 84 insertions(+), 37 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/include/msdfs.h b/source3/include/msdfs.h
index 333a84082d6..6a851cb3330 100644
--- a/source3/include/msdfs.h
+++ b/source3/include/msdfs.h
@@ -53,7 +53,7 @@ struct junction_map {
 	char *service_name;
 	char *volume_name;
 	const char *comment;
-	int referral_count;
+	size_t referral_count;
 	struct referral* referral_list;
 };
 
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 5666e09f60b..82238e4b96c 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -192,7 +192,7 @@ static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
 	char *pathnamep = NULL;
 	char *local_dfs_path = NULL;
 	NTSTATUS status;
-	int i;
+	size_t i;
 	uint16_t max_referral_level = r->in.req.max_referral_level;
 
 	if (DEBUGLVL(10)) {
diff --git a/source3/rpc_server/dfs/srv_dfs_nt.c b/source3/rpc_server/dfs/srv_dfs_nt.c
index 0a4d6d31b7c..55cd045abd0 100644
--- a/source3/rpc_server/dfs/srv_dfs_nt.c
+++ b/source3/rpc_server/dfs/srv_dfs_nt.c
@@ -162,9 +162,11 @@ WERROR _dfs_Remove(struct pipes_struct *p, struct dfs_Remove *r)
 			return WERR_NERR_DFSNOSUCHVOLUME;
 		}
 	} else {
-		int i=0;
+		size_t i = 0;
 		/* compare each referral in the list with the one to remove */
-		DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn->referral_count));
+		DBG_DEBUG("altpath: .%s. refcnt: %zu\n",
+				altpath,
+				jn->referral_count);
 		for(i=0;i<jn->referral_count;i++) {
 			char *refpath = talloc_strdup(ctx,
 					jn->referral_list[i].alternate_path);
@@ -226,7 +228,7 @@ static bool init_reply_dfs_info_2(TALLOC_CTX *mem_ctx, struct junction_map* j, s
 
 static bool init_reply_dfs_info_3(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info3* dfs3)
 {
-	int ii;
+	size_t ii;
 	if (j->volume_name[0] == '\0')
 		dfs3->path = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
 			lp_netbios_name(), j->service_name);
@@ -268,7 +270,7 @@ static bool init_reply_dfs_info_3(TALLOC_CTX *mem_ctx, struct junction_map* j, s
 			continue;
 		}
 		*p = '\0';
-		DEBUG(5,("storage %d: %s.%s\n",ii,path,p+1));
+		DBG_INFO("storage %zu: %s.%s\n",ii,path,p+1);
 		stor->state = 2; /* set all stores as ONLINE */
 		stor->server = talloc_strdup(mem_ctx, path);
 		stor->share = talloc_strdup(mem_ctx, p+1);
diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c
index a70e795f0ca..0fc7a6313a2 100644
--- a/source3/smbd/msdfs.c
+++ b/source3/smbd/msdfs.c
@@ -535,12 +535,12 @@ static bool parse_msdfs_symlink(TALLOC_CTX *ctx,
 				int snum,
 				const char *target,
 				struct referral **preflist,
-				int *refcount)
+				size_t *refcount)
 {
 	char *temp = NULL;
 	char *prot;
 	char **alt_path = NULL;
-	int count = 0, i;
+	size_t count = 0, i;
 	struct referral *reflist;
 	char *saveptr;
 
@@ -570,7 +570,7 @@ static bool parse_msdfs_symlink(TALLOC_CTX *ctx,
 		shuffle_strlist(alt_path, count);
 	}
 
-	DEBUG(10,("parse_msdfs_symlink: count=%d\n", count));
+	DBG_DEBUG("count=%zu\n", count);
 
 	if (count) {
 		reflist = *preflist = talloc_zero_array(ctx,
@@ -1083,7 +1083,7 @@ NTSTATUS get_referred_path(TALLOC_CTX *ctx,
 	if (pdp->reqpath[0] == '\0') {
 		char *tmp;
 		struct referral *ref;
-		int refcount;
+		size_t refcount;
 
 		if (*lp_msdfs_proxy(talloc_tos(), lp_sub, snum) == '\0') {
 			TALLOC_FREE(frame);
@@ -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;
-	int 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",
@@ -1500,7 +1537,7 @@ bool remove_msdfs_link(const struct junction_map *jucn)
  Return the number of DFS links at the root of this share.
 *********************************************************************/
 
-static int count_dfs_links(TALLOC_CTX *ctx, int snum)
+static size_t count_dfs_links(TALLOC_CTX *ctx, int snum)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
 	const struct loadparm_substitution *lp_sub =
@@ -1573,6 +1610,10 @@ static int count_dfs_links(TALLOC_CTX *ctx, int snum)
 			goto out;
 		}
 		if (is_msdfs_link(conn, smb_dname)) {
+			if (cnt + 1 < cnt) {
+				cnt = 0;
+				goto out;
+			}
 			cnt++;
 		}
 		TALLOC_FREE(talloced);
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);


-- 
Samba Shared Repository



More information about the samba-cvs mailing list