From 8d87c90cc36275f11d488c6bc9d4cdf3c01b817a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 17 Jul 2017 10:37:15 -0700 Subject: [PATCH 1/2] s3: libsmb: Reverse sense of 'clear all attributes', ignore attribute change in SMB2 to match SMB1. SMB1 uses attr == 0 to clear all attributes on a file (end up with FILE_ATTRIBUTE_NORMAL), and attr == FILE_ATTRIBUTE_NORMAL to mean ignore request attribute change. SMB2 uses exactly the reverse. Unfortunately as the cli_setatr() ABI is exposed inside libsmbclient, we must make the SMB2 cli_smb2_setatr() call export the same ABI as the SMB1 cli_setatr() which calls it. This means reversing the sense of the requested attr argument if it's zero or FILE_ATTRIBUTE_NORMAL. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12899 Signed-off-by: Jeremy Allison Reviewed-by: Richard Sharpe (cherry picked from commit f1cc79a46d56bda99c392d491d88479cd6427a32) --- source3/libsmb/cli_smb2_fnum.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c index 954f3fe3a7f..6967555797a 100644 --- a/source3/libsmb/cli_smb2_fnum.c +++ b/source3/libsmb/cli_smb2_fnum.c @@ -1698,6 +1698,29 @@ NTSTATUS cli_smb2_setatr(struct cli_state *cli, inbuf.length = sizeof(inbuf_store); data_blob_clear(&inbuf); + /* + * SMB1 uses attr == 0 to clear all attributes + * on a file (end up with FILE_ATTRIBUTE_NORMAL), + * and attr == FILE_ATTRIBUTE_NORMAL to mean ignore + * request attribute change. + * + * SMB2 uses exactly the reverse. Unfortunately as the + * cli_setatr() ABI is exposed inside libsmbclient, + * we must make the SMB2 cli_smb2_setatr() call + * export the same ABI as the SMB1 cli_setatr() + * which calls it. This means reversing the sense + * of the requested attr argument if it's zero + * or FILE_ATTRIBUTE_NORMAL. + * + * See BUG: https://bugzilla.samba.org/show_bug.cgi?id=12899 + */ + + if (attr == 0) { + attr = FILE_ATTRIBUTE_NORMAL; + } else if (attr == FILE_ATTRIBUTE_NORMAL) { + attr = 0; + } + SSVAL(inbuf.data, 32, attr); if (mtime != 0) { put_long_date((char *)inbuf.data + 16,mtime); -- 2.13.2.932.g7449e964c-goog From 1a8424af855cf6952edbe1827a3571c2c8b8bfa4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 18 Jul 2017 11:15:28 -0700 Subject: [PATCH 2/2] s3: smbclient: Add a test for the setmode command. Tested over SMB1 and SMB2. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12899 Back ported from 5facd045efe88783ba078c14793d05439bcc5a4b in master. Signed-off-by: Jeremy Allison --- source3/script/tests/test_smbclient_s3.sh | 51 +++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh index 4cfd054b018..ae8ae675b81 100755 --- a/source3/script/tests/test_smbclient_s3.sh +++ b/source3/script/tests/test_smbclient_s3.sh @@ -1189,6 +1189,53 @@ EOF fi } +# Test smbclient setmode command +test_setmode() +{ + tmpfile=$PREFIX/smbclient_interactive_prompt_commands + + cat > $tmpfile <