[SCM] Samba Shared Repository - branch master updated

Stefan Metzmacher metze at samba.org
Thu May 14 22:07:02 UTC 2020


The branch, master has been updated
       via  01db877c776 srvsvc: Move brl_get_locks() out of enum_file_fn()
       via  8e4583f730a test: Show that netfileenum is broken
       via  1d40cc01c2d rpcclient: Make netfileenum cmd print the path names
       via  8c080f28c37 rpcclient: Use struct initializers in cmd_srvsvc_net_file_enum()
       via  46ab1d478d8 srvsvc: Collect file ids in enum_file_fn()
       via  bda0b3875d9 srvsvc: Use a struct initializer in net_enum_files()
       via  96d68bb9f26 srvsvc: Directly use "ctr3->count" instead of "i"
       via  ff80f68c302 srvsvc: Use a struct assignment in enum_file_fn()
       via  a9397f87881 srvsvc: Introduce ctx3 helper var in enum_file_fn()
      from  7215669d297 vfs: remove root_dir_fid arg from SMB_VFS_CREATE_FILE()

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


- Log -----------------------------------------------------------------
commit 01db877c7766387984ef32914eca0b2e817c4c6a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:54:25 2020 +0200

    srvsvc: Move brl_get_locks() out of enum_file_fn()
    
    With share_infos.tdb this is a locking order violation:
    share_infos.tdb is level 4, brlock.tdb is level 2. Avoid this by first
    walking the share_infos.tdb and then fetching all the brlock entries.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(master): Thu May 14 22:06:32 UTC 2020 on sn-devel-184

commit 8e4583f730abd1a210ec52d5a060dddc4ad850bb
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 11 11:08:54 2020 +0200

    test: Show that netfileenum is broken
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 1d40cc01c2d7f14704c1d9b4b7c42c4cf3450da9
Author: Volker Lendecke <vl at samba.org>
Date:   Mon May 11 11:09:02 2020 +0200

    rpcclient: Make netfileenum cmd print the path names
    
    Needed for the next commit testing netfileenum
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8c080f28c37a4ada4f3605123a357666881fa3a0
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Apr 22 13:21:40 2020 +0200

    rpcclient: Use struct initializers in cmd_srvsvc_net_file_enum()
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 46ab1d478d8c27bb4837bf277f8eae5d59613dd2
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:32:16 2020 +0200

    srvsvc: Collect file ids in enum_file_fn()
    
    Will be used a few patches down
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit bda0b3875d965c5cccd09dc09f593229e268ee9b
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:42:50 2020 +0200

    srvsvc: Use a struct initializer in net_enum_files()
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 96d68bb9f26a0c99d00e92130a2f2c91c7b985e2
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:24:48 2020 +0200

    srvsvc: Directly use "ctr3->count" instead of "i"
    
    To me this was not very transparent, and now that we have "ctr3" a
    single indirect looks okay
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit ff80f68c3020be0a92eb41115a64518ece097ee7
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:21:49 2020 +0200

    srvsvc: Use a struct assignment in enum_file_fn()
    
    Looks nicer than 5 complex array references...
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit a9397f87881b9a67407b557e09478cdd40f75b75
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Apr 21 14:16:41 2020 +0200

    srvsvc: Introduce ctx3 helper var in enum_file_fn()
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=14355
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

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

Summary of changes:
 source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 74 +++++++++++++++++++------------
 source3/rpcclient/cmd_srvsvc.c            | 29 +++++++-----
 source3/script/tests/test_netfileenum.sh  | 73 ++++++++++++++++++++++++++++++
 source3/selftest/tests.py                 |  9 ++++
 4 files changed, 145 insertions(+), 40 deletions(-)
 create mode 100755 source3/script/tests/test_netfileenum.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 17391424fc0..3fb8427693b 100644
--- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
+++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c
@@ -54,6 +54,7 @@ struct file_enum_count {
 	TALLOC_CTX *ctx;
 	const char *username;
 	struct srvsvc_NetFileCtr3 *ctr3;
+	struct file_id *fids;
 };
 
 struct sess_file_info {
@@ -88,12 +89,9 @@ static int enum_file_fn(struct file_id id,
 {
 	struct file_enum_count *fenum =
 		(struct file_enum_count *)private_data;
-
+	struct srvsvc_NetFileCtr3 *ctr3 = fenum->ctr3;
 	struct srvsvc_NetFileInfo3 *f;
-	int i = fenum->ctr3->count;
-	files_struct fsp;
-	struct byte_range_lock *brl;
-	int num_locks = 0;
+	struct file_id *fids = NULL;
 	char *fullpath = NULL;
 	uint32_t permissions;
 	const char *username;
@@ -111,23 +109,25 @@ static int enum_file_fn(struct file_id id,
 		return 0;
 	}
 
-	f = talloc_realloc(fenum->ctx, fenum->ctr3->array,
-				 struct srvsvc_NetFileInfo3, i+1);
+	f = talloc_realloc(
+		fenum->ctx,
+		ctr3->array,
+		struct srvsvc_NetFileInfo3,
+		ctr3->count+1);
 	if ( !f ) {
-		DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
+		DBG_ERR("realloc failed for %"PRIu32" items\n", ctr3->count+1);
 		return 0;
 	}
-	fenum->ctr3->array = f;
-
-	/* need to count the number of locks on a file */
+	ctr3->array = f;
 
-	ZERO_STRUCT( fsp );
-	fsp.file_id = id;
-
-	if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
-		num_locks = brl_num_locks(brl);
-		TALLOC_FREE(brl);
+	fids = talloc_realloc(
+		fenum->ctx, fenum->fids, struct file_id, ctr3->count+1);
+	if (fids == NULL) {
+		DBG_ERR("realloc failed for %"PRIu32" items\n", ctr3->count+1);
+		return 0;
 	}
+	fids[ctr3->count] = id;
+	fenum->fids = fids;
 
 	if ( strcmp(d->base_name, "." ) == 0 ) {
 		fullpath = talloc_asprintf(
@@ -152,14 +152,15 @@ static int enum_file_fn(struct file_id id,
 
 	/* now fill in the srvsvc_NetFileInfo3 struct */
 
-	fenum->ctr3->array[i].fid		=
-		(((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id);
-	fenum->ctr3->array[i].permissions	= permissions;
-	fenum->ctr3->array[i].num_locks		= num_locks;
-	fenum->ctr3->array[i].path		= fullpath;
-	fenum->ctr3->array[i].user		= username;
+	ctr3->array[ctr3->count] = (struct srvsvc_NetFileInfo3) {
+		.fid	 	= (((uint32_t)(procid_to_pid(&e->pid))<<16) |
+				   e->share_file_id),
+		.permissions 	= permissions,
+		.path		= fullpath,
+		.user		= username,
+	};
 
-	fenum->ctr3->count++;
+	ctr3->count++;
 
 	return 0;
 }
@@ -172,16 +173,31 @@ static WERROR net_enum_files(TALLOC_CTX *ctx,
 			     struct srvsvc_NetFileCtr3 **ctr3,
 			     uint32_t resume)
 {
-	struct file_enum_count f_enum_cnt;
-
-	f_enum_cnt.ctx = ctx;
-	f_enum_cnt.username = username;
-	f_enum_cnt.ctr3 = *ctr3;
+	struct file_enum_count f_enum_cnt = {
+		.ctx = ctx, .username = username, .ctr3 = *ctr3,
+	};
+	uint32_t i;
 
 	share_entry_forall(enum_file_fn, (void *)&f_enum_cnt );
 
 	*ctr3 = f_enum_cnt.ctr3;
 
+	/* need to count the number of locks on a file */
+
+	for (i=0; i<(*ctr3)->count; i++) {
+		struct files_struct fsp = { .file_id = f_enum_cnt.fids[i], };
+		struct byte_range_lock *brl = NULL;
+
+		brl = brl_get_locks(ctx, &fsp);
+		if (brl == NULL) {
+			continue;
+		}
+
+		(*ctr3)->array[i].num_locks = brl_num_locks(brl);
+
+		TALLOC_FREE(brl);
+	}
+
 	return WERR_OK;
 }
 
diff --git a/source3/rpcclient/cmd_srvsvc.c b/source3/rpcclient/cmd_srvsvc.c
index 9c000608463..478afc68cd1 100644
--- a/source3/rpcclient/cmd_srvsvc.c
+++ b/source3/rpcclient/cmd_srvsvc.c
@@ -643,9 +643,13 @@ static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
 					 TALLOC_CTX *mem_ctx,
 					 int argc, const char **argv)
 {
-	uint32_t info_level = 3;
-	struct srvsvc_NetFileInfoCtr info_ctr;
-	struct srvsvc_NetFileCtr3 ctr3;
+	struct srvsvc_NetFileCtr3 ctr3 = { 0 };
+	struct srvsvc_NetFileInfoCtr info_ctr = {
+		.level = 3,
+		.ctr = {
+			.ctr3 = &ctr3,
+		},
+	};
 	WERROR result;
 	NTSTATUS status;
 	uint32_t preferred_len = 0xffff;
@@ -658,14 +662,9 @@ static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
 		return WERR_OK;
 	}
 
-	if (argc == 2)
-		info_level = atoi(argv[1]);
-
-	ZERO_STRUCT(info_ctr);
-	ZERO_STRUCT(ctr3);
-
-	info_ctr.level = info_level;
-	info_ctr.ctr.ctr3 = &ctr3;
+	if (argc == 2) {
+		info_ctr.level = atoi(argv[1]);
+	}
 
 	status = dcerpc_srvsvc_NetFileEnum(b, mem_ctx,
 					   cli->desthost,
@@ -685,6 +684,14 @@ static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
 		goto done;
 	}
 
+	if (info_ctr.level == 3) {
+		struct srvsvc_NetFileCtr3 *ret = info_ctr.ctr.ctr3;
+		uint32_t i;
+
+		for (i=0; i<ret->count; i++) {
+			printf("%s\n", ret->array[i].path);
+		}
+	}
  done:
 	return result;
 }
diff --git a/source3/script/tests/test_netfileenum.sh b/source3/script/tests/test_netfileenum.sh
new file mode 100755
index 00000000000..e917ad42862
--- /dev/null
+++ b/source3/script/tests/test_netfileenum.sh
@@ -0,0 +1,73 @@
+#!/bin/bash
+#
+# Test rpcclient netfileenum
+#
+# Copyright (C) 2020 Volker Lendecke
+
+if [ $# -lt 5 ]; then
+    echo Usage: $0 \
+	 SMBCLIENT RPCCLIENT NET SERVER SHARE
+exit 1
+fi
+
+SMBCLIENT="$1"; shift 1
+RPCCLIENT="$1"; shift 1
+NET="$1"; shift 1
+SERVER="$1"; shift 1
+SHARE="$1"; shift 1
+
+incdir=$(dirname $0)/../../../testprogs/blackbox
+. $incdir/subunit.sh
+
+failed=0
+
+rm -f smbclient-stdin smbclient-stdout smbclient-stderr
+mkfifo smbclient-stdin smbclient-stdout smbclient-stderr
+
+CLI_FORCE_INTERACTIVE=1; export CLI_FORCE_INTERACTIVE
+
+${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
+	     < smbclient-stdin > smbclient-stdout 2>smbclient-stderr &
+CLIENT_PID=$!
+
+sleep 1
+
+exec 100>smbclient-stdin 101<smbclient-stdout 102<smbclient-stderr
+
+# consume the smbclient startup messages
+head -n 1 <&101
+head -n 1 <&102
+
+FILE=x64
+
+printf "open %s\\n" "$FILE" >&100
+
+sleep 1
+
+testit "Create builtin\\administrators group" \
+       "${NET}" groupmap add \
+       sid=S-1-5-32-544 unixgroup="${USER}"-group type=builtin || \
+    failed=$((failed+1))
+testit "Add ${USER} to builtin\\administrators" \
+       "${NET}" groupmap addmem S-1-5-32-544 \
+       $("${NET}" lookup name "${USER}" | cut -d' ' -f1) || \
+    failed=$((failed+1))
+
+"${RPCCLIENT}" "${SERVER}" -U"${USER}"%"${PASSWORD}" -c netfileenum |
+    grep "$FILE"\$
+RC=$?
+testit "netfileenum" test $RC = 0 || failed=$((failed+1))
+
+kill ${CLIENT_PID}
+rm -f smbclient-stdin smbclient-stdout smbclient-stderr
+
+testit "Remove ${USER} from builtin\\administrators" \
+       "${NET}" groupmap delmem S-1-5-32-544 \
+       $("${NET}" lookup name "${USER}" | cut -d' ' -f1) || \
+    failed=$((failed+1))
+testit "Remove builtin\\administrators group" \
+       "${NET}" groupmap delete \
+       sid=S-1-5-32-544 || \
+    failed=$((failed+1))
+
+testok $0 $failed
diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
index 7309c05a7a5..38ed8c771c2 100755
--- a/source3/selftest/tests.py
+++ b/source3/selftest/tests.py
@@ -923,6 +923,15 @@ plantestsuite("samba3.blackbox.open-eintr", "simpleserver:local",
                '$SERVER_IP',
                "error_inject"])
 
+plantestsuite("samba3.blackbox.netfileenum", "simpleserver:local",
+              [os.path.join(samba3srcdir,
+                            "script/tests/test_netfileenum.sh"),
+               os.path.join(bindir(), "smbclient"),
+               os.path.join(bindir(), "rpcclient"),
+               os.path.join(bindir(), "net"),
+               '$SERVER_IP',
+               'tmp'])
+
 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