s3/script/tests: Make smb_client 'die' behaviour configurable
authorNoel Power <noel.power@suse.com>
Mon, 30 Nov 2020 10:18:32 +0000 (10:18 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 1 Dec 2020 19:06:44 +0000 (19:06 +0000)
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 <noel.power@suse.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/script/tests/test_smbclient_tarmode.pl

index 4aaee3e8c9c17a393f354ad8b844bbe79d017392..7b9e2f938d1d0fc11b97f0834d8dfbfdf09e10fe 100755 (executable)
@@ -1118,7 +1118,9 @@ sub check_tar {
     return (@more + @less + @diff); # nb of errors
 }
 
-=head3 C<smb_client ( @args )>
+=head3 C<smb_client_cmd( $will_die, @args)>
+
+=head3 C<smb_client_cmd( 0, '-c', 'deltree', $somedir )>
 
 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<STDOUT> and C<STDERR>.
 
-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<smb_client ( @args )>
+
+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<STDOUT> and C<STDERR>.
+
+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(' ', @_));
 }