[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed May 18 17:43:02 UTC 2022


The branch, master has been updated
       via  04e0e02c695 srvsvc: Announce [username] in NetShareEnum
       via  20cbade5b16 srvsvc: Add a central return point to init_srv_share_info_ctr()
       via  31451318092 selftest: Test for bug 15062 -- list "username" in netshareenum
      from  91d8bc7ac2b gitlab-ci: Update Fedora to version 36

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


- Log -----------------------------------------------------------------
commit 04e0e02c6951e327130210e44deb87b9a303cdb3
Author: Volker Lendecke <vl at samba.org>
Date:   Wed May 18 16:01:08 2022 +0200

    srvsvc: Announce [username] in NetShareEnum
    
    This patch has two flaws: First, it does not cover api_RNetShareEnum()
    for SMB1, and the second one is: To make this elegant, we would have
    to restructure our share handling. It is really only listing shares
    for which we have to pull in everything from smb.conf, registry,
    usershares and potentially printers. What we should do is modify our
    loadparm handling to only load share definitions on demand and for
    listing shares handle all the potential sources specially. Add code
    that walks the registry shares without adding them to our services
    list and so on.
    
    This patch is the quick&dirty way to fix the bug, the alternative
    would be weeks or more. And hopefully nobody notices the SMB1
    problem...
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15062
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed May 18 17:42:20 UTC 2022 on sn-devel-184

commit 20cbade5b164c0e9eec744bd5a564110923a0c61
Author: Volker Lendecke <vl at samba.org>
Date:   Wed May 18 15:39:23 2022 +0200

    srvsvc: Add a central return point to init_srv_share_info_ctr()
    
    Soon there will be cleanup work to do.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15062
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3145131809269a33ad07261f94ee6e09e1850365
Author: Volker Lendecke <vl at samba.org>
Date:   Wed May 18 14:40:49 2022 +0000

    selftest: Test for bug 15062 -- list "username" in netshareenum
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=15062
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

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

Summary of changes:
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c      | 114 +++++++++++++++++++------
 source3/script/tests/test_user_in_sharelist.sh |  22 +++++
 source3/selftest/tests.py                      |   6 ++
 3 files changed, 116 insertions(+), 26 deletions(-)
 create mode 100755 source3/script/tests/test_user_in_sharelist.sh


Changeset truncated at 500 lines:

diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
index e863bdf3dab..99808ee8f3a 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -610,6 +610,9 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 				      uint32_t *total_entries,
 				      bool all_shares)
 {
+	struct dcesrv_call_state *dce_call = p->dce_call;
+	struct auth_session_info *session_info =
+		dcesrv_call_session_info(dce_call);
 	const struct loadparm_substitution *lp_sub =
 		loadparm_s3_global_substitution();
 	uint32_t num_entries = 0;
@@ -622,6 +625,10 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 	bool *allowed = 0;
 	union srvsvc_NetShareCtr ctr;
 	uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
+	const char *unix_name = session_info->unix_info->unix_name;
+	int existing_home = lp_servicenumber(unix_name);
+	int added_home = -1;
+	WERROR ret = WERR_OK;
 
 	DEBUG(5,("init_srv_share_info_ctr\n"));
 
@@ -630,11 +637,18 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 	delete_and_reload_printers();
 	load_usershare_shares(NULL, connections_snum_used);
 	load_registry_shares();
-	num_services = lp_numservices();
 	unbecome_root();
 
+	if (existing_home == -1) {
+		added_home = register_homes_share(unix_name);
+	}
+
+	num_services = lp_numservices();
+
         allowed = talloc_zero_array(ctx, bool, num_services);
-        W_ERROR_HAVE_NO_MEMORY(allowed);
+	if (allowed == NULL) {
+		goto nomem;
+	}
 
         /* Count the number of entries. */
         for (snum = 0; snum < num_services; snum++) {
@@ -652,7 +666,7 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
         }
 
 	if (!num_entries || (resume_handle >= num_entries)) {
-		return WERR_OK;
+		goto done;
 	}
 
 	/* Calculate alloc entries. */
@@ -660,11 +674,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 	switch (info_ctr->level) {
 	case 0:
 		ctr.ctr0 = talloc_zero(ctx, struct srvsvc_NetShareCtr0);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr0);
+		if (ctr.ctr0 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr0->count = alloc_entries;
 		ctr.ctr0->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo0, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr0->array);
+		if (ctr.ctr0->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -677,11 +695,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1:
 		ctr.ctr1 = talloc_zero(ctx, struct srvsvc_NetShareCtr1);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1);
+		if (ctr.ctr1 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1->count = alloc_entries;
 		ctr.ctr1->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1->array);
+		if (ctr.ctr1->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -694,11 +716,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 2:
 		ctr.ctr2 = talloc_zero(ctx, struct srvsvc_NetShareCtr2);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr2);
+		if (ctr.ctr2 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr2->count = alloc_entries;
 		ctr.ctr2->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo2, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr2->array);
+		if (ctr.ctr2->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -712,11 +738,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 501:
 		ctr.ctr501 = talloc_zero(ctx, struct srvsvc_NetShareCtr501);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr501);
+		if (ctr.ctr501 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr501->count = alloc_entries;
 		ctr.ctr501->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo501, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr501->array);
+		if (ctr.ctr501->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -729,11 +759,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 502:
 		ctr.ctr502 = talloc_zero(ctx, struct srvsvc_NetShareCtr502);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr502);
+		if (ctr.ctr502 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr502->count = alloc_entries;
 		ctr.ctr502->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo502, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr502->array);
+		if (ctr.ctr502->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -746,11 +780,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1004:
 		ctr.ctr1004 = talloc_zero(ctx, struct srvsvc_NetShareCtr1004);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004);
+		if (ctr.ctr1004 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1004->count = alloc_entries;
 		ctr.ctr1004->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1004, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004->array);
+		if (ctr.ctr1004->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -763,11 +801,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1005:
 		ctr.ctr1005 = talloc_zero(ctx, struct srvsvc_NetShareCtr1005);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005);
+		if (ctr.ctr1005 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1005->count = alloc_entries;
 		ctr.ctr1005->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1005, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005->array);
+		if (ctr.ctr1005->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -780,11 +822,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1006:
 		ctr.ctr1006 = talloc_zero(ctx, struct srvsvc_NetShareCtr1006);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006);
+		if (ctr.ctr1006 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1006->count = alloc_entries;
 		ctr.ctr1006->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1006, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006->array);
+		if (ctr.ctr1006->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -797,11 +843,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1007:
 		ctr.ctr1007 = talloc_zero(ctx, struct srvsvc_NetShareCtr1007);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007);
+		if (ctr.ctr1007 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1007->count = alloc_entries;
 		ctr.ctr1007->array = talloc_zero_array(ctx, struct srvsvc_NetShareInfo1007, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007->array);
+		if (ctr.ctr1007->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -814,11 +864,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 
 	case 1501:
 		ctr.ctr1501 = talloc_zero(ctx, struct srvsvc_NetShareCtr1501);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501);
+		if (ctr.ctr1501 == NULL) {
+			goto nomem;
+		}
 
 		ctr.ctr1501->count = alloc_entries;
 		ctr.ctr1501->array = talloc_zero_array(ctx, struct sec_desc_buf, alloc_entries);
-		W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501->array);
+		if (ctr.ctr1501->array == NULL) {
+			goto nomem;
+		}
 
 		for (snum = 0; snum < num_services; snum++) {
 			if (allowed[snum] &&
@@ -834,7 +888,8 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 	default:
 		DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n",
 			info_ctr->level));
-		return WERR_INVALID_LEVEL;
+		ret = WERR_INVALID_LEVEL;
+		goto done;
 	}
 
 	*total_entries = alloc_entries;
@@ -847,8 +902,15 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p,
 	}
 
 	info_ctr->ctr = ctr;
-
-	return WERR_OK;
+	ret = WERR_OK;
+	goto done;
+nomem:
+	ret = WERR_NOT_ENOUGH_MEMORY;
+done:
+	if (added_home != -1) {
+		lp_killservice(added_home);
+	}
+	return ret;
 }
 
 /*******************************************************************
diff --git a/source3/script/tests/test_user_in_sharelist.sh b/source3/script/tests/test_user_in_sharelist.sh
new file mode 100755
index 00000000000..1abd554f90b
--- /dev/null
+++ b/source3/script/tests/test_user_in_sharelist.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+if [ $# -lt 2 ]; then
+    echo Usage: $0 RPCCLIENT SERVER
+    exit 1
+fi
+
+incdir=$(dirname $0)/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+failed=0
+
+RPCCLIENT="$1"; shift 1
+SERVER="$1"; shift 1
+
+"${RPCCLIENT}" "${SERVER}" -U"${USER}"%"${PASSWORD}" -c netshareenum |
+    grep "^netname: $USER\$"
+RC=$?
+testit "Verify username is listed in netshareenum due to [homes]" \
+       test $RC = 0 || failed=$((failed+1))
+
+testok $0 $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index a43889b5964..5502e498124 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -1218,6 +1218,12 @@ plantestsuite("samba3.blackbox.netfileenum", "simpleserver:local",
                '$SERVER_IP',
                'tmp'])
 
+plantestsuite("samba3.blackbox.netshareenum_username", "fileserver",
+              [os.path.join(samba3srcdir,
+                            "script/tests/test_user_in_sharelist.sh"),
+               os.path.join(bindir(), "rpcclient"),
+               '$SERVER_IP'])
+
 plantestsuite("samba3.blackbox.net_tdb", "simpleserver:local",
               [os.path.join(samba3srcdir, "script/tests/test_net_tdb.sh"),
                smbclient3, '$SERVER', 'tmp', '$USERNAME', '$PASSWORD',


-- 
Samba Shared Repository



More information about the samba-cvs mailing list