| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test DOS extended attributes |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2004 |
| 7 |
Copyright (C) Guenter Kukkukk 2005 |
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 3 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "includes.h" |
| 24 |
#include "torture/torture.h" |
| 25 |
#include "libcli/raw/libcliraw.h" |
| 26 |
#include "libcli/libcli.h" |
| 27 |
#include "torture/util.h" |
| 28 |
#include "torture/raw/proto.h" |
| 29 |
|
| 30 |
#define BASEDIR "\\testeas" |
| 31 |
|
| 32 |
#define CHECK_STATUS(status, correct) do { \ |
| 33 |
torture_assert_ntstatus_equal_goto(tctx, status, correct, ret, done, "Incorrect status"); \ |
| 34 |
} while (0) |
| 35 |
|
| 36 |
static bool maxeadebug; /* need that here, to allow no file delete in debug case */ |
| 37 |
|
| 38 |
static bool check_ea(struct smbcli_state *cli, |
| 39 |
const char *fname, const char *eaname, const char *value) |
| 40 |
{ |
| 41 |
NTSTATUS status = torture_check_ea(cli, fname, eaname, value); |
| 42 |
return NT_STATUS_IS_OK(status); |
| 43 |
} |
| 44 |
|
| 45 |
static char bad_ea_chars[] = "\"*+,/:;<=>?[\\]|"; |
| 46 |
|
| 47 |
static bool test_eas(struct smbcli_state *cli, struct torture_context *tctx) |
| 48 |
{ |
| 49 |
NTSTATUS status; |
| 50 |
union smb_setfileinfo setfile; |
| 51 |
union smb_open io; |
| 52 |
const char *fname = BASEDIR "\\ea.txt"; |
| 53 |
bool ret = true; |
| 54 |
char bad_ea_name[7]; |
| 55 |
int i; |
| 56 |
int fnum = -1; |
| 57 |
|
| 58 |
torture_comment(tctx, "TESTING SETFILEINFO EA_SET\n"); |
| 59 |
|
| 60 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 61 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 62 |
io.ntcreatex.in.flags = 0; |
| 63 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 64 |
io.ntcreatex.in.create_options = 0; |
| 65 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 66 |
io.ntcreatex.in.share_access = |
| 67 |
NTCREATEX_SHARE_ACCESS_READ | |
| 68 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 69 |
io.ntcreatex.in.alloc_size = 0; |
| 70 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 71 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 72 |
io.ntcreatex.in.security_flags = 0; |
| 73 |
io.ntcreatex.in.fname = fname; |
| 74 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 75 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 76 |
fnum = io.ntcreatex.out.file.fnum; |
| 77 |
|
| 78 |
ret &= check_ea(cli, fname, "EAONE", NULL); |
| 79 |
|
| 80 |
torture_comment(tctx, "Adding first two EAs\n"); |
| 81 |
setfile.generic.level = RAW_SFILEINFO_EA_SET; |
| 82 |
setfile.generic.in.file.fnum = fnum; |
| 83 |
setfile.ea_set.in.num_eas = 2; |
| 84 |
setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 2); |
| 85 |
setfile.ea_set.in.eas[0].flags = 0; |
| 86 |
setfile.ea_set.in.eas[0].name.s = "EAONE"; |
| 87 |
setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE1"); |
| 88 |
setfile.ea_set.in.eas[1].flags = 0; |
| 89 |
setfile.ea_set.in.eas[1].name.s = "SECONDEA"; |
| 90 |
setfile.ea_set.in.eas[1].value = data_blob_string_const("ValueTwo"); |
| 91 |
|
| 92 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 93 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 94 |
|
| 95 |
ret &= check_ea(cli, fname, "EAONE", "VALUE1"); |
| 96 |
ret &= check_ea(cli, fname, "SECONDEA", "ValueTwo"); |
| 97 |
|
| 98 |
torture_comment(tctx, "Modifying 2nd EA\n"); |
| 99 |
setfile.ea_set.in.num_eas = 1; |
| 100 |
setfile.ea_set.in.eas[0].name.s = "SECONDEA"; |
| 101 |
setfile.ea_set.in.eas[0].value = data_blob_string_const(" Changed Value"); |
| 102 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 103 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 104 |
|
| 105 |
ret &= check_ea(cli, fname, "EAONE", "VALUE1"); |
| 106 |
ret &= check_ea(cli, fname, "SECONDEA", " Changed Value"); |
| 107 |
|
| 108 |
torture_comment(tctx, "Setting a NULL EA\n"); |
| 109 |
setfile.ea_set.in.eas[0].value = data_blob(NULL, 0); |
| 110 |
setfile.ea_set.in.eas[0].name.s = "NULLEA"; |
| 111 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 112 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 113 |
|
| 114 |
ret &= check_ea(cli, fname, "EAONE", "VALUE1"); |
| 115 |
ret &= check_ea(cli, fname, "SECONDEA", " Changed Value"); |
| 116 |
ret &= check_ea(cli, fname, "NULLEA", NULL); |
| 117 |
|
| 118 |
torture_comment(tctx, "Deleting first EA\n"); |
| 119 |
setfile.ea_set.in.eas[0].flags = 0; |
| 120 |
setfile.ea_set.in.eas[0].name.s = "EAONE"; |
| 121 |
setfile.ea_set.in.eas[0].value = data_blob(NULL, 0); |
| 122 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 123 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 124 |
|
| 125 |
ret &= check_ea(cli, fname, "EAONE", NULL); |
| 126 |
ret &= check_ea(cli, fname, "SECONDEA", " Changed Value"); |
| 127 |
|
| 128 |
torture_comment(tctx, "Deleting second EA\n"); |
| 129 |
setfile.ea_set.in.eas[0].flags = 0; |
| 130 |
setfile.ea_set.in.eas[0].name.s = "SECONDEA"; |
| 131 |
setfile.ea_set.in.eas[0].value = data_blob(NULL, 0); |
| 132 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 133 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 134 |
|
| 135 |
ret &= check_ea(cli, fname, "EAONE", NULL); |
| 136 |
ret &= check_ea(cli, fname, "SECONDEA", NULL); |
| 137 |
|
| 138 |
/* Check EA name containing colon. All EA's set |
| 139 |
must be ignored, not just the one with the bad |
| 140 |
name. */ |
| 141 |
|
| 142 |
torture_comment(tctx, "Adding bad EA name\n"); |
| 143 |
setfile.generic.level = RAW_SFILEINFO_EA_SET; |
| 144 |
setfile.generic.in.file.fnum = fnum; |
| 145 |
setfile.ea_set.in.num_eas = 3; |
| 146 |
setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 3); |
| 147 |
setfile.ea_set.in.eas[0].flags = 0; |
| 148 |
setfile.ea_set.in.eas[0].name.s = "EAONE"; |
| 149 |
setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE1"); |
| 150 |
setfile.ea_set.in.eas[1].flags = 0; |
| 151 |
setfile.ea_set.in.eas[1].name.s = "SECOND:EA"; |
| 152 |
setfile.ea_set.in.eas[1].value = data_blob_string_const("ValueTwo"); |
| 153 |
setfile.ea_set.in.eas[2].flags = 0; |
| 154 |
setfile.ea_set.in.eas[2].name.s = "THIRDEA"; |
| 155 |
setfile.ea_set.in.eas[2].value = data_blob_string_const("ValueThree"); |
| 156 |
|
| 157 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 158 |
CHECK_STATUS(status, STATUS_INVALID_EA_NAME); |
| 159 |
|
| 160 |
ret &= check_ea(cli, fname, "EAONE", NULL); |
| 161 |
ret &= check_ea(cli, fname, "THIRDEA", NULL); |
| 162 |
|
| 163 |
setfile.generic.level = RAW_SFILEINFO_EA_SET; |
| 164 |
setfile.generic.in.file.fnum = fnum; |
| 165 |
setfile.ea_set.in.num_eas = 1; |
| 166 |
setfile.ea_set.in.eas = talloc_array(tctx, struct ea_struct, 1); |
| 167 |
setfile.ea_set.in.eas[0].flags = 0; |
| 168 |
strlcpy(bad_ea_name, "TEST_X", sizeof(bad_ea_name)); |
| 169 |
setfile.ea_set.in.eas[0].name.s = bad_ea_name; |
| 170 |
|
| 171 |
torture_comment(tctx, "Testing bad EA name range.\n"); |
| 172 |
|
| 173 |
for (i = 1; i < 256; i++) { |
| 174 |
setfile.ea_set.in.eas[0].value = data_blob_string_const("VALUE1"); |
| 175 |
bad_ea_name[5] = (char)i; |
| 176 |
torture_comment(tctx, "Testing bad EA name %d.\n", i); |
| 177 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 178 |
if (i < 32 || strchr(bad_ea_chars, i)) { |
| 179 |
CHECK_STATUS(status, STATUS_INVALID_EA_NAME); |
| 180 |
} else { |
| 181 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 182 |
|
| 183 |
/* Now delete the EA we just set to make |
| 184 |
sure we don't run out of room. */ |
| 185 |
setfile.ea_set.in.eas[0].value = data_blob(NULL, 0); |
| 186 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 187 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
done: |
| 192 |
smbcli_close(cli->tree, fnum); |
| 193 |
return ret; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
/* |
| 198 |
* Helper function to retrieve the max. ea size for one ea name |
| 199 |
*/ |
| 200 |
static int test_one_eamax(struct torture_context *tctx, |
| 201 |
struct smbcli_state *cli, const int fnum, |
| 202 |
const char *eaname, DATA_BLOB eablob, |
| 203 |
const int eastart, const int eadebug) |
| 204 |
{ |
| 205 |
NTSTATUS status; |
| 206 |
struct ea_struct eastruct; |
| 207 |
union smb_setfileinfo setfile; |
| 208 |
int i, high, low, maxeasize; |
| 209 |
|
| 210 |
setfile.generic.level = RAW_SFILEINFO_EA_SET; |
| 211 |
setfile.generic.in.file.fnum = fnum; |
| 212 |
setfile.ea_set.in.num_eas = 1; |
| 213 |
setfile.ea_set.in.eas = &eastruct; |
| 214 |
setfile.ea_set.in.eas->flags = 0; |
| 215 |
setfile.ea_set.in.eas->name.s = eaname; |
| 216 |
setfile.ea_set.in.eas->value = eablob; |
| 217 |
|
| 218 |
maxeasize = eablob.length; |
| 219 |
i = eastart; |
| 220 |
low = 0; |
| 221 |
high = maxeasize; |
| 222 |
|
| 223 |
do { |
| 224 |
if (eadebug) { |
| 225 |
torture_comment(tctx, "Testing EA size: %d\n", i); |
| 226 |
} |
| 227 |
setfile.ea_set.in.eas->value.length = i; |
| 228 |
|
| 229 |
status = smb_raw_setfileinfo(cli->tree, &setfile); |
| 230 |
|
| 231 |
if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) { |
| 232 |
if (eadebug) { |
| 233 |
torture_comment(tctx, "[%s] EA size %d succeeded! " |
| 234 |
"(high=%d low=%d)\n", |
| 235 |
eaname, i, high, low); |
| 236 |
} |
| 237 |
low = i; |
| 238 |
if (low == maxeasize) { |
| 239 |
torture_comment(tctx, "Max. EA size for \"%s\"=%d " |
| 240 |
"[but could be possibly larger]\n", |
| 241 |
eaname, low); |
| 242 |
break; |
| 243 |
} |
| 244 |
if (high - low == 1 && high != maxeasize) { |
| 245 |
torture_comment(tctx, "Max. EA size for \"%s\"=%d\n", |
| 246 |
eaname, low); |
| 247 |
break; |
| 248 |
} |
| 249 |
i += (high - low + 1) / 2; |
| 250 |
} else { |
| 251 |
if (eadebug) { |
| 252 |
torture_comment(tctx, "[%s] EA size %d failed! " |
| 253 |
"(high=%d low=%d) [%s]\n", |
| 254 |
eaname, i, high, low, |
| 255 |
nt_errstr(status)); |
| 256 |
} |
| 257 |
high = i; |
| 258 |
if (high - low <= 1) { |
| 259 |
torture_comment(tctx, "Max. EA size for \"%s\"=%d\n", |
| 260 |
eaname, low); |
| 261 |
break; |
| 262 |
} |
| 263 |
i -= (high - low + 1) / 2; |
| 264 |
} |
| 265 |
} while (true); |
| 266 |
|
| 267 |
return low; |
| 268 |
} |
| 269 |
|
| 270 |
/* |
| 271 |
* Test for maximum ea size - more than one ea name is checked. |
| 272 |
* |
| 273 |
* Additional parameters can be passed, to allow further testing: |
| 274 |
* |
| 275 |
* default |
| 276 |
* maxeasize 65536 limit the max. size for a single EA name |
| 277 |
* maxeanames 101 limit of the number of tested names |
| 278 |
* maxeastart 1 this EA size is used to test for the 1st EA (atm) |
| 279 |
* maxeadebug 0 if set true, further debug output is done - in addition |
| 280 |
* the testfile is not deleted for further inspection! |
| 281 |
* |
| 282 |
* Set some/all of these options on the cmdline with: |
| 283 |
* --option torture:maxeasize=1024 --option torture:maxeadebug=1 ... |
| 284 |
* |
| 285 |
*/ |
| 286 |
static bool test_max_eas(struct smbcli_state *cli, struct torture_context *tctx) |
| 287 |
{ |
| 288 |
NTSTATUS status; |
| 289 |
union smb_open io; |
| 290 |
const char *fname = BASEDIR "\\ea_max.txt"; |
| 291 |
int fnum = -1; |
| 292 |
bool ret = true; |
| 293 |
bool err = false; |
| 294 |
|
| 295 |
int i, j, k, last; |
| 296 |
size_t total; |
| 297 |
DATA_BLOB eablob; |
| 298 |
char *eaname = NULL; |
| 299 |
int maxeasize; |
| 300 |
int maxeanames; |
| 301 |
int maxeastart; |
| 302 |
|
| 303 |
torture_comment(tctx, "TESTING SETFILEINFO MAX. EA_SET\n"); |
| 304 |
|
| 305 |
maxeasize = torture_setting_int(tctx, "maxeasize", 65536); |
| 306 |
maxeanames = torture_setting_int(tctx, "maxeanames", 101); |
| 307 |
maxeastart = torture_setting_int(tctx, "maxeastart", 1); |
| 308 |
maxeadebug = torture_setting_bool(tctx, "maxeadebug", false); |
| 309 |
|
| 310 |
/* Do some sanity check on possibly passed parms */ |
| 311 |
if (maxeasize <= 0) { |
| 312 |
torture_comment(tctx, "Invalid parameter 'maxeasize=%d'",maxeasize); |
| 313 |
err = true; |
| 314 |
} |
| 315 |
if (maxeanames <= 0) { |
| 316 |
torture_comment(tctx, "Invalid parameter 'maxeanames=%d'",maxeanames); |
| 317 |
err = true; |
| 318 |
} |
| 319 |
if (maxeastart <= 0) { |
| 320 |
torture_comment(tctx, "Invalid parameter 'maxeastart=%d'",maxeastart); |
| 321 |
err = true; |
| 322 |
} |
| 323 |
if (err) { |
| 324 |
torture_comment(tctx, "\n\n"); |
| 325 |
goto done; |
| 326 |
} |
| 327 |
if (maxeastart > maxeasize) { |
| 328 |
maxeastart = maxeasize; |
| 329 |
torture_comment(tctx, "'maxeastart' outside range - corrected to %d\n", |
| 330 |
maxeastart); |
| 331 |
} |
| 332 |
torture_comment(tctx, "MAXEA parms: maxeasize=%d maxeanames=%d maxeastart=%d" |
| 333 |
" maxeadebug=%d\n", maxeasize, maxeanames, maxeastart, |
| 334 |
maxeadebug); |
| 335 |
|
| 336 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 337 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 338 |
io.ntcreatex.in.flags = 0; |
| 339 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 340 |
io.ntcreatex.in.create_options = 0; |
| 341 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 342 |
io.ntcreatex.in.share_access = |
| 343 |
NTCREATEX_SHARE_ACCESS_READ | |
| 344 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 345 |
io.ntcreatex.in.alloc_size = 0; |
| 346 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 347 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 348 |
io.ntcreatex.in.security_flags = 0; |
| 349 |
io.ntcreatex.in.fname = fname; |
| 350 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 351 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 352 |
fnum = io.ntcreatex.out.file.fnum; |
| 353 |
|
| 354 |
eablob = data_blob_talloc(tctx, NULL, maxeasize); |
| 355 |
if (eablob.data == NULL) { |
| 356 |
goto done; |
| 357 |
} |
| 358 |
/* |
| 359 |
* Fill in some EA data - the offset could be easily checked |
| 360 |
* during a hexdump. |
| 361 |
*/ |
| 362 |
for (i = 0, k = 0; i < eablob.length / 4; i++, k+=4) { |
| 363 |
eablob.data[k] = k & 0xff; |
| 364 |
eablob.data[k+1] = (k >> 8) & 0xff; |
| 365 |
eablob.data[k+2] = (k >> 16) & 0xff; |
| 366 |
eablob.data[k+3] = (k >> 24) & 0xff; |
| 367 |
} |
| 368 |
|
| 369 |
i = eablob.length % 4; |
| 370 |
if (i-- > 0) { |
| 371 |
eablob.data[k] = k & 0xff; |
| 372 |
if (i-- > 0) { |
| 373 |
eablob.data[k+1] = (k >> 8) & 0xff; |
| 374 |
if (i-- > 0) { |
| 375 |
eablob.data[k+2] = (k >> 16) & 0xff; |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
/* |
| 380 |
* Filesystems might allow max. EAs data for different EA names. |
| 381 |
* So more than one EA name should be checked. |
| 382 |
*/ |
| 383 |
total = 0; |
| 384 |
last = maxeastart; |
| 385 |
|
| 386 |
for (i = 0; i < maxeanames; i++) { |
| 387 |
if (eaname != NULL) { |
| 388 |
talloc_free(eaname); |
| 389 |
} |
| 390 |
eaname = talloc_asprintf(tctx, "MAX%d", i); |
| 391 |
if(eaname == NULL) { |
| 392 |
goto done; |
| 393 |
} |
| 394 |
j = test_one_eamax(tctx, cli, fnum, eaname, eablob, last, maxeadebug); |
| 395 |
if (j <= 0) { |
| 396 |
break; |
| 397 |
} |
| 398 |
total += j; |
| 399 |
last = j; |
| 400 |
} |
| 401 |
|
| 402 |
torture_comment(tctx, "Total EA size:%zu\n", total); |
| 403 |
if (i == maxeanames) { |
| 404 |
torture_comment(tctx, "NOTE: More EAs could be available!\n"); |
| 405 |
} |
| 406 |
if (total == 0) { |
| 407 |
ret = false; |
| 408 |
} |
| 409 |
done: |
| 410 |
smbcli_close(cli->tree, fnum); |
| 411 |
return ret; |
| 412 |
} |
| 413 |
|
| 414 |
/* |
| 415 |
test using NTTRANS CREATE to create a file with an initial EA set |
| 416 |
*/ |
| 417 |
static bool test_nttrans_create(struct smbcli_state *cli, struct torture_context *tctx) |
| 418 |
{ |
| 419 |
NTSTATUS status; |
| 420 |
union smb_open io; |
| 421 |
const char *fname = BASEDIR "\\ea2.txt"; |
| 422 |
const char *fname_bad = BASEDIR "\\ea2_bad.txt"; |
| 423 |
bool ret = true; |
| 424 |
int fnum = -1; |
| 425 |
struct ea_struct eas[3]; |
| 426 |
struct smb_ea_list ea_list; |
| 427 |
|
| 428 |
torture_comment(tctx, "TESTING NTTRANS CREATE WITH EAS\n"); |
| 429 |
|
| 430 |
io.generic.level = RAW_OPEN_NTTRANS_CREATE; |
| 431 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 432 |
io.ntcreatex.in.flags = 0; |
| 433 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 434 |
io.ntcreatex.in.create_options = 0; |
| 435 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 436 |
io.ntcreatex.in.share_access = |
| 437 |
NTCREATEX_SHARE_ACCESS_READ | |
| 438 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 439 |
io.ntcreatex.in.alloc_size = 0; |
| 440 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 441 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 442 |
io.ntcreatex.in.security_flags = 0; |
| 443 |
io.ntcreatex.in.fname = fname; |
| 444 |
|
| 445 |
ea_list.num_eas = 3; |
| 446 |
ea_list.eas = eas; |
| 447 |
|
| 448 |
eas[0].flags = 0; |
| 449 |
eas[0].name.s = "1st EA"; |
| 450 |
eas[0].value = data_blob_string_const("Value One"); |
| 451 |
|
| 452 |
eas[1].flags = 0; |
| 453 |
eas[1].name.s = "2nd EA"; |
| 454 |
eas[1].value = data_blob_string_const("Second Value"); |
| 455 |
|
| 456 |
eas[2].flags = 0; |
| 457 |
eas[2].name.s = "and 3rd"; |
| 458 |
eas[2].value = data_blob_string_const("final value"); |
| 459 |
|
| 460 |
io.ntcreatex.in.ea_list = &ea_list; |
| 461 |
io.ntcreatex.in.sec_desc = NULL; |
| 462 |
|
| 463 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 464 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 465 |
fnum = io.ntcreatex.out.file.fnum; |
| 466 |
|
| 467 |
ret &= check_ea(cli, fname, "EAONE", NULL); |
| 468 |
ret &= check_ea(cli, fname, "1st EA", "Value One"); |
| 469 |
ret &= check_ea(cli, fname, "2nd EA", "Second Value"); |
| 470 |
ret &= check_ea(cli, fname, "and 3rd", "final value"); |
| 471 |
|
| 472 |
smbcli_close(cli->tree, fnum); |
| 473 |
|
| 474 |
torture_comment(tctx, "Trying to add EAs on non-create\n"); |
| 475 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; |
| 476 |
io.ntcreatex.in.fname = fname; |
| 477 |
|
| 478 |
ea_list.num_eas = 1; |
| 479 |
eas[0].flags = 0; |
| 480 |
eas[0].name.s = "Fourth EA"; |
| 481 |
eas[0].value = data_blob_string_const("Value Four"); |
| 482 |
|
| 483 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 484 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 485 |
fnum = io.ntcreatex.out.file.fnum; |
| 486 |
|
| 487 |
ret &= check_ea(cli, fname, "1st EA", "Value One"); |
| 488 |
ret &= check_ea(cli, fname, "2nd EA", "Second Value"); |
| 489 |
ret &= check_ea(cli, fname, "and 3rd", "final value"); |
| 490 |
ret &= check_ea(cli, fname, "Fourth EA", NULL); |
| 491 |
|
| 492 |
torture_comment(tctx, "TESTING NTTRANS CREATE WITH BAD EA NAMES\n"); |
| 493 |
|
| 494 |
io.generic.level = RAW_OPEN_NTTRANS_CREATE; |
| 495 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 496 |
io.ntcreatex.in.flags = 0; |
| 497 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 498 |
io.ntcreatex.in.create_options = 0; |
| 499 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 500 |
io.ntcreatex.in.share_access = |
| 501 |
NTCREATEX_SHARE_ACCESS_READ | |
| 502 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 503 |
io.ntcreatex.in.alloc_size = 0; |
| 504 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 505 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 506 |
io.ntcreatex.in.security_flags = 0; |
| 507 |
io.ntcreatex.in.fname = fname_bad; |
| 508 |
|
| 509 |
ea_list.num_eas = 3; |
| 510 |
ea_list.eas = eas; |
| 511 |
|
| 512 |
eas[0].flags = 0; |
| 513 |
eas[0].name.s = "1st EA"; |
| 514 |
eas[0].value = data_blob_string_const("Value One"); |
| 515 |
|
| 516 |
eas[1].flags = 0; |
| 517 |
eas[1].name.s = "2nd:BAD:EA"; |
| 518 |
eas[1].value = data_blob_string_const("Second Value"); |
| 519 |
|
| 520 |
eas[2].flags = 0; |
| 521 |
eas[2].name.s = "and 3rd"; |
| 522 |
eas[2].value = data_blob_string_const("final value"); |
| 523 |
|
| 524 |
io.ntcreatex.in.ea_list = &ea_list; |
| 525 |
io.ntcreatex.in.sec_desc = NULL; |
| 526 |
|
| 527 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 528 |
CHECK_STATUS(status, STATUS_INVALID_EA_NAME); |
| 529 |
|
| 530 |
/* File must not exist. */ |
| 531 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 532 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 533 |
io.ntcreatex.in.flags = 0; |
| 534 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 535 |
io.ntcreatex.in.create_options = 0; |
| 536 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 537 |
io.ntcreatex.in.share_access = |
| 538 |
NTCREATEX_SHARE_ACCESS_READ | |
| 539 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 540 |
io.ntcreatex.in.alloc_size = 0; |
| 541 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; |
| 542 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 543 |
io.ntcreatex.in.security_flags = 0; |
| 544 |
io.ntcreatex.in.fname = fname_bad; |
| 545 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 546 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 547 |
|
| 548 |
done: |
| 549 |
smbcli_close(cli->tree, fnum); |
| 550 |
return ret; |
| 551 |
} |
| 552 |
|
| 553 |
/* |
| 554 |
basic testing of EA calls |
| 555 |
*/ |
| 556 |
bool torture_raw_eas(struct torture_context *torture, struct smbcli_state *cli) |
| 557 |
{ |
| 558 |
bool ret = true; |
| 559 |
|
| 560 |
torture_assert(torture, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 561 |
|
| 562 |
ret &= test_eas(cli, torture); |
| 563 |
ret &= test_nttrans_create(cli, torture); |
| 564 |
|
| 565 |
smb_raw_exit(cli->session); |
| 566 |
|
| 567 |
return ret; |
| 568 |
} |
| 569 |
|
| 570 |
/* |
| 571 |
test max EA size |
| 572 |
*/ |
| 573 |
bool torture_max_eas(struct torture_context *torture) |
| 574 |
{ |
| 575 |
struct smbcli_state *cli; |
| 576 |
bool ret = true; |
| 577 |
|
| 578 |
if (!torture_open_connection(&cli, torture, 0)) { |
| 579 |
return false; |
| 580 |
} |
| 581 |
|
| 582 |
torture_assert(torture, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 583 |
|
| 584 |
ret &= test_max_eas(cli, torture); |
| 585 |
|
| 586 |
smb_raw_exit(cli->session); |
| 587 |
if (!maxeadebug) { |
| 588 |
/* in no ea debug case, all files are gone now */ |
| 589 |
smbcli_deltree(cli->tree, BASEDIR); |
| 590 |
} |
| 591 |
|
| 592 |
torture_close_connection(cli); |
| 593 |
return ret; |
| 594 |
} |