| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
rename test suite |
| 4 |
Copyright (C) Andrew Tridgell 2003 |
| 5 |
|
| 6 |
This program is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 3 of the License, or |
| 9 |
(at your option) any later version. |
| 10 |
|
| 11 |
This program is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "includes.h" |
| 21 |
#include "libcli/libcli.h" |
| 22 |
#include "torture/util.h" |
| 23 |
#include "torture/raw/proto.h" |
| 24 |
|
| 25 |
#define CHECK_STATUS(status, correct) do { \ |
| 26 |
if (!NT_STATUS_EQUAL(status, correct)) { \ |
| 27 |
torture_result(tctx, TORTURE_FAIL, \ |
| 28 |
"(%s) Incorrect status %s - should be %s\n", \ |
| 29 |
__location__, nt_errstr(status), nt_errstr(correct)); \ |
| 30 |
ret = false; \ |
| 31 |
goto done; \ |
| 32 |
}} while (0) |
| 33 |
|
| 34 |
#define CHECK_VALUE(v, correct) do { \ |
| 35 |
if ((v) != (correct)) { \ |
| 36 |
torture_result(tctx, TORTURE_FAIL, \ |
| 37 |
"(%s) Incorrect %s %d - should be %d\n", \ |
| 38 |
__location__, #v, (int)v, (int)correct); \ |
| 39 |
ret = false; \ |
| 40 |
}} while (0) |
| 41 |
|
| 42 |
#define BASEDIR "\\testrename" |
| 43 |
|
| 44 |
/* |
| 45 |
test SMBmv ops |
| 46 |
*/ |
| 47 |
static bool test_mv(struct torture_context *tctx, |
| 48 |
struct smbcli_state *cli) |
| 49 |
{ |
| 50 |
union smb_rename io; |
| 51 |
NTSTATUS status; |
| 52 |
bool ret = true; |
| 53 |
int fnum = -1; |
| 54 |
const char *fname1 = BASEDIR "\\test1.txt"; |
| 55 |
const char *fname2 = BASEDIR "\\test2.txt"; |
| 56 |
const char *Fname1 = BASEDIR "\\Test1.txt"; |
| 57 |
union smb_fileinfo finfo; |
| 58 |
union smb_open op; |
| 59 |
|
| 60 |
torture_comment(tctx, "Testing SMBmv\n"); |
| 61 |
|
| 62 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 63 |
|
| 64 |
torture_comment(tctx, "Trying simple rename\n"); |
| 65 |
|
| 66 |
op.generic.level = RAW_OPEN_NTCREATEX; |
| 67 |
op.ntcreatex.in.root_fid.fnum = 0; |
| 68 |
op.ntcreatex.in.flags = 0; |
| 69 |
op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 70 |
op.ntcreatex.in.create_options = 0; |
| 71 |
op.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 72 |
op.ntcreatex.in.share_access = |
| 73 |
NTCREATEX_SHARE_ACCESS_READ | |
| 74 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 75 |
op.ntcreatex.in.alloc_size = 0; |
| 76 |
op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; |
| 77 |
op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 78 |
op.ntcreatex.in.security_flags = 0; |
| 79 |
op.ntcreatex.in.fname = fname1; |
| 80 |
|
| 81 |
status = smb_raw_open(cli->tree, tctx, &op); |
| 82 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 83 |
fnum = op.ntcreatex.out.file.fnum; |
| 84 |
|
| 85 |
io.generic.level = RAW_RENAME_RENAME; |
| 86 |
io.rename.in.pattern1 = fname1; |
| 87 |
io.rename.in.pattern2 = fname2; |
| 88 |
io.rename.in.attrib = 0; |
| 89 |
|
| 90 |
torture_comment(tctx, "trying rename while first file open\n"); |
| 91 |
status = smb_raw_rename(cli->tree, &io); |
| 92 |
CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); |
| 93 |
|
| 94 |
smbcli_close(cli->tree, fnum); |
| 95 |
|
| 96 |
op.ntcreatex.in.access_mask = SEC_FILE_READ_DATA; |
| 97 |
op.ntcreatex.in.share_access = |
| 98 |
NTCREATEX_SHARE_ACCESS_DELETE | |
| 99 |
NTCREATEX_SHARE_ACCESS_READ | |
| 100 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 101 |
status = smb_raw_open(cli->tree, tctx, &op); |
| 102 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 103 |
fnum = op.ntcreatex.out.file.fnum; |
| 104 |
|
| 105 |
torture_comment(tctx, "trying rename while first file open with SHARE_ACCESS_DELETE\n"); |
| 106 |
status = smb_raw_rename(cli->tree, &io); |
| 107 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 108 |
|
| 109 |
io.rename.in.pattern1 = fname2; |
| 110 |
io.rename.in.pattern2 = fname1; |
| 111 |
status = smb_raw_rename(cli->tree, &io); |
| 112 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 113 |
|
| 114 |
torture_comment(tctx, "Trying case-changing rename\n"); |
| 115 |
io.rename.in.pattern1 = fname1; |
| 116 |
io.rename.in.pattern2 = Fname1; |
| 117 |
status = smb_raw_rename(cli->tree, &io); |
| 118 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 119 |
|
| 120 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 121 |
finfo.all_info.in.file.path = fname1; |
| 122 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 123 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 124 |
if (strcmp(finfo.all_info.out.fname.s, Fname1) != 0) { |
| 125 |
torture_warning(tctx, "(%s) Incorrect filename [%s] after case-changing " |
| 126 |
"rename, should be [%s]\n", __location__, |
| 127 |
finfo.all_info.out.fname.s, Fname1); |
| 128 |
} |
| 129 |
|
| 130 |
io.rename.in.pattern1 = fname1; |
| 131 |
io.rename.in.pattern2 = fname2; |
| 132 |
|
| 133 |
torture_comment(tctx, "trying rename while not open\n"); |
| 134 |
smb_raw_exit(cli->session); |
| 135 |
status = smb_raw_rename(cli->tree, &io); |
| 136 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 137 |
|
| 138 |
torture_comment(tctx, "Trying self rename\n"); |
| 139 |
io.rename.in.pattern1 = fname2; |
| 140 |
io.rename.in.pattern2 = fname2; |
| 141 |
status = smb_raw_rename(cli->tree, &io); |
| 142 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 143 |
|
| 144 |
io.rename.in.pattern1 = fname1; |
| 145 |
io.rename.in.pattern2 = fname1; |
| 146 |
status = smb_raw_rename(cli->tree, &io); |
| 147 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 148 |
|
| 149 |
done: |
| 150 |
smbcli_close(cli->tree, fnum); |
| 151 |
smb_raw_exit(cli->session); |
| 152 |
smbcli_deltree(cli->tree, BASEDIR); |
| 153 |
return ret; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
static bool test_osxrename(struct torture_context *tctx, |
| 158 |
struct smbcli_state *cli) |
| 159 |
{ |
| 160 |
union smb_rename io; |
| 161 |
union smb_unlink io_un; |
| 162 |
NTSTATUS status; |
| 163 |
bool ret = true; |
| 164 |
int fnum = -1; |
| 165 |
const char *fname1 = BASEDIR "\\test1"; |
| 166 |
const char *FNAME1 = BASEDIR "\\TEST1"; |
| 167 |
union smb_fileinfo finfo; |
| 168 |
union smb_open op; |
| 169 |
|
| 170 |
torture_comment(tctx, "\nTesting OSX Rename\n"); |
| 171 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 172 |
op.generic.level = RAW_OPEN_NTCREATEX; |
| 173 |
op.ntcreatex.in.root_fid.fnum = 0; |
| 174 |
op.ntcreatex.in.flags = 0; |
| 175 |
op.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 176 |
op.ntcreatex.in.create_options = 0; |
| 177 |
op.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 178 |
op.ntcreatex.in.share_access = |
| 179 |
NTCREATEX_SHARE_ACCESS_READ | |
| 180 |
NTCREATEX_SHARE_ACCESS_WRITE; |
| 181 |
op.ntcreatex.in.alloc_size = 0; |
| 182 |
op.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; |
| 183 |
op.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 184 |
op.ntcreatex.in.security_flags = 0; |
| 185 |
op.ntcreatex.in.fname = fname1; |
| 186 |
|
| 187 |
status = smb_raw_open(cli->tree, tctx, &op); |
| 188 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 189 |
fnum = op.ntcreatex.out.file.fnum; |
| 190 |
|
| 191 |
io.generic.level = RAW_RENAME_RENAME; |
| 192 |
io.rename.in.attrib = 0; |
| 193 |
|
| 194 |
smbcli_close(cli->tree, fnum); |
| 195 |
|
| 196 |
/* Rename by changing case. First check for the |
| 197 |
* existence of the file with the "newname". |
| 198 |
* If we find one and both the output and input are same case, |
| 199 |
* delete it. */ |
| 200 |
|
| 201 |
torture_comment(tctx, "Checking os X rename (case changing)\n"); |
| 202 |
|
| 203 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 204 |
finfo.all_info.in.file.path = FNAME1; |
| 205 |
torture_comment(tctx, "Looking for file %s \n",FNAME1); |
| 206 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 207 |
|
| 208 |
if (NT_STATUS_EQUAL(status, NT_STATUS_OK)) { |
| 209 |
torture_comment(tctx, "Name of the file found %s \n", finfo.all_info.out.fname.s); |
| 210 |
if (strcmp(finfo.all_info.out.fname.s, finfo.all_info.in.file.path) == 0) { |
| 211 |
/* If file is found with the same case delete it */ |
| 212 |
torture_comment(tctx, "Deleting File %s \n", finfo.all_info.out.fname.s); |
| 213 |
io_un.unlink.in.pattern = finfo.all_info.out.fname.s; |
| 214 |
io_un.unlink.in.attrib = 0; |
| 215 |
status = smb_raw_unlink(cli->tree, &io_un); |
| 216 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
io.rename.in.pattern1 = fname1; |
| 221 |
io.rename.in.pattern2 = FNAME1; |
| 222 |
status = smb_raw_rename(cli->tree, &io); |
| 223 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 224 |
|
| 225 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 226 |
finfo.all_info.in.file.path = fname1; |
| 227 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 228 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 229 |
torture_comment(tctx, "File name after rename %s \n",finfo.all_info.out.fname.s); |
| 230 |
|
| 231 |
done: |
| 232 |
smbcli_close(cli->tree, fnum); |
| 233 |
smb_raw_exit(cli->session); |
| 234 |
smbcli_deltree(cli->tree, BASEDIR); |
| 235 |
return ret; |
| 236 |
} |
| 237 |
|
| 238 |
/* |
| 239 |
test SMBntrename ops |
| 240 |
*/ |
| 241 |
static bool test_ntrename(struct torture_context *tctx, |
| 242 |
struct smbcli_state *cli) |
| 243 |
{ |
| 244 |
union smb_rename io; |
| 245 |
NTSTATUS status; |
| 246 |
bool ret = true; |
| 247 |
int fnum, i; |
| 248 |
const char *fname1 = BASEDIR "\\test1.txt"; |
| 249 |
const char *fname2 = BASEDIR "\\test2.txt"; |
| 250 |
union smb_fileinfo finfo; |
| 251 |
|
| 252 |
torture_comment(tctx, "Testing SMBntrename\n"); |
| 253 |
|
| 254 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 255 |
|
| 256 |
torture_comment(tctx, "Trying simple rename\n"); |
| 257 |
|
| 258 |
fnum = create_complex_file(cli, tctx, fname1); |
| 259 |
|
| 260 |
io.generic.level = RAW_RENAME_NTRENAME; |
| 261 |
io.ntrename.in.old_name = fname1; |
| 262 |
io.ntrename.in.new_name = fname2; |
| 263 |
io.ntrename.in.attrib = 0; |
| 264 |
io.ntrename.in.cluster_size = 0; |
| 265 |
io.ntrename.in.flags = RENAME_FLAG_RENAME; |
| 266 |
|
| 267 |
status = smb_raw_rename(cli->tree, &io); |
| 268 |
CHECK_STATUS(status, NT_STATUS_SHARING_VIOLATION); |
| 269 |
|
| 270 |
smbcli_close(cli->tree, fnum); |
| 271 |
status = smb_raw_rename(cli->tree, &io); |
| 272 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 273 |
|
| 274 |
torture_comment(tctx, "Trying self rename\n"); |
| 275 |
io.ntrename.in.old_name = fname2; |
| 276 |
io.ntrename.in.new_name = fname2; |
| 277 |
status = smb_raw_rename(cli->tree, &io); |
| 278 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 279 |
|
| 280 |
io.ntrename.in.old_name = fname1; |
| 281 |
io.ntrename.in.new_name = fname1; |
| 282 |
status = smb_raw_rename(cli->tree, &io); |
| 283 |
CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND); |
| 284 |
|
| 285 |
torture_comment(tctx, "trying wildcard rename\n"); |
| 286 |
io.ntrename.in.old_name = BASEDIR "\\*.txt"; |
| 287 |
io.ntrename.in.new_name = fname1; |
| 288 |
|
| 289 |
status = smb_raw_rename(cli->tree, &io); |
| 290 |
CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD); |
| 291 |
|
| 292 |
torture_comment(tctx, "Checking attrib handling\n"); |
| 293 |
torture_set_file_attribute(cli->tree, fname2, FILE_ATTRIBUTE_HIDDEN); |
| 294 |
io.ntrename.in.old_name = fname2; |
| 295 |
io.ntrename.in.new_name = fname1; |
| 296 |
io.ntrename.in.attrib = 0; |
| 297 |
status = smb_raw_rename(cli->tree, &io); |
| 298 |
CHECK_STATUS(status, NT_STATUS_NO_SUCH_FILE); |
| 299 |
|
| 300 |
io.ntrename.in.attrib = FILE_ATTRIBUTE_HIDDEN; |
| 301 |
status = smb_raw_rename(cli->tree, &io); |
| 302 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 303 |
|
| 304 |
torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL); |
| 305 |
|
| 306 |
torture_comment(tctx, "Checking copy\n"); |
| 307 |
io.ntrename.in.old_name = fname1; |
| 308 |
io.ntrename.in.new_name = fname2; |
| 309 |
io.ntrename.in.attrib = 0; |
| 310 |
io.ntrename.in.flags = RENAME_FLAG_COPY; |
| 311 |
status = smb_raw_rename(cli->tree, &io); |
| 312 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 313 |
|
| 314 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 315 |
finfo.generic.in.file.path = fname1; |
| 316 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 317 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 318 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 319 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL); |
| 320 |
|
| 321 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 322 |
finfo.generic.in.file.path = fname2; |
| 323 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 324 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 325 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 326 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL); |
| 327 |
|
| 328 |
torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_SYSTEM); |
| 329 |
|
| 330 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 331 |
finfo.generic.in.file.path = fname2; |
| 332 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 333 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 334 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 335 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL); |
| 336 |
|
| 337 |
finfo.generic.in.file.path = fname1; |
| 338 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 339 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 340 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 341 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM); |
| 342 |
|
| 343 |
torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL); |
| 344 |
|
| 345 |
smbcli_unlink(cli->tree, fname2); |
| 346 |
|
| 347 |
finfo.generic.in.file.path = fname1; |
| 348 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 349 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 350 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 351 |
|
| 352 |
torture_comment(tctx, "Checking invalid flags\n"); |
| 353 |
io.ntrename.in.old_name = fname1; |
| 354 |
io.ntrename.in.new_name = fname2; |
| 355 |
io.ntrename.in.attrib = 0; |
| 356 |
io.ntrename.in.flags = 0; |
| 357 |
status = smb_raw_rename(cli->tree, &io); |
| 358 |
if (TARGET_IS_WIN7(tctx)) { |
| 359 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 360 |
} else { |
| 361 |
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); |
| 362 |
} |
| 363 |
|
| 364 |
io.ntrename.in.flags = 300; |
| 365 |
status = smb_raw_rename(cli->tree, &io); |
| 366 |
if (TARGET_IS_WIN7(tctx)) { |
| 367 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 368 |
} else { |
| 369 |
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); |
| 370 |
} |
| 371 |
|
| 372 |
io.ntrename.in.flags = 0x106; |
| 373 |
status = smb_raw_rename(cli->tree, &io); |
| 374 |
if (TARGET_IS_WIN7(tctx)) { |
| 375 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 376 |
} else { |
| 377 |
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); |
| 378 |
} |
| 379 |
|
| 380 |
torture_comment(tctx, "Checking unknown field\n"); |
| 381 |
io.ntrename.in.old_name = fname1; |
| 382 |
io.ntrename.in.new_name = fname2; |
| 383 |
io.ntrename.in.attrib = 0; |
| 384 |
io.ntrename.in.flags = RENAME_FLAG_RENAME; |
| 385 |
io.ntrename.in.cluster_size = 0xff; |
| 386 |
status = smb_raw_rename(cli->tree, &io); |
| 387 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 388 |
|
| 389 |
torture_comment(tctx, "Trying RENAME_FLAG_MOVE_CLUSTER_INFORMATION\n"); |
| 390 |
|
| 391 |
io.ntrename.in.old_name = fname2; |
| 392 |
io.ntrename.in.new_name = fname1; |
| 393 |
io.ntrename.in.attrib = 0; |
| 394 |
io.ntrename.in.flags = RENAME_FLAG_MOVE_CLUSTER_INFORMATION; |
| 395 |
io.ntrename.in.cluster_size = 1; |
| 396 |
status = smb_raw_rename(cli->tree, &io); |
| 397 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 398 |
|
| 399 |
io.ntrename.in.flags = RENAME_FLAG_COPY; |
| 400 |
status = smb_raw_rename(cli->tree, &io); |
| 401 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 402 |
|
| 403 |
#if 0 |
| 404 |
{ |
| 405 |
char buf[16384]; |
| 406 |
fnum = smbcli_open(cli->tree, fname1, O_RDWR, DENY_NONE); |
| 407 |
memset(buf, 1, sizeof(buf)); |
| 408 |
smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf)); |
| 409 |
smbcli_close(cli->tree, fnum); |
| 410 |
|
| 411 |
fnum = smbcli_open(cli->tree, fname2, O_RDWR, DENY_NONE); |
| 412 |
memset(buf, 1, sizeof(buf)); |
| 413 |
smbcli_write(cli->tree, fnum, 0, buf, 0, sizeof(buf)-1); |
| 414 |
smbcli_close(cli->tree, fnum); |
| 415 |
|
| 416 |
torture_all_info(cli->tree, fname1); |
| 417 |
torture_all_info(cli->tree, fname2); |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
io.ntrename.in.flags = RENAME_FLAG_MOVE_CLUSTER_INFORMATION; |
| 422 |
status = smb_raw_rename(cli->tree, &io); |
| 423 |
CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER); |
| 424 |
|
| 425 |
for (i=0;i<20000;i++) { |
| 426 |
io.ntrename.in.cluster_size = i; |
| 427 |
status = smb_raw_rename(cli->tree, &io); |
| 428 |
if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) { |
| 429 |
torture_warning(tctx, "i=%d status=%s\n", i, nt_errstr(status)); |
| 430 |
} |
| 431 |
} |
| 432 |
#endif |
| 433 |
|
| 434 |
torture_comment(tctx, "Checking other flags\n"); |
| 435 |
|
| 436 |
for (i=0;i<0xFFF;i++) { |
| 437 |
if (i == RENAME_FLAG_RENAME || |
| 438 |
i == RENAME_FLAG_HARD_LINK || |
| 439 |
i == RENAME_FLAG_COPY) { |
| 440 |
continue; |
| 441 |
} |
| 442 |
|
| 443 |
io.ntrename.in.old_name = fname2; |
| 444 |
io.ntrename.in.new_name = fname1; |
| 445 |
io.ntrename.in.flags = i; |
| 446 |
io.ntrename.in.attrib = 0; |
| 447 |
io.ntrename.in.cluster_size = 0; |
| 448 |
status = smb_raw_rename(cli->tree, &io); |
| 449 |
if (TARGET_IS_WIN7(tctx)){ |
| 450 |
if (!NT_STATUS_EQUAL(status, |
| 451 |
NT_STATUS_INVALID_PARAMETER)) { |
| 452 |
torture_warning(tctx, "flags=0x%x status=%s\n", |
| 453 |
i, nt_errstr(status)); |
| 454 |
} |
| 455 |
} else { |
| 456 |
if (!NT_STATUS_EQUAL(status, |
| 457 |
NT_STATUS_ACCESS_DENIED)) { |
| 458 |
torture_warning(tctx, "flags=0x%x status=%s\n", |
| 459 |
i, nt_errstr(status)); |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
done: |
| 465 |
smb_raw_exit(cli->session); |
| 466 |
smbcli_deltree(cli->tree, BASEDIR); |
| 467 |
return ret; |
| 468 |
} |
| 469 |
|
| 470 |
/* |
| 471 |
test SMBntrename ops |
| 472 |
*/ |
| 473 |
static bool test_nthardlink(struct torture_context *tctx, |
| 474 |
struct smbcli_state *cli) |
| 475 |
{ |
| 476 |
union smb_rename io = {}; |
| 477 |
NTSTATUS status; |
| 478 |
bool ret = true; |
| 479 |
int fnum; |
| 480 |
const char *fname1 = BASEDIR "\\test1.txt"; |
| 481 |
const char *fname2 = BASEDIR "\\test2.txt"; |
| 482 |
union smb_fileinfo finfo = {}; |
| 483 |
|
| 484 |
torture_comment(tctx, "Testing SMBnthardlink\n"); |
| 485 |
|
| 486 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 487 |
|
| 488 |
fnum = create_complex_file(cli, tctx, fname1); |
| 489 |
status = smbcli_close(cli->tree, fnum); |
| 490 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 491 |
|
| 492 |
torture_comment(tctx, "Checking hard link\n"); |
| 493 |
io.generic.level = RAW_RENAME_NTRENAME; |
| 494 |
io.ntrename.in.old_name = fname1; |
| 495 |
io.ntrename.in.new_name = fname2; |
| 496 |
io.ntrename.in.attrib = 0; |
| 497 |
io.ntrename.in.flags = RENAME_FLAG_HARD_LINK; |
| 498 |
status = smb_raw_rename(cli->tree, &io); |
| 499 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 500 |
|
| 501 |
torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_SYSTEM); |
| 502 |
|
| 503 |
finfo.generic.level = RAW_FILEINFO_ALL_INFO; |
| 504 |
finfo.generic.in.file.path = fname2; |
| 505 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 506 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 507 |
CHECK_VALUE(finfo.all_info.out.nlink, 2); |
| 508 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM); |
| 509 |
|
| 510 |
finfo.generic.in.file.path = fname1; |
| 511 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 512 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 513 |
CHECK_VALUE(finfo.all_info.out.nlink, 2); |
| 514 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_SYSTEM); |
| 515 |
|
| 516 |
torture_set_file_attribute(cli->tree, fname1, FILE_ATTRIBUTE_NORMAL); |
| 517 |
|
| 518 |
smbcli_unlink(cli->tree, fname2); |
| 519 |
|
| 520 |
finfo.generic.in.file.path = fname1; |
| 521 |
status = smb_raw_pathinfo(cli->tree, tctx, &finfo); |
| 522 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 523 |
CHECK_VALUE(finfo.all_info.out.nlink, 1); |
| 524 |
CHECK_VALUE(finfo.all_info.out.attrib, FILE_ATTRIBUTE_NORMAL); |
| 525 |
|
| 526 |
done: |
| 527 |
smb_raw_exit(cli->session); |
| 528 |
smbcli_deltree(cli->tree, BASEDIR); |
| 529 |
return ret; |
| 530 |
} |
| 531 |
|
| 532 |
/* |
| 533 |
test dir rename. |
| 534 |
*/ |
| 535 |
static bool test_dir_rename(struct torture_context *tctx, struct smbcli_state *cli) |
| 536 |
{ |
| 537 |
union smb_open io; |
| 538 |
union smb_rename ren_io; |
| 539 |
NTSTATUS status; |
| 540 |
const char *dname1 = BASEDIR "\\dir_for_rename"; |
| 541 |
const char *dname2 = BASEDIR "\\renamed_dir"; |
| 542 |
const char *dname1_long = BASEDIR "\\dir_for_rename_long"; |
| 543 |
const char *fname = BASEDIR "\\dir_for_rename\\file.txt"; |
| 544 |
const char *sname = BASEDIR "\\renamed_dir:a stream:$DATA"; |
| 545 |
bool ret = true; |
| 546 |
int fnum = -1; |
| 547 |
|
| 548 |
torture_comment(tctx, "Checking rename on a directory containing an open file.\n"); |
| 549 |
|
| 550 |
torture_assert(tctx, torture_setup_dir(cli, BASEDIR), "Failed to setup up test directory: " BASEDIR); |
| 551 |
|
| 552 |
/* create a directory */ |
| 553 |
smbcli_rmdir(cli->tree, dname1); |
| 554 |
smbcli_rmdir(cli->tree, dname2); |
| 555 |
smbcli_rmdir(cli->tree, dname1_long); |
| 556 |
smbcli_unlink(cli->tree, dname1); |
| 557 |
smbcli_unlink(cli->tree, dname2); |
| 558 |
smbcli_unlink(cli->tree, dname1_long); |
| 559 |
|
| 560 |
ZERO_STRUCT(io); |
| 561 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 562 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 563 |
io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 564 |
io.ntcreatex.in.alloc_size = 0; |
| 565 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 566 |
io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE; |
| 567 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 568 |
io.ntcreatex.in.create_options = NTCREATEX_OPTIONS_DIRECTORY; |
| 569 |
io.ntcreatex.in.fname = dname1; |
| 570 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 571 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 572 |
|
| 573 |
fnum = io.ntcreatex.out.file.fnum; |
| 574 |
smbcli_close(cli->tree, fnum); |
| 575 |
|
| 576 |
/* create the longname directory */ |
| 577 |
io.ntcreatex.in.fname = dname1_long; |
| 578 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 579 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 580 |
|
| 581 |
fnum = io.ntcreatex.out.file.fnum; |
| 582 |
smbcli_close(cli->tree, fnum); |
| 583 |
|
| 584 |
/* Now create and hold open a file. */ |
| 585 |
ZERO_STRUCT(io); |
| 586 |
|
| 587 |
io.generic.level = RAW_OPEN_NTCREATEX; |
| 588 |
io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED; |
| 589 |
io.ntcreatex.in.root_fid.fnum = 0; |
| 590 |
io.ntcreatex.in.alloc_size = 0; |
| 591 |
io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL; |
| 592 |
io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL; |
| 593 |
io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE | NTCREATEX_SHARE_ACCESS_DELETE; |
| 594 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE; |
| 595 |
io.ntcreatex.in.create_options = 0; |
| 596 |
io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS; |
| 597 |
io.ntcreatex.in.security_flags = 0; |
| 598 |
io.ntcreatex.in.fname = fname; |
| 599 |
|
| 600 |
/* Create the file. */ |
| 601 |
|
| 602 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 603 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 604 |
fnum = io.ntcreatex.out.file.fnum; |
| 605 |
|
| 606 |
/* Now try and rename the directory. */ |
| 607 |
|
| 608 |
ZERO_STRUCT(ren_io); |
| 609 |
ren_io.generic.level = RAW_RENAME_RENAME; |
| 610 |
ren_io.rename.in.pattern1 = dname1; |
| 611 |
ren_io.rename.in.pattern2 = dname2; |
| 612 |
ren_io.rename.in.attrib = 0; |
| 613 |
|
| 614 |
status = smb_raw_rename(cli->tree, &ren_io); |
| 615 |
CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED); |
| 616 |
|
| 617 |
/* Close the file and try the rename. */ |
| 618 |
smbcli_close(cli->tree, fnum); |
| 619 |
|
| 620 |
status = smb_raw_rename(cli->tree, &ren_io); |
| 621 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 622 |
|
| 623 |
/* |
| 624 |
* Now try just holding a second handle on the directory and holding |
| 625 |
* it open across a rename. This should be allowed. |
| 626 |
*/ |
| 627 |
io.ntcreatex.in.fname = dname2; |
| 628 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; |
| 629 |
|
| 630 |
io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL | |
| 631 |
SEC_FILE_READ_ATTRIBUTE | SEC_FILE_READ_EA | SEC_FILE_READ_DATA; |
| 632 |
|
| 633 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 634 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 635 |
fnum = io.ntcreatex.out.file.fnum; |
| 636 |
|
| 637 |
ren_io.generic.level = RAW_RENAME_RENAME; |
| 638 |
ren_io.rename.in.pattern1 = dname2; |
| 639 |
ren_io.rename.in.pattern2 = dname1; |
| 640 |
ren_io.rename.in.attrib = 0; |
| 641 |
|
| 642 |
status = smb_raw_rename(cli->tree, &ren_io); |
| 643 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 644 |
|
| 645 |
/* close our handle to the directory. */ |
| 646 |
smbcli_close(cli->tree, fnum); |
| 647 |
|
| 648 |
/* Open a handle on the long name, and then |
| 649 |
* try a rename. This would catch a regression |
| 650 |
* in bug #6781. |
| 651 |
*/ |
| 652 |
io.ntcreatex.in.fname = dname1_long; |
| 653 |
io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN_IF; |
| 654 |
|
| 655 |
io.ntcreatex.in.access_mask = SEC_STD_READ_CONTROL | |
| 656 |
SEC_FILE_READ_ATTRIBUTE | SEC_FILE_READ_EA | SEC_FILE_READ_DATA; |
| 657 |
|
| 658 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 659 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 660 |
fnum = io.ntcreatex.out.file.fnum; |
| 661 |
|
| 662 |
ren_io.generic.level = RAW_RENAME_RENAME; |
| 663 |
ren_io.rename.in.pattern1 = dname1; |
| 664 |
ren_io.rename.in.pattern2 = dname2; |
| 665 |
ren_io.rename.in.attrib = 0; |
| 666 |
|
| 667 |
status = smb_raw_rename(cli->tree, &ren_io); |
| 668 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 669 |
|
| 670 |
/* close our handle to the longname directory. */ |
| 671 |
smbcli_close(cli->tree, fnum); |
| 672 |
|
| 673 |
/* |
| 674 |
* Now try opening a stream on the directory and holding it open |
| 675 |
* across a rename. This should be allowed. |
| 676 |
*/ |
| 677 |
io.ntcreatex.in.fname = sname; |
| 678 |
|
| 679 |
status = smb_raw_open(cli->tree, tctx, &io); |
| 680 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 681 |
fnum = io.ntcreatex.out.file.fnum; |
| 682 |
|
| 683 |
ren_io.generic.level = RAW_RENAME_RENAME; |
| 684 |
ren_io.rename.in.pattern1 = dname2; |
| 685 |
ren_io.rename.in.pattern2 = dname1; |
| 686 |
ren_io.rename.in.attrib = 0; |
| 687 |
|
| 688 |
status = smb_raw_rename(cli->tree, &ren_io); |
| 689 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 690 |
|
| 691 |
done: |
| 692 |
|
| 693 |
if (fnum != -1) { |
| 694 |
smbcli_close(cli->tree, fnum); |
| 695 |
} |
| 696 |
smb_raw_exit(cli->session); |
| 697 |
smbcli_deltree(cli->tree, BASEDIR); |
| 698 |
return ret; |
| 699 |
} |
| 700 |
|
| 701 |
extern bool test_trans2rename(struct torture_context *tctx, struct smbcli_state *cli1, struct smbcli_state *cli2); |
| 702 |
extern bool test_nttransrename(struct torture_context *tctx, struct smbcli_state *cli1); |
| 703 |
|
| 704 |
/* |
| 705 |
basic testing of rename calls |
| 706 |
*/ |
| 707 |
struct torture_suite *torture_raw_rename(TALLOC_CTX *mem_ctx) |
| 708 |
{ |
| 709 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "rename"); |
| 710 |
|
| 711 |
torture_suite_add_1smb_test(suite, "mv", test_mv); |
| 712 |
/* test_trans2rename and test_nttransrename are actually in torture/raw/oplock.c to |
| 713 |
use the handlers and macros there. */ |
| 714 |
torture_suite_add_2smb_test(suite, "trans2rename", test_trans2rename); |
| 715 |
torture_suite_add_1smb_test(suite, "nttransrename", test_nttransrename); |
| 716 |
torture_suite_add_1smb_test(suite, "ntrename", test_ntrename); |
| 717 |
torture_suite_add_1smb_test(suite, "nthardlink", test_nthardlink); |
| 718 |
torture_suite_add_1smb_test(suite, "osxrename", test_osxrename); |
| 719 |
torture_suite_add_1smb_test(suite, "directory rename", test_dir_rename); |
| 720 |
|
| 721 |
return suite; |
| 722 |
} |