From 22029a515180ef321a06407d0560ca00aa2c19b4 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 22 Apr 2022 15:46:04 +0200 Subject: [PATCH 1/4] testprogs: Reformat subunit.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit shfmt -w -p -i 0 -fn testprogs/blackbox/subunit.sh Signed-off-by: Andreas Schneider Reviewed-by: Pavel Filipenský (cherry picked from commit 561e9256551ae3fe1d6ff4974884714d69d91898) --- testprogs/blackbox/subunit.sh | 115 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/testprogs/blackbox/subunit.sh b/testprogs/blackbox/subunit.sh index 45183575bddb..75a9b5ec7e3c 100755 --- a/testprogs/blackbox/subunit.sh +++ b/testprogs/blackbox/subunit.sh @@ -18,69 +18,74 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -timestamp() { - # mark the start time. With Gnu date, you get nanoseconds from %N - # (here truncated to microseconds with %6N), but not on BSDs, - # Solaris, etc, which will apparently leave either %N or N at the end. - date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/' +timestamp() +{ + # mark the start time. With Gnu date, you get nanoseconds from %N + # (here truncated to microseconds with %6N), but not on BSDs, + # Solaris, etc, which will apparently leave either %N or N at the end. + date -u +'time: %Y-%m-%d %H:%M:%S.%6NZ' | sed 's/\..*NZ$/.000000Z/' } -subunit_start_test () { - # emit the current protocol start-marker for test $1 - timestamp - printf 'test: %s\n' "$1" +subunit_start_test() +{ + # emit the current protocol start-marker for test $1 + timestamp + printf 'test: %s\n' "$1" } - -subunit_pass_test () { - # emit the current protocol test passed marker for test $1 - timestamp - printf 'success: %s\n' "$1" +subunit_pass_test() +{ + # emit the current protocol test passed marker for test $1 + timestamp + printf 'success: %s\n' "$1" } # This is just a hack as we have some broken scripts # which use "exit $failed", without initializing failed. failed=0 -subunit_fail_test () { - # emit the current protocol fail-marker for test $1, and emit stdin as - # the error text. - # we use stdin because the failure message can be arbitrarily long, and this - # makes it convenient to write in scripts (using <&1` + output=$($cmdline 2>&1) status=$? if [ x$status = x0 ]; then subunit_pass_test "$name" @@ -92,14 +97,15 @@ testit () { # This returns 0 if the command gave success and the grep value was found # all other cases return != 0 -testit_grep () { +testit_grep() +{ name="$1" shift grep="$1" shift cmdline="$@" subunit_start_test "$name" - output=`$cmdline 2>&1` + output=$($cmdline 2>&1) status=$? if [ x$status != x0 ]; then printf '%s' "$output" | subunit_fail_test "$name" @@ -115,12 +121,13 @@ testit_grep () { return $status } -testit_expect_failure () { +testit_expect_failure() +{ name="$1" shift cmdline="$@" subunit_start_test "$name" - output=`$cmdline 2>&1` + output=$($cmdline 2>&1) status=$? if [ x$status = x0 ]; then echo "$output" | subunit_fail_test "$name" @@ -132,14 +139,15 @@ testit_expect_failure () { # This returns 0 if the command gave a failure and the grep value was found # all other cases return != 0 -testit_expect_failure_grep () { +testit_expect_failure_grep() +{ name="$1" shift grep="$1" shift cmdline="$@" subunit_start_test "$name" - output=`$cmdline 2>&1` + output=$($cmdline 2>&1) status=$? if [ x$status = x0 ]; then printf '%s' "$output" | subunit_fail_test "$name" @@ -155,8 +163,9 @@ testit_expect_failure_grep () { return $status } -testok () { - name=`basename $1` +testok() +{ + name=$(basename $1) failed=$2 exit $failed @@ -164,8 +173,8 @@ testok () { # work out the top level source directory if [ -d source4 ]; then - SRCDIR="." + SRCDIR="." else - SRCDIR=".." + SRCDIR=".." fi export SRCDIR -- 2.34.1 From d14dd2d13a2f3949ff8d0cbb24e6d7d88ef342d5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 9 Nov 2022 14:04:23 +0100 Subject: [PATCH 2/4] testprogs: Add testit_grep_count() helper Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher (cherry picked from commit 55feb593012fc5b24e795a00081666fca740429c) BUG: https://bugzilla.samba.org/show_bug.cgi?id=15243 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15266 --- testprogs/blackbox/subunit.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/testprogs/blackbox/subunit.sh b/testprogs/blackbox/subunit.sh index 75a9b5ec7e3c..ba4e997c5253 100755 --- a/testprogs/blackbox/subunit.sh +++ b/testprogs/blackbox/subunit.sh @@ -121,6 +121,35 @@ testit_grep() return $status } +# This returns 0 if the command gave success and the grep value was found +# num times all other cases return != 0 +testit_grep_count() +{ + name="$1" + shift + grep="$1" + shift + num="$1" + shift + cmdline="$@" + subunit_start_test "$name" + output=$($cmdline 2>&1) + status=$? + if [ x$status != x0 ]; then + printf '%s' "$output" | subunit_fail_test "$name" + return $status + fi + found=$(printf '%s' "$output" | grep -c "$grep") + if [ x"$found" = x"$num" ]; then + subunit_pass_test "$name" + else + printf 'GREP: "%s" found "%d" times, expected "%d" in output:\n%s'\ + "$grep" "$found" "$num" "$output" | + subunit_fail_test "$name" + fi + return $status +} + testit_expect_failure() { name="$1" -- 2.34.1 From f69d4313296bfb81621c26d448b72d27034abafe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Dec 2022 16:18:40 +0100 Subject: [PATCH 3/4] selftest: add samba3.blackbox.registry_share This demonstrates the regression introduced by f03665bb7e8ea97699062630f2aa1bac4c5dfc7f, where registry shares are no longer listed. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15243 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15266 Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Walker (cherry picked from commit a00c7395fbc7974a61a70ae54ea6ae6349933de2) --- selftest/knownfail.d/registry_share | 1 + selftest/target/Samba3.pm | 30 ++++++++++++++++ source3/script/tests/test_registry_share.sh | 39 +++++++++++++++++++++ source3/selftest/tests.py | 5 +++ 4 files changed, 75 insertions(+) create mode 100644 selftest/knownfail.d/registry_share create mode 100755 source3/script/tests/test_registry_share.sh diff --git a/selftest/knownfail.d/registry_share b/selftest/knownfail.d/registry_share new file mode 100644 index 000000000000..4adbf0915b87 --- /dev/null +++ b/selftest/knownfail.d/registry_share @@ -0,0 +1 @@ +^samba3.blackbox.registry_share.Test.for.share.enum.with.registry.share.clusteredmember diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 0b720a68927b..cb17408e3987 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -529,6 +529,36 @@ sub setup_clusteredmember return undef; } + my $registry_share_template = "$node_ret->{SERVERCONFFILE}.registry_share_template"; + unless (open(REGISTRYCONF, ">$registry_share_template")) { + warn("Unable to open $registry_share_template"); + teardown_env($self, $node_ret); + teardown_env($self, $ctdb_data); + return undef; + } + + print REGISTRYCONF " +[registry_share] + copy = tmp + comment = smb username is [%U] +"; + + close(REGISTRYCONF); + + my $net = Samba::bindir_path($self, "net"); + my $cmd = ""; + + $cmd .= "UID_WRAPPER_ROOT=1 "; + $cmd .= "$net conf import $node_ret->{CONFIGURATION} ${registry_share_template}"; + + my $net_ret = system($cmd); + if ($net_ret != 0) { + warn("net conf import failed: $net_ret\n$cmd"); + teardown_env($self, $node_ret); + teardown_env($self, $ctdb_data); + return undef; + } + my $nmblookup = Samba::bindir_path($self, "nmblookup"); do { print "Waiting for the LOGON SERVER registration ...\n"; diff --git a/source3/script/tests/test_registry_share.sh b/source3/script/tests/test_registry_share.sh new file mode 100755 index 000000000000..22e9f732a58c --- /dev/null +++ b/source3/script/tests/test_registry_share.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# Blackbox tests for registry shares +# + +if [ $# -lt 3 ]; then + cat < Date: Wed, 28 Dec 2022 13:50:45 +0100 Subject: [PATCH 4/4] s3:rpc_server/srvsvc: make sure we (re-)load all shares as root. This fixes a regression in commit f03665bb7e8ea97699062630f2aa1bac4c5dfc7f The use of reload_services() has a lot of side effects, e.g. reopen of log files and other things, which are only useful in smbd, but not in rpcd_classic. It was also unloading the user and registry shares we loaded a few lines above. We need to do all (re-)loading as root, otherwise we won't be able to read root only smb.conf files, access registry shares, ... BUG: https://bugzilla.samba.org/show_bug.cgi?id=15243 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15266 Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Walker Autobuild-User(master): Stefan Metzmacher Autobuild-Date(master): Thu Dec 29 21:14:02 UTC 2022 on sn-devel-184 (cherry picked from commit f28553105be7465026bcc0fcbbed6a1a8c2133dd) --- selftest/knownfail.d/registry_share | 1 - source3/rpc_server/srvsvc/srv_srvsvc_nt.c | 28 +++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) delete mode 100644 selftest/knownfail.d/registry_share diff --git a/selftest/knownfail.d/registry_share b/selftest/knownfail.d/registry_share deleted file mode 100644 index 4adbf0915b87..000000000000 --- a/selftest/knownfail.d/registry_share +++ /dev/null @@ -1 +0,0 @@ -^samba3.blackbox.registry_share.Test.for.share.enum.with.registry.share.clusteredmember diff --git a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c index f0686a411e17..a582f411412c 100644 --- a/source3/rpc_server/srvsvc/srv_srvsvc_nt.c +++ b/source3/rpc_server/srvsvc/srv_srvsvc_nt.c @@ -626,30 +626,34 @@ static WERROR init_srv_share_info_ctr(struct pipes_struct *p, 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 existing_home = -1; int added_home = -1; WERROR ret = WERR_OK; DEBUG(5,("init_srv_share_info_ctr\n")); - /* Ensure all the usershares are loaded. */ + /* + * We need to make sure to reload the services for the connecting user. + * It is possible that we have includes with substitutions. + * + * include = /etc/samba/%U.conf + * + * We also need all printers and usershares. + * + * We need to be root in order to have access to registry shares + * and root only smb.conf files. + */ become_root(); + lp_kill_all_services(); + lp_load_with_shares(get_dyn_CONFIGFILE()); delete_and_reload_printers(); load_usershare_shares(NULL, connections_snum_used); load_registry_shares(); - unbecome_root(); - + existing_home = lp_servicenumber(unix_name); if (existing_home == -1) { added_home = register_homes_share(unix_name); } - - /* - * We need to make sure to reload the services for the connecting user. - * It is possible that the we have includes with substitutions. - * - * include = /etc/samba/%U.conf - */ - reload_services(NULL, NULL, false); + unbecome_root(); num_services = lp_numservices(); -- 2.34.1