Changeset 988 for vendor/current/source3/torture
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source3/torture
- Files:
-
- 19 added
- 7 deleted
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/torture/cmd_vfs.c
r740 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 VFS module functions … … 10 10 the Free Software Foundation; either version 3 of the License, or 11 11 (at your option) any later version. 12 12 13 13 This program is distributed in the hope that it will be useful, 14 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 16 GNU General Public License for more details. 17 17 18 18 You should have received a copy of the GNU General Public License 19 19 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 26 26 #include "vfstest.h" 27 27 #include "../lib/util/util_pw.h" 28 #include "libcli/security/security.h" 29 #include "passdb/machine_sid.h" 28 30 29 31 static const char *null_string = ""; … … 32 34 { 33 35 int i; 34 36 35 37 if (argc < 2) { 36 38 printf("Usage: load <modules>\n"); … … 58 60 c = argv[1][0]; 59 61 size = atoi(argv[2]); 60 vfs->data = TALLOC_ARRAY(mem_ctx, char, size);62 vfs->data = talloc_array(mem_ctx, char, size); 61 63 if (vfs->data == NULL) { 62 64 printf("populate: error=-1 (not enough memory)"); … … 92 94 return NT_STATUS_UNSUCCESSFUL; 93 95 } 94 dump_data(0, (uint8 *)(vfs->data) + offset, len);96 dump_data(0, (uint8_t *)(vfs->data) + offset, len); 95 97 return NT_STATUS_OK; 96 98 } … … 98 100 static NTSTATUS cmd_connect(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) 99 101 { 100 SMB_VFS_CONNECT(vfs->conn, lp_servicename( SNUM(vfs->conn)), "vfstest");102 SMB_VFS_CONNECT(vfs->conn, lp_servicename(talloc_tos(), SNUM(vfs->conn)), "vfstest"); 101 103 return NT_STATUS_OK; 102 104 } … … 116 118 } 117 119 118 diskfree = SMB_VFS_DISK_FREE(vfs->conn, argv[1], False,&bsize, &dfree, &dsize);120 diskfree = SMB_VFS_DISK_FREE(vfs->conn, argv[1], &bsize, &dfree, &dsize); 119 121 printf("disk_free: %lu, bsize = %lu, dfree = %lu, dsize = %lu\n", 120 122 (unsigned long)diskfree, … … 147 149 { 148 150 SMB_STRUCT_STAT st; 149 SMB_STRUCT_DIRENT*dent = NULL;151 struct dirent *dent = NULL; 150 152 151 153 if (vfs->currentdir == NULL) { … … 208 210 return NT_STATUS_UNSUCCESSFUL; 209 211 } 210 212 211 213 printf("mkdir: ok\n"); 212 214 return NT_STATUS_OK; … … 217 219 { 218 220 int ret; 219 221 220 222 if (vfs->currentdir == NULL) { 221 223 printf("closedir: failure (no directory open)\n"); … … 243 245 struct smb_filename *smb_fname = NULL; 244 246 NTSTATUS status; 247 int ret; 245 248 246 249 mode = 00400; … … 318 321 } 319 322 320 fsp = SMB_MALLOC_P(struct files_struct);323 fsp = talloc_zero(vfs, struct files_struct); 321 324 if (fsp == NULL) { 322 325 return NT_STATUS_NO_MEMORY; 323 326 } 324 fsp->fh = SMB_MALLOC_P(struct fd_handle);327 fsp->fh = talloc_zero(fsp, struct fd_handle); 325 328 if (fsp->fh == NULL) { 326 SAFE_FREE(fsp->fsp_name); 327 SAFE_FREE(fsp); 329 TALLOC_FREE(fsp); 328 330 return NT_STATUS_NO_MEMORY; 329 331 } 330 332 fsp->conn = vfs->conn; 331 333 332 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL, 333 &smb_fname); 334 if (!NT_STATUS_IS_OK(status)) { 335 SAFE_FREE(fsp); 336 return status; 334 smb_fname = synthetic_smb_fname_split(NULL, argv[1], NULL); 335 if (smb_fname == NULL) { 336 TALLOC_FREE(fsp); 337 return NT_STATUS_NO_MEMORY; 337 338 } 338 339 … … 342 343 if (fsp->fh->fd == -1) { 343 344 printf("open: error=%d (%s)\n", errno, strerror(errno)); 344 SAFE_FREE(fsp->fh); 345 SAFE_FREE(fsp); 345 TALLOC_FREE(fsp); 346 346 TALLOC_FREE(smb_fname); 347 347 return NT_STATUS_UNSUCCESSFUL; 348 348 } 349 350 status = NT_STATUS_OK; 351 ret = SMB_VFS_FSTAT(fsp, &smb_fname->st); 352 if (ret == -1) { 353 /* If we have an fd, this stat should succeed. */ 354 DEBUG(0,("Error doing fstat on open file %s " 355 "(%s)\n", 356 smb_fname_str_dbg(smb_fname), 357 strerror(errno) )); 358 status = map_nt_error_from_unix(errno); 359 } else if (S_ISDIR(smb_fname->st.st_ex_mode)) { 360 errno = EISDIR; 361 status = NT_STATUS_FILE_IS_A_DIRECTORY; 362 } 363 364 if (!NT_STATUS_IS_OK(status)) { 365 SMB_VFS_CLOSE(fsp); 366 TALLOC_FREE(fsp); 367 TALLOC_FREE(smb_fname); 368 return status; 369 } 370 371 fsp->file_id = vfs_file_id_from_sbuf(vfs->conn, &smb_fname->st); 372 fsp->vuid = UID_FIELD_INVALID; 373 fsp->file_pid = 0; 374 fsp->can_lock = True; 375 fsp->can_read = True; 376 fsp->can_write = 377 CAN_WRITE(vfs->conn); 378 fsp->print_file = NULL; 379 fsp->modified = False; 380 fsp->sent_oplock_break = NO_BREAK_SENT; 381 fsp->is_directory = False; 349 382 350 383 vfs->files[fsp->fh->fd] = fsp; … … 366 399 ret = SMB_VFS_RMDIR(vfs->conn, argv[1]); 367 400 } else if (strcmp("unlink", argv[0]) == 0 ) { 368 struct smb_filename *smb_fname = NULL; 369 NTSTATUS status; 370 371 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], 372 NULL, &smb_fname); 373 if (!NT_STATUS_IS_OK(status)) { 374 return status; 401 struct smb_filename *smb_fname; 402 403 smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL); 404 if (smb_fname == NULL) { 405 return NT_STATUS_NO_MEMORY; 375 406 } 376 407 … … 415 446 printf("close: ok\n"); 416 447 417 TALLOC_FREE(vfs->files[fd]->fsp_name); 418 SAFE_FREE(vfs->files[fd]->fh); 419 SAFE_FREE(vfs->files[fd]); 448 TALLOC_FREE(vfs->files[fd]); 420 449 vfs->files[fd] = NULL; 421 450 return NT_STATUS_OK; … … 436 465 fd = atoi(argv[1]); 437 466 size = atoi(argv[2]); 438 vfs->data = TALLOC_ARRAY(mem_ctx, char, size);467 vfs->data = talloc_array(mem_ctx, char, size); 439 468 if (vfs->data == NULL) { 440 469 printf("read: error=-1 (not enough memory)"); … … 442 471 } 443 472 vfs->data_size = size; 444 473 445 474 rsize = SMB_VFS_READ(vfs->files[fd], vfs->data, size); 446 475 if (rsize == -1) { … … 491 520 { 492 521 int fd, offset, whence; 493 SMB_OFF_Tpos;522 off_t pos; 494 523 495 524 if (argc != 4) { … … 508 537 509 538 pos = SMB_VFS_LSEEK(vfs->files[fd], offset, whence); 510 if (pos == ( SMB_OFF_T)-1) {539 if (pos == (off_t)-1) { 511 540 printf("lseek: error=%d (%s)\n", errno, strerror(errno)); 512 541 return NT_STATUS_UNSUCCESSFUL; … … 523 552 struct smb_filename *smb_fname_src = NULL; 524 553 struct smb_filename *smb_fname_dst = NULL; 525 NTSTATUS status;526 554 527 555 if (argc != 3) { … … 530 558 } 531 559 532 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL, 533 &smb_fname_src); 534 if (!NT_STATUS_IS_OK(status)) { 535 return status; 536 } 537 538 status = create_synthetic_smb_fname_split(mem_ctx, argv[2], NULL, 539 &smb_fname_dst); 540 if (!NT_STATUS_IS_OK(status)) { 560 smb_fname_src = synthetic_smb_fname_split(mem_ctx, argv[1], NULL); 561 if (smb_fname_src == NULL) { 562 return NT_STATUS_NO_MEMORY; 563 } 564 565 smb_fname_dst = synthetic_smb_fname_split(mem_ctx, argv[2], NULL); 566 if (smb_fname_dst == NULL) { 541 567 TALLOC_FREE(smb_fname_src); 542 return status;568 return NT_STATUS_NO_MEMORY; 543 569 } 544 570 … … 586 612 SMB_STRUCT_STAT st; 587 613 time_t tmp_time; 588 NTSTATUS status;589 614 590 615 if (argc != 2) { … … 593 618 } 594 619 595 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL, 596 &smb_fname); 597 if (!NT_STATUS_IS_OK(status)) { 598 return status; 620 smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL); 621 if (smb_fname == NULL) { 622 return NT_STATUS_NO_MEMORY; 599 623 } 600 624 … … 608 632 TALLOC_FREE(smb_fname); 609 633 610 pwd = sys_getpwuid(st.st_ex_uid);634 pwd = getpwuid(st.st_ex_uid); 611 635 if (pwd != NULL) user = pwd->pw_name; 612 636 else user = null_string; 613 grp = sys_getgrgid(st.st_ex_gid);637 grp = getgrgid(st.st_ex_gid); 614 638 if (grp != NULL) group = grp->gr_name; 615 639 else group = null_string; … … 679 703 } 680 704 681 pwd = sys_getpwuid(st.st_ex_uid);705 pwd = getpwuid(st.st_ex_uid); 682 706 if (pwd != NULL) user = pwd->pw_name; 683 707 else user = null_string; 684 grp = sys_getgrgid(st.st_ex_gid);708 grp = getgrgid(st.st_ex_gid); 685 709 if (grp != NULL) group = grp->gr_name; 686 710 else group = null_string; … … 727 751 SMB_STRUCT_STAT st; 728 752 time_t tmp_time; 729 NTSTATUS status;730 753 731 754 if (argc != 2) { … … 734 757 } 735 758 736 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], NULL, 737 &smb_fname); 738 if (!NT_STATUS_IS_OK(status)) { 739 return status; 759 smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL); 760 if (smb_fname == NULL) { 761 return NT_STATUS_NO_MEMORY; 740 762 } 741 763 … … 748 770 TALLOC_FREE(smb_fname); 749 771 750 pwd = sys_getpwuid(st.st_ex_uid);772 pwd = getpwuid(st.st_ex_uid); 751 773 if (pwd != NULL) user = pwd->pw_name; 752 774 else user = null_string; 753 grp = sys_getgrgid(st.st_ex_gid);775 grp = getgrgid(st.st_ex_gid); 754 776 if (grp != NULL) group = grp->gr_name; 755 777 else group = null_string; … … 782 804 tmp_time = convert_timespec_to_time_t(st.st_ex_ctime); 783 805 printf(" Change: %s", ctime(&tmp_time)); 784 806 785 807 return NT_STATUS_OK; 786 808 } … … 832 854 833 855 printf("fchmod: ok\n"); 856 return NT_STATUS_OK; 857 } 858 859 860 static NTSTATUS cmd_chmod_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) 861 { 862 mode_t mode; 863 if (argc != 3) { 864 printf("Usage: chmod_acl <path> <mode>\n"); 865 return NT_STATUS_OK; 866 } 867 868 mode = atoi(argv[2]); 869 if (SMB_VFS_CHMOD_ACL(vfs->conn, argv[1], mode) == -1) { 870 printf("chmod_acl: error=%d (%s)\n", errno, strerror(errno)); 871 return NT_STATUS_UNSUCCESSFUL; 872 } 873 874 printf("chmod_acl: ok\n"); 875 return NT_STATUS_OK; 876 } 877 878 879 static NTSTATUS cmd_fchmod_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) 880 { 881 int fd; 882 mode_t mode; 883 if (argc != 3) { 884 printf("Usage: fchmod_acl <fd> <mode>\n"); 885 return NT_STATUS_OK; 886 } 887 888 fd = atoi(argv[1]); 889 mode = atoi(argv[2]); 890 if (fd < 0 || fd >= 1024) { 891 printf("fchmod_acl: error=%d (file descriptor out of range)\n", EBADF); 892 return NT_STATUS_OK; 893 } 894 if (vfs->files[fd] == NULL) { 895 printf("fchmod_acl: error=%d (invalid file descriptor)\n", EBADF); 896 return NT_STATUS_OK; 897 } 898 899 if (SMB_VFS_FCHMOD_ACL(vfs->files[fd], mode) == -1) { 900 printf("fchmod_acl: error=%d (%s)\n", errno, strerror(errno)); 901 return NT_STATUS_UNSUCCESSFUL; 902 } 903 904 printf("fchmod_acl: ok\n"); 834 905 return NT_STATUS_OK; 835 906 } … … 890 961 static NTSTATUS cmd_getwd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) 891 962 { 892 char buf[PATH_MAX];893 if ( SMB_VFS_GETWD(vfs->conn, buf)== NULL) {963 char *buf = SMB_VFS_GETWD(vfs->conn); 964 if (buf == NULL) { 894 965 printf("getwd: error=%d (%s)\n", errno, strerror(errno)); 895 966 return NT_STATUS_UNSUCCESSFUL; … … 897 968 898 969 printf("getwd: %s\n", buf); 970 SAFE_FREE(buf); 899 971 return NT_STATUS_OK; 900 972 } … … 904 976 struct smb_file_time ft; 905 977 struct smb_filename *smb_fname = NULL; 906 NTSTATUS status;907 978 908 979 if (argc != 4) { … … 916 987 ft.mtime = convert_time_t_to_timespec(atoi(argv[3])); 917 988 918 status = create_synthetic_smb_fname_split(mem_ctx, argv[1], 919 NULL, &smb_fname); 920 if (!NT_STATUS_IS_OK(status)) { 921 return status; 989 smb_fname = synthetic_smb_fname_split(mem_ctx, argv[1], NULL); 990 if (smb_fname == NULL) { 991 return NT_STATUS_NO_MEMORY; 922 992 } 923 993 … … 936 1006 { 937 1007 int fd; 938 SMB_OFF_Toff;1008 off_t off; 939 1009 if (argc != 3) { 940 1010 printf("Usage: ftruncate <fd> <length>\n"); … … 970 1040 int type; 971 1041 const char *typestr; 972 1042 973 1043 if (argc != 6) { 974 1044 printf("Usage: lock <fd> <op> <offset> <count> <type>\n"); … … 1103 1173 unsigned int dev_val; 1104 1174 SMB_DEV_T dev; 1105 1175 1106 1176 if (argc != 4) { 1107 1177 printf("Usage: mknod <path> <mode> <dev>\n"); … … 1146 1216 return NT_STATUS_OK; 1147 1217 } 1218 1219 static NTSTATUS cmd_getxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1220 int argc, const char **argv) 1221 { 1222 uint8_t *buf; 1223 ssize_t ret; 1224 1225 if (argc != 3) { 1226 printf("Usage: getxattr <path> <xattr>\n"); 1227 return NT_STATUS_OK; 1228 } 1229 1230 buf = NULL; 1231 1232 ret = SMB_VFS_GETXATTR(vfs->conn, argv[1], argv[2], buf, 1233 talloc_get_size(buf)); 1234 if (ret == -1) { 1235 int err = errno; 1236 printf("getxattr returned (%s)\n", strerror(err)); 1237 return map_nt_error_from_unix(err); 1238 } 1239 buf = talloc_array(mem_ctx, uint8_t, ret); 1240 if (buf == NULL) { 1241 return NT_STATUS_NO_MEMORY; 1242 } 1243 ret = SMB_VFS_GETXATTR(vfs->conn, argv[1], argv[2], buf, 1244 talloc_get_size(buf)); 1245 if (ret == -1) { 1246 int err = errno; 1247 printf("getxattr returned (%s)\n", strerror(err)); 1248 return map_nt_error_from_unix(err); 1249 } 1250 dump_data_file(buf, talloc_get_size(buf), false, stdout); 1251 return NT_STATUS_OK; 1252 } 1253 1254 static NTSTATUS cmd_listxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1255 int argc, const char **argv) 1256 { 1257 char *buf, *p; 1258 ssize_t ret; 1259 1260 if (argc != 2) { 1261 printf("Usage: listxattr <path>\n"); 1262 return NT_STATUS_OK; 1263 } 1264 1265 buf = NULL; 1266 1267 ret = SMB_VFS_LISTXATTR(vfs->conn, argv[1], buf, talloc_get_size(buf)); 1268 if (ret == -1) { 1269 int err = errno; 1270 printf("listxattr returned (%s)\n", strerror(err)); 1271 return map_nt_error_from_unix(err); 1272 } 1273 buf = talloc_array(mem_ctx, char, ret); 1274 if (buf == NULL) { 1275 return NT_STATUS_NO_MEMORY; 1276 } 1277 ret = SMB_VFS_LISTXATTR(vfs->conn, argv[1], buf, talloc_get_size(buf)); 1278 if (ret == -1) { 1279 int err = errno; 1280 printf("listxattr returned (%s)\n", strerror(err)); 1281 return map_nt_error_from_unix(err); 1282 } 1283 if (ret == 0) { 1284 return NT_STATUS_OK; 1285 } 1286 if (buf[ret-1] != '\0') { 1287 printf("listxattr returned non 0-terminated strings\n"); 1288 return NT_STATUS_INTERNAL_ERROR; 1289 } 1290 1291 p = buf; 1292 while (p < buf+ret) { 1293 printf("%s\n", p); 1294 p = strchr(p, 0); 1295 p += 1; 1296 } 1297 return NT_STATUS_OK; 1298 } 1299 1300 static NTSTATUS cmd_setxattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1301 int argc, const char **argv) 1302 { 1303 ssize_t ret; 1304 int flags = 0; 1305 1306 if ((argc < 4) || (argc > 5)) { 1307 printf("Usage: setxattr <path> <xattr> <value> [flags]\n"); 1308 return NT_STATUS_OK; 1309 } 1310 1311 if (argc == 5) { 1312 flags = atoi(argv[4]); 1313 } 1314 1315 ret = SMB_VFS_SETXATTR(vfs->conn, argv[1], argv[2], 1316 argv[3], strlen(argv[3]), flags); 1317 if (ret == -1) { 1318 int err = errno; 1319 printf("setxattr returned (%s)\n", strerror(err)); 1320 return map_nt_error_from_unix(err); 1321 } 1322 return NT_STATUS_OK; 1323 } 1324 1325 static NTSTATUS cmd_removexattr(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1326 int argc, const char **argv) 1327 { 1328 ssize_t ret; 1329 1330 if (argc != 3) { 1331 printf("Usage: removexattr <path> <xattr>\n"); 1332 return NT_STATUS_OK; 1333 } 1334 1335 ret = SMB_VFS_REMOVEXATTR(vfs->conn, argv[1], argv[2]); 1336 if (ret == -1) { 1337 int err = errno; 1338 printf("removexattr returned (%s)\n", strerror(err)); 1339 return map_nt_error_from_unix(err); 1340 } 1341 return NT_STATUS_OK; 1342 } 1343 1344 static NTSTATUS cmd_fget_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1345 int argc, const char **argv) 1346 { 1347 int fd; 1348 NTSTATUS status; 1349 struct security_descriptor *sd; 1350 1351 if (argc != 2) { 1352 printf("Usage: fget_nt_acl <fd>\n"); 1353 return NT_STATUS_OK; 1354 } 1355 1356 fd = atoi(argv[1]); 1357 if (fd < 0 || fd >= 1024) { 1358 printf("fget_nt_acl: error=%d (file descriptor out of range)\n", EBADF); 1359 return NT_STATUS_OK; 1360 } 1361 if (vfs->files[fd] == NULL) { 1362 printf("fget_nt_acl: error=%d (invalid file descriptor)\n", EBADF); 1363 return NT_STATUS_OK; 1364 } 1365 1366 status = SMB_VFS_FGET_NT_ACL(vfs->files[fd], 1367 SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, 1368 talloc_tos(), &sd); 1369 if (!NT_STATUS_IS_OK(status)) { 1370 printf("fget_nt_acl returned (%s)\n", nt_errstr(status)); 1371 return status; 1372 } 1373 printf("%s\n", sddl_encode(talloc_tos(), sd, get_global_sam_sid())); 1374 TALLOC_FREE(sd); 1375 return NT_STATUS_OK; 1376 } 1377 1378 static NTSTATUS cmd_get_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1379 int argc, const char **argv) 1380 { 1381 NTSTATUS status; 1382 struct security_descriptor *sd; 1383 1384 if (argc != 2) { 1385 printf("Usage: get_nt_acl <path>\n"); 1386 return NT_STATUS_OK; 1387 } 1388 1389 status = SMB_VFS_GET_NT_ACL(vfs->conn, argv[1], 1390 SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, 1391 talloc_tos(), &sd); 1392 if (!NT_STATUS_IS_OK(status)) { 1393 printf("get_nt_acl returned (%s)\n", nt_errstr(status)); 1394 return status; 1395 } 1396 printf("%s\n", sddl_encode(talloc_tos(), sd, get_global_sam_sid())); 1397 TALLOC_FREE(sd); 1398 return NT_STATUS_OK; 1399 } 1400 1401 static NTSTATUS cmd_fset_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1402 int argc, const char **argv) 1403 { 1404 int fd; 1405 NTSTATUS status; 1406 struct security_descriptor *sd; 1407 1408 if (argc != 3) { 1409 printf("Usage: fset_nt_acl <fd> <sddl>\n"); 1410 return NT_STATUS_OK; 1411 } 1412 1413 fd = atoi(argv[1]); 1414 if (fd < 0 || fd >= 1024) { 1415 printf("fset_nt_acl: error=%d (file descriptor out of range)\n", EBADF); 1416 return NT_STATUS_OK; 1417 } 1418 if (vfs->files[fd] == NULL) { 1419 printf("fset_nt_acl: error=%d (invalid file descriptor)\n", EBADF); 1420 return NT_STATUS_OK; 1421 } 1422 1423 sd = sddl_decode(talloc_tos(), argv[2], get_global_sam_sid()); 1424 if (!sd) { 1425 printf("sddl_decode failed to parse %s as SDDL\n", argv[2]); 1426 return NT_STATUS_INVALID_PARAMETER; 1427 } 1428 1429 status = SMB_VFS_FSET_NT_ACL(vfs->files[fd], SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, sd); 1430 if (!NT_STATUS_IS_OK(status)) { 1431 printf("fset_nt_acl returned (%s)\n", nt_errstr(status)); 1432 return status; 1433 } 1434 TALLOC_FREE(sd); 1435 return NT_STATUS_OK; 1436 } 1437 1438 static NTSTATUS cmd_set_nt_acl(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, int argc, const char **argv) 1439 { 1440 int flags; 1441 int ret; 1442 mode_t mode; 1443 files_struct *fsp; 1444 struct smb_filename *smb_fname = NULL; 1445 NTSTATUS status; 1446 struct security_descriptor *sd = NULL; 1447 1448 if (argc != 3) { 1449 printf("Usage: set_nt_acl <file> <sddl>\n"); 1450 return NT_STATUS_OK; 1451 } 1452 1453 mode = 00400; 1454 1455 fsp = talloc_zero(vfs, struct files_struct); 1456 if (fsp == NULL) { 1457 return NT_STATUS_NO_MEMORY; 1458 } 1459 fsp->fh = talloc_zero(fsp, struct fd_handle); 1460 if (fsp->fh == NULL) { 1461 TALLOC_FREE(fsp); 1462 return NT_STATUS_NO_MEMORY; 1463 } 1464 fsp->conn = vfs->conn; 1465 1466 smb_fname = synthetic_smb_fname_split(NULL, argv[1], NULL); 1467 if (smb_fname == NULL) { 1468 TALLOC_FREE(fsp); 1469 return NT_STATUS_NO_MEMORY; 1470 } 1471 1472 fsp->fsp_name = smb_fname; 1473 1474 #ifdef O_DIRECTORY 1475 flags = O_RDONLY|O_DIRECTORY; 1476 #else 1477 /* POSIX allows us to open a directory with O_RDONLY. */ 1478 flags = O_RDONLY; 1479 #endif 1480 1481 fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, O_RDWR, mode); 1482 if (fsp->fh->fd == -1 && errno == EISDIR) { 1483 fsp->fh->fd = SMB_VFS_OPEN(vfs->conn, smb_fname, fsp, flags, mode); 1484 } 1485 if (fsp->fh->fd == -1) { 1486 printf("open: error=%d (%s)\n", errno, strerror(errno)); 1487 TALLOC_FREE(fsp); 1488 TALLOC_FREE(smb_fname); 1489 return NT_STATUS_UNSUCCESSFUL; 1490 } 1491 1492 status = NT_STATUS_OK; 1493 ret = SMB_VFS_FSTAT(fsp, &smb_fname->st); 1494 if (ret == -1) { 1495 /* If we have an fd, this stat should succeed. */ 1496 DEBUG(0,("Error doing fstat on open file %s " 1497 "(%s)\n", 1498 smb_fname_str_dbg(smb_fname), 1499 strerror(errno) )); 1500 status = map_nt_error_from_unix(errno); 1501 } 1502 1503 if (!NT_STATUS_IS_OK(status)) { 1504 goto out; 1505 } 1506 1507 fsp->file_id = vfs_file_id_from_sbuf(vfs->conn, &smb_fname->st); 1508 fsp->vuid = UID_FIELD_INVALID; 1509 fsp->file_pid = 0; 1510 fsp->can_lock = True; 1511 fsp->can_read = True; 1512 fsp->can_write = True; 1513 fsp->print_file = NULL; 1514 fsp->modified = False; 1515 fsp->sent_oplock_break = NO_BREAK_SENT; 1516 fsp->is_directory = S_ISDIR(smb_fname->st.st_ex_mode); 1517 1518 1519 sd = sddl_decode(talloc_tos(), argv[2], get_global_sam_sid()); 1520 if (!sd) { 1521 printf("sddl_decode failed to parse %s as SDDL\n", argv[2]); 1522 status = NT_STATUS_INVALID_PARAMETER; 1523 goto out; 1524 } 1525 1526 status = SMB_VFS_FSET_NT_ACL(fsp, SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL, sd); 1527 if (!NT_STATUS_IS_OK(status)) { 1528 printf("fset_nt_acl returned (%s)\n", nt_errstr(status)); 1529 goto out; 1530 } 1531 out: 1532 TALLOC_FREE(sd); 1533 1534 ret = SMB_VFS_CLOSE(fsp); 1535 if (ret == -1 ) 1536 printf("close: error=%d (%s)\n", errno, strerror(errno)); 1537 1538 TALLOC_FREE(fsp); 1539 1540 return status; 1541 } 1542 1543 1544 1545 static NTSTATUS cmd_sys_acl_get_fd(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1546 int argc, const char **argv) 1547 { 1548 int fd; 1549 SMB_ACL_T acl; 1550 char *acl_text; 1551 1552 if (argc != 2) { 1553 printf("Usage: sys_acl_get_fd <fd>\n"); 1554 return NT_STATUS_OK; 1555 } 1556 1557 fd = atoi(argv[1]); 1558 if (fd < 0 || fd >= 1024) { 1559 printf("sys_acl_get_fd: error=%d (file descriptor out of range)\n", EBADF); 1560 return NT_STATUS_OK; 1561 } 1562 if (vfs->files[fd] == NULL) { 1563 printf("sys_acl_get_fd: error=%d (invalid file descriptor)\n", EBADF); 1564 return NT_STATUS_OK; 1565 } 1566 1567 acl = SMB_VFS_SYS_ACL_GET_FD(vfs->files[fd], talloc_tos()); 1568 if (!acl) { 1569 printf("sys_acl_get_fd failed (%s)\n", strerror(errno)); 1570 return NT_STATUS_UNSUCCESSFUL; 1571 } 1572 acl_text = sys_acl_to_text(acl, NULL); 1573 printf("%s", acl_text); 1574 TALLOC_FREE(acl); 1575 SAFE_FREE(acl_text); 1576 return NT_STATUS_OK; 1577 } 1578 1579 static NTSTATUS cmd_sys_acl_get_file(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1580 int argc, const char **argv) 1581 { 1582 SMB_ACL_T acl; 1583 char *acl_text; 1584 int type; 1585 if (argc != 3) { 1586 printf("Usage: sys_acl_get_file <path> <type>\n"); 1587 return NT_STATUS_OK; 1588 } 1589 1590 type = atoi(argv[2]); 1591 acl = SMB_VFS_SYS_ACL_GET_FILE(vfs->conn, argv[1], type, talloc_tos()); 1592 if (!acl) { 1593 printf("sys_acl_get_file failed (%s)\n", strerror(errno)); 1594 return NT_STATUS_UNSUCCESSFUL; 1595 } 1596 acl_text = sys_acl_to_text(acl, NULL); 1597 printf("%s", acl_text); 1598 TALLOC_FREE(acl); 1599 SAFE_FREE(acl_text); 1600 return NT_STATUS_OK; 1601 } 1602 1603 static NTSTATUS cmd_sys_acl_blob_get_file(struct vfs_state *vfs, 1604 TALLOC_CTX *mem_ctx, 1605 int argc, const char **argv) 1606 { 1607 char *description; 1608 DATA_BLOB blob; 1609 int ret; 1610 size_t i; 1611 1612 if (argc != 2) { 1613 printf("Usage: sys_acl_get_file <path>\n"); 1614 return NT_STATUS_OK; 1615 } 1616 1617 ret = SMB_VFS_SYS_ACL_BLOB_GET_FILE(vfs->conn, argv[1], talloc_tos(), 1618 &description, &blob); 1619 if (ret != 0) { 1620 printf("sys_acl_blob_get_file failed (%s)\n", strerror(errno)); 1621 return map_nt_error_from_unix(errno); 1622 } 1623 printf("Description: %s\n", description); 1624 for (i = 0; i < blob.length; i++) { 1625 printf("%.2x ", blob.data[i]); 1626 } 1627 printf("\n"); 1628 1629 return NT_STATUS_OK; 1630 } 1631 1632 static NTSTATUS cmd_sys_acl_blob_get_fd(struct vfs_state *vfs, 1633 TALLOC_CTX *mem_ctx, 1634 int argc, const char **argv) 1635 { 1636 int fd; 1637 char *description; 1638 DATA_BLOB blob; 1639 int ret; 1640 size_t i; 1641 1642 if (argc != 2) { 1643 printf("Usage: sys_acl_blob_get_fd <fd>\n"); 1644 return NT_STATUS_OK; 1645 } 1646 1647 fd = atoi(argv[1]); 1648 if (fd < 0 || fd >= 1024) { 1649 printf("sys_acl_blob_get_fd: error=%d " 1650 "(file descriptor out of range)\n", EBADF); 1651 return NT_STATUS_OK; 1652 } 1653 if (vfs->files[fd] == NULL) { 1654 printf("sys_acl_blob_get_fd: error=%d " 1655 "(invalid file descriptor)\n", EBADF); 1656 return NT_STATUS_OK; 1657 } 1658 1659 ret = SMB_VFS_SYS_ACL_BLOB_GET_FD(vfs->files[fd], talloc_tos(), 1660 &description, &blob); 1661 if (ret != 0) { 1662 printf("sys_acl_blob_get_fd failed (%s)\n", strerror(errno)); 1663 return map_nt_error_from_unix(errno); 1664 } 1665 printf("Description: %s\n", description); 1666 for (i = 0; i < blob.length; i++) { 1667 printf("%.2x ", blob.data[i]); 1668 } 1669 printf("\n"); 1670 1671 return NT_STATUS_OK; 1672 } 1673 1674 1675 1676 static NTSTATUS cmd_sys_acl_delete_def_file(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1677 int argc, const char **argv) 1678 { 1679 int ret; 1680 1681 if (argc != 2) { 1682 printf("Usage: sys_acl_delete_def_file <path>\n"); 1683 return NT_STATUS_OK; 1684 } 1685 1686 ret = SMB_VFS_SYS_ACL_DELETE_DEF_FILE(vfs->conn, argv[1]); 1687 if (ret == -1) { 1688 printf("sys_acl_delete_def_file failed (%s)\n", strerror(errno)); 1689 return NT_STATUS_UNSUCCESSFUL; 1690 } 1691 return NT_STATUS_OK; 1692 } 1693 1694 /* Afaik translate name was first introduced with vfs_catia, to be able 1695 to translate unix file/dir-names, containing invalid windows characters, 1696 to valid windows names. 1697 The used translation direction is always unix --> windows 1698 */ 1699 static NTSTATUS cmd_translate_name(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 1700 int argc, const char **argv) 1701 { 1702 int ret; 1703 struct dirent *dent = NULL; 1704 SMB_STRUCT_STAT st; 1705 bool found = false; 1706 char *translated = NULL; 1707 NTSTATUS status; 1708 1709 if (argc != 2) { 1710 DEBUG(0, ("Usage: translate_name unix_filename\n")); 1711 return NT_STATUS_UNSUCCESSFUL; 1712 } 1713 1714 vfs->currentdir = SMB_VFS_OPENDIR(vfs->conn, ".", NULL, 0); 1715 if (vfs->currentdir == NULL) { 1716 DEBUG(0, ("cmd_translate_name: opendir error=%d (%s)\n", 1717 errno, strerror(errno))); 1718 return NT_STATUS_UNSUCCESSFUL; 1719 } 1720 1721 while (true) { 1722 dent = SMB_VFS_READDIR(vfs->conn, vfs->currentdir, &st); 1723 if (dent == NULL) { 1724 break; 1725 } 1726 if (strcmp (dent->d_name, argv[1]) == 0) { 1727 found = true; 1728 break; 1729 } 1730 }; 1731 1732 if (!found) { 1733 DEBUG(0, ("cmd_translate_name: file '%s' not found.\n", 1734 argv[1])); 1735 status = NT_STATUS_UNSUCCESSFUL; 1736 goto cleanup; 1737 } 1738 status = SMB_VFS_TRANSLATE_NAME(vfs->conn, dent->d_name, 1739 vfs_translate_to_windows, 1740 talloc_tos(), &translated); 1741 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) { 1742 DEBUG(0, ("cmd_translate_name: file '%s' cannot be " 1743 "translated\n", argv[1])); 1744 TALLOC_FREE(translated); 1745 goto cleanup; 1746 } 1747 /* translation success. But that could also mean 1748 that translating "aaa" to "aaa" was successful :-( 1749 */ 1750 DEBUG(0, ("cmd_translate_name: file '%s' --> '%s'\n", 1751 argv[1], translated)); 1752 1753 TALLOC_FREE(translated); 1754 1755 cleanup: 1756 ret = SMB_VFS_CLOSEDIR(vfs->conn, vfs->currentdir); 1757 if (ret == -1) { 1758 DEBUG(0, ("cmd_translate_name: closedir failure: %s\n", 1759 strerror(errno))); 1760 return NT_STATUS_UNSUCCESSFUL; 1761 } 1762 1763 vfs->currentdir = NULL; 1764 return status;; 1765 } 1766 1148 1767 1149 1768 struct cmd_set vfs_commands[] = { … … 1162 1781 { "rmdir", cmd_pathfunc, "VFS rmdir()", "rmdir <path>" }, 1163 1782 { "closedir", cmd_closedir, "VFS closedir()", "closedir" }, 1164 { "open", cmd_open, "VFS open()", "open <fname> " },1783 { "open", cmd_open, "VFS open()", "open <fname> <flags> <mode>" }, 1165 1784 { "close", cmd_close, "VFS close()", "close <fd>" }, 1166 1785 { "read", cmd_read, "VFS read()", "read <fd> <size>" }, … … 1187 1806 { "mknod", cmd_mknod, "VFS mknod()", "mknod <path> <mode> <dev>" }, 1188 1807 { "realpath", cmd_realpath, "VFS realpath()", "realpath <path>" }, 1808 { "getxattr", cmd_getxattr, "VFS getxattr()", 1809 "getxattr <path> <name>" }, 1810 { "listxattr", cmd_listxattr, "VFS listxattr()", 1811 "listxattr <path>" }, 1812 { "setxattr", cmd_setxattr, "VFS setxattr()", 1813 "setxattr <path> <name> <value> [<flags>]" }, 1814 { "removexattr", cmd_removexattr, "VFS removexattr()", 1815 "removexattr <path> <name>\n" }, 1816 { "fget_nt_acl", cmd_fget_nt_acl, "VFS fget_nt_acl()", 1817 "fget_nt_acl <fd>\n" }, 1818 { "get_nt_acl", cmd_get_nt_acl, "VFS get_nt_acl()", 1819 "get_nt_acl <path>\n" }, 1820 { "fset_nt_acl", cmd_fset_nt_acl, "VFS fset_nt_acl()", 1821 "fset_nt_acl <fd>\n" }, 1822 { "set_nt_acl", cmd_set_nt_acl, "VFS open() and fset_nt_acl()", 1823 "set_nt_acl <file>\n" }, 1824 { "fchmod_acl", cmd_fchmod_acl, "VFS fchmod_acl()", "fchmod_acl <fd> <mode>" }, 1825 { "chmod_acl", cmd_chmod_acl, "VFS chmod_acl()", "chmod_acl <path> <mode>" }, 1826 { "sys_acl_get_file", cmd_sys_acl_get_file, "VFS sys_acl_get_file()", "sys_acl_get_file <path>" }, 1827 { "sys_acl_get_fd", cmd_sys_acl_get_fd, "VFS sys_acl_get_fd()", "sys_acl_get_fd <fd>" }, 1828 { "sys_acl_blob_get_file", cmd_sys_acl_blob_get_file, 1829 "VFS sys_acl_blob_get_file()", "sys_acl_blob_get_file <path>" }, 1830 { "sys_acl_blob_get_fd", cmd_sys_acl_blob_get_fd, 1831 "VFS sys_acl_blob_get_fd()", "sys_acl_blob_get_fd <path>" }, 1832 { "sys_acl_delete_def_file", cmd_sys_acl_delete_def_file, "VFS sys_acl_delete_def_file()", "sys_acl_delete_def_file <path>" }, 1833 1834 1835 { "test_chain", cmd_test_chain, "test chain code", 1836 "test_chain" }, 1837 { "translate_name", cmd_translate_name, "VFS translate_name()", "translate_name unix_filename" }, 1189 1838 { NULL } 1190 1839 }; -
vendor/current/source3/torture/denytest.c
r740 r988 1413 1413 int i; 1414 1414 bool correct = True; 1415 NTSTATUS ret1, ret2 ;1415 NTSTATUS ret1, ret2, status; 1416 1416 const char *fnames[2] = {"\\denytest1.dat", "\\denytest1.exe"}; 1417 size_t nread; 1417 1418 1418 1419 if (!torture_open_connection(&cli1, 0)) { … … 1424 1425 for (i=0;i<2;i++) { 1425 1426 cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1426 cli_open (cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);1427 cli_writeall(cli1, fnum1, 0, ( uint8_t *)fnames[i], 0,1427 cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1); 1428 cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0, 1428 1429 strlen(fnames[i]), NULL); 1429 1430 cli_close(cli1, fnum1); … … 1438 1439 progress_bar(i, ARRAY_SIZE(denytable1)); 1439 1440 1440 ret1 = cli_open (cli1, fname,1441 ret1 = cli_openx(cli1, fname, 1441 1442 denytable1[i].mode1, 1442 1443 denytable1[i].deny1, &fnum1); 1443 ret2 = cli_open (cli1, fname,1444 ret2 = cli_openx(cli1, fname, 1444 1445 denytable1[i].mode2, 1445 1446 denytable1[i].deny2, &fnum2); … … 1452 1453 char x = 1; 1453 1454 res = A_0; 1454 if (cli_read(cli1, fnum2, (char *)&x, 0, 1) == 1) { 1455 1456 status = cli_read(cli1, fnum2, (char *)&x, 0, 1, 1457 &nread); 1458 if (NT_STATUS_IS_OK(status) && nread == 1) { 1455 1459 res += A_R; 1456 1460 } … … 1507 1511 int i; 1508 1512 bool correct = True; 1509 NTSTATUS ret1, ret2 ;1513 NTSTATUS ret1, ret2, status; 1510 1514 const char *fnames[2] = {"\\denytest2.dat", "\\denytest2.exe"}; 1515 size_t nread; 1511 1516 1512 1517 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) { … … 1518 1523 for (i=0;i<2;i++) { 1519 1524 cli_unlink(cli1, fnames[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1520 cli_open (cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1);1521 cli_writeall(cli1, fnum1, 0, ( uint8_t *)fnames[i], 0,1525 cli_openx(cli1, fnames[i], O_RDWR|O_CREAT, DENY_NONE, &fnum1); 1526 cli_writeall(cli1, fnum1, 0, (const uint8_t *)fnames[i], 0, 1522 1527 strlen(fnames[i]), NULL); 1523 1528 cli_close(cli1, fnum1); … … 1530 1535 progress_bar(i, ARRAY_SIZE(denytable2)); 1531 1536 1532 ret1 = cli_open (cli1, fname,1537 ret1 = cli_openx(cli1, fname, 1533 1538 denytable2[i].mode1, 1534 1539 denytable2[i].deny1, &fnum1); 1535 ret2 = cli_open (cli2, fname,1540 ret2 = cli_openx(cli2, fname, 1536 1541 denytable2[i].mode2, 1537 1542 denytable2[i].deny2, &fnum2); … … 1544 1549 char x = 1; 1545 1550 res = A_0; 1546 if (cli_read(cli2, fnum2, (char *)&x, 0, 1) == 1) { 1547 res += A_R; 1548 } 1551 1552 status = cli_read(cli2, fnum2, (char *)&x, 0, 1, 1553 &nread); 1554 if (NT_STATUS_IS_OK(status) && nread == 1) { 1555 res += A_R; 1556 } 1549 1557 if (NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, 1550 1558 (uint8_t *)&x, 0, 1, -
vendor/current/source3/torture/locktest2.c
r740 r988 74 74 { 75 75 uint16_t fd; 76 if (!NT_STATUS_IS_OK(cli_open (c, fname, flags, DENY_NONE, &fd))) {76 if (!NT_STATUS_IS_OK(cli_openx(c, fname, flags, DENY_NONE, &fd))) { 77 77 return -1; 78 78 } … … 115 115 switch (fstype) { 116 116 case FSTYPE_SMB: 117 return cli_lock(c, fd, start, len, LOCK_TIMEOUT, op); 117 return NT_STATUS_IS_OK(cli_lock32(c, fd, start, len, 118 LOCK_TIMEOUT, op)); 118 119 119 120 case FSTYPE_NFS: … … 184 185 185 186 if (!got_pass) { 186 char *pass = getpass("Password: "); 187 if (pass) { 188 fstrcpy(password, pass); 187 char pwd[256] = {0}; 188 int rc; 189 190 rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false); 191 if (rc == 0) { 192 fstrcpy(password, pwd); 189 193 } 190 194 } … … 194 198 nt_status = cli_full_connection(&c, myname, server_n, NULL, 0, share, "?????", 195 199 username, lp_workgroup(), password, 0, 196 Undefined);200 SMB_SIGNING_DEFAULT); 197 201 198 202 if (!NT_STATUS_IS_OK(nt_status)) { … … 513 517 argv += 4; 514 518 515 lp_load (get_dyn_CONFIGFILE(),True,False,False,True);519 lp_load_global(get_dyn_CONFIGFILE()); 516 520 load_interfaces(); 517 521 -
vendor/current/source3/torture/mangle_test.c
r740 r988 43 43 total++; 44 44 45 if (!NT_STATUS_IS_OK(cli_open(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 46 printf("open of %s failed (%s)\n", name, cli_errstr(cli)); 47 return False; 48 } 49 50 if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) { 51 printf("close of %s failed (%s)\n", name, cli_errstr(cli)); 45 status = cli_openx(cli, name, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 46 if (!NT_STATUS_IS_OK(status)) { 47 printf("open of %s failed (%s)\n", name, nt_errstr(status)); 48 return False; 49 } 50 51 status = cli_close(cli, fnum); 52 if (!NT_STATUS_IS_OK(status)) { 53 printf("close of %s failed (%s)\n", name, nt_errstr(status)); 52 54 return False; 53 55 } … … 56 58 status = cli_qpathinfo_alt_name(cli, name, shortname); 57 59 if (!NT_STATUS_IS_OK(status)) { 58 printf("query altname of %s failed (%s)\n", name, cli_errstr(cli));60 printf("query altname of %s failed (%s)\n", name, nt_errstr(status)); 59 61 return False; 60 62 } 61 63 62 64 fstr_sprintf(name2, "\\mangle_test\\%s", shortname); 63 if (!NT_STATUS_IS_OK(cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 65 status = cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 66 if (!NT_STATUS_IS_OK(status)) { 64 67 printf("unlink of %s (%s) failed (%s)\n", 65 name2, name, cli_errstr(cli));68 name2, name, nt_errstr(status)); 66 69 return False; 67 70 } 68 71 69 72 /* recreate by short name */ 70 if (!NT_STATUS_IS_OK(cli_open(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 71 printf("open2 of %s failed (%s)\n", name2, cli_errstr(cli)); 72 return False; 73 } 74 if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) { 75 printf("close of %s failed (%s)\n", name, cli_errstr(cli)); 73 status = cli_openx(cli, name2, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 74 if (!NT_STATUS_IS_OK(status)) { 75 printf("open2 of %s failed (%s)\n", name2, nt_errstr(status)); 76 return False; 77 } 78 79 status = cli_close(cli, fnum); 80 if (!NT_STATUS_IS_OK(status)) { 81 printf("close of %s failed (%s)\n", name, nt_errstr(status)); 76 82 return False; 77 83 } 78 84 79 85 /* and unlink by long name */ 80 if (!NT_STATUS_IS_OK(cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 86 status = cli_unlink(cli, name, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 87 if (!NT_STATUS_IS_OK(status)) { 81 88 printf("unlink2 of %s (%s) failed (%s)\n", 82 name, name2, cli_errstr(cli));89 name, name2, nt_errstr(status)); 83 90 failures++; 84 91 cli_unlink(cli, name2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); … … 101 108 TDB_DATA namedata; 102 109 /* store it for later */ 103 namedata.dptr = CONST_DISCARD(uint8 *, name);110 namedata.dptr = discard_const_p(uint8_t, name); 104 111 namedata.dsize = strlen(name)+1; 105 112 tdb_store_bystring(tdb, shortname, namedata, TDB_REPLACE); -
vendor/current/source3/torture/masktest.c
r740 r988 3 3 mask_match tester 4 4 Copyright (C) Andrew Tridgell 1999 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 23 23 #include "libsmb/libsmb.h" 24 24 #include "libsmb/nmblib.h" 25 #include "../libcli/smb/smbXcli_base.h" 25 26 26 27 static fstring password; 27 28 static fstring username; 28 29 static int got_pass; 29 static int max_protocol = PROTOCOL_NT1;30 static int max_protocol = -1; 30 31 static bool showall = False; 31 32 static bool old_list = False; … … 145 146 if (strcmp(file,"..") == 0) file = "."; 146 147 147 return ms_fnmatch(pattern, file, cli->protocol, False) == 0;148 return ms_fnmatch(pattern, file, smbXcli_conn_protocol(cli->conn), False) == 0; 148 149 } 149 150 … … 168 169 { 169 170 struct cli_state *c; 170 struct nmb_name called, calling;171 171 char *server_n; 172 172 char *server; 173 struct sockaddr_storage ss;174 173 NTSTATUS status; 175 174 … … 182 181 server_n = server; 183 182 184 zero_sockaddr(&ss); 185 186 make_nmb_name(&calling, "masktest", 0x0); 187 make_nmb_name(&called , server, 0x20); 188 189 again: 190 zero_sockaddr(&ss); 191 192 /* have to open a new connection */ 193 if (!(c=cli_initialise())) { 194 DEBUG(0,("Connection to %s failed\n", server_n)); 183 status = cli_connect_nb(server, NULL, 0, 0x20, "masktest", 184 SMB_SIGNING_DEFAULT, 0, &c); 185 if (!NT_STATUS_IS_OK(status)) { 186 DEBUG(0,("Connection to %s failed. Error %s\n", server_n, 187 nt_errstr(status))); 195 188 return NULL; 196 189 } 197 190 198 status = cli_connect(c, server_n, &ss); 199 if (!NT_STATUS_IS_OK(status)) { 200 DEBUG(0,("Connection to %s failed. Error %s\n", server_n, nt_errstr(status) )); 201 return NULL; 202 } 203 204 c->protocol = max_protocol; 205 206 if (!cli_session_request(c, &calling, &called)) { 207 DEBUG(0,("session request to %s failed\n", called.name)); 208 cli_shutdown(c); 209 if (strcmp(called.name, "*SMBSERVER")) { 210 make_nmb_name(&called , "*SMBSERVER", 0x20); 211 goto again; 212 } 213 return NULL; 214 } 215 216 DEBUG(4,(" session request ok\n")); 217 218 status = cli_negprot(c); 191 status = smbXcli_negprot(c->conn, c->timeout, PROTOCOL_CORE, 192 max_protocol); 219 193 if (!NT_STATUS_IS_OK(status)) { 220 194 DEBUG(0, ("protocol negotiation failed: %s\n", … … 225 199 226 200 if (!got_pass) { 227 char *pass = getpass("Password: "); 228 if (pass) { 201 char pwd[256] = {0}; 202 int rc; 203 204 rc = samba_getpass("Password: ", pwd, sizeof(pwd), false, false); 205 if (rc == 0) { 229 206 fstrcpy(password, pass); 230 207 } … … 254 231 DEBUG(4,(" session setup ok\n")); 255 232 256 status = cli_t con_andx(c, share, "?????", password,257 233 status = cli_tree_connect(c, share, "?????", password, 234 strlen(password)+1); 258 235 if (!NT_STATUS_IS_OK(status)) { 259 236 DEBUG(0,("tree connect failed: %s\n", nt_errstr(status))); … … 294 271 } 295 272 296 fstrcpy(state->short_name, f->short_name); 297 strlower_m(state->short_name); 273 274 fstrcpy(state->short_name, f->short_name ? f->short_name : ""); 275 (void)strlower_m(state->short_name); 298 276 *state->pp_long_name = SMB_STRDUP(f->name); 299 277 if (!*state->pp_long_name) { 300 278 return NT_STATUS_NO_MEMORY; 301 279 } 302 strlower_m(*state->pp_long_name);280 (void)strlower_m(*state->pp_long_name); 303 281 return NT_STATUS_OK; 304 282 } … … 348 326 fstrcpy(res1, "---"); 349 327 350 if (!NT_STATUS_IS_OK(cli_open (cli, file, O_CREAT|O_TRUNC|O_RDWR, 0, &fnum))) {328 if (!NT_STATUS_IS_OK(cli_openx(cli, file, O_CREAT|O_TRUNC|O_RDWR, 0, &fnum))) { 351 329 DEBUG(0,("Can't create %s\n", file)); 352 330 return; … … 413 391 l1 = 1 + random() % 20; 414 392 l2 = 1 + random() % 20; 415 mask = TALLOC_ARRAY(ctx, char, strlen("\\masktest\\")+1+22);416 file = TALLOC_ARRAY(ctx, char, strlen("\\masktest\\")+1+22);393 mask = talloc_array(ctx, char, strlen("\\masktest\\")+1+22); 394 file = talloc_array(ctx, char, strlen("\\masktest\\")+1+22); 417 395 if (!mask || !file) { 418 396 goto finished; … … 505 483 argv += 1; 506 484 507 load_case_tables();508 lp_load (get_dyn_CONFIGFILE(),True,False,False,True);485 smb_init_locale(); 486 lp_load_global(get_dyn_CONFIGFILE()); 509 487 load_interfaces(); 510 488 … … 533 511 break; 534 512 case 'M': 535 max_protocol = interpret_protocol(optarg, max_protocol);513 lp_set_cmdline("client max protocol", optarg); 536 514 break; 537 515 case 'U': … … 571 549 argv += optind; 572 550 551 max_protocol = lp_client_max_protocol(); 573 552 574 553 cli = connect_one(share); -
vendor/current/source3/torture/msgtest.c
r740 r988 47 47 char buf[12]; 48 48 int ret; 49 TALLOC_CTX *frame = talloc_stackframe(); 49 50 50 load_case_tables();51 smb_init_locale(); 51 52 52 53 setup_logging(argv[0], DEBUG_STDOUT); 53 54 54 lp_load (get_dyn_CONFIGFILE(),False,False,False,True);55 lp_load_global(get_dyn_CONFIGFILE()); 55 56 56 if (!(evt_ctx = tevent_context_init(NULL)) ||57 !(msg_ctx = messaging_init(NULL, procid_self(),evt_ctx))) {57 if (!(evt_ctx = samba_tevent_context_init(NULL)) || 58 !(msg_ctx = messaging_init(NULL, evt_ctx))) { 58 59 fprintf(stderr, "could not init messaging context\n"); 60 TALLOC_FREE(frame); 59 61 exit(1); 60 62 } … … 63 65 fprintf(stderr, "%s: Usage - %s pid count\n", argv[0], 64 66 argv[0]); 67 TALLOC_FREE(frame); 65 68 exit(1); 66 69 } … … 83 86 } 84 87 85 /* Now test that the duplicate filtering code works. */88 /* Ensure all messages get through to ourselves. */ 86 89 pong_count = 0; 87 90 88 s afe_strcpy(buf, "1234567890", sizeof(buf)-1);91 strlcpy(buf, "1234567890", sizeof(buf)); 89 92 90 93 for (i=0;i<n;i++) { … … 92 95 &data_blob_null); 93 96 messaging_send_buf(msg_ctx, messaging_server_id(msg_ctx), 94 MSG_PING,(uint8 *)buf, 11);97 MSG_PING,(uint8_t *)buf, 11); 95 98 } 96 99 97 for (i=0;i<n;i++) { 100 /* 101 * We have to loop at least 2 times for 102 * each message as local ping messages are 103 * handled by an immediate callback, that 104 * has to be dispatched, which sends a pong 105 * message, which also has to be dispatched. 106 * Above we sent 2*n messages, which means 107 * we have to dispatch 4*n times. 108 */ 109 110 while (pong_count < n*2) { 98 111 ret = tevent_loop_once(evt_ctx); 99 112 if (ret != 0) { … … 102 115 } 103 116 104 if (pong_count != 2 ) {105 fprintf(stderr, " Duplicate filterfailed (%d).\n", pong_count);117 if (pong_count != 2*n) { 118 fprintf(stderr, "Message count failed (%d).\n", pong_count); 106 119 } 107 120 … … 120 133 msg_ctx, pid_to_procid(pid), 121 134 MSG_PING, 122 (uint8 *)buf, 11)))135 (uint8_t *)buf, 11))) 123 136 ping_count++; 124 137 if(NT_STATUS_IS_OK(messaging_send( … … 153 166 } 154 167 168 TALLOC_FREE(frame); 155 169 return (0); 156 170 } -
vendor/current/source3/torture/nbench.c
r740 r988 97 97 char *status; 98 98 99 result = TALLOC_P(mem_ctx, struct nbench_cmd_struct);99 result = talloc(mem_ctx, struct nbench_cmd_struct); 100 100 if (result == NULL) { 101 101 return NULL; … … 299 299 subreq = cli_qpathinfo_send(state, ev, nb_state->cli, fname, 300 300 ival(state->cmd->params[2]), 301 0, nb_state->cli->max_xmit);301 0, CLI_BUFFER_SIZE); 302 302 break; 303 303 } … … 339 339 case NBENCH_CMD_NTCREATEX: { 340 340 struct ftable *ft; 341 status = cli_ntcreate_recv(subreq, &state->ft->fnum );341 status = cli_ntcreate_recv(subreq, &state->ft->fnum, NULL); 342 342 TALLOC_FREE(subreq); 343 343 if (status_wrong(req, state->cmd->status, status)) { … … 466 466 return false; 467 467 } 468 ev = tevent_context_init(talloc_tos());468 ev = samba_tevent_context_init(talloc_tos()); 469 469 if (ev == NULL) { 470 470 goto fail; -
vendor/current/source3/torture/nbio.c
r740 r988 77 77 { 78 78 nprocs = n; 79 children = (struct children *) shm_setup(sizeof(*children) * nprocs);79 children = (struct children *)anonymous_shared_allocate(sizeof(*children) * nprocs); 80 80 if (!children) { 81 81 printf("Failed to setup shared memory!\n"); … … 136 136 void nb_unlink(const char *fname) 137 137 { 138 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 138 NTSTATUS status; 139 140 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 141 if (!NT_STATUS_IS_OK(status)) { 139 142 #if NBDEBUG 140 143 printf("(%d) unlink %s failed (%s)\n", 141 line_count, fname, cli_errstr(c));144 line_count, fname, nt_errstr(status)); 142 145 #endif 143 146 } … … 151 154 int i; 152 155 NTSTATUS status; 153 uint32 desired_access;156 uint32_t desired_access; 154 157 155 158 if (create_options & FILE_DIRECTORY_FILE) { … … 164 167 FILE_SHARE_READ|FILE_SHARE_WRITE, 165 168 create_disposition, 166 create_options, 0, &fd );169 create_options, 0, &fd, NULL); 167 170 if (!NT_STATUS_IS_OK(status) && handle != -1) { 168 171 printf("ERROR: cli_ntcreate failed for %s - %s\n", 169 fname, cli_errstr(c));172 fname, nt_errstr(status)); 170 173 exit(1); 171 174 } … … 210 213 void nb_readx(int handle, int offset, int size, int ret_size) 211 214 { 212 int i, ret; 215 int i; 216 NTSTATUS status; 217 size_t nread; 213 218 214 219 i = find_handle(handle); 215 if ((ret=cli_read(c, ftable[i].fd, buf, offset, size)) != ret_size) { 216 printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d res=%d fd %d errno %d (%s)\n", 217 line_count, handle, offset, size, ret, ftable[i].fd, errno, strerror(errno)); 220 status = cli_read(c, ftable[i].fd, buf, offset, size, &nread); 221 if (!NT_STATUS_IS_OK(status)) { 222 printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d " 223 "fd %d nterror %s\n", 224 line_count, handle, offset, size, 225 ftable[i].fd, nt_errstr(status)); 226 exit(1); 227 } else if (nread != ret_size) { 228 printf("(%d) ERROR: read failed on handle %d ofs=%d size=%d " 229 "nread=%lu ret_size=%d fd %d\n", 230 line_count, handle, offset, size, (unsigned long)nread, 231 ret_size, ftable[i].fd); 218 232 exit(1); 219 233 } … … 234 248 void nb_rmdir(const char *fname) 235 249 { 236 if (!NT_STATUS_IS_OK(cli_rmdir(c, fname))) { 250 NTSTATUS status; 251 252 status = cli_rmdir(c, fname); 253 if (!NT_STATUS_IS_OK(status)) { 237 254 printf("ERROR: rmdir %s failed (%s)\n", 238 fname, cli_errstr(c));255 fname, nt_errstr(status)); 239 256 exit(1); 240 257 } … … 243 260 void nb_rename(const char *oldname, const char *newname) 244 261 { 245 if (!NT_STATUS_IS_OK(cli_rename(c, oldname, newname))) { 262 NTSTATUS status; 263 264 status = cli_rename(c, oldname, newname); 265 if (!NT_STATUS_IS_OK(status)) { 246 266 printf("ERROR: rename %s %s failed (%s)\n", 247 oldname, newname, cli_errstr(c));267 oldname, newname, nt_errstr(status)); 248 268 exit(1); 249 269 } … … 266 286 void nb_qfsinfo(int level) 267 287 { 268 int bsize, total, avail;288 uint64_t bsize, total, avail; 269 289 /* this is not the right call - we need cli_qfsinfo() */ 270 cli_d skattr(c, &bsize, &total, &avail);290 cli_disk_size(c, "", &bsize, &total, &avail); 271 291 } 272 292 … … 287 307 int i; 288 308 i = find_handle(fnum); 289 /* hmmm, we don't have cli_flush() yet */ 309 310 cli_flush(NULL, c, i); 290 311 } 291 312 … … 304 325 n[strlen(n)-1] = 0; 305 326 if (asprintf(&s, "%s%s", n, finfo->name) == -1) { 327 free(n); 306 328 printf("asprintf failed\n"); 307 329 return NT_STATUS_NO_MEMORY; … … 311 333 if (asprintf(&s2, "%s\\*", s) == -1) { 312 334 printf("asprintf failed\n"); 335 free(s); 336 free(n); 313 337 return NT_STATUS_NO_MEMORY; 314 338 } 315 339 status = cli_list(c, s2, FILE_ATTRIBUTE_DIRECTORY, delete_fn, NULL); 340 free(s2); 316 341 if (!NT_STATUS_IS_OK(status)) { 342 free(s); 317 343 free(n); 318 free(s2);319 344 return status; 320 345 } -
vendor/current/source3/torture/pdbtest.c
r740 r988 2 2 Unix SMB/CIFS implementation. 3 3 passdb testing utility 4 4 5 5 Copyright (C) Wilco Baan Hofman 2006 6 6 Copyright (C) Jelmer Vernooij 2006 7 Copyright (C) Andrew Bartlett 2012 7 8 8 9 This program is free software; you can redistribute it and/or modify … … 10 11 the Free Software Foundation; either version 3 of the License, or 11 12 (at your option) any later version. 12 13 13 14 This program is distributed in the hope that it will be useful, 14 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 17 GNU General Public License for more details. 17 18 18 19 You should have received a copy of the GNU General Public License 19 20 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 25 26 #include "passdb.h" 26 27 28 #include "../librpc/gen_ndr/drsblobs.h" 29 #include "../librpc/gen_ndr/ndr_drsblobs.h" 30 #include "../libcli/security/dom_sid.h" 31 #include "../libcli/auth/libcli_auth.h" 32 #include "../auth/common_auth.h" 33 #include "lib/tsocket/tsocket.h" 34 #include "include/auth.h" 35 36 #define TRUST_DOM "trustdom" 37 #define TRUST_PWD "trustpwd1232" 38 #define TRUST_SID "S-1-5-21-1111111111-2222222222-3333333333" 39 27 40 static bool samu_correct(struct samu *s1, struct samu *s2) 28 41 { 29 42 bool ret = True; 30 uint32 s1_len, s2_len;43 uint32_t s1_len, s2_len; 31 44 const char *s1_buf, *s2_buf; 32 const uint8 *d1_buf, *d2_buf; 33 45 const uint8_t *d1_buf, *d2_buf; 46 const struct dom_sid *s1_sid, *s2_sid; 47 34 48 /* Check Unix username */ 35 49 s1_buf = pdb_get_username(s1); … … 104 118 } else if (d1_buf == NULL) { 105 119 /* Do nothing */ 106 } else if (s1_len != s 1_len) {120 } else if (s1_len != s2_len) { 107 121 DEBUG(0, ("Password history not written correctly, lengths differ, want %d, got %d\n", 108 122 s1_len, s2_len)); … … 121 135 /* Check logoff time */ 122 136 if (pdb_get_logoff_time(s1) != pdb_get_logoff_time(s2)) { 123 DEBUG(0, ("Logoff time is not written correctly\n")); 124 ret = False; 125 } 126 137 DEBUG(0, ("Logoff time is not written correctly: %s vs %s \n", 138 http_timestring(talloc_tos(), pdb_get_logoff_time(s1)), 139 http_timestring(talloc_tos(), pdb_get_logoff_time(s2)))); 140 ret = False; 141 } 142 127 143 /* Check kickoff time */ 128 if (pdb_get_kickoff_time(s1) != pdb_get_logoff_time(s2)) { 129 DEBUG(0, ("Kickoff time is not written correctly\n")); 130 ret = False; 131 } 132 144 if (pdb_get_kickoff_time(s1) != pdb_get_kickoff_time(s2)) { 145 DEBUG(0, ("Kickoff time is not written correctly: %s vs %s \n", 146 http_timestring(talloc_tos(), pdb_get_kickoff_time(s1)), 147 http_timestring(talloc_tos(), pdb_get_kickoff_time(s2)))); 148 ret = False; 149 } 150 133 151 /* Check bad password time */ 134 152 if (pdb_get_bad_password_time(s1) != pdb_get_bad_password_time(s2)) { … … 136 154 ret = False; 137 155 } 138 156 139 157 /* Check password last set time */ 140 158 if (pdb_get_pass_last_set_time(s1) != pdb_get_pass_last_set_time(s2)) { 141 DEBUG(0, ("Password last set time is not written correctly\n")); 142 ret = False; 143 } 144 159 DEBUG(0, ("Password last set time is not written correctly: %s vs %s \n", 160 http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s1)), 161 http_timestring(talloc_tos(), pdb_get_pass_last_set_time(s2)))); 162 ret = False; 163 } 164 145 165 /* Check password can change time */ 146 166 if (pdb_get_pass_can_change_time(s1) != pdb_get_pass_can_change_time(s2)) { 147 DEBUG(0, ("Password can change time is not written correctly\n")); 148 ret = False; 149 } 150 167 DEBUG(0, ("Password can change time is not written correctly %s vs %s \n", 168 http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s1)), 169 http_timestring(talloc_tos(), pdb_get_pass_can_change_time(s2)))); 170 ret = False; 171 } 172 151 173 /* Check password must change time */ 152 174 if (pdb_get_pass_must_change_time(s1) != pdb_get_pass_must_change_time(s2)) { … … 154 176 ret = False; 155 177 } 156 178 157 179 /* Check logon divs */ 158 180 if (pdb_get_logon_divs(s1) != pdb_get_logon_divs(s2)) { … … 160 182 ret = False; 161 183 } 162 184 163 185 /* Check logon hours */ 164 186 if (pdb_get_hours_len(s1) != pdb_get_hours_len(s2)) { … … 178 200 } 179 201 } 180 202 181 203 /* Check profile path */ 182 204 s1_buf = pdb_get_profile_path(s1); … … 204 226 ret = False; 205 227 } 206 228 207 229 /* Check logon script */ 208 230 s1_buf = pdb_get_logon_script(s1); … … 217 239 ret = False; 218 240 } 219 220 /* TODO Check user and group sids */ 221 241 242 /* Check user and group sids */ 243 s1_sid = pdb_get_user_sid(s1); 244 s2_sid = pdb_get_user_sid(s2); 245 if (s2_sid == NULL && s1_sid != NULL) { 246 DEBUG(0, ("USER SID not set\n")); 247 ret = False; 248 } else if (s1_sid == NULL) { 249 /* Do nothing */ 250 } else if (!dom_sid_equal(s1_sid, s2_sid)) { 251 DEBUG(0, ("USER SID is not written correctly\n")); 252 ret = False; 253 } 254 222 255 return ret; 223 256 } 224 257 225 226 int main(int argc, char **argv) 258 static bool test_auth(TALLOC_CTX *mem_ctx, struct samu *pdb_entry) 259 { 260 struct auth_usersupplied_info *user_info; 261 struct auth_context *auth_context; 262 static const uint8_t challenge_8[8] = {1, 2, 3, 4, 5, 6, 7, 8}; 263 DATA_BLOB challenge = data_blob_const(challenge_8, sizeof(challenge_8)); 264 struct tsocket_address *tsocket_address; 265 unsigned char local_nt_response[24]; 266 DATA_BLOB nt_resp = data_blob_const(local_nt_response, sizeof(local_nt_response)); 267 unsigned char local_nt_session_key[16]; 268 struct netr_SamInfo3 *info3_sam, *info3_auth; 269 struct auth_serversupplied_info *server_info; 270 NTSTATUS status; 271 272 SMBOWFencrypt(pdb_get_nt_passwd(pdb_entry), challenge_8, 273 local_nt_response); 274 SMBsesskeygen_ntv1(pdb_get_nt_passwd(pdb_entry), local_nt_session_key); 275 276 if (tsocket_address_inet_from_strings(NULL, "ip", NULL, 0, &tsocket_address) != 0) { 277 return False; 278 } 279 280 status = make_user_info(mem_ctx, 281 &user_info, pdb_get_username(pdb_entry), pdb_get_username(pdb_entry), 282 pdb_get_domain(pdb_entry), pdb_get_domain(pdb_entry), lp_netbios_name(), 283 tsocket_address, NULL, &nt_resp, NULL, NULL, NULL, 284 AUTH_PASSWORD_RESPONSE); 285 if (!NT_STATUS_IS_OK(status)) { 286 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status))); 287 return False; 288 } 289 290 status = check_sam_security_info3(&challenge, NULL, user_info, &info3_sam); 291 if (!NT_STATUS_IS_OK(status)) { 292 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status))); 293 return False; 294 } 295 296 if (memcmp(info3_sam->base.key.key, local_nt_session_key, 16) != 0) { 297 DEBUG(0, ("Returned NT session key is incorrect\n")); 298 return False; 299 } 300 301 status = make_auth_context_fixed(NULL, &auth_context, challenge.data); 302 303 if (!NT_STATUS_IS_OK(status)) { 304 DEBUG(0, ("Failed to test authentication with check_sam_security_info3: %s\n", nt_errstr(status))); 305 return False; 306 } 307 308 status = auth_check_ntlm_password(mem_ctx, 309 auth_context, 310 user_info, 311 &server_info); 312 313 if (!NT_STATUS_IS_OK(status)) { 314 DEBUG(0, ("Failed to test authentication with auth module: %s\n", nt_errstr(status))); 315 return False; 316 } 317 318 info3_auth = talloc_zero(mem_ctx, struct netr_SamInfo3); 319 if (info3_auth == NULL) { 320 return False; 321 } 322 323 status = serverinfo_to_SamInfo3(server_info, info3_auth); 324 if (!NT_STATUS_IS_OK(status)) { 325 DEBUG(0, ("serverinfo_to_SamInfo3 failed: %s\n", 326 nt_errstr(status))); 327 return False; 328 } 329 330 if (memcmp(info3_auth->base.key.key, local_nt_session_key, 16) != 0) { 331 DEBUG(0, ("Returned NT session key is incorrect\n")); 332 return False; 333 } 334 335 if (!dom_sid_equal(info3_sam->base.domain_sid, info3_auth->base.domain_sid)) { 336 DEBUG(0, ("domain_sid in SAM info3 %s does not match domain_sid in AUTH info3 %s\n", 337 dom_sid_string(NULL, info3_sam->base.domain_sid), 338 dom_sid_string(NULL, info3_auth->base.domain_sid))); 339 return False; 340 } 341 342 /* TODO: 343 * Compre more details from the two info3 structures, 344 * then test that an expired/disabled/pwdmustchange account 345 * returns the correct errors 346 */ 347 348 return True; 349 } 350 351 static bool test_trusted_domains(TALLOC_CTX *ctx, 352 struct pdb_methods *pdb, 353 bool *error) 354 { 355 NTSTATUS rv; 356 /* test trustdom calls */ 357 struct pdb_trusted_domain *td; 358 struct pdb_trusted_domain *new_td; 359 struct trustAuthInOutBlob taiob; 360 struct AuthenticationInformation aia; 361 enum ndr_err_code ndr_err; 362 363 td = talloc_zero(ctx ,struct pdb_trusted_domain); 364 if (!td) { 365 fprintf(stderr, "talloc failed\n"); 366 return false; 367 } 368 369 td->domain_name = talloc_strdup(td, TRUST_DOM); 370 td->netbios_name = talloc_strdup(td, TRUST_DOM); 371 if (!td->domain_name || !td->netbios_name) { 372 fprintf(stderr, "talloc failed\n"); 373 return false; 374 } 375 376 td->trust_auth_incoming = data_blob_null; 377 378 ZERO_STRUCT(taiob); 379 ZERO_STRUCT(aia); 380 taiob.count = 1; 381 taiob.current.count = 1; 382 taiob.current.array = &aia; 383 unix_to_nt_time(&aia.LastUpdateTime, time(NULL)); 384 aia.AuthType = TRUST_AUTH_TYPE_CLEAR; 385 aia.AuthInfo.clear.password = (uint8_t *) talloc_strdup(ctx, TRUST_PWD); 386 aia.AuthInfo.clear.size = strlen(TRUST_PWD); 387 388 taiob.previous.count = 0; 389 taiob.previous.array = NULL; 390 391 ndr_err = ndr_push_struct_blob(&td->trust_auth_outgoing, 392 td, &taiob, 393 (ndr_push_flags_fn_t) ndr_push_trustAuthInOutBlob); 394 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 395 fprintf(stderr, "ndr_push_struct_blob failed.\n"); 396 return false; 397 } 398 399 td->trust_direction = LSA_TRUST_DIRECTION_OUTBOUND; 400 td->trust_type = LSA_TRUST_TYPE_DOWNLEVEL; 401 td->trust_attributes = 0; 402 td->trust_forest_trust_info = data_blob_null; 403 404 rv = pdb->set_trusted_domain(pdb, TRUST_DOM, td); 405 if (!NT_STATUS_IS_OK(rv)) { 406 fprintf(stderr, "Error in set_trusted_domain %s\n", 407 get_friendly_nt_error_msg(rv)); 408 *error = true; 409 } 410 411 rv = pdb->get_trusted_domain(pdb, ctx, TRUST_DOM, &new_td); 412 if (!NT_STATUS_IS_OK(rv)) { 413 fprintf(stderr, "Error in set_trusted_domain %s\n", 414 get_friendly_nt_error_msg(rv)); 415 *error = true; 416 } 417 418 if (!strequal(td->domain_name, new_td->domain_name) || 419 !strequal(td->netbios_name, new_td->netbios_name) || 420 !dom_sid_equal(&td->security_identifier, 421 &new_td->security_identifier) || 422 td->trust_direction != new_td->trust_direction || 423 td->trust_type != new_td->trust_type || 424 td->trust_attributes != new_td->trust_attributes || 425 td->trust_auth_incoming.length != new_td->trust_auth_incoming.length || 426 td->trust_forest_trust_info.length != new_td->trust_forest_trust_info.length || 427 data_blob_cmp(&td->trust_auth_outgoing, &new_td->trust_auth_outgoing) != 0) { 428 fprintf(stderr, "Old and new trusdet domain data do not match\n"); 429 *error = true; 430 } 431 432 return true; 433 } 434 435 436 int main(int argc, const char **argv) 227 437 { 228 438 TALLOC_CTX *ctx; … … 234 444 bool error = False; 235 445 struct passwd *pwd; 236 uint8 *buf;237 uint32 expire, min_age, history;446 uint8_t *buf; 447 uint32_t expire, min_age, history; 238 448 struct pdb_methods *pdb; 239 449 poptContext pc; … … 248 458 }; 249 459 250 load_case_tables(); 251 252 pc = poptGetContext("pdbtest", argc, (const char **) argv, 253 long_options, 0); 460 ctx = talloc_stackframe(); 461 462 smb_init_locale(); 463 464 pc = poptGetContext("pdbtest", argc, argv, long_options, 0); 254 465 255 466 poptSetOtherOptionHelp(pc, "backend[:settings] username"); 256 467 257 468 while(poptGetNextOpt(pc) != -1); 258 469 … … 260 471 261 472 /* Load configuration */ 262 lp_load (get_dyn_CONFIGFILE(), False, False, True, True);473 lp_load_global(get_dyn_CONFIGFILE()); 263 474 setup_logging("pdbtest", DEBUG_STDOUT); 475 init_names(); 264 476 265 477 if (backend == NULL) { … … 272 484 exit(1); 273 485 } 274 275 ctx = talloc_init("PDBTEST"); 276 486 277 487 if (!(out = samu_new(ctx))) { 278 488 fprintf(stderr, "Can't create samu structure.\n"); 279 489 exit(1); 280 490 } 281 491 282 492 if ((pwd = Get_Pwnam_alloc(ctx, unix_user)) == NULL) { 283 493 fprintf(stderr, "Error getting user information for %s\n", unix_user); 284 494 exit(1); 285 495 } 286 496 287 497 samu_set_unix(out, pwd); 288 498 … … 291 501 pdb_set_logon_script(out, "torture_script.cmd", PDB_SET); 292 502 503 pdb_set_acct_ctrl(out, ACB_NORMAL, PDB_SET); 504 293 505 pdb_get_account_policy(PDB_POLICY_PASSWORD_HISTORY, &history); 294 506 if (history * PW_HISTORY_ENTRY_LEN < NT_HASH_LEN) { 295 buf = (uint8 *)TALLOC(ctx, NT_HASH_LEN);507 buf = (uint8_t *)TALLOC(ctx, NT_HASH_LEN); 296 508 } else { 297 buf = (uint8 *)TALLOC(ctx, history * PW_HISTORY_ENTRY_LEN);509 buf = (uint8_t *)TALLOC(ctx, history * PW_HISTORY_ENTRY_LEN); 298 510 } 299 511 … … 302 514 srand(tv.tv_usec); 303 515 for (i = 0; i < NT_HASH_LEN; i++) { 304 buf[i] = (uint8 ) rand();516 buf[i] = (uint8_t) rand(); 305 517 } 306 518 pdb_set_nt_passwd(out, buf, PDB_SET); 307 519 for (i = 0; i < LM_HASH_LEN; i++) { 308 buf[i] = (uint8 ) rand();520 buf[i] = (uint8_t) rand(); 309 521 } 310 522 pdb_set_lanman_passwd(out, buf, PDB_SET); 311 523 for (i = 0; i < history * PW_HISTORY_ENTRY_LEN; i++) { 312 buf[i] = (uint8 ) rand();524 buf[i] = (uint8_t) rand(); 313 525 } 314 526 pdb_set_pw_history(out, buf, history, PDB_SET); … … 317 529 pdb_get_account_policy(PDB_POLICY_MIN_PASSWORD_AGE, &min_age); 318 530 pdb_set_pass_last_set_time(out, time(NULL), PDB_SET); 319 320 if (expire == 0 || expire == (uint32)-1) { 321 pdb_set_pass_must_change_time(out, get_time_t_max(), PDB_SET); 322 } else { 323 pdb_set_pass_must_change_time(out, time(NULL)+expire, PDB_SET); 324 } 325 326 if (min_age == (uint32)-1) { 531 532 if (min_age == (uint32_t)-1) { 327 533 pdb_set_pass_can_change_time(out, 0, PDB_SET); 328 534 } else { 329 535 pdb_set_pass_can_change_time(out, time(NULL)+min_age, PDB_SET); 330 536 } 331 537 538 pdb_set_logon_time(out, time(NULL)-3600, PDB_SET); 539 540 pdb_set_logoff_time(out, time(NULL), PDB_SET); 541 542 pdb_set_kickoff_time(out, time(NULL)+3600, PDB_SET); 543 332 544 /* Create account */ 333 545 if (!NT_STATUS_IS_OK(rv = pdb->add_sam_account(pdb, out))) { … … 341 553 exit(1); 342 554 } 343 555 344 556 /* Get account information through getsampwnam() */ 345 if (NT_STATUS_IS_ERR(pdb->getsampwnam(pdb, in, out->username))) { 346 fprintf(stderr, "Error getting sampw of added user %s.\n", 347 out->username); 557 rv = pdb->getsampwnam(pdb, in, out->username); 558 if (NT_STATUS_IS_ERR(rv)) { 559 fprintf(stderr, "Error getting sampw of added user %s: %s\n", 560 out->username, nt_errstr(rv)); 348 561 if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) { 349 562 fprintf(stderr, "Error in delete_sam_account %s\n", … … 351 564 } 352 565 TALLOC_FREE(ctx); 353 } 354 566 exit(1); 567 } 568 355 569 /* Verify integrity */ 356 570 if (samu_correct(out, in)) { … … 360 574 error = True; 361 575 } 362 576 577 if (test_auth(ctx, out)) { 578 printf("Authentication module test passed\n"); 579 } else { 580 printf("Authentication module test failed!\n"); 581 error = True; 582 } 583 584 363 585 /* Delete account */ 364 586 if (!NT_STATUS_IS_OK(rv = pdb->delete_sam_account(pdb, out))) { … … 367 589 } 368 590 591 if (pdb_capabilities() & PDB_CAP_TRUSTED_DOMAINS_EX) { 592 if (!test_trusted_domains(ctx, pdb, &error)) { 593 fprintf(stderr, "failed testing trusted domains.\n"); 594 exit(1); 595 } 596 } 597 369 598 TALLOC_FREE(ctx); 370 599 -
vendor/current/source3/torture/proto.h
r740 r988 64 64 /* The following definitions come from torture/torture.c */ 65 65 66 void *shm_setup(int size);67 66 bool smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx, 68 67 char **hostname, char **sharename); 69 68 bool torture_open_connection(struct cli_state **c, int conn_index); 70 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid); 69 bool torture_init_connection(struct cli_state **pcli); 70 bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid); 71 71 bool torture_close_connection(struct cli_state *c); 72 72 bool torture_ioctl_test(int dummy); … … 84 84 85 85 bool run_posix_append(int dummy); 86 bool run_case_insensitive_create(int dummy); 86 87 87 88 bool run_nbench2(int dummy); … … 89 90 bool run_smb_any_connect(int dummy); 90 91 bool run_addrchange(int dummy); 92 bool run_notify_online(int dummy); 93 bool run_nttrans_create(int dummy); 94 bool run_nttrans_fsctl(int dummy); 95 bool run_smb2_basic(int dummy); 96 bool run_smb2_negprot(int dummy); 97 bool run_smb2_session_reconnect(int dummy); 98 bool run_smb2_tcon_dependence(int dummy); 99 bool run_smb2_multi_channel(int dummy); 100 bool run_smb2_session_reauth(int dummy); 101 bool run_chain3(int dummy); 102 bool run_local_conv_auth_info(int dummy); 103 bool run_local_sprintf_append(int dummy); 104 bool run_cleanup1(int dummy); 105 bool run_cleanup2(int dummy); 106 bool run_cleanup3(int dummy); 107 bool run_cleanup4(int dummy); 108 bool run_notify_bench2(int dummy); 109 bool run_notify_bench3(int dummy); 110 bool run_dbwrap_watch1(int dummy); 111 bool run_idmap_tdb_common_test(int dummy); 112 bool run_local_dbwrap_ctdb(int dummy); 113 bool run_qpathinfo_bufsize(int dummy); 114 bool run_bench_pthreadpool(int dummy); 115 bool run_messaging_read1(int dummy); 116 bool run_messaging_read2(int dummy); 117 bool run_messaging_read3(int dummy); 118 bool run_messaging_read4(int dummy); 119 bool run_messaging_fdpass1(int dummy); 120 bool run_messaging_fdpass2(int dummy); 121 bool run_messaging_fdpass2a(int dummy); 122 bool run_messaging_fdpass2b(int dummy); 123 bool run_oplock_cancel(int dummy); 91 124 92 125 #endif /* __TORTURE_H__ */ -
vendor/current/source3/torture/rpc_open_tcp.c
r740 r988 95 95 } 96 96 97 status = rpc_pipe_open_tcp(mem_ctx, argv[2], &((*table)->syntax_id), 97 status = rpc_pipe_open_tcp(mem_ctx, argv[2], NULL, 98 *table, 98 99 &rpc_pipe); 99 100 if (!NT_STATUS_IS_OK(status)) { -
vendor/current/source3/torture/scanner.c
r740 r988 22 22 #include "torture/proto.h" 23 23 #include "libsmb/libsmb.h" 24 #include "../libcli/smb/smbXcli_base.h" 24 25 25 26 #define VERBOSE 0 … … 68 69 NULL, 0, 0, /* setup */ 69 70 param, param_len, 2, 70 data, data_len, cli->max_xmit,71 data, data_len, CLI_BUFFER_SIZE, 71 72 NULL, /* recv_flags2 */ 72 73 NULL, 0, NULL, /* rsetup */ … … 122 123 uint32_t param_len = 0; 123 124 uint32_t rparam_len, rdata_len; 124 uint8_t param[PARAM_SIZE], data[DATA_SIZE]; 125 uint8_t *param = NULL; 126 uint8_t data[DATA_SIZE]; 127 const char *newfname; 128 const char *dname; 125 129 NTSTATUS status; 126 130 … … 129 133 130 134 /* try with a info level only */ 131 param_len = 2; 132 SSVAL(param, 0, level); 135 TALLOC_FREE(param); 136 param = talloc_array(talloc_tos(), uint8_t, 2); 137 if (param == NULL) return True; 138 139 SSVAL(param, 0, level); 140 141 param_len = talloc_get_size(param); 133 142 status = try_trans2_len(cli, "void", op, level, param, data, param_len, &data_len, 134 143 &rparam_len, &rdata_len); … … 136 145 137 146 /* try with a file descriptor */ 138 param_len = 6; 147 TALLOC_FREE(param); 148 param = talloc_array(talloc_tos(), uint8_t, 6); 149 if (param == NULL) return True; 150 139 151 SSVAL(param, 0, fnum); 140 152 SSVAL(param, 2, level); 141 153 SSVAL(param, 4, 0); 154 155 param_len = talloc_get_size(param); 142 156 status = try_trans2_len(cli, "fnum", op, level, param, data, param_len, &data_len, 143 157 &rparam_len, &rdata_len); … … 146 160 147 161 /* try with a notify style */ 148 param_len = 6; 162 TALLOC_FREE(param); 163 param = talloc_array(talloc_tos(), uint8_t, 6); 164 if (param == NULL) return True; 165 149 166 SSVAL(param, 0, dnum); 150 167 SSVAL(param, 2, dnum); 151 168 SSVAL(param, 4, level); 169 170 param_len = talloc_get_size(param); 152 171 status = try_trans2_len(cli, "notify", op, level, param, data, param_len, &data_len, 153 172 &rparam_len, &rdata_len); … … 155 174 156 175 /* try with a file name */ 157 param_len = 6; 176 TALLOC_FREE(param); 177 param = talloc_array(talloc_tos(), uint8_t, 6); 178 if (param == NULL) return True; 179 158 180 SSVAL(param, 0, level); 159 181 SSVAL(param, 2, 0); 160 182 SSVAL(param, 4, 0); 161 param_len += clistr_push(cli, ¶m[6], fname, -1, STR_TERMINATE); 162 183 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 184 fname, strlen(fname)+1, NULL); 185 if (param == NULL) return True; 186 187 param_len = talloc_get_size(param); 163 188 status = try_trans2_len(cli, "fname", op, level, param, data, param_len, &data_len, 164 189 &rparam_len, &rdata_len); … … 166 191 167 192 /* try with a new file name */ 168 param_len = 6; 193 newfname = "\\newfile.dat"; 194 TALLOC_FREE(param); 195 param = talloc_array(talloc_tos(), uint8_t, 6); 196 if (param == NULL) return True; 197 169 198 SSVAL(param, 0, level); 170 199 SSVAL(param, 2, 0); 171 200 SSVAL(param, 4, 0); 172 param_len += clistr_push(cli, ¶m[6], "\\newfile.dat", -1, STR_TERMINATE); 173 201 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 202 newfname, strlen(newfname)+1, NULL); 203 if (param == NULL) return True; 204 205 param_len = talloc_get_size(param); 174 206 status = try_trans2_len(cli, "newfile", op, level, param, data, param_len, &data_len, 175 207 &rparam_len, &rdata_len); 176 cli_unlink(cli, "\\newfile.dat", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);177 cli_rmdir(cli, "\\newfile.dat");208 cli_unlink(cli, newfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 209 cli_rmdir(cli, newfname); 178 210 if (NT_STATUS_IS_OK(status)) return True; 179 211 180 212 /* try dfs style */ 181 cli_mkdir(cli, "\\testdir"); 182 param_len = 2; 183 SSVAL(param, 0, level); 184 param_len += clistr_push(cli, ¶m[2], "\\testdir", -1, STR_TERMINATE); 185 213 dname = "\\testdir"; 214 cli_mkdir(cli, dname); 215 TALLOC_FREE(param); 216 param = talloc_array(talloc_tos(), uint8_t, 2); 217 if (param == NULL) return True; 218 219 SSVAL(param, 0, level); 220 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 221 dname, strlen(dname)+1, NULL); 222 if (param == NULL) return True; 223 224 param_len = talloc_get_size(param); 186 225 status = try_trans2_len(cli, "dfs", op, level, param, data, param_len, &data_len, 187 226 &rparam_len, &rdata_len); 188 cli_rmdir(cli, "\\testdir");227 cli_rmdir(cli, dname); 189 228 if (NT_STATUS_IS_OK(status)) return True; 190 229 … … 206 245 } 207 246 208 if (!NT_STATUS_IS_OK(cli_open (cli, fname, O_RDWR | O_CREAT | O_TRUNC,247 if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 209 248 DENY_NONE, &fnum))) { 210 249 printf("open of %s failed\n", fname); 211 250 return false; 212 251 } 213 if (!NT_STATUS_IS_OK(cli_open (cli, "\\", O_RDONLY, DENY_NONE, &dnum))) {252 if (!NT_STATUS_IS_OK(cli_openx(cli, "\\", O_RDONLY, DENY_NONE, &dnum))) { 214 253 printf("open of \\ failed\n"); 215 254 return false; … … 276 315 NULL, 0, 0, /* setup */ 277 316 param, param_len, 2, 278 data, data_len, cli->max_xmit,317 data, data_len, CLI_BUFFER_SIZE, 279 318 NULL, /* recv_flags2 */ 280 319 NULL, 0, NULL, /* rsetup */ … … 329 368 uint32_t param_len = 0; 330 369 uint32_t rparam_len, rdata_len; 331 uint8_t param[PARAM_SIZE], data[DATA_SIZE]; 370 uint8_t *param = NULL; 371 uint8_t data[DATA_SIZE]; 332 372 NTSTATUS status; 373 const char *newfname; 374 const char *dname; 333 375 334 376 memset(data, 0, sizeof(data)); … … 336 378 337 379 /* try with a info level only */ 338 param_len = 2; 339 SSVAL(param, 0, level); 380 TALLOC_FREE(param); 381 param = talloc_array(talloc_tos(), uint8_t, 2); 382 if (param == NULL) return True; 383 384 SSVAL(param, 0, level); 385 386 param_len = talloc_get_size(param); 340 387 status = try_nttrans_len(cli, "void", op, level, param, data, param_len, &data_len, 341 388 &rparam_len, &rdata_len); … … 343 390 344 391 /* try with a file descriptor */ 345 param_len = 6; 392 TALLOC_FREE(param); 393 param = talloc_array(talloc_tos(), uint8_t, 6); 394 if (param == NULL) return True; 395 346 396 SSVAL(param, 0, fnum); 347 397 SSVAL(param, 2, level); 348 398 SSVAL(param, 4, 0); 399 400 param_len = talloc_get_size(param); 349 401 status = try_nttrans_len(cli, "fnum", op, level, param, data, param_len, &data_len, 350 402 &rparam_len, &rdata_len); … … 353 405 354 406 /* try with a notify style */ 355 param_len = 6; 407 TALLOC_FREE(param); 408 param = talloc_array(talloc_tos(), uint8_t, 6); 409 if (param == NULL) return True; 410 356 411 SSVAL(param, 0, dnum); 357 412 SSVAL(param, 2, dnum); 358 413 SSVAL(param, 4, level); 414 415 param_len = talloc_get_size(param); 359 416 status = try_nttrans_len(cli, "notify", op, level, param, data, param_len, &data_len, 360 417 &rparam_len, &rdata_len); … … 362 419 363 420 /* try with a file name */ 364 param_len = 6; 421 TALLOC_FREE(param); 422 param = talloc_array(talloc_tos(), uint8_t, 6); 423 if (param == NULL) return True; 424 365 425 SSVAL(param, 0, level); 366 426 SSVAL(param, 2, 0); 367 427 SSVAL(param, 4, 0); 368 param_len += clistr_push(cli, ¶m[6], fname, -1, STR_TERMINATE); 369 428 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 429 fname, strlen(fname)+1, NULL); 430 if (param == NULL) return True; 431 432 param_len = talloc_get_size(param); 370 433 status = try_nttrans_len(cli, "fname", op, level, param, data, param_len, &data_len, 371 434 &rparam_len, &rdata_len); … … 373 436 374 437 /* try with a new file name */ 375 param_len = 6; 438 newfname = "\\newfile.dat"; 439 TALLOC_FREE(param); 440 param = talloc_array(talloc_tos(), uint8_t, 6); 441 if (param == NULL) return True; 442 376 443 SSVAL(param, 0, level); 377 444 SSVAL(param, 2, 0); 378 445 SSVAL(param, 4, 0); 379 param_len += clistr_push(cli, ¶m[6], "\\newfile.dat", -1, STR_TERMINATE); 380 446 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 447 newfname, strlen(newfname)+1, NULL); 448 if (param == NULL) return True; 449 450 param_len = talloc_get_size(param); 381 451 status = try_nttrans_len(cli, "newfile", op, level, param, data, param_len, &data_len, 382 452 &rparam_len, &rdata_len); 383 cli_unlink(cli, "\\newfile.dat", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN);384 cli_rmdir(cli, "\\newfile.dat");453 cli_unlink(cli, newfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 454 cli_rmdir(cli, newfname); 385 455 if (NT_STATUS_IS_OK(status)) return True; 386 456 387 457 /* try dfs style */ 388 cli_mkdir(cli, "\\testdir"); 389 param_len = 2; 390 SSVAL(param, 0, level); 391 param_len += clistr_push(cli, ¶m[2], "\\testdir", -1, STR_TERMINATE); 392 458 dname = "\\testdir"; 459 cli_mkdir(cli, dname); 460 TALLOC_FREE(param); 461 param = talloc_array(talloc_tos(), uint8_t, 2); 462 if (param == NULL) return True; 463 464 SSVAL(param, 0, level); 465 param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), 466 dname, strlen(dname)+1, NULL); 467 if (param == NULL) return True; 468 469 param_len = talloc_get_size(param); 393 470 status = try_nttrans_len(cli, "dfs", op, level, param, data, param_len, &data_len, 394 471 &rparam_len, &rdata_len); 395 cli_rmdir(cli, "\\testdir");472 cli_rmdir(cli, dname); 396 473 if (NT_STATUS_IS_OK(status)) return True; 397 474 … … 413 490 } 414 491 415 cli_open (cli, fname, O_RDWR | O_CREAT | O_TRUNC,492 cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 416 493 DENY_NONE, &fnum); 417 cli_open (cli, "\\", O_RDONLY, DENY_NONE, &dnum);494 cli_openx(cli, "\\", O_RDONLY, DENY_NONE, &dnum); 418 495 419 496 for (op=OP_MIN; op<=OP_MAX; op++) { -
vendor/current/source3/torture/t_strappend.c
r414 r988 6 6 7 7 #include "includes.h" 8 #include <assert.h>8 #include "torture/proto.h" 9 9 10 int main(int argc, char *argv[])10 bool run_local_sprintf_append(int dummy) 11 11 { 12 12 TALLOC_CTX *mem_ctx; 13 13 char *string = NULL; 14 int len = 0;15 int bufsize = 4;14 ssize_t len = 0; 15 size_t bufsize = 4; 16 16 int i; 17 17 … … 19 19 if (mem_ctx == NULL) { 20 20 fprintf(stderr, "talloc_init failed\n"); 21 return 1;21 return false; 22 22 } 23 23 … … 31 31 32 32 33 for (i=0; i<(10000 0); i++) {33 for (i=0; i<(10000); i++) { 34 34 if (i%1000 == 0) { 35 printf("%d % d\r", i,bufsize);35 printf("%d %lld\r", i, (long long int)bufsize); 36 36 fflush(stdout); 37 37 } 38 38 sprintf_append(mem_ctx, &string, &len, &bufsize, "%d\n", i); 39 assert(strlen(string) == len); 39 if (strlen(string) != len) { 40 fprintf(stderr, "sprintf_append failed: strlen(string) %lld != len %lld\n", 41 (long long int)strlen(string), (long long int)len); 42 return false; 43 } 40 44 } 41 45 42 46 talloc_destroy(mem_ctx); 43 47 44 return 0;48 return true; 45 49 } -
vendor/current/source3/torture/test_addrchange.c
r740 r988 20 20 #include "includes.h" 21 21 #include "lib/addrchange.h" 22 #include "lib/util/tevent_ntstatus.h" 22 23 #include "proto.h" 23 24 … … 31 32 int i; 32 33 33 ev = tevent_context_init(talloc_tos());34 ev = samba_tevent_context_init(talloc_tos()); 34 35 if (ev == NULL) { 35 36 d_fprintf(stderr, "tevent_context_init failed\n"); -
vendor/current/source3/torture/test_async_echo.c
r740 r988 47 47 } 48 48 49 static void cli_close_done(struct tevent_req *req)49 static void write_andx_done(struct tevent_req *req) 50 50 { 51 51 int *done = (int *)tevent_req_callback_data_void(req); … … 55 55 status = cli_write_andx_recv(req, &written); 56 56 TALLOC_FREE(req); 57 printf("cl osereturned %s\n", nt_errstr(status));57 printf("cli_write_andx returned %s\n", nt_errstr(status)); 58 58 *done -= 1; 59 59 } … … 69 69 bool ret = false; 70 70 int i, num_reqs; 71 uint8_t buf[ 32768];71 uint8_t buf[65536]; 72 72 73 73 printf("Starting ASYNC_ECHO\n"); 74 74 75 ev = tevent_context_init(talloc_tos());75 ev = samba_tevent_context_init(talloc_tos()); 76 76 if (ev == NULL) { 77 77 printf("tevent_context_init failed\n"); … … 83 83 goto fail; 84 84 } 85 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho .syntax_id,85 status = cli_rpc_pipe_open_noauth(cli, &ndr_table_rpcecho, 86 86 &p); 87 87 if (!NT_STATUS_IS_OK(status)) { … … 112 112 113 113 for (i=0; i<10; i++) { 114 req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0, sizeof(buf)); 114 req = cli_write_andx_send(ev, ev, cli, 4711, 0, buf, 0, 115 sizeof(buf)); 115 116 if (req == NULL) { 116 printf("cli_ close_send failed\n");117 printf("cli_write_andx_send failed\n"); 117 118 goto fail; 118 119 } 119 tevent_req_set_callback(req, cli_close_done, &num_reqs);120 tevent_req_set_callback(req, write_andx_done, &num_reqs); 120 121 num_reqs += 1; 121 122 122 req = cli_echo_send(ev, ev, cli, 1, data_blob_const("hello", 5)); 123 req = cli_echo_send(ev, ev, cli, 1, 124 data_blob_const("hello", 5)); 123 125 if (req == NULL) { 124 126 printf("cli_echo_send failed\n"); -
vendor/current/source3/torture/test_case_insensitive.c
r740 r988 50 50 goto rmdir; 51 51 } 52 status = cli_open (cli, "x\\y", O_RDWR|O_CREAT, 0, &fnum);52 status = cli_openx(cli, "x\\y", O_RDWR|O_CREAT, 0, &fnum); 53 53 if (!NT_STATUS_IS_OK(status)) { 54 printf("cli_open failed: %s\n", nt_errstr(status));54 printf("cli_openx failed: %s\n", nt_errstr(status)); 55 55 56 56 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_IS_A_DIRECTORY)) { -
vendor/current/source3/torture/test_ntlm_auth.py
r414 r988 28 28 29 29 class ReadChildError(Exception): 30 30 pass 31 31 32 32 class WriteChildError(Exception): 33 33 pass 34 34 35 35 def readLine(pipe): 36 37 38 39 40 41 42 43 44 36 """readLine(pipe) -> str 37 Read a line from the child's pipe, returns the string read. 38 Throws ReadChildError if the read fails. 39 """ 40 buf = os.read(pipe, 2047) 41 newline = buf.find('\n') 42 if newline == -1: 43 raise ReadChildError() 44 return buf[:newline] 45 45 46 46 def writeLine(pipe, buf): 47 48 49 50 51 52 53 54 47 """writeLine(pipe, buf) -> nul 48 Write a line to the child's pipe. 49 Raises WriteChildError if the write fails. 50 """ 51 written = os.write(pipe, buf) 52 if written != len(buf): 53 raise WriteChildError() 54 os.write(pipe, "\n") 55 55 56 56 def parseCommandLine(): 57 """parseCommandLine() -> (opts, ntlm_auth_path) 58 Parse the command line. 59 Return a tuple consisting of the options and the path to ntlm_auth. 60 """ 61 usage = "usage: %prog [options] path/to/ntlm_auth" 62 parser = OptionParser(usage) 63 64 parser.set_defaults(client_username="foo") 65 parser.set_defaults(client_password="secret") 66 parser.set_defaults(client_domain="FOO") 67 parser.set_defaults(client_helper="ntlmssp-client-1") 68 69 parser.set_defaults(server_username="foo") 70 parser.set_defaults(server_password="secret") 71 parser.set_defaults(server_domain="FOO") 72 parser.set_defaults(server_helper="squid-2.5-ntlmssp") 73 parser.set_defaults(config_file="/etc/samba/smb.conf") 74 75 parser.add_option("--client-username", dest="client_username",\ 76 help="User name for the client. [default: foo]") 77 parser.add_option("--client-password", dest="client_password",\ 78 help="Password the client will send. [default: secret]") 79 parser.add_option("--client-domain", dest="client_domain",\ 80 help="Domain the client authenticates for. [default: FOO]") 81 parser.add_option("--client-helper", dest="client_helper",\ 82 help="Helper mode for the ntlm_auth client. [default: ntlmssp-client-1]") 83 84 parser.add_option("--server-username", dest="server_username",\ 85 help="User name server uses for local auth. [default: foo]") 86 parser.add_option("--server-password", dest="server_password",\ 87 help="Password server uses for local auth. [default: secret]") 88 parser.add_option("--server-domain", dest="server_domain",\ 89 help="Domain server uses for local auth. [default: FOO]") 90 parser.add_option("--server-helper", dest="server_helper",\ 91 help="Helper mode for the ntlm_auth server. [default: squid-2.5-server]") 92 93 parser.add_option("-s", "--configfile", dest="config_file",\ 94 help="Path to smb.conf file. [default:/etc/samba/smb.conf") 95 96 (opts, args) = parser.parse_args() 97 if len(args) != 1: 98 parser.error("Invalid number of arguments.") 99 100 if not os.access(args[0], os.X_OK): 101 parser.error("%s is not executable." % args[0]) 102 103 return (opts, args[0]) 57 """parseCommandLine() -> (opts, ntlm_auth_path) 58 Parse the command line. 59 Return a tuple consisting of the options and the path to ntlm_auth. 60 """ 61 usage = "usage: %prog [options] path/to/ntlm_auth" 62 parser = OptionParser(usage) 63 64 parser.set_defaults(client_username="foo") 65 parser.set_defaults(client_password="secret") 66 parser.set_defaults(client_domain="FOO") 67 parser.set_defaults(client_helper="ntlmssp-client-1") 68 69 parser.set_defaults(server_username="foo") 70 parser.set_defaults(server_password="secret") 71 parser.set_defaults(server_domain="FOO") 72 parser.set_defaults(server_helper="squid-2.5-ntlmssp") 73 parser.set_defaults(config_file="/etc/samba/smb.conf") 74 75 parser.add_option("--client-username", dest="client_username",\ 76 help="User name for the client. [default: foo]") 77 parser.add_option("--client-password", dest="client_password",\ 78 help="Password the client will send. [default: secret]") 79 parser.add_option("--client-domain", dest="client_domain",\ 80 help="Domain the client authenticates for. [default: FOO]") 81 parser.add_option("--client-helper", dest="client_helper",\ 82 help="Helper mode for the ntlm_auth client. [default: ntlmssp-client-1]") 83 parser.add_option("--client-use-cached-creds", dest="client_use_cached_creds",\ 84 help="Use winbindd credentials cache (rather than default username/pw)", action="store_true") 85 86 parser.add_option("--target-hostname", dest="target_hostname",\ 87 help="Target hostname for kerberos") 88 parser.add_option("--target-service", dest="target_service",\ 89 help="Target service for kerberos") 90 91 92 parser.add_option("--server-username", dest="server_username",\ 93 help="User name server uses for local auth. [default: foo]") 94 parser.add_option("--server-password", dest="server_password",\ 95 help="Password server uses for local auth. [default: secret]") 96 parser.add_option("--server-domain", dest="server_domain",\ 97 help="Domain server uses for local auth. [default: FOO]") 98 parser.add_option("--server-helper", dest="server_helper",\ 99 help="Helper mode for the ntlm_auth server. [default: squid-2.5-server]") 100 parser.add_option("--server-use-winbindd", dest="server_use_winbindd",\ 101 help="Use winbindd to check the password (rather than default username/pw)", action="store_true") 102 parser.add_option("--require-membership-of", dest="sid",\ 103 help="Require that the user is a member of this group to authenticate.") 104 105 106 parser.add_option("-s", "--configfile", dest="config_file",\ 107 help="Path to smb.conf file. [default:/etc/samba/smb.conf") 108 109 (opts, args) = parser.parse_args() 110 if len(args) != 1: 111 parser.error("Invalid number of arguments.") 112 113 if not os.access(args[0], os.X_OK): 114 parser.error("%s is not executable." % args[0]) 115 116 return (opts, args[0]) 104 117 105 118 106 119 def main(): 107 """main() -> int 108 Run the test. 109 Returns 0 if test succeeded, <>0 otherwise. 110 """ 111 (opts, ntlm_auth_path) = parseCommandLine() 112 113 (client_in_r, client_in_w) = os.pipe() 114 (client_out_r, client_out_w) = os.pipe() 115 116 client_pid = os.fork() 117 118 if not client_pid: 119 # We're in the client child 120 os.close(0) 121 os.close(1) 122 123 os.dup2(client_out_r, 0) 124 os.close(client_out_r) 125 os.close(client_out_w) 126 127 os.dup2(client_in_w, 1) 128 os.close(client_in_r) 129 os.close(client_in_w) 130 131 client_args = [] 132 client_args.append("--helper-protocol=%s" % opts.client_helper) 133 client_args.append("--username=%s" % opts.client_username) 134 client_args.append("--password=%s" % opts.client_password) 135 client_args.append("--domain=%s" % opts.client_domain) 136 client_args.append("--configfile=%s" % opts.config_file) 137 138 os.execv(ntlm_auth_path, client_args) 139 140 client_in = client_in_r 141 os.close(client_in_w) 142 143 client_out = client_out_w 144 os.close(client_out_r) 145 146 (server_in_r, server_in_w) = os.pipe() 147 (server_out_r, server_out_w) = os.pipe() 148 149 server_pid = os.fork() 150 151 if not server_pid: 152 # We're in the server child 153 os.close(0) 154 os.close(1) 155 156 os.dup2(server_out_r, 0) 157 os.close(server_out_r) 158 os.close(server_out_w) 159 160 os.dup2(server_in_w, 1) 161 os.close(server_in_r) 162 os.close(server_in_w) 163 164 server_args = [] 165 server_args.append("--helper-protocol=%s" % opts.server_helper) 166 server_args.append("--username=%s" % opts.server_username) 167 server_args.append("--password=%s" % opts.server_password) 168 server_args.append("--domain=%s" % opts.server_domain) 169 server_args.append("--configfile=%s" % opts.config_file) 170 171 os.execv(ntlm_auth_path, server_args) 172 173 server_in = server_in_r 174 os.close(server_in_w) 175 176 server_out = server_out_w 177 os.close(server_out_r) 178 179 # We're in the parent 180 writeLine(client_out, "YR") 181 buf = readLine(client_in) 182 183 if buf.count("YR ", 0, 3) != 1: 184 sys.exit(1) 185 186 writeLine(server_out, buf) 187 buf = readLine(server_in) 188 189 if buf.count("TT ", 0, 3) != 1: 190 sys.exit(2) 191 192 writeLine(client_out, buf) 193 buf = readLine(client_in) 194 195 if buf.count("AF ", 0, 3) != 1: 196 sys.exit(3) 197 198 # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>' 199 buf = buf.replace("AF", "KK", 1) 200 201 writeLine(server_out, buf) 202 buf = readLine(server_in) 203 204 if buf.count("AF ", 0, 3) != 1: 205 sys.exit(4) 206 207 os.close(server_in) 208 os.close(server_out) 209 os.close(client_in) 210 os.close(client_out) 211 os.waitpid(server_pid, 0) 212 os.waitpid(client_pid, 0) 213 sys.exit(0) 120 """main() -> int 121 Run the test. 122 Returns 0 if test succeeded, <>0 otherwise. 123 """ 124 (opts, ntlm_auth_path) = parseCommandLine() 125 126 (client_in_r, client_in_w) = os.pipe() 127 (client_out_r, client_out_w) = os.pipe() 128 129 client_pid = os.fork() 130 131 if not client_pid: 132 # We're in the client child 133 os.close(0) 134 os.close(1) 135 136 os.dup2(client_out_r, 0) 137 os.close(client_out_r) 138 os.close(client_out_w) 139 140 os.dup2(client_in_w, 1) 141 os.close(client_in_r) 142 os.close(client_in_w) 143 144 client_args = [] 145 client_args.append("--helper-protocol=%s" % opts.client_helper) 146 client_args.append("--username=%s" % opts.client_username) 147 if opts.client_use_cached_creds: 148 client_args.append("--use-cached-creds") 149 else: 150 client_args.append("--password=%s" % opts.client_password) 151 client_args.append("--domain=%s" % opts.client_domain) 152 client_args.append("--configfile=%s" % opts.config_file) 153 if opts.target_service: 154 client_args.append("--target-service=%s" % opts.target_service) 155 if opts.target_hostname: 156 client_args.append("--target-hostname=%s" % opts.target_hostname) 157 158 os.execv(ntlm_auth_path, client_args) 159 160 client_in = client_in_r 161 os.close(client_in_w) 162 163 client_out = client_out_w 164 os.close(client_out_r) 165 166 (server_in_r, server_in_w) = os.pipe() 167 (server_out_r, server_out_w) = os.pipe() 168 169 server_pid = os.fork() 170 171 if not server_pid: 172 # We're in the server child 173 os.close(0) 174 os.close(1) 175 176 os.dup2(server_out_r, 0) 177 os.close(server_out_r) 178 os.close(server_out_w) 179 180 os.dup2(server_in_w, 1) 181 os.close(server_in_r) 182 os.close(server_in_w) 183 184 server_args = [] 185 server_args.append("--helper-protocol=%s" % opts.server_helper) 186 if not opts.server_use_winbindd: 187 server_args.append("--username=%s" % opts.server_username) 188 server_args.append("--password=%s" % opts.server_password) 189 server_args.append("--domain=%s" % opts.server_domain) 190 if opts.sid: 191 raise Exception("Server must be using winbindd for require-membership-of.") 192 else: 193 if opts.sid: 194 server_args.append("--require-membership-of=%s" % opts.sid) 195 196 server_args.append("--configfile=%s" % opts.config_file) 197 198 os.execv(ntlm_auth_path, server_args) 199 200 server_in = server_in_r 201 os.close(server_in_w) 202 203 server_out = server_out_w 204 os.close(server_out_r) 205 206 if opts.client_helper == "ntlmssp-client-1" and opts.server_helper == "squid-2.5-ntlmssp": 207 208 # We're in the parent 209 writeLine(client_out, "YR") 210 buf = readLine(client_in) 211 212 if buf.count("YR ", 0, 3) != 1: 213 sys.exit(1) 214 215 writeLine(server_out, buf) 216 buf = readLine(server_in) 217 218 if buf.count("TT ", 0, 3) != 1: 219 sys.exit(2) 220 221 writeLine(client_out, buf) 222 buf = readLine(client_in) 223 224 if buf.count("AF ", 0, 3) != 1: 225 sys.exit(3) 226 227 # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>' 228 buf = buf.replace("AF", "KK", 1) 229 230 writeLine(server_out, buf) 231 buf = readLine(server_in) 232 233 if buf.count("AF ", 0, 3) != 1: 234 sys.exit(4) 235 236 237 elif opts.client_helper == "ntlmssp-client-1" and opts.server_helper == "gss-spnego": 238 # We're in the parent 239 writeLine(client_out, "YR") 240 buf = readLine(client_in) 241 242 if buf.count("YR ", 0, 3) != 1: 243 sys.exit(1) 244 245 writeLine(server_out, buf) 246 buf = readLine(server_in) 247 248 if buf.count("TT ", 0, 3) != 1: 249 sys.exit(2) 250 251 writeLine(client_out, buf) 252 buf = readLine(client_in) 253 254 if buf.count("AF ", 0, 3) != 1: 255 sys.exit(3) 256 257 # Client sends 'AF <base64 blob>' but server expects 'KK <abse64 blob>' 258 buf = buf.replace("AF", "KK", 1) 259 260 writeLine(server_out, buf) 261 buf = readLine(server_in) 262 263 if buf.count("AF * ", 0, 5) != 1: 264 sys.exit(4) 265 266 267 elif opts.client_helper == "gss-spnego-client" and opts.server_helper == "gss-spnego": 268 # We're in the parent 269 writeLine(server_out, "YR") 270 buf = readLine(server_in) 271 272 while True: 273 if buf.count("AF ", 0, 3) != 1 and buf.count("TT ", 0, 3) != 1: 274 sys.exit(1) 275 276 writeLine(client_out, buf) 277 buf = readLine(client_in) 278 279 if buf.count("AF", 0, 2) == 1: 280 break 281 282 if buf.count("AF ", 0, 5) != 1 and buf.count("KK ", 0, 3) != 1 and buf.count("TT ", 0, 3) != 1: 283 sys.exit(2) 284 285 writeLine(server_out, buf) 286 buf = readLine(server_in) 287 288 if buf.count("AF * ", 0, 5) == 1: 289 break 290 291 else: 292 sys.exit(5) 293 294 if opts.client_helper == "ntlmssp-client-1": 295 writeLine(client_out, "GK") 296 buf = readLine(client_in) 297 298 if buf.count("GK ", 0, 3) != 1: 299 sys.exit(4) 300 301 writeLine(client_out, "GF") 302 buf = readLine(client_in) 303 304 if buf.count("GF ", 0, 3) != 1: 305 sys.exit(4) 306 307 if opts.server_helper == "squid-2.5-ntlmssp": 308 writeLine(server_out, "GK") 309 buf = readLine(server_in) 310 311 if buf.count("GK ", 0, 3) != 1: 312 sys.exit(4) 313 314 writeLine(server_out, "GF") 315 buf = readLine(server_in) 316 317 if buf.count("GF ", 0, 3) != 1: 318 sys.exit(4) 319 320 os.close(server_in) 321 os.close(server_out) 322 os.close(client_in) 323 os.close(client_out) 324 os.waitpid(server_pid, 0) 325 os.waitpid(client_pid, 0) 326 sys.exit(0) 214 327 215 328 if __name__ == "__main__": 216 217 218 329 main() 330 331 -
vendor/current/source3/torture/test_posix_append.c
r740 r988 34 34 NTSTATUS status; 35 35 uint16_t fnum; 36 SMB_OFF_Tsize;36 off_t size; 37 37 uint8_t c = '\0'; 38 38 bool ret = false; … … 58 58 FILE_OVERWRITE_IF, 59 59 FILE_NON_DIRECTORY_FILE|FILE_DELETE_ON_CLOSE, 60 0, &fnum );60 0, &fnum, NULL); 61 61 62 62 if (!NT_STATUS_IS_OK(status)) { -
vendor/current/source3/torture/torture.c
r746 r988 27 27 #include "tldap_util.h" 28 28 #include "../librpc/gen_ndr/svcctl.h" 29 #include " memcache.h"29 #include "../lib/util/memcache.h" 30 30 #include "nsswitch/winbind_client.h" 31 #include "dbwrap.h" 31 #include "dbwrap/dbwrap.h" 32 #include "dbwrap/dbwrap_open.h" 33 #include "dbwrap/dbwrap_rbt.h" 32 34 #include "talloc_dict.h" 33 35 #include "async_smb.h" … … 38 40 #include "../lib/util/tevent_ntstatus.h" 39 41 #include "util_tdb.h" 42 #include "../libcli/smb/read_smb.h" 43 #include "../libcli/smb/smbXcli_base.h" 44 #include "lib/util/sys_rw_data.h" 40 45 41 46 extern char *optarg; 42 47 extern int optind; 43 48 44 static fstring host, workgroup, share, password, username, myname; 45 static int max_protocol = PROTOCOL_NT1; 49 fstring host, workgroup, share, password, username, myname; 46 50 static const char *sockops="TCP_NODELAY"; 47 static intnprocs=1;51 int torture_nprocs=1; 48 52 static int port_to_use=0; 49 53 int torture_numops=100; … … 55 59 static bool use_level_II_oplocks; 56 60 static const char *client_txt = "client_oplocks.txt"; 61 static bool disable_spnego; 57 62 static bool use_kerberos; 63 static bool force_dos_errors; 58 64 static fstring multishare_conn_fname; 59 65 static bool use_multishare_conn = False; 60 66 static bool do_encrypt; 61 67 static const char *local_path = NULL; 62 static int signing_state = Undefined; 68 static enum smb_signing_setting signing_state = SMB_SIGNING_DEFAULT; 69 char *test_filename; 63 70 64 71 bool torture_showall = False; 65 72 66 73 static double create_procs(bool (*fn)(int), bool *result); 67 68 69 /* return a pointer to a anonymous shared memory segment of size "size"70 which will persist across fork() but will disappear when all processes71 exit72 73 The memory is not zeroed74 75 This function uses system5 shared memory. It takes advantage of a property76 that the memory is not destroyed if it is attached when the id is removed77 */78 void *shm_setup(int size)79 {80 int shmid;81 void *ret;82 83 #ifdef __QNXNTO__84 shmid = shm_open("private", O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);85 if (shmid == -1) {86 printf("can't get shared memory\n");87 exit(1);88 }89 shm_unlink("private");90 if (ftruncate(shmid, size) == -1) {91 printf("can't set shared memory size\n");92 exit(1);93 }94 ret = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, shmid, 0);95 if (ret == MAP_FAILED) {96 printf("can't map shared memory\n");97 exit(1);98 }99 #else100 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);101 if (shmid == -1) {102 printf("can't get shared memory\n");103 exit(1);104 }105 ret = (void *)shmat(shmid, 0, 0);106 if (!ret || ret == (void *)-1) {107 printf("can't attach to shared memory\n");108 return NULL;109 }110 /* the following releases the ipc, but note that this process111 and all its children will still have access to the memory, its112 just that the shmid is no longer valid for other shm calls. This113 means we don't leave behind lots of shm segments after we exit114 115 See Stevens "advanced programming in unix env" for details116 */117 shmctl(shmid, IPC_RMID, 0);118 #endif119 120 return ret;121 }122 74 123 75 /******************************************************************** … … 128 80 const char *sharename) 129 81 { 130 uint16 major, minor;131 uint32 caplow, caphigh;82 uint16_t major, minor; 83 uint32_t caplow, caphigh; 132 84 NTSTATUS status; 133 85 … … 177 129 static struct cli_state *open_nbt_connection(void) 178 130 { 179 struct nmb_name called, calling;180 struct sockaddr_storage ss;181 131 struct cli_state *c; 182 132 NTSTATUS status; 183 184 make_nmb_name(&calling, myname, 0x0); 185 make_nmb_name(&called , host, 0x20); 186 187 zero_sockaddr(&ss); 188 189 if (!(c = cli_initialise_ex(signing_state))) { 190 printf("Failed initialize cli_struct to connect with %s\n", host); 191 return NULL; 192 } 193 194 c->port = port_to_use; 195 196 status = cli_connect(c, host, &ss); 133 int flags = 0; 134 135 if (disable_spnego) { 136 flags |= CLI_FULL_CONNECTION_DONT_SPNEGO; 137 } 138 139 if (use_oplocks) { 140 flags |= CLI_FULL_CONNECTION_OPLOCKS; 141 } 142 143 if (use_level_II_oplocks) { 144 flags |= CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS; 145 } 146 147 if (use_kerberos) { 148 flags |= CLI_FULL_CONNECTION_USE_KERBEROS; 149 } 150 151 if (force_dos_errors) { 152 flags |= CLI_FULL_CONNECTION_FORCE_DOS_ERRORS; 153 } 154 155 status = cli_connect_nb(host, NULL, port_to_use, 0x20, myname, 156 signing_state, flags, &c); 197 157 if (!NT_STATUS_IS_OK(status)) { 198 158 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) ); … … 200 160 } 201 161 202 c->use_kerberos = use_kerberos; 203 204 c->timeout = 120000; /* set a really long timeout (2 minutes) */ 205 if (use_oplocks) c->use_oplocks = True; 206 if (use_level_II_oplocks) c->use_level_II_oplocks = True; 207 208 if (!cli_session_request(c, &calling, &called)) { 209 /* 210 * Well, that failed, try *SMBSERVER ... 211 * However, we must reconnect as well ... 212 */ 213 status = cli_connect(c, host, &ss); 214 if (!NT_STATUS_IS_OK(status)) { 215 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) ); 216 return NULL; 217 } 218 219 make_nmb_name(&called, "*SMBSERVER", 0x20); 220 if (!cli_session_request(c, &calling, &called)) { 221 printf("%s rejected the session\n",host); 222 printf("We tried with a called name of %s & %s\n", 223 host, "*SMBSERVER"); 224 cli_shutdown(c); 225 return NULL; 226 } 227 } 162 cli_set_timeout(c, 120000); /* set a really long timeout (2 minutes) */ 228 163 229 164 return c; … … 234 169 ****************************************************************************/ 235 170 236 static bool cli_bad_session_request( struct cli_state *cli,171 static bool cli_bad_session_request(int fd, 237 172 struct nmb_name *calling, struct nmb_name *called) 238 173 { 239 char *p; 240 int len = 4; 241 int namelen = 0; 242 char *tmp; 243 244 memcpy(&(cli->calling), calling, sizeof(*calling)); 245 memcpy(&(cli->called ), called , sizeof(*called )); 246 247 /* put in the destination name */ 248 249 tmp = name_mangle(talloc_tos(), cli->called.name, 250 cli->called.name_type); 251 if (tmp == NULL) { 252 return false; 253 } 254 255 p = cli->outbuf+len; 256 namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp)); 257 if (namelen > 0) { 258 memcpy(p, tmp, namelen); 259 len += namelen; 260 } 261 TALLOC_FREE(tmp); 174 TALLOC_CTX *frame; 175 uint8_t len_buf[4]; 176 struct iovec iov[3]; 177 ssize_t len; 178 uint8_t *inbuf; 179 int err; 180 bool ret = false; 181 uint8_t message_type; 182 uint8_t error; 183 struct tevent_context *ev; 184 struct tevent_req *req; 185 186 frame = talloc_stackframe(); 187 188 iov[0].iov_base = len_buf; 189 iov[0].iov_len = sizeof(len_buf); 190 191 /* put in the destination name */ 192 193 iov[1].iov_base = name_mangle(talloc_tos(), called->name, 194 called->name_type); 195 if (iov[1].iov_base == NULL) { 196 goto fail; 197 } 198 iov[1].iov_len = name_len((unsigned char *)iov[1].iov_base, 199 talloc_get_size(iov[1].iov_base)); 200 201 /* and my name */ 202 203 iov[2].iov_base = name_mangle(talloc_tos(), calling->name, 204 calling->name_type); 205 if (iov[2].iov_base == NULL) { 206 goto fail; 207 } 208 iov[2].iov_len = name_len((unsigned char *)iov[2].iov_base, 209 talloc_get_size(iov[2].iov_base)); 262 210 263 211 /* Deliberately corrupt the name len (first byte) */ 264 *p = 100; 265 266 /* and my name */ 267 268 tmp = name_mangle(talloc_tos(), cli->calling.name, 269 cli->calling.name_type); 270 if (tmp == NULL) { 271 return false; 272 } 273 274 p = cli->outbuf+len; 275 namelen = name_len((unsigned char *)tmp, talloc_get_size(tmp)); 276 if (namelen > 0) { 277 memcpy(p, tmp, namelen); 278 len += namelen; 279 } 280 TALLOC_FREE(tmp); 281 /* Deliberately corrupt the name len (first byte) */ 282 *p = 100; 283 284 /* send a session request (RFC 1002) */ 285 /* setup the packet length 212 *((uint8_t *)iov[2].iov_base) = 100; 213 214 /* send a session request (RFC 1002) */ 215 /* setup the packet length 286 216 * Remove four bytes from the length count, since the length 287 217 * field in the NBT Session Service header counts the number … … 290 220 * CRH. 291 221 */ 292 len -= 4; 293 _smb_setlen(cli->outbuf,len); 294 SCVAL(cli->outbuf,0,0x81); 295 296 cli_send_smb(cli); 297 DEBUG(5,("Sent session request\n")); 298 299 if (!cli_receive_smb(cli)) 300 return False; 301 302 if (CVAL(cli->inbuf,0) != 0x82) { 303 /* This is the wrong place to put the error... JRA. */ 304 cli->rap_error = CVAL(cli->inbuf,4); 305 return False; 222 223 _smb_setlen(len_buf, iov[1].iov_len + iov[2].iov_len); 224 SCVAL(len_buf,0,0x81); 225 226 len = write_data_iov(fd, iov, 3); 227 if (len == -1) { 228 goto fail; 229 } 230 231 ev = samba_tevent_context_init(frame); 232 if (ev == NULL) { 233 goto fail; 234 } 235 req = read_smb_send(frame, ev, fd); 236 if (req == NULL) { 237 goto fail; 238 } 239 if (!tevent_req_poll(req, ev)) { 240 goto fail; 241 } 242 len = read_smb_recv(req, talloc_tos(), &inbuf, &err); 243 if (len == -1) { 244 errno = err; 245 goto fail; 246 } 247 TALLOC_FREE(ev); 248 249 message_type = CVAL(inbuf, 0); 250 if (message_type != 0x83) { 251 d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n", 252 message_type); 253 goto fail; 306 254 } 307 return(True); 308 } 309 310 static struct cli_state *open_bad_nbt_connection(void) 311 { 312 struct nmb_name called, calling; 313 struct sockaddr_storage ss; 314 struct cli_state *c; 315 NTSTATUS status; 316 317 make_nmb_name(&calling, myname, 0x0); 318 make_nmb_name(&called , host, 0x20); 319 320 zero_sockaddr(&ss); 321 322 if (!(c = cli_initialise_ex(signing_state))) { 323 printf("Failed initialize cli_struct to connect with %s\n", host); 324 return NULL; 325 } 326 327 c->port = 139; 328 329 status = cli_connect(c, host, &ss); 330 if (!NT_STATUS_IS_OK(status)) { 331 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) ); 332 return NULL; 333 } 334 335 c->timeout = 4000; /* set a short timeout (4 seconds) */ 336 337 if (!cli_bad_session_request(c, &calling, &called)) { 338 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) ); 339 return NULL; 340 } 341 342 return c; 343 } 344 255 256 if (smb_len(inbuf) != 1) { 257 d_fprintf(stderr, "Expected smb_len 1, got %d\n", 258 (int)smb_len(inbuf)); 259 goto fail; 260 } 261 262 error = CVAL(inbuf, 4); 263 if (error != 0x82) { 264 d_fprintf(stderr, "Expected error 0x82, got %d\n", 265 (int)error); 266 goto fail; 267 } 268 269 ret = true; 270 fail: 271 TALLOC_FREE(frame); 272 return ret; 273 } 345 274 346 275 /* Insert a NULL at the first separator of the given path and return a pointer … … 427 356 } 428 357 429 (*c)->timeout = 120000; /* set a really long timeout (2 minutes) */358 cli_set_timeout(*c, 120000); /* set a really long timeout (2 minutes) */ 430 359 431 360 if (do_encrypt) { … … 468 397 } 469 398 470 bool torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid) 471 { 472 uint16 old_vuid = cli->vuid; 473 fstring old_user_name; 399 bool torture_init_connection(struct cli_state **pcli) 400 { 401 struct cli_state *cli; 402 403 cli = open_nbt_connection(); 404 if (cli == NULL) { 405 return false; 406 } 407 408 *pcli = cli; 409 return true; 410 } 411 412 bool torture_cli_session_setup2(struct cli_state *cli, uint16_t *new_vuid) 413 { 414 uint16_t old_vuid = cli_state_get_uid(cli); 474 415 size_t passlen = strlen(password); 475 416 NTSTATUS status; 476 417 bool ret; 477 418 478 fstrcpy(old_user_name, cli->user_name); 479 cli->vuid = 0; 480 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username, 481 password, passlen, 482 password, passlen, 483 workgroup)); 484 *new_vuid = cli->vuid; 485 cli->vuid = old_vuid; 486 status = cli_set_username(cli, old_user_name); 487 if (!NT_STATUS_IS_OK(status)) { 488 return false; 489 } 419 cli_state_set_uid(cli, 0); 420 status = cli_session_setup(cli, username, 421 password, passlen, 422 password, passlen, 423 workgroup); 424 ret = NT_STATUS_IS_OK(status); 425 *new_vuid = cli_state_get_uid(cli); 426 cli_state_set_uid(cli, old_vuid); 490 427 return ret; 491 428 } … … 509 446 510 447 448 /* check if the server produced the expected dos or nt error code */ 449 static bool check_both_error(int line, NTSTATUS status, 450 uint8_t eclass, uint32_t ecode, NTSTATUS nterr) 451 { 452 if (NT_STATUS_IS_DOS(status)) { 453 uint8_t cclass; 454 uint32_t num; 455 456 /* Check DOS error */ 457 cclass = NT_STATUS_DOS_CLASS(status); 458 num = NT_STATUS_DOS_CODE(status); 459 460 if (eclass != cclass || ecode != num) { 461 printf("unexpected error code class=%d code=%d\n", 462 (int)cclass, (int)num); 463 printf(" expected %d/%d %s (line=%d)\n", 464 (int)eclass, (int)ecode, nt_errstr(nterr), line); 465 return false; 466 } 467 } else { 468 /* Check NT error */ 469 if (!NT_STATUS_EQUAL(nterr, status)) { 470 printf("unexpected error code %s\n", 471 nt_errstr(status)); 472 printf(" expected %s (line=%d)\n", 473 nt_errstr(nterr), line); 474 return false; 475 } 476 } 477 478 return true; 479 } 480 481 511 482 /* check if the server produced the expected error code */ 512 static bool check_error(int line, struct cli_state *c,513 uint8 eclass, uint32ecode, NTSTATUS nterr)514 { 515 if (cli_is_dos_error(c)) {516 uint8 cclass;517 uint32 num;483 static bool check_error(int line, NTSTATUS status, 484 uint8_t eclass, uint32_t ecode, NTSTATUS nterr) 485 { 486 if (NT_STATUS_IS_DOS(status)) { 487 uint8_t cclass; 488 uint32_t num; 518 489 519 490 /* Check DOS error */ 520 491 521 cli_dos_error(c, &cclass, &num); 492 cclass = NT_STATUS_DOS_CLASS(status); 493 num = NT_STATUS_DOS_CODE(status); 522 494 523 495 if (eclass != cclass || ecode != num) { … … 525 497 (int)cclass, (int)num); 526 498 printf(" expected %d/%d %s (line=%d)\n", 527 (int)eclass, (int)ecode, nt_errstr(nterr), line); 499 (int)eclass, (int)ecode, nt_errstr(nterr), 500 line); 528 501 return False; 529 502 } 530 503 531 504 } else { 532 NTSTATUS status;533 534 505 /* Check NT error */ 535 506 536 status = cli_nt_error(c);537 538 507 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) { 539 printf("unexpected error code %s\n", nt_errstr(status)); 540 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line); 508 printf("unexpected error code %s\n", 509 nt_errstr(status)); 510 printf(" expected %s (line=%d)\n", nt_errstr(nterr), 511 line); 541 512 return False; 542 513 } … … 547 518 548 519 549 static bool wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len) 550 { 551 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) { 552 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; 553 } 554 return True; 520 static bool wait_lock(struct cli_state *c, int fnum, uint32_t offset, uint32_t len) 521 { 522 NTSTATUS status; 523 524 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK); 525 526 while (!NT_STATUS_IS_OK(status)) { 527 if (!check_both_error(__LINE__, status, ERRDOS, 528 ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) { 529 return false; 530 } 531 532 status = cli_lock32(c, fnum, offset, len, -1, WRITE_LOCK); 533 } 534 535 return true; 555 536 } 556 537 … … 566 547 char buf[1024]; 567 548 bool correct = True; 549 size_t nread = 0; 568 550 NTSTATUS status; 569 551 570 552 memset(buf, '\0', sizeof(buf)); 571 553 572 status = cli_open (c, lockfname, O_RDWR | O_CREAT | O_EXCL,554 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 573 555 DENY_NONE, &fnum2); 574 556 if (!NT_STATUS_IS_OK(status)) { 575 status = cli_open(c, lockfname, O_RDWR, DENY_NONE, &fnum2); 576 } 577 if (!NT_STATUS_IS_OK(status)) { 578 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c)); 557 status = cli_openx(c, lockfname, O_RDWR, DENY_NONE, &fnum2); 558 } 559 if (!NT_STATUS_IS_OK(status)) { 560 printf("open of %s failed (%s)\n", 561 lockfname, nt_errstr(status)); 579 562 return False; 580 563 } … … 592 575 } 593 576 594 if (!NT_STATUS_IS_OK(cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL, &fnum))) { 595 printf("open failed (%s)\n", cli_errstr(c)); 577 status = cli_openx(c, fname, O_RDWR | O_CREAT | O_TRUNC, 578 DENY_ALL, &fnum); 579 if (!NT_STATUS_IS_OK(status)) { 580 printf("open failed (%s)\n", nt_errstr(status)); 596 581 correct = False; 597 582 break; … … 618 603 pid2 = 0; 619 604 620 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) { 621 printf("read failed (%s)\n", cli_errstr(c)); 622 correct = False; 605 status = cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid), 606 &nread); 607 if (!NT_STATUS_IS_OK(status)) { 608 printf("read failed (%s)\n", nt_errstr(status)); 609 correct = false; 610 } else if (nread != sizeof(pid)) { 611 printf("read/write compare failed: " 612 "recv %ld req %ld\n", (unsigned long)nread, 613 (unsigned long)sizeof(pid)); 614 correct = false; 623 615 } 624 616 … … 628 620 } 629 621 630 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) { 631 printf("close failed (%s)\n", cli_errstr(c)); 622 status = cli_close(c, fnum); 623 if (!NT_STATUS_IS_OK(status)) { 624 printf("close failed (%s)\n", nt_errstr(status)); 632 625 correct = False; 633 626 } 634 627 635 if (!NT_STATUS_IS_OK(cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 636 printf("unlink failed (%s)\n", cli_errstr(c)); 628 status = cli_unlink(c, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 629 if (!NT_STATUS_IS_OK(status)) { 630 printf("unlink failed (%s)\n", nt_errstr(status)); 637 631 correct = False; 638 632 } 639 633 640 if (!NT_STATUS_IS_OK(cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)))) { 641 printf("unlock failed (%s)\n", cli_errstr(c)); 634 status = cli_unlock(c, fnum2, n*sizeof(int), sizeof(int)); 635 if (!NT_STATUS_IS_OK(status)) { 636 printf("unlock failed (%s)\n", nt_errstr(status)); 642 637 correct = False; 643 638 } … … 659 654 cli = current_cli; 660 655 661 cli_sockopt(cli, sockops);656 smbXcli_conn_set_sockopt(cli->conn, sockops); 662 657 663 658 ret = rw_torture(cli); … … 678 673 unsigned count; 679 674 unsigned countprev = 0; 680 s size_t sent = 0;675 size_t sent = 0; 681 676 bool correct = True; 682 677 NTSTATUS status = NT_STATUS_OK; 683 678 684 679 srandom(1); 685 for (i = 0; i < sizeof(buf); i += sizeof(uint32 ))680 for (i = 0; i < sizeof(buf); i += sizeof(uint32_t)) 686 681 { 687 682 SIVAL(buf, i, sys_random()); … … 690 685 if (procnum == 0) 691 686 { 692 if (!NT_STATUS_IS_OK(cli_unlink(c, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 693 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c)); 694 } 695 696 if (!NT_STATUS_IS_OK(cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 697 DENY_NONE, &fnum))) { 687 status = cli_unlink( 688 c, lockfname, 689 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 690 if (!NT_STATUS_IS_OK(status)) { 691 printf("unlink failed (%s) (normal, this file should " 692 "not exist)\n", nt_errstr(status)); 693 } 694 695 status = cli_openx(c, lockfname, O_RDWR | O_CREAT | O_EXCL, 696 DENY_NONE, &fnum); 697 if (!NT_STATUS_IS_OK(status)) { 698 698 printf("first open read/write of %s failed (%s)\n", 699 lockfname, cli_errstr(c));699 lockfname, nt_errstr(status)); 700 700 return False; 701 701 } … … 705 705 for (i = 0; i < 500 && fnum == (uint16_t)-1; i++) 706 706 { 707 status = cli_open (c, lockfname, O_RDONLY,707 status = cli_openx(c, lockfname, O_RDONLY, 708 708 DENY_NONE, &fnum); 709 if ( !NT_STATUS_IS_OK(status)) {709 if (NT_STATUS_IS_OK(status)) { 710 710 break; 711 711 } … … 714 714 if (!NT_STATUS_IS_OK(status)) { 715 715 printf("second open read-only of %s failed (%s)\n", 716 lockfname, cli_errstr(c));716 lockfname, nt_errstr(status)); 717 717 return False; 718 718 } … … 738 738 739 739 status = cli_writeall(c, fnum, 0, (uint8_t *)buf+count, 740 count, (size_t)sent, NULL);740 count, sent, NULL); 741 741 if (!NT_STATUS_IS_OK(status)) { 742 742 printf("write failed (%s)\n", … … 747 747 else 748 748 { 749 sent = cli_read(c, fnum, buf_rd+count, count, 750 sizeof(buf)-count); 751 if (sent < 0) 752 { 749 status = cli_read(c, fnum, buf_rd+count, count, 750 sizeof(buf)-count, &sent); 751 if(!NT_STATUS_IS_OK(status)) { 753 752 printf("read failed offset:%d size:%ld (%s)\n", 754 753 count, (unsigned long)sizeof(buf)-count, 755 cli_errstr(c));754 nt_errstr(status)); 756 755 correct = False; 757 756 sent = 0; 758 } 759 if (sent > 0) 760 { 757 } else if (sent > 0) { 761 758 if (memcmp(buf_rd+count, buf+count, sent) != 0) 762 759 { … … 771 768 } 772 769 773 if (!NT_STATUS_IS_OK(cli_close(c, fnum))) { 774 printf("close failed (%s)\n", cli_errstr(c)); 770 status = cli_close(c, fnum); 771 if (!NT_STATUS_IS_OK(status)) { 772 printf("close failed (%s)\n", nt_errstr(status)); 775 773 correct = False; 776 774 } … … 788 786 char buf_rd[131072]; 789 787 bool correct = True; 790 ssize_t bytes_read; 791 792 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 793 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1)); 794 } 795 796 if (!NT_STATUS_IS_OK(cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, 797 DENY_NONE, &fnum1))) { 788 size_t bytes_read; 789 NTSTATUS status; 790 791 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 792 if (!NT_STATUS_IS_OK(status)) { 793 printf("unlink failed (%s) (normal, this file should not exist)\n", nt_errstr(status)); 794 } 795 796 status = cli_openx(c1, lockfname, O_RDWR | O_CREAT | O_EXCL, 797 DENY_NONE, &fnum1); 798 if (!NT_STATUS_IS_OK(status)) { 798 799 printf("first open read/write of %s failed (%s)\n", 799 lockfname, cli_errstr(c1)); 800 return False; 801 } 802 if (!NT_STATUS_IS_OK(cli_open(c2, lockfname, O_RDONLY, 803 DENY_NONE, &fnum2))) { 800 lockfname, nt_errstr(status)); 801 return False; 802 } 803 804 status = cli_openx(c2, lockfname, O_RDONLY, DENY_NONE, &fnum2); 805 if (!NT_STATUS_IS_OK(status)) { 804 806 printf("second open read-only of %s failed (%s)\n", 805 lockfname, cli_errstr(c2));807 lockfname, nt_errstr(status)); 806 808 cli_close(c1, fnum1); 807 809 return False; 808 810 } 809 811 810 for (i =0;i<torture_numops;i++)812 for (i = 0; i < torture_numops; i++) 811 813 { 812 NTSTATUS status;813 814 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1; 814 815 if (i % 10 == 0) { … … 826 827 } 827 828 828 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) { 829 printf("read failed (%s)\n", cli_errstr(c2)); 830 printf("read %d, expected %ld\n", (int)bytes_read, 829 status = cli_read(c2, fnum2, buf_rd, 0, buf_size, &bytes_read); 830 if(!NT_STATUS_IS_OK(status)) { 831 printf("read failed (%s)\n", nt_errstr(status)); 832 correct = false; 833 break; 834 } else if (bytes_read != buf_size) { 835 printf("read failed\n"); 836 printf("read %ld, expected %ld\n", 837 (unsigned long)bytes_read, 831 838 (unsigned long)buf_size); 832 839 correct = False; … … 842 849 } 843 850 844 if (!NT_STATUS_IS_OK(cli_close(c2, fnum2))) { 845 printf("close failed (%s)\n", cli_errstr(c2)); 851 status = cli_close(c2, fnum2); 852 if (!NT_STATUS_IS_OK(status)) { 853 printf("close failed (%s)\n", nt_errstr(status)); 846 854 correct = False; 847 855 } 848 if (!NT_STATUS_IS_OK(cli_close(c1, fnum1))) { 849 printf("close failed (%s)\n", cli_errstr(c1)); 856 857 status = cli_close(c1, fnum1); 858 if (!NT_STATUS_IS_OK(status)) { 859 printf("close failed (%s)\n", nt_errstr(status)); 850 860 correct = False; 851 861 } 852 862 853 if (!NT_STATUS_IS_OK(cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 854 printf("unlink failed (%s)\n", cli_errstr(c1)); 863 status = cli_unlink(c1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 864 if (!NT_STATUS_IS_OK(status)) { 865 printf("unlink failed (%s)\n", nt_errstr(status)); 855 866 correct = False; 856 867 } … … 867 878 return False; 868 879 } 869 cli_sockopt(cli1, sockops);870 cli_sockopt(cli2, sockops);880 smbXcli_conn_set_sockopt(cli1->conn, sockops); 881 smbXcli_conn_set_sockopt(cli2->conn, sockops); 871 882 872 883 printf("starting readwritetest\n"); … … 898 909 cli = current_cli; 899 910 900 cli_sockopt(cli, sockops);911 smbXcli_conn_set_sockopt(cli->conn, sockops); 901 912 902 913 printf("run_readwritemulti: fname %s\n", randomfname); … … 910 921 } 911 922 912 static bool run_readwritelarge_internal( int max_xmit_k)923 static bool run_readwritelarge_internal(void) 913 924 { 914 925 static struct cli_state *cli1; 915 926 uint16_t fnum1; 916 927 const char *lockfname = "\\large.dat"; 917 SMB_OFF_Tfsize;928 off_t fsize; 918 929 char buf[126*1024]; 919 930 bool correct = True; 931 NTSTATUS status; 920 932 921 933 if (!torture_open_connection(&cli1, 0)) { 922 934 return False; 923 935 } 924 cli_sockopt(cli1, sockops);936 smbXcli_conn_set_sockopt(cli1->conn, sockops); 925 937 memset(buf,'\0',sizeof(buf)); 926 938 927 cli1->max_xmit = max_xmit_k*1024;928 929 if (signing_state == Required) {930 /* Horrible cheat to force931 multiple signed outstanding932 packets against a Samba server.933 */934 cli1->is_samba = false;935 }936 937 939 printf("starting readwritelarge_internal\n"); 938 940 939 941 cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 940 942 941 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) { 942 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1)); 943 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, 944 DENY_NONE, &fnum1); 945 if (!NT_STATUS_IS_OK(status)) { 946 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status)); 943 947 return False; 944 948 } … … 946 950 cli_writeall(cli1, fnum1, 0, (uint8_t *)buf, 0, sizeof(buf), NULL); 947 951 948 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(949 cli1, fnum1, NULL, &fsize, NULL, NULL,950 NULL, NULL, NULL))) {951 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));952 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, 953 NULL, NULL, NULL); 954 if (!NT_STATUS_IS_OK(status)) { 955 printf("qfileinfo failed (%s)\n", nt_errstr(status)); 952 956 correct = False; 953 957 } … … 962 966 } 963 967 964 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 965 printf("close failed (%s)\n", cli_errstr(cli1)); 968 status = cli_close(cli1, fnum1); 969 if (!NT_STATUS_IS_OK(status)) { 970 printf("close failed (%s)\n", nt_errstr(status)); 966 971 correct = False; 967 972 } 968 973 969 if (!NT_STATUS_IS_OK(cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 970 printf("unlink failed (%s)\n", cli_errstr(cli1)); 974 status = cli_unlink(cli1, lockfname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 975 if (!NT_STATUS_IS_OK(status)) { 976 printf("unlink failed (%s)\n", nt_errstr(status)); 971 977 correct = False; 972 978 } 973 979 974 if (!NT_STATUS_IS_OK(cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE, &fnum1))) {975 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));976 return False;977 }978 979 cli1->max_xmit = 4*1024;980 status = cli_openx(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, 981 DENY_NONE, &fnum1); 982 if (!NT_STATUS_IS_OK(status)) { 983 printf("open read/write of %s failed (%s)\n", lockfname, nt_errstr(status)); 984 return False; 985 } 980 986 981 987 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf), NULL); 982 988 983 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(984 cli1, fnum1, NULL, &fsize, NULL, NULL,985 NULL, NULL, NULL))) {986 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));989 status = cli_qfileinfo_basic(cli1, fnum1, NULL, &fsize, NULL, NULL, 990 NULL, NULL, NULL); 991 if (!NT_STATUS_IS_OK(status)) { 992 printf("qfileinfo failed (%s)\n", nt_errstr(status)); 987 993 correct = False; 988 994 } … … 1012 1018 #endif 1013 1019 1014 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 1015 printf("close failed (%s)\n", cli_errstr(cli1)); 1020 status = cli_close(cli1, fnum1); 1021 if (!NT_STATUS_IS_OK(status)) { 1022 printf("close failed (%s)\n", nt_errstr(status)); 1016 1023 correct = False; 1017 1024 } … … 1025 1032 static bool run_readwritelarge(int dummy) 1026 1033 { 1027 return run_readwritelarge_internal( 128);1034 return run_readwritelarge_internal(); 1028 1035 } 1029 1036 … … 1031 1038 { 1032 1039 bool ret; 1033 signing_state = Required;1034 ret = run_readwritelarge_internal( 2);1035 signing_state = Undefined;1040 signing_state = SMB_SIGNING_REQUIRED; 1041 ret = run_readwritelarge_internal(); 1042 signing_state = SMB_SIGNING_DEFAULT; 1036 1043 return ret; 1037 1044 } … … 1057 1064 nbio_id = client; 1058 1065 1059 cli_sockopt(cli, sockops);1066 smbXcli_conn_set_sockopt(cli->conn, sockops); 1060 1067 1061 1068 nb_setup(cli); … … 1146 1153 bool correct = True; 1147 1154 1148 nbio_shmem( nprocs);1155 nbio_shmem(torture_nprocs); 1149 1156 1150 1157 nbio_id = -1; … … 1175 1182 time_t t1, t2; 1176 1183 unsigned lock_timeout; 1184 NTSTATUS status; 1177 1185 1178 1186 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) { 1179 1187 return False; 1180 1188 } 1181 cli_sockopt(cli1, sockops);1182 cli_sockopt(cli2, sockops);1189 smbXcli_conn_set_sockopt(cli1->conn, sockops); 1190 smbXcli_conn_set_sockopt(cli2->conn, sockops); 1183 1191 1184 1192 printf("starting locktest1\n"); … … 1186 1194 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1187 1195 1188 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 1189 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 1190 return False; 1191 } 1192 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum2))) { 1193 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1)); 1194 return False; 1195 } 1196 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum3))) { 1197 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2)); 1198 return False; 1199 } 1200 1201 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { 1202 printf("lock1 failed (%s)\n", cli_errstr(cli1)); 1203 return False; 1204 } 1205 1206 1207 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { 1196 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 1197 &fnum1); 1198 if (!NT_STATUS_IS_OK(status)) { 1199 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 1200 return False; 1201 } 1202 1203 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum2); 1204 if (!NT_STATUS_IS_OK(status)) { 1205 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status)); 1206 return False; 1207 } 1208 1209 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum3); 1210 if (!NT_STATUS_IS_OK(status)) { 1211 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status)); 1212 return False; 1213 } 1214 1215 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK); 1216 if (!NT_STATUS_IS_OK(status)) { 1217 printf("lock1 failed (%s)\n", nt_errstr(status)); 1218 return false; 1219 } 1220 1221 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK); 1222 if (NT_STATUS_IS_OK(status)) { 1208 1223 printf("lock2 succeeded! This is a locking bug\n"); 1209 return False;1224 return false; 1210 1225 } else { 1211 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 1212 NT_STATUS_LOCK_NOT_GRANTED)) return False; 1213 } 1214 1226 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1227 NT_STATUS_LOCK_NOT_GRANTED)) { 1228 return false; 1229 } 1230 } 1215 1231 1216 1232 lock_timeout = (1 + (random() % 20)); 1217 1233 printf("Testing lock timeout with timeout=%u\n", lock_timeout); 1218 1234 t1 = time(NULL); 1219 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) { 1235 status = cli_lock32(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK); 1236 if (NT_STATUS_IS_OK(status)) { 1220 1237 printf("lock3 succeeded! This is a locking bug\n"); 1221 return False;1238 return false; 1222 1239 } else { 1223 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 1224 NT_STATUS_FILE_LOCK_CONFLICT)) return False; 1240 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1241 NT_STATUS_FILE_LOCK_CONFLICT)) { 1242 return false; 1243 } 1225 1244 } 1226 1245 t2 = time(NULL); … … 1233 1252 (unsigned int)(t2-t1), lock_timeout); 1234 1253 1235 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) { 1236 printf("close1 failed (%s)\n", cli_errstr(cli1)); 1237 return False; 1238 } 1239 1240 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) { 1254 status = cli_close(cli1, fnum2); 1255 if (!NT_STATUS_IS_OK(status)) { 1256 printf("close1 failed (%s)\n", nt_errstr(status)); 1257 return False; 1258 } 1259 1260 status = cli_lock32(cli2, fnum3, 0, 4, 0, WRITE_LOCK); 1261 if (NT_STATUS_IS_OK(status)) { 1241 1262 printf("lock4 succeeded! This is a locking bug\n"); 1242 return False;1263 return false; 1243 1264 } else { 1244 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock, 1245 NT_STATUS_FILE_LOCK_CONFLICT)) return False; 1246 } 1247 1248 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 1249 printf("close2 failed (%s)\n", cli_errstr(cli1)); 1250 return False; 1251 } 1252 1253 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum3))) { 1254 printf("close3 failed (%s)\n", cli_errstr(cli2)); 1255 return False; 1256 } 1257 1258 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 1259 printf("unlink failed (%s)\n", cli_errstr(cli1)); 1265 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1266 NT_STATUS_FILE_LOCK_CONFLICT)) { 1267 return false; 1268 } 1269 } 1270 1271 status = cli_close(cli1, fnum1); 1272 if (!NT_STATUS_IS_OK(status)) { 1273 printf("close2 failed (%s)\n", nt_errstr(status)); 1274 return False; 1275 } 1276 1277 status = cli_close(cli2, fnum3); 1278 if (!NT_STATUS_IS_OK(status)) { 1279 printf("close3 failed (%s)\n", nt_errstr(status)); 1280 return False; 1281 } 1282 1283 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1284 if (!NT_STATUS_IS_OK(status)) { 1285 printf("unlink failed (%s)\n", nt_errstr(status)); 1260 1286 return False; 1261 1287 } … … 1282 1308 static struct cli_state *cli; 1283 1309 const char *fname = "\\tcontest.tmp"; 1284 uint16 fnum1;1285 uint16 cnum1, cnum2, cnum3;1286 uint16 vuid1, vuid2;1310 uint16_t fnum1; 1311 uint16_t cnum1, cnum2, cnum3; 1312 uint16_t vuid1, vuid2; 1287 1313 char buf[4]; 1288 1314 bool ret = True; … … 1294 1320 return False; 1295 1321 } 1296 cli_sockopt(cli, sockops);1322 smbXcli_conn_set_sockopt(cli->conn, sockops); 1297 1323 1298 1324 printf("starting tcontest\n"); … … 1300 1326 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1301 1327 1302 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 1303 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 1304 return False; 1305 } 1306 1307 cnum1 = cli->cnum; 1308 vuid1 = cli->vuid; 1328 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 1329 if (!NT_STATUS_IS_OK(status)) { 1330 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 1331 return False; 1332 } 1333 1334 cnum1 = cli_state_get_tid(cli); 1335 vuid1 = cli_state_get_uid(cli); 1309 1336 1310 1337 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL); … … 1314 1341 } 1315 1342 1316 status = cli_t con_andx(cli, share, "?????",1317 1343 status = cli_tree_connect(cli, share, "?????", 1344 password, strlen(password)+1); 1318 1345 if (!NT_STATUS_IS_OK(status)) { 1319 1346 printf("%s refused 2nd tree connect (%s)\n", host, … … 1323 1350 } 1324 1351 1325 cnum2 = cli ->cnum;1352 cnum2 = cli_state_get_tid(cli); 1326 1353 cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */ 1327 vuid2 = cli ->vuid+ 1;1354 vuid2 = cli_state_get_uid(cli) + 1; 1328 1355 1329 1356 /* try a write with the wrong tid */ 1330 cli ->cnum = cnum2;1357 cli_state_set_tid(cli, cnum2); 1331 1358 1332 1359 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL); … … 1341 1368 1342 1369 /* try a write with an invalid tid */ 1343 cli ->cnum = cnum3;1370 cli_state_set_tid(cli, cnum3); 1344 1371 1345 1372 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL); … … 1353 1380 1354 1381 /* try a write with an invalid vuid */ 1355 cli ->vuid = vuid2;1356 cli ->cnum = cnum1;1382 cli_state_set_uid(cli, vuid2); 1383 cli_state_set_tid(cli, cnum1); 1357 1384 1358 1385 status = cli_writeall(cli, fnum1, 0, (uint8_t *)buf, 130, 4, NULL); … … 1365 1392 } 1366 1393 1367 cli->cnum = cnum1; 1368 cli->vuid = vuid1; 1369 1370 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) { 1371 printf("close failed (%s)\n", cli_errstr(cli)); 1372 return False; 1373 } 1374 1375 cli->cnum = cnum2; 1394 cli_state_set_tid(cli, cnum1); 1395 cli_state_set_uid(cli, vuid1); 1396 1397 status = cli_close(cli, fnum1); 1398 if (!NT_STATUS_IS_OK(status)) { 1399 printf("close failed (%s)\n", nt_errstr(status)); 1400 return False; 1401 } 1402 1403 cli_state_set_tid(cli, cnum2); 1376 1404 1377 1405 status = cli_tdis(cli); … … 1381 1409 } 1382 1410 1383 cli ->cnum = cnum1;1411 cli_state_set_tid(cli, cnum1); 1384 1412 1385 1413 if (!torture_close_connection(cli)) { … … 1397 1425 { 1398 1426 static struct cli_state *cli; 1399 uint16 cnum, max_xmit;1427 uint16_t cnum, max_xmit; 1400 1428 char *service; 1401 1429 NTSTATUS status; … … 1404 1432 return False; 1405 1433 } 1406 cli_sockopt(cli, sockops);1434 smbXcli_conn_set_sockopt(cli->conn, sockops); 1407 1435 1408 1436 printf("starting tcon2 test\n"); … … 1439 1467 bool ret; 1440 1468 1441 status = cli_t con_andx(cli, myshare, devtype,1442 1469 status = cli_tree_connect(cli, myshare, devtype, 1470 password, strlen(password)+1); 1443 1471 1444 1472 if (NT_STATUS_IS_OK(expected_error)) { … … 1467 1495 ret = False; 1468 1496 } else { 1469 if (NT_STATUS_EQUAL(cli_nt_error(cli), 1470 expected_error)) { 1497 if (NT_STATUS_EQUAL(status, expected_error)) { 1471 1498 ret = True; 1472 1499 } else { … … 1556 1583 uint16_t fnum1, fnum2, fnum3; 1557 1584 bool correct = True; 1585 NTSTATUS status; 1558 1586 1559 1587 if (!torture_open_connection(&cli, 0)) { … … 1561 1589 } 1562 1590 1563 cli_sockopt(cli, sockops);1591 smbXcli_conn_set_sockopt(cli->conn, sockops); 1564 1592 1565 1593 printf("starting locktest2\n"); … … 1569 1597 cli_setpid(cli, 1); 1570 1598 1571 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 1572 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 1573 return False; 1574 } 1575 1576 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum2))) { 1577 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli)); 1599 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 1600 if (!NT_STATUS_IS_OK(status)) { 1601 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 1602 return False; 1603 } 1604 1605 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum2); 1606 if (!NT_STATUS_IS_OK(status)) { 1607 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status)); 1578 1608 return False; 1579 1609 } … … 1581 1611 cli_setpid(cli, 2); 1582 1612 1583 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum3))) { 1584 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli)); 1613 status = cli_openx(cli, fname, O_RDWR, DENY_NONE, &fnum3); 1614 if (!NT_STATUS_IS_OK(status)) { 1615 printf("open3 of %s failed (%s)\n", fname, nt_errstr(status)); 1585 1616 return False; 1586 1617 } … … 1588 1619 cli_setpid(cli, 1); 1589 1620 1590 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) { 1591 printf("lock1 failed (%s)\n", cli_errstr(cli)); 1592 return False; 1593 } 1594 1595 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) { 1621 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK); 1622 if (!NT_STATUS_IS_OK(status)) { 1623 printf("lock1 failed (%s)\n", nt_errstr(status)); 1624 return false; 1625 } 1626 1627 status = cli_lock32(cli, fnum1, 0, 4, 0, WRITE_LOCK); 1628 if (NT_STATUS_IS_OK(status)) { 1596 1629 printf("WRITE lock1 succeeded! This is a locking bug\n"); 1597 correct = False;1630 correct = false; 1598 1631 } else { 1599 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 1600 NT_STATUS_LOCK_NOT_GRANTED)) return False; 1601 } 1602 1603 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) { 1632 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1633 NT_STATUS_LOCK_NOT_GRANTED)) { 1634 return false; 1635 } 1636 } 1637 1638 status = cli_lock32(cli, fnum2, 0, 4, 0, WRITE_LOCK); 1639 if (NT_STATUS_IS_OK(status)) { 1604 1640 printf("WRITE lock2 succeeded! This is a locking bug\n"); 1605 correct = False;1641 correct = false; 1606 1642 } else { 1607 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 1608 NT_STATUS_LOCK_NOT_GRANTED)) return False; 1609 } 1610 1611 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) { 1643 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1644 NT_STATUS_LOCK_NOT_GRANTED)) { 1645 return false; 1646 } 1647 } 1648 1649 status = cli_lock32(cli, fnum2, 0, 4, 0, READ_LOCK); 1650 if (NT_STATUS_IS_OK(status)) { 1612 1651 printf("READ lock2 succeeded! This is a locking bug\n"); 1613 correct = False;1652 correct = false; 1614 1653 } else { 1615 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, 1616 NT_STATUS_FILE_LOCK_CONFLICT)) return False; 1617 } 1618 1619 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) { 1620 printf("lock at 100 failed (%s)\n", cli_errstr(cli)); 1654 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1655 NT_STATUS_FILE_LOCK_CONFLICT)) { 1656 return false; 1657 } 1658 } 1659 1660 status = cli_lock32(cli, fnum1, 100, 4, 0, WRITE_LOCK); 1661 if (!NT_STATUS_IS_OK(status)) { 1662 printf("lock at 100 failed (%s)\n", nt_errstr(status)); 1621 1663 } 1622 1664 cli_setpid(cli, 2); … … 1626 1668 } 1627 1669 1628 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 4))) { 1670 status = cli_unlock(cli, fnum1, 0, 4); 1671 if (NT_STATUS_IS_OK(status)) { 1629 1672 printf("unlock1 succeeded! This is a locking bug\n"); 1630 correct = False;1673 correct = false; 1631 1674 } else { 1632 if (!check_error(__LINE__, cli, 1633 ERRDOS, ERRlock, 1634 NT_STATUS_RANGE_NOT_LOCKED)) return False; 1635 } 1636 1637 if (NT_STATUS_IS_OK(cli_unlock(cli, fnum1, 0, 8))) { 1675 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1676 NT_STATUS_RANGE_NOT_LOCKED)) { 1677 return false; 1678 } 1679 } 1680 1681 status = cli_unlock(cli, fnum1, 0, 8); 1682 if (NT_STATUS_IS_OK(status)) { 1638 1683 printf("unlock2 succeeded! This is a locking bug\n"); 1639 correct = False;1684 correct = false; 1640 1685 } else { 1641 if (!check_error(__LINE__, cli, 1642 ERRDOS, ERRlock, 1643 NT_STATUS_RANGE_NOT_LOCKED)) return False; 1644 } 1645 1646 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) { 1686 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1687 NT_STATUS_RANGE_NOT_LOCKED)) { 1688 return false; 1689 } 1690 } 1691 1692 status = cli_lock32(cli, fnum3, 0, 4, 0, WRITE_LOCK); 1693 if (NT_STATUS_IS_OK(status)) { 1647 1694 printf("lock3 succeeded! This is a locking bug\n"); 1648 correct = False;1695 correct = false; 1649 1696 } else { 1650 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False; 1697 if (!check_both_error(__LINE__, status, ERRDOS, ERRlock, 1698 NT_STATUS_LOCK_NOT_GRANTED)) { 1699 return false; 1700 } 1651 1701 } 1652 1702 1653 1703 cli_setpid(cli, 1); 1654 1704 1655 if (!NT_STATUS_IS_OK(cli_close(cli, fnum1))) { 1656 printf("close1 failed (%s)\n", cli_errstr(cli)); 1657 return False; 1658 } 1659 1660 if (!NT_STATUS_IS_OK(cli_close(cli, fnum2))) { 1661 printf("close2 failed (%s)\n", cli_errstr(cli)); 1662 return False; 1663 } 1664 1665 if (!NT_STATUS_IS_OK(cli_close(cli, fnum3))) { 1666 printf("close3 failed (%s)\n", cli_errstr(cli)); 1705 status = cli_close(cli, fnum1); 1706 if (!NT_STATUS_IS_OK(status)) { 1707 printf("close1 failed (%s)\n", nt_errstr(status)); 1708 return False; 1709 } 1710 1711 status = cli_close(cli, fnum2); 1712 if (!NT_STATUS_IS_OK(status)) { 1713 printf("close2 failed (%s)\n", nt_errstr(status)); 1714 return False; 1715 } 1716 1717 status = cli_close(cli, fnum3); 1718 if (!NT_STATUS_IS_OK(status)) { 1719 printf("close3 failed (%s)\n", nt_errstr(status)); 1667 1720 return False; 1668 1721 } … … 1689 1742 uint16_t fnum1, fnum2; 1690 1743 int i; 1691 uint32 offset;1744 uint32_t offset; 1692 1745 bool correct = True; 1693 1694 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops 1746 NTSTATUS status; 1747 1748 #define NEXT_OFFSET offset += (~(uint32_t)0) / torture_numops 1695 1749 1696 1750 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) { 1697 1751 return False; 1698 1752 } 1699 cli_sockopt(cli1, sockops);1700 cli_sockopt(cli2, sockops);1753 smbXcli_conn_set_sockopt(cli1->conn, sockops); 1754 smbXcli_conn_set_sockopt(cli2->conn, sockops); 1701 1755 1702 1756 printf("starting locktest3\n"); … … 1704 1758 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1705 1759 1706 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 1707 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 1708 return False; 1709 } 1710 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) { 1711 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 1760 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 1761 &fnum1); 1762 if (!NT_STATUS_IS_OK(status)) { 1763 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 1764 return False; 1765 } 1766 1767 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2); 1768 if (!NT_STATUS_IS_OK(status)) { 1769 printf("open2 of %s failed (%s)\n", fname, nt_errstr(status)); 1712 1770 return False; 1713 1771 } … … 1715 1773 for (offset=i=0;i<torture_numops;i++) { 1716 1774 NEXT_OFFSET; 1717 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) { 1775 1776 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK); 1777 if (!NT_STATUS_IS_OK(status)) { 1718 1778 printf("lock1 %d failed (%s)\n", 1719 1779 i, 1720 cli_errstr(cli1));1780 nt_errstr(status)); 1721 1781 return False; 1722 1782 } 1723 1783 1724 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) { 1784 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK); 1785 if (!NT_STATUS_IS_OK(status)) { 1725 1786 printf("lock2 %d failed (%s)\n", 1726 1787 i, 1727 cli_errstr(cli1));1788 nt_errstr(status)); 1728 1789 return False; 1729 1790 } … … 1733 1794 NEXT_OFFSET; 1734 1795 1735 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) { 1796 status = cli_lock32(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK); 1797 if (NT_STATUS_IS_OK(status)) { 1736 1798 printf("error: lock1 %d succeeded!\n", i); 1737 1799 return False; 1738 1800 } 1739 1801 1740 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) { 1802 status = cli_lock32(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK); 1803 if (NT_STATUS_IS_OK(status)) { 1741 1804 printf("error: lock2 %d succeeded!\n", i); 1742 1805 return False; 1743 1806 } 1744 1807 1745 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) { 1808 status = cli_lock32(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK); 1809 if (NT_STATUS_IS_OK(status)) { 1746 1810 printf("error: lock3 %d succeeded!\n", i); 1747 1811 return False; 1748 1812 } 1749 1813 1750 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) { 1814 status = cli_lock32(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK); 1815 if (NT_STATUS_IS_OK(status)) { 1751 1816 printf("error: lock4 %d succeeded!\n", i); 1752 1817 return False; … … 1757 1822 NEXT_OFFSET; 1758 1823 1759 if (!NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, offset-1, 1))) { 1824 status = cli_unlock(cli1, fnum1, offset-1, 1); 1825 if (!NT_STATUS_IS_OK(status)) { 1760 1826 printf("unlock1 %d failed (%s)\n", 1761 1827 i, 1762 cli_errstr(cli1));1828 nt_errstr(status)); 1763 1829 return False; 1764 1830 } 1765 1831 1766 if (!NT_STATUS_IS_OK(cli_unlock(cli2, fnum2, offset-2, 1))) { 1832 status = cli_unlock(cli2, fnum2, offset-2, 1); 1833 if (!NT_STATUS_IS_OK(status)) { 1767 1834 printf("unlock2 %d failed (%s)\n", 1768 1835 i, 1769 cli_errstr(cli1));1836 nt_errstr(status)); 1770 1837 return False; 1771 1838 } 1772 1839 } 1773 1840 1774 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 1775 printf("close1 failed (%s)\n", cli_errstr(cli1)); 1776 return False; 1777 } 1778 1779 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 1780 printf("close2 failed (%s)\n", cli_errstr(cli2)); 1781 return False; 1782 } 1783 1784 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 1785 printf("unlink failed (%s)\n", cli_errstr(cli1)); 1841 status = cli_close(cli1, fnum1); 1842 if (!NT_STATUS_IS_OK(status)) { 1843 printf("close1 failed (%s)\n", nt_errstr(status)); 1844 return False; 1845 } 1846 1847 status = cli_close(cli2, fnum2); 1848 if (!NT_STATUS_IS_OK(status)) { 1849 printf("close2 failed (%s)\n", nt_errstr(status)); 1850 return False; 1851 } 1852 1853 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1854 if (!NT_STATUS_IS_OK(status)) { 1855 printf("unlink failed (%s)\n", nt_errstr(status)); 1786 1856 return False; 1787 1857 } … … 1798 1868 1799 1869 return correct; 1870 } 1871 1872 static bool test_cli_read(struct cli_state *cli, uint16_t fnum, 1873 char *buf, off_t offset, size_t size, 1874 size_t *nread, size_t expect) 1875 { 1876 NTSTATUS status; 1877 size_t l_nread; 1878 1879 status = cli_read(cli, fnum, buf, offset, size, &l_nread); 1880 1881 if(!NT_STATUS_IS_OK(status)) { 1882 return false; 1883 } else if (l_nread != expect) { 1884 return false; 1885 } 1886 1887 if (nread) { 1888 *nread = l_nread; 1889 } 1890 1891 return true; 1800 1892 } 1801 1893 … … 1821 1913 } 1822 1914 1823 cli_sockopt(cli1, sockops);1824 cli_sockopt(cli2, sockops);1915 smbXcli_conn_set_sockopt(cli1->conn, sockops); 1916 smbXcli_conn_set_sockopt(cli2->conn, sockops); 1825 1917 1826 1918 printf("starting locktest4\n"); … … 1828 1920 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 1829 1921 1830 cli_open (cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);1831 cli_open (cli2, fname, O_RDWR, DENY_NONE, &fnum2);1922 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 1923 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2); 1832 1924 1833 1925 memset(buf, 0, sizeof(buf)); … … 1841 1933 } 1842 1934 1843 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&1844 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);1935 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) && 1936 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 2, 4, 0, WRITE_LOCK)); 1845 1937 EXPECTED(ret, False); 1846 1938 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot"); 1847 1939 1848 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&1849 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);1940 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 10, 4, 0, READ_LOCK)) && 1941 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 12, 4, 0, READ_LOCK)); 1850 1942 EXPECTED(ret, True); 1851 1943 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot"); 1852 1944 1853 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&1854 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);1945 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 20, 4, 0, WRITE_LOCK)) && 1946 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 22, 4, 0, WRITE_LOCK)); 1855 1947 EXPECTED(ret, False); 1856 1948 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot"); 1857 1949 1858 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&1859 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);1950 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 30, 4, 0, READ_LOCK)) && 1951 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 32, 4, 0, READ_LOCK)); 1860 1952 EXPECTED(ret, True); 1861 1953 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot"); 1862 1954 1863 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) && 1864 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK)); 1955 ret = (cli_setpid(cli1, 1), 1956 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 40, 4, 0, WRITE_LOCK))) && 1957 (cli_setpid(cli1, 2), 1958 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 42, 4, 0, WRITE_LOCK))); 1865 1959 EXPECTED(ret, False); 1866 1960 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot"); 1867 1961 1868 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) && 1869 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK)); 1962 ret = (cli_setpid(cli1, 1), 1963 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 50, 4, 0, READ_LOCK))) && 1964 (cli_setpid(cli1, 2), 1965 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 52, 4, 0, READ_LOCK))); 1870 1966 EXPECTED(ret, True); 1871 1967 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot"); 1872 1968 1873 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&1874 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);1969 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)) && 1970 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 60, 4, 0, READ_LOCK)); 1875 1971 EXPECTED(ret, True); 1876 1972 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot"); 1877 1973 1878 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&1879 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);1974 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)) && 1975 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 70, 4, 0, WRITE_LOCK)); 1880 1976 EXPECTED(ret, False); 1881 1977 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot"); 1882 1978 1883 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&1884 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);1979 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, READ_LOCK)) && 1980 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 80, 4, 0, WRITE_LOCK)); 1885 1981 EXPECTED(ret, False); 1886 1982 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot"); 1887 1983 1888 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&1889 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);1984 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, WRITE_LOCK)) && 1985 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 90, 4, 0, READ_LOCK)); 1890 1986 EXPECTED(ret, True); 1891 1987 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot"); 1892 1988 1893 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) && 1894 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK)); 1989 ret = (cli_setpid(cli1, 1), 1990 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, WRITE_LOCK))) && 1991 (cli_setpid(cli1, 2), 1992 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 100, 4, 0, READ_LOCK))); 1895 1993 EXPECTED(ret, False); 1896 1994 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot"); 1897 1995 1898 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&1899 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&1996 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 110, 4, 0, READ_LOCK)) && 1997 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 112, 4, 0, READ_LOCK)) && 1900 1998 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 110, 6)); 1901 1999 EXPECTED(ret, False); … … 1903 2001 1904 2002 1905 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&1906 (cli_read(cli2, fnum2, buf, 120, 4) ==4);2003 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 120, 4, 0, WRITE_LOCK)) && 2004 test_cli_read(cli2, fnum2, buf, 120, 4, NULL, 4); 1907 2005 EXPECTED(ret, False); 1908 2006 printf("this server %s strict write locking\n", ret?"doesn't do":"does"); 1909 2007 1910 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK); 2008 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK); 2009 ret = NT_STATUS_IS_OK(status); 1911 2010 if (ret) { 1912 2011 status = cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 130, 4, … … 1918 2017 1919 2018 1920 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&1921 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&2019 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) && 2020 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 140, 4, 0, READ_LOCK)) && 1922 2021 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)) && 1923 2022 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 140, 4)); … … 1926 2025 1927 2026 1928 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&1929 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&2027 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, WRITE_LOCK)) && 2028 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 150, 4, 0, READ_LOCK)) && 1930 2029 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 150, 4)) && 1931 (cli_read(cli2, fnum2, buf, 150, 4) ==4) &&2030 test_cli_read(cli2, fnum2, buf, 150, 4, NULL, 4) && 1932 2031 !(NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 1933 2032 150, 4, NULL))) && … … 1936 2035 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't"); 1937 2036 1938 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&2037 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 160, 4, 0, READ_LOCK)) && 1939 2038 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 160, 4)) && 1940 2039 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 1941 2040 160, 4, NULL)) && 1942 (cli_read(cli2, fnum2, buf, 160, 4) == 4);2041 test_cli_read(cli2, fnum2, buf, 160, 4, NULL, 4); 1943 2042 EXPECTED(ret, True); 1944 2043 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot"); 1945 2044 1946 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&2045 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 170, 4, 0, WRITE_LOCK)) && 1947 2046 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 170, 4)) && 1948 2047 NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 1949 2048 170, 4, NULL)) && 1950 (cli_read(cli2, fnum2, buf, 170, 4) == 4);2049 test_cli_read(cli2, fnum2, buf, 170, 4, NULL, 4); 1951 2050 EXPECTED(ret, True); 1952 2051 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot"); 1953 2052 1954 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&1955 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&2053 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, WRITE_LOCK)) && 2054 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 190, 4, 0, READ_LOCK)) && 1956 2055 NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 190, 4)) && 1957 2056 !NT_STATUS_IS_OK(cli_writeall(cli2, fnum2, 0, (uint8_t *)buf, 1958 2057 190, 4, NULL)) && 1959 (cli_read(cli2, fnum2, buf, 190, 4) == 4);2058 test_cli_read(cli2, fnum2, buf, 190, 4, NULL, 4); 1960 2059 EXPECTED(ret, True); 1961 2060 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't"); … … 1963 2062 cli_close(cli1, fnum1); 1964 2063 cli_close(cli2, fnum2); 1965 cli_open (cli1, fname, O_RDWR, DENY_NONE, &fnum1);1966 cli_open (cli1, fname, O_RDWR, DENY_NONE, &f);1967 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&1968 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&2064 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 2065 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &f); 2066 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) && 2067 NT_STATUS_IS_OK(cli_lock32(cli1, f, 0, 1, 0, READ_LOCK)) && 1969 2068 NT_STATUS_IS_OK(cli_close(cli1, fnum1)) && 1970 NT_STATUS_IS_OK(cli_open (cli1, fname, O_RDWR, DENY_NONE, &fnum1)) &&1971 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);2069 NT_STATUS_IS_OK(cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1)) && 2070 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK)); 1972 2071 cli_close(cli1, f); 1973 2072 cli_close(cli1, fnum1); … … 2003 2102 } 2004 2103 2005 cli_sockopt(cli1, sockops);2006 cli_sockopt(cli2, sockops);2104 smbXcli_conn_set_sockopt(cli1->conn, sockops); 2105 smbXcli_conn_set_sockopt(cli2->conn, sockops); 2007 2106 2008 2107 printf("starting locktest5\n"); … … 2010 2109 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2011 2110 2012 cli_open (cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);2013 cli_open (cli2, fname, O_RDWR, DENY_NONE, &fnum2);2014 cli_open (cli1, fname, O_RDWR, DENY_NONE, &fnum3);2111 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 2112 cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2); 2113 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum3); 2015 2114 2016 2115 memset(buf, 0, sizeof(buf)); … … 2025 2124 2026 2125 /* Check for NT bug... */ 2027 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&2028 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);2126 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 8, 0, READ_LOCK)) && 2127 NT_STATUS_IS_OK(cli_lock32(cli1, fnum3, 0, 1, 0, READ_LOCK)); 2029 2128 cli_close(cli1, fnum1); 2030 cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 2031 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK); 2129 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 2130 status = cli_lock32(cli1, fnum1, 7, 1, 0, WRITE_LOCK); 2131 ret = NT_STATUS_IS_OK(status); 2032 2132 EXPECTED(ret, True); 2033 2133 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has"); 2034 2134 cli_close(cli1, fnum1); 2035 cli_open (cli1, fname, O_RDWR, DENY_NONE, &fnum1);2135 cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 2036 2136 cli_unlock(cli1, fnum3, 0, 1); 2037 2137 2038 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&2039 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);2138 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) && 2139 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 1, 1, 0, READ_LOCK)); 2040 2140 EXPECTED(ret, True); 2041 2141 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot"); 2042 2142 2043 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK); 2143 status = cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK); 2144 ret = NT_STATUS_IS_OK(status); 2044 2145 EXPECTED(ret, False); 2045 2146 … … 2049 2150 cli_unlock(cli2, fnum2, 0, 4); 2050 2151 2051 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK); 2152 status = cli_lock32(cli1, fnum3, 0, 4, 0, READ_LOCK); 2153 ret = NT_STATUS_IS_OK(status); 2052 2154 EXPECTED(ret, False); 2053 2155 … … 2058 2160 2059 2161 /* Stack 2 more locks here. */ 2060 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&2061 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);2162 ret = NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)) && 2163 NT_STATUS_IS_OK(cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK)); 2062 2164 2063 2165 EXPECTED(ret, True); … … 2068 2170 2069 2171 ret = NT_STATUS_IS_OK(cli_unlock(cli1, fnum1, 0, 4)) && 2070 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);2172 NT_STATUS_IS_OK(cli_lock32(cli2, fnum2, 0, 4, 0, READ_LOCK)); 2071 2173 2072 2174 EXPECTED(ret, True); … … 2091 2193 2092 2194 /* Ensure connection 2 can get a write lock. */ 2093 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK); 2195 status = cli_lock32(cli2, fnum2, 0, 4, 0, WRITE_LOCK); 2196 ret = NT_STATUS_IS_OK(status); 2094 2197 EXPECTED(ret, True); 2095 2198 … … 2128 2231 } 2129 2232 2130 cli_sockopt(cli, sockops);2233 smbXcli_conn_set_sockopt(cli->conn, sockops); 2131 2234 2132 2235 printf("starting locktest6\n"); … … 2137 2240 cli_unlink(cli, fname[i], FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2138 2241 2139 cli_open (cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum);2242 cli_openx(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 2140 2243 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE); 2141 2244 cli_close(cli, fnum); 2142 2245 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status)); 2143 2246 2144 cli_open (cli, fname[i], O_RDWR, DENY_NONE, &fnum);2247 cli_openx(cli, fname[i], O_RDWR, DENY_NONE, &fnum); 2145 2248 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK); 2146 2249 cli_close(cli, fnum); … … 2163 2266 char buf[200]; 2164 2267 bool correct = False; 2268 size_t nread; 2165 2269 NTSTATUS status; 2166 2270 … … 2169 2273 } 2170 2274 2171 cli_sockopt(cli1, sockops);2275 smbXcli_conn_set_sockopt(cli1->conn, sockops); 2172 2276 2173 2277 printf("starting locktest7\n"); … … 2175 2279 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2176 2280 2177 cli_open (cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1);2281 cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 2178 2282 2179 2283 memset(buf, 0, sizeof(buf)); … … 2188 2292 cli_setpid(cli1, 1); 2189 2293 2190 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) { 2191 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1)); 2294 status = cli_lock32(cli1, fnum1, 130, 4, 0, READ_LOCK); 2295 if (!NT_STATUS_IS_OK(status)) { 2296 printf("Unable to apply read lock on range 130:4, " 2297 "error was %s\n", nt_errstr(status)); 2192 2298 goto fail; 2193 2299 } else { … … 2195 2301 } 2196 2302 2197 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { 2198 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); 2303 status = cli_read(cli1, fnum1, buf, 130, 4, &nread); 2304 if (!NT_STATUS_IS_OK(status)) { 2305 printf("pid1 unable to read the range 130:4, error was %s\n", 2306 nt_errstr(status)); 2307 goto fail; 2308 } else if (nread != 4) { 2309 printf("pid1 unable to read the range 130:4, " 2310 "recv %ld req %d\n", (unsigned long)nread, 4); 2199 2311 goto fail; 2200 2312 } else { … … 2217 2329 cli_setpid(cli1, 2); 2218 2330 2219 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { 2220 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); 2331 status = cli_read(cli1, fnum1, buf, 130, 4, &nread); 2332 if (!NT_STATUS_IS_OK(status)) { 2333 printf("pid2 unable to read the range 130:4, error was %s\n", 2334 nt_errstr(status)); 2335 goto fail; 2336 } else if (nread != 4) { 2337 printf("pid2 unable to read the range 130:4, " 2338 "recv %ld req %d\n", (unsigned long)nread, 4); 2339 goto fail; 2221 2340 } else { 2222 2341 printf("pid2 successfully read the range 130:4\n"); … … 2239 2358 cli_unlock(cli1, fnum1, 130, 4); 2240 2359 2241 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) { 2242 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1)); 2360 status = cli_lock32(cli1, fnum1, 130, 4, 0, WRITE_LOCK); 2361 if (!NT_STATUS_IS_OK(status)) { 2362 printf("Unable to apply write lock on range 130:4, error was %s\n", nt_errstr(status)); 2243 2363 goto fail; 2244 2364 } else { … … 2246 2366 } 2247 2367 2248 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { 2249 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); 2368 status = cli_read(cli1, fnum1, buf, 130, 4, &nread); 2369 if (!NT_STATUS_IS_OK(status)) { 2370 printf("pid1 unable to read the range 130:4, error was %s\n", 2371 nt_errstr(status)); 2372 goto fail; 2373 } else if (nread != 4) { 2374 printf("pid1 unable to read the range 130:4, " 2375 "recv %ld req %d\n", (unsigned long)nread, 4); 2250 2376 goto fail; 2251 2377 } else { … … 2264 2390 cli_setpid(cli1, 2); 2265 2391 2266 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) { 2267 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1)); 2268 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) { 2392 status = cli_read(cli1, fnum1, buf, 130, 4, &nread); 2393 if (!NT_STATUS_IS_OK(status)) { 2394 printf("pid2 unable to read the range 130:4, error was " 2395 "%s\n", nt_errstr(status)); 2396 if (!NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) { 2269 2397 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n"); 2270 2398 goto fail; 2271 2399 } 2272 2400 } else { 2273 printf("pid2 successfully read the range 130:4 (should be denied)\n"); 2401 printf("pid2 successfully read the range 130:4 (should be denied) recv %ld\n", 2402 (unsigned long)nread); 2274 2403 goto fail; 2275 2404 } … … 2321 2450 } 2322 2451 2323 cli_sockopt(cli1, sockops);2452 smbXcli_conn_set_sockopt(cli1->conn, sockops); 2324 2453 2325 2454 printf("starting locktest8\n"); … … 2327 2456 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2328 2457 2329 status = cli_open (cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE,2458 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_WRITE, 2330 2459 &fnum1); 2331 2460 if (!NT_STATUS_IS_OK(status)) { 2332 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));2461 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status)); 2333 2462 return false; 2334 2463 } … … 2336 2465 memset(buf, 0, sizeof(buf)); 2337 2466 2338 status = cli_open (cli1, fname, O_RDONLY, DENY_NONE, &fnum2);2339 if (!NT_STATUS_IS_OK(status)) { 2340 d_fprintf(stderr, "cli_open second time returned %s\n",2341 cli_errstr(cli1));2467 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum2); 2468 if (!NT_STATUS_IS_OK(status)) { 2469 d_fprintf(stderr, "cli_openx second time returned %s\n", 2470 nt_errstr(status)); 2342 2471 goto fail; 2343 2472 } 2344 2473 2345 if (!cli_lock(cli1, fnum2, 1, 1, 0, READ_LOCK)) { 2474 status = cli_lock32(cli1, fnum2, 1, 1, 0, READ_LOCK); 2475 if (!NT_STATUS_IS_OK(status)) { 2346 2476 printf("Unable to apply read lock on range 1:1, error was " 2347 "%s\n", cli_errstr(cli1));2477 "%s\n", nt_errstr(status)); 2348 2478 goto fail; 2349 2479 } … … 2351 2481 status = cli_close(cli1, fnum1); 2352 2482 if (!NT_STATUS_IS_OK(status)) { 2353 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));2483 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status)); 2354 2484 goto fail; 2355 2485 } 2356 2486 2357 status = cli_open (cli1, fname, O_RDWR, DENY_NONE, &fnum1);2358 if (!NT_STATUS_IS_OK(status)) { 2359 d_fprintf(stderr, "cli_open third time returned %s\n",2360 cli_errstr(cli1));2487 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 2488 if (!NT_STATUS_IS_OK(status)) { 2489 d_fprintf(stderr, "cli_openx third time returned %s\n", 2490 nt_errstr(status)); 2361 2491 goto fail; 2362 2492 } … … 2382 2512 2383 2513 static bool got_alarm; 2384 static int alarm_fd;2514 static struct cli_state *alarm_cli; 2385 2515 2386 2516 static void alarm_handler(int dummy) … … 2391 2521 static void alarm_handler_parent(int dummy) 2392 2522 { 2393 close(alarm_fd);2523 smbXcli_conn_disconnect(alarm_cli->conn, NT_STATUS_OK); 2394 2524 } 2395 2525 … … 2515 2645 } 2516 2646 2517 cli_sockopt(cli1, sockops);2518 2519 status = cli_open (cli1, fname, O_RDWR, DENY_NONE,2647 smbXcli_conn_set_sockopt(cli1->conn, sockops); 2648 2649 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, 2520 2650 &fnum); 2521 2651 if (!NT_STATUS_IS_OK(status)) { 2522 d_fprintf(stderr, "cli_open returned %s\n", cli_errstr(cli1));2652 d_fprintf(stderr, "cli_openx returned %s\n", nt_errstr(status)); 2523 2653 return false; 2524 2654 } 2525 2655 2526 2656 /* Ensure the child has the lock. */ 2527 if (cli_lock(cli1, fnum, 0, 4, 0, WRITE_LOCK)) { 2657 status = cli_lock32(cli1, fnum, 0, 4, 0, WRITE_LOCK); 2658 if (NT_STATUS_IS_OK(status)) { 2528 2659 d_fprintf(stderr, "Got the lock on range 0:4 - this should not happen !\n"); 2529 2660 goto fail; … … 2541 2672 2542 2673 /* Wait 20 seconds for the lock. */ 2543 alarm_ fd = cli1->fd;2674 alarm_cli = cli1; 2544 2675 CatchSignal(SIGALRM, alarm_handler_parent); 2545 2676 alarm(20); … … 2547 2678 start = timeval_current(); 2548 2679 2549 if (!cli_lock(cli1, fnum, 0, 4, -1, WRITE_LOCK)) { 2680 status = cli_lock32(cli1, fnum, 0, 4, -1, WRITE_LOCK); 2681 if (!NT_STATUS_IS_OK(status)) { 2550 2682 d_fprintf(stderr, "Unable to apply write lock on range 0:4, error was " 2551 "%s\n", cli_errstr(cli1));2683 "%s\n", nt_errstr(status)); 2552 2684 goto fail_nofd; 2553 2685 } … … 2561 2693 status = cli_close(cli1, fnum); 2562 2694 if (!NT_STATUS_IS_OK(status)) { 2563 d_fprintf(stderr, "cli_close(fnum1) %s\n", cli_errstr(cli1));2695 d_fprintf(stderr, "cli_close(fnum1) %s\n", nt_errstr(status)); 2564 2696 goto fail; 2565 2697 } … … 2592 2724 return False; 2593 2725 } 2594 cli_sockopt(cli1, sockops);2595 cli_sockopt(cli2, sockops);2726 smbXcli_conn_set_sockopt(cli1->conn, sockops); 2727 smbXcli_conn_set_sockopt(cli2->conn, sockops); 2596 2728 2597 2729 printf("starting fdpasstest\n"); … … 2599 2731 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2600 2732 2601 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 2602 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 2603 return False; 2604 } 2605 2606 status = cli_writeall(cli1, fnum1, 0, (uint8_t *)"hello world\n", 0, 2733 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 2734 &fnum1); 2735 if (!NT_STATUS_IS_OK(status)) { 2736 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 2737 return False; 2738 } 2739 2740 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"hello world\n", 0, 2607 2741 13, NULL); 2608 2742 if (!NT_STATUS_IS_OK(status)) { … … 2611 2745 } 2612 2746 2613 cli2->vuid = cli1->vuid; 2614 cli2->cnum = cli1->cnum; 2615 cli2->pid = cli1->pid; 2616 2617 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) { 2618 printf("read succeeded! nasty security hole [%s]\n", 2619 buf); 2620 return False; 2747 cli_state_set_uid(cli2, cli_state_get_uid(cli1)); 2748 cli_state_set_tid(cli2, cli_state_get_tid(cli1)); 2749 cli_setpid(cli2, cli_getpid(cli1)); 2750 2751 if (test_cli_read(cli2, fnum1, buf, 0, 13, NULL, 13)) { 2752 printf("read succeeded! nasty security hole [%s]\n", buf); 2753 return false; 2621 2754 } 2622 2755 … … 2634 2767 { 2635 2768 struct cli_state *cli; 2636 uint16 new_vuid;2637 uint16 saved_vuid;2638 uint16 new_cnum;2639 uint16 saved_cnum;2769 uint16_t new_vuid; 2770 uint16_t saved_vuid; 2771 uint16_t new_cnum; 2772 uint16_t saved_cnum; 2640 2773 const char *fname = "\\fdsess.tst"; 2641 2774 const char *fname1 = "\\fdsess1.tst"; … … 2648 2781 if (!torture_open_connection(&cli, 0)) 2649 2782 return False; 2650 cli_sockopt(cli, sockops);2783 smbXcli_conn_set_sockopt(cli->conn, sockops); 2651 2784 2652 2785 if (!torture_cli_session_setup2(cli, &new_vuid)) 2653 2786 return False; 2654 2787 2655 saved_cnum = cli ->cnum;2656 if (!NT_STATUS_IS_OK(cli_t con_andx(cli, share, "?????", "", 1)))2657 return False; 2658 new_cnum = cli ->cnum;2659 cli ->cnum = saved_cnum;2788 saved_cnum = cli_state_get_tid(cli); 2789 if (!NT_STATUS_IS_OK(cli_tree_connect(cli, share, "?????", "", 1))) 2790 return False; 2791 new_cnum = cli_state_get_tid(cli); 2792 cli_state_set_tid(cli, saved_cnum); 2660 2793 2661 2794 printf("starting fdsesstest\n"); … … 2664 2797 cli_unlink(cli, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2665 2798 2666 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 2667 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 2668 return False; 2669 } 2670 2671 status = cli_writeall(cli, fnum1, 0, (uint8_t *)"hello world\n", 0, 13, 2799 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 2800 if (!NT_STATUS_IS_OK(status)) { 2801 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 2802 return False; 2803 } 2804 2805 status = cli_writeall(cli, fnum1, 0, (const uint8_t *)"hello world\n", 0, 13, 2672 2806 NULL); 2673 2807 if (!NT_STATUS_IS_OK(status)) { … … 2676 2810 } 2677 2811 2678 saved_vuid = cli ->vuid;2679 cli ->vuid = new_vuid;2680 2681 if ( cli_read(cli, fnum1, buf, 0, 13) == 13) {2682 printf("read succeeded with different vuid! nasty security hole [%s]\n",2683 buf);2684 ret = False;2812 saved_vuid = cli_state_get_uid(cli); 2813 cli_state_set_uid(cli, new_vuid); 2814 2815 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) { 2816 printf("read succeeded with different vuid! " 2817 "nasty security hole [%s]\n", buf); 2818 ret = false; 2685 2819 } 2686 2820 /* Try to open a file with different vuid, samba cnum. */ 2687 if (NT_STATUS_IS_OK(cli_open (cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) {2821 if (NT_STATUS_IS_OK(cli_openx(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum2))) { 2688 2822 printf("create with different vuid, same cnum succeeded.\n"); 2689 2823 cli_close(cli, fnum2); … … 2695 2829 } 2696 2830 2697 cli ->vuid = saved_vuid;2831 cli_state_set_uid(cli, saved_vuid); 2698 2832 2699 2833 /* Try with same vuid, different cnum. */ 2700 cli->cnum = new_cnum; 2701 2702 if (cli_read(cli, fnum1, buf, 0, 13) == 13) { 2703 printf("read succeeded with different cnum![%s]\n", 2704 buf); 2705 ret = False; 2706 } 2707 2708 cli->cnum = saved_cnum; 2834 cli_state_set_tid(cli, new_cnum); 2835 2836 if (test_cli_read(cli, fnum1, buf, 0, 13, NULL, 13)) { 2837 printf("read succeeded with different cnum![%s]\n", buf); 2838 ret = false; 2839 } 2840 2841 cli_state_set_tid(cli, saved_cnum); 2709 2842 cli_close(cli, fnum1); 2710 2843 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); … … 2727 2860 uint16_t fnum; 2728 2861 bool correct = True; 2862 NTSTATUS status; 2729 2863 2730 2864 if (!torture_open_connection(&cli, 0)) { … … 2732 2866 } 2733 2867 2734 cli_sockopt(cli, sockops);2868 smbXcli_conn_set_sockopt(cli->conn, sockops); 2735 2869 2736 2870 printf("starting unlink test\n"); … … 2740 2874 cli_setpid(cli, 1); 2741 2875 2742 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 2743 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 2744 return False; 2745 } 2746 2747 if (NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 2876 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 2877 if (!NT_STATUS_IS_OK(status)) { 2878 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 2879 return False; 2880 } 2881 2882 status = cli_unlink(cli, fname, 2883 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2884 if (NT_STATUS_IS_OK(status)) { 2748 2885 printf("error: server allowed unlink on an open file\n"); 2749 2886 correct = False; 2750 2887 } else { 2751 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,2888 correct = check_error(__LINE__, status, ERRDOS, ERRbadshare, 2752 2889 NT_STATUS_SHARING_VIOLATION); 2753 2890 } … … 2772 2909 { 2773 2910 struct cli_state *cli; 2774 const char *ftemplate = "\\maxfid.%d.%d";2775 2911 fstring fname; 2776 2912 uint16_t fnums[0x11000]; … … 2778 2914 int retries=4; 2779 2915 bool correct = True; 2916 NTSTATUS status; 2780 2917 2781 2918 cli = current_cli; … … 2786 2923 } 2787 2924 2788 cli_sockopt(cli, sockops);2925 smbXcli_conn_set_sockopt(cli->conn, sockops); 2789 2926 2790 2927 for (i=0; i<0x11000; i++) { 2791 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid()); 2792 if (!NT_STATUS_IS_OK(cli_open(cli, fname, 2793 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnums[i]))) { 2928 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid()); 2929 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, 2930 &fnums[i]); 2931 if (!NT_STATUS_IS_OK(status)) { 2794 2932 printf("open of %s failed (%s)\n", 2795 fname, cli_errstr(cli));2933 fname, nt_errstr(status)); 2796 2934 printf("maximum fnum is %d\n", i); 2797 2935 break; … … 2804 2942 printf("cleaning up\n"); 2805 2943 for (;i>=0;i--) { 2806 slprintf(fname,sizeof(fname)-1, ftemplate, i,(int)getpid());2944 slprintf(fname,sizeof(fname)-1,"\\maxfid.%d.%d", i,(int)getpid()); 2807 2945 cli_close(cli, fnums[i]); 2808 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 2946 2947 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 2948 if (!NT_STATUS_IS_OK(status)) { 2809 2949 printf("unlink of %s failed (%s)\n", 2810 fname, cli_errstr(cli));2950 fname, nt_errstr(status)); 2811 2951 correct = False; 2812 2952 } … … 2841 2981 printf("starting negprot nowait test\n"); 2842 2982 2843 ev = tevent_context_init(talloc_tos());2983 ev = samba_tevent_context_init(talloc_tos()); 2844 2984 if (ev == NULL) { 2845 2985 return false; … … 2854 2994 struct tevent_req *req; 2855 2995 2856 req = cli_negprot_send(ev, ev, cli); 2996 req = smbXcli_negprot_send(ev, ev, cli->conn, cli->timeout, 2997 PROTOCOL_CORE, PROTOCOL_NT1); 2857 2998 if (req == NULL) { 2858 2999 TALLOC_FREE(ev); … … 2880 3021 static bool run_bad_nbt_session(int dummy) 2881 3022 { 2882 static struct cli_state *cli; 3023 struct nmb_name called, calling; 3024 struct sockaddr_storage ss; 3025 NTSTATUS status; 3026 int fd; 3027 bool ret; 2883 3028 2884 3029 printf("starting bad nbt session test\n"); 2885 3030 2886 if (!(cli = open_bad_nbt_connection())) { 2887 return False; 2888 } 2889 2890 cli_shutdown(cli); 3031 make_nmb_name(&calling, myname, 0x0); 3032 make_nmb_name(&called , host, 0x20); 3033 3034 if (!resolve_name(host, &ss, 0x20, true)) { 3035 d_fprintf(stderr, "Could not resolve name %s\n", host); 3036 return false; 3037 } 3038 3039 status = open_socket_out(&ss, NBT_SMB_PORT, 10000, &fd); 3040 if (!NT_STATUS_IS_OK(status)) { 3041 d_fprintf(stderr, "open_socket_out failed: %s\n", 3042 nt_errstr(status)); 3043 return false; 3044 } 3045 3046 ret = cli_bad_session_request(fd, &calling, &called); 3047 close(fd); 3048 if (!ret) { 3049 d_fprintf(stderr, "open_socket_out failed: %s\n", 3050 nt_errstr(status)); 3051 return false; 3052 } 3053 2891 3054 printf("finished bad nbt session test\n"); 2892 3055 return true; … … 2921 3084 cli_api(cli, 2922 3085 param, param_len, 8, 2923 NULL, 0, BUFFER_SIZE,3086 NULL, 0, CLI_BUFFER_SIZE, 2924 3087 &rparam, &rprcnt, 2925 3088 &rdata, &rdrcnt); … … 2934 3097 } 2935 3098 3099 SAFE_FREE(rparam); 3100 SAFE_FREE(rdata); 3101 2936 3102 printf("finished random ipc test\n"); 2937 3103 … … 2941 3107 2942 3108 2943 static void browse_callback(const char *sname, uint32 stype,3109 static void browse_callback(const char *sname, uint32_t stype, 2944 3110 const char *comment, void *state) 2945 3111 { … … 2995 3161 const char *fname = "\\attrib123456789.tst"; 2996 3162 bool correct = True; 3163 NTSTATUS status; 2997 3164 2998 3165 printf("starting attrib test\n"); … … 3003 3170 3004 3171 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3005 cli_open (cli, fname,3172 cli_openx(cli, fname, 3006 3173 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); 3007 3174 cli_close(cli, fnum); 3008 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) { 3009 printf("getatr failed (%s)\n", cli_errstr(cli)); 3175 3176 status = cli_getatr(cli, fname, NULL, NULL, &t); 3177 if (!NT_STATUS_IS_OK(status)) { 3178 printf("getatr failed (%s)\n", nt_errstr(status)); 3010 3179 correct = False; 3011 3180 } … … 3020 3189 t2 = t-60*60*24; /* 1 day ago */ 3021 3190 3022 if (!NT_STATUS_IS_OK(cli_setatr(cli, fname, 0, t2))) { 3023 printf("setatr failed (%s)\n", cli_errstr(cli)); 3191 status = cli_setatr(cli, fname, 0, t2); 3192 if (!NT_STATUS_IS_OK(status)) { 3193 printf("setatr failed (%s)\n", nt_errstr(status)); 3024 3194 correct = True; 3025 3195 } 3026 3196 3027 if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) { 3028 printf("getatr failed (%s)\n", cli_errstr(cli)); 3197 status = cli_getatr(cli, fname, NULL, NULL, &t); 3198 if (!NT_STATUS_IS_OK(status)) { 3199 printf("getatr failed (%s)\n", nt_errstr(status)); 3029 3200 correct = True; 3030 3201 } … … 3056 3227 struct cli_state *cli; 3057 3228 uint16_t fnum; 3058 SMB_OFF_Tsize;3229 off_t size; 3059 3230 time_t c_time, a_time, m_time; 3060 3231 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts; … … 3062 3233 const char *dname = "\\trans2"; 3063 3234 const char *fname2 = "\\trans2\\trans2.tst"; 3064 char pname[1024];3235 char *pname; 3065 3236 bool correct = True; 3066 3237 NTSTATUS status; … … 3081 3252 3082 3253 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3083 cli_open(cli, fname, 3084 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); 3085 if (!NT_STATUS_IS_OK(cli_qfileinfo_basic( 3086 cli, fnum, NULL, &size, &c_time_ts, 3087 &a_time_ts, &w_time_ts, 3088 &m_time_ts, NULL))) { 3089 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli)); 3254 cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); 3255 status = cli_qfileinfo_basic(cli, fnum, NULL, &size, &c_time_ts, 3256 &a_time_ts, &w_time_ts, &m_time_ts, NULL); 3257 if (!NT_STATUS_IS_OK(status)) { 3258 printf("ERROR: qfileinfo failed (%s)\n", nt_errstr(status)); 3090 3259 correct = False; 3091 3260 } 3092 3261 3093 if (!NT_STATUS_IS_OK(cli_qfilename(cli, fnum, pname, sizeof(pname)))) { 3094 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli)); 3262 status = cli_qfilename(cli, fnum, talloc_tos(), &pname); 3263 if (!NT_STATUS_IS_OK(status)) { 3264 printf("ERROR: qfilename failed (%s)\n", nt_errstr(status)); 3095 3265 correct = False; 3096 3266 } 3097 3098 if (strcmp(pname, fname)) { 3267 else if (strcmp(pname, fname)) { 3099 3268 printf("qfilename gave different name? [%s] [%s]\n", 3100 3269 fname, pname); … … 3107 3276 3108 3277 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3109 if (!NT_STATUS_IS_OK(cli_open(cli, fname, 3110 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { 3111 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 3278 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, 3279 &fnum); 3280 if (!NT_STATUS_IS_OK(status)) { 3281 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3112 3282 return False; 3113 3283 } … … 3120 3290 correct = False; 3121 3291 } else { 3292 time_t t = time(NULL); 3293 3122 3294 if (c_time != m_time) { 3123 3295 printf("create time=%s", ctime(&c_time)); … … 3125 3297 printf("This system appears to have sticky create times\n"); 3126 3298 } 3127 if ( a_time % (60*60) == 0) {3299 if ((abs(a_time - t) > 60) && (a_time % (60*60) == 0)) { 3128 3300 printf("access time=%s", ctime(&a_time)); 3129 3301 printf("This system appears to set a midnight access time\n"); … … 3131 3303 } 3132 3304 3133 if (abs(m_time - t ime(NULL)) > 60*60*24*7) {3305 if (abs(m_time - t) > 60*60*24*7) { 3134 3306 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time)); 3135 3307 correct = False; … … 3139 3311 3140 3312 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3141 cli_open (cli, fname,3313 cli_openx(cli, fname, 3142 3314 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); 3143 3315 cli_close(cli, fnum); … … 3160 3332 /* check if the server updates the directory modification time 3161 3333 when creating a new file */ 3162 if (!NT_STATUS_IS_OK(cli_mkdir(cli, dname))) { 3163 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli)); 3334 status = cli_mkdir(cli, dname); 3335 if (!NT_STATUS_IS_OK(status)) { 3336 printf("ERROR: mkdir failed (%s)\n", nt_errstr(status)); 3164 3337 correct = False; 3165 3338 } … … 3172 3345 } 3173 3346 3174 cli_open (cli, fname2,3347 cli_openx(cli, fname2, 3175 3348 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum); 3176 3349 cli_writeall(cli, fnum, 0, (uint8_t *)&fnum, 0, sizeof(fnum), NULL); … … 3207 3380 { 3208 3381 uint8_t *buf = NULL; 3209 uint32 len;3382 uint32_t len; 3210 3383 NTSTATUS status; 3211 3384 3212 3385 status = cli_qfileinfo(talloc_tos(), pcli, fnum, level, 0, 3213 pcli->max_xmit, &buf, &len);3386 CLI_BUFFER_SIZE, NULL, &buf, &len); 3214 3387 if (!NT_STATUS_IS_OK(status)) { 3215 3388 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, … … 3217 3390 } else { 3218 3391 printf("qfileinfo: level %d, len = %u\n", level, len); 3219 dump_data(0, (uint8 *)buf, len);3392 dump_data(0, (uint8_t *)buf, len); 3220 3393 printf("\n"); 3221 3394 } … … 3238 3411 } 3239 3412 3240 cli_open (cli, fname,3413 cli_openx(cli, fname, 3241 3414 O_RDWR | O_CREAT , DENY_NONE, &fnum); 3242 3415 … … 3266 3439 uint16_t fnum1; 3267 3440 bool correct = True; 3441 NTSTATUS status; 3268 3442 3269 3443 printf("starting oplock test 1\n"); … … 3275 3449 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3276 3450 3277 cli_sockopt(cli1, sockops);3451 smbXcli_conn_set_sockopt(cli1->conn, sockops); 3278 3452 3279 3453 cli1->use_oplocks = True; 3280 3454 3281 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 3282 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3455 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 3456 &fnum1); 3457 if (!NT_STATUS_IS_OK(status)) { 3458 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3283 3459 return False; 3284 3460 } … … 3289 3465 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3290 3466 3291 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3292 printf("close2 failed (%s)\n", cli_errstr(cli1)); 3293 return False; 3294 } 3295 3296 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 3297 printf("unlink failed (%s)\n", cli_errstr(cli1)); 3467 status = cli_close(cli1, fnum1); 3468 if (!NT_STATUS_IS_OK(status)) { 3469 printf("close2 failed (%s)\n", nt_errstr(status)); 3470 return False; 3471 } 3472 3473 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3474 if (!NT_STATUS_IS_OK(status)) { 3475 printf("unlink failed (%s)\n", nt_errstr(status)); 3298 3476 return False; 3299 3477 } … … 3317 3495 bool correct = True; 3318 3496 volatile bool *shared_correct; 3319 3320 shared_correct = (volatile bool *)shm_setup(sizeof(bool)); 3497 size_t nread; 3498 NTSTATUS status; 3499 3500 shared_correct = (volatile bool *)anonymous_shared_allocate(sizeof(bool)); 3321 3501 *shared_correct = True; 3322 3502 … … 3332 3512 } 3333 3513 3334 cli1->use_oplocks = True;3335 cli1->use_level_II_oplocks = True;3336 3337 3514 if (!torture_open_connection(&cli2, 1)) { 3338 3515 use_level_II_oplocks = False; … … 3341 3518 } 3342 3519 3343 cli2->use_oplocks = True;3344 cli2->use_level_II_oplocks = True;3345 3346 3520 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3347 3521 3348 cli_sockopt(cli1, sockops); 3349 cli_sockopt(cli2, sockops); 3350 3351 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 3352 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3522 smbXcli_conn_set_sockopt(cli1->conn, sockops); 3523 smbXcli_conn_set_sockopt(cli2->conn, sockops); 3524 3525 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 3526 &fnum1); 3527 if (!NT_STATUS_IS_OK(status)) { 3528 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3353 3529 return False; 3354 3530 } … … 3360 3536 if (fork() == 0) { 3361 3537 /* Child code */ 3362 if (!NT_STATUS_IS_OK(cli_open(cli2, fname, O_RDWR, DENY_NONE, &fnum2))) { 3363 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3538 status = cli_openx(cli2, fname, O_RDWR, DENY_NONE, &fnum2); 3539 if (!NT_STATUS_IS_OK(status)) { 3540 printf("second open of %s failed (%s)\n", fname, nt_errstr(status)); 3364 3541 *shared_correct = False; 3365 3542 exit(0); … … 3368 3545 sleep(2); 3369 3546 3370 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 3371 printf("close2 failed (%s)\n", cli_errstr(cli1)); 3547 status = cli_close(cli2, fnum2); 3548 if (!NT_STATUS_IS_OK(status)) { 3549 printf("close2 failed (%s)\n", nt_errstr(status)); 3372 3550 *shared_correct = False; 3373 3551 } … … 3380 3558 /* Ensure cli1 processes the break. Empty file should always return 0 3381 3559 * bytes. */ 3382 3383 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) { 3384 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1)); 3385 correct = False; 3560 status = cli_read(cli1, fnum1, buf, 0, 4, &nread); 3561 if (!NT_STATUS_IS_OK(status)) { 3562 printf("read on fnum1 failed (%s)\n", nt_errstr(status)); 3563 correct = false; 3564 } else if (nread != 0) { 3565 printf("read on empty fnum1 failed. recv %ld expected %d\n", 3566 (unsigned long)nread, 0); 3567 correct = false; 3386 3568 } 3387 3569 3388 3570 /* Should now be at level II. */ 3389 3571 /* Test if sending a write locks causes a break to none. */ 3390 3391 if (! cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {3392 printf("lock failed (%s)\n", cli_errstr(cli1));3572 status = cli_lock32(cli1, fnum1, 0, 4, 0, READ_LOCK); 3573 if (!NT_STATUS_IS_OK(status)) { 3574 printf("lock failed (%s)\n", nt_errstr(status)); 3393 3575 correct = False; 3394 3576 } … … 3398 3580 sleep(2); 3399 3581 3400 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) { 3401 printf("lock failed (%s)\n", cli_errstr(cli1)); 3582 status = cli_lock32(cli1, fnum1, 0, 4, 0, WRITE_LOCK); 3583 if (!NT_STATUS_IS_OK(status)) { 3584 printf("lock failed (%s)\n", nt_errstr(status)); 3402 3585 correct = False; 3403 3586 } … … 3407 3590 sleep(2); 3408 3591 3409 cli_read(cli1, fnum1, buf, 0, 4); 3410 3411 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3412 printf("close1 failed (%s)\n", cli_errstr(cli1)); 3592 cli_read(cli1, fnum1, buf, 0, 4, NULL); 3593 3594 status = cli_close(cli1, fnum1); 3595 if (!NT_STATUS_IS_OK(status)) { 3596 printf("close1 failed (%s)\n", nt_errstr(status)); 3413 3597 correct = False; 3414 3598 } … … 3416 3600 sleep(4); 3417 3601 3418 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 3419 printf("unlink failed (%s)\n", cli_errstr(cli1)); 3602 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3603 if (!NT_STATUS_IS_OK(status)) { 3604 printf("unlink failed (%s)\n", nt_errstr(status)); 3420 3605 correct = False; 3421 3606 } … … 3434 3619 } 3435 3620 3436 /* handler for oplock 3 tests */ 3437 static NTSTATUS oplock3_handler(struct cli_state *cli, uint16_t fnum, unsigned char level) 3438 { 3439 printf("got oplock break fnum=%d level=%d\n", 3440 fnum, level); 3441 return cli_oplock_ack(cli, fnum, level); 3442 } 3443 3444 static bool run_oplock3(int dummy) 3445 { 3621 struct oplock4_state { 3622 struct tevent_context *ev; 3446 3623 struct cli_state *cli; 3447 const char *fname = "\\oplockt3.dat"; 3448 uint16_t fnum; 3449 char buf[4] = "abcd"; 3450 bool correct = True; 3451 volatile bool *shared_correct; 3452 3453 shared_correct = (volatile bool *)shm_setup(sizeof(bool)); 3454 *shared_correct = True; 3455 3456 printf("starting oplock test 3\n"); 3457 3458 if (fork() == 0) { 3459 /* Child code */ 3460 use_oplocks = True; 3461 use_level_II_oplocks = True; 3462 if (!torture_open_connection(&cli, 0)) { 3463 *shared_correct = False; 3464 exit(0); 3465 } 3466 sleep(2); 3467 /* try to trigger a oplock break in parent */ 3468 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum); 3469 cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL); 3470 exit(0); 3471 } 3472 3473 /* parent code */ 3474 use_oplocks = True; 3475 use_level_II_oplocks = True; 3476 if (!torture_open_connection(&cli, 1)) { /* other is forked */ 3477 return False; 3478 } 3479 cli_oplock_handler(cli, oplock3_handler); 3480 cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum); 3481 cli_writeall(cli, fnum, 0, (uint8_t *)buf, 0, 4, NULL); 3482 cli_close(cli, fnum); 3483 cli_open(cli, fname, O_RDWR, DENY_NONE, &fnum); 3484 cli->timeout = 20000; 3485 cli_receive_smb(cli); 3486 printf("finished oplock test 3\n"); 3487 3488 return (correct && *shared_correct); 3489 3490 /* What are we looking for here? What's sucess and what's FAILURE? */ 3491 } 3492 3493 /* handler for oplock 4 tests */ 3494 bool *oplock4_shared_correct; 3495 3496 static NTSTATUS oplock4_handler(struct cli_state *cli, uint16_t fnum, unsigned char level) 3497 { 3498 printf("got oplock break fnum=%d level=%d\n", 3499 fnum, level); 3500 *oplock4_shared_correct = true; 3501 cli_oplock_ack(cli, fnum, level); 3502 return NT_STATUS_UNSUCCESSFUL; /* Cause cli_receive_smb to return. */ 3503 } 3624 bool *got_break; 3625 uint16_t *fnum2; 3626 }; 3627 3628 static void oplock4_got_break(struct tevent_req *req); 3629 static void oplock4_got_open(struct tevent_req *req); 3504 3630 3505 3631 static bool run_oplock4(int dummy) 3506 3632 { 3633 struct tevent_context *ev; 3507 3634 struct cli_state *cli1, *cli2; 3635 struct tevent_req *oplock_req, *open_req; 3508 3636 const char *fname = "\\lockt4.lck"; 3509 3637 const char *fname_ln = "\\lockt4_ln.lck"; … … 3513 3641 bool correct = true; 3514 3642 3515 oplock4_shared_correct = (bool *)shm_setup(sizeof(bool)); 3516 *oplock4_shared_correct = false; 3643 bool got_break; 3644 3645 struct oplock4_state *state; 3517 3646 3518 3647 printf("starting oplock test 4\n"); … … 3533 3662 cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3534 3663 3535 cli_sockopt(cli1, sockops);3536 cli_sockopt(cli2, sockops);3664 smbXcli_conn_set_sockopt(cli1->conn, sockops); 3665 smbXcli_conn_set_sockopt(cli2->conn, sockops); 3537 3666 3538 3667 /* Create the file. */ 3539 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 3540 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3541 return false; 3542 } 3543 3544 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3545 printf("close1 failed (%s)\n", cli_errstr(cli1)); 3668 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, 3669 &fnum1); 3670 if (!NT_STATUS_IS_OK(status)) { 3671 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3672 return false; 3673 } 3674 3675 status = cli_close(cli1, fnum1); 3676 if (!NT_STATUS_IS_OK(status)) { 3677 printf("close1 failed (%s)\n", nt_errstr(status)); 3546 3678 return false; 3547 3679 } 3548 3680 3549 3681 /* Now create a hardlink. */ 3550 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli1, fname, fname_ln))) { 3551 printf("nt hardlink failed (%s)\n", cli_errstr(cli1)); 3682 status = cli_nt_hardlink(cli1, fname, fname_ln); 3683 if (!NT_STATUS_IS_OK(status)) { 3684 printf("nt hardlink failed (%s)\n", nt_errstr(status)); 3552 3685 return false; 3553 3686 } 3554 3687 3555 3688 /* Prove that opening hardlinks cause deny modes to conflict. */ 3556 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum1))) { 3557 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3558 return false; 3559 } 3560 3561 status = cli_open(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2); 3689 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum1); 3690 if (!NT_STATUS_IS_OK(status)) { 3691 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3692 return false; 3693 } 3694 3695 status = cli_openx(cli1, fname_ln, O_RDWR, DENY_NONE, &fnum2); 3562 3696 if (NT_STATUS_IS_OK(status)) { 3563 3697 printf("open of %s succeeded - should fail with sharing violation.\n", … … 3572 3706 } 3573 3707 3574 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3575 printf("close1 failed (%s)\n", cli_errstr(cli1)); 3708 status = cli_close(cli1, fnum1); 3709 if (!NT_STATUS_IS_OK(status)) { 3710 printf("close1 failed (%s)\n", nt_errstr(status)); 3576 3711 return false; 3577 3712 } 3578 3713 3579 3714 cli1->use_oplocks = true; 3580 cli1->use_level_II_oplocks = true;3581 3582 3715 cli2->use_oplocks = true; 3583 cli2->use_level_II_oplocks = true; 3584 3585 cli_oplock_handler(cli1, oplock4_handler); 3586 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) { 3587 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3588 return false; 3589 } 3590 3591 if (fork() == 0) { 3592 /* Child code */ 3593 if (!NT_STATUS_IS_OK(cli_open(cli2, fname_ln, O_RDWR, DENY_NONE, &fnum2))) { 3594 printf("open of %s failed (%s)\n", fname_ln, cli_errstr(cli1)); 3595 *oplock4_shared_correct = false; 3596 exit(0); 3597 } 3598 3599 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 3600 printf("close2 failed (%s)\n", cli_errstr(cli1)); 3601 *oplock4_shared_correct = false; 3602 } 3603 3604 exit(0); 3605 } 3606 3607 sleep(2); 3608 3609 /* Process the oplock break. */ 3610 cli_receive_smb(cli1); 3611 3612 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3613 printf("close1 failed (%s)\n", cli_errstr(cli1)); 3716 3717 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 3718 if (!NT_STATUS_IS_OK(status)) { 3719 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 3720 return false; 3721 } 3722 3723 ev = samba_tevent_context_init(talloc_tos()); 3724 if (ev == NULL) { 3725 printf("tevent_context_init failed\n"); 3726 return false; 3727 } 3728 3729 state = talloc(ev, struct oplock4_state); 3730 if (state == NULL) { 3731 printf("talloc failed\n"); 3732 return false; 3733 } 3734 state->ev = ev; 3735 state->cli = cli1; 3736 state->got_break = &got_break; 3737 state->fnum2 = &fnum2; 3738 3739 oplock_req = cli_smb_oplock_break_waiter_send( 3740 talloc_tos(), ev, cli1); 3741 if (oplock_req == NULL) { 3742 printf("cli_smb_oplock_break_waiter_send failed\n"); 3743 return false; 3744 } 3745 tevent_req_set_callback(oplock_req, oplock4_got_break, state); 3746 3747 open_req = cli_openx_send( 3748 talloc_tos(), ev, cli2, fname_ln, O_RDWR, DENY_NONE); 3749 if (open_req == NULL) { 3750 printf("cli_openx_send failed\n"); 3751 return false; 3752 } 3753 tevent_req_set_callback(open_req, oplock4_got_open, state); 3754 3755 got_break = false; 3756 fnum2 = 0xffff; 3757 3758 while (!got_break || fnum2 == 0xffff) { 3759 int ret; 3760 ret = tevent_loop_once(ev); 3761 if (ret == -1) { 3762 printf("tevent_loop_once failed: %s\n", 3763 strerror(errno)); 3764 return false; 3765 } 3766 } 3767 3768 status = cli_close(cli2, fnum2); 3769 if (!NT_STATUS_IS_OK(status)) { 3770 printf("close2 failed (%s)\n", nt_errstr(status)); 3614 3771 correct = false; 3615 3772 } 3616 3773 3617 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 3618 printf("unlink failed (%s)\n", cli_errstr(cli1)); 3774 status = cli_close(cli1, fnum1); 3775 if (!NT_STATUS_IS_OK(status)) { 3776 printf("close1 failed (%s)\n", nt_errstr(status)); 3619 3777 correct = false; 3620 3778 } 3621 if (!NT_STATUS_IS_OK(cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 3622 printf("unlink failed (%s)\n", cli_errstr(cli1)); 3779 3780 status = cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3781 if (!NT_STATUS_IS_OK(status)) { 3782 printf("unlink failed (%s)\n", nt_errstr(status)); 3783 correct = false; 3784 } 3785 3786 status = cli_unlink(cli1, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3787 if (!NT_STATUS_IS_OK(status)) { 3788 printf("unlink failed (%s)\n", nt_errstr(status)); 3623 3789 correct = false; 3624 3790 } … … 3628 3794 } 3629 3795 3630 if (! *oplock4_shared_correct) {3796 if (!got_break) { 3631 3797 correct = false; 3632 3798 } … … 3637 3803 } 3638 3804 3805 static void oplock4_got_break(struct tevent_req *req) 3806 { 3807 struct oplock4_state *state = tevent_req_callback_data( 3808 req, struct oplock4_state); 3809 uint16_t fnum; 3810 uint8_t level; 3811 NTSTATUS status; 3812 3813 status = cli_smb_oplock_break_waiter_recv(req, &fnum, &level); 3814 TALLOC_FREE(req); 3815 if (!NT_STATUS_IS_OK(status)) { 3816 printf("cli_smb_oplock_break_waiter_recv returned %s\n", 3817 nt_errstr(status)); 3818 return; 3819 } 3820 *state->got_break = true; 3821 3822 req = cli_oplock_ack_send(state, state->ev, state->cli, fnum, 3823 NO_OPLOCK); 3824 if (req == NULL) { 3825 printf("cli_oplock_ack_send failed\n"); 3826 return; 3827 } 3828 } 3829 3830 static void oplock4_got_open(struct tevent_req *req) 3831 { 3832 struct oplock4_state *state = tevent_req_callback_data( 3833 req, struct oplock4_state); 3834 NTSTATUS status; 3835 3836 status = cli_openx_recv(req, state->fnum2); 3837 if (!NT_STATUS_IS_OK(status)) { 3838 printf("cli_openx_recv returned %s\n", nt_errstr(status)); 3839 *state->fnum2 = 0xffff; 3840 } 3841 } 3639 3842 3640 3843 /* … … 3648 3851 uint16_t fnum1 = (uint16_t)-1; 3649 3852 uint16_t fnum2 = (uint16_t)-1; 3650 bool correct = True; 3853 bool correct = false; 3854 NTSTATUS status; 3651 3855 3652 3856 printf("starting delete test\n"); … … 3656 3860 } 3657 3861 3658 cli_sockopt(cli1, sockops);3862 smbXcli_conn_set_sockopt(cli1->conn, sockops); 3659 3863 3660 3864 /* Test 1 - this should delete the file on close. */ … … 3663 3867 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3664 3868 3665 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,3666 0, FILE_OVERWRITE_IF,3667 FILE_DELETE_ON_CLOSE, 0, &fnum1))) {3668 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));3669 correct = False;3869 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, 3870 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 3871 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL); 3872 if (!NT_STATUS_IS_OK(status)) { 3873 printf("[1] open of %s failed (%s)\n", fname, nt_errstr(status)); 3670 3874 goto fail; 3671 3875 } 3672 3876 3673 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3674 printf("[1] close failed (%s)\n", cli_errstr(cli1));3675 correct = False;3877 status = cli_close(cli1, fnum1); 3878 if (!NT_STATUS_IS_OK(status)) { 3879 printf("[1] close failed (%s)\n", nt_errstr(status)); 3676 3880 goto fail; 3677 3881 } 3678 3882 3679 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR, DENY_NONE, &fnum1))) { 3883 status = cli_openx(cli1, fname, O_RDWR, DENY_NONE, &fnum1); 3884 if (NT_STATUS_IS_OK(status)) { 3680 3885 printf("[1] open of %s succeeded (should fail)\n", fname); 3681 correct = False;3682 3886 goto fail; 3683 3887 } … … 3690 3894 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3691 3895 3692 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS,3693 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,3694 FILE_OVERWRITE_IF, 0, 0, &fnum1))) {3695 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));3696 correct = False;3896 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, 3897 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 3898 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 3899 if (!NT_STATUS_IS_OK(status)) { 3900 printf("[2] open of %s failed (%s)\n", fname, nt_errstr(status)); 3697 3901 goto fail; 3698 3902 } 3699 3903 3700 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {3701 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));3702 correct = False;3904 status = cli_nt_delete_on_close(cli1, fnum1, true); 3905 if (!NT_STATUS_IS_OK(status)) { 3906 printf("[2] setting delete_on_close failed (%s)\n", nt_errstr(status)); 3703 3907 goto fail; 3704 3908 } 3705 3909 3706 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3707 printf("[2] close failed (%s)\n", cli_errstr(cli1));3708 correct = False;3910 status = cli_close(cli1, fnum1); 3911 if (!NT_STATUS_IS_OK(status)) { 3912 printf("[2] close failed (%s)\n", nt_errstr(status)); 3709 3913 goto fail; 3710 3914 } 3711 3915 3712 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) { 3916 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1); 3917 if (NT_STATUS_IS_OK(status)) { 3713 3918 printf("[2] open of %s succeeded should have been deleted on close !\n", fname); 3714 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3715 printf("[2] close failed (%s)\n", cli_errstr(cli1)); 3716 correct = False; 3717 goto fail; 3919 status = cli_close(cli1, fnum1); 3920 if (!NT_STATUS_IS_OK(status)) { 3921 printf("[2] close failed (%s)\n", nt_errstr(status)); 3718 3922 } 3719 3923 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3720 } else 3721 printf("second delete on close test succeeded.\n"); 3924 goto fail; 3925 } 3926 3927 printf("second delete on close test succeeded.\n"); 3722 3928 3723 3929 /* Test 3 - ... */ … … 3725 3931 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3726 3932 3727 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, 3728 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 3729 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 3730 correct = False; 3933 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, 3934 FILE_ATTRIBUTE_NORMAL, 3935 FILE_SHARE_READ|FILE_SHARE_WRITE, 3936 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 3937 if (!NT_STATUS_IS_OK(status)) { 3938 printf("[3] open - 1 of %s failed (%s)\n", fname, nt_errstr(status)); 3731 3939 goto fail; 3732 3940 } … … 3735 3943 with SHARE_DELETE. */ 3736 3944 3737 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 3738 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0, &fnum2))) { 3945 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 3946 FILE_ATTRIBUTE_NORMAL, 3947 FILE_SHARE_READ|FILE_SHARE_WRITE, 3948 FILE_OPEN, 0, 0, &fnum2, NULL); 3949 if (NT_STATUS_IS_OK(status)) { 3739 3950 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname); 3740 correct = False;3741 3951 goto fail; 3742 3952 } 3743 3953 3744 3954 /* This should succeed. */ 3745 3746 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 3747 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) { 3748 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); 3749 correct = False; 3955 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 3956 FILE_ATTRIBUTE_NORMAL, 3957 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 3958 FILE_OPEN, 0, 0, &fnum2, NULL); 3959 if (!NT_STATUS_IS_OK(status)) { 3960 printf("[3] open - 3 of %s failed (%s)\n", fname, nt_errstr(status)); 3750 3961 goto fail; 3751 3962 } 3752 3963 3753 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {3754 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));3755 correct = False;3964 status = cli_nt_delete_on_close(cli1, fnum1, true); 3965 if (!NT_STATUS_IS_OK(status)) { 3966 printf("[3] setting delete_on_close failed (%s)\n", nt_errstr(status)); 3756 3967 goto fail; 3757 3968 } 3758 3969 3759 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3760 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));3761 correct = False;3970 status = cli_close(cli1, fnum1); 3971 if (!NT_STATUS_IS_OK(status)) { 3972 printf("[3] close 1 failed (%s)\n", nt_errstr(status)); 3762 3973 goto fail; 3763 3974 } 3764 3975 3765 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {3766 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));3767 correct = False;3976 status = cli_close(cli1, fnum2); 3977 if (!NT_STATUS_IS_OK(status)) { 3978 printf("[3] close 2 failed (%s)\n", nt_errstr(status)); 3768 3979 goto fail; 3769 3980 } … … 3771 3982 /* This should fail - file should no longer be there. */ 3772 3983 3773 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) { 3984 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1); 3985 if (NT_STATUS_IS_OK(status)) { 3774 3986 printf("[3] open of %s succeeded should have been deleted on close !\n", fname); 3775 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3776 printf("[3] close failed (%s)\n", cli_errstr(cli1)); 3987 status = cli_close(cli1, fnum1); 3988 if (!NT_STATUS_IS_OK(status)) { 3989 printf("[3] close failed (%s)\n", nt_errstr(status)); 3777 3990 } 3778 3991 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3779 correct = False;3780 3992 goto fail; 3781 } else 3782 printf("third delete on close test succeeded.\n"); 3993 } 3994 3995 printf("third delete on close test succeeded.\n"); 3783 3996 3784 3997 /* Test 4 ... */ … … 3786 3999 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3787 4000 3788 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 3789 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 3790 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3791 correct = False; 4001 status = cli_ntcreate(cli1, fname, 0, 4002 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4003 FILE_ATTRIBUTE_NORMAL, 4004 FILE_SHARE_READ|FILE_SHARE_WRITE, 4005 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4006 if (!NT_STATUS_IS_OK(status)) { 4007 printf("[4] open of %s failed (%s)\n", fname, nt_errstr(status)); 3792 4008 goto fail; 3793 4009 } 3794 4010 3795 4011 /* This should succeed. */ 3796 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 3797 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0, &fnum2))) { 3798 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); 3799 correct = False; 4012 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4013 FILE_ATTRIBUTE_NORMAL, 4014 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4015 FILE_OPEN, 0, 0, &fnum2, NULL); 4016 if (!NT_STATUS_IS_OK(status)) { 4017 printf("[4] open - 2 of %s failed (%s)\n", fname, nt_errstr(status)); 3800 4018 goto fail; 3801 4019 } 3802 4020 3803 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum2))) {3804 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));3805 correct = False;4021 status = cli_close(cli1, fnum2); 4022 if (!NT_STATUS_IS_OK(status)) { 4023 printf("[4] close - 1 failed (%s)\n", nt_errstr(status)); 3806 4024 goto fail; 3807 4025 } 3808 4026 3809 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) {3810 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));3811 correct = False;4027 status = cli_nt_delete_on_close(cli1, fnum1, true); 4028 if (!NT_STATUS_IS_OK(status)) { 4029 printf("[4] setting delete_on_close failed (%s)\n", nt_errstr(status)); 3812 4030 goto fail; 3813 4031 } 3814 4032 3815 4033 /* This should fail - no more opens once delete on close set. */ 3816 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 3817 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 3818 FILE_OPEN, 0, 0, &fnum2))) { 4034 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4035 FILE_ATTRIBUTE_NORMAL, 4036 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4037 FILE_OPEN, 0, 0, &fnum2, NULL); 4038 if (NT_STATUS_IS_OK(status)) { 3819 4039 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname ); 3820 correct = False;3821 4040 goto fail; 3822 } else 3823 printf("fourth delete on close test succeeded.\n"); 3824 3825 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 3826 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1)); 3827 correct = False; 4041 } 4042 4043 status = cli_close(cli1, fnum1); 4044 if (!NT_STATUS_IS_OK(status)) { 4045 printf("[4] close - 2 failed (%s)\n", nt_errstr(status)); 3828 4046 goto fail; 3829 4047 } 4048 4049 printf("fourth delete on close test succeeded.\n"); 3830 4050 3831 4051 /* Test 5 ... */ … … 3833 4053 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3834 4054 3835 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1))) {3836 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));3837 correct = False;4055 status = cli_openx(cli1, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum1); 4056 if (!NT_STATUS_IS_OK(status)) { 4057 printf("[5] open of %s failed (%s)\n", fname, nt_errstr(status)); 3838 4058 goto fail; 3839 4059 } … … 3841 4061 /* This should fail - only allowed on NT opens with DELETE access. */ 3842 4062 3843 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) { 4063 status = cli_nt_delete_on_close(cli1, fnum1, true); 4064 if (NT_STATUS_IS_OK(status)) { 3844 4065 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n"); 3845 correct = False;3846 4066 goto fail; 3847 4067 } 3848 4068 3849 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3850 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));3851 correct = False;4069 status = cli_close(cli1, fnum1); 4070 if (!NT_STATUS_IS_OK(status)) { 4071 printf("[5] close failed (%s)\n", nt_errstr(status)); 3852 4072 goto fail; 3853 4073 } … … 3859 4079 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3860 4080 3861 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, 3862 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 3863 FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 3864 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3865 correct = False; 4081 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, 4082 FILE_ATTRIBUTE_NORMAL, 4083 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4084 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4085 if (!NT_STATUS_IS_OK(status)) { 4086 printf("[6] open of %s failed (%s)\n", fname, 4087 nt_errstr(status)); 3866 4088 goto fail; 3867 4089 } … … 3869 4091 /* This should fail - only allowed on NT opens with DELETE access. */ 3870 4092 3871 if (NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) { 4093 status = cli_nt_delete_on_close(cli1, fnum1, true); 4094 if (NT_STATUS_IS_OK(status)) { 3872 4095 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n"); 3873 correct = False;3874 4096 goto fail; 3875 4097 } 3876 4098 3877 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3878 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));3879 correct = False;4099 status = cli_close(cli1, fnum1); 4100 if (!NT_STATUS_IS_OK(status)) { 4101 printf("[6] close failed (%s)\n", nt_errstr(status)); 3880 4102 goto fail; 3881 4103 } … … 3887 4109 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 3888 4110 3889 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 3890 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 3891 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3892 correct = False; 4111 status = cli_ntcreate(cli1, fname, 0, 4112 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4113 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 4114 0, 0, &fnum1, NULL); 4115 if (!NT_STATUS_IS_OK(status)) { 4116 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status)); 3893 4117 goto fail; 3894 4118 } 3895 4119 3896 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) { 4120 status = cli_nt_delete_on_close(cli1, fnum1, true); 4121 if (!NT_STATUS_IS_OK(status)) { 3897 4122 printf("[7] setting delete_on_close on file failed !\n"); 3898 correct = False;3899 4123 goto fail; 3900 4124 } 3901 4125 3902 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, false))) { 4126 status = cli_nt_delete_on_close(cli1, fnum1, false); 4127 if (!NT_STATUS_IS_OK(status)) { 3903 4128 printf("[7] unsetting delete_on_close on file failed !\n"); 3904 correct = False;3905 4129 goto fail; 3906 4130 } 3907 4131 3908 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3909 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));3910 correct = False;4132 status = cli_close(cli1, fnum1); 4133 if (!NT_STATUS_IS_OK(status)) { 4134 printf("[7] close - 1 failed (%s)\n", nt_errstr(status)); 3911 4135 goto fail; 3912 4136 } 3913 4137 3914 4138 /* This next open should succeed - we reset the flag. */ 3915 3916 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) { 3917 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3918 correct = False; 4139 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1); 4140 if (!NT_STATUS_IS_OK(status)) { 4141 printf("[7] open of %s failed (%s)\n", fname, nt_errstr(status)); 3919 4142 goto fail; 3920 4143 } 3921 4144 3922 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3923 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));3924 correct = False;4145 status = cli_close(cli1, fnum1); 4146 if (!NT_STATUS_IS_OK(status)) { 4147 printf("[7] close - 2 failed (%s)\n", nt_errstr(status)); 3925 4148 goto fail; 3926 4149 } … … 3928 4151 printf("seventh delete on close test succeeded.\n"); 3929 4152 3930 /* Test 7... */4153 /* Test 8 ... */ 3931 4154 cli_setatr(cli1, fname, 0, 0); 3932 4155 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); … … 3934 4157 if (!torture_open_connection(&cli2, 1)) { 3935 4158 printf("[8] failed to open second connection.\n"); 3936 correct = False;3937 4159 goto fail; 3938 4160 } 3939 4161 3940 cli_sockopt(cli1, sockops); 3941 3942 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 3943 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 3944 FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 3945 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 3946 correct = False; 4162 smbXcli_conn_set_sockopt(cli1->conn, sockops); 4163 4164 status = cli_ntcreate(cli1, fname, 0, 4165 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4166 FILE_ATTRIBUTE_NORMAL, 4167 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4168 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4169 if (!NT_STATUS_IS_OK(status)) { 4170 printf("[8] open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 3947 4171 goto fail; 3948 4172 } 3949 4173 3950 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 3951 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 3952 FILE_OPEN, 0, 0, &fnum2))) { 3953 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 3954 correct = False; 4174 status = cli_ntcreate(cli2, fname, 0, 4175 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4176 FILE_ATTRIBUTE_NORMAL, 4177 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4178 FILE_OPEN, 0, 0, &fnum2, NULL); 4179 if (!NT_STATUS_IS_OK(status)) { 4180 printf("[8] open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 3955 4181 goto fail; 3956 4182 } 3957 4183 3958 if (!NT_STATUS_IS_OK(cli_nt_delete_on_close(cli1, fnum1, true))) { 4184 status = cli_nt_delete_on_close(cli1, fnum1, true); 4185 if (!NT_STATUS_IS_OK(status)) { 3959 4186 printf("[8] setting delete_on_close on file failed !\n"); 3960 correct = False;3961 4187 goto fail; 3962 4188 } 3963 4189 3964 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {3965 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));3966 correct = False;4190 status = cli_close(cli1, fnum1); 4191 if (!NT_STATUS_IS_OK(status)) { 4192 printf("[8] close - 1 failed (%s)\n", nt_errstr(status)); 3967 4193 goto fail; 3968 4194 } 3969 4195 3970 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) {3971 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));3972 correct = False;4196 status = cli_close(cli2, fnum2); 4197 if (!NT_STATUS_IS_OK(status)) { 4198 printf("[8] close - 2 failed (%s)\n", nt_errstr(status)); 3973 4199 goto fail; 3974 4200 } 3975 4201 3976 4202 /* This should fail.. */ 3977 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) { 4203 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1); 4204 if (NT_STATUS_IS_OK(status)) { 3978 4205 printf("[8] open of %s succeeded should have been deleted on close !\n", fname); 3979 4206 goto fail; 3980 correct = False; 3981 } else 3982 printf("eighth delete on close test succeeded.\n"); 4207 } 4208 4209 printf("eighth delete on close test succeeded.\n"); 4210 4211 /* Test 9 ... */ 3983 4212 3984 4213 /* This should fail - we need to set DELETE_ACCESS. */ 3985 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA, 3986 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) { 4214 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, 4215 FILE_ATTRIBUTE_NORMAL, 4216 FILE_SHARE_NONE, 4217 FILE_OVERWRITE_IF, 4218 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL); 4219 if (NT_STATUS_IS_OK(status)) { 3987 4220 printf("[9] open of %s succeeded should have failed!\n", fname); 3988 correct = False;3989 4221 goto fail; 3990 4222 } … … 3992 4224 printf("ninth delete on close test succeeded.\n"); 3993 4225 3994 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 3995 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0, &fnum1))) { 3996 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 3997 correct = False; 4226 /* Test 10 ... */ 4227 4228 status = cli_ntcreate(cli1, fname, 0, 4229 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4230 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 4231 FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 4232 0, &fnum1, NULL); 4233 if (!NT_STATUS_IS_OK(status)) { 4234 printf("[10] open of %s failed (%s)\n", fname, nt_errstr(status)); 3998 4235 goto fail; 3999 4236 } 4000 4237 4001 4238 /* This should delete the file. */ 4002 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {4003 printf("[10] close failed (%s)\n", cli_errstr(cli1));4004 correct = False;4239 status = cli_close(cli1, fnum1); 4240 if (!NT_STATUS_IS_OK(status)) { 4241 printf("[10] close failed (%s)\n", nt_errstr(status)); 4005 4242 goto fail; 4006 4243 } 4007 4244 4008 4245 /* This should fail.. */ 4009 if (NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_NONE, &fnum1))) { 4246 status = cli_openx(cli1, fname, O_RDONLY, DENY_NONE, &fnum1); 4247 if (NT_STATUS_IS_OK(status)) { 4010 4248 printf("[10] open of %s succeeded should have been deleted on close !\n", fname); 4011 4249 goto fail; 4012 correct = False; 4013 } else 4014 printf("tenth delete on close test succeeded.\n"); 4250 } 4251 4252 printf("tenth delete on close test succeeded.\n"); 4253 4254 /* Test 11 ... */ 4015 4255 4016 4256 cli_setatr(cli1, fname, 0, 0); 4017 4257 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4018 4258 4019 /* What error do we get when attempting to open a read-only file with 4020 delete access ? */ 4259 /* Can we open a read-only file with delete access? */ 4021 4260 4022 4261 /* Create a readonly file. */ 4023 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, 4024 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4025 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1)); 4026 correct = False; 4262 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, 4263 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, 4264 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4265 if (!NT_STATUS_IS_OK(status)) { 4266 printf("[11] open of %s failed (%s)\n", fname, nt_errstr(status)); 4027 4267 goto fail; 4028 4268 } 4029 4269 4030 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) {4031 printf("[11] close failed (%s)\n", cli_errstr(cli1));4032 correct = False;4270 status = cli_close(cli1, fnum1); 4271 if (!NT_STATUS_IS_OK(status)) { 4272 printf("[11] close failed (%s)\n", nt_errstr(status)); 4033 4273 goto fail; 4034 4274 } 4035 4275 4036 4276 /* Now try open for delete access. */ 4037 if (NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS, 4038 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4039 FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4040 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname); 4041 cli_close(cli1, fnum1); 4277 status = cli_ntcreate(cli1, fname, 0, 4278 FILE_READ_ATTRIBUTES|DELETE_ACCESS, 4279 0, 4280 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4281 FILE_OPEN, 0, 0, &fnum1, NULL); 4282 if (!NT_STATUS_IS_OK(status)) { 4283 printf("[11] open of %s failed: %s\n", fname, nt_errstr(status)); 4042 4284 goto fail; 4043 correct = False; 4044 } else { 4045 NTSTATUS nterr = cli_nt_error(cli1); 4046 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) { 4047 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr)); 4048 goto fail; 4049 correct = False; 4050 } else { 4051 printf("eleventh delete on close test succeeded.\n"); 4052 } 4053 } 4285 } 4286 4287 cli_close(cli1, fnum1); 4288 4289 printf("eleventh delete on close test succeeded.\n"); 4290 4291 /* 4292 * Test 12 4293 * like test 4 but with initial delete on close 4294 */ 4295 4296 cli_setatr(cli1, fname, 0, 0); 4297 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4298 4299 status = cli_ntcreate(cli1, fname, 0, 4300 FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS, 4301 FILE_ATTRIBUTE_NORMAL, 4302 FILE_SHARE_READ|FILE_SHARE_WRITE, 4303 FILE_OVERWRITE_IF, 4304 FILE_DELETE_ON_CLOSE, 0, &fnum1, NULL); 4305 if (!NT_STATUS_IS_OK(status)) { 4306 printf("[12] open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 4307 goto fail; 4308 } 4309 4310 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4311 FILE_ATTRIBUTE_NORMAL, 4312 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4313 FILE_OPEN, 0, 0, &fnum2, NULL); 4314 if (!NT_STATUS_IS_OK(status)) { 4315 printf("[12] open 2 of %s failed(%s).\n", fname, nt_errstr(status)); 4316 goto fail; 4317 } 4318 4319 status = cli_close(cli1, fnum2); 4320 if (!NT_STATUS_IS_OK(status)) { 4321 printf("[12] close 1 failed (%s)\n", nt_errstr(status)); 4322 goto fail; 4323 } 4324 4325 status = cli_nt_delete_on_close(cli1, fnum1, true); 4326 if (!NT_STATUS_IS_OK(status)) { 4327 printf("[12] setting delete_on_close failed (%s)\n", nt_errstr(status)); 4328 goto fail; 4329 } 4330 4331 /* This should fail - no more opens once delete on close set. */ 4332 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4333 FILE_ATTRIBUTE_NORMAL, 4334 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4335 FILE_OPEN, 0, 0, &fnum2, NULL); 4336 if (NT_STATUS_IS_OK(status)) { 4337 printf("[12] open 3 of %s succeeded - should fail).\n", fname); 4338 goto fail; 4339 } 4340 4341 status = cli_nt_delete_on_close(cli1, fnum1, false); 4342 if (!NT_STATUS_IS_OK(status)) { 4343 printf("[12] unsetting delete_on_close failed (%s)\n", nt_errstr(status)); 4344 goto fail; 4345 } 4346 4347 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4348 FILE_ATTRIBUTE_NORMAL, 4349 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4350 FILE_OPEN, 0, 0, &fnum2, NULL); 4351 if (!NT_STATUS_IS_OK(status)) { 4352 printf("[12] open 4 of %s failed (%s)\n", fname, nt_errstr(status)); 4353 goto fail; 4354 } 4355 4356 status = cli_close(cli1, fnum2); 4357 if (!NT_STATUS_IS_OK(status)) { 4358 printf("[12] close 2 failed (%s)\n", nt_errstr(status)); 4359 goto fail; 4360 } 4361 4362 status = cli_close(cli1, fnum1); 4363 if (!NT_STATUS_IS_OK(status)) { 4364 printf("[12] close 3 failed (%s)\n", nt_errstr(status)); 4365 goto fail; 4366 } 4367 4368 /* 4369 * setting delete on close on the handle does 4370 * not unset the initial delete on close... 4371 */ 4372 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4373 FILE_ATTRIBUTE_NORMAL, 4374 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4375 FILE_OPEN, 0, 0, &fnum2, NULL); 4376 if (NT_STATUS_IS_OK(status)) { 4377 printf("[12] open 5 of %s succeeded - should fail).\n", fname); 4378 goto fail; 4379 } else if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { 4380 printf("ntcreate returned %s, expected " 4381 "NT_STATUS_OBJECT_NAME_NOT_FOUND\n", 4382 nt_errstr(status)); 4383 goto fail; 4384 } 4385 4386 printf("twelfth delete on close test succeeded.\n"); 4387 4054 4388 4055 4389 printf("finished delete test\n"); 4390 4391 correct = true; 4056 4392 4057 4393 fail: … … 4070 4406 if (cli2 && !torture_close_connection(cli2)) { 4071 4407 correct = False; 4408 } 4409 return correct; 4410 } 4411 4412 4413 /* 4414 Test wildcard delete. 4415 */ 4416 static bool run_wild_deletetest(int dummy) 4417 { 4418 struct cli_state *cli = NULL; 4419 const char *dname = "\\WTEST"; 4420 const char *fname = "\\WTEST\\A"; 4421 const char *wunlink_name = "\\WTEST\\*"; 4422 uint16_t fnum1 = (uint16_t)-1; 4423 bool correct = false; 4424 NTSTATUS status; 4425 4426 printf("starting wildcard delete test\n"); 4427 4428 if (!torture_open_connection(&cli, 0)) { 4429 return false; 4430 } 4431 4432 smbXcli_conn_set_sockopt(cli->conn, sockops); 4433 4434 cli_unlink(cli, fname, 0); 4435 cli_rmdir(cli, dname); 4436 status = cli_mkdir(cli, dname); 4437 if (!NT_STATUS_IS_OK(status)) { 4438 printf("mkdir of %s failed %s!\n", dname, nt_errstr(status)); 4439 goto fail; 4440 } 4441 status = cli_openx(cli, fname, O_CREAT|O_RDONLY, DENY_NONE, &fnum1); 4442 if (!NT_STATUS_IS_OK(status)) { 4443 printf("open of %s failed %s!\n", fname, nt_errstr(status)); 4444 goto fail; 4445 } 4446 status = cli_close(cli, fnum1); 4447 fnum1 = -1; 4448 4449 /* 4450 * Note the unlink attribute-type of zero. This should 4451 * map into FILE_ATTRIBUTE_NORMAL at the server even 4452 * on a wildcard delete. 4453 */ 4454 4455 status = cli_unlink(cli, wunlink_name, 0); 4456 if (!NT_STATUS_IS_OK(status)) { 4457 printf("unlink of %s failed %s!\n", 4458 wunlink_name, nt_errstr(status)); 4459 goto fail; 4460 } 4461 4462 printf("finished wildcard delete test\n"); 4463 4464 correct = true; 4465 4466 fail: 4467 4468 if (fnum1 != (uint16_t)-1) cli_close(cli, fnum1); 4469 cli_unlink(cli, fname, 0); 4470 cli_rmdir(cli, dname); 4471 4472 if (cli && !torture_close_connection(cli)) { 4473 correct = false; 4072 4474 } 4073 4475 return correct; … … 4094 4496 cli_unlink(cli, fname_ln, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4095 4497 4096 cli_sockopt(cli, sockops);4498 smbXcli_conn_set_sockopt(cli->conn, sockops); 4097 4499 4098 4500 /* Create the file. */ 4099 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 4100 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 4101 return false; 4102 } 4103 4104 if (!NT_STATUS_IS_OK(cli_close(cli, fnum))) { 4105 printf("close1 failed (%s)\n", cli_errstr(cli)); 4501 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 4502 if (!NT_STATUS_IS_OK(status)) { 4503 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 4504 return false; 4505 } 4506 4507 status = cli_close(cli, fnum); 4508 if (!NT_STATUS_IS_OK(status)) { 4509 printf("close1 failed (%s)\n", nt_errstr(status)); 4106 4510 return false; 4107 4511 } 4108 4512 4109 4513 /* Now create a hardlink. */ 4110 if (!NT_STATUS_IS_OK(cli_nt_hardlink(cli, fname, fname_ln))) { 4111 printf("nt hardlink failed (%s)\n", cli_errstr(cli)); 4514 status = cli_nt_hardlink(cli, fname, fname_ln); 4515 if (!NT_STATUS_IS_OK(status)) { 4516 printf("nt hardlink failed (%s)\n", nt_errstr(status)); 4112 4517 return false; 4113 4518 } … … 4117 4522 FILE_ATTRIBUTE_NORMAL, 4118 4523 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4119 FILE_OPEN_IF, 0, 0, &fnum );4524 FILE_OPEN_IF, 0, 0, &fnum, NULL); 4120 4525 if (!NT_STATUS_IS_OK(status)) { 4121 4526 printf("ntcreate of %s failed (%s)\n", fname, nt_errstr(status)); … … 4127 4532 FILE_ATTRIBUTE_NORMAL, 4128 4533 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4129 FILE_OPEN_IF, 0, 0, &fnum1 );4534 FILE_OPEN_IF, 0, 0, &fnum1, NULL); 4130 4535 if (!NT_STATUS_IS_OK(status)) { 4131 4536 printf("ntcreate of %s failed (%s)\n", fname_ln, nt_errstr(status)); … … 4201 4606 } 4202 4607 4203 cli_sockopt(cli, sockops);4204 4205 d_printf("Capabilities 0x%08x\n", cli->capabilities);4608 smbXcli_conn_set_sockopt(cli->conn, sockops); 4609 4610 d_printf("Capabilities 0x%08x\n", smb1cli_conn_capabilities(cli->conn)); 4206 4611 4207 4612 if (!torture_close_connection(cli)) { … … 4242 4647 bool correct = True; 4243 4648 uint16_t fnum1, fnum2; 4649 NTSTATUS status; 4244 4650 4245 4651 printf("starting xcopy test\n"); … … 4249 4655 } 4250 4656 4251 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,4252 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,4253 FILE_SHARE_NONE, FILE_OVERWRITE_IF,4254 0x4044, 0, &fnum1))) {4255 printf("First open failed - %s\n", cli_errstr(cli1));4256 return False; 4257 } 4258 4259 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0,4260 SECOND_DESIRED_ACCESS, 0,4261 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,4262 0x200000, 0, &fnum2))) {4263 printf("second open failed - %s\n", cli_errstr(cli1));4657 status = cli_ntcreate(cli1, fname, 0, FIRST_DESIRED_ACCESS, 4658 FILE_ATTRIBUTE_ARCHIVE, FILE_SHARE_NONE, 4659 FILE_OVERWRITE_IF, 0x4044, 0, &fnum1, NULL); 4660 if (!NT_STATUS_IS_OK(status)) { 4661 printf("First open failed - %s\n", nt_errstr(status)); 4662 return False; 4663 } 4664 4665 status = cli_ntcreate(cli1, fname, 0, SECOND_DESIRED_ACCESS, 0, 4666 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4667 FILE_OPEN, 0x200000, 0, &fnum2, NULL); 4668 if (!NT_STATUS_IS_OK(status)) { 4669 printf("second open failed - %s\n", nt_errstr(status)); 4264 4670 return False; 4265 4671 } … … 4293 4699 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4294 4700 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4295 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 4296 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4297 printf("First open failed - %s\n", cli_errstr(cli1)); 4298 return False; 4299 } 4300 4301 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) { 4302 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1)); 4701 4702 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4703 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, 4704 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4705 if (!NT_STATUS_IS_OK(status)) { 4706 printf("First open failed - %s\n", nt_errstr(status)); 4707 return False; 4708 } 4709 4710 status = cli_rename(cli1, fname, fname1); 4711 if (!NT_STATUS_IS_OK(status)) { 4712 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", nt_errstr(status)); 4303 4713 } else { 4304 4714 printf("First rename succeeded (SHARE_READ) - this should have failed !\n"); … … 4306 4716 } 4307 4717 4308 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4309 printf("close - 1 failed (%s)\n", cli_errstr(cli1)); 4718 status = cli_close(cli1, fnum1); 4719 if (!NT_STATUS_IS_OK(status)) { 4720 printf("close - 1 failed (%s)\n", nt_errstr(status)); 4310 4721 return False; 4311 4722 } … … 4319 4730 FILE_SHARE_DELETE|FILE_SHARE_READ, 4320 4731 #endif 4321 FILE_OVERWRITE_IF, 0, 0, &fnum1); 4322 if (!NT_STATUS_IS_OK(status)) { 4323 printf("Second open failed - %s\n", cli_errstr(cli1)); 4324 return False; 4325 } 4326 4327 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) { 4328 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1)); 4732 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4733 if (!NT_STATUS_IS_OK(status)) { 4734 printf("Second open failed - %s\n", nt_errstr(status)); 4735 return False; 4736 } 4737 4738 status = cli_rename(cli1, fname, fname1); 4739 if (!NT_STATUS_IS_OK(status)) { 4740 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", nt_errstr(status)); 4329 4741 correct = False; 4330 4742 } else { … … 4332 4744 } 4333 4745 4334 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4335 printf("close - 2 failed (%s)\n", cli_errstr(cli1)); 4746 status = cli_close(cli1, fnum1); 4747 if (!NT_STATUS_IS_OK(status)) { 4748 printf("close - 2 failed (%s)\n", nt_errstr(status)); 4336 4749 return False; 4337 4750 } … … 4340 4753 cli_unlink(cli1, fname1, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4341 4754 4342 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL, 4343 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4344 printf("Third open failed - %s\n", cli_errstr(cli1)); 4755 status = cli_ntcreate(cli1, fname, 0, READ_CONTROL_ACCESS, 4756 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 4757 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4758 if (!NT_STATUS_IS_OK(status)) { 4759 printf("Third open failed - %s\n", nt_errstr(status)); 4345 4760 return False; 4346 4761 } … … 4352 4767 4353 4768 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL, 4354 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2 ))) {4769 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) { 4355 4770 printf("Fourth open failed - %s\n", cli_errstr(cli1)); 4356 4771 return False; … … 4368 4783 #endif 4369 4784 4370 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) { 4371 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1)); 4785 status = cli_rename(cli1, fname, fname1); 4786 if (!NT_STATUS_IS_OK(status)) { 4787 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", nt_errstr(status)); 4372 4788 correct = False; 4373 4789 } else { … … 4375 4791 } 4376 4792 4377 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4378 printf("close - 3 failed (%s)\n", cli_errstr(cli1)); 4793 status = cli_close(cli1, fnum1); 4794 if (!NT_STATUS_IS_OK(status)) { 4795 printf("close - 3 failed (%s)\n", nt_errstr(status)); 4379 4796 return False; 4380 4797 } … … 4385 4802 /*----*/ 4386 4803 4387 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 4388 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4389 printf("Fourth open failed - %s\n", cli_errstr(cli1)); 4390 return False; 4391 } 4392 4393 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) { 4394 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1)); 4804 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4805 FILE_ATTRIBUTE_NORMAL, 4806 FILE_SHARE_READ | FILE_SHARE_WRITE, 4807 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4808 if (!NT_STATUS_IS_OK(status)) { 4809 printf("Fourth open failed - %s\n", nt_errstr(status)); 4810 return False; 4811 } 4812 4813 status = cli_rename(cli1, fname, fname1); 4814 if (!NT_STATUS_IS_OK(status)) { 4815 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", nt_errstr(status)); 4395 4816 } else { 4396 4817 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n"); … … 4398 4819 } 4399 4820 4400 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4401 printf("close - 4 failed (%s)\n", cli_errstr(cli1)); 4821 status = cli_close(cli1, fnum1); 4822 if (!NT_STATUS_IS_OK(status)) { 4823 printf("close - 4 failed (%s)\n", nt_errstr(status)); 4402 4824 return False; 4403 4825 } … … 4408 4830 /*--*/ 4409 4831 4410 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 4411 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4412 printf("Fifth open failed - %s\n", cli_errstr(cli1)); 4413 return False; 4414 } 4415 4416 if (!NT_STATUS_IS_OK(cli_rename(cli1, fname, fname1))) { 4417 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", 4418 cli_errstr(cli1)); 4832 status = cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, 4833 FILE_ATTRIBUTE_NORMAL, 4834 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 4835 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4836 if (!NT_STATUS_IS_OK(status)) { 4837 printf("Fifth open failed - %s\n", nt_errstr(status)); 4838 return False; 4839 } 4840 4841 status = cli_rename(cli1, fname, fname1); 4842 if (!NT_STATUS_IS_OK(status)) { 4843 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have succeeded - %s ! \n", nt_errstr(status)); 4419 4844 correct = False; 4420 4845 } else { 4421 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));4846 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", nt_errstr(status)); 4422 4847 } 4423 4848 … … 4427 4852 4428 4853 /* if (!NT_STATUS_OP(cli_ntcreate(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL, 4429 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum2))) { 4854 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 4855 FILE_OVERWRITE_IF, 0, 0, &fnum2, NULL))) { 4430 4856 printf("Opening original file after rename of open file fails: %s\n", 4431 4857 cli_errstr(cli1)); … … 4437 4863 4438 4864 /*--*/ 4439 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4440 printf("close - 5 failed (%s)\n", cli_errstr(cli1)); 4865 status = cli_close(cli1, fnum1); 4866 if (!NT_STATUS_IS_OK(status)) { 4867 printf("close - 5 failed (%s)\n", nt_errstr(status)); 4441 4868 return False; 4442 4869 } 4443 4870 4444 4871 /* Check that the renamed file has FILE_ATTRIBUTE_ARCHIVE. */ 4445 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname1, &attr, NULL, NULL))) { 4872 status = cli_getatr(cli1, fname1, &attr, NULL, NULL); 4873 if (!NT_STATUS_IS_OK(status)) { 4446 4874 printf("getatr on file %s failed - %s ! \n", 4447 fname1, 4448 cli_errstr(cli1)); 4875 fname1, nt_errstr(status)); 4449 4876 correct = False; 4450 4877 } else { … … 4477 4904 uint16_t fnum; 4478 4905 int num_pipes = 0; 4906 NTSTATUS status; 4479 4907 4480 4908 printf("starting pipenumber test\n"); … … 4483 4911 } 4484 4912 4485 cli_sockopt(cli1, sockops);4913 smbXcli_conn_set_sockopt(cli1->conn, sockops); 4486 4914 while(1) { 4487 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, 4488 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0, &fnum))) { 4489 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1)); 4915 status = cli_ntcreate(cli1, pipe_name, 0, FILE_READ_DATA, 4916 FILE_ATTRIBUTE_NORMAL, 4917 FILE_SHARE_READ|FILE_SHARE_WRITE, 4918 FILE_OPEN_IF, 0, 0, &fnum, NULL); 4919 if (!NT_STATUS_IS_OK(status)) { 4920 printf("Open of pipe %s failed with error (%s)\n", pipe_name, nt_errstr(status)); 4490 4921 break; 4491 4922 } … … 4509 4940 uint16_t fnum1, fnum2; 4510 4941 char buf[20]; 4511 SMB_OFF_Tfsize;4942 off_t fsize; 4512 4943 bool correct = True; 4513 4944 char *tmp_path; … … 4523 4954 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4524 4955 4525 cli_sockopt(cli1, sockops); 4526 4527 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) { 4528 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 4529 return False; 4530 } 4531 4532 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4533 printf("close2 failed (%s)\n", cli_errstr(cli1)); 4534 return False; 4535 } 4536 4537 if (!NT_STATUS_IS_OK(cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0))) { 4538 printf("cli_setatr failed (%s)\n", cli_errstr(cli1)); 4539 return False; 4540 } 4541 4542 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) { 4543 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 4956 smbXcli_conn_set_sockopt(cli1->conn, sockops); 4957 4958 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 4959 if (!NT_STATUS_IS_OK(status)) { 4960 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 4961 return False; 4962 } 4963 4964 status = cli_close(cli1, fnum1); 4965 if (!NT_STATUS_IS_OK(status)) { 4966 printf("close2 failed (%s)\n", nt_errstr(status)); 4967 return False; 4968 } 4969 4970 status = cli_setatr(cli1, fname, FILE_ATTRIBUTE_READONLY, 0); 4971 if (!NT_STATUS_IS_OK(status)) { 4972 printf("cli_setatr failed (%s)\n", nt_errstr(status)); 4973 return False; 4974 } 4975 4976 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1); 4977 if (!NT_STATUS_IS_OK(status)) { 4978 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 4544 4979 return False; 4545 4980 } 4546 4981 4547 4982 /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */ 4548 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);4549 4550 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,4983 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2); 4984 4985 if (check_error(__LINE__, status, ERRDOS, ERRnoaccess, 4551 4986 NT_STATUS_ACCESS_DENIED)) { 4552 4987 printf("correct error code ERRDOS/ERRnoaccess returned\n"); … … 4561 4996 cli_setatr(cli1, fname, 0, 0); 4562 4997 4563 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1))) { 4564 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1)); 4998 status = cli_openx(cli1, fname, O_RDONLY, DENY_WRITE, &fnum1); 4999 if (!NT_STATUS_IS_OK(status)) { 5000 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 4565 5001 return False; 4566 5002 } 4567 5003 4568 5004 /* This will fail - but the error should be ERRshare. */ 4569 cli_open(cli1, fname, O_RDWR, DENY_ALL, &fnum2);4570 4571 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,5005 status = cli_openx(cli1, fname, O_RDWR, DENY_ALL, &fnum2); 5006 5007 if (check_error(__LINE__, status, ERRDOS, ERRbadshare, 4572 5008 NT_STATUS_SHARING_VIOLATION)) { 4573 5009 printf("correct error code ERRDOS/ERRbadshare returned\n"); 4574 5010 } 4575 5011 4576 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4577 printf("close2 failed (%s)\n", cli_errstr(cli1)); 5012 status = cli_close(cli1, fnum1); 5013 if (!NT_STATUS_IS_OK(status)) { 5014 printf("close2 failed (%s)\n", nt_errstr(status)); 4578 5015 return False; 4579 5016 } … … 4584 5021 4585 5022 /* Test truncate open disposition on file opened for read. */ 4586 4587 if (!NT_STATUS_IS_OK( cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1))) {4588 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));5023 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum1); 5024 if (!NT_STATUS_IS_OK(status)) { 5025 printf("(3) open (1) of %s failed (%s)\n", fname, nt_errstr(status)); 4589 5026 return False; 4590 5027 } … … 4600 5037 } 4601 5038 4602 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4603 printf("(3) close1 failed (%s)\n", cli_errstr(cli1)); 5039 status = cli_close(cli1, fnum1); 5040 if (!NT_STATUS_IS_OK(status)) { 5041 printf("(3) close1 failed (%s)\n", nt_errstr(status)); 4604 5042 return False; 4605 5043 } 4606 5044 4607 5045 /* Ensure size == 20. */ 4608 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) { 4609 printf("(3) getatr failed (%s)\n", cli_errstr(cli1)); 5046 status = cli_getatr(cli1, fname, NULL, &fsize, NULL); 5047 if (!NT_STATUS_IS_OK(status)) { 5048 printf("(3) getatr failed (%s)\n", nt_errstr(status)); 4610 5049 return False; 4611 5050 } … … 4617 5056 4618 5057 /* Now test if we can truncate a file opened for readonly. */ 4619 4620 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1))) { 4621 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1)); 4622 return False; 4623 } 4624 4625 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4626 printf("close2 failed (%s)\n", cli_errstr(cli1)); 5058 status = cli_openx(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE, &fnum1); 5059 if (!NT_STATUS_IS_OK(status)) { 5060 printf("(3) open (2) of %s failed (%s)\n", fname, nt_errstr(status)); 5061 return False; 5062 } 5063 5064 status = cli_close(cli1, fnum1); 5065 if (!NT_STATUS_IS_OK(status)) { 5066 printf("close2 failed (%s)\n", nt_errstr(status)); 4627 5067 return False; 4628 5068 } 4629 5069 4630 5070 /* Ensure size == 0. */ 4631 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) { 4632 printf("(3) getatr failed (%s)\n", cli_errstr(cli1)); 5071 status = cli_getatr(cli1, fname, NULL, &fsize, NULL); 5072 if (!NT_STATUS_IS_OK(status)) { 5073 printf("(3) getatr failed (%s)\n", nt_errstr(status)); 4633 5074 return False; 4634 5075 } … … 4643 5084 4644 5085 printf("Do ctemp tests\n"); 4645 if (!NT_STATUS_IS_OK(cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path))) { 4646 printf("ctemp failed (%s)\n", cli_errstr(cli1)); 4647 return False; 4648 } 5086 status = cli_ctemp(cli1, talloc_tos(), "\\", &fnum1, &tmp_path); 5087 if (!NT_STATUS_IS_OK(status)) { 5088 printf("ctemp failed (%s)\n", nt_errstr(status)); 5089 return False; 5090 } 5091 4649 5092 printf("ctemp gave path %s\n", tmp_path); 4650 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4651 printf("close of temp failed (%s)\n", cli_errstr(cli1)); 4652 } 4653 if (!NT_STATUS_IS_OK(cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 4654 printf("unlink of temp failed (%s)\n", cli_errstr(cli1)); 5093 status = cli_close(cli1, fnum1); 5094 if (!NT_STATUS_IS_OK(status)) { 5095 printf("close of temp failed (%s)\n", nt_errstr(status)); 5096 } 5097 5098 status = cli_unlink(cli1, tmp_path, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 5099 if (!NT_STATUS_IS_OK(status)) { 5100 printf("unlink of temp failed (%s)\n", nt_errstr(status)); 4655 5101 } 4656 5102 … … 4664 5110 cli_unlink(cli2, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4665 5111 4666 cli_sockopt(cli2, sockops);5112 smbXcli_conn_set_sockopt(cli2->conn, sockops); 4667 5113 4668 5114 printf("TEST #1 testing 2 non-io opens (no delete)\n"); 4669 4670 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4671 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4672 printf("TEST #1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4673 return False; 4674 } 4675 4676 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4677 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4678 printf("TEST #1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 4679 return False; 4680 } 4681 4682 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4683 printf("TEST #1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4684 return False; 4685 } 4686 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 4687 printf("TEST #1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 5115 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, 5116 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5117 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5118 if (!NT_STATUS_IS_OK(status)) { 5119 printf("TEST #1 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5120 return False; 5121 } 5122 5123 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, 5124 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5125 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5126 if (!NT_STATUS_IS_OK(status)) { 5127 printf("TEST #1 open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 5128 return False; 5129 } 5130 5131 status = cli_close(cli1, fnum1); 5132 if (!NT_STATUS_IS_OK(status)) { 5133 printf("TEST #1 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5134 return False; 5135 } 5136 5137 status = cli_close(cli2, fnum2); 5138 if (!NT_STATUS_IS_OK(status)) { 5139 printf("TEST #1 close 2 of %s failed (%s)\n", fname, nt_errstr(status)); 4688 5140 return False; 4689 5141 } … … 4695 5147 printf("TEST #2 testing 2 non-io opens (first with delete)\n"); 4696 5148 4697 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4698 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4699 printf("TEST #2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4700 return False; 4701 } 4702 4703 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4704 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4705 printf("TEST #2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 4706 return False; 4707 } 4708 4709 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4710 printf("TEST #2 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4711 return False; 4712 } 4713 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 4714 printf("TEST #2 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1)); 5149 status = cli_ntcreate(cli1, fname, 0, 5150 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5151 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5152 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5153 if (!NT_STATUS_IS_OK(status)) { 5154 printf("TEST #2 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5155 return False; 5156 } 5157 5158 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, 5159 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5160 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5161 if (!NT_STATUS_IS_OK(status)) { 5162 printf("TEST #2 open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 5163 return False; 5164 } 5165 5166 status = cli_close(cli1, fnum1); 5167 if (!NT_STATUS_IS_OK(status)) { 5168 printf("TEST #2 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5169 return False; 5170 } 5171 5172 status = cli_close(cli2, fnum2); 5173 if (!NT_STATUS_IS_OK(status)) { 5174 printf("TEST #2 close 2 of %s failed (%s)\n", fname, nt_errstr(status)); 4715 5175 return False; 4716 5176 } … … 4722 5182 printf("TEST #3 testing 2 non-io opens (second with delete)\n"); 4723 5183 4724 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4725 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4726 printf("TEST #3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4727 return False; 4728 } 4729 4730 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4731 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4732 printf("TEST #3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 4733 return False; 4734 } 4735 4736 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4737 printf("TEST #3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4738 return False; 4739 } 4740 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 4741 printf("TEST #3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 5184 status = cli_ntcreate(cli1, fname, 0, FILE_READ_ATTRIBUTES, 5185 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5186 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5187 if (!NT_STATUS_IS_OK(status)) { 5188 printf("TEST #3 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5189 return False; 5190 } 5191 5192 status = cli_ntcreate(cli2, fname, 0, 5193 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5194 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5195 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5196 if (!NT_STATUS_IS_OK(status)) { 5197 printf("TEST #3 open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 5198 return False; 5199 } 5200 5201 status = cli_close(cli1, fnum1); 5202 if (!NT_STATUS_IS_OK(status)) { 5203 printf("TEST #3 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5204 return False; 5205 } 5206 5207 status = cli_close(cli2, fnum2); 5208 if (!NT_STATUS_IS_OK(status)) { 5209 printf("TEST #3 close 2 of %s failed (%s)\n", fname, nt_errstr(status)); 4742 5210 return False; 4743 5211 } … … 4749 5217 printf("TEST #4 testing 2 non-io opens (both with delete)\n"); 4750 5218 4751 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4752 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4753 printf("TEST #4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4754 return False; 4755 } 4756 4757 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4758 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4759 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2)); 4760 return False; 4761 } 4762 4763 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation"); 4764 4765 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4766 printf("TEST #4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 5219 status = cli_ntcreate(cli1, fname, 0, 5220 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5221 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5222 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5223 if (!NT_STATUS_IS_OK(status)) { 5224 printf("TEST #4 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5225 return False; 5226 } 5227 5228 status = cli_ntcreate(cli2, fname, 0, 5229 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5230 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5231 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5232 if (NT_STATUS_IS_OK(status)) { 5233 printf("TEST #4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status)); 5234 return False; 5235 } 5236 5237 printf("TEST #4 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation"); 5238 5239 status = cli_close(cli1, fnum1); 5240 if (!NT_STATUS_IS_OK(status)) { 5241 printf("TEST #4 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 4767 5242 return False; 4768 5243 } … … 4774 5249 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n"); 4775 5250 4776 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4777 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4778 printf("TEST #5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4779 return False; 4780 } 4781 4782 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4783 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4784 printf("TEST #5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 4785 return False; 4786 } 4787 4788 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4789 printf("TEST #5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4790 return False; 4791 } 4792 4793 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 4794 printf("TEST #5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 5251 status = cli_ntcreate(cli1, fname, 0, 5252 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5253 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE, 5254 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5255 if (!NT_STATUS_IS_OK(status)) { 5256 printf("TEST #5 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5257 return False; 5258 } 5259 5260 status = cli_ntcreate(cli2, fname, 0, 5261 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5262 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_DELETE, 5263 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5264 if (!NT_STATUS_IS_OK(status)) { 5265 printf("TEST #5 open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 5266 return False; 5267 } 5268 5269 status = cli_close(cli1, fnum1); 5270 if (!NT_STATUS_IS_OK(status)) { 5271 printf("TEST #5 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5272 return False; 5273 } 5274 5275 status = cli_close(cli2, fnum2); 5276 if (!NT_STATUS_IS_OK(status)) { 5277 printf("TEST #5 close 2 of %s failed (%s)\n", fname, nt_errstr(status)); 4795 5278 return False; 4796 5279 } … … 4802 5285 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4803 5286 4804 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, 4805 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4806 printf("TEST #6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4807 return False; 4808 } 4809 4810 if (!NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4811 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0, &fnum2))) { 4812 printf("TEST #6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 4813 return False; 4814 } 4815 4816 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4817 printf("TEST #6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4818 return False; 4819 } 4820 4821 if (!NT_STATUS_IS_OK(cli_close(cli2, fnum2))) { 4822 printf("TEST #6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2)); 5287 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, 5288 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5289 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5290 if (!NT_STATUS_IS_OK(status)) { 5291 printf("TEST #6 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5292 return False; 5293 } 5294 5295 status = cli_ntcreate(cli2, fname, 0, FILE_READ_ATTRIBUTES, 5296 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, 5297 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5298 if (!NT_STATUS_IS_OK(status)) { 5299 printf("TEST #6 open 2 of %s failed (%s)\n", fname, nt_errstr(status)); 5300 return False; 5301 } 5302 5303 status = cli_close(cli1, fnum1); 5304 if (!NT_STATUS_IS_OK(status)) { 5305 printf("TEST #6 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5306 return False; 5307 } 5308 5309 status = cli_close(cli2, fnum2); 5310 if (!NT_STATUS_IS_OK(status)) { 5311 printf("TEST #6 close 2 of %s failed (%s)\n", fname, nt_errstr(status)); 4823 5312 return False; 4824 5313 } … … 4830 5319 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 4831 5320 4832 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL, 4833 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 4834 printf("TEST #7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 4835 return False; 4836 } 4837 4838 if (NT_STATUS_IS_OK(cli_ntcreate(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL, 4839 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0, &fnum2))) { 4840 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2)); 4841 return False; 4842 } 4843 4844 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation"); 4845 4846 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4847 printf("TEST #7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1)); 5321 status = cli_ntcreate(cli1, fname, 0, FILE_READ_DATA, 5322 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, 5323 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 5324 if (!NT_STATUS_IS_OK(status)) { 5325 printf("TEST #7 open 1 of %s failed (%s)\n", fname, nt_errstr(status)); 5326 return False; 5327 } 5328 5329 status = cli_ntcreate(cli2, fname, 0, 5330 DELETE_ACCESS|FILE_READ_ATTRIBUTES, 5331 FILE_ATTRIBUTE_NORMAL, 5332 FILE_SHARE_READ|FILE_SHARE_DELETE, 5333 FILE_OPEN_IF, 0, 0, &fnum2, NULL); 5334 if (NT_STATUS_IS_OK(status)) { 5335 printf("TEST #7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, nt_errstr(status)); 5336 return False; 5337 } 5338 5339 printf("TEST #7 open 2 of %s gave %s (correct error should be %s)\n", fname, nt_errstr(status), "sharing violation"); 5340 5341 status = cli_close(cli1, fnum1); 5342 if (!NT_STATUS_IS_OK(status)) { 5343 printf("TEST #7 close 1 of %s failed (%s)\n", fname, nt_errstr(status)); 4848 5344 return False; 4849 5345 } … … 4856 5352 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL, 4857 5353 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 4858 FILE_OVERWRITE_IF, 0, 0, &fnum1 );5354 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 4859 5355 if (!NT_STATUS_IS_OK(status)) { 4860 5356 printf("TEST #8 open of %s failed (%s)\n", fname, nt_errstr(status)); … … 4864 5360 4865 5361 /* Write to ensure we have to update the file time. */ 4866 status = cli_writeall(cli1, fnum1, 0, ( uint8_t *)"TEST DATA\n", 0, 10,5362 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10, 4867 5363 NULL); 4868 5364 if (!NT_STATUS_IS_OK(status)) { … … 4892 5388 NTSTATUS torture_setup_unix_extensions(struct cli_state *cli) 4893 5389 { 4894 uint16 major, minor;4895 uint32 caplow, caphigh;5390 uint16_t major, minor; 5391 uint32_t caplow, caphigh; 4896 5392 NTSTATUS status; 4897 5393 … … 4936 5432 bool correct = false; 4937 5433 NTSTATUS status; 5434 size_t nread; 5435 const char *fname_windows = "windows_file"; 5436 uint16_t fnum2 = (uint16_t)-1; 4938 5437 4939 5438 printf("Starting simple POSIX open test\n"); … … 4943 5442 } 4944 5443 4945 cli_sockopt(cli1, sockops);5444 smbXcli_conn_set_sockopt(cli1->conn, sockops); 4946 5445 4947 5446 status = torture_setup_unix_extensions(cli1); … … 4958 5457 cli_setatr(cli1, sname, 0, 0); 4959 5458 cli_posix_unlink(cli1, sname); 5459 cli_setatr(cli1, fname_windows, 0, 0); 5460 cli_posix_unlink(cli1, fname_windows); 4960 5461 4961 5462 /* Create a directory. */ 4962 if (!NT_STATUS_IS_OK(cli_posix_mkdir(cli1, dname, 0777))) { 4963 printf("POSIX mkdir of %s failed (%s)\n", dname, cli_errstr(cli1)); 5463 status = cli_posix_mkdir(cli1, dname, 0777); 5464 if (!NT_STATUS_IS_OK(status)) { 5465 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status)); 4964 5466 goto out; 4965 5467 } 4966 5468 4967 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) { 4968 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1)); 5469 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 5470 0600, &fnum1); 5471 if (!NT_STATUS_IS_OK(status)) { 5472 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status)); 4969 5473 goto out; 4970 5474 } 4971 5475 4972 5476 /* Test ftruncate - set file size. */ 4973 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) { 4974 printf("ftruncate failed (%s)\n", cli_errstr(cli1)); 5477 status = cli_ftruncate(cli1, fnum1, 1000); 5478 if (!NT_STATUS_IS_OK(status)) { 5479 printf("ftruncate failed (%s)\n", nt_errstr(status)); 4975 5480 goto out; 4976 5481 } 4977 5482 4978 5483 /* Ensure st_size == 1000 */ 4979 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) { 4980 printf("stat failed (%s)\n", cli_errstr(cli1)); 5484 status = cli_posix_stat(cli1, fname, &sbuf); 5485 if (!NT_STATUS_IS_OK(status)) { 5486 printf("stat failed (%s)\n", nt_errstr(status)); 4981 5487 goto out; 4982 5488 } … … 4987 5493 } 4988 5494 5495 /* Ensure st_mode == 0600 */ 5496 if ((sbuf.st_ex_mode & 07777) != 0600) { 5497 printf("posix_open - bad permissions 0%o != 0600\n", 5498 (unsigned int)(sbuf.st_ex_mode & 07777)); 5499 goto out; 5500 } 5501 4989 5502 /* Test ftruncate - set file size back to zero. */ 4990 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 0))) { 4991 printf("ftruncate failed (%s)\n", cli_errstr(cli1)); 5503 status = cli_ftruncate(cli1, fnum1, 0); 5504 if (!NT_STATUS_IS_OK(status)) { 5505 printf("ftruncate failed (%s)\n", nt_errstr(status)); 4992 5506 goto out; 4993 5507 } 4994 5508 4995 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 4996 printf("close failed (%s)\n", cli_errstr(cli1)); 5509 status = cli_close(cli1, fnum1); 5510 if (!NT_STATUS_IS_OK(status)) { 5511 printf("close failed (%s)\n", nt_errstr(status)); 4997 5512 goto out; 4998 5513 } 4999 5514 5000 5515 /* Now open the file again for read only. */ 5001 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) { 5002 printf("POSIX open of %s failed (%s)\n", fname, cli_errstr(cli1)); 5516 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1); 5517 if (!NT_STATUS_IS_OK(status)) { 5518 printf("POSIX open of %s failed (%s)\n", fname, nt_errstr(status)); 5003 5519 goto out; 5004 5520 } 5005 5521 5006 5522 /* Now unlink while open. */ 5007 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) { 5008 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1)); 5523 status = cli_posix_unlink(cli1, fname); 5524 if (!NT_STATUS_IS_OK(status)) { 5525 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status)); 5009 5526 goto out; 5010 5527 } 5011 5528 5012 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 5013 printf("close(2) failed (%s)\n", cli_errstr(cli1)); 5529 status = cli_close(cli1, fnum1); 5530 if (!NT_STATUS_IS_OK(status)) { 5531 printf("close(2) failed (%s)\n", nt_errstr(status)); 5014 5532 goto out; 5015 5533 } 5016 5534 5017 5535 /* Ensure the file has gone. */ 5018 if (NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1))) { 5536 status = cli_posix_open(cli1, fname, O_RDONLY, 0, &fnum1); 5537 if (NT_STATUS_IS_OK(status)) { 5019 5538 printf("POSIX open of %s succeeded, should have been deleted.\n", fname); 5020 5539 goto out; … … 5022 5541 5023 5542 /* Create again to test open with O_TRUNC. */ 5024 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) { 5025 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1)); 5543 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1); 5544 if (!NT_STATUS_IS_OK(status)) { 5545 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status)); 5026 5546 goto out; 5027 5547 } 5028 5548 5029 5549 /* Test ftruncate - set file size. */ 5030 if (!NT_STATUS_IS_OK(cli_ftruncate(cli1, fnum1, 1000))) { 5031 printf("ftruncate failed (%s)\n", cli_errstr(cli1)); 5550 status = cli_ftruncate(cli1, fnum1, 1000); 5551 if (!NT_STATUS_IS_OK(status)) { 5552 printf("ftruncate failed (%s)\n", nt_errstr(status)); 5032 5553 goto out; 5033 5554 } 5034 5555 5035 5556 /* Ensure st_size == 1000 */ 5036 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) { 5037 printf("stat failed (%s)\n", cli_errstr(cli1)); 5557 status = cli_posix_stat(cli1, fname, &sbuf); 5558 if (!NT_STATUS_IS_OK(status)) { 5559 printf("stat failed (%s)\n", nt_errstr(status)); 5038 5560 goto out; 5039 5561 } … … 5044 5566 } 5045 5567 5046 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 5047 printf("close(2) failed (%s)\n", cli_errstr(cli1)); 5568 status = cli_close(cli1, fnum1); 5569 if (!NT_STATUS_IS_OK(status)) { 5570 printf("close(2) failed (%s)\n", nt_errstr(status)); 5048 5571 goto out; 5049 5572 } 5050 5573 5051 5574 /* Re-open with O_TRUNC. */ 5052 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1))) { 5053 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1)); 5575 status = cli_posix_open(cli1, fname, O_WRONLY|O_TRUNC, 0600, &fnum1); 5576 if (!NT_STATUS_IS_OK(status)) { 5577 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status)); 5054 5578 goto out; 5055 5579 } 5056 5580 5057 5581 /* Ensure st_size == 0 */ 5058 if (!NT_STATUS_IS_OK(cli_posix_stat(cli1, fname, &sbuf))) { 5059 printf("stat failed (%s)\n", cli_errstr(cli1)); 5582 status = cli_posix_stat(cli1, fname, &sbuf); 5583 if (!NT_STATUS_IS_OK(status)) { 5584 printf("stat failed (%s)\n", nt_errstr(status)); 5060 5585 goto out; 5061 5586 } … … 5066 5591 } 5067 5592 5068 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 5069 printf("close failed (%s)\n", cli_errstr(cli1)); 5593 status = cli_close(cli1, fnum1); 5594 if (!NT_STATUS_IS_OK(status)) { 5595 printf("close failed (%s)\n", nt_errstr(status)); 5070 5596 goto out; 5071 5597 } 5072 5598 5073 if (!NT_STATUS_IS_OK(cli_posix_unlink(cli1, fname))) { 5074 printf("POSIX unlink of %s failed (%s)\n", fname, cli_errstr(cli1)); 5599 status = cli_posix_unlink(cli1, fname); 5600 if (!NT_STATUS_IS_OK(status)) { 5601 printf("POSIX unlink of %s failed (%s)\n", fname, nt_errstr(status)); 5075 5602 goto out; 5076 5603 } 5077 5604 5078 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1))) { 5605 status = cli_posix_open(cli1, dname, O_RDONLY, 0, &fnum1); 5606 if (!NT_STATUS_IS_OK(status)) { 5079 5607 printf("POSIX open directory O_RDONLY of %s failed (%s)\n", 5080 dname, cli_errstr(cli1));5608 dname, nt_errstr(status)); 5081 5609 goto out; 5082 5610 } … … 5085 5613 5086 5614 /* What happens when we try and POSIX open a directory for write ? */ 5087 if (NT_STATUS_IS_OK(cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1))) { 5615 status = cli_posix_open(cli1, dname, O_RDWR, 0, &fnum1); 5616 if (NT_STATUS_IS_OK(status)) { 5088 5617 printf("POSIX open of directory %s succeeded, should have failed.\n", fname); 5089 5618 goto out; 5090 5619 } else { 5091 if (!check_ error(__LINE__, cli1, ERRDOS, EISDIR,5620 if (!check_both_error(__LINE__, status, ERRDOS, EISDIR, 5092 5621 NT_STATUS_FILE_IS_A_DIRECTORY)) { 5093 5622 goto out; … … 5096 5625 5097 5626 /* Create the file. */ 5098 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 0600, &fnum1))) { 5099 printf("POSIX create of %s failed (%s)\n", fname, cli_errstr(cli1)); 5627 status = cli_posix_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, 5628 0600, &fnum1); 5629 if (!NT_STATUS_IS_OK(status)) { 5630 printf("POSIX create of %s failed (%s)\n", fname, nt_errstr(status)); 5100 5631 goto out; 5101 5632 } 5102 5633 5103 5634 /* Write some data into it. */ 5104 status = cli_writeall(cli1, fnum1, 0, ( uint8_t *)"TEST DATA\n", 0, 10,5635 status = cli_writeall(cli1, fnum1, 0, (const uint8_t *)"TEST DATA\n", 0, 10, 5105 5636 NULL); 5106 5637 if (!NT_STATUS_IS_OK(status)) { … … 5112 5643 5113 5644 /* Now create a hardlink. */ 5114 if (!NT_STATUS_IS_OK(cli_posix_hardlink(cli1, fname, hname))) { 5115 printf("POSIX hardlink of %s failed (%s)\n", hname, cli_errstr(cli1)); 5645 status = cli_posix_hardlink(cli1, fname, hname); 5646 if (!NT_STATUS_IS_OK(status)) { 5647 printf("POSIX hardlink of %s failed (%s)\n", hname, nt_errstr(status)); 5116 5648 goto out; 5117 5649 } 5118 5650 5119 5651 /* Now create a symlink. */ 5120 if (!NT_STATUS_IS_OK(cli_posix_symlink(cli1, fname, sname))) { 5121 printf("POSIX symlink of %s failed (%s)\n", sname, cli_errstr(cli1)); 5652 status = cli_posix_symlink(cli1, fname, sname); 5653 if (!NT_STATUS_IS_OK(status)) { 5654 printf("POSIX symlink of %s failed (%s)\n", sname, nt_errstr(status)); 5122 5655 goto out; 5123 5656 } 5124 5657 5125 5658 /* Open the hardlink for read. */ 5126 if (!NT_STATUS_IS_OK(cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1))) { 5127 printf("POSIX open of %s failed (%s)\n", hname, cli_errstr(cli1)); 5659 status = cli_posix_open(cli1, hname, O_RDONLY, 0, &fnum1); 5660 if (!NT_STATUS_IS_OK(status)) { 5661 printf("POSIX open of %s failed (%s)\n", hname, nt_errstr(status)); 5128 5662 goto out; 5129 5663 } 5130 5664 5131 if (cli_read(cli1, fnum1, buf, 0, 10) != 10) { 5132 printf("POSIX read of %s failed (%s)\n", hname, cli_errstr(cli1)); 5665 status = cli_read(cli1, fnum1, buf, 0, 10, &nread); 5666 if (!NT_STATUS_IS_OK(status)) { 5667 printf("POSIX read of %s failed (%s)\n", hname, 5668 nt_errstr(status)); 5669 goto out; 5670 } else if (nread != 10) { 5671 printf("POSIX read of %s failed. Received %ld, expected %d\n", 5672 hname, (unsigned long)nread, 10); 5133 5673 goto out; 5134 5674 } … … 5140 5680 5141 5681 /* Do a POSIX lock/unlock. */ 5142 if (!NT_STATUS_IS_OK(cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK))) { 5143 printf("POSIX lock failed %s\n", cli_errstr(cli1)); 5682 status = cli_posix_lock(cli1, fnum1, 0, 100, true, READ_LOCK); 5683 if (!NT_STATUS_IS_OK(status)) { 5684 printf("POSIX lock failed %s\n", nt_errstr(status)); 5144 5685 goto out; 5145 5686 } 5146 5687 5147 5688 /* Punch a hole in the locked area. */ 5148 if (!NT_STATUS_IS_OK(cli_posix_unlock(cli1, fnum1, 10, 80))) { 5149 printf("POSIX unlock failed %s\n", cli_errstr(cli1)); 5689 status = cli_posix_unlock(cli1, fnum1, 10, 80); 5690 if (!NT_STATUS_IS_OK(status)) { 5691 printf("POSIX unlock failed %s\n", nt_errstr(status)); 5150 5692 goto out; 5151 5693 } … … 5155 5697 /* Open the symlink for read - this should fail. A POSIX 5156 5698 client should not be doing opens on a symlink. */ 5157 if (NT_STATUS_IS_OK(cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1))) { 5699 status = cli_posix_open(cli1, sname, O_RDONLY, 0, &fnum1); 5700 if (NT_STATUS_IS_OK(status)) { 5158 5701 printf("POSIX open of %s succeeded (should have failed)\n", sname); 5159 5702 goto out; 5160 5703 } else { 5161 if (!check_ error(__LINE__, cli1, ERRDOS, ERRbadpath,5704 if (!check_both_error(__LINE__, status, ERRDOS, ERRbadpath, 5162 5705 NT_STATUS_OBJECT_PATH_NOT_FOUND)) { 5163 5706 printf("POSIX open of %s should have failed " 5164 5707 "with NT_STATUS_OBJECT_PATH_NOT_FOUND, " 5165 5708 "failed with %s instead.\n", 5166 sname, cli_errstr(cli1));5709 sname, nt_errstr(status)); 5167 5710 goto out; 5168 5711 } 5169 5712 } 5170 5713 5171 if (!NT_STATUS_IS_OK(cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)))) { 5172 printf("POSIX readlink on %s failed (%s)\n", sname, cli_errstr(cli1)); 5714 status = cli_posix_readlink(cli1, sname, namebuf, sizeof(namebuf)); 5715 if (!NT_STATUS_IS_OK(status)) { 5716 printf("POSIX readlink on %s failed (%s)\n", sname, nt_errstr(status)); 5173 5717 goto out; 5174 5718 } … … 5180 5724 } 5181 5725 5182 if (!NT_STATUS_IS_OK(cli_posix_rmdir(cli1, dname))) { 5183 printf("POSIX rmdir failed (%s)\n", cli_errstr(cli1)); 5726 status = cli_posix_rmdir(cli1, dname); 5727 if (!NT_STATUS_IS_OK(status)) { 5728 printf("POSIX rmdir failed (%s)\n", nt_errstr(status)); 5184 5729 goto out; 5185 5730 } 5731 5732 /* Check directory opens with a specific permission. */ 5733 status = cli_posix_mkdir(cli1, dname, 0700); 5734 if (!NT_STATUS_IS_OK(status)) { 5735 printf("POSIX mkdir of %s failed (%s)\n", dname, nt_errstr(status)); 5736 goto out; 5737 } 5738 5739 /* Ensure st_mode == 0700 */ 5740 status = cli_posix_stat(cli1, dname, &sbuf); 5741 if (!NT_STATUS_IS_OK(status)) { 5742 printf("stat failed (%s)\n", nt_errstr(status)); 5743 goto out; 5744 } 5745 5746 if ((sbuf.st_ex_mode & 07777) != 0700) { 5747 printf("posix_mkdir - bad permissions 0%o != 0700\n", 5748 (unsigned int)(sbuf.st_ex_mode & 07777)); 5749 goto out; 5750 } 5751 5752 /* 5753 * Now create a Windows file, and attempt a POSIX unlink. 5754 * This should fail with a sharing violation but due to: 5755 * 5756 * [Bug 9571] Unlink after open causes smbd to panic 5757 * 5758 * ensure we've fixed the lock ordering violation. 5759 */ 5760 5761 status = cli_ntcreate(cli1, fname_windows, 0, 5762 FILE_READ_DATA|FILE_WRITE_DATA, 0, 5763 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 5764 FILE_CREATE, 5765 0x0, 0x0, &fnum2, NULL); 5766 if (!NT_STATUS_IS_OK(status)) { 5767 printf("Windows create of %s failed (%s)\n", fname_windows, 5768 nt_errstr(status)); 5769 goto out; 5770 } 5771 5772 /* Now try posix_unlink. */ 5773 status = cli_posix_unlink(cli1, fname_windows); 5774 if (!NT_STATUS_EQUAL(status, NT_STATUS_SHARING_VIOLATION)) { 5775 printf("POSIX unlink of %s should fail " 5776 "with NT_STATUS_SHARING_VIOLATION " 5777 "got %s instead !\n", 5778 fname_windows, 5779 nt_errstr(status)); 5780 goto out; 5781 } 5782 5783 cli_close(cli1, fnum2); 5186 5784 5187 5785 printf("Simple POSIX open test passed\n"); … … 5193 5791 cli_close(cli1, fnum1); 5194 5792 fnum1 = (uint16_t)-1; 5793 } 5794 5795 if (fnum2 != (uint16_t)-1) { 5796 cli_close(cli1, fnum2); 5797 fnum2 = (uint16_t)-1; 5195 5798 } 5196 5799 … … 5203 5806 cli_setatr(cli1, dname, 0, 0); 5204 5807 cli_posix_rmdir(cli1, dname); 5808 cli_setatr(cli1, fname_windows, 0, 0); 5809 cli_posix_unlink(cli1, fname_windows); 5205 5810 5206 5811 if (!torture_close_connection(cli1)) { … … 5211 5816 } 5212 5817 5213 5214 static uint32 open_attrs_table[] = { 5818 /* 5819 Test POSIX and Windows ACLs are rejected on symlinks. 5820 */ 5821 static bool run_acl_symlink_test(int dummy) 5822 { 5823 static struct cli_state *cli; 5824 const char *fname = "posix_file"; 5825 const char *sname = "posix_symlink"; 5826 uint16_t fnum = (uint16_t)-1; 5827 bool correct = false; 5828 NTSTATUS status; 5829 char *posix_acl = NULL; 5830 size_t posix_acl_len = 0; 5831 char *posix_acl_sym = NULL; 5832 size_t posix_acl_len_sym = 0; 5833 struct security_descriptor *sd = NULL; 5834 struct security_descriptor *sd_sym = NULL; 5835 TALLOC_CTX *frame = NULL; 5836 5837 frame = talloc_stackframe(); 5838 5839 printf("Starting acl symlink test\n"); 5840 5841 if (!torture_open_connection(&cli, 0)) { 5842 TALLOC_FREE(frame); 5843 return false; 5844 } 5845 5846 smbXcli_conn_set_sockopt(cli->conn, sockops); 5847 5848 status = torture_setup_unix_extensions(cli); 5849 if (!NT_STATUS_IS_OK(status)) { 5850 TALLOC_FREE(frame); 5851 return false; 5852 } 5853 5854 cli_setatr(cli, fname, 0, 0); 5855 cli_posix_unlink(cli, fname); 5856 cli_setatr(cli, sname, 0, 0); 5857 cli_posix_unlink(cli, sname); 5858 5859 status = cli_ntcreate(cli, 5860 fname, 5861 0, 5862 READ_CONTROL_ACCESS, 5863 0, 5864 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 5865 FILE_CREATE, 5866 0x0, 5867 0x0, 5868 &fnum, 5869 NULL); 5870 5871 if (!NT_STATUS_IS_OK(status)) { 5872 printf("cli_ntcreate of %s failed (%s)\n", 5873 fname, 5874 nt_errstr(status)); 5875 goto out; 5876 } 5877 5878 /* Get the Windows ACL on the file. */ 5879 status = cli_query_secdesc(cli, 5880 fnum, 5881 frame, 5882 &sd); 5883 if (!NT_STATUS_IS_OK(status)) { 5884 printf("cli_query_secdesc failed (%s)\n", 5885 nt_errstr(status)); 5886 goto out; 5887 } 5888 5889 /* Get the POSIX ACL on the file. */ 5890 status = cli_posix_getacl(cli, 5891 fname, 5892 frame, 5893 &posix_acl_len, 5894 &posix_acl); 5895 5896 if (!NT_STATUS_IS_OK(status)) { 5897 printf("cli_posix_getacl failed (%s)\n", 5898 nt_errstr(status)); 5899 goto out; 5900 } 5901 5902 status = cli_close(cli, fnum); 5903 if (!NT_STATUS_IS_OK(status)) { 5904 printf("close failed (%s)\n", nt_errstr(status)); 5905 goto out; 5906 } 5907 fnum = (uint16_t)-1; 5908 5909 /* Now create a symlink. */ 5910 status = cli_posix_symlink(cli, fname, sname); 5911 if (!NT_STATUS_IS_OK(status)) { 5912 printf("cli_posix_symlink of %s -> %s failed (%s)\n", 5913 sname, 5914 fname, 5915 nt_errstr(status)); 5916 goto out; 5917 } 5918 5919 /* Open a handle on the symlink. */ 5920 status = cli_ntcreate(cli, 5921 sname, 5922 0, 5923 READ_CONTROL_ACCESS|SEC_STD_WRITE_DAC, 5924 0, 5925 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 5926 FILE_OPEN, 5927 0x0, 5928 0x0, 5929 &fnum, 5930 NULL); 5931 5932 if (!NT_STATUS_IS_OK(status)) { 5933 printf("cli_posix_open of %s failed (%s)\n", 5934 sname, 5935 nt_errstr(status)); 5936 goto out; 5937 } 5938 5939 /* Get the Windows ACL on the symlink handle. Should fail */ 5940 status = cli_query_secdesc(cli, 5941 fnum, 5942 frame, 5943 &sd_sym); 5944 5945 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 5946 printf("cli_query_secdesc on a symlink gave %s. " 5947 "Should be NT_STATUS_ACCESS_DENIED.\n", 5948 nt_errstr(status)); 5949 goto out; 5950 } 5951 5952 /* Get the POSIX ACL on the symlink pathname. Should fail. */ 5953 status = cli_posix_getacl(cli, 5954 sname, 5955 frame, 5956 &posix_acl_len_sym, 5957 &posix_acl_sym); 5958 5959 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 5960 printf("cli_posix_getacl on a symlink gave %s. " 5961 "Should be NT_STATUS_ACCESS_DENIED.\n", 5962 nt_errstr(status)); 5963 goto out; 5964 } 5965 5966 /* Set the Windows ACL on the symlink handle. Should fail */ 5967 status = cli_set_security_descriptor(cli, 5968 fnum, 5969 SECINFO_DACL, 5970 sd); 5971 5972 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 5973 printf("cli_query_secdesc on a symlink gave %s. " 5974 "Should be NT_STATUS_ACCESS_DENIED.\n", 5975 nt_errstr(status)); 5976 goto out; 5977 } 5978 5979 /* Set the POSIX ACL on the symlink pathname. Should fail. */ 5980 status = cli_posix_setacl(cli, 5981 sname, 5982 posix_acl, 5983 posix_acl_len); 5984 5985 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 5986 printf("cli_posix_getacl on a symlink gave %s. " 5987 "Should be NT_STATUS_ACCESS_DENIED.\n", 5988 nt_errstr(status)); 5989 goto out; 5990 } 5991 5992 printf("ACL symlink test passed\n"); 5993 correct = true; 5994 5995 out: 5996 5997 if (fnum != (uint16_t)-1) { 5998 cli_close(cli, fnum); 5999 fnum = (uint16_t)-1; 6000 } 6001 6002 cli_setatr(cli, sname, 0, 0); 6003 cli_posix_unlink(cli, sname); 6004 cli_setatr(cli, fname, 0, 0); 6005 cli_posix_unlink(cli, fname); 6006 6007 if (!torture_close_connection(cli)) { 6008 correct = false; 6009 } 6010 6011 TALLOC_FREE(frame); 6012 return correct; 6013 } 6014 6015 /* 6016 Test setting EA's are rejected on symlinks. 6017 */ 6018 static bool run_ea_symlink_test(int dummy) 6019 { 6020 static struct cli_state *cli; 6021 const char *fname = "posix_file_ea"; 6022 const char *sname = "posix_symlink_ea"; 6023 const char *ea_name = "testea_name"; 6024 const char *ea_value = "testea_value"; 6025 uint16_t fnum = (uint16_t)-1; 6026 bool correct = false; 6027 NTSTATUS status; 6028 size_t i, num_eas; 6029 struct ea_struct *eas = NULL; 6030 TALLOC_CTX *frame = NULL; 6031 6032 frame = talloc_stackframe(); 6033 6034 printf("Starting EA symlink test\n"); 6035 6036 if (!torture_open_connection(&cli, 0)) { 6037 TALLOC_FREE(frame); 6038 return false; 6039 } 6040 6041 smbXcli_conn_set_sockopt(cli->conn, sockops); 6042 6043 status = torture_setup_unix_extensions(cli); 6044 if (!NT_STATUS_IS_OK(status)) { 6045 TALLOC_FREE(frame); 6046 return false; 6047 } 6048 6049 cli_setatr(cli, fname, 0, 0); 6050 cli_posix_unlink(cli, fname); 6051 cli_setatr(cli, sname, 0, 0); 6052 cli_posix_unlink(cli, sname); 6053 6054 status = cli_ntcreate(cli, 6055 fname, 6056 0, 6057 READ_CONTROL_ACCESS, 6058 0, 6059 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, 6060 FILE_CREATE, 6061 0x0, 6062 0x0, 6063 &fnum, 6064 NULL); 6065 6066 if (!NT_STATUS_IS_OK(status)) { 6067 printf("cli_ntcreate of %s failed (%s)\n", 6068 fname, 6069 nt_errstr(status)); 6070 goto out; 6071 } 6072 6073 status = cli_close(cli, fnum); 6074 if (!NT_STATUS_IS_OK(status)) { 6075 printf("close failed (%s)\n", 6076 nt_errstr(status)); 6077 goto out; 6078 } 6079 fnum = (uint16_t)-1; 6080 6081 /* Set an EA on the path. */ 6082 status = cli_set_ea_path(cli, 6083 fname, 6084 ea_name, 6085 ea_value, 6086 strlen(ea_value)+1); 6087 6088 if (!NT_STATUS_IS_OK(status)) { 6089 printf("cli_set_ea_path failed (%s)\n", 6090 nt_errstr(status)); 6091 goto out; 6092 } 6093 6094 /* Now create a symlink. */ 6095 status = cli_posix_symlink(cli, fname, sname); 6096 if (!NT_STATUS_IS_OK(status)) { 6097 printf("cli_posix_symlink of %s -> %s failed (%s)\n", 6098 sname, 6099 fname, 6100 nt_errstr(status)); 6101 goto out; 6102 } 6103 6104 /* Get the EA list on the path. Should return value set. */ 6105 status = cli_get_ea_list_path(cli, 6106 fname, 6107 frame, 6108 &num_eas, 6109 &eas); 6110 6111 if (!NT_STATUS_IS_OK(status)) { 6112 printf("cli_get_ea_list_path failed (%s)\n", 6113 nt_errstr(status)); 6114 goto out; 6115 } 6116 6117 /* Ensure the EA we set is there. */ 6118 for (i=0; i<num_eas; i++) { 6119 if (strcmp(eas[i].name, ea_name) == 0 && 6120 eas[i].value.length == strlen(ea_value)+1 && 6121 memcmp(eas[i].value.data, 6122 ea_value, 6123 eas[i].value.length) == 0) { 6124 break; 6125 } 6126 } 6127 6128 if (i == num_eas) { 6129 printf("Didn't find EA on pathname %s\n", 6130 fname); 6131 goto out; 6132 } 6133 6134 num_eas = 0; 6135 TALLOC_FREE(eas); 6136 6137 /* Get the EA list on the symlink. Should return empty list. */ 6138 status = cli_get_ea_list_path(cli, 6139 sname, 6140 frame, 6141 &num_eas, 6142 &eas); 6143 6144 if (!NT_STATUS_IS_OK(status)) { 6145 printf("cli_get_ea_list_path failed (%s)\n", 6146 nt_errstr(status)); 6147 goto out; 6148 } 6149 6150 if (num_eas != 0) { 6151 printf("cli_get_ea_list_path failed (%s)\n", 6152 nt_errstr(status)); 6153 goto out; 6154 } 6155 6156 /* Set an EA on the symlink. Should fail. */ 6157 status = cli_set_ea_path(cli, 6158 sname, 6159 ea_name, 6160 ea_value, 6161 strlen(ea_value)+1); 6162 6163 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 6164 printf("cli_set_ea_path on a symlink gave %s. " 6165 "Should be NT_STATUS_ACCESS_DENIED.\n", 6166 nt_errstr(status)); 6167 goto out; 6168 } 6169 6170 printf("EA symlink test passed\n"); 6171 correct = true; 6172 6173 out: 6174 6175 if (fnum != (uint16_t)-1) { 6176 cli_close(cli, fnum); 6177 fnum = (uint16_t)-1; 6178 } 6179 6180 cli_setatr(cli, sname, 0, 0); 6181 cli_posix_unlink(cli, sname); 6182 cli_setatr(cli, fname, 0, 0); 6183 cli_posix_unlink(cli, fname); 6184 6185 if (!torture_close_connection(cli)) { 6186 correct = false; 6187 } 6188 6189 TALLOC_FREE(frame); 6190 return correct; 6191 } 6192 6193 static uint32_t open_attrs_table[] = { 5215 6194 FILE_ATTRIBUTE_NORMAL, 5216 6195 FILE_ATTRIBUTE_ARCHIVE, … … 5234 6213 struct trunc_open_results { 5235 6214 unsigned int num; 5236 uint32 init_attr;5237 uint32 trunc_attr;5238 uint32 result_attr;6215 uint32_t init_attr; 6216 uint32_t trunc_attr; 6217 uint32_t result_attr; 5239 6218 }; 5240 6219 … … 5274 6253 uint16_t fnum1; 5275 6254 bool correct = True; 5276 uint16 attr;6255 uint16_t attr; 5277 6256 unsigned int i, j, k, l; 6257 NTSTATUS status; 5278 6258 5279 6259 printf("starting open attr test\n"); … … 5283 6263 } 5284 6264 5285 cli_sockopt(cli1, sockops);5286 5287 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32 ); i++) {6265 smbXcli_conn_set_sockopt(cli1->conn, sockops); 6266 6267 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32_t); i++) { 5288 6268 cli_setatr(cli1, fname, 0, 0); 5289 6269 cli_unlink(cli1, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 5290 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i], 5291 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0, &fnum1))) { 5292 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1)); 6270 6271 status = cli_ntcreate(cli1, fname, 0, FILE_WRITE_DATA, 6272 open_attrs_table[i], FILE_SHARE_NONE, 6273 FILE_OVERWRITE_IF, 0, 0, &fnum1, NULL); 6274 if (!NT_STATUS_IS_OK(status)) { 6275 printf("open %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status)); 5293 6276 return False; 5294 6277 } 5295 6278 5296 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 5297 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1)); 6279 status = cli_close(cli1, fnum1); 6280 if (!NT_STATUS_IS_OK(status)) { 6281 printf("close %d (1) of %s failed (%s)\n", i, fname, nt_errstr(status)); 5298 6282 return False; 5299 6283 } 5300 6284 5301 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) { 5302 if (!NT_STATUS_IS_OK(cli_ntcreate(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j], 5303 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0, &fnum1))) { 6285 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32_t); j++) { 6286 status = cli_ntcreate(cli1, fname, 0, 6287 FILE_READ_DATA|FILE_WRITE_DATA, 6288 open_attrs_table[j], 6289 FILE_SHARE_NONE, FILE_OVERWRITE, 6290 0, 0, &fnum1, NULL); 6291 if (!NT_STATUS_IS_OK(status)) { 5304 6292 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) { 5305 6293 if (attr_results[l].num == k) { … … 5307 6295 k, open_attrs_table[i], 5308 6296 open_attrs_table[j], 5309 fname, NT_STATUS_V( cli_nt_error(cli1)), cli_errstr(cli1));6297 fname, NT_STATUS_V(status), nt_errstr(status)); 5310 6298 correct = False; 5311 6299 } 5312 6300 } 5313 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) { 6301 6302 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) { 5314 6303 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n", 5315 6304 k, open_attrs_table[i], open_attrs_table[j], 5316 cli_errstr(cli1));6305 nt_errstr(status)); 5317 6306 correct = False; 5318 6307 } … … 5324 6313 } 5325 6314 5326 if (!NT_STATUS_IS_OK(cli_close(cli1, fnum1))) { 5327 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1)); 6315 status = cli_close(cli1, fnum1); 6316 if (!NT_STATUS_IS_OK(status)) { 6317 printf("close %d (2) of %s failed (%s)\n", j, fname, nt_errstr(status)); 5328 6318 return False; 5329 6319 } 5330 6320 5331 if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) { 5332 printf("getatr(2) failed (%s)\n", cli_errstr(cli1)); 6321 status = cli_getatr(cli1, fname, &attr, NULL, NULL); 6322 if (!NT_STATUS_IS_OK(status)) { 6323 printf("getatr(2) failed (%s)\n", nt_errstr(status)); 5333 6324 return False; 5334 6325 } … … 5397 6388 } 5398 6389 5399 cli_sockopt(cli, sockops);6390 smbXcli_conn_set_sockopt(cli->conn, sockops); 5400 6391 5401 6392 srandom(0); … … 5403 6394 fstring fname; 5404 6395 slprintf(fname, sizeof(fname), "\\%x", (int)random()); 5405 if (!NT_STATUS_IS_OK(cli_open (cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) {6396 if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR|O_CREAT, DENY_NONE, &fnum))) { 5406 6397 fprintf(stderr,"Failed to open %s\n", fname); 5407 6398 return False; … … 5483 6474 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 5484 6475 5485 if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 5486 printf("open of %s failed (%s)\n", fname, cli_errstr(cli)); 6476 status = cli_openx(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 6477 if (!NT_STATUS_IS_OK(status)) { 6478 printf("open of %s failed (%s)\n", fname, nt_errstr(status)); 5487 6479 return False; 5488 6480 } … … 5497 6489 printf("ioctl test with device = 0x%x\n", device); 5498 6490 for (function=0;function<0x100;function++) { 5499 uint32 code = (device<<16) | function;6491 uint32_t code = (device<<16) | function; 5500 6492 5501 6493 status = cli_raw_ioctl(cli, fnum, code, &blob); … … 5525 6517 uint16_t fnum; 5526 6518 bool ret; 6519 NTSTATUS status; 5527 6520 5528 6521 if (!torture_open_connection(&cli, 0)) { … … 5537 6530 cli_rmdir(cli, "\\chkpath.dir"); 5538 6531 5539 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir"))) { 5540 printf("mkdir1 failed : %s\n", cli_errstr(cli)); 5541 return False; 5542 } 5543 5544 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\chkpath.dir\\dir2"))) { 5545 printf("mkdir2 failed : %s\n", cli_errstr(cli)); 5546 return False; 5547 } 5548 5549 if (!NT_STATUS_IS_OK(cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 5550 printf("open1 failed (%s)\n", cli_errstr(cli)); 6532 status = cli_mkdir(cli, "\\chkpath.dir"); 6533 if (!NT_STATUS_IS_OK(status)) { 6534 printf("mkdir1 failed : %s\n", nt_errstr(status)); 6535 return False; 6536 } 6537 6538 status = cli_mkdir(cli, "\\chkpath.dir\\dir2"); 6539 if (!NT_STATUS_IS_OK(status)) { 6540 printf("mkdir2 failed : %s\n", nt_errstr(status)); 6541 return False; 6542 } 6543 6544 status = cli_openx(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, 6545 DENY_NONE, &fnum); 6546 if (!NT_STATUS_IS_OK(status)) { 6547 printf("open1 failed (%s)\n", nt_errstr(status)); 5551 6548 return False; 5552 6549 } 5553 6550 cli_close(cli, fnum); 5554 6551 5555 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir"))) { 5556 printf("chkpath1 failed: %s\n", cli_errstr(cli)); 6552 status = cli_chkpath(cli, "\\chkpath.dir"); 6553 if (!NT_STATUS_IS_OK(status)) { 6554 printf("chkpath1 failed: %s\n", nt_errstr(status)); 5557 6555 ret = False; 5558 6556 } 5559 6557 5560 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dir2"))) { 5561 printf("chkpath2 failed: %s\n", cli_errstr(cli)); 6558 status = cli_chkpath(cli, "\\chkpath.dir\\dir2"); 6559 if (!NT_STATUS_IS_OK(status)) { 6560 printf("chkpath2 failed: %s\n", nt_errstr(status)); 5562 6561 ret = False; 5563 6562 } 5564 6563 5565 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\foo.txt"))) { 5566 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 6564 status = cli_chkpath(cli, "\\chkpath.dir\\foo.txt"); 6565 if (!NT_STATUS_IS_OK(status)) { 6566 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath, 5567 6567 NT_STATUS_NOT_A_DIRECTORY); 5568 6568 } else { … … 5571 6571 } 5572 6572 5573 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\bar.txt"))) { 5574 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile, 6573 status = cli_chkpath(cli, "\\chkpath.dir\\bar.txt"); 6574 if (!NT_STATUS_IS_OK(status)) { 6575 ret = check_error(__LINE__, status, ERRDOS, ERRbadfile, 5575 6576 NT_STATUS_OBJECT_NAME_NOT_FOUND); 5576 6577 } else { 5577 printf("* chkpath on a non exist ant file should fail\n");6578 printf("* chkpath on a non existent file should fail\n"); 5578 6579 ret = False; 5579 6580 } 5580 6581 5581 if (!NT_STATUS_IS_OK(cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"))) { 5582 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath, 6582 status = cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt"); 6583 if (!NT_STATUS_IS_OK(status)) { 6584 ret = check_error(__LINE__, status, ERRDOS, ERRbadpath, 5583 6585 NT_STATUS_OBJECT_PATH_NOT_FOUND); 5584 6586 } else { … … 5618 6620 5619 6621 cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 5620 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, 5621 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE, 5622 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 5623 0x4044, 0, &fnum))) { 5624 printf("open failed - %s\n", cli_errstr(cli)); 6622 6623 status = cli_ntcreate(cli, fname, 0, 6624 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE, 6625 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 6626 0x4044, 0, &fnum, NULL); 6627 if (!NT_STATUS_IS_OK(status)) { 6628 printf("open failed - %s\n", nt_errstr(status)); 5625 6629 talloc_destroy(mem_ctx); 5626 6630 return False; … … 5712 6716 } 5713 6717 5714 /* Try and delete a non exist ant EA. */6718 /* Try and delete a non existent EA. */ 5715 6719 status = cli_set_ea_path(cli, fname, "foo", "", 0); 5716 6720 if (!NT_STATUS_IS_OK(status)) { 5717 printf("deleting non-exist ant EA 'foo' should succeed. %s\n",6721 printf("deleting non-existent EA 'foo' should succeed. %s\n", 5718 6722 nt_errstr(status)); 5719 6723 correct = False; … … 5742 6746 } 5743 6747 5744 cli_sockopt(cli, sockops);6748 smbXcli_conn_set_sockopt(cli->conn, sockops); 5745 6749 5746 6750 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli); … … 5754 6758 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i); 5755 6759 if (!NT_STATUS_IS_OK(cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE, 5756 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum))) { 6760 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 6761 0, 0, &fnum, NULL))) { 5757 6762 fprintf(stderr,"Failed to open %s\n", fname); 5758 6763 return False; … … 5818 6823 NTSTATUS status; 5819 6824 5820 uint32 error;5821 5822 uint32 flgs2,errnum;5823 uint8 errclass;6825 uint32_t error; 6826 6827 uint32_t errnum; 6828 uint8_t errclass; 5824 6829 5825 6830 NTSTATUS nt_status; … … 5829 6834 /* NT-Error connection */ 5830 6835 6836 disable_spnego = true; 5831 6837 if (!(c_nt = open_nbt_connection())) { 5832 return False; 5833 } 5834 5835 c_nt->use_spnego = False; 5836 5837 status = cli_negprot(c_nt); 6838 disable_spnego = false; 6839 return False; 6840 } 6841 disable_spnego = false; 6842 6843 status = smbXcli_negprot(c_nt->conn, c_nt->timeout, PROTOCOL_CORE, 6844 PROTOCOL_NT1); 5838 6845 5839 6846 if (!NT_STATUS_IS_OK(status)) { … … 5844 6851 } 5845 6852 5846 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,5847 workgroup))) {5848 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));6853 status = cli_session_setup(c_nt, "", "", 0, "", 0, workgroup); 6854 if (!NT_STATUS_IS_OK(status)) { 6855 printf("%s rejected the NT-error initial session setup (%s)\n",host, nt_errstr(status)); 5849 6856 return False; 5850 6857 } … … 5852 6859 /* DOS-Error connection */ 5853 6860 6861 disable_spnego = true; 6862 force_dos_errors = true; 5854 6863 if (!(c_dos = open_nbt_connection())) { 5855 return False; 5856 } 5857 5858 c_dos->use_spnego = False; 5859 c_dos->force_dos_errors = True; 5860 5861 status = cli_negprot(c_dos); 6864 disable_spnego = false; 6865 force_dos_errors = false; 6866 return False; 6867 } 6868 disable_spnego = false; 6869 force_dos_errors = false; 6870 6871 status = smbXcli_negprot(c_dos->conn, c_dos->timeout, PROTOCOL_CORE, 6872 PROTOCOL_NT1); 5862 6873 if (!NT_STATUS_IS_OK(status)) { 5863 6874 printf("%s rejected the DOS-error negprot (%s)\n", host, … … 5867 6878 } 5868 6879 5869 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0, 5870 workgroup))) { 5871 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos)); 5872 return False; 5873 } 6880 status = cli_session_setup(c_dos, "", "", 0, "", 0, workgroup); 6881 if (!NT_STATUS_IS_OK(status)) { 6882 printf("%s rejected the DOS-error initial session setup (%s)\n", 6883 host, nt_errstr(status)); 6884 return False; 6885 } 6886 6887 c_nt->map_dos_errors = false; 6888 c_dos->map_dos_errors = false; 5874 6889 5875 6890 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) { 5876 6891 fstr_sprintf(user, "%X", error); 5877 6892 5878 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user, 5879 password, strlen(password), 5880 password, strlen(password), 5881 workgroup))) { 6893 status = cli_session_setup(c_nt, user, 6894 password, strlen(password), 6895 password, strlen(password), 6896 workgroup); 6897 if (NT_STATUS_IS_OK(status)) { 5882 6898 printf("/** Session setup succeeded. This shouldn't happen...*/\n"); 5883 6899 } 5884 6900 5885 flgs2 = SVAL(c_nt->inbuf,smb_flg2);5886 5887 6901 /* Case #1: 32-bit NT errors */ 5888 if ( flgs2 & FLAGS2_32_BIT_ERROR_CODES) {5889 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));6902 if (!NT_STATUS_IS_DOS(status)) { 6903 nt_status = status; 5890 6904 } else { 5891 6905 printf("/** Dos error on NT connection! (%s) */\n", 5892 cli_errstr(c_nt));6906 nt_errstr(status)); 5893 6907 nt_status = NT_STATUS(0xc0000000); 5894 6908 } 5895 6909 5896 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user, 5897 password, strlen(password), 5898 password, strlen(password), 5899 workgroup))) { 6910 status = cli_session_setup(c_dos, user, 6911 password, strlen(password), 6912 password, strlen(password), 6913 workgroup); 6914 if (NT_STATUS_IS_OK(status)) { 5900 6915 printf("/** Session setup succeeded. This shouldn't happen...*/\n"); 5901 6916 } 5902 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;5903 6917 5904 6918 /* Case #1: 32-bit NT errors */ 5905 if ( flgs2 & FLAGS2_32_BIT_ERROR_CODES) {6919 if (NT_STATUS_IS_DOS(status)) { 5906 6920 printf("/** NT error on DOS connection! (%s) */\n", 5907 cli_errstr(c_nt));6921 nt_errstr(status)); 5908 6922 errnum = errclass = 0; 5909 6923 } else { 5910 cli_dos_error(c_dos, &errclass, &errnum); 6924 errclass = NT_STATUS_DOS_CLASS(status); 6925 errnum = NT_STATUS_DOS_CODE(status); 5911 6926 } 5912 6927 5913 6928 if (NT_STATUS_V(nt_status) != error) { 5914 6929 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n", 5915 get_nt_error_c_code( NT_STATUS(error)),5916 get_nt_error_c_code( nt_status));6930 get_nt_error_c_code(talloc_tos(), NT_STATUS(error)), 6931 get_nt_error_c_code(talloc_tos(), nt_status)); 5917 6932 } 5918 6933 … … 5920 6935 smb_dos_err_class(errclass), 5921 6936 smb_dos_err_name(errclass, errnum), 5922 get_nt_error_c_code( NT_STATUS(error)));6937 get_nt_error_c_code(talloc_tos(), NT_STATUS(error))); 5923 6938 } 5924 6939 return True; … … 5937 6952 } 5938 6953 5939 if (!NT_STATUS_IS_OK(cli_ntcreate(5940 c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS,5941 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF,5942 FILE_DELETE_ON_CLOSE, 0, &fnum))) {5943 d_printf("open %s failed: %s\n", fname, cli_errstr(c));6954 status = cli_ntcreate(c, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, 6955 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 6956 FILE_DELETE_ON_CLOSE, 0, &fnum, NULL); 6957 if (!NT_STATUS_IS_OK(status)) { 6958 d_printf("open %s failed: %s\n", fname, nt_errstr(status)); 5944 6959 return false; 5945 6960 } … … 5957 6972 } 5958 6973 5959 d_printf("\r%d ", (int)c ->vuid);6974 d_printf("\r%d ", (int)cli_state_get_uid(c)); 5960 6975 5961 6976 status = cli_ulogoff(c); … … 5965 6980 return false; 5966 6981 } 5967 c->vuid = 0;5968 6982 } 5969 6983 … … 5977 6991 bool result = true; 5978 6992 5979 subst = talloc_sub_specified(talloc_tos(), str, user, domain, uid, gid);6993 subst = talloc_sub_specified(talloc_tos(), str, user, NULL, domain, uid, gid); 5980 6994 5981 6995 if (strcmp(subst, expected) != 0) { … … 5994 7008 uint16_t fnum; 5995 7009 NTSTATUS status; 5996 status = cli_open _recv(req, &fnum);7010 status = cli_openx_recv(req, &fnum); 5997 7011 TALLOC_FREE(req); 5998 7012 5999 d_printf("cli_open _recv returned %s: %d\n",7013 d_printf("cli_openx_recv returned %s: %d\n", 6000 7014 nt_errstr(status), 6001 7015 NT_STATUS_IS_OK(status) ? fnum : -1); … … 6030 7044 { 6031 7045 struct cli_state *cli1; 6032 struct event_context *evt =event_context_init(NULL);7046 struct tevent_context *evt = samba_tevent_context_init(NULL); 6033 7047 struct tevent_req *reqs[3], *smbreqs[3]; 6034 7048 bool done = false; … … 6041 7055 } 6042 7056 6043 cli_sockopt(cli1, sockops);6044 6045 reqs[0] = cli_open _create(talloc_tos(), evt, cli1, "\\test",7057 smbXcli_conn_set_sockopt(cli1->conn, sockops); 7058 7059 reqs[0] = cli_openx_create(talloc_tos(), evt, cli1, "\\test", 6046 7060 O_CREAT|O_RDWR, 0, &smbreqs[0]); 6047 7061 if (reqs[0] == NULL) return false; … … 6050 7064 6051 7065 reqs[1] = cli_write_andx_create(talloc_tos(), evt, cli1, 0, 0, 6052 ( uint8_t *)str, 0, strlen(str)+1,7066 (const uint8_t *)str, 0, strlen(str)+1, 6053 7067 smbreqs, 1, &smbreqs[1]); 6054 7068 if (reqs[1] == NULL) return false; … … 6059 7073 tevent_req_set_callback(reqs[2], chain1_close_completion, &done); 6060 7074 6061 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));7075 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs)); 6062 7076 if (!NT_STATUS_IS_OK(status)) { 6063 7077 return false; … … 6065 7079 6066 7080 while (!done) { 6067 event_loop_once(evt);7081 tevent_loop_once(evt); 6068 7082 } 6069 7083 … … 6091 7105 { 6092 7106 struct cli_state *cli1; 6093 struct event_context *evt =event_context_init(NULL);7107 struct tevent_context *evt = samba_tevent_context_init(NULL); 6094 7108 struct tevent_req *reqs[2], *smbreqs[2]; 6095 7109 bool done = false; … … 6097 7111 6098 7112 printf("starting chain2 test\n"); 6099 status = cli_start_connection(&cli1, global_myname(), host, NULL,6100 port_to_use, Undefined, 0);6101 if (!NT_STATUS_IS_OK(status)) { 6102 return False; 6103 } 6104 6105 cli_sockopt(cli1, sockops);7113 status = cli_start_connection(&cli1, lp_netbios_name(), host, NULL, 7114 port_to_use, SMB_SIGNING_DEFAULT, 0); 7115 if (!NT_STATUS_IS_OK(status)) { 7116 return False; 7117 } 7118 7119 smbXcli_conn_set_sockopt(cli1->conn, sockops); 6106 7120 6107 7121 reqs[0] = cli_session_setup_guest_create(talloc_tos(), evt, cli1, … … 6115 7129 tevent_req_set_callback(reqs[1], chain2_tcon_completion, &done); 6116 7130 6117 status = cli_smb_chain_send(smbreqs, ARRAY_SIZE(smbreqs));7131 status = smb1cli_req_chain_submit(smbreqs, ARRAY_SIZE(smbreqs)); 6118 7132 if (!NT_STATUS_IS_OK(status)) { 6119 7133 return false; … … 6121 7135 6122 7136 while (!done) { 6123 event_loop_once(evt);7137 tevent_loop_once(evt); 6124 7138 } 6125 7139 … … 6176 7190 uint16_t fnum; 6177 7191 6178 status = cli_ntcreate_recv(subreq, &fnum );7192 status = cli_ntcreate_recv(subreq, &fnum, NULL); 6179 7193 TALLOC_FREE(subreq); 6180 if ( !NT_STATUS_IS_OK(status)) {7194 if (tevent_req_nterror(req, status)) { 6181 7195 DEBUG(10, ("cli_ntcreate_recv returned %s\n", 6182 7196 nt_errstr(status))); 6183 tevent_req_nterror(req, status);6184 7197 return; 6185 7198 } … … 6199 7212 6200 7213 status = cli_close_recv(subreq); 6201 if ( !NT_STATUS_IS_OK(status)) {7214 if (tevent_req_nterror(req, status)) { 6202 7215 DEBUG(10, ("cli_close_recv returned %s\n", nt_errstr(status))); 6203 tevent_req_nterror(req, status);6204 7216 return; 6205 7217 } … … 6456 7468 } 6457 7469 6458 ev = tevent_context_init(talloc_tos());7470 ev = samba_tevent_context_init(talloc_tos()); 6459 7471 if (ev == NULL) { 6460 7472 d_printf("tevent_context_init failed\n"); … … 6481 7493 FILE_SHARE_DELETE, 6482 7494 FILE_OPEN_IF, FILE_DIRECTORY_FILE, 0, 6483 &dnum );7495 &dnum, NULL); 6484 7496 6485 7497 if (!NT_STATUS_IS_OK(status)) { … … 6539 7551 NTSTATUS status; 6540 7552 time_t change_time, access_time, write_time; 6541 SMB_OFF_Tsize;7553 off_t size; 6542 7554 uint16_t mode; 6543 7555 … … 6547 7559 } 6548 7560 6549 cli_sockopt(cli, sockops); 6550 6551 if (!NT_STATUS_IS_OK(cli_ntcreate( 6552 cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, 6553 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0, &fnum))) { 6554 d_printf("open %s failed: %s\n", fname, cli_errstr(cli)); 7561 smbXcli_conn_set_sockopt(cli->conn, sockops); 7562 7563 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, 7564 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 7565 0, 0, &fnum, NULL); 7566 if (!NT_STATUS_IS_OK(status)) { 7567 d_printf("open %s failed: %s\n", fname, nt_errstr(status)); 6555 7568 return false; 6556 7569 } … … 6565 7578 d_printf("alt_name: %s\n", alt_name); 6566 7579 6567 if (!NT_STATUS_IS_OK(cli_open(cli, alt_name, O_RDONLY, DENY_NONE, &fnum))) { 6568 d_printf("cli_open(%s) failed: %s\n", alt_name, 6569 cli_errstr(cli)); 7580 status = cli_openx(cli, alt_name, O_RDONLY, DENY_NONE, &fnum); 7581 if (!NT_STATUS_IS_OK(status)) { 7582 d_printf("cli_openx(%s) failed: %s\n", alt_name, 7583 nt_errstr(status)); 6570 7584 return false; 6571 7585 } … … 6608 7622 double seconds; 6609 7623 double kbytes; 7624 NTSTATUS status; 6610 7625 6611 7626 printf("starting windows_write test\n"); … … 6614 7629 } 6615 7630 6616 if (!NT_STATUS_IS_OK(cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum))) { 6617 printf("open failed (%s)\n", cli_errstr(cli1)); 6618 return False; 6619 } 6620 6621 cli_sockopt(cli1, sockops); 7631 status = cli_openx(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE, &fnum); 7632 if (!NT_STATUS_IS_OK(status)) { 7633 printf("open failed (%s)\n", nt_errstr(status)); 7634 return False; 7635 } 7636 7637 smbXcli_conn_set_sockopt(cli1->conn, sockops); 6622 7638 6623 7639 start_time = timeval_current(); … … 6626 7642 uint8_t c = 0; 6627 7643 off_t start = i * torture_blocksize; 6628 NTSTATUS status;6629 7644 size_t to_pull = torture_blocksize - 1; 6630 7645 … … 6659 7674 } 6660 7675 7676 static size_t calc_expected_return(struct cli_state *cli, size_t len_requested) 7677 { 7678 size_t max_pdu = 0x1FFFF; 7679 7680 if (cli->server_posix_capabilities & CIFS_UNIX_LARGE_READ_CAP) { 7681 max_pdu = 0xFFFFFF; 7682 } 7683 7684 if (smb1cli_conn_signing_is_active(cli->conn)) { 7685 max_pdu = 0x1FFFF; 7686 } 7687 7688 if (smb1cli_conn_encryption_on(cli->conn)) { 7689 max_pdu = CLI_BUFFER_SIZE; 7690 } 7691 7692 if ((len_requested & 0xFFFF0000) == 0xFFFF0000) { 7693 len_requested &= 0xFFFF; 7694 } 7695 7696 return MIN(len_requested, 7697 max_pdu - (MIN_SMB_SIZE + VWV(12) + 1 /* padding byte */)); 7698 } 7699 7700 static bool check_read_call(struct cli_state *cli, 7701 uint16_t fnum, 7702 uint8_t *buf, 7703 size_t len_requested) 7704 { 7705 NTSTATUS status; 7706 struct tevent_req *subreq = NULL; 7707 ssize_t len_read = 0; 7708 size_t len_expected = 0; 7709 struct tevent_context *ev = NULL; 7710 7711 ev = samba_tevent_context_init(talloc_tos()); 7712 if (ev == NULL) { 7713 return false; 7714 } 7715 7716 subreq = cli_read_andx_send(talloc_tos(), 7717 ev, 7718 cli, 7719 fnum, 7720 0, 7721 len_requested); 7722 7723 if (!tevent_req_poll_ntstatus(subreq, ev, &status)) { 7724 return false; 7725 } 7726 7727 status = cli_read_andx_recv(subreq, &len_read, &buf); 7728 if (!NT_STATUS_IS_OK(status)) { 7729 d_printf("cli_read_andx_recv failed: %s\n", nt_errstr(status)); 7730 return false; 7731 } 7732 7733 TALLOC_FREE(subreq); 7734 TALLOC_FREE(ev); 7735 7736 len_expected = calc_expected_return(cli, len_requested); 7737 7738 if (len_expected > 0x10000 && len_read == 0x10000) { 7739 /* Windows servers only return a max of 0x10000, 7740 doesn't matter if you set CAP_LARGE_READX in 7741 the client sessionsetupX call or not. */ 7742 d_printf("Windows server - returned 0x10000 on a read of 0x%x\n", 7743 (unsigned int)len_requested); 7744 } else if (len_read != len_expected) { 7745 d_printf("read of 0x%x failed: got 0x%x, expected 0x%x\n", 7746 (unsigned int)len_requested, 7747 (unsigned int)len_read, 7748 (unsigned int)len_expected); 7749 return false; 7750 } else { 7751 d_printf("Correct read reply.\n"); 7752 } 7753 7754 return true; 7755 } 7756 7757 /* Test large readX variants. */ 7758 static bool large_readx_tests(struct cli_state *cli, 7759 uint16_t fnum, 7760 uint8_t *buf) 7761 { 7762 /* A read of 0xFFFF0001 should *always* return 1 byte. */ 7763 if (check_read_call(cli, fnum, buf, 0xFFFF0001) == false) { 7764 return false; 7765 } 7766 /* A read of 0x10000 should return 0x10000 bytes. */ 7767 if (check_read_call(cli, fnum, buf, 0x10000) == false) { 7768 return false; 7769 } 7770 /* A read of 0x10000 should return 0x10001 bytes. */ 7771 if (check_read_call(cli, fnum, buf, 0x10001) == false) { 7772 return false; 7773 } 7774 /* A read of 0x1FFFF - (MIN_SMB_SIZE + VWV(12) should return 7775 the requested number of bytes. */ 7776 if (check_read_call(cli, fnum, buf, 0x1FFFF - (MIN_SMB_SIZE + VWV(12))) == false) { 7777 return false; 7778 } 7779 /* A read of 1MB should return 1MB bytes (on Samba). */ 7780 if (check_read_call(cli, fnum, buf, 0x100000) == false) { 7781 return false; 7782 } 7783 7784 if (check_read_call(cli, fnum, buf, 0x20001) == false) { 7785 return false; 7786 } 7787 if (check_read_call(cli, fnum, buf, 0x22000001) == false) { 7788 return false; 7789 } 7790 if (check_read_call(cli, fnum, buf, 0xFFFE0001) == false) { 7791 return false; 7792 } 7793 return true; 7794 } 7795 7796 static bool run_large_readx(int dummy) 7797 { 7798 uint8_t *buf = NULL; 7799 struct cli_state *cli1 = NULL; 7800 struct cli_state *cli2 = NULL; 7801 bool correct = false; 7802 const char *fname = "\\large_readx.dat"; 7803 NTSTATUS status; 7804 uint16_t fnum1 = UINT16_MAX; 7805 uint32_t normal_caps = 0; 7806 size_t file_size = 20*1024*1024; 7807 TALLOC_CTX *frame = talloc_stackframe(); 7808 size_t i; 7809 struct { 7810 const char *name; 7811 enum smb_signing_setting signing_setting; 7812 enum protocol_types protocol; 7813 } runs[] = { 7814 { 7815 .name = "NT1", 7816 .signing_setting = SMB_SIGNING_IF_REQUIRED, 7817 .protocol = PROTOCOL_NT1, 7818 },{ 7819 .name = "NT1 - SIGNING_REQUIRED", 7820 .signing_setting = SMB_SIGNING_REQUIRED, 7821 .protocol = PROTOCOL_NT1, 7822 }, 7823 }; 7824 7825 printf("starting large_readx test\n"); 7826 7827 if (!torture_open_connection(&cli1, 0)) { 7828 goto out; 7829 } 7830 7831 normal_caps = smb1cli_conn_capabilities(cli1->conn); 7832 7833 if (!(normal_caps & CAP_LARGE_READX)) { 7834 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n", 7835 (unsigned int)normal_caps); 7836 goto out; 7837 } 7838 7839 /* Create a file of size 4MB. */ 7840 status = cli_ntcreate(cli1, fname, 0, GENERIC_ALL_ACCESS, 7841 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 7842 0, 0, &fnum1, NULL); 7843 7844 if (!NT_STATUS_IS_OK(status)) { 7845 d_printf("open %s failed: %s\n", fname, nt_errstr(status)); 7846 goto out; 7847 } 7848 7849 /* Write file_size bytes. */ 7850 buf = talloc_zero_array(frame, uint8_t, file_size); 7851 if (buf == NULL) { 7852 goto out; 7853 } 7854 7855 status = cli_writeall(cli1, 7856 fnum1, 7857 0, 7858 buf, 7859 0, 7860 file_size, 7861 NULL); 7862 if (!NT_STATUS_IS_OK(status)) { 7863 d_printf("cli_writeall failed: %s\n", nt_errstr(status)); 7864 goto out; 7865 } 7866 7867 status = cli_close(cli1, fnum1); 7868 if (!NT_STATUS_IS_OK(status)) { 7869 d_printf("cli_close failed: %s\n", nt_errstr(status)); 7870 goto out; 7871 } 7872 7873 fnum1 = UINT16_MAX; 7874 7875 for (i=0; i < ARRAY_SIZE(runs); i++) { 7876 enum smb_signing_setting saved_signing_setting = signing_state; 7877 uint16_t fnum2 = -1; 7878 7879 if (do_encrypt && 7880 (runs[i].signing_setting == SMB_SIGNING_REQUIRED)) 7881 { 7882 d_printf("skip[%u] - %s\n", (unsigned)i, runs[i].name); 7883 continue; 7884 } 7885 7886 d_printf("run[%u] - %s\n", (unsigned)i, runs[i].name); 7887 7888 signing_state = runs[i].signing_setting; 7889 cli2 = open_nbt_connection(); 7890 signing_state = saved_signing_setting; 7891 if (cli2 == NULL) { 7892 goto out; 7893 } 7894 7895 status = smbXcli_negprot(cli2->conn, 7896 cli2->timeout, 7897 runs[i].protocol, 7898 runs[i].protocol); 7899 if (!NT_STATUS_IS_OK(status)) { 7900 goto out; 7901 } 7902 7903 status = cli_session_setup(cli2, 7904 username, 7905 password, 7906 strlen(password)+1, 7907 password, 7908 strlen(password)+1, 7909 workgroup); 7910 if (!NT_STATUS_IS_OK(status)) { 7911 goto out; 7912 } 7913 7914 status = cli_tree_connect(cli2, 7915 share, 7916 "?????", 7917 password, 7918 strlen(password)+1); 7919 if (!NT_STATUS_IS_OK(status)) { 7920 goto out; 7921 } 7922 7923 cli_set_timeout(cli2, 120000); /* set a really long timeout (2 minutes) */ 7924 7925 normal_caps = smb1cli_conn_capabilities(cli2->conn); 7926 7927 if (!(normal_caps & CAP_LARGE_READX)) { 7928 d_printf("Server doesn't have CAP_LARGE_READX 0x%x\n", 7929 (unsigned int)normal_caps); 7930 goto out; 7931 } 7932 7933 if (do_encrypt) { 7934 if (force_cli_encryption(cli2, share) == false) { 7935 goto out; 7936 } 7937 } else if (SERVER_HAS_UNIX_CIFS(cli2)) { 7938 uint16_t major, minor; 7939 uint32_t caplow, caphigh; 7940 7941 status = cli_unix_extensions_version(cli2, 7942 &major, &minor, 7943 &caplow, &caphigh); 7944 if (!NT_STATUS_IS_OK(status)) { 7945 goto out; 7946 } 7947 } 7948 7949 status = cli_ntcreate(cli2, fname, 0, FILE_READ_DATA, 7950 FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, 7951 0, 0, &fnum2, NULL); 7952 if (!NT_STATUS_IS_OK(status)) { 7953 d_printf("Second open %s failed: %s\n", fname, nt_errstr(status)); 7954 goto out; 7955 } 7956 7957 /* All reads must return less than file_size bytes. */ 7958 if (!large_readx_tests(cli2, fnum2, buf)) { 7959 goto out; 7960 } 7961 7962 status = cli_close(cli2, fnum2); 7963 if (!NT_STATUS_IS_OK(status)) { 7964 d_printf("cli_close failed: %s\n", nt_errstr(status)); 7965 goto out; 7966 } 7967 fnum2 = -1; 7968 7969 if (!torture_close_connection(cli2)) { 7970 goto out; 7971 } 7972 cli2 = NULL; 7973 } 7974 7975 correct = true; 7976 printf("Success on large_readx test\n"); 7977 7978 out: 7979 7980 if (cli2) { 7981 if (!torture_close_connection(cli2)) { 7982 correct = false; 7983 } 7984 } 7985 7986 if (cli1) { 7987 if (fnum1 != UINT16_MAX) { 7988 status = cli_close(cli1, fnum1); 7989 if (!NT_STATUS_IS_OK(status)) { 7990 d_printf("cli_close failed: %s\n", nt_errstr(status)); 7991 } 7992 fnum1 = UINT16_MAX; 7993 } 7994 7995 status = cli_unlink(cli1, fname, 7996 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 7997 if (!NT_STATUS_IS_OK(status)) { 7998 printf("unlink failed (%s)\n", nt_errstr(status)); 7999 } 8000 8001 if (!torture_close_connection(cli1)) { 8002 correct = false; 8003 } 8004 } 8005 8006 TALLOC_FREE(frame); 8007 8008 printf("finished large_readx test\n"); 8009 return correct; 8010 } 8011 6661 8012 static bool run_cli_echo(int dummy) 6662 8013 { … … 6668 8019 return false; 6669 8020 } 6670 cli_sockopt(cli, sockops);8021 smbXcli_conn_set_sockopt(cli->conn, sockops); 6671 8022 6672 8023 status = cli_echo(cli, 5, data_blob_const("hello", 5)); … … 6692 8043 } 6693 8044 6694 cli_sockopt(cli, sockops);8045 smbXcli_conn_set_sockopt(cli->conn, sockops); 6695 8046 6696 8047 /* Ok - now save then logoff our current user. */ 6697 old_vuid = cli ->vuid;8048 old_vuid = cli_state_get_uid(cli); 6698 8049 6699 8050 status = cli_ulogoff(cli); … … 6705 8056 } 6706 8057 6707 cli ->vuid = old_vuid;8058 cli_state_set_uid(cli, old_vuid); 6708 8059 6709 8060 /* Try an operation. */ … … 6716 8067 } else { 6717 8068 /* Should be bad uid. */ 6718 if (!check_error(__LINE__, cli, ERRSRV, ERRbaduid,6719 NT_STATUS_USER_SESSION_DELETED)) {8069 if (!check_error(__LINE__, status, ERRSRV, ERRbaduid, 8070 NT_STATUS_USER_SESSION_DELETED)) { 6720 8071 correct = false; 6721 8072 goto out; … … 6723 8074 } 6724 8075 6725 old_cnum = cli ->cnum;8076 old_cnum = cli_state_get_tid(cli); 6726 8077 6727 8078 /* Now try a SMBtdis with the invald vuid set to zero. */ 6728 cli ->vuid = 0;8079 cli_state_set_uid(cli, 0); 6729 8080 6730 8081 /* This should succeed. */ … … 6739 8090 } 6740 8091 6741 cli ->vuid = old_vuid;6742 cli ->cnum = old_cnum;8092 cli_state_set_uid(cli, old_vuid); 8093 cli_state_set_tid(cli, old_cnum); 6743 8094 6744 8095 /* This should fail. */ … … 6750 8101 } else { 6751 8102 /* Should be bad tid. */ 6752 if (!check_error(__LINE__, cli, ERRSRV, ERRinvnid,8103 if (!check_error(__LINE__, status, ERRSRV, ERRinvnid, 6753 8104 NT_STATUS_NETWORK_NAME_DELETED)) { 6754 8105 correct = false; … … 6813 8164 6814 8165 if (strchr(force_shortname_chars, i)) { 6815 if (!finfo->short_name [0]) {8166 if (!finfo->short_name) { 6816 8167 /* Shortname not created when it should be. */ 6817 8168 d_printf("(%s) ERROR: Shortname was not created for file %s containing %d\n", … … 6819 8170 s->val = true; 6820 8171 } 6821 } else if (finfo->short_name [0]){8172 } else if (finfo->short_name){ 6822 8173 /* Shortname created when it should not be. */ 6823 8174 d_printf("(%s) ERROR: Shortname %s was created for file %s\n", … … 6835 8186 int i; 6836 8187 struct sn_state s; 6837 char fname[20]; 8188 char fname[40]; 8189 NTSTATUS status; 6838 8190 6839 8191 printf("starting shortname test\n"); … … 6843 8195 } 6844 8196 6845 cli_sockopt(cli, sockops);8197 smbXcli_conn_set_sockopt(cli->conn, sockops); 6846 8198 6847 8199 cli_list(cli, "\\shortname\\*", 0, shortname_del_fn, cli); … … 6849 8201 cli_rmdir(cli, "\\shortname"); 6850 8202 6851 if (!NT_STATUS_IS_OK(cli_mkdir(cli, "\\shortname"))) { 8203 status = cli_mkdir(cli, "\\shortname"); 8204 if (!NT_STATUS_IS_OK(status)) { 6852 8205 d_printf("(%s) cli_mkdir of \\shortname failed: %s\n", 6853 __location__, cli_errstr(cli));8206 __location__, nt_errstr(status)); 6854 8207 correct = false; 6855 8208 goto out; 6856 8209 } 6857 8210 6858 strlcpy(fname, "\\shortname\\", sizeof(fname)); 6859 strlcat(fname, "test .txt", sizeof(fname)); 8211 if (strlcpy(fname, "\\shortname\\", sizeof(fname)) >= sizeof(fname)) { 8212 correct = false; 8213 goto out; 8214 } 8215 if (strlcat(fname, "test .txt", sizeof(fname)) >= sizeof(fname)) { 8216 correct = false; 8217 goto out; 8218 } 6860 8219 6861 8220 s.val = false; 6862 8221 6863 8222 for (i = 32; i < 128; i++) { 6864 NTSTATUS status;6865 8223 uint16_t fnum = (uint16_t)-1; 6866 8224 … … 6873 8231 6874 8232 status = cli_ntcreate(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL, 6875 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0, &fnum); 8233 FILE_SHARE_READ|FILE_SHARE_WRITE, 8234 FILE_OVERWRITE_IF, 0, 0, &fnum, NULL); 6876 8235 if (!NT_STATUS_IS_OK(status)) { 6877 8236 d_printf("(%s) cli_nt_create of %s failed: %s\n", 6878 __location__, fname, cli_errstr(cli));8237 __location__, fname, nt_errstr(status)); 6879 8238 correct = false; 6880 8239 goto out; … … 6883 8242 6884 8243 s.matched = 0; 6885 cli_list(cli, "\\shortname\\test*.*", 0, shortname_list_fn,6886 &s);8244 status = cli_list(cli, "\\shortname\\test*.*", 0, 8245 shortname_list_fn, &s); 6887 8246 if (s.matched != 1) { 6888 8247 d_printf("(%s) failed to list %s: %s\n", 6889 __location__, fname, cli_errstr(cli));8248 __location__, fname, nt_errstr(status)); 6890 8249 correct = false; 6891 8250 goto out; 6892 8251 } 6893 if (!NT_STATUS_IS_OK(cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN))) { 8252 8253 status = cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); 8254 if (!NT_STATUS_IS_OK(status)) { 6894 8255 d_printf("(%s) failed to delete %s: %s\n", 6895 __location__, fname, cli_errstr(cli));8256 __location__, fname, nt_errstr(status)); 6896 8257 correct = false; 6897 8258 goto out; … … 6980 8341 d_printf("defaultNamingContext: %s\n", basedn); 6981 8342 6982 ev = tevent_context_init(talloc_tos());8343 ev = samba_tevent_context_init(talloc_tos()); 6983 8344 if (ev == NULL) { 6984 8345 d_printf("tevent_context_init failed\n"); … … 7056 8417 sleep(3); 7057 8418 7058 status = cli_open (cli, fname, O_RDWR | O_CREAT | O_EXCL,8419 status = cli_openx(cli, fname, O_RDWR | O_CREAT | O_EXCL, 7059 8420 DENY_NONE, &fnum); 7060 8421 if (!NT_STATUS_IS_OK(status)) { 7061 printf("cli_open failed: %s\n", nt_errstr(status));8422 printf("cli_openx failed: %s\n", nt_errstr(status)); 7062 8423 goto out; 7063 8424 } … … 7097 8458 NTSTATUS status; 7098 8459 time_t change_time, access_time, write_time; 7099 SMB_OFF_Tsize;8460 off_t size; 7100 8461 uint16_t mode, fnum; 7101 8462 bool ret = true; … … 7114 8475 } 7115 8476 7116 cli_qpathinfo1(cli, streamname, &change_time, &access_time, &write_time, 7117 &size, &mode); 7118 status = cli_nt_error(cli); 7119 8477 status = cli_qpathinfo1(cli, streamname, &change_time, &access_time, 8478 &write_time, &size, &mode); 7120 8479 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { 7121 8480 printf("pathinfo returned %s, expected " … … 7129 8488 FILE_READ_ATTRIBUTES|READ_CONTROL_ACCESS, 7130 8489 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, 7131 FILE_OPEN, 0, 0, &fnum );8490 FILE_OPEN, 0, 0, &fnum, NULL); 7132 8491 7133 8492 if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) { … … 7197 8556 } 7198 8557 8558 static void parse_fn(time_t timeout, DATA_BLOB blob, void *private_data) 8559 { 8560 return; 8561 } 8562 7199 8563 static bool run_local_gencache(int dummy) 7200 8564 { … … 7202 8566 time_t tm; 7203 8567 DATA_BLOB blob; 8568 char v; 8569 struct memcache *mem; 8570 int i; 8571 8572 mem = memcache_init(NULL, 0); 8573 if (mem == NULL) { 8574 d_printf("%s: memcache_init failed\n", __location__); 8575 return false; 8576 } 8577 memcache_set_global(mem); 7204 8578 7205 8579 if (!gencache_set("foo", "bar", time(NULL) + 1000)) { … … 7208 8582 } 7209 8583 7210 if (!gencache_get("foo", NULL, NULL )) {8584 if (!gencache_get("foo", NULL, NULL, NULL)) { 7211 8585 d_printf("%s: gencache_get() failed\n", __location__); 7212 8586 return False; 7213 8587 } 7214 8588 7215 if (!gencache_get("foo", &val, &tm)) { 8589 for (i=0; i<1000000; i++) { 8590 gencache_parse("foo", parse_fn, NULL); 8591 } 8592 8593 if (!gencache_get("foo", talloc_tos(), &val, &tm)) { 8594 d_printf("%s: gencache_get() failed\n", __location__); 8595 return False; 8596 } 8597 TALLOC_FREE(val); 8598 8599 if (!gencache_get("foo", talloc_tos(), &val, &tm)) { 7216 8600 d_printf("%s: gencache_get() failed\n", __location__); 7217 8601 return False; … … 7221 8605 d_printf("%s: gencache_get() returned %s, expected %s\n", 7222 8606 __location__, val, "bar"); 7223 SAFE_FREE(val);7224 return False; 7225 } 7226 7227 SAFE_FREE(val);8607 TALLOC_FREE(val); 8608 return False; 8609 } 8610 8611 TALLOC_FREE(val); 7228 8612 7229 8613 if (!gencache_del("foo")) { … … 7237 8621 } 7238 8622 7239 if (gencache_get("foo", &val, &tm)) {8623 if (gencache_get("foo", talloc_tos(), &val, &tm)) { 7240 8624 d_printf("%s: gencache_get() on deleted entry " 7241 8625 "succeeded\n", __location__); … … 7251 8635 } 7252 8636 7253 if (!gencache_get_data_blob("foo", &blob, NULL, NULL)) {8637 if (!gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) { 7254 8638 d_printf("%s: gencache_get_data_blob() failed\n", __location__); 7255 8639 return False; … … 7275 8659 } 7276 8660 7277 if (gencache_get_data_blob("foo", &blob, NULL, NULL)) {8661 if (gencache_get_data_blob("foo", talloc_tos(), &blob, NULL, NULL)) { 7278 8662 d_printf("%s: gencache_get_data_blob() on deleted entry " 7279 8663 "succeeded\n", __location__); 7280 8664 return False; 8665 } 8666 8667 v = 1; 8668 blob.data = (uint8_t *)&v; 8669 blob.length = sizeof(v); 8670 8671 if (!gencache_set_data_blob("blob", &blob, tm)) { 8672 d_printf("%s: gencache_set_data_blob() failed\n", 8673 __location__); 8674 return false; 8675 } 8676 if (gencache_get("blob", talloc_tos(), &val, &tm)) { 8677 d_printf("%s: gencache_get succeeded\n", __location__); 8678 return false; 7281 8679 } 7282 8680 … … 7291 8689 bool ret = false; 7292 8690 NTSTATUS status; 7293 7294 rec = db->fetch_locked(db, db, string_tdb_data(key)); 8691 TDB_DATA dbvalue; 8692 8693 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key)); 7295 8694 if (rec == NULL) { 7296 8695 d_fprintf(stderr, "fetch_locked failed\n"); 7297 8696 goto done; 7298 8697 } 7299 status = rec->store(rec, data, 0);8698 status = dbwrap_record_store(rec, data, 0); 7300 8699 if (!NT_STATUS_IS_OK(status)) { 7301 8700 d_fprintf(stderr, "store failed: %s\n", nt_errstr(status)); … … 7304 8703 TALLOC_FREE(rec); 7305 8704 7306 rec = db ->fetch_locked(db, db, string_tdb_data(key));8705 rec = dbwrap_fetch_locked(db, db, string_tdb_data(key)); 7307 8706 if (rec == NULL) { 7308 8707 d_fprintf(stderr, "second fetch_locked failed\n"); 7309 8708 goto done; 7310 8709 } 7311 if ((rec->value.dsize != data.dsize) 7312 || (memcmp(rec->value.dptr, data.dptr, data.dsize) != 0)) { 8710 8711 dbvalue = dbwrap_record_get_value(rec); 8712 if ((dbvalue.dsize != data.dsize) 8713 || (memcmp(dbvalue.dptr, data.dptr, data.dsize) != 0)) { 7313 8714 d_fprintf(stderr, "Got wrong data back\n"); 7314 8715 goto done; … … 7321 8722 } 7322 8723 8724 static int local_rbtree_traverse_read(struct db_record *rec, void *private_data) 8725 { 8726 int *count2 = (int *)private_data; 8727 (*count2)++; 8728 return 0; 8729 } 8730 8731 static int local_rbtree_traverse_delete(struct db_record *rec, void *private_data) 8732 { 8733 int *count2 = (int *)private_data; 8734 (*count2)++; 8735 dbwrap_record_delete(rec); 8736 return 0; 8737 } 8738 7323 8739 static bool run_local_rbtree(int dummy) 7324 8740 { … … 7326 8742 bool ret = false; 7327 8743 int i; 8744 NTSTATUS status; 8745 int count = 0; 8746 int count2 = 0; 7328 8747 7329 8748 db = db_open_rbt(NULL); … … 7368 8787 7369 8788 ret = true; 8789 count = 0; count2 = 0; 8790 status = dbwrap_traverse_read(db, local_rbtree_traverse_read, 8791 &count2, &count); 8792 printf("%s: read1: %d %d, %s\n", __func__, count, count2, nt_errstr(status)); 8793 if ((count != count2) || (count != 1000)) { 8794 ret = false; 8795 } 8796 count = 0; count2 = 0; 8797 status = dbwrap_traverse(db, local_rbtree_traverse_delete, 8798 &count2, &count); 8799 printf("%s: delete: %d %d, %s\n", __func__, count, count2, nt_errstr(status)); 8800 if ((count != count2) || (count != 1000)) { 8801 ret = false; 8802 } 8803 count = 0; count2 = 0; 8804 status = dbwrap_traverse_read(db, local_rbtree_traverse_read, 8805 &count2, &count); 8806 printf("%s: read2: %d %d, %s\n", __func__, count, count2, nt_errstr(status)); 8807 if ((count != count2) || (count != 0)) { 8808 ret = false; 8809 } 7370 8810 7371 8811 done: … … 7374 8814 } 7375 8815 8816 8817 /* 8818 local test for character set functions 8819 8820 This is a very simple test for the functionality in convert_string_error() 8821 */ 8822 static bool run_local_convert_string(int dummy) 8823 { 8824 TALLOC_CTX *tmp_ctx = talloc_new(NULL); 8825 const char *test_strings[2] = { "March", "M\303\244rz" }; 8826 char dst[7]; 8827 int i; 8828 8829 for (i=0; i<2; i++) { 8830 const char *str = test_strings[i]; 8831 int len = strlen(str); 8832 size_t converted_size; 8833 bool ret; 8834 8835 memset(dst, 'X', sizeof(dst)); 8836 8837 /* first try with real source length */ 8838 ret = convert_string_error(CH_UNIX, CH_UTF8, 8839 str, len, 8840 dst, sizeof(dst), 8841 &converted_size); 8842 if (ret != true) { 8843 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str); 8844 goto failed; 8845 } 8846 8847 if (converted_size != len) { 8848 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n", 8849 str, len, (int)converted_size); 8850 goto failed; 8851 } 8852 8853 if (strncmp(str, dst, converted_size) != 0) { 8854 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst); 8855 goto failed; 8856 } 8857 8858 if (strlen(str) != converted_size) { 8859 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str, 8860 (int)strlen(str), (int)converted_size); 8861 goto failed; 8862 } 8863 8864 if (dst[converted_size] != 'X') { 8865 d_fprintf(stderr, "Expected no termination of '%s'\n", dst); 8866 goto failed; 8867 } 8868 8869 /* now with srclen==-1, this causes the nul to be 8870 * converted too */ 8871 ret = convert_string_error(CH_UNIX, CH_UTF8, 8872 str, -1, 8873 dst, sizeof(dst), 8874 &converted_size); 8875 if (ret != true) { 8876 d_fprintf(stderr, "Failed to convert '%s' to CH_DISPLAY\n", str); 8877 goto failed; 8878 } 8879 8880 if (converted_size != len+1) { 8881 d_fprintf(stderr, "Converted size of '%s' should be %d - got %d\n", 8882 str, len, (int)converted_size); 8883 goto failed; 8884 } 8885 8886 if (strncmp(str, dst, converted_size) != 0) { 8887 d_fprintf(stderr, "Expected '%s' to match '%s'\n", str, dst); 8888 goto failed; 8889 } 8890 8891 if (len+1 != converted_size) { 8892 d_fprintf(stderr, "Expected '%s' length %d - got %d\n", str, 8893 len+1, (int)converted_size); 8894 goto failed; 8895 } 8896 8897 if (dst[converted_size] != 'X') { 8898 d_fprintf(stderr, "Expected no termination of '%s'\n", dst); 8899 goto failed; 8900 } 8901 8902 } 8903 8904 8905 TALLOC_FREE(tmp_ctx); 8906 return true; 8907 failed: 8908 TALLOC_FREE(tmp_ctx); 8909 return false; 8910 } 8911 8912 7376 8913 struct talloc_dict_test { 7377 8914 int content; … … 7389 8926 struct talloc_dict *dict; 7390 8927 struct talloc_dict_test *t; 7391 int key, count; 8928 int key, count, res; 8929 bool ok; 7392 8930 7393 8931 dict = talloc_dict_init(talloc_tos()); … … 7403 8941 key = 1; 7404 8942 t->content = 1; 7405 if (!talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), t)) { 8943 ok = talloc_dict_set(dict, data_blob_const(&key, sizeof(key)), &t); 8944 if (!ok) { 7406 8945 return false; 7407 8946 } 7408 8947 7409 8948 count = 0; 7410 if (talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count) != 0) { 8949 res = talloc_dict_traverse(dict, talloc_dict_traverse_fn, &count); 8950 if (res == -1) { 7411 8951 return false; 7412 8952 } 7413 8953 7414 8954 if (count != 1) { 8955 return false; 8956 } 8957 8958 if (count != res) { 7415 8959 return false; 7416 8960 } … … 7438 8982 if (string_to_sid(&sid, "S-1-5-32-545-abc")) { 7439 8983 printf("allowing S-1-5-32-545-abc\n"); 8984 return false; 8985 } 8986 if (string_to_sid(&sid, "S-300-5-32-545")) { 8987 printf("allowing S-300-5-32-545\n"); 8988 return false; 8989 } 8990 if (string_to_sid(&sid, "S-1-0xfffffffffffffe-32-545")) { 8991 printf("allowing S-1-0xfffffffffffffe-32-545\n"); 8992 return false; 8993 } 8994 if (string_to_sid(&sid, "S-1-0xffffffffffff-5294967297-545")) { 8995 printf("allowing S-1-0xffffffffffff-5294967297-545\n"); 8996 return false; 8997 } 8998 if (!string_to_sid(&sid, "S-1-0xfffffffffffe-32-545")) { 8999 printf("could not parse S-1-0xfffffffffffe-32-545\n"); 7440 9000 return false; 7441 9001 } … … 7452 9012 } 7453 9013 9014 static bool sid_to_string_test(const char *expected) { 9015 char *str; 9016 bool res = true; 9017 struct dom_sid sid; 9018 9019 if (!string_to_sid(&sid, expected)) { 9020 printf("could not parse %s\n", expected); 9021 return false; 9022 } 9023 9024 str = dom_sid_string(NULL, &sid); 9025 if (strcmp(str, expected)) { 9026 printf("Comparison failed (%s != %s)\n", str, expected); 9027 res = false; 9028 } 9029 TALLOC_FREE(str); 9030 return res; 9031 } 9032 9033 static bool run_local_sid_to_string(int dummy) { 9034 if (!sid_to_string_test("S-1-0xffffffffffff-1-1-1-1-1-1-1-1-1-1-1-1")) 9035 return false; 9036 if (!sid_to_string_test("S-1-545")) 9037 return false; 9038 if (!sid_to_string_test("S-255-3840-1-1-1-1")) 9039 return false; 9040 return true; 9041 } 9042 7454 9043 static bool run_local_binary_to_sid(int dummy) { 7455 9044 struct dom_sid *sid = talloc(NULL, struct dom_sid); 7456 static const chargood_binary_sid[] = {9045 static const uint8_t good_binary_sid[] = { 7457 9046 0x1, /* revision number */ 7458 9047 15, /* num auths */ … … 7475 9064 }; 7476 9065 7477 static const charlong_binary_sid[] = {9066 static const uint8_t long_binary_sid[] = { 7478 9067 0x1, /* revision number */ 7479 9068 15, /* num auths */ … … 7499 9088 }; 7500 9089 7501 static const charlong_binary_sid2[] = {9090 static const uint8_t long_binary_sid2[] = { 7502 9091 0x1, /* revision number */ 7503 9092 32, /* num auths */ … … 7591 9180 } 7592 9181 else { 7593 if ( StrCaseCmp(stype, ":$DATA") != 0) {9182 if (strcasecmp_m(stype, ":$DATA") != 0) { 7594 9183 /* 7595 9184 * If there is an explicit stream type, so far we only … … 7626 9215 * upper-case the type field 7627 9216 */ 7628 strupper_m(strchr_m(stream, ':')+1);9217 (void)strupper_m(strchr_m(stream, ':')+1); 7629 9218 } 7630 9219 … … 7733 9322 bool ret = false; 7734 9323 7735 cache = memcache_init(NULL, 100);9324 cache = memcache_init(NULL, sizeof(void *) == 8 ? 200 : 100); 7736 9325 7737 9326 if (cache == NULL) { … … 7825 9414 } 7826 9415 7827 static bool run_ local_wbclient(int dummy)7828 { 7829 struct event_context *ev;9416 static bool run_wbclient_multi_ping(int dummy) 9417 { 9418 struct tevent_context *ev; 7830 9419 struct wb_context **wb_ctx; 7831 9420 struct winbindd_request wb_req; … … 7835 9424 BlockSignals(True, SIGPIPE); 7836 9425 7837 ev = tevent_context_init _byname(talloc_tos(), "epoll");9426 ev = tevent_context_init(talloc_tos()); 7838 9427 if (ev == NULL) { 7839 9428 goto fail; 7840 9429 } 7841 9430 7842 wb_ctx = TALLOC_ARRAY(ev, struct wb_context *,nprocs);9431 wb_ctx = talloc_array(ev, struct wb_context *, torture_nprocs); 7843 9432 if (wb_ctx == NULL) { 7844 9433 goto fail; … … 7848 9437 wb_req.cmd = WINBINDD_PING; 7849 9438 7850 d_printf(" nprocs=%d, numops=%d\n", (int)nprocs, (int)torture_numops);7851 7852 for (i=0; i< nprocs; i++) {9439 d_printf("torture_nprocs=%d, numops=%d\n", (int)torture_nprocs, (int)torture_numops); 9440 9441 for (i=0; i<torture_nprocs; i++) { 7853 9442 wb_ctx[i] = wb_context_init(ev, NULL); 7854 9443 if (wb_ctx[i] == NULL) { … … 7868 9457 i = 0; 7869 9458 7870 while (i < nprocs * torture_numops) {7871 event_loop_once(ev);9459 while (i < torture_nprocs * torture_numops) { 9460 tevent_loop_once(ev); 7872 9461 } 7873 9462 … … 7904 9493 int i; 7905 9494 7906 ev = event_context_init(frame);9495 ev = samba_tevent_context_init(frame); 7907 9496 if (ev == NULL) { 7908 9497 goto fail; … … 7918 9507 } 7919 9508 tevent_req_set_callback(reqs[i], getaddrinfo_finished, 7920 (void *)names[i]);9509 discard_const_p(void, names[i])); 7921 9510 } 7922 9511 … … 7934 9523 { 7935 9524 struct db_record *rec; 7936 uint32_t *val;9525 uint32_t val; 7937 9526 bool ret = false; 7938 9527 NTSTATUS status; 7939 7940 rec = db->fetch_locked(db, db, string_term_tdb_data("transtest")); 9528 TDB_DATA value; 9529 9530 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest")); 7941 9531 if (rec == NULL) { 7942 9532 printf(__location__ "fetch_lock failed\n"); … … 7944 9534 } 7945 9535 7946 if (rec->value.dsize != sizeof(uint32_t)) { 9536 value = dbwrap_record_get_value(rec); 9537 9538 if (value.dsize != sizeof(uint32_t)) { 7947 9539 printf(__location__ "value.dsize = %d\n", 7948 (int) rec->value.dsize);9540 (int)value.dsize); 7949 9541 goto fail; 7950 9542 } 7951 9543 7952 val = (uint32_t *)rec->value.dptr; 7953 *val += 1; 7954 7955 status = rec->store(rec, make_tdb_data((uint8_t *)val, 7956 sizeof(uint32_t)), 7957 0); 9544 memcpy(&val, value.dptr, sizeof(val)); 9545 val += 1; 9546 9547 status = dbwrap_record_store( 9548 rec, make_tdb_data((uint8_t *)&val, sizeof(val)), 0); 7958 9549 if (!NT_STATUS_IS_OK(status)) { 7959 9550 printf(__location__ "store failed: %s\n", … … 7975 9566 uint32_t initial; 7976 9567 int res; 9568 TDB_DATA value; 7977 9569 7978 9570 db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT, 7979 O_RDWR|O_CREAT, 0600); 9571 O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1, 9572 DBWRAP_FLAG_NONE); 7980 9573 if (db == NULL) { 7981 9574 printf("Could not open transtest.db\n"); … … 7983 9576 } 7984 9577 7985 res = db ->transaction_start(db);7986 if (res == -1) {9578 res = dbwrap_transaction_start(db); 9579 if (res != 0) { 7987 9580 printf(__location__ "transaction_start failed\n"); 7988 9581 return false; 7989 9582 } 7990 9583 7991 rec = db ->fetch_locked(db, db, string_term_tdb_data("transtest"));9584 rec = dbwrap_fetch_locked(db, db, string_term_tdb_data("transtest")); 7992 9585 if (rec == NULL) { 7993 9586 printf(__location__ "fetch_lock failed\n"); … … 7995 9588 } 7996 9589 7997 if (rec->value.dptr == NULL) { 9590 value = dbwrap_record_get_value(rec); 9591 9592 if (value.dptr == NULL) { 7998 9593 initial = 0; 7999 status = rec->store(9594 status = dbwrap_record_store( 8000 9595 rec, make_tdb_data((uint8_t *)&initial, 8001 9596 sizeof(initial)), … … 8010 9605 TALLOC_FREE(rec); 8011 9606 8012 res = db ->transaction_commit(db);8013 if (res == -1) {9607 res = dbwrap_transaction_commit(db); 9608 if (res != 0) { 8014 9609 printf(__location__ "transaction_commit failed\n"); 8015 9610 return false; … … 8020 9615 int i; 8021 9616 8022 res = db ->transaction_start(db);8023 if (res == -1) {9617 res = dbwrap_transaction_start(db); 9618 if (res != 0) { 8024 9619 printf(__location__ "transaction_start failed\n"); 8025 9620 break; 8026 9621 } 8027 9622 8028 if (!dbwrap_fetch_uint32(db, "transtest", &val)) { 8029 printf(__location__ "dbwrap_fetch_uint32 failed\n"); 9623 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val); 9624 if (!NT_STATUS_IS_OK(status)) { 9625 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n", 9626 nt_errstr(status)); 8030 9627 break; 8031 9628 } … … 8037 9634 } 8038 9635 8039 if (!dbwrap_fetch_uint32(db, "transtest", &val2)) { 8040 printf(__location__ "dbwrap_fetch_uint32 failed\n"); 9636 status = dbwrap_fetch_uint32_bystring(db, "transtest", &val2); 9637 if (!NT_STATUS_IS_OK(status)) { 9638 printf(__location__ "dbwrap_fetch_uint32 failed: %s\n", 9639 nt_errstr(status)); 8041 9640 break; 8042 9641 } … … 8050 9649 printf("val2=%d\r", val2); 8051 9650 8052 res = db ->transaction_commit(db);8053 if (res == -1) {9651 res = dbwrap_transaction_commit(db); 9652 if (res != 0) { 8054 9653 printf(__location__ "transaction_commit failed\n"); 8055 9654 break; … … 8101 9700 TALLOC_FREE(ev); 8102 9701 return result; 9702 } 9703 9704 static bool run_local_hex_encode_buf(int dummy) 9705 { 9706 char buf[17]; 9707 uint8_t src[8]; 9708 int i; 9709 9710 for (i=0; i<sizeof(src); i++) { 9711 src[i] = i; 9712 } 9713 hex_encode_buf(buf, src, sizeof(src)); 9714 if (strcmp(buf, "0001020304050607") != 0) { 9715 return false; 9716 } 9717 hex_encode_buf(buf, NULL, 0); 9718 if (buf[0] != '\0') { 9719 return false; 9720 } 9721 return true; 9722 } 9723 9724 static const char *remove_duplicate_addrs2_test_strings_vector[] = { 9725 "0.0.0.0", 9726 "::0", 9727 "1.2.3.1", 9728 "0.0.0.0", 9729 "0.0.0.0", 9730 "1.2.3.2", 9731 "1.2.3.3", 9732 "1.2.3.4", 9733 "1.2.3.5", 9734 "::0", 9735 "1.2.3.6", 9736 "1.2.3.7", 9737 "::0", 9738 "::0", 9739 "::0", 9740 "1.2.3.8", 9741 "1.2.3.9", 9742 "1.2.3.10", 9743 "1.2.3.11", 9744 "1.2.3.12", 9745 "1.2.3.13", 9746 "1001:1111:1111:1000:0:1111:1111:1111", 9747 "1.2.3.1", 9748 "1.2.3.2", 9749 "1.2.3.3", 9750 "1.2.3.12", 9751 "::0", 9752 "::0" 9753 }; 9754 9755 static const char *remove_duplicate_addrs2_test_strings_result[] = { 9756 "1.2.3.1", 9757 "1.2.3.2", 9758 "1.2.3.3", 9759 "1.2.3.4", 9760 "1.2.3.5", 9761 "1.2.3.6", 9762 "1.2.3.7", 9763 "1.2.3.8", 9764 "1.2.3.9", 9765 "1.2.3.10", 9766 "1.2.3.11", 9767 "1.2.3.12", 9768 "1.2.3.13", 9769 "1001:1111:1111:1000:0:1111:1111:1111" 9770 }; 9771 9772 static bool run_local_remove_duplicate_addrs2(int dummy) 9773 { 9774 struct ip_service test_vector[28]; 9775 int count, i; 9776 9777 /* Construct the sockaddr_storage test vector. */ 9778 for (i = 0; i < 28; i++) { 9779 struct addrinfo hints; 9780 struct addrinfo *res = NULL; 9781 int ret; 9782 9783 memset(&hints, '\0', sizeof(hints)); 9784 hints.ai_flags = AI_NUMERICHOST; 9785 ret = getaddrinfo(remove_duplicate_addrs2_test_strings_vector[i], 9786 NULL, 9787 &hints, 9788 &res); 9789 if (ret) { 9790 fprintf(stderr, "getaddrinfo failed on [%s]\n", 9791 remove_duplicate_addrs2_test_strings_vector[i]); 9792 return false; 9793 } 9794 memset(&test_vector[i], '\0', sizeof(test_vector[i])); 9795 memcpy(&test_vector[i].ss, 9796 res->ai_addr, 9797 res->ai_addrlen); 9798 freeaddrinfo(res); 9799 } 9800 9801 count = remove_duplicate_addrs2(test_vector, i); 9802 9803 if (count != 14) { 9804 fprintf(stderr, "count wrong (%d) should be 14\n", 9805 count); 9806 return false; 9807 } 9808 9809 for (i = 0; i < count; i++) { 9810 char addr[INET6_ADDRSTRLEN]; 9811 9812 print_sockaddr(addr, sizeof(addr), &test_vector[i].ss); 9813 9814 if (strcmp(addr, remove_duplicate_addrs2_test_strings_result[i]) != 0) { 9815 fprintf(stderr, "mismatch on [%d] [%s] [%s]\n", 9816 i, 9817 addr, 9818 remove_duplicate_addrs2_test_strings_result[i]); 9819 return false; 9820 } 9821 } 9822 9823 printf("run_local_remove_duplicate_addrs2: success\n"); 9824 return true; 8103 9825 } 8104 9826 … … 8168 9890 synccount = 0; 8169 9891 8170 child_status = (volatile pid_t *) shm_setup(sizeof(pid_t)*nprocs);9892 child_status = (volatile pid_t *)anonymous_shared_allocate(sizeof(pid_t)*torture_nprocs); 8171 9893 if (!child_status) { 8172 9894 printf("Failed to setup shared memory\n"); … … 8174 9896 } 8175 9897 8176 child_status_out = (volatile bool *) shm_setup(sizeof(bool)*nprocs);9898 child_status_out = (volatile bool *)anonymous_shared_allocate(sizeof(bool)*torture_nprocs); 8177 9899 if (!child_status_out) { 8178 9900 printf("Failed to setup result status shared memory\n"); … … 8180 9902 } 8181 9903 8182 for (i = 0; i < nprocs; i++) {9904 for (i = 0; i < torture_nprocs; i++) { 8183 9905 child_status[i] = 0; 8184 9906 child_status_out[i] = True; … … 8187 9909 start = timeval_current(); 8188 9910 8189 for (i=0;i< nprocs;i++) {9911 for (i=0;i<torture_nprocs;i++) { 8190 9912 procnum = i; 8191 9913 if (fork() == 0) { … … 8215 9937 do { 8216 9938 synccount = 0; 8217 for (i=0;i< nprocs;i++) {9939 for (i=0;i<torture_nprocs;i++) { 8218 9940 if (child_status[i]) synccount++; 8219 9941 } 8220 if (synccount == nprocs) break;9942 if (synccount == torture_nprocs) break; 8221 9943 smb_msleep(10); 8222 9944 } while (timeval_elapsed(&start) < 30); 8223 9945 8224 if (synccount != nprocs) {8225 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);9946 if (synccount != torture_nprocs) { 9947 printf("FAILED TO START %d CLIENTS (started %d)\n", torture_nprocs, synccount); 8226 9948 *result = False; 8227 9949 return timeval_elapsed(&start); … … 8231 9953 start = timeval_current(); 8232 9954 8233 for (i=0;i< nprocs;i++) {9955 for (i=0;i<torture_nprocs;i++) { 8234 9956 child_status[i] = 0; 8235 9957 } 8236 9958 8237 printf("%d clients started\n", nprocs);8238 8239 for (i=0;i< nprocs;i++) {9959 printf("%d clients started\n", torture_nprocs); 9960 9961 for (i=0;i<torture_nprocs;i++) { 8240 9962 while (waitpid(0, &status, 0) == -1 && errno == EINTR) /* noop */ ; 8241 9963 } … … 8243 9965 printf("\n"); 8244 9966 8245 for (i=0;i< nprocs;i++) {9967 for (i=0;i<torture_nprocs;i++) { 8246 9968 if (!child_status_out[i]) { 8247 9969 *result = False; … … 8280 10002 {"OPLOCK1", run_oplock1, 0}, 8281 10003 {"OPLOCK2", run_oplock2, 0}, 8282 {"OPLOCK3", run_oplock3, 0},8283 10004 {"OPLOCK4", run_oplock4, 0}, 8284 10005 {"DIR", run_dirtest, 0}, … … 8296 10017 {"POSIX", run_simple_posix_open_test, 0}, 8297 10018 {"POSIX-APPEND", run_posix_append, 0}, 10019 {"POSIX-SYMLINK-ACL", run_acl_symlink_test, 0}, 10020 {"POSIX-SYMLINK-EA", run_ea_symlink_test, 0}, 10021 {"CASE-INSENSITIVE-CREATE", run_case_insensitive_create, 0}, 8298 10022 {"ASYNC-ECHO", run_async_echo, 0}, 8299 10023 { "UID-REGRESSION-TEST", run_uid_regression_test, 0}, … … 8306 10030 {"RENAME", run_rename, 0}, 8307 10031 {"DELETE", run_deletetest, 0}, 10032 {"WILDDELETE", run_wild_deletetest, 0}, 8308 10033 {"DELETE-LN", run_deletetest_ln, 0}, 8309 10034 {"PROPERTIES", run_properties, 0}, … … 8325 10050 { "CHAIN1", run_chain1, 0}, 8326 10051 { "CHAIN2", run_chain2, 0}, 10052 { "CHAIN3", run_chain3, 0}, 8327 10053 { "WINDOWS-WRITE", run_windows_write, 0}, 10054 { "LARGE_READX", run_large_readx, 0}, 10055 { "NTTRANS-CREATE", run_nttrans_create, 0}, 10056 { "NTTRANS-FSCTL", run_nttrans_fsctl, 0}, 8328 10057 { "CLI_ECHO", run_cli_echo, 0}, 8329 10058 { "GETADDRINFO", run_getaddrinfo_send, 0}, … … 8331 10060 { "STREAMERROR", run_streamerror }, 8332 10061 { "NOTIFY-BENCH", run_notify_bench }, 10062 { "NOTIFY-BENCH2", run_notify_bench2 }, 10063 { "NOTIFY-BENCH3", run_notify_bench3 }, 8333 10064 { "BAD-NBT-SESSION", run_bad_nbt_session }, 8334 10065 { "SMB-ANY-CONNECT", run_smb_any_connect }, 10066 { "NOTIFY-ONLINE", run_notify_online }, 10067 { "SMB2-BASIC", run_smb2_basic }, 10068 { "SMB2-NEGPROT", run_smb2_negprot }, 10069 { "SMB2-SESSION-RECONNECT", run_smb2_session_reconnect }, 10070 { "SMB2-TCON-DEPENDENCE", run_smb2_tcon_dependence }, 10071 { "SMB2-MULTI-CHANNEL", run_smb2_multi_channel }, 10072 { "SMB2-SESSION-REAUTH", run_smb2_session_reauth }, 10073 { "CLEANUP1", run_cleanup1 }, 10074 { "CLEANUP2", run_cleanup2 }, 10075 { "CLEANUP3", run_cleanup3 }, 10076 { "CLEANUP4", run_cleanup4 }, 10077 { "OPLOCK-CANCEL", run_oplock_cancel }, 8335 10078 { "LOCAL-SUBSTITUTE", run_local_substitute, 0}, 8336 10079 { "LOCAL-GENCACHE", run_local_gencache, 0}, 8337 10080 { "LOCAL-TALLOC-DICT", run_local_talloc_dict, 0}, 10081 { "LOCAL-DBWRAP-WATCH1", run_dbwrap_watch1, 0 }, 10082 { "LOCAL-MESSAGING-READ1", run_messaging_read1, 0 }, 10083 { "LOCAL-MESSAGING-READ2", run_messaging_read2, 0 }, 10084 { "LOCAL-MESSAGING-READ3", run_messaging_read3, 0 }, 10085 { "LOCAL-MESSAGING-READ4", run_messaging_read4, 0 }, 10086 { "LOCAL-MESSAGING-FDPASS1", run_messaging_fdpass1, 0 }, 10087 { "LOCAL-MESSAGING-FDPASS2", run_messaging_fdpass2, 0 }, 10088 { "LOCAL-MESSAGING-FDPASS2a", run_messaging_fdpass2a, 0 }, 10089 { "LOCAL-MESSAGING-FDPASS2b", run_messaging_fdpass2b, 0 }, 8338 10090 { "LOCAL-BASE64", run_local_base64, 0}, 8339 10091 { "LOCAL-RBTREE", run_local_rbtree, 0}, 8340 10092 { "LOCAL-MEMCACHE", run_local_memcache, 0}, 8341 10093 { "LOCAL-STREAM-NAME", run_local_stream_name, 0}, 8342 { " LOCAL-WBCLIENT", run_local_wbclient, 0},10094 { "WBCLIENT-MULTI-PING", run_wbclient_multi_ping, 0}, 8343 10095 { "LOCAL-string_to_sid", run_local_string_to_sid, 0}, 10096 { "LOCAL-sid_to_string", run_local_sid_to_string, 0}, 8344 10097 { "LOCAL-binary_to_sid", run_local_binary_to_sid, 0}, 8345 10098 { "LOCAL-DBTRANS", run_local_dbtrans, 0}, 8346 10099 { "LOCAL-TEVENT-SELECT", run_local_tevent_select, 0}, 8347 { "LOCAL-TDB-OPENER", run_local_tdb_opener, 0 }, 8348 { "LOCAL-TDB-WRITER", run_local_tdb_writer, 0 }, 10100 { "LOCAL-CONVERT-STRING", run_local_convert_string, 0}, 10101 { "LOCAL-CONV-AUTH-INFO", run_local_conv_auth_info, 0}, 10102 { "LOCAL-sprintf_append", run_local_sprintf_append, 0}, 10103 { "LOCAL-hex_encode_buf", run_local_hex_encode_buf, 0}, 10104 { "LOCAL-IDMAP-TDB-COMMON", run_idmap_tdb_common_test, 0}, 10105 { "LOCAL-remove_duplicate_addrs2", run_local_remove_duplicate_addrs2, 0}, 10106 { "local-tdb-opener", run_local_tdb_opener, 0 }, 10107 { "local-tdb-writer", run_local_tdb_writer, 0 }, 10108 { "LOCAL-DBWRAP-CTDB", run_local_dbwrap_ctdb, 0 }, 10109 { "LOCAL-BENCH-PTHREADPOOL", run_bench_pthreadpool, 0 }, 10110 { "qpathinfo-bufsize", run_qpathinfo_bufsize, 0 }, 8349 10111 {NULL, NULL, 0}}; 8350 10112 8351 10113 /* 10114 * dummy function to satisfy linker dependency 10115 */ 10116 struct tevent_context *winbind_event_context(void); 10117 struct tevent_context *winbind_event_context(void) 10118 { 10119 return NULL; 10120 } 8352 10121 8353 10122 /**************************************************************************** … … 8414 10183 printf("\t-d debuglevel\n"); 8415 10184 printf("\t-U user%%pass\n"); 8416 printf("\t-k use kerberos\n");10185 printf("\t-k use kerberos\n"); 8417 10186 printf("\t-N numprocs\n"); 8418 10187 printf("\t-n my_netbios_name\n"); … … 8422 10191 printf("\t-m maximum protocol\n"); 8423 10192 printf("\t-L use oplocks\n"); 8424 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");10193 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n"); 8425 10194 printf("\t-A showall\n"); 8426 10195 printf("\t-p port\n"); 8427 10196 printf("\t-s seed\n"); 8428 10197 printf("\t-b unclist_filename specify multiple shares for multiple connections\n"); 10198 printf("\t-f filename filename to test\n"); 10199 printf("\t-e encrypt\n"); 8429 10200 printf("\n\n"); 8430 10201 … … 8459 10230 setup_logging("smbtorture", DEBUG_STDOUT); 8460 10231 8461 load_case_tables(); 10232 smb_init_locale(); 10233 fault_setup(); 8462 10234 8463 10235 if (is_default_dyn_CONFIGFILE()) { … … 8466 10238 } 8467 10239 } 8468 lp_load (get_dyn_CONFIGFILE(),True,False,False,True);10240 lp_load_global(get_dyn_CONFIGFILE()); 8469 10241 load_interfaces(); 8470 10242 … … 8504 10276 fstrcpy(workgroup, lp_workgroup()); 8505 10277 8506 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:")) != EOF) { 10278 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ll:d:Aec:ks:b:B:f:")) 10279 != EOF) { 8507 10280 switch (opt) { 8508 10281 case 'p': … … 8516 10289 break; 8517 10290 case 'm': 8518 max_protocol = interpret_protocol(optarg, max_protocol);10291 lp_set_cmdline("client max protocol", optarg); 8519 10292 break; 8520 10293 case 'N': 8521 nprocs = atoi(optarg);10294 torture_nprocs = atoi(optarg); 8522 10295 break; 8523 10296 case 'o': … … 8573 10346 torture_blocksize = atoi(optarg); 8574 10347 break; 10348 case 'f': 10349 test_filename = SMB_STRDUP(optarg); 10350 break; 8575 10351 default: 8576 10352 printf("Unknown option %c (%d)\n", (char)opt, opt); … … 8586 10362 8587 10363 while (!gotpass) { 8588 p = getpass("Password:"); 8589 if (p) { 8590 fstrcpy(password, p); 10364 char pwd[256] = {0}; 10365 int rc; 10366 10367 rc = samba_getpass("Password:", pwd, sizeof(pwd), false, false); 10368 if (rc == 0) { 10369 fstrcpy(password, pwd); 8591 10370 gotpass = 1; 8592 10371 } -
vendor/current/source3/torture/utable.c
r740 r988 33 33 int c, len, fd; 34 34 int chars_allowed=0, alt_allowed=0; 35 uint8 valid[0x10000];35 uint8_t valid[0x10000]; 36 36 37 37 printf("starting utable\n"); … … 47 47 48 48 for (c=1; c < 0x10000; c++) { 49 size_t size = 0; 49 50 char *p; 50 51 … … 52 53 fstrcpy(fname, "\\utable\\x"); 53 54 p = fname+strlen(fname); 54 len = convert_string(CH_UTF16LE, CH_UNIX,55 if (!convert_string(CH_UTF16LE, CH_UNIX, 55 56 &c2, 2, 56 p, sizeof(fname)-strlen(fname), True); 57 p, sizeof(fname)-strlen(fname),&size)) { 58 d_printf("convert_string %s failed !\n", fname); 59 continue; 60 } 61 len = size; 57 62 p[len] = 0; 58 63 fstrcat(fname,"_a_long_extension"); 59 64 60 if (!NT_STATUS_IS_OK(cli_open (cli, fname, O_RDWR | O_CREAT | O_TRUNC,65 if (!NT_STATUS_IS_OK(cli_openx(cli, fname, O_RDWR | O_CREAT | O_TRUNC, 61 66 DENY_NONE, &fnum))) { 62 67 continue; … … 108 113 smb_ucs2_t c2; 109 114 char *p; 110 int len;115 size_t len = 0; 111 116 112 117 fstrcpy(fname, "\\utable\\"); … … 114 119 SSVAL(&c2, 0, c); 115 120 116 len = convert_string(CH_UTF16LE, CH_UNIX,121 if (!convert_string(CH_UTF16LE, CH_UNIX, 117 122 &c2, 2, 118 p, sizeof(fname)-strlen(fname), True); 123 p, sizeof(fname)-strlen(fname), &len)) { 124 d_printf("form_name: convert string %s failed\n", 125 fname); 126 return NULL; 127 } 119 128 p[len] = 0; 120 129 return fname; … … 145 154 146 155 for (c=1; c < 0x10000; c++) { 147 SMB_OFF_Tsize;156 off_t size; 148 157 149 158 if (c == '.' || c == '\\') continue; … … 156 165 FILE_ATTRIBUTE_NORMAL, 157 166 FILE_SHARE_NONE, 158 FILE_OPEN_IF, 0, 0, &fnum ))) {167 FILE_OPEN_IF, 0, 0, &fnum, NULL))) { 159 168 printf("Failed to create file with char %04x\n", c); 160 169 continue; … … 180 189 } 181 190 182 cli_read(cli, fnum, (char *)c2, 0, size );191 cli_read(cli, fnum, (char *)c2, 0, size, NULL); 183 192 printf("%04x: ", c); 184 193 equiv[c][0] = c; -
vendor/current/source3/torture/vfstest.c
r740 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 VFS module tester … … 14 14 the Free Software Foundation; either version 3 of the License, or 15 15 (at your option) any later version. 16 16 17 17 This program is distributed in the hope that it will be useful, 18 18 but WITHOUT ANY WARRANTY; without even the implied warranty of 19 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 20 GNU General Public License for more details. 21 21 22 22 You should have received a copy of the GNU General Public License 23 23 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 26 26 #include "includes.h" 27 27 #include "smbd/smbd.h" 28 #include "smbd/globals.h" 28 29 #include "popt_common.h" 29 30 #include "vfstest.h" 30 31 #include "../libcli/smbreadline/smbreadline.h" 32 #include "auth.h" 33 #include "serverid.h" 34 #include "messages.h" 35 #include "libcli/security/security.h" 36 #include "lib/smbd_shim.h" 37 #include "system/filesys.h" 31 38 32 39 /* List to hold groups of commands */ … … 36 43 } *cmd_list; 37 44 45 /* shall we do talloc_report after each command? */ 46 static int memreports = 0; 47 38 48 /**************************************************************************** 39 49 handle completion of commands for readline … … 46 56 struct cmd_list *commands = cmd_list; 47 57 48 if (start) 58 if (start) 49 59 return NULL; 50 60 51 61 /* make sure we have a list of valid commands */ 52 if (!commands) 62 if (!commands) 53 63 return NULL; 54 64 … … 59 69 if (!matches[0]) return NULL; 60 70 61 while (commands && count < MAX_COMPLETIONS-1) 71 while (commands && count < MAX_COMPLETIONS-1) 62 72 { 63 73 if (!commands->cmd_set) 64 74 break; 65 75 66 76 for (i=0; commands->cmd_set[i].name; i++) 67 77 { 68 78 if ((strncmp(text, commands->cmd_set[i].name, strlen(text)) == 0) && 69 commands->cmd_set[i].fn) 79 commands->cmd_set[i].fn) 70 80 { 71 81 matches[count] = SMB_STRDUP(commands->cmd_set[i].name); 72 if (!matches[count]) 82 if (!matches[count]) 73 83 return NULL; 74 84 count++; 75 85 } 76 86 } 77 87 78 88 commands = commands->next; 79 80 89 } 81 90 … … 100 109 *p = '\0'; 101 110 command = talloc_strdup(ctx, *cmdstr); 102 *cmdstr = p; 111 112 /* Pass back the remaining cmdstring 113 (a trailing delimiter ";" does also work), 114 or NULL at last cmdstring. 115 */ 116 *cmdstr = p ? p + 1 : p; 103 117 104 118 return command; … … 114 128 } 115 129 116 if (!lp_load (argv[1], False, True, False, True)) {130 if (!lp_load_with_shares(argv[1])) { 117 131 printf("Error loading \"%s\"\n", argv[1]); 118 132 return NT_STATUS_OK; … … 122 136 return NT_STATUS_OK; 123 137 } 124 138 125 139 /* Display help on commands */ 126 140 static NTSTATUS cmd_help(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, … … 140 154 if (argc == 2) { 141 155 for (tmp = cmd_list; tmp; tmp = tmp->next) { 142 156 143 157 tmp_set = tmp->cmd_set; 144 158 … … 263 277 { 264 278 const char *p = cmd; 265 c har **argv = NULL;279 const char **argv = NULL; 266 280 NTSTATUS result = NT_STATUS_UNSUCCESSFUL; 267 281 char *buf; 268 282 TALLOC_CTX *mem_ctx = talloc_stackframe(); 269 int argc = 0 , i;283 int argc = 0; 270 284 271 285 /* Count number of arguments first time through the loop then … … 275 289 while(next_token_talloc(mem_ctx, &p, &buf, " ")) { 276 290 if (argv) { 277 argv[argc] = SMB_STRDUP(buf);291 argv[argc] = talloc_strdup(argv, buf); 278 292 } 279 293 argc++; … … 283 297 /* Create argument list */ 284 298 285 argv = SMB_MALLOC_ARRAY(char *, argc); 286 memset(argv, 0, sizeof(char *) * argc); 287 288 if (!argv) { 299 argv = talloc_zero_array(mem_ctx, const char *, argc); 300 if (argv == NULL) { 289 301 fprintf(stderr, "out of memory\n"); 290 302 result = NT_STATUS_NO_MEMORY; … … 313 325 314 326 if (argv) { 315 for (i = 0; i < argc; i++) 316 SAFE_FREE(argv[i]); 317 318 SAFE_FREE(argv); 319 } 320 327 char **_argv = discard_const_p(char *, argv); 328 TALLOC_FREE(_argv); 329 argv = NULL; 330 } 331 332 if (memreports != 0) { 333 talloc_report_full(mem_ctx, stdout); 334 } 321 335 TALLOC_FREE(mem_ctx); 322 336 return result; … … 402 416 } 403 417 404 void exit_server(const char *reason) 418 static void vfstest_exit_server(const char * const reason) _NORETURN_; 419 static void vfstest_exit_server(const char * const reason) 405 420 { 406 421 DEBUG(3,("Server exit (%s)\n", (reason ? reason : ""))); … … 408 423 } 409 424 410 void exit_server_cleanly(const char *const reason) 411 { 412 exit_server("normal exit"); 413 } 414 415 int last_message = -1; 416 417 struct event_context *smbd_event_context(void) 418 { 419 static struct event_context *ctx; 420 421 if (!ctx && !(ctx = event_context_init(NULL))) { 422 smb_panic("Could not init smbd event context\n"); 423 } 424 return ctx; 425 static void vfstest_exit_server_cleanly(const char * const reason) _NORETURN_; 426 static void vfstest_exit_server_cleanly(const char * const reason) 427 { 428 vfstest_exit_server("normal exit"); 429 } 430 431 struct smb_request *vfstest_get_smbreq(TALLOC_CTX *mem_ctx, 432 struct vfs_state *vfs) 433 { 434 struct smb_request *result; 435 uint8_t *inbuf; 436 437 result = talloc_zero(mem_ctx, struct smb_request); 438 if (result == NULL) { 439 return NULL; 440 } 441 result->sconn = vfs->conn->sconn; 442 result->mid = ++vfs->mid; 443 444 inbuf = talloc_array(result, uint8_t, smb_size); 445 if (inbuf == NULL) { 446 goto fail; 447 } 448 SSVAL(inbuf, smb_mid, result->mid); 449 smb_setlen(inbuf, smb_size-4); 450 result->inbuf = inbuf; 451 return result; 452 fail: 453 TALLOC_FREE(result); 454 return NULL; 425 455 } 426 456 427 457 /* Main function */ 428 458 429 int main(int argc, c har *argv[])430 { 431 static char*cmdstr = NULL;432 struct cmd_set 433 st atic struct vfs_statevfs;459 int main(int argc, const char *argv[]) 460 { 461 char *cmdstr = NULL; 462 struct cmd_set **cmd_set; 463 struct vfs_state *vfs; 434 464 int i; 435 static char *filename = NULL; 465 char *filename = NULL; 466 char cwd[MAXPATHLEN]; 436 467 TALLOC_CTX *frame = talloc_stackframe(); 468 struct tevent_context *ev; 469 struct auth_session_info *session_info = NULL; 470 NTSTATUS status = NT_STATUS_OK; 437 471 438 472 /* make sure the vars that get altered (4th field) are in … … 443 477 {"file", 'f', POPT_ARG_STRING, &filename, 0, }, 444 478 {"command", 'c', POPT_ARG_STRING, &cmdstr, 0, "Execute specified list of commands" }, 479 {"memreport", 'm', POPT_ARG_INT, &memreports, 0, 480 "Report memory left on talloc stackframe after each command" }, 445 481 POPT_COMMON_SAMBA 446 482 POPT_TABLEEND 447 483 }; 448 449 load_case_tables(); 484 static const struct smbd_shim vfstest_shim_fns = 485 { 486 .exit_server = vfstest_exit_server, 487 .exit_server_cleanly = vfstest_exit_server_cleanly, 488 }; 489 490 smb_init_locale(); 450 491 451 492 setlinebuf(stdout); 452 493 453 pc = poptGetContext("vfstest", argc, (const char **) argv, 454 long_options, 0); 455 494 pc = poptGetContext("vfstest", argc, argv, long_options, 0); 495 456 496 while(poptGetNextOpt(pc) != -1); 457 497 … … 459 499 poptFreeContext(pc); 460 500 501 /* we want total control over the permissions on created files, 502 so set our umask to 0 */ 503 umask(0); 504 461 505 lp_load_initial_only(get_dyn_CONFIGFILE()); 462 506 463 507 /* TODO: check output */ 464 reload_services( smbd_messaging_context(), -1, False);508 reload_services(NULL, NULL, false); 465 509 466 510 /* the following functions are part of the Samba debugging 467 511 facilities. See lib/debug.c */ 468 512 setup_logging("vfstest", DEBUG_STDOUT); 469 513 514 set_smbd_shim(&vfstest_shim_fns); 515 470 516 /* Load command lists */ 471 517 … … 480 526 /* some basic initialization stuff */ 481 527 sec_init(); 482 vfs.conn = TALLOC_ZERO_P(NULL, connection_struct); 483 vfs.conn->params = TALLOC_P(vfs.conn, struct share_params); 528 init_guest_info(); 529 locking_init(); 530 serverid_parent_init(NULL); 531 vfs = talloc_zero(NULL, struct vfs_state); 532 if (vfs == NULL) { 533 return 1; 534 } 535 status = make_session_info_guest(vfs, &session_info); 536 if (!NT_STATUS_IS_OK(status)) { 537 return 1; 538 } 539 540 ev = server_event_context(); 541 542 status = create_conn_struct(vfs, 543 ev, 544 server_messaging_context(), 545 &vfs->conn, 546 -1, 547 getcwd(cwd, sizeof(cwd)), 548 session_info); 549 if (!NT_STATUS_IS_OK(status)) { 550 return 1; 551 } 552 553 vfs->conn->share_access = FILE_GENERIC_ALL; 554 vfs->conn->read_only = false; 555 556 serverid_register(messaging_server_id(vfs->conn->sconn->msg_ctx), 0); 557 file_init(vfs->conn->sconn); 484 558 for (i=0; i < 1024; i++) 485 vfs.files[i] = NULL; 486 487 /* some advanced initiliazation stuff */ 488 smbd_vfs_init(vfs.conn); 559 vfs->files[i] = NULL; 560 561 if (!posix_locking_init(false)) { 562 return 1; 563 } 489 564 490 565 /* Do we have a file input? */ 491 566 if (filename && filename[0]) { 492 process_file( &vfs, filename);567 process_file(vfs, filename); 493 568 return 0; 494 569 } … … 500 575 501 576 while((cmd=next_command(frame, &p)) != NULL) { 502 process_cmd(&vfs, cmd);577 status = process_cmd(vfs, cmd); 503 578 } 504 579 505 580 TALLOC_FREE(cmd); 506 return 0;581 return NT_STATUS_IS_OK(status) ? 0 : 1; 507 582 } 508 583 … … 519 594 520 595 if (line[0] != '\n') { 521 process_cmd(&vfs, line);596 status = process_cmd(vfs, line); 522 597 } 523 598 SAFE_FREE(line); 524 599 } 525 600 526 TALLOC_FREE(vfs .conn);601 TALLOC_FREE(vfs); 527 602 TALLOC_FREE(frame); 528 return 0;529 } 603 return NT_STATUS_IS_OK(status) ? 0 : 1; 604 } -
vendor/current/source3/torture/vfstest.h
r414 r988 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 VFS module tester … … 13 13 the Free Software Foundation; either version 3 of the License, or 14 14 (at your option) any later version. 15 15 16 16 This program is distributed in the hope that it will be useful, 17 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 19 GNU General Public License for more details. 20 20 21 21 You should have received a copy of the GNU General Public License 22 22 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 30 30 struct vfs_state { 31 31 struct connection_struct *conn; 32 uint64_t mid; 32 33 struct files_struct *files[1024]; 33 34 DIR *currentdir; … … 35 36 size_t data_size; 36 37 }; 38 39 struct smb_request *vfstest_get_smbreq(TALLOC_CTX *mem_ctx, 40 struct vfs_state *vfs); 37 41 38 42 struct cmd_set { … … 43 47 const char *usage; 44 48 }; 49 50 NTSTATUS cmd_test_chain(struct vfs_state *vfs, TALLOC_CTX *mem_ctx, 51 int argc, const char **argv); -
vendor/current/source3/torture/wbc_async.c
r740 r988 289 289 subreq = async_connect_send(mem_ctx, ev, wb_ctx->fd, 290 290 (struct sockaddr *)(void *)&sunaddr, 291 sizeof(sunaddr) );291 sizeof(sunaddr), NULL, NULL, NULL); 292 292 if (subreq == NULL) { 293 293 goto nomem; … … 326 326 static const char *winbindd_socket_dir(void) 327 327 { 328 #ifdef SOCKET_WRAPPER 329 const char *env_dir;330 331 env_dir = getenv(WINBINDD_SOCKET_DIR_ENVVAR);332 if (env_dir) {333 return env_dir;334 }335 #endif 328 if (nss_wrapper_enabled()) { 329 const char *env_dir; 330 331 env_dir = getenv("SELFTEST_WINBINDD_SOCKET_DIR"); 332 if (env_dir != NULL) { 333 return env_dir; 334 } 335 } 336 336 337 337 return WINBINDD_SOCKET_DIR; … … 552 552 if (!tevent_queue_add(wb_ctx->queue, ev, req, wb_trans_trigger, 553 553 NULL)) { 554 tevent_req_ nomem(NULL,req);554 tevent_req_oom(req); 555 555 return tevent_req_post(req, ev); 556 556 }
Note:
See TracChangeset
for help on using the changeset viewer.