From 75fd5fed202a6bf4ee37a600b5afc79be056f1bb Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 May 2022 20:11:13 +0100 Subject: [PATCH 1/2] s3/script/tests: Test smbclient -E redirects output to stderr Add new test to ensure smbclient is writing to stderr (with '-E') Add knownfail for this test (will be removed when issue is fixed in later commit) BUG: https://bugzilla.samba.org/show_bug.cgi?id=15075 Signed-off-by: Noel Power (cherry picked from commit 5b6493043fc90a2bed5aaedad3b4511621d0b9fd) --- selftest/knownfail.d/smbclient-smb3 | 1 + source3/script/tests/test_smbclient_s3.sh | 45 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/selftest/knownfail.d/smbclient-smb3 b/selftest/knownfail.d/smbclient-smb3 index 119e93e479a..4d884db5025 100644 --- a/selftest/knownfail.d/smbclient-smb3 +++ b/selftest/knownfail.d/smbclient-smb3 @@ -1,4 +1,5 @@ ^samba3.blackbox.smbclient_s3.SMB3.*.creating.a.bad.symlink.and.deleting.it +^samba3.blackbox.smbclient_s3.*.smbclient output goes to stderr when -E is passed ^samba3.blackbox.acl_xattr.SMB3.nt_affects_posix ^samba3.blackbox.acl_xattr.SMB3.nt_affects_chown ^samba3.blackbox.acl_xattr.SMB3.nt_affects_chgrp diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh index 3da37e699e6..fc608bdfc9b 100755 --- a/source3/script/tests/test_smbclient_s3.sh +++ b/source3/script/tests/test_smbclient_s3.sh @@ -2043,6 +2043,47 @@ EOF return 0 } +test_smbclient_minus_e_stderr() +{ + cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -c ls' + eval echo "$cmd" + out=`eval $cmd` + if [ $? != 0 ] ; then + echo "$out" + echo "command failed" + return 1 + fi + + # test smbclient 'ls' command output went to stdout + echo "$out" | grep "blocks available" >/dev/null 2>&1 + if [ $? != 0 ] ; then + # didn't get output to stdout + echo "expected output was NOT output to stdout" + return 1 + fi + + # this time execute ls but redirect stdout alone to /dev/null + cmd='$SMBCLIENT -E "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -c "ls" 2>&1 > /dev/null' + eval echo "$cmd" + out=`eval $cmd` + if [ $? != 0 ] ; then + echo "$out" + echo "command failed" + return 1 + fi + + # test smbclient 'ls' command output went to stderr + echo "$out" | grep "blocks available" >/dev/null 2>&1 + if [ $? != 0 ] ; then + # didn't get output to stderr + echo "expected output was NOT output to stderr" + return 1 + fi + + return 0 + +} + # # LOGDIR_PREFIX=test_smbclient_s3 @@ -2068,6 +2109,10 @@ testit "noninteractive smbclient -l does not prompt" \ test_noninteractive_no_prompt -l $LOGDIR || \ failed=`expr $failed + 1` +testit "smbclient output goes to stderr when -E is passed" \ + test_smbclient_minus_e_stderr || \ + failed=`expr $failed + 1` + testit "interactive smbclient prompts on stdout" \ test_interactive_prompt_stdout || \ failed=`expr $failed + 1` -- 2.35.3 From 500218ad6384c3a668efc30201f4b409b1730f48 Mon Sep 17 00:00:00 2001 From: Noel Power Date: Mon, 23 May 2022 17:23:41 +0100 Subject: [PATCH 2/2] s3/client: Restore '-E' handling Sometimes we really do need to redirect output to stderr e.g. when using the tar command to output the archive to stdout we don't want debug or cmdline status messages straying into stdout. was removed with commit: e4474ac0a540c56548b4d15e38f2e234455e19b6 remove known fail for the test BUG: https://bugzilla.samba.org/show_bug.cgi?id=15075 Signed-off-by: Noel Power Autobuild-User(master): Noel Power Autobuild-Date(master): Tue May 24 10:29:27 UTC 2022 on sn-devel-184 (cherry picked from commit 56e179817123b40c3646476563d345d8f97efff9) --- selftest/knownfail.d/smbclient-smb3 | 1 - source3/client/client.c | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/selftest/knownfail.d/smbclient-smb3 b/selftest/knownfail.d/smbclient-smb3 index 4d884db5025..119e93e479a 100644 --- a/selftest/knownfail.d/smbclient-smb3 +++ b/selftest/knownfail.d/smbclient-smb3 @@ -1,5 +1,4 @@ ^samba3.blackbox.smbclient_s3.SMB3.*.creating.a.bad.symlink.and.deleting.it -^samba3.blackbox.smbclient_s3.*.smbclient output goes to stderr when -E is passed ^samba3.blackbox.acl_xattr.SMB3.nt_affects_posix ^samba3.blackbox.acl_xattr.SMB3.nt_affects_chown ^samba3.blackbox.acl_xattr.SMB3.nt_affects_chgrp diff --git a/source3/client/client.c b/source3/client/client.c index 690f9deaec9..8ec4589a1cd 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -6552,6 +6552,11 @@ int main(int argc,char *argv[]) print_sockaddr(dest_ss_str, sizeof(dest_ss_str), &dest_ss); } break; + case 'E': + setup_logging("smbclient", DEBUG_STDERR ); + display_set_stderr(); + break; + case 'L': query_host = talloc_strdup(frame, poptGetOptArg(pc)); if (!query_host) { -- 2.35.3