From 3cc55c77df79cadc0d96aae8e53a8e5f24452ab2 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Thu, 26 Nov 2020 17:31:50 +0000 Subject: [PATCH 01/12] selftest: Add a new tarmode shares samba3.blackbox.smbclient_tar & samba3.blackbox.smbclient_tar need separate shares with own xattr tdb(s) BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- selftest/target/Samba3.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm index 5623e2a149f..8b1d809c941 100755 --- a/selftest/target/Samba3.pm +++ b/selftest/target/Samba3.pm @@ -1369,6 +1369,9 @@ sub setup_fileserver my $tarmode_sharedir="$share_dir/tarmode"; push(@dirs,$tarmode_sharedir); + my $tarmode2_sharedir="$share_dir/tarmode2"; + push(@dirs,$tarmode2_sharedir); + my $smbcacls_sharedir="$share_dir/smbcacls"; push(@dirs,$smbcacls_sharedir); @@ -1397,6 +1400,14 @@ sub setup_fileserver get quota command = $prefix_abs/getset_quota.py set quota command = $prefix_abs/getset_quota.py +[tarmode] + path = $tarmode_sharedir + comment = tar test share + xattr_tdb:file = $prefix_abs/tarmode-xattr.tdb +[tarmode2] + path = $tarmode2_sharedir + comment = tar test share + xattr_tdb:file = $prefix_abs/tarmode2-xattr.tdb [spotlight] path = $share_dir spotlight = yes -- 2.26.2 From c7a698f9088bd134c89922d0855fba9abf499273 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Nov 2020 15:25:21 +0000 Subject: [PATCH 02/12] s3/script/test: Use different testdir for samba3.blackbox.smbclient_tarmode The other tarmode torture test samba3.blackbox.smbclient_tar now uses a share 'tarmode' which uses the same source path as samba3.blackbox.smbclient_tarmode Avoid conflicting paths and use a new subdir (of the test share) called 'smbclient_tarmode' BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.sh | 8 ++++---- source3/selftest/tests.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.sh b/source3/script/tests/test_smbclient_tarmode.sh index 3779c38a5ca..298f428b041 100755 --- a/source3/script/tests/test_smbclient_tarmode.sh +++ b/source3/script/tests/test_smbclient_tarmode.sh @@ -105,7 +105,7 @@ test_tarmode_creation() { # Create tarfile with smbclient if ! $SMBCLIENT //$SERVER/tmp $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ - $ADDARGS -c "tarmode full" -Tc "$PREFIX/tarmode.tar" "/tarmode"; then + $ADDARGS -c "tarmode full" -Tc "$PREFIX/tarmode.tar" "/smbclient_tar"; then echo "Couldn't create tar file with tarmode -Tc" false return @@ -119,7 +119,7 @@ test_tarmode_creation() { fi # Verify data - if ! validate_data "$PREFIX/tarmode" "$LOCAL_PATH"; then + if ! validate_data "$PREFIX/smbclient_tar" "$LOCAL_PATH"; then echo "Data not equivalent" false return @@ -146,7 +146,7 @@ test_tarmode_extraction() { fi # Create tarfile to extract on client - if ! tar -cf "$PREFIX/tarmode.tar" -C "$PREFIX" tarmode; then + if ! tar -cf "$PREFIX/tarmode.tar" -C "$PREFIX" smbclient_tar; then echo "Couldn't create tar archive" false return @@ -161,7 +161,7 @@ test_tarmode_extraction() { fi # Verify data - if ! validate_data "$PREFIX/tarmode" "$LOCAL_PATH"; then + if ! validate_data "$PREFIX/smbclient_tar" "$LOCAL_PATH"; then echo "Data not equivalent" false return diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 6cfb98e2bb6..8a5d69132e6 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -483,11 +483,11 @@ for env in ["fileserver"]: plantestsuite("samba3.blackbox.smbclient_tarmode.NT1", env + "_smb1_done", [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', - '$LOCAL_PATH/tarmode', '$PREFIX', smbclient3, configuration, "-mNT1"]) + '$LOCAL_PATH/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mNT1"]) plantestsuite("samba3.blackbox.smbclient_tarmode.SMB3", env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', - '$LOCAL_PATH/tarmode', '$PREFIX', smbclient3, configuration, "-mSMB3"]) + '$LOCAL_PATH/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mSMB3"]) # Test suite for new smbclient/tar with libarchive (GSoC 13) plantestsuite("samba3.blackbox.smbclient_tar.NT1", env + "_smb1_done", -- 2.26.2 From ddf51ccd045390b1d2c035ef88baf938353a5153 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Nov 2020 15:33:26 +0000 Subject: [PATCH 03/12] s3/script/tests: Use tarmode share for samba3.blackbox.smbclient_tar* After this change both samba3.blackbox.smbclient_tar & samba3.blackbox.smbclient_tarmode now use the same dedicated share BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.sh | 4 ++-- source3/selftest/tests.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.sh b/source3/script/tests/test_smbclient_tarmode.sh index 298f428b041..54dd833dae3 100755 --- a/source3/script/tests/test_smbclient_tarmode.sh +++ b/source3/script/tests/test_smbclient_tarmode.sh @@ -104,7 +104,7 @@ test_tarmode_creation() { fi # Create tarfile with smbclient - if ! $SMBCLIENT //$SERVER/tmp $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ + if ! $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ $ADDARGS -c "tarmode full" -Tc "$PREFIX/tarmode.tar" "/smbclient_tar"; then echo "Couldn't create tar file with tarmode -Tc" false @@ -153,7 +153,7 @@ test_tarmode_extraction() { fi # Extract tarfile with smbclient - if ! $SMBCLIENT //$SERVER/tmp $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ + if ! $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -I $SERVER_IP -p 139 \ $ADDARGS -c "tarmode full" -Tx "$PREFIX/tarmode.tar"; then echo "Couldn't extact tar file with tarmode -Tx" false diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 8a5d69132e6..5e90fab1692 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -483,11 +483,11 @@ for env in ["fileserver"]: plantestsuite("samba3.blackbox.smbclient_tarmode.NT1", env + "_smb1_done", [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', - '$LOCAL_PATH/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mNT1"]) + '$LOCAL_PATH/tarmode/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mNT1"]) plantestsuite("samba3.blackbox.smbclient_tarmode.SMB3", env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', - '$LOCAL_PATH/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mSMB3"]) + '$LOCAL_PATH/tarmode/smbclient_tar', '$PREFIX', smbclient3, configuration, "-mSMB3"]) # Test suite for new smbclient/tar with libarchive (GSoC 13) plantestsuite("samba3.blackbox.smbclient_tar.NT1", env + "_smb1_done", -- 2.26.2 From 42964db865630448f2180f041db53d3d2de86d31 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Fri, 27 Nov 2020 15:52:27 +0000 Subject: [PATCH 04/12] s3/script: Use smbclient deltree to clean up smbclient_tarmode subdir Replace rm -rf of local dir (that is hosted remotely) with smbclient deltree BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.sh b/source3/script/tests/test_smbclient_tarmode.sh index 54dd833dae3..49680e93196 100755 --- a/source3/script/tests/test_smbclient_tarmode.sh +++ b/source3/script/tests/test_smbclient_tarmode.sh @@ -94,7 +94,7 @@ test_tarmode_creation() { # Clear temp data rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1 rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1 - rm -rf "$LOCAL_PATH" > /dev/null 2>&1 + $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -c "deltree smbclient_tar" # Build the test data if ! create_test_data "$LOCAL_PATH"; then @@ -136,7 +136,7 @@ test_tarmode_extraction() { # Clear temp data rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1 rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1 - rm -rf "$LOCAL_PATH" > /dev/null 2>&1 + $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -c "deltree smbclient_tar" # Build the test data if ! create_test_data "$PREFIX/tarmode"; then -- 2.26.2 From a8a58a3254ae75264f8baf52bba4b8bba3026c27 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 17:39:25 +0000 Subject: [PATCH 05/12] s3/script/tests: Fix samba3.blackbox.smbclient_tarmode cleanup Make sure samba3.blackbox.smbclient_tarmode removes data files not just before running the test but also after BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/source3/script/tests/test_smbclient_tarmode.sh b/source3/script/tests/test_smbclient_tarmode.sh index 49680e93196..8bc5b9947cf 100755 --- a/source3/script/tests/test_smbclient_tarmode.sh +++ b/source3/script/tests/test_smbclient_tarmode.sh @@ -111,7 +111,8 @@ test_tarmode_creation() { return fi - # Extract data to verify + # Extract data to verify - this puts it into $PREFIX/smbclient_tar/ + # but we must leave it there as it's used to verify in test_tarmode_extraction() if ! tar -xf "$PREFIX/tarmode.tar" -C "$PREFIX"; then echo "Couldn't extract data from created tarfile" false @@ -125,6 +126,10 @@ test_tarmode_creation() { return fi + # Clear temp data + rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1 + rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1 + $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -c "deltree smbclient_tar" true return @@ -167,6 +172,12 @@ test_tarmode_extraction() { return fi + # Clear temp data + rm -rf -- "$PREFIX"/tarmode > /dev/null 2>&1 + rm -f "$PREFIX"/tarmode.tar > /dev/null 2>&1 + $SMBCLIENT //$SERVER/tarmode $CONFIGURATION -U$USERNAME%$PASSWORD -c "deltree smbclient_tar" + # Cleanup the verification data created by test_tarmode_creation(). + rm -rf "$PREFIX"/smbclient_tar > /dev/null 2>&1 true return -- 2.26.2 From 03503d9f590fc78a9b1633f91ed04beb49300f38 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 11:15:06 +0000 Subject: [PATCH 06/12] selftest: make samba3.blackbox.smbclient_tar runnable (even manually) samba3.blackbox.smbclient_tar is marked as flapping so it seems we have missed that it has stopped working. The local path passed to script/tests/test_smbclient_tarmode.pl must point to a valid share BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/selftest/tests.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py index 5e90fab1692..74bf3abb95f 100755 --- a/source3/selftest/tests.py +++ b/source3/selftest/tests.py @@ -492,14 +492,14 @@ for env in ["fileserver"]: # Test suite for new smbclient/tar with libarchive (GSoC 13) plantestsuite("samba3.blackbox.smbclient_tar.NT1", env + "_smb1_done", [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.pl"), - '-n', '$SERVER', '-i', '$SERVER_IP', '-s', 'tmp', - '-u', '$USERNAME', '-p', '$PASSWORD', '-l', '$LOCAL_PATH/tarmode', + '-n', '$SERVER', '-i', '$SERVER_IP', '-s', 'tarmode2', + '-u', '$USERNAME', '-p', '$PASSWORD', '-l', '$LOCAL_PATH/tarmode2', '-d', '$PREFIX', '-b', smbclient3, '--subunit', '--', configuration, '-mNT1']) plantestsuite("samba3.blackbox.smbclient_tar.SMB3", env, [os.path.join(samba3srcdir, "script/tests/test_smbclient_tarmode.pl"), - '-n', '$SERVER', '-i', '$SERVER_IP', '-s', 'tmp', - '-u', '$USERNAME', '-p', '$PASSWORD', '-l', '$LOCAL_PATH/tarmode', + '-n', '$SERVER', '-i', '$SERVER_IP', '-s', 'tarmode2', + '-u', '$USERNAME', '-p', '$PASSWORD', '-l', '$LOCAL_PATH/tarmode2', '-d', '$PREFIX', '-b', smbclient3, '--subunit', '--', configuration, '-mSMB3']) -- 2.26.2 From 591522d554f8b94bcd04a202d04c70d5c8d04a8c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 09:59:58 +0000 Subject: [PATCH 07/12] s3/script/tests: Remove make_path (for remote dir) LOCALPATH is actually the local path to the share, we should not need to create the share path (it should already exist) Note: When we remove the tree located at LOCALPATH we keep the root so the share path should always be there BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.pl | 2 -- 1 file changed, 2 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl index d638ae5ac4b..4aaee3e8c9c 100755 --- a/source3/script/tests/test_smbclient_tarmode.pl +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -1,5 +1,4 @@ #!/usr/bin/perl - # Unix SMB/CIFS implementation. # Test suite for the tar backup mode of smbclient. # Copyright (C) Aurélien Aptel 2013 @@ -918,7 +917,6 @@ sub reset_remote { # remove_tree($LOCALPATH . '/'. $DIR); # make_path($LOCALPATH . '/'. $DIR); remove_tree($LOCALPATH, {keep_root => 1}); - make_path($LOCALPATH); } =head3 C -- 2.26.2 From 9eb08658c2e1bb51355452b490322c7578228317 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 10:18:32 +0000 Subject: [PATCH 08/12] s3/script/tests: Make smb_client 'die' behaviour configurable smb_client behaviour is to die if there is an error. This is a little heavy handed and make it impossible for example to use smb_client to run a command that might fail (where such a failure isn't really an error) E.G. Calling deltree and the directory doesn't exist BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- .../script/tests/test_smbclient_tarmode.pl | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl index 4aaee3e8c9c..7b9e2f938d1 100755 --- a/source3/script/tests/test_smbclient_tarmode.pl +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -1118,7 +1118,9 @@ sub check_tar { return (@more + @less + @diff); # nb of errors } -=head3 C +=head3 C + +=head3 C Run smbclient with C<@args> passed as argument and return output. @@ -1129,11 +1131,12 @@ the command-line are already inserted. The output contains both the C and C. -Die if smbclient crashes or exits with an error code. +if C<$will_die> then Die if smbclient crashes or exits with an error code. +otherwise return output =cut -sub smb_client { - my (@args) = @_; +sub smb_client_cmd { + my ($will_die, @args) = @_; my $fullpath = "//$HOST/$SHARE"; my $cmd = sprintf("%s %s %s", @@ -1166,11 +1169,34 @@ sub smb_client { } if ($err) { - die "ERROR: $errstr"; + if ($will_die) { + die "ERROR: $errstr"; + } else { + say "ERROR: $errstr"; + } } return $out; } +=head3 C + +Run smbclient with C<@args> passed as argument and return output. + +Each element of C<@args> becomes one escaped argument of smbclient. + +Host, share, user, password and the additionnal arguments provided on +the command-line are already inserted. + +The output contains both the C and C. + +Die if smbclient crashes or exits with an error code. + +=cut +sub smb_client { + my (@args) = @_; + return smb_client_cmd(1, @args) +} + sub smb_cmd { return smb_client('-c', join(' ', @_)); } -- 2.26.2 From 1340cd1f745a7a66552cb98895e3e1fa54517430 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 10:41:57 +0000 Subject: [PATCH 09/12] s3/script/tests: call smbclient deltree to remove remote files BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- source3/script/tests/test_smbclient_tarmode.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl index 7b9e2f938d1..c0c35b93732 100755 --- a/source3/script/tests/test_smbclient_tarmode.pl +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -303,6 +303,8 @@ sub test_creation_attr { @inc = grep { $_->attr('a') && !$_->attr_any('h', 's') } @all; smb_tar('tarmode inc nohidden nosystem', '-Tc', $TAR, $DIR); $err += check_tar($TAR, \@inc); + # adjust attr so remote files can be deleted with deltree + File::walk(sub { $_->set_attr(qw/n r s h/) }, File::tree($DIR)); $err; } @@ -398,7 +400,10 @@ sub test_creation_incremental { } else { smb_tar('', '-Tcg', $TAR, $DIR); } - return check_tar($TAR, \@files); + my $res = check_tar($TAR, \@files); + # adjust attr so remote files can be deleted with deltree + File::walk(sub { $_->set_attr(qw/n r s h/) }, File::tree($DIR)); + return $res } @@ -916,7 +921,7 @@ Remove all files in the server C<$DIR> (not root) sub reset_remote { # remove_tree($LOCALPATH . '/'. $DIR); # make_path($LOCALPATH . '/'. $DIR); - remove_tree($LOCALPATH, {keep_root => 1}); + smb_client_cmd(0, '-c', "deltree ./*"); } =head3 C -- 2.26.2 From b9d78a0dee8d40c6c30982763ac55c6d2f9c9229 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Nov 2020 17:19:29 +0000 Subject: [PATCH 10/12] s3/script/tests: Ensure all remote test files are removed BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- source3/script/tests/test_smbclient_tarmode.pl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source3/script/tests/test_smbclient_tarmode.pl b/source3/script/tests/test_smbclient_tarmode.pl index c0c35b93732..bdbbd1a44a8 100755 --- a/source3/script/tests/test_smbclient_tarmode.pl +++ b/source3/script/tests/test_smbclient_tarmode.pl @@ -921,7 +921,22 @@ Remove all files in the server C<$DIR> (not root) sub reset_remote { # remove_tree($LOCALPATH . '/'. $DIR); # make_path($LOCALPATH . '/'. $DIR); + my $DIR; + my @names; + my $name; + smb_client_cmd(0, '-c', "deltree ./*"); + + # Ensure all files are gone. + + opendir(DIR,$LOCALPATH) or die "Can't open $LOCALPATH\n"; + @names = readdir(DIR) or die "Unable to read $LOCALPATH\n"; + closedir(DIR); + foreach $name (@names) { + next if ($name eq "."); # skip the current directory entry + next if ($name eq ".."); # skip the parent directory entry + die "$LOCALPATH not empty\n"; + } } =head3 C -- 2.26.2 From e06e3bd8aed425c2d37b5e5179ff0fad36b6a7e2 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 20:01:39 +0000 Subject: [PATCH 11/12] s3/client: Allow do_list() to be called recursively. clitar.c does this. Prevent nested calls to 'do_list' corrupting the global shared 'queue', 'do_list_recurse', and 'do_list_fn' variables. Move these to the existing do_list state (which is stored on the stack at the start of each call to do_list) BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Pair-Programmed-With: Jeremy Alisson Signed-off-by: Noel Power --- source3/client/client.c | 90 +++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/source3/client/client.c b/source3/client/client.c index e2fdacd1251..ff746219ce2 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -680,28 +680,23 @@ struct do_list_queue { struct do_list_queue_entry *list; }; -static bool do_list_recurse; -static bool do_list_dirs; -static struct do_list_queue *queue = NULL; -static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *, - const char *dir); - /**************************************************************************** Functions for do_list_queue. ****************************************************************************/ -static void reset_do_list_queue(void) +static void reset_do_list_queue(struct do_list_queue **ppqueue) { - TALLOC_FREE(queue); + TALLOC_FREE(*ppqueue); } -static void init_do_list_queue(void) +static void init_do_list_queue(struct do_list_queue **ppqueue) { - TALLOC_FREE(queue); - queue = talloc_zero(NULL, struct do_list_queue); + TALLOC_FREE(*ppqueue); + *ppqueue = talloc_zero(NULL, struct do_list_queue); } -static void add_to_do_list_queue(const char *entry) +static void add_to_do_list_queue(struct do_list_queue **ppqueue, + const char *entry) { struct do_list_queue_entry *e = NULL; size_t entry_str_len = strlen(entry)+1; @@ -710,7 +705,7 @@ static void add_to_do_list_queue(const char *entry) entry_len += entry_str_len; SMB_ASSERT(entry_len >= entry_str_len); - e = talloc_size(queue, entry_len); + e = talloc_size((*ppqueue), entry_len); if (e == NULL) { d_printf("talloc failed for entry %s\n", entry); return; @@ -718,24 +713,24 @@ static void add_to_do_list_queue(const char *entry) talloc_set_name_const(e, "struct do_list_queue_entry"); memcpy(e->name, entry, entry_str_len); - DLIST_ADD_END(queue->list, e); + DLIST_ADD_END((*ppqueue)->list, e); } -static char *do_list_queue_head(void) +static char *do_list_queue_head(struct do_list_queue **ppqueue) { - return queue->list->name; + return (*ppqueue)->list->name; } -static void remove_do_list_queue_head(void) +static void remove_do_list_queue_head(struct do_list_queue **ppqueue) { - struct do_list_queue_entry *e = queue->list; - DLIST_REMOVE(queue->list, e); + struct do_list_queue_entry *e = (*ppqueue)->list; + DLIST_REMOVE((*ppqueue)->list, e); TALLOC_FREE(e); } -static int do_list_queue_empty(void) +static int do_list_queue_empty(struct do_list_queue **ppqueue) { - return (queue == NULL) || (queue->list == NULL); + return ((*ppqueue) == NULL) || ((*ppqueue)->list == NULL); } /**************************************************************************** @@ -745,6 +740,12 @@ static int do_list_queue_empty(void) struct do_list_helper_state { const char *mask; struct cli_state *cli; + struct do_list_queue *queue; + bool do_list_recurse; + bool do_list_dirs; + NTSTATUS (*do_list_fn)(struct cli_state *cli_state, + struct file_info *, + const char *dir); }; static NTSTATUS do_list_helper( @@ -770,20 +771,20 @@ static NTSTATUS do_list_helper( if (!(f->attr & FILE_ATTRIBUTE_DIRECTORY)) { if (do_this_one(f)) { - status = do_list_fn(state->cli, f, dir); + status = state->do_list_fn(state->cli, f, dir); } TALLOC_FREE(dir); return status; } - if (do_list_dirs && do_this_one(f)) { - status = do_list_fn(state->cli, f, dir); + if (state->do_list_dirs && do_this_one(f)) { + status = state->do_list_fn(state->cli, f, dir); if (!NT_STATUS_IS_OK(status)) { return status; } } - if (!do_list_recurse || + if (!state->do_list_recurse || (f->name == NULL) || ISDOT(f->name) || ISDOTDOT(f->name)) { @@ -806,7 +807,7 @@ static NTSTATUS do_list_helper( TALLOC_FREE(dir); return NT_STATUS_NO_MEMORY; } - add_to_do_list_queue(mask2); + add_to_do_list_queue(&state->queue, mask2); TALLOC_FREE(mask2); TALLOC_FREE(dir); @@ -824,7 +825,13 @@ NTSTATUS do_list(const char *mask, bool rec, bool dirs) { - struct do_list_helper_state state = { .cli = cli, }; + struct do_list_helper_state state = { + .cli = cli, + .queue = NULL, + .do_list_recurse = rec, + .do_list_dirs = dirs, + .do_list_fn = fn, + }; static int in_do_list = 0; TALLOC_CTX *ctx = talloc_tos(); struct cli_credentials *creds = @@ -832,25 +839,21 @@ NTSTATUS do_list(const char *mask, NTSTATUS ret_status = NT_STATUS_OK; NTSTATUS status = NT_STATUS_OK; - if (in_do_list && rec) { + if (in_do_list && state.do_list_recurse) { fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n"); exit(1); } - in_do_list = 1; - - do_list_recurse = rec; - do_list_dirs = dirs; - do_list_fn = fn; + in_do_list++; - init_do_list_queue(); - add_to_do_list_queue(mask); + init_do_list_queue(&state.queue); + add_to_do_list_queue(&state.queue, mask); - while (!do_list_queue_empty()) { + while (!do_list_queue_empty(&state.queue)) { struct cli_state *targetcli = NULL; char *targetpath = NULL; - state.mask = do_list_queue_head(); + state.mask = do_list_queue_head(&state.queue); /* check for dfs */ @@ -865,7 +868,7 @@ NTSTATUS do_list(const char *mask, if (!NT_STATUS_IS_OK(status)) { d_printf("do_list: [%s] %s\n", state.mask, nt_errstr(status)); - remove_do_list_queue_head(); + remove_do_list_queue_head(&state.queue); continue; } @@ -880,9 +883,10 @@ NTSTATUS do_list(const char *mask, nt_errstr(status), targetpath); ret_status = status; } - remove_do_list_queue_head(); - if ((! do_list_queue_empty()) && (fn == display_finfo)) { - char *next_file = do_list_queue_head(); + remove_do_list_queue_head(&state.queue); + if ((! do_list_queue_empty(&state.queue)) + && (state.do_list_fn == display_finfo)) { + char *next_file = do_list_queue_head(&state.queue); char *save_ch = 0; if ((strlen(next_file) >= 2) && (next_file[strlen(next_file) - 1] == '*') && @@ -904,8 +908,8 @@ NTSTATUS do_list(const char *mask, TALLOC_FREE(targetpath); } - in_do_list = 0; - reset_do_list_queue(); + in_do_list--; + reset_do_list_queue(&state.queue); return ret_status; } -- 2.26.2 From 4b1941c4f05e5737a7745b9ad9996d1a4649b11c Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 30 Nov 2020 09:21:50 +0000 Subject: [PATCH 12/12] selftest: Remove samba3.blackbox.smbclient_tar from flapping tests BUG: https://bugzilla.samba.org/show_bug.cgi?id=14581 Signed-off-by: Noel Power Reviewed-by: Jeremy Allison --- selftest/flapping | 1 - 1 file changed, 1 deletion(-) diff --git a/selftest/flapping b/selftest/flapping index c9f0adbf1bd..8c3f9e8969a 100644 --- a/selftest/flapping +++ b/selftest/flapping @@ -31,6 +31,5 @@ # This test just is not reliable in finding the max search limit # ^samba4.ldap.notification.python\(.*\).__main__.LDAPNotificationTest.test_max_search -^samba3.blackbox.smbclient_tar.* # fails very, very often on sn-devel ^samba3.blackbox.smbclient_s3.*.sending a message to the remote server # flakey on sn-devel-104 and sn-devel-144 ^samba3.blackbox.smbclient_s3.*.creating a good symlink and deleting it by path # flakey on sn-devel-104 and sn-devel-144 -- 2.26.2