]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4/libcli/smb2: avoid using smb2_composite_setpathinfo() in smb2_util_setatr()
authorRalph Boehme <slow@samba.org>
Sun, 14 Aug 2022 16:51:30 +0000 (18:51 +0200)
committerJule Anger <janger@samba.org>
Tue, 6 Sep 2022 06:32:13 +0000 (06:32 +0000)
smb2_composite_setpathinfo() uses SEC_FLAG_MAXIMUM_ALLOWED which can
have unwanted side effects like breaking oplocks if the effective access
includes [READ|WRITE]_DATA.

For changing the DOS attributes we only need SEC_FILE_WRITE_ATTRIBUTE. With this
change test_smb2_oplock_batch25() doesn't trigger an oplock break anymore.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15153

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
(cherry picked from commit 66e40690bdd41800a01333ce4243bd62ee2b1894)

source4/libcli/smb2/util.c
source4/torture/smb2/oplock.c

index b2efabb5a4439aaaee2fc4dd22100e8f0a799728..f86a149c646a041f46bf6baf139559b86a10cadb 100644 (file)
@@ -88,14 +88,37 @@ NTSTATUS smb2_util_mkdir(struct smb2_tree *tree, const char *dname)
 */
 NTSTATUS smb2_util_setatr(struct smb2_tree *tree, const char *name, uint32_t attrib)
 {
-       union smb_setfileinfo io;
-       
-       ZERO_STRUCT(io);
-       io.basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION;
-       io.basic_info.in.file.path = name;
-       io.basic_info.in.attrib = attrib;
+       struct smb2_create cr = {0};
+       struct smb2_handle h1 = {{0}};
+       union smb_setfileinfo setinfo;
+       NTSTATUS status;
+
+       cr = (struct smb2_create) {
+               .in.desired_access = SEC_FILE_WRITE_ATTRIBUTE,
+               .in.share_access = NTCREATEX_SHARE_ACCESS_MASK,
+               .in.create_disposition = FILE_OPEN,
+               .in.fname = name,
+       };
+       status = smb2_create(tree, tree, &cr);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+       h1 = cr.out.file.handle;
 
-       return smb2_composite_setpathinfo(tree, &io);
+       setinfo = (union smb_setfileinfo) {
+               .basic_info.level = RAW_SFILEINFO_BASIC_INFORMATION,
+               .basic_info.in.file.handle = h1,
+               .basic_info.in.attrib = attrib,
+       };
+
+       status = smb2_setinfo_file(tree, &setinfo);
+       if (!NT_STATUS_IS_OK(status)) {
+               smb2_util_close(tree, h1);
+               return status;
+       }
+
+       smb2_util_close(tree, h1);
+       return NT_STATUS_OK;
 }
 
 
index 6bf7567ddb1acc2b2aba3d7dc82656e586ae3546..8f275bafcdb7c1b2962db8ea15da5bb5b5805cf9 100644 (file)
@@ -2957,15 +2957,9 @@ static bool test_smb2_oplock_batch25(struct torture_context *tctx,
        h1 = io.smb2.out.file.handle;
        CHECK_VAL(io.smb2.out.oplock_level, SMB2_OPLOCK_LEVEL_BATCH);
 
-       torture_comment(tctx, "changing the file attribute info should trigger "
-                       "a break and a violation\n");
-
        status = smb2_util_setatr(tree1, fname, FILE_ATTRIBUTE_HIDDEN);
-       torture_assert_ntstatus_equal(tctx, status, NT_STATUS_SHARING_VIOLATION,
-                                     "Incorrect status");
-
-       torture_wait_for_oplock_break(tctx);
-       CHECK_VAL(break_info.count, 1);
+       torture_assert_ntstatus_ok(tctx, status, "Setting attributes "
+                                  "shouldn't trigger an oplock break");
 
        smb2_util_close(tree1, h1);
        smb2_util_close(tree1, h);