2 Unix SMB/CIFS implementation.
5 Copyright (C) Ralph Boehme 2022
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "ntstatus_gen.h"
23 #include "system/time.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
29 #define BASEDIR "test_ea"
31 static bool find_returned_ea(union smb_fileinfo
*finfo2
,
35 unsigned int num_eas
= finfo2
->all_eas
.out
.num_eas
;
36 struct ea_struct
*eas
= finfo2
->all_eas
.out
.eas
;
38 for (i
= 0; i
< num_eas
; i
++) {
39 if (eas
[i
].name
.s
== NULL
) {
42 /* Windows capitalizes returned EA names. */
43 if (strequal(eas
[i
].name
.s
, eaname
)) {
50 static bool torture_smb2_acl_xattr(struct torture_context
*tctx
,
51 struct smb2_tree
*tree
)
53 const char *fname
= BASEDIR
"\\test_acl_xattr";
54 const char *xattr_name
= NULL
;
55 struct smb2_handle h1
;
57 union smb_fileinfo finfo
;
58 union smb_setfileinfo sfinfo
;
62 torture_comment(tctx
, "Verify NTACL xattr can't be accessed\n");
64 xattr_name
= torture_setting_string(tctx
, "acl_xattr_name", NULL
);
65 torture_assert_not_null(tctx
, xattr_name
, "Missing acl_xattr_name option\n");
67 smb2_deltree(tree
, BASEDIR
);
69 status
= torture_smb2_testdir(tree
, BASEDIR
, &h1
);
70 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
71 "torture_smb2_testdir\n");
72 smb2_util_close(tree
, h1
);
74 status
= torture_smb2_testfile(tree
, fname
, &h1
);
75 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
76 "torture_smb2_testfile failed\n");
79 * 1. Set an EA, so we have something to list
83 ea
.name
.private_length
= strlen("void") + 1;
84 ea
.value
= data_blob_string_const("testme");
87 sfinfo
.generic
.level
= RAW_SFILEINFO_FULL_EA_INFORMATION
;
88 sfinfo
.generic
.in
.file
.handle
= h1
;
89 sfinfo
.full_ea_information
.in
.eas
.num_eas
= 1;
90 sfinfo
.full_ea_information
.in
.eas
.eas
= &ea
;
92 status
= smb2_setinfo_file(tree
, &sfinfo
);
93 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
94 "Setting EA should fail\n");
97 * 2. Verify NT ACL EA is not listed
100 finfo
.generic
.level
= RAW_FILEINFO_SMB2_ALL_EAS
;
101 finfo
.generic
.in
.file
.handle
= h1
;
103 status
= smb2_getinfo_file(tree
, tctx
, &finfo
);
104 torture_assert_ntstatus_ok_goto(tctx
, status
, ret
, done
,
105 "torture_smb2_testdir\n");
107 if (find_returned_ea(&finfo
, xattr_name
)) {
108 torture_result(tctx
, TORTURE_FAIL
,
109 "%s: NTACL EA leaked\n",
116 * 3. Try to set EA, should fail
119 ea
.name
.s
= xattr_name
;
120 ea
.name
.private_length
= strlen(xattr_name
) + 1;
121 ea
.value
= data_blob_string_const("testme");
124 sfinfo
.generic
.level
= RAW_SFILEINFO_FULL_EA_INFORMATION
;
125 sfinfo
.generic
.in
.file
.handle
= h1
;
126 sfinfo
.full_ea_information
.in
.eas
.num_eas
= 1;
127 sfinfo
.full_ea_information
.in
.eas
.eas
= &ea
;
129 status
= smb2_setinfo_file(tree
, &sfinfo
);
130 torture_assert_ntstatus_equal_goto(
131 tctx
, status
, NT_STATUS_ACCESS_DENIED
,
132 ret
, done
, "Setting EA should fail\n");
135 if (!smb2_util_handle_empty(h1
)) {
136 smb2_util_close(tree
, h1
);
139 smb2_deltree(tree
, BASEDIR
);
144 struct torture_suite
*torture_smb2_ea(TALLOC_CTX
*ctx
)
146 struct torture_suite
*suite
= torture_suite_create(ctx
, "ea");
147 suite
->description
= talloc_strdup(suite
, "SMB2-EA tests");
149 torture_suite_add_1smb2_test(suite
, "acl_xattr", torture_smb2_acl_xattr
);