1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
/*
Unix SMB/CIFS implementation.
SMB2 EA tests
Copyright (C) Ralph Boehme 2022
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "ntstatus_gen.h"
#include "system/time.h"
#include "libcli/smb2/smb2.h"
#include "libcli/smb2/smb2_calls.h"
#include "torture/torture.h"
#include "torture/smb2/proto.h"
#define BASEDIR "test_ea"
static bool find_returned_ea(union smb_fileinfo *finfo2,
const char *eaname)
{
unsigned int i;
unsigned int num_eas = finfo2->all_eas.out.num_eas;
struct ea_struct *eas = finfo2->all_eas.out.eas;
for (i = 0; i < num_eas; i++) {
if (eas[i].name.s == NULL) {
continue;
}
/* Windows capitalizes returned EA names. */
if (strequal(eas[i].name.s, eaname)) {
return true;
}
}
return false;
}
static bool torture_smb2_acl_xattr(struct torture_context *tctx,
struct smb2_tree *tree)
{
const char *fname = BASEDIR "\\test_acl_xattr";
const char *xattr_name = NULL;
struct smb2_handle h1;
struct ea_struct ea;
union smb_fileinfo finfo;
union smb_setfileinfo sfinfo;
NTSTATUS status;
bool ret = true;
torture_comment(tctx, "Verify NTACL xattr can't be accessed\n");
xattr_name = torture_setting_string(tctx, "acl_xattr_name", NULL);
torture_assert_not_null(tctx, xattr_name, "Missing acl_xattr_name option\n");
smb2_deltree(tree, BASEDIR);
status = torture_smb2_testdir(tree, BASEDIR, &h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testdir\n");
smb2_util_close(tree, h1);
status = torture_smb2_testfile(tree, fname, &h1);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testfile failed\n");
/*
* 1. Set an EA, so we have something to list
*/
ZERO_STRUCT(ea);
ea.name.s = "void";
ea.name.private_length = strlen("void") + 1;
ea.value = data_blob_string_const("testme");
ZERO_STRUCT(sfinfo);
sfinfo.generic.level = RAW_SFILEINFO_FULL_EA_INFORMATION;
sfinfo.generic.in.file.handle = h1;
sfinfo.full_ea_information.in.eas.num_eas = 1;
sfinfo.full_ea_information.in.eas.eas = &ea;
status = smb2_setinfo_file(tree, &sfinfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"Setting EA should fail\n");
/*
* 2. Verify NT ACL EA is not listed
*/
ZERO_STRUCT(finfo);
finfo.generic.level = RAW_FILEINFO_SMB2_ALL_EAS;
finfo.generic.in.file.handle = h1;
status = smb2_getinfo_file(tree, tctx, &finfo);
torture_assert_ntstatus_ok_goto(tctx, status, ret, done,
"torture_smb2_testdir\n");
if (find_returned_ea(&finfo, xattr_name)) {
torture_result(tctx, TORTURE_FAIL,
"%s: NTACL EA leaked\n",
__location__);
ret = false;
goto done;
}
/*
* 3. Try to set EA, should fail
*/
ZERO_STRUCT(ea);
ea.name.s = xattr_name;
ea.name.private_length = strlen(xattr_name) + 1;
ea.value = data_blob_string_const("testme");
ZERO_STRUCT(sfinfo);
sfinfo.generic.level = RAW_SFILEINFO_FULL_EA_INFORMATION;
sfinfo.generic.in.file.handle = h1;
sfinfo.full_ea_information.in.eas.num_eas = 1;
sfinfo.full_ea_information.in.eas.eas = &ea;
status = smb2_setinfo_file(tree, &sfinfo);
torture_assert_ntstatus_equal_goto(
tctx, status, NT_STATUS_ACCESS_DENIED,
ret, done, "Setting EA should fail\n");
done:
if (!smb2_util_handle_empty(h1)) {
smb2_util_close(tree, h1);
}
smb2_deltree(tree, BASEDIR);
return ret;
}
struct torture_suite *torture_smb2_ea(TALLOC_CTX *ctx)
{
struct torture_suite *suite = torture_suite_create(ctx, "ea");
suite->description = talloc_strdup(suite, "SMB2-EA tests");
torture_suite_add_1smb2_test(suite, "acl_xattr", torture_smb2_acl_xattr);
return suite;
}
|