2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libcli/libcli.h"
24 #include "torture/util.h"
26 extern int torture_failures
;
28 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
31 static const uint32_t open_attrs_table
[] = {
32 FILE_ATTRIBUTE_NORMAL
,
33 FILE_ATTRIBUTE_ARCHIVE
,
34 FILE_ATTRIBUTE_READONLY
,
35 FILE_ATTRIBUTE_HIDDEN
,
36 FILE_ATTRIBUTE_SYSTEM
,
38 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
,
39 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
,
40 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
,
41 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
42 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
43 FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
45 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
,
46 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
,
47 FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
,
48 FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_SYSTEM
,
51 struct trunc_open_results
{
58 static const struct trunc_open_results attr_results
[] = {
59 { 0, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
60 { 1, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
61 { 2, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
62 { 16, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_NORMAL
, FILE_ATTRIBUTE_ARCHIVE
},
63 { 17, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_ARCHIVE
},
64 { 18, FILE_ATTRIBUTE_ARCHIVE
, FILE_ATTRIBUTE_READONLY
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
},
65 { 51, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
66 { 54, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
67 { 56, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
68 { 68, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
69 { 71, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
70 { 73, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
71 { 99, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
,FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
72 { 102, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
73 { 104, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
74 { 116, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
75 { 119, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
76 { 121, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
},
77 { 170, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
},
78 { 173, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
},
79 { 227, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
80 { 230, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_HIDDEN
},
81 { 232, FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
},
82 { 244, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
83 { 247, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_SYSTEM
},
84 { 249, FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_SYSTEM
}
88 bool torture_openattrtest(struct torture_context
*tctx
,
89 struct smbcli_state
*cli1
)
91 const char *fname
= "\\openattr.file";
97 for (k
= 0, i
= 0; i
< sizeof(open_attrs_table
)/sizeof(uint32_t); i
++) {
98 smbcli_setatr(cli1
->tree
, fname
, 0, 0);
99 smbcli_unlink(cli1
->tree
, fname
);
100 fnum1
= smbcli_nt_create_full(cli1
->tree
, fname
, 0,
103 NTCREATEX_SHARE_ACCESS_NONE
, NTCREATEX_DISP_OVERWRITE_IF
, 0, 0);
105 torture_assert(tctx
, fnum1
!= -1, talloc_asprintf(tctx
, "open %d (1) of %s failed (%s)", i
,
106 fname
, smbcli_errstr(cli1
->tree
)));
108 torture_assert_ntstatus_ok(tctx
,
109 smbcli_close(cli1
->tree
, fnum1
),
110 talloc_asprintf(tctx
, "close %d (1) of %s failed (%s)", i
, fname
,
111 smbcli_errstr(cli1
->tree
)));
113 for (j
= 0; j
< ARRAY_SIZE(open_attrs_table
); j
++) {
114 fnum1
= smbcli_nt_create_full(cli1
->tree
, fname
, 0,
118 NTCREATEX_SHARE_ACCESS_NONE
,
119 NTCREATEX_DISP_OVERWRITE
, 0, 0);
122 for (l
= 0; l
< ARRAY_SIZE(attr_results
); l
++) {
123 if (attr_results
[l
].num
== k
) {
124 torture_comment(tctx
, "[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(%s)\n",
125 k
, open_attrs_table
[i
],
127 fname
, smbcli_errstr(cli1
->tree
));
128 CHECK_MAX_FAILURES(error_exit
);
131 torture_assert_ntstatus_equal(tctx
,
132 smbcli_nt_error(cli1
->tree
), NT_STATUS_ACCESS_DENIED
,
133 talloc_asprintf(tctx
, "[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s",
134 k
, open_attrs_table
[i
], open_attrs_table
[j
],
135 smbcli_errstr(cli1
->tree
)));
136 CHECK_MAX_FAILURES(error_exit
);
138 torture_comment(tctx
, "[%d] trunc open 0x%x -> 0x%x failed\n", k
, open_attrs_table
[i
], open_attrs_table
[j
]);
144 torture_assert_ntstatus_ok(tctx
,
145 smbcli_close(cli1
->tree
, fnum1
),
146 talloc_asprintf(tctx
, "close %d (2) of %s failed (%s)", j
,
147 fname
, smbcli_errstr(cli1
->tree
)));
149 torture_assert_ntstatus_ok(tctx
,
150 smbcli_getatr(cli1
->tree
, fname
, &attr
, NULL
, NULL
),
151 talloc_asprintf(tctx
, "getatr(2) failed (%s)", smbcli_errstr(cli1
->tree
)));
154 torture_comment(tctx
, "[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
155 k
, open_attrs_table
[i
], open_attrs_table
[j
], attr
);
158 for (l
= 0; l
< ARRAY_SIZE(attr_results
); l
++) {
159 if (attr_results
[l
].num
== k
) {
160 if (attr
!= attr_results
[l
].result_attr
||
161 open_attrs_table
[i
] != attr_results
[l
].init_attr
||
162 open_attrs_table
[j
] != attr_results
[l
].trunc_attr
) {
163 torture_comment(tctx
, "[%d] getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
164 k
, open_attrs_table
[i
],
167 attr_results
[l
].result_attr
);
168 CHECK_MAX_FAILURES(error_exit
);
177 smbcli_setatr(cli1
->tree
, fname
, 0, 0);
178 smbcli_unlink(cli1
->tree
, fname
);