00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "includes.h"
00022
00023 extern char *optarg;
00024 extern int optind;
00025
00026 static fstring host, workgroup, share, password, username, myname;
00027 static int max_protocol = PROTOCOL_NT1;
00028 static const char *sockops="TCP_NODELAY";
00029 static int nprocs=1;
00030 static int port_to_use=0;
00031 int torture_numops=100;
00032 static int procnum;
00033 static struct cli_state *current_cli;
00034 static fstring randomfname;
00035 static BOOL use_oplocks;
00036 static BOOL use_level_II_oplocks;
00037 static const char *client_txt = "client_oplocks.txt";
00038 static BOOL use_kerberos;
00039 static fstring multishare_conn_fname;
00040 static BOOL use_multishare_conn = False;
00041
00042 BOOL torture_showall = False;
00043
00044 static double create_procs(BOOL (*fn)(int), BOOL *result);
00045
00046
00047 static struct timeval tp1,tp2;
00048
00049
00050 void start_timer(void)
00051 {
00052 GetTimeOfDay(&tp1);
00053 }
00054
00055 double end_timer(void)
00056 {
00057 GetTimeOfDay(&tp2);
00058 return((tp2.tv_sec - tp1.tv_sec) +
00059 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 void *shm_setup(int size)
00073 {
00074 int shmid;
00075 void *ret;
00076
00077 shmid = shmget(IPC_PRIVATE, size, S_IRUSR | S_IWUSR);
00078 if (shmid == -1) {
00079 printf("can't get shared memory\n");
00080 exit(1);
00081 }
00082 ret = (void *)shmat(shmid, 0, 0);
00083 if (!ret || ret == (void *)-1) {
00084 printf("can't attach to shared memory\n");
00085 return NULL;
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 shmctl(shmid, IPC_RMID, 0);
00095
00096 return ret;
00097 }
00098
00099
00100 static struct cli_state *open_nbt_connection(void)
00101 {
00102 struct nmb_name called, calling;
00103 struct in_addr ip;
00104 struct cli_state *c;
00105 NTSTATUS status;
00106
00107 make_nmb_name(&calling, myname, 0x0);
00108 make_nmb_name(&called , host, 0x20);
00109
00110 zero_ip(&ip);
00111
00112 if (!(c = cli_initialise())) {
00113 printf("Failed initialize cli_struct to connect with %s\n", host);
00114 return NULL;
00115 }
00116
00117 c->port = port_to_use;
00118
00119 status = cli_connect(c, host, &ip);
00120 if (!NT_STATUS_IS_OK(status)) {
00121 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
00122 return NULL;
00123 }
00124
00125 c->use_kerberos = use_kerberos;
00126
00127 c->timeout = 120000;
00128 if (use_oplocks) c->use_oplocks = True;
00129 if (use_level_II_oplocks) c->use_level_II_oplocks = True;
00130
00131 if (!cli_session_request(c, &calling, &called)) {
00132
00133
00134
00135
00136 status = cli_connect(c, host, &ip);
00137 if (!NT_STATUS_IS_OK(status)) {
00138 printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
00139 return NULL;
00140 }
00141
00142 make_nmb_name(&called, "*SMBSERVER", 0x20);
00143 if (!cli_session_request(c, &calling, &called)) {
00144 printf("%s rejected the session\n",host);
00145 printf("We tried with a called name of %s & %s\n",
00146 host, "*SMBSERVER");
00147 cli_shutdown(c);
00148 return NULL;
00149 }
00150 }
00151
00152 return c;
00153 }
00154
00155
00156
00157
00158 static char *
00159 terminate_path_at_separator(char * path)
00160 {
00161 char * p;
00162
00163 if (!path) {
00164 return NULL;
00165 }
00166
00167 if ((p = strchr_m(path, '/'))) {
00168 *p = '\0';
00169 return p + 1;
00170 }
00171
00172 if ((p = strchr_m(path, '\\'))) {
00173 *p = '\0';
00174 return p + 1;
00175 }
00176
00177
00178 return NULL;
00179 }
00180
00181
00182
00183
00184 BOOL smbcli_parse_unc(const char *unc_name, TALLOC_CTX *mem_ctx,
00185 char **hostname, char **sharename)
00186 {
00187 char *p;
00188
00189 *hostname = *sharename = NULL;
00190
00191 if (strncmp(unc_name, "\\\\", 2) &&
00192 strncmp(unc_name, "//", 2)) {
00193 return False;
00194 }
00195
00196 *hostname = talloc_strdup(mem_ctx, &unc_name[2]);
00197 p = terminate_path_at_separator(*hostname);
00198
00199 if (p && *p) {
00200 *sharename = talloc_strdup(mem_ctx, p);
00201 terminate_path_at_separator(*sharename);
00202 }
00203
00204 if (*hostname && *sharename) {
00205 return True;
00206 }
00207
00208 TALLOC_FREE(*hostname);
00209 TALLOC_FREE(*sharename);
00210 return False;
00211 }
00212
00213 static BOOL torture_open_connection_share(struct cli_state **c,
00214 const char *hostname,
00215 const char *sharename)
00216 {
00217 BOOL retry;
00218 int flags = 0;
00219 NTSTATUS status;
00220
00221 if (use_kerberos)
00222 flags |= CLI_FULL_CONNECTION_USE_KERBEROS;
00223
00224 status = cli_full_connection(c, myname,
00225 hostname, NULL, port_to_use,
00226 sharename, "?????",
00227 username, workgroup,
00228 password, flags, Undefined, &retry);
00229 if (!NT_STATUS_IS_OK(status)) {
00230 printf("failed to open share connection: //%s/%s port:%d - %s\n",
00231 hostname, sharename, port_to_use, nt_errstr(status));
00232 return False;
00233 }
00234
00235 if (use_oplocks) (*c)->use_oplocks = True;
00236 if (use_level_II_oplocks) (*c)->use_level_II_oplocks = True;
00237 (*c)->timeout = 120000;
00238
00239 return True;
00240 }
00241
00242 void torture_open_connection_free_unclist(char **unc_list)
00243 {
00244 if (unc_list!=NULL)
00245 {
00246 SAFE_FREE(unc_list[0]);
00247 SAFE_FREE(unc_list);
00248 }
00249 }
00250
00251 BOOL torture_open_connection(struct cli_state **c, int conn_index)
00252 {
00253 char **unc_list = NULL;
00254 int num_unc_names = 0;
00255 BOOL result;
00256
00257 if (use_multishare_conn==True) {
00258 char *h, *s;
00259 unc_list = file_lines_load(multishare_conn_fname, &num_unc_names, 0);
00260 if (!unc_list || num_unc_names <= 0) {
00261 printf("Failed to load unc names list from '%s'\n", multishare_conn_fname);
00262 exit(1);
00263 }
00264
00265 if (!smbcli_parse_unc(unc_list[conn_index % num_unc_names],
00266 NULL, &h, &s)) {
00267 printf("Failed to parse UNC name %s\n",
00268 unc_list[conn_index % num_unc_names]);
00269 torture_open_connection_free_unclist(unc_list);
00270 exit(1);
00271 }
00272
00273 result = torture_open_connection_share(c, h, s);
00274
00275
00276 torture_open_connection_free_unclist(unc_list);
00277 return result;
00278 }
00279
00280 return torture_open_connection_share(c, host, share);
00281 }
00282
00283 BOOL torture_cli_session_setup2(struct cli_state *cli, uint16 *new_vuid)
00284 {
00285 uint16 old_vuid = cli->vuid;
00286 fstring old_user_name;
00287 size_t passlen = strlen(password);
00288 BOOL ret;
00289
00290 fstrcpy(old_user_name, cli->user_name);
00291 cli->vuid = 0;
00292 ret = NT_STATUS_IS_OK(cli_session_setup(cli, username,
00293 password, passlen,
00294 password, passlen,
00295 workgroup));
00296 *new_vuid = cli->vuid;
00297 cli->vuid = old_vuid;
00298 fstrcpy(cli->user_name, old_user_name);
00299 return ret;
00300 }
00301
00302
00303 BOOL torture_close_connection(struct cli_state *c)
00304 {
00305 BOOL ret = True;
00306 if (!cli_tdis(c)) {
00307 printf("tdis failed (%s)\n", cli_errstr(c));
00308 ret = False;
00309 }
00310
00311 cli_shutdown(c);
00312
00313 return ret;
00314 }
00315
00316
00317
00318 static BOOL check_error(int line, struct cli_state *c,
00319 uint8 eclass, uint32 ecode, NTSTATUS nterr)
00320 {
00321 if (cli_is_dos_error(c)) {
00322 uint8 cclass;
00323 uint32 num;
00324
00325
00326
00327 cli_dos_error(c, &cclass, &num);
00328
00329 if (eclass != cclass || ecode != num) {
00330 printf("unexpected error code class=%d code=%d\n",
00331 (int)cclass, (int)num);
00332 printf(" expected %d/%d %s (line=%d)\n",
00333 (int)eclass, (int)ecode, nt_errstr(nterr), line);
00334 return False;
00335 }
00336
00337 } else {
00338 NTSTATUS status;
00339
00340
00341
00342 status = cli_nt_error(c);
00343
00344 if (NT_STATUS_V(nterr) != NT_STATUS_V(status)) {
00345 printf("unexpected error code %s\n", nt_errstr(status));
00346 printf(" expected %s (line=%d)\n", nt_errstr(nterr), line);
00347 return False;
00348 }
00349 }
00350
00351 return True;
00352 }
00353
00354
00355 static BOOL wait_lock(struct cli_state *c, int fnum, uint32 offset, uint32 len)
00356 {
00357 while (!cli_lock(c, fnum, offset, len, -1, WRITE_LOCK)) {
00358 if (!check_error(__LINE__, c, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
00359 }
00360 return True;
00361 }
00362
00363
00364 static BOOL rw_torture(struct cli_state *c)
00365 {
00366 const char *lockfname = "\\torture.lck";
00367 fstring fname;
00368 int fnum;
00369 int fnum2;
00370 pid_t pid2, pid = getpid();
00371 int i, j;
00372 char buf[1024];
00373 BOOL correct = True;
00374
00375 memset(buf, '\0', sizeof(buf));
00376
00377 fnum2 = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
00378 DENY_NONE);
00379 if (fnum2 == -1)
00380 fnum2 = cli_open(c, lockfname, O_RDWR, DENY_NONE);
00381 if (fnum2 == -1) {
00382 printf("open of %s failed (%s)\n", lockfname, cli_errstr(c));
00383 return False;
00384 }
00385
00386
00387 for (i=0;i<torture_numops;i++) {
00388 unsigned n = (unsigned)sys_random()%10;
00389 if (i % 10 == 0) {
00390 printf("%d\r", i); fflush(stdout);
00391 }
00392 slprintf(fname, sizeof(fstring) - 1, "\\torture.%u", n);
00393
00394 if (!wait_lock(c, fnum2, n*sizeof(int), sizeof(int))) {
00395 return False;
00396 }
00397
00398 fnum = cli_open(c, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_ALL);
00399 if (fnum == -1) {
00400 printf("open failed (%s)\n", cli_errstr(c));
00401 correct = False;
00402 break;
00403 }
00404
00405 if (cli_write(c, fnum, 0, (char *)&pid, 0, sizeof(pid)) != sizeof(pid)) {
00406 printf("write failed (%s)\n", cli_errstr(c));
00407 correct = False;
00408 }
00409
00410 for (j=0;j<50;j++) {
00411 if (cli_write(c, fnum, 0, (char *)buf,
00412 sizeof(pid)+(j*sizeof(buf)),
00413 sizeof(buf)) != sizeof(buf)) {
00414 printf("write failed (%s)\n", cli_errstr(c));
00415 correct = False;
00416 }
00417 }
00418
00419 pid2 = 0;
00420
00421 if (cli_read(c, fnum, (char *)&pid2, 0, sizeof(pid)) != sizeof(pid)) {
00422 printf("read failed (%s)\n", cli_errstr(c));
00423 correct = False;
00424 }
00425
00426 if (pid2 != pid) {
00427 printf("data corruption!\n");
00428 correct = False;
00429 }
00430
00431 if (!cli_close(c, fnum)) {
00432 printf("close failed (%s)\n", cli_errstr(c));
00433 correct = False;
00434 }
00435
00436 if (!cli_unlink(c, fname)) {
00437 printf("unlink failed (%s)\n", cli_errstr(c));
00438 correct = False;
00439 }
00440
00441 if (!cli_unlock(c, fnum2, n*sizeof(int), sizeof(int))) {
00442 printf("unlock failed (%s)\n", cli_errstr(c));
00443 correct = False;
00444 }
00445 }
00446
00447 cli_close(c, fnum2);
00448 cli_unlink(c, lockfname);
00449
00450 printf("%d\n", i);
00451
00452 return correct;
00453 }
00454
00455 static BOOL run_torture(int dummy)
00456 {
00457 struct cli_state *cli;
00458 BOOL ret;
00459
00460 cli = current_cli;
00461
00462 cli_sockopt(cli, sockops);
00463
00464 ret = rw_torture(cli);
00465
00466 if (!torture_close_connection(cli)) {
00467 ret = False;
00468 }
00469
00470 return ret;
00471 }
00472
00473 static BOOL rw_torture3(struct cli_state *c, char *lockfname)
00474 {
00475 int fnum = -1;
00476 unsigned int i = 0;
00477 char buf[131072];
00478 char buf_rd[131072];
00479 unsigned count;
00480 unsigned countprev = 0;
00481 ssize_t sent = 0;
00482 BOOL correct = True;
00483
00484 srandom(1);
00485 for (i = 0; i < sizeof(buf); i += sizeof(uint32))
00486 {
00487 SIVAL(buf, i, sys_random());
00488 }
00489
00490 if (procnum == 0)
00491 {
00492 fnum = cli_open(c, lockfname, O_RDWR | O_CREAT | O_EXCL,
00493 DENY_NONE);
00494 if (fnum == -1) {
00495 printf("first open read/write of %s failed (%s)\n",
00496 lockfname, cli_errstr(c));
00497 return False;
00498 }
00499 }
00500 else
00501 {
00502 for (i = 0; i < 500 && fnum == -1; i++)
00503 {
00504 fnum = cli_open(c, lockfname, O_RDONLY,
00505 DENY_NONE);
00506 smb_msleep(10);
00507 }
00508 if (fnum == -1) {
00509 printf("second open read-only of %s failed (%s)\n",
00510 lockfname, cli_errstr(c));
00511 return False;
00512 }
00513 }
00514
00515 i = 0;
00516 for (count = 0; count < sizeof(buf); count += sent)
00517 {
00518 if (count >= countprev) {
00519 printf("%d %8d\r", i, count);
00520 fflush(stdout);
00521 i++;
00522 countprev += (sizeof(buf) / 20);
00523 }
00524
00525 if (procnum == 0)
00526 {
00527 sent = ((unsigned)sys_random()%(20))+ 1;
00528 if (sent > sizeof(buf) - count)
00529 {
00530 sent = sizeof(buf) - count;
00531 }
00532
00533 if (cli_write(c, fnum, 0, buf+count, count, (size_t)sent) != sent) {
00534 printf("write failed (%s)\n", cli_errstr(c));
00535 correct = False;
00536 }
00537 }
00538 else
00539 {
00540 sent = cli_read(c, fnum, buf_rd+count, count,
00541 sizeof(buf)-count);
00542 if (sent < 0)
00543 {
00544 printf("read failed offset:%d size:%ld (%s)\n",
00545 count, (unsigned long)sizeof(buf)-count,
00546 cli_errstr(c));
00547 correct = False;
00548 sent = 0;
00549 }
00550 if (sent > 0)
00551 {
00552 if (memcmp(buf_rd+count, buf+count, sent) != 0)
00553 {
00554 printf("read/write compare failed\n");
00555 printf("offset: %d req %ld recvd %ld\n", count, (unsigned long)sizeof(buf)-count, (unsigned long)sent);
00556 correct = False;
00557 break;
00558 }
00559 }
00560 }
00561
00562 }
00563
00564 if (!cli_close(c, fnum)) {
00565 printf("close failed (%s)\n", cli_errstr(c));
00566 correct = False;
00567 }
00568
00569 return correct;
00570 }
00571
00572 static BOOL rw_torture2(struct cli_state *c1, struct cli_state *c2)
00573 {
00574 const char *lockfname = "\\torture2.lck";
00575 int fnum1;
00576 int fnum2;
00577 int i;
00578 char buf[131072];
00579 char buf_rd[131072];
00580 BOOL correct = True;
00581 ssize_t bytes_read;
00582
00583 if (!cli_unlink(c1, lockfname)) {
00584 printf("unlink failed (%s) (normal, this file should not exist)\n", cli_errstr(c1));
00585 }
00586
00587 fnum1 = cli_open(c1, lockfname, O_RDWR | O_CREAT | O_EXCL,
00588 DENY_NONE);
00589 if (fnum1 == -1) {
00590 printf("first open read/write of %s failed (%s)\n",
00591 lockfname, cli_errstr(c1));
00592 return False;
00593 }
00594 fnum2 = cli_open(c2, lockfname, O_RDONLY,
00595 DENY_NONE);
00596 if (fnum2 == -1) {
00597 printf("second open read-only of %s failed (%s)\n",
00598 lockfname, cli_errstr(c2));
00599 cli_close(c1, fnum1);
00600 return False;
00601 }
00602
00603 for (i=0;i<torture_numops;i++)
00604 {
00605 size_t buf_size = ((unsigned)sys_random()%(sizeof(buf)-1))+ 1;
00606 if (i % 10 == 0) {
00607 printf("%d\r", i); fflush(stdout);
00608 }
00609
00610 generate_random_buffer((unsigned char *)buf, buf_size);
00611
00612 if (cli_write(c1, fnum1, 0, buf, 0, buf_size) != buf_size) {
00613 printf("write failed (%s)\n", cli_errstr(c1));
00614 correct = False;
00615 break;
00616 }
00617
00618 if ((bytes_read = cli_read(c2, fnum2, buf_rd, 0, buf_size)) != buf_size) {
00619 printf("read failed (%s)\n", cli_errstr(c2));
00620 printf("read %d, expected %ld\n", (int)bytes_read,
00621 (unsigned long)buf_size);
00622 correct = False;
00623 break;
00624 }
00625
00626 if (memcmp(buf_rd, buf, buf_size) != 0)
00627 {
00628 printf("read/write compare failed\n");
00629 correct = False;
00630 break;
00631 }
00632 }
00633
00634 if (!cli_close(c2, fnum2)) {
00635 printf("close failed (%s)\n", cli_errstr(c2));
00636 correct = False;
00637 }
00638 if (!cli_close(c1, fnum1)) {
00639 printf("close failed (%s)\n", cli_errstr(c1));
00640 correct = False;
00641 }
00642
00643 if (!cli_unlink(c1, lockfname)) {
00644 printf("unlink failed (%s)\n", cli_errstr(c1));
00645 correct = False;
00646 }
00647
00648 return correct;
00649 }
00650
00651 static BOOL run_readwritetest(int dummy)
00652 {
00653 static struct cli_state *cli1, *cli2;
00654 BOOL test1, test2 = False;
00655
00656 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
00657 return False;
00658 }
00659 cli_sockopt(cli1, sockops);
00660 cli_sockopt(cli2, sockops);
00661
00662 printf("starting readwritetest\n");
00663
00664 test1 = rw_torture2(cli1, cli2);
00665 printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
00666
00667 if (test1) {
00668 test2 = rw_torture2(cli1, cli1);
00669 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
00670 }
00671
00672 if (!torture_close_connection(cli1)) {
00673 test1 = False;
00674 }
00675
00676 if (!torture_close_connection(cli2)) {
00677 test2 = False;
00678 }
00679
00680 return (test1 && test2);
00681 }
00682
00683 static BOOL run_readwritemulti(int dummy)
00684 {
00685 struct cli_state *cli;
00686 BOOL test;
00687
00688 cli = current_cli;
00689
00690 cli_sockopt(cli, sockops);
00691
00692 printf("run_readwritemulti: fname %s\n", randomfname);
00693 test = rw_torture3(cli, randomfname);
00694
00695 if (!torture_close_connection(cli)) {
00696 test = False;
00697 }
00698
00699 return test;
00700 }
00701
00702 static BOOL run_readwritelarge(int dummy)
00703 {
00704 static struct cli_state *cli1;
00705 int fnum1;
00706 const char *lockfname = "\\large.dat";
00707 SMB_OFF_T fsize;
00708 char buf[126*1024];
00709 BOOL correct = True;
00710
00711 if (!torture_open_connection(&cli1, 0)) {
00712 return False;
00713 }
00714 cli_sockopt(cli1, sockops);
00715 memset(buf,'\0',sizeof(buf));
00716
00717 cli1->max_xmit = 128*1024;
00718
00719 printf("starting readwritelarge\n");
00720
00721 cli_unlink(cli1, lockfname);
00722
00723 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
00724 if (fnum1 == -1) {
00725 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
00726 return False;
00727 }
00728
00729 cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf));
00730
00731 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
00732 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
00733 correct = False;
00734 }
00735
00736 if (fsize == sizeof(buf))
00737 printf("readwritelarge test 1 succeeded (size = %lx)\n",
00738 (unsigned long)fsize);
00739 else {
00740 printf("readwritelarge test 1 failed (size = %lx)\n",
00741 (unsigned long)fsize);
00742 correct = False;
00743 }
00744
00745 if (!cli_close(cli1, fnum1)) {
00746 printf("close failed (%s)\n", cli_errstr(cli1));
00747 correct = False;
00748 }
00749
00750 if (!cli_unlink(cli1, lockfname)) {
00751 printf("unlink failed (%s)\n", cli_errstr(cli1));
00752 correct = False;
00753 }
00754
00755 fnum1 = cli_open(cli1, lockfname, O_RDWR | O_CREAT | O_EXCL, DENY_NONE);
00756 if (fnum1 == -1) {
00757 printf("open read/write of %s failed (%s)\n", lockfname, cli_errstr(cli1));
00758 return False;
00759 }
00760
00761 cli1->max_xmit = 4*1024;
00762
00763 cli_smbwrite(cli1, fnum1, buf, 0, sizeof(buf));
00764
00765 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
00766 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
00767 correct = False;
00768 }
00769
00770 if (fsize == sizeof(buf))
00771 printf("readwritelarge test 2 succeeded (size = %lx)\n",
00772 (unsigned long)fsize);
00773 else {
00774 printf("readwritelarge test 2 failed (size = %lx)\n",
00775 (unsigned long)fsize);
00776 correct = False;
00777 }
00778
00779 #if 0
00780
00781 if(!cli_set_allocation_size(cli1, fnum1, 0)) {
00782 printf("set allocation size to zero failed (%s)\n", cli_errstr(&cli1));
00783 return False;
00784 }
00785 if (!cli_qfileinfo(cli1, fnum1, NULL, &fsize, NULL, NULL, NULL, NULL, NULL)) {
00786 printf("qfileinfo failed (%s)\n", cli_errstr(cli1));
00787 correct = False;
00788 }
00789 if (fsize != 0)
00790 printf("readwritelarge test 3 (truncate test) succeeded (size = %x)\n", fsize);
00791 #endif
00792
00793 if (!cli_close(cli1, fnum1)) {
00794 printf("close failed (%s)\n", cli_errstr(cli1));
00795 correct = False;
00796 }
00797
00798 if (!torture_close_connection(cli1)) {
00799 correct = False;
00800 }
00801 return correct;
00802 }
00803
00804 int line_count = 0;
00805 int nbio_id;
00806
00807 #define ival(s) strtol(s, NULL, 0)
00808
00809
00810 static BOOL run_netbench(int client)
00811 {
00812 struct cli_state *cli;
00813 int i;
00814 pstring line;
00815 char cname[20];
00816 FILE *f;
00817 const char *params[20];
00818 BOOL correct = True;
00819
00820 cli = current_cli;
00821
00822 nbio_id = client;
00823
00824 cli_sockopt(cli, sockops);
00825
00826 nb_setup(cli);
00827
00828 slprintf(cname,sizeof(cname)-1, "client%d", client);
00829
00830 f = fopen(client_txt, "r");
00831
00832 if (!f) {
00833 perror(client_txt);
00834 return False;
00835 }
00836
00837 while (fgets(line, sizeof(line)-1, f)) {
00838 line_count++;
00839
00840 line[strlen(line)-1] = 0;
00841
00842
00843
00844 all_string_sub(line,"client1", cname, sizeof(line));
00845
00846
00847 params[0] = strtok(line," ");
00848 i = 0;
00849 while (params[i]) params[++i] = strtok(NULL," ");
00850
00851 params[i] = "";
00852
00853 if (i < 2) continue;
00854
00855 if (!strncmp(params[0],"SMB", 3)) {
00856 printf("ERROR: You are using a dbench 1 load file\n");
00857 exit(1);
00858 }
00859
00860 if (!strcmp(params[0],"NTCreateX")) {
00861 nb_createx(params[1], ival(params[2]), ival(params[3]),
00862 ival(params[4]));
00863 } else if (!strcmp(params[0],"Close")) {
00864 nb_close(ival(params[1]));
00865 } else if (!strcmp(params[0],"Rename")) {
00866 nb_rename(params[1], params[2]);
00867 } else if (!strcmp(params[0],"Unlink")) {
00868 nb_unlink(params[1]);
00869 } else if (!strcmp(params[0],"Deltree")) {
00870 nb_deltree(params[1]);
00871 } else if (!strcmp(params[0],"Rmdir")) {
00872 nb_rmdir(params[1]);
00873 } else if (!strcmp(params[0],"QUERY_PATH_INFORMATION")) {
00874 nb_qpathinfo(params[1]);
00875 } else if (!strcmp(params[0],"QUERY_FILE_INFORMATION")) {
00876 nb_qfileinfo(ival(params[1]));
00877 } else if (!strcmp(params[0],"QUERY_FS_INFORMATION")) {
00878 nb_qfsinfo(ival(params[1]));
00879 } else if (!strcmp(params[0],"FIND_FIRST")) {
00880 nb_findfirst(params[1]);
00881 } else if (!strcmp(params[0],"WriteX")) {
00882 nb_writex(ival(params[1]),
00883 ival(params[2]), ival(params[3]), ival(params[4]));
00884 } else if (!strcmp(params[0],"ReadX")) {
00885 nb_readx(ival(params[1]),
00886 ival(params[2]), ival(params[3]), ival(params[4]));
00887 } else if (!strcmp(params[0],"Flush")) {
00888 nb_flush(ival(params[1]));
00889 } else {
00890 printf("Unknown operation %s\n", params[0]);
00891 exit(1);
00892 }
00893 }
00894 fclose(f);
00895
00896 nb_cleanup();
00897
00898 if (!torture_close_connection(cli)) {
00899 correct = False;
00900 }
00901
00902 return correct;
00903 }
00904
00905
00906
00907 static BOOL run_nbench(int dummy)
00908 {
00909 double t;
00910 BOOL correct = True;
00911
00912 nbio_shmem(nprocs);
00913
00914 nbio_id = -1;
00915
00916 signal(SIGALRM, nb_alarm);
00917 alarm(1);
00918 t = create_procs(run_netbench, &correct);
00919 alarm(0);
00920
00921 printf("\nThroughput %g MB/sec\n",
00922 1.0e-6 * nbio_total() / t);
00923 return correct;
00924 }
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934 static BOOL run_locktest1(int dummy)
00935 {
00936 struct cli_state *cli1, *cli2;
00937 const char *fname = "\\lockt1.lck";
00938 int fnum1, fnum2, fnum3;
00939 time_t t1, t2;
00940 unsigned lock_timeout;
00941
00942 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
00943 return False;
00944 }
00945 cli_sockopt(cli1, sockops);
00946 cli_sockopt(cli2, sockops);
00947
00948 printf("starting locktest1\n");
00949
00950 cli_unlink(cli1, fname);
00951
00952 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
00953 if (fnum1 == -1) {
00954 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
00955 return False;
00956 }
00957 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
00958 if (fnum2 == -1) {
00959 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli1));
00960 return False;
00961 }
00962 fnum3 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
00963 if (fnum3 == -1) {
00964 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli2));
00965 return False;
00966 }
00967
00968 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
00969 printf("lock1 failed (%s)\n", cli_errstr(cli1));
00970 return False;
00971 }
00972
00973
00974 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
00975 printf("lock2 succeeded! This is a locking bug\n");
00976 return False;
00977 } else {
00978 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
00979 NT_STATUS_LOCK_NOT_GRANTED)) return False;
00980 }
00981
00982
00983 lock_timeout = (1 + (random() % 20));
00984 printf("Testing lock timeout with timeout=%u\n", lock_timeout);
00985 t1 = time(NULL);
00986 if (cli_lock(cli2, fnum3, 0, 4, lock_timeout * 1000, WRITE_LOCK)) {
00987 printf("lock3 succeeded! This is a locking bug\n");
00988 return False;
00989 } else {
00990 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
00991 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
00992 }
00993 t2 = time(NULL);
00994
00995 if (ABS(t2 - t1) < lock_timeout-1) {
00996 printf("error: This server appears not to support timed lock requests\n");
00997 }
00998
00999 printf("server slept for %u seconds for a %u second timeout\n",
01000 (unsigned int)(t2-t1), lock_timeout);
01001
01002 if (!cli_close(cli1, fnum2)) {
01003 printf("close1 failed (%s)\n", cli_errstr(cli1));
01004 return False;
01005 }
01006
01007 if (cli_lock(cli2, fnum3, 0, 4, 0, WRITE_LOCK)) {
01008 printf("lock4 succeeded! This is a locking bug\n");
01009 return False;
01010 } else {
01011 if (!check_error(__LINE__, cli2, ERRDOS, ERRlock,
01012 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
01013 }
01014
01015 if (!cli_close(cli1, fnum1)) {
01016 printf("close2 failed (%s)\n", cli_errstr(cli1));
01017 return False;
01018 }
01019
01020 if (!cli_close(cli2, fnum3)) {
01021 printf("close3 failed (%s)\n", cli_errstr(cli2));
01022 return False;
01023 }
01024
01025 if (!cli_unlink(cli1, fname)) {
01026 printf("unlink failed (%s)\n", cli_errstr(cli1));
01027 return False;
01028 }
01029
01030
01031 if (!torture_close_connection(cli1)) {
01032 return False;
01033 }
01034
01035 if (!torture_close_connection(cli2)) {
01036 return False;
01037 }
01038
01039 printf("Passed locktest1\n");
01040 return True;
01041 }
01042
01043
01044
01045
01046
01047 static BOOL run_tcon_test(int dummy)
01048 {
01049 static struct cli_state *cli;
01050 const char *fname = "\\tcontest.tmp";
01051 int fnum1;
01052 uint16 cnum1, cnum2, cnum3;
01053 uint16 vuid1, vuid2;
01054 char buf[4];
01055 BOOL ret = True;
01056
01057 memset(buf, '\0', sizeof(buf));
01058
01059 if (!torture_open_connection(&cli, 0)) {
01060 return False;
01061 }
01062 cli_sockopt(cli, sockops);
01063
01064 printf("starting tcontest\n");
01065
01066 cli_unlink(cli, fname);
01067
01068 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01069 if (fnum1 == -1) {
01070 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
01071 return False;
01072 }
01073
01074 cnum1 = cli->cnum;
01075 vuid1 = cli->vuid;
01076
01077 if (cli_write(cli, fnum1, 0, buf, 130, 4) != 4) {
01078 printf("initial write failed (%s)", cli_errstr(cli));
01079 return False;
01080 }
01081
01082 if (!cli_send_tconX(cli, share, "?????",
01083 password, strlen(password)+1)) {
01084 printf("%s refused 2nd tree connect (%s)\n", host,
01085 cli_errstr(cli));
01086 cli_shutdown(cli);
01087 return False;
01088 }
01089
01090 cnum2 = cli->cnum;
01091 cnum3 = MAX(cnum1, cnum2) + 1;
01092 vuid2 = cli->vuid + 1;
01093
01094
01095 cli->cnum = cnum2;
01096
01097 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
01098 printf("* server allows write with wrong TID\n");
01099 ret = False;
01100 } else {
01101 printf("server fails write with wrong TID : %s\n", cli_errstr(cli));
01102 }
01103
01104
01105
01106 cli->cnum = cnum3;
01107
01108 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
01109 printf("* server allows write with invalid TID\n");
01110 ret = False;
01111 } else {
01112 printf("server fails write with invalid TID : %s\n", cli_errstr(cli));
01113 }
01114
01115
01116 cli->vuid = vuid2;
01117 cli->cnum = cnum1;
01118
01119 if (cli_write(cli, fnum1, 0, buf, 130, 4) == 4) {
01120 printf("* server allows write with invalid VUID\n");
01121 ret = False;
01122 } else {
01123 printf("server fails write with invalid VUID : %s\n", cli_errstr(cli));
01124 }
01125
01126 cli->cnum = cnum1;
01127 cli->vuid = vuid1;
01128
01129 if (!cli_close(cli, fnum1)) {
01130 printf("close failed (%s)\n", cli_errstr(cli));
01131 return False;
01132 }
01133
01134 cli->cnum = cnum2;
01135
01136 if (!cli_tdis(cli)) {
01137 printf("secondary tdis failed (%s)\n", cli_errstr(cli));
01138 return False;
01139 }
01140
01141 cli->cnum = cnum1;
01142
01143 if (!torture_close_connection(cli)) {
01144 return False;
01145 }
01146
01147 return ret;
01148 }
01149
01150
01151
01152
01153
01154 static BOOL run_tcon2_test(int dummy)
01155 {
01156 static struct cli_state *cli;
01157 uint16 cnum, max_xmit;
01158 char *service;
01159 NTSTATUS status;
01160
01161 if (!torture_open_connection(&cli, 0)) {
01162 return False;
01163 }
01164 cli_sockopt(cli, sockops);
01165
01166 printf("starting tcon2 test\n");
01167
01168 asprintf(&service, "\\\\%s\\%s", host, share);
01169
01170 status = cli_raw_tcon(cli, service, password, "?????", &max_xmit, &cnum);
01171
01172 if (!NT_STATUS_IS_OK(status)) {
01173 printf("tcon2 failed : %s\n", cli_errstr(cli));
01174 } else {
01175 printf("tcon OK : max_xmit=%d cnum=%d tid=%d\n",
01176 (int)max_xmit, (int)cnum, SVAL(cli->inbuf, smb_tid));
01177 }
01178
01179 if (!torture_close_connection(cli)) {
01180 return False;
01181 }
01182
01183 printf("Passed tcon2 test\n");
01184 return True;
01185 }
01186
01187 static BOOL tcon_devtest(struct cli_state *cli,
01188 const char *myshare, const char *devtype,
01189 const char *return_devtype,
01190 NTSTATUS expected_error)
01191 {
01192 BOOL status;
01193 BOOL ret;
01194
01195 status = cli_send_tconX(cli, myshare, devtype,
01196 password, strlen(password)+1);
01197
01198 if (NT_STATUS_IS_OK(expected_error)) {
01199 if (status) {
01200 if (strcmp(cli->dev, return_devtype) == 0) {
01201 ret = True;
01202 } else {
01203 printf("tconX to share %s with type %s "
01204 "succeeded but returned the wrong "
01205 "device type (got [%s] but should have got [%s])\n",
01206 myshare, devtype, cli->dev, return_devtype);
01207 ret = False;
01208 }
01209 } else {
01210 printf("tconX to share %s with type %s "
01211 "should have succeeded but failed\n",
01212 myshare, devtype);
01213 ret = False;
01214 }
01215 cli_tdis(cli);
01216 } else {
01217 if (status) {
01218 printf("tconx to share %s with type %s "
01219 "should have failed but succeeded\n",
01220 myshare, devtype);
01221 ret = False;
01222 } else {
01223 if (NT_STATUS_EQUAL(cli_nt_error(cli),
01224 expected_error)) {
01225 ret = True;
01226 } else {
01227 printf("Returned unexpected error\n");
01228 ret = False;
01229 }
01230 }
01231 }
01232 return ret;
01233 }
01234
01235
01236
01237
01238 static BOOL run_tcon_devtype_test(int dummy)
01239 {
01240 static struct cli_state *cli1 = NULL;
01241 BOOL retry;
01242 int flags = 0;
01243 NTSTATUS status;
01244 BOOL ret = True;
01245
01246 status = cli_full_connection(&cli1, myname,
01247 host, NULL, port_to_use,
01248 NULL, NULL,
01249 username, workgroup,
01250 password, flags, Undefined, &retry);
01251
01252 if (!NT_STATUS_IS_OK(status)) {
01253 printf("could not open connection\n");
01254 return False;
01255 }
01256
01257 if (!tcon_devtest(cli1, "IPC$", "A:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01258 ret = False;
01259
01260 if (!tcon_devtest(cli1, "IPC$", "?????", "IPC", NT_STATUS_OK))
01261 ret = False;
01262
01263 if (!tcon_devtest(cli1, "IPC$", "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01264 ret = False;
01265
01266 if (!tcon_devtest(cli1, "IPC$", "IPC", "IPC", NT_STATUS_OK))
01267 ret = False;
01268
01269 if (!tcon_devtest(cli1, "IPC$", "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01270 ret = False;
01271
01272 if (!tcon_devtest(cli1, share, "A:", "A:", NT_STATUS_OK))
01273 ret = False;
01274
01275 if (!tcon_devtest(cli1, share, "?????", "A:", NT_STATUS_OK))
01276 ret = False;
01277
01278 if (!tcon_devtest(cli1, share, "LPT:", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01279 ret = False;
01280
01281 if (!tcon_devtest(cli1, share, "IPC", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01282 ret = False;
01283
01284 if (!tcon_devtest(cli1, share, "FOOBA", NULL, NT_STATUS_BAD_DEVICE_TYPE))
01285 ret = False;
01286
01287 cli_shutdown(cli1);
01288
01289 if (ret)
01290 printf("Passed tcondevtest\n");
01291
01292 return ret;
01293 }
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307 static BOOL run_locktest2(int dummy)
01308 {
01309 static struct cli_state *cli;
01310 const char *fname = "\\lockt2.lck";
01311 int fnum1, fnum2, fnum3;
01312 BOOL correct = True;
01313
01314 if (!torture_open_connection(&cli, 0)) {
01315 return False;
01316 }
01317
01318 cli_sockopt(cli, sockops);
01319
01320 printf("starting locktest2\n");
01321
01322 cli_unlink(cli, fname);
01323
01324 cli_setpid(cli, 1);
01325
01326 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01327 if (fnum1 == -1) {
01328 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
01329 return False;
01330 }
01331
01332 fnum2 = cli_open(cli, fname, O_RDWR, DENY_NONE);
01333 if (fnum2 == -1) {
01334 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli));
01335 return False;
01336 }
01337
01338 cli_setpid(cli, 2);
01339
01340 fnum3 = cli_open(cli, fname, O_RDWR, DENY_NONE);
01341 if (fnum3 == -1) {
01342 printf("open3 of %s failed (%s)\n", fname, cli_errstr(cli));
01343 return False;
01344 }
01345
01346 cli_setpid(cli, 1);
01347
01348 if (!cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
01349 printf("lock1 failed (%s)\n", cli_errstr(cli));
01350 return False;
01351 }
01352
01353 if (cli_lock(cli, fnum1, 0, 4, 0, WRITE_LOCK)) {
01354 printf("WRITE lock1 succeeded! This is a locking bug\n");
01355 correct = False;
01356 } else {
01357 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
01358 NT_STATUS_LOCK_NOT_GRANTED)) return False;
01359 }
01360
01361 if (cli_lock(cli, fnum2, 0, 4, 0, WRITE_LOCK)) {
01362 printf("WRITE lock2 succeeded! This is a locking bug\n");
01363 correct = False;
01364 } else {
01365 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
01366 NT_STATUS_LOCK_NOT_GRANTED)) return False;
01367 }
01368
01369 if (cli_lock(cli, fnum2, 0, 4, 0, READ_LOCK)) {
01370 printf("READ lock2 succeeded! This is a locking bug\n");
01371 correct = False;
01372 } else {
01373 if (!check_error(__LINE__, cli, ERRDOS, ERRlock,
01374 NT_STATUS_FILE_LOCK_CONFLICT)) return False;
01375 }
01376
01377 if (!cli_lock(cli, fnum1, 100, 4, 0, WRITE_LOCK)) {
01378 printf("lock at 100 failed (%s)\n", cli_errstr(cli));
01379 }
01380 cli_setpid(cli, 2);
01381 if (cli_unlock(cli, fnum1, 100, 4)) {
01382 printf("unlock at 100 succeeded! This is a locking bug\n");
01383 correct = False;
01384 }
01385
01386 if (cli_unlock(cli, fnum1, 0, 4)) {
01387 printf("unlock1 succeeded! This is a locking bug\n");
01388 correct = False;
01389 } else {
01390 if (!check_error(__LINE__, cli,
01391 ERRDOS, ERRlock,
01392 NT_STATUS_RANGE_NOT_LOCKED)) return False;
01393 }
01394
01395 if (cli_unlock(cli, fnum1, 0, 8)) {
01396 printf("unlock2 succeeded! This is a locking bug\n");
01397 correct = False;
01398 } else {
01399 if (!check_error(__LINE__, cli,
01400 ERRDOS, ERRlock,
01401 NT_STATUS_RANGE_NOT_LOCKED)) return False;
01402 }
01403
01404 if (cli_lock(cli, fnum3, 0, 4, 0, WRITE_LOCK)) {
01405 printf("lock3 succeeded! This is a locking bug\n");
01406 correct = False;
01407 } else {
01408 if (!check_error(__LINE__, cli, ERRDOS, ERRlock, NT_STATUS_LOCK_NOT_GRANTED)) return False;
01409 }
01410
01411 cli_setpid(cli, 1);
01412
01413 if (!cli_close(cli, fnum1)) {
01414 printf("close1 failed (%s)\n", cli_errstr(cli));
01415 return False;
01416 }
01417
01418 if (!cli_close(cli, fnum2)) {
01419 printf("close2 failed (%s)\n", cli_errstr(cli));
01420 return False;
01421 }
01422
01423 if (!cli_close(cli, fnum3)) {
01424 printf("close3 failed (%s)\n", cli_errstr(cli));
01425 return False;
01426 }
01427
01428 if (!torture_close_connection(cli)) {
01429 correct = False;
01430 }
01431
01432 printf("locktest2 finished\n");
01433
01434 return correct;
01435 }
01436
01437
01438
01439
01440
01441
01442
01443 static BOOL run_locktest3(int dummy)
01444 {
01445 static struct cli_state *cli1, *cli2;
01446 const char *fname = "\\lockt3.lck";
01447 int fnum1, fnum2, i;
01448 uint32 offset;
01449 BOOL correct = True;
01450
01451 #define NEXT_OFFSET offset += (~(uint32)0) / torture_numops
01452
01453 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
01454 return False;
01455 }
01456 cli_sockopt(cli1, sockops);
01457 cli_sockopt(cli2, sockops);
01458
01459 printf("starting locktest3\n");
01460
01461 cli_unlink(cli1, fname);
01462
01463 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01464 if (fnum1 == -1) {
01465 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
01466 return False;
01467 }
01468 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
01469 if (fnum2 == -1) {
01470 printf("open2 of %s failed (%s)\n", fname, cli_errstr(cli2));
01471 return False;
01472 }
01473
01474 for (offset=i=0;i<torture_numops;i++) {
01475 NEXT_OFFSET;
01476 if (!cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
01477 printf("lock1 %d failed (%s)\n",
01478 i,
01479 cli_errstr(cli1));
01480 return False;
01481 }
01482
01483 if (!cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
01484 printf("lock2 %d failed (%s)\n",
01485 i,
01486 cli_errstr(cli1));
01487 return False;
01488 }
01489 }
01490
01491 for (offset=i=0;i<torture_numops;i++) {
01492 NEXT_OFFSET;
01493
01494 if (cli_lock(cli1, fnum1, offset-2, 1, 0, WRITE_LOCK)) {
01495 printf("error: lock1 %d succeeded!\n", i);
01496 return False;
01497 }
01498
01499 if (cli_lock(cli2, fnum2, offset-1, 1, 0, WRITE_LOCK)) {
01500 printf("error: lock2 %d succeeded!\n", i);
01501 return False;
01502 }
01503
01504 if (cli_lock(cli1, fnum1, offset-1, 1, 0, WRITE_LOCK)) {
01505 printf("error: lock3 %d succeeded!\n", i);
01506 return False;
01507 }
01508
01509 if (cli_lock(cli2, fnum2, offset-2, 1, 0, WRITE_LOCK)) {
01510 printf("error: lock4 %d succeeded!\n", i);
01511 return False;
01512 }
01513 }
01514
01515 for (offset=i=0;i<torture_numops;i++) {
01516 NEXT_OFFSET;
01517
01518 if (!cli_unlock(cli1, fnum1, offset-1, 1)) {
01519 printf("unlock1 %d failed (%s)\n",
01520 i,
01521 cli_errstr(cli1));
01522 return False;
01523 }
01524
01525 if (!cli_unlock(cli2, fnum2, offset-2, 1)) {
01526 printf("unlock2 %d failed (%s)\n",
01527 i,
01528 cli_errstr(cli1));
01529 return False;
01530 }
01531 }
01532
01533 if (!cli_close(cli1, fnum1)) {
01534 printf("close1 failed (%s)\n", cli_errstr(cli1));
01535 return False;
01536 }
01537
01538 if (!cli_close(cli2, fnum2)) {
01539 printf("close2 failed (%s)\n", cli_errstr(cli2));
01540 return False;
01541 }
01542
01543 if (!cli_unlink(cli1, fname)) {
01544 printf("unlink failed (%s)\n", cli_errstr(cli1));
01545 return False;
01546 }
01547
01548 if (!torture_close_connection(cli1)) {
01549 correct = False;
01550 }
01551
01552 if (!torture_close_connection(cli2)) {
01553 correct = False;
01554 }
01555
01556 printf("finished locktest3\n");
01557
01558 return correct;
01559 }
01560
01561 #define EXPECTED(ret, v) if ((ret) != (v)) { \
01562 printf("** "); correct = False; \
01563 }
01564
01565
01566
01567
01568 static BOOL run_locktest4(int dummy)
01569 {
01570 static struct cli_state *cli1, *cli2;
01571 const char *fname = "\\lockt4.lck";
01572 int fnum1, fnum2, f;
01573 BOOL ret;
01574 char buf[1000];
01575 BOOL correct = True;
01576
01577 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
01578 return False;
01579 }
01580
01581 cli_sockopt(cli1, sockops);
01582 cli_sockopt(cli2, sockops);
01583
01584 printf("starting locktest4\n");
01585
01586 cli_unlink(cli1, fname);
01587
01588 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01589 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
01590
01591 memset(buf, 0, sizeof(buf));
01592
01593 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
01594 printf("Failed to create file\n");
01595 correct = False;
01596 goto fail;
01597 }
01598
01599 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
01600 cli_lock(cli1, fnum1, 2, 4, 0, WRITE_LOCK);
01601 EXPECTED(ret, False);
01602 printf("the same process %s set overlapping write locks\n", ret?"can":"cannot");
01603
01604 ret = cli_lock(cli1, fnum1, 10, 4, 0, READ_LOCK) &&
01605 cli_lock(cli1, fnum1, 12, 4, 0, READ_LOCK);
01606 EXPECTED(ret, True);
01607 printf("the same process %s set overlapping read locks\n", ret?"can":"cannot");
01608
01609 ret = cli_lock(cli1, fnum1, 20, 4, 0, WRITE_LOCK) &&
01610 cli_lock(cli2, fnum2, 22, 4, 0, WRITE_LOCK);
01611 EXPECTED(ret, False);
01612 printf("a different connection %s set overlapping write locks\n", ret?"can":"cannot");
01613
01614 ret = cli_lock(cli1, fnum1, 30, 4, 0, READ_LOCK) &&
01615 cli_lock(cli2, fnum2, 32, 4, 0, READ_LOCK);
01616 EXPECTED(ret, True);
01617 printf("a different connection %s set overlapping read locks\n", ret?"can":"cannot");
01618
01619 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 40, 4, 0, WRITE_LOCK)) &&
01620 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 42, 4, 0, WRITE_LOCK));
01621 EXPECTED(ret, False);
01622 printf("a different pid %s set overlapping write locks\n", ret?"can":"cannot");
01623
01624 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 50, 4, 0, READ_LOCK)) &&
01625 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 52, 4, 0, READ_LOCK));
01626 EXPECTED(ret, True);
01627 printf("a different pid %s set overlapping read locks\n", ret?"can":"cannot");
01628
01629 ret = cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK) &&
01630 cli_lock(cli1, fnum1, 60, 4, 0, READ_LOCK);
01631 EXPECTED(ret, True);
01632 printf("the same process %s set the same read lock twice\n", ret?"can":"cannot");
01633
01634 ret = cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK) &&
01635 cli_lock(cli1, fnum1, 70, 4, 0, WRITE_LOCK);
01636 EXPECTED(ret, False);
01637 printf("the same process %s set the same write lock twice\n", ret?"can":"cannot");
01638
01639 ret = cli_lock(cli1, fnum1, 80, 4, 0, READ_LOCK) &&
01640 cli_lock(cli1, fnum1, 80, 4, 0, WRITE_LOCK);
01641 EXPECTED(ret, False);
01642 printf("the same process %s overlay a read lock with a write lock\n", ret?"can":"cannot");
01643
01644 ret = cli_lock(cli1, fnum1, 90, 4, 0, WRITE_LOCK) &&
01645 cli_lock(cli1, fnum1, 90, 4, 0, READ_LOCK);
01646 EXPECTED(ret, True);
01647 printf("the same process %s overlay a write lock with a read lock\n", ret?"can":"cannot");
01648
01649 ret = (cli_setpid(cli1, 1), cli_lock(cli1, fnum1, 100, 4, 0, WRITE_LOCK)) &&
01650 (cli_setpid(cli1, 2), cli_lock(cli1, fnum1, 100, 4, 0, READ_LOCK));
01651 EXPECTED(ret, False);
01652 printf("a different pid %s overlay a write lock with a read lock\n", ret?"can":"cannot");
01653
01654 ret = cli_lock(cli1, fnum1, 110, 4, 0, READ_LOCK) &&
01655 cli_lock(cli1, fnum1, 112, 4, 0, READ_LOCK) &&
01656 cli_unlock(cli1, fnum1, 110, 6);
01657 EXPECTED(ret, False);
01658 printf("the same process %s coalesce read locks\n", ret?"can":"cannot");
01659
01660
01661 ret = cli_lock(cli1, fnum1, 120, 4, 0, WRITE_LOCK) &&
01662 (cli_read(cli2, fnum2, buf, 120, 4) == 4);
01663 EXPECTED(ret, False);
01664 printf("this server %s strict write locking\n", ret?"doesn't do":"does");
01665
01666 ret = cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK) &&
01667 (cli_write(cli2, fnum2, 0, buf, 130, 4) == 4);
01668 EXPECTED(ret, False);
01669 printf("this server %s strict read locking\n", ret?"doesn't do":"does");
01670
01671
01672 ret = cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
01673 cli_lock(cli1, fnum1, 140, 4, 0, READ_LOCK) &&
01674 cli_unlock(cli1, fnum1, 140, 4) &&
01675 cli_unlock(cli1, fnum1, 140, 4);
01676 EXPECTED(ret, True);
01677 printf("this server %s do recursive read locking\n", ret?"does":"doesn't");
01678
01679
01680 ret = cli_lock(cli1, fnum1, 150, 4, 0, WRITE_LOCK) &&
01681 cli_lock(cli1, fnum1, 150, 4, 0, READ_LOCK) &&
01682 cli_unlock(cli1, fnum1, 150, 4) &&
01683 (cli_read(cli2, fnum2, buf, 150, 4) == 4) &&
01684 !(cli_write(cli2, fnum2, 0, buf, 150, 4) == 4) &&
01685 cli_unlock(cli1, fnum1, 150, 4);
01686 EXPECTED(ret, True);
01687 printf("this server %s do recursive lock overlays\n", ret?"does":"doesn't");
01688
01689 ret = cli_lock(cli1, fnum1, 160, 4, 0, READ_LOCK) &&
01690 cli_unlock(cli1, fnum1, 160, 4) &&
01691 (cli_write(cli2, fnum2, 0, buf, 160, 4) == 4) &&
01692 (cli_read(cli2, fnum2, buf, 160, 4) == 4);
01693 EXPECTED(ret, True);
01694 printf("the same process %s remove a read lock using write locking\n", ret?"can":"cannot");
01695
01696 ret = cli_lock(cli1, fnum1, 170, 4, 0, WRITE_LOCK) &&
01697 cli_unlock(cli1, fnum1, 170, 4) &&
01698 (cli_write(cli2, fnum2, 0, buf, 170, 4) == 4) &&
01699 (cli_read(cli2, fnum2, buf, 170, 4) == 4);
01700 EXPECTED(ret, True);
01701 printf("the same process %s remove a write lock using read locking\n", ret?"can":"cannot");
01702
01703 ret = cli_lock(cli1, fnum1, 190, 4, 0, WRITE_LOCK) &&
01704 cli_lock(cli1, fnum1, 190, 4, 0, READ_LOCK) &&
01705 cli_unlock(cli1, fnum1, 190, 4) &&
01706 !(cli_write(cli2, fnum2, 0, buf, 190, 4) == 4) &&
01707 (cli_read(cli2, fnum2, buf, 190, 4) == 4);
01708 EXPECTED(ret, True);
01709 printf("the same process %s remove the first lock first\n", ret?"does":"doesn't");
01710
01711 cli_close(cli1, fnum1);
01712 cli_close(cli2, fnum2);
01713 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
01714 f = cli_open(cli1, fname, O_RDWR, DENY_NONE);
01715 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
01716 cli_lock(cli1, f, 0, 1, 0, READ_LOCK) &&
01717 cli_close(cli1, fnum1) &&
01718 ((fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE)) != -1) &&
01719 cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
01720 cli_close(cli1, f);
01721 cli_close(cli1, fnum1);
01722 EXPECTED(ret, True);
01723 printf("the server %s have the NT byte range lock bug\n", !ret?"does":"doesn't");
01724
01725 fail:
01726 cli_close(cli1, fnum1);
01727 cli_close(cli2, fnum2);
01728 cli_unlink(cli1, fname);
01729 torture_close_connection(cli1);
01730 torture_close_connection(cli2);
01731
01732 printf("finished locktest4\n");
01733 return correct;
01734 }
01735
01736
01737
01738
01739 static BOOL run_locktest5(int dummy)
01740 {
01741 static struct cli_state *cli1, *cli2;
01742 const char *fname = "\\lockt5.lck";
01743 int fnum1, fnum2, fnum3;
01744 BOOL ret;
01745 char buf[1000];
01746 BOOL correct = True;
01747
01748 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
01749 return False;
01750 }
01751
01752 cli_sockopt(cli1, sockops);
01753 cli_sockopt(cli2, sockops);
01754
01755 printf("starting locktest5\n");
01756
01757 cli_unlink(cli1, fname);
01758
01759 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01760 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
01761 fnum3 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
01762
01763 memset(buf, 0, sizeof(buf));
01764
01765 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
01766 printf("Failed to create file\n");
01767 correct = False;
01768 goto fail;
01769 }
01770
01771
01772 ret = cli_lock(cli1, fnum1, 0, 8, 0, READ_LOCK) &&
01773 cli_lock(cli1, fnum3, 0, 1, 0, READ_LOCK);
01774 cli_close(cli1, fnum1);
01775 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
01776 ret = cli_lock(cli1, fnum1, 7, 1, 0, WRITE_LOCK);
01777 EXPECTED(ret, True);
01778 printf("this server %s the NT locking bug\n", ret ? "doesn't have" : "has");
01779 cli_close(cli1, fnum1);
01780 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
01781 cli_unlock(cli1, fnum3, 0, 1);
01782
01783 ret = cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK) &&
01784 cli_lock(cli1, fnum1, 1, 1, 0, READ_LOCK);
01785 EXPECTED(ret, True);
01786 printf("the same process %s overlay a write with a read lock\n", ret?"can":"cannot");
01787
01788 ret = cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
01789 EXPECTED(ret, False);
01790
01791 printf("a different processs %s get a read lock on the first process lock stack\n", ret?"can":"cannot");
01792
01793
01794 cli_unlock(cli2, fnum2, 0, 4);
01795
01796 ret = cli_lock(cli1, fnum3, 0, 4, 0, READ_LOCK);
01797 EXPECTED(ret, False);
01798
01799 printf("the same processs on a different fnum %s get a read lock\n", ret?"can":"cannot");
01800
01801
01802 cli_unlock(cli1, fnum3, 0, 4);
01803
01804
01805 ret = cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK) &&
01806 cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK);
01807
01808 EXPECTED(ret, True);
01809 printf("the same process %s stack read locks\n", ret?"can":"cannot");
01810
01811
01812
01813
01814 ret = cli_unlock(cli1, fnum1, 0, 4) &&
01815 cli_lock(cli2, fnum2, 0, 4, 0, READ_LOCK);
01816
01817 EXPECTED(ret, True);
01818 printf("the first unlock removes the %s lock\n", ret?"WRITE":"READ");
01819
01820
01821 cli_unlock(cli2, fnum2, 0, 4);
01822
01823
01824
01825 ret = cli_unlock(cli1, fnum1, 1, 1) &&
01826 cli_unlock(cli1, fnum1, 0, 4) &&
01827 cli_unlock(cli1, fnum1, 0, 4);
01828
01829 EXPECTED(ret, True);
01830 printf("the same process %s unlock the stack of 4 locks\n", ret?"can":"cannot");
01831
01832
01833 ret = cli_unlock(cli1, fnum1, 0, 4);
01834 EXPECTED(ret, False);
01835 printf("the same process %s count the lock stack\n", !ret?"can":"cannot");
01836
01837
01838 ret = cli_lock(cli2, fnum2, 0, 4, 0, WRITE_LOCK);
01839 EXPECTED(ret, True);
01840
01841 printf("a different processs %s get a write lock on the unlocked stack\n", ret?"can":"cannot");
01842
01843
01844 fail:
01845 cli_close(cli1, fnum1);
01846 cli_close(cli2, fnum2);
01847 cli_unlink(cli1, fname);
01848 if (!torture_close_connection(cli1)) {
01849 correct = False;
01850 }
01851 if (!torture_close_connection(cli2)) {
01852 correct = False;
01853 }
01854
01855 printf("finished locktest5\n");
01856
01857 return correct;
01858 }
01859
01860
01861
01862
01863 static BOOL run_locktest6(int dummy)
01864 {
01865 static struct cli_state *cli;
01866 const char *fname[1] = { "\\lock6.txt" };
01867 int i;
01868 int fnum;
01869 NTSTATUS status;
01870
01871 if (!torture_open_connection(&cli, 0)) {
01872 return False;
01873 }
01874
01875 cli_sockopt(cli, sockops);
01876
01877 printf("starting locktest6\n");
01878
01879 for (i=0;i<1;i++) {
01880 printf("Testing %s\n", fname[i]);
01881
01882 cli_unlink(cli, fname[i]);
01883
01884 fnum = cli_open(cli, fname[i], O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01885 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CHANGE_LOCKTYPE);
01886 cli_close(cli, fnum);
01887 printf("CHANGE_LOCKTYPE gave %s\n", nt_errstr(status));
01888
01889 fnum = cli_open(cli, fname[i], O_RDWR, DENY_NONE);
01890 status = cli_locktype(cli, fnum, 0, 8, 0, LOCKING_ANDX_CANCEL_LOCK);
01891 cli_close(cli, fnum);
01892 printf("CANCEL_LOCK gave %s\n", nt_errstr(status));
01893
01894 cli_unlink(cli, fname[i]);
01895 }
01896
01897 torture_close_connection(cli);
01898
01899 printf("finished locktest6\n");
01900 return True;
01901 }
01902
01903 static BOOL run_locktest7(int dummy)
01904 {
01905 struct cli_state *cli1;
01906 const char *fname = "\\lockt7.lck";
01907 int fnum1;
01908 char buf[200];
01909 BOOL correct = False;
01910
01911 if (!torture_open_connection(&cli1, 0)) {
01912 return False;
01913 }
01914
01915 cli_sockopt(cli1, sockops);
01916
01917 printf("starting locktest7\n");
01918
01919 cli_unlink(cli1, fname);
01920
01921 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
01922
01923 memset(buf, 0, sizeof(buf));
01924
01925 if (cli_write(cli1, fnum1, 0, buf, 0, sizeof(buf)) != sizeof(buf)) {
01926 printf("Failed to create file\n");
01927 goto fail;
01928 }
01929
01930 cli_setpid(cli1, 1);
01931
01932 if (!cli_lock(cli1, fnum1, 130, 4, 0, READ_LOCK)) {
01933 printf("Unable to apply read lock on range 130:4, error was %s\n", cli_errstr(cli1));
01934 goto fail;
01935 } else {
01936 printf("pid1 successfully locked range 130:4 for READ\n");
01937 }
01938
01939 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
01940 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
01941 goto fail;
01942 } else {
01943 printf("pid1 successfully read the range 130:4\n");
01944 }
01945
01946 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
01947 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
01948 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
01949 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
01950 goto fail;
01951 }
01952 } else {
01953 printf("pid1 successfully wrote to the range 130:4 (should be denied)\n");
01954 goto fail;
01955 }
01956
01957 cli_setpid(cli1, 2);
01958
01959 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
01960 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
01961 } else {
01962 printf("pid2 successfully read the range 130:4\n");
01963 }
01964
01965 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
01966 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
01967 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
01968 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
01969 goto fail;
01970 }
01971 } else {
01972 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
01973 goto fail;
01974 }
01975
01976 cli_setpid(cli1, 1);
01977 cli_unlock(cli1, fnum1, 130, 4);
01978
01979 if (!cli_lock(cli1, fnum1, 130, 4, 0, WRITE_LOCK)) {
01980 printf("Unable to apply write lock on range 130:4, error was %s\n", cli_errstr(cli1));
01981 goto fail;
01982 } else {
01983 printf("pid1 successfully locked range 130:4 for WRITE\n");
01984 }
01985
01986 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
01987 printf("pid1 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
01988 goto fail;
01989 } else {
01990 printf("pid1 successfully read the range 130:4\n");
01991 }
01992
01993 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
01994 printf("pid1 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
01995 goto fail;
01996 } else {
01997 printf("pid1 successfully wrote to the range 130:4\n");
01998 }
01999
02000 cli_setpid(cli1, 2);
02001
02002 if (cli_read(cli1, fnum1, buf, 130, 4) != 4) {
02003 printf("pid2 unable to read the range 130:4, error was %s\n", cli_errstr(cli1));
02004 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
02005 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
02006 goto fail;
02007 }
02008 } else {
02009 printf("pid2 successfully read the range 130:4 (should be denied)\n");
02010 goto fail;
02011 }
02012
02013 if (cli_write(cli1, fnum1, 0, buf, 130, 4) != 4) {
02014 printf("pid2 unable to write to the range 130:4, error was %s\n", cli_errstr(cli1));
02015 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_FILE_LOCK_CONFLICT)) {
02016 printf("Incorrect error (should be NT_STATUS_FILE_LOCK_CONFLICT)\n");
02017 goto fail;
02018 }
02019 } else {
02020 printf("pid2 successfully wrote to the range 130:4 (should be denied)\n");
02021 goto fail;
02022 }
02023
02024 cli_unlock(cli1, fnum1, 130, 0);
02025 correct = True;
02026
02027 fail:
02028 cli_close(cli1, fnum1);
02029 cli_unlink(cli1, fname);
02030 torture_close_connection(cli1);
02031
02032 printf("finished locktest7\n");
02033 return correct;
02034 }
02035
02036
02037
02038
02039
02040 static BOOL run_fdpasstest(int dummy)
02041 {
02042 struct cli_state *cli1, *cli2;
02043 const char *fname = "\\fdpass.tst";
02044 int fnum1;
02045 pstring buf;
02046
02047 if (!torture_open_connection(&cli1, 0) || !torture_open_connection(&cli2, 1)) {
02048 return False;
02049 }
02050 cli_sockopt(cli1, sockops);
02051 cli_sockopt(cli2, sockops);
02052
02053 printf("starting fdpasstest\n");
02054
02055 cli_unlink(cli1, fname);
02056
02057 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02058 if (fnum1 == -1) {
02059 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
02060 return False;
02061 }
02062
02063 if (cli_write(cli1, fnum1, 0, "hello world\n", 0, 13) != 13) {
02064 printf("write failed (%s)\n", cli_errstr(cli1));
02065 return False;
02066 }
02067
02068 cli2->vuid = cli1->vuid;
02069 cli2->cnum = cli1->cnum;
02070 cli2->pid = cli1->pid;
02071
02072 if (cli_read(cli2, fnum1, buf, 0, 13) == 13) {
02073 printf("read succeeded! nasty security hole [%s]\n",
02074 buf);
02075 return False;
02076 }
02077
02078 cli_close(cli1, fnum1);
02079 cli_unlink(cli1, fname);
02080
02081 torture_close_connection(cli1);
02082 torture_close_connection(cli2);
02083
02084 printf("finished fdpasstest\n");
02085 return True;
02086 }
02087
02088 static BOOL run_fdsesstest(int dummy)
02089 {
02090 struct cli_state *cli;
02091 uint16 new_vuid;
02092 uint16 saved_vuid;
02093 uint16 new_cnum;
02094 uint16 saved_cnum;
02095 const char *fname = "\\fdsess.tst";
02096 const char *fname1 = "\\fdsess1.tst";
02097 int fnum1;
02098 int fnum2;
02099 pstring buf;
02100 BOOL ret = True;
02101
02102 if (!torture_open_connection(&cli, 0))
02103 return False;
02104 cli_sockopt(cli, sockops);
02105
02106 if (!torture_cli_session_setup2(cli, &new_vuid))
02107 return False;
02108
02109 saved_cnum = cli->cnum;
02110 if (!cli_send_tconX(cli, share, "?????", "", 1))
02111 return False;
02112 new_cnum = cli->cnum;
02113 cli->cnum = saved_cnum;
02114
02115 printf("starting fdsesstest\n");
02116
02117 cli_unlink(cli, fname);
02118 cli_unlink(cli, fname1);
02119
02120 fnum1 = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02121 if (fnum1 == -1) {
02122 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
02123 return False;
02124 }
02125
02126 if (cli_write(cli, fnum1, 0, "hello world\n", 0, 13) != 13) {
02127 printf("write failed (%s)\n", cli_errstr(cli));
02128 return False;
02129 }
02130
02131 saved_vuid = cli->vuid;
02132 cli->vuid = new_vuid;
02133
02134 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
02135 printf("read succeeded with different vuid! nasty security hole [%s]\n",
02136 buf);
02137 ret = False;
02138 }
02139
02140 fnum2 = cli_open(cli, fname1, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02141 if (fnum2 != -1) {
02142 printf("create with different vuid, same cnum succeeded.\n");
02143 cli_close(cli, fnum2);
02144 cli_unlink(cli, fname1);
02145 } else {
02146 printf("create with different vuid, same cnum failed.\n");
02147 printf("This will cause problems with service clients.\n");
02148 ret = False;
02149 }
02150
02151 cli->vuid = saved_vuid;
02152
02153
02154 cli->cnum = new_cnum;
02155
02156 if (cli_read(cli, fnum1, buf, 0, 13) == 13) {
02157 printf("read succeeded with different cnum![%s]\n",
02158 buf);
02159 ret = False;
02160 }
02161
02162 cli->cnum = saved_cnum;
02163 cli_close(cli, fnum1);
02164 cli_unlink(cli, fname);
02165
02166 torture_close_connection(cli);
02167
02168 printf("finished fdsesstest\n");
02169 return ret;
02170 }
02171
02172
02173
02174
02175
02176
02177 static BOOL run_unlinktest(int dummy)
02178 {
02179 struct cli_state *cli;
02180 const char *fname = "\\unlink.tst";
02181 int fnum;
02182 BOOL correct = True;
02183
02184 if (!torture_open_connection(&cli, 0)) {
02185 return False;
02186 }
02187
02188 cli_sockopt(cli, sockops);
02189
02190 printf("starting unlink test\n");
02191
02192 cli_unlink(cli, fname);
02193
02194 cli_setpid(cli, 1);
02195
02196 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02197 if (fnum == -1) {
02198 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
02199 return False;
02200 }
02201
02202 if (cli_unlink(cli, fname)) {
02203 printf("error: server allowed unlink on an open file\n");
02204 correct = False;
02205 } else {
02206 correct = check_error(__LINE__, cli, ERRDOS, ERRbadshare,
02207 NT_STATUS_SHARING_VIOLATION);
02208 }
02209
02210 cli_close(cli, fnum);
02211 cli_unlink(cli, fname);
02212
02213 if (!torture_close_connection(cli)) {
02214 correct = False;
02215 }
02216
02217 printf("unlink test finished\n");
02218
02219 return correct;
02220 }
02221
02222
02223
02224
02225
02226 static BOOL run_maxfidtest(int dummy)
02227 {
02228 struct cli_state *cli;
02229 const char *ftemplate = "\\maxfid.%d.%d";
02230 fstring fname;
02231 int fnums[0x11000], i;
02232 int retries=4;
02233 BOOL correct = True;
02234
02235 cli = current_cli;
02236
02237 if (retries <= 0) {
02238 printf("failed to connect\n");
02239 return False;
02240 }
02241
02242 cli_sockopt(cli, sockops);
02243
02244 for (i=0; i<0x11000; i++) {
02245 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
02246 if ((fnums[i] = cli_open(cli, fname,
02247 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE)) ==
02248 -1) {
02249 printf("open of %s failed (%s)\n",
02250 fname, cli_errstr(cli));
02251 printf("maximum fnum is %d\n", i);
02252 break;
02253 }
02254 printf("%6d\r", i);
02255 }
02256 printf("%6d\n", i);
02257 i--;
02258
02259 printf("cleaning up\n");
02260 for (;i>=0;i--) {
02261 slprintf(fname,sizeof(fname)-1,ftemplate, i,(int)getpid());
02262 cli_close(cli, fnums[i]);
02263 if (!cli_unlink(cli, fname)) {
02264 printf("unlink of %s failed (%s)\n",
02265 fname, cli_errstr(cli));
02266 correct = False;
02267 }
02268 printf("%6d\r", i);
02269 }
02270 printf("%6d\n", 0);
02271
02272 printf("maxfid test finished\n");
02273 if (!torture_close_connection(cli)) {
02274 correct = False;
02275 }
02276 return correct;
02277 }
02278
02279
02280 static void rand_buf(char *buf, int len)
02281 {
02282 while (len--) {
02283 *buf = (char)sys_random();
02284 buf++;
02285 }
02286 }
02287
02288
02289 static BOOL run_negprot_nowait(int dummy)
02290 {
02291 int i;
02292 static struct cli_state *cli;
02293 BOOL correct = True;
02294
02295 printf("starting negprot nowait test\n");
02296
02297 if (!(cli = open_nbt_connection())) {
02298 return False;
02299 }
02300
02301 for (i=0;i<50000;i++) {
02302 cli_negprot_send(cli);
02303 }
02304
02305 if (!torture_close_connection(cli)) {
02306 correct = False;
02307 }
02308
02309 printf("finished negprot nowait test\n");
02310
02311 return correct;
02312 }
02313
02314
02315
02316 static BOOL run_randomipc(int dummy)
02317 {
02318 char *rparam = NULL;
02319 char *rdata = NULL;
02320 unsigned int rdrcnt,rprcnt;
02321 pstring param;
02322 int api, param_len, i;
02323 struct cli_state *cli;
02324 BOOL correct = True;
02325 int count = 50000;
02326
02327 printf("starting random ipc test\n");
02328
02329 if (!torture_open_connection(&cli, 0)) {
02330 return False;
02331 }
02332
02333 for (i=0;i<count;i++) {
02334 api = sys_random() % 500;
02335 param_len = (sys_random() % 64);
02336
02337 rand_buf(param, param_len);
02338
02339 SSVAL(param,0,api);
02340
02341 cli_api(cli,
02342 param, param_len, 8,
02343 NULL, 0, BUFFER_SIZE,
02344 &rparam, &rprcnt,
02345 &rdata, &rdrcnt);
02346 if (i % 100 == 0) {
02347 printf("%d/%d\r", i,count);
02348 }
02349 }
02350 printf("%d/%d\n", i, count);
02351
02352 if (!torture_close_connection(cli)) {
02353 correct = False;
02354 }
02355
02356 printf("finished random ipc test\n");
02357
02358 return correct;
02359 }
02360
02361
02362
02363 static void browse_callback(const char *sname, uint32 stype,
02364 const char *comment, void *state)
02365 {
02366 printf("\t%20.20s %08x %s\n", sname, stype, comment);
02367 }
02368
02369
02370
02371
02372
02373
02374
02375 static BOOL run_browsetest(int dummy)
02376 {
02377 static struct cli_state *cli;
02378 BOOL correct = True;
02379
02380 printf("starting browse test\n");
02381
02382 if (!torture_open_connection(&cli, 0)) {
02383 return False;
02384 }
02385
02386 printf("domain list:\n");
02387 cli_NetServerEnum(cli, cli->server_domain,
02388 SV_TYPE_DOMAIN_ENUM,
02389 browse_callback, NULL);
02390
02391 printf("machine list:\n");
02392 cli_NetServerEnum(cli, cli->server_domain,
02393 SV_TYPE_ALL,
02394 browse_callback, NULL);
02395
02396 if (!torture_close_connection(cli)) {
02397 correct = False;
02398 }
02399
02400 printf("browse test finished\n");
02401
02402 return correct;
02403
02404 }
02405
02406
02407
02408
02409
02410 static BOOL run_attrtest(int dummy)
02411 {
02412 struct cli_state *cli;
02413 int fnum;
02414 time_t t, t2;
02415 const char *fname = "\\attrib123456789.tst";
02416 BOOL correct = True;
02417
02418 printf("starting attrib test\n");
02419
02420 if (!torture_open_connection(&cli, 0)) {
02421 return False;
02422 }
02423
02424 cli_unlink(cli, fname);
02425 fnum = cli_open(cli, fname,
02426 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
02427 cli_close(cli, fnum);
02428 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
02429 printf("getatr failed (%s)\n", cli_errstr(cli));
02430 correct = False;
02431 }
02432
02433 if (abs(t - time(NULL)) > 60*60*24*10) {
02434 printf("ERROR: SMBgetatr bug. time is %s",
02435 ctime(&t));
02436 t = time(NULL);
02437 correct = True;
02438 }
02439
02440 t2 = t-60*60*24;
02441
02442 if (!cli_setatr(cli, fname, 0, t2)) {
02443 printf("setatr failed (%s)\n", cli_errstr(cli));
02444 correct = True;
02445 }
02446
02447 if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
02448 printf("getatr failed (%s)\n", cli_errstr(cli));
02449 correct = True;
02450 }
02451
02452 if (t != t2) {
02453 printf("ERROR: getatr/setatr bug. times are\n%s",
02454 ctime(&t));
02455 printf("%s", ctime(&t2));
02456 correct = True;
02457 }
02458
02459 cli_unlink(cli, fname);
02460
02461 if (!torture_close_connection(cli)) {
02462 correct = False;
02463 }
02464
02465 printf("attrib test finished\n");
02466
02467 return correct;
02468 }
02469
02470
02471
02472
02473
02474 static BOOL run_trans2test(int dummy)
02475 {
02476 struct cli_state *cli;
02477 int fnum;
02478 SMB_OFF_T size;
02479 time_t c_time, a_time, m_time;
02480 struct timespec c_time_ts, a_time_ts, m_time_ts, w_time_ts, m_time2_ts;
02481 const char *fname = "\\trans2.tst";
02482 const char *dname = "\\trans2";
02483 const char *fname2 = "\\trans2\\trans2.tst";
02484 pstring pname;
02485 BOOL correct = True;
02486
02487 printf("starting trans2 test\n");
02488
02489 if (!torture_open_connection(&cli, 0)) {
02490 return False;
02491 }
02492
02493 cli_unlink(cli, fname);
02494 fnum = cli_open(cli, fname,
02495 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
02496 if (!cli_qfileinfo(cli, fnum, NULL, &size, &c_time_ts, &a_time_ts, &w_time_ts,
02497 &m_time_ts, NULL)) {
02498 printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(cli));
02499 correct = False;
02500 }
02501
02502 if (!cli_qfilename(cli, fnum, pname)) {
02503 printf("ERROR: qfilename failed (%s)\n", cli_errstr(cli));
02504 correct = False;
02505 }
02506
02507 if (strcmp(pname, fname)) {
02508 printf("qfilename gave different name? [%s] [%s]\n",
02509 fname, pname);
02510 correct = False;
02511 }
02512
02513 cli_close(cli, fnum);
02514
02515 sleep(2);
02516
02517 cli_unlink(cli, fname);
02518 fnum = cli_open(cli, fname,
02519 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
02520 if (fnum == -1) {
02521 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
02522 return False;
02523 }
02524 cli_close(cli, fnum);
02525
02526 if (!cli_qpathinfo(cli, fname, &c_time, &a_time, &m_time, &size, NULL)) {
02527 printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(cli));
02528 correct = False;
02529 } else {
02530 if (c_time != m_time) {
02531 printf("create time=%s", ctime(&c_time));
02532 printf("modify time=%s", ctime(&m_time));
02533 printf("This system appears to have sticky create times\n");
02534 }
02535 if (a_time % (60*60) == 0) {
02536 printf("access time=%s", ctime(&a_time));
02537 printf("This system appears to set a midnight access time\n");
02538 correct = False;
02539 }
02540
02541 if (abs(m_time - time(NULL)) > 60*60*24*7) {
02542 printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
02543 correct = False;
02544 }
02545 }
02546
02547
02548 cli_unlink(cli, fname);
02549 fnum = cli_open(cli, fname,
02550 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
02551 cli_close(cli, fnum);
02552 if (!cli_qpathinfo2(cli, fname, &c_time_ts, &a_time_ts, &w_time_ts,
02553 &m_time_ts, &size, NULL, NULL)) {
02554 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
02555 correct = False;
02556 } else {
02557 if (w_time_ts.tv_sec < 60*60*24*2) {
02558 printf("write time=%s", ctime(&w_time_ts.tv_sec));
02559 printf("This system appears to set a initial 0 write time\n");
02560 correct = False;
02561 }
02562 }
02563
02564 cli_unlink(cli, fname);
02565
02566
02567
02568
02569 if (!cli_mkdir(cli, dname)) {
02570 printf("ERROR: mkdir failed (%s)\n", cli_errstr(cli));
02571 correct = False;
02572 }
02573 sleep(3);
02574 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
02575 &m_time_ts, &size, NULL, NULL)) {
02576 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
02577 correct = False;
02578 }
02579
02580 fnum = cli_open(cli, fname2,
02581 O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
02582 cli_write(cli, fnum, 0, (char *)&fnum, 0, sizeof(fnum));
02583 cli_close(cli, fnum);
02584 if (!cli_qpathinfo2(cli, "\\trans2\\", &c_time_ts, &a_time_ts, &w_time_ts,
02585 &m_time2_ts, &size, NULL, NULL)) {
02586 printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(cli));
02587 correct = False;
02588 } else {
02589 if (memcmp(&m_time_ts, &m_time2_ts, sizeof(struct timespec))
02590 == 0) {
02591 printf("This system does not update directory modification times\n");
02592 correct = False;
02593 }
02594 }
02595 cli_unlink(cli, fname2);
02596 cli_rmdir(cli, dname);
02597
02598 if (!torture_close_connection(cli)) {
02599 correct = False;
02600 }
02601
02602 printf("trans2 test finished\n");
02603
02604 return correct;
02605 }
02606
02607
02608
02609
02610
02611 static BOOL new_trans(struct cli_state *pcli, int fnum, int level)
02612 {
02613 char *buf = NULL;
02614 uint32 len;
02615 BOOL correct = True;
02616
02617 if (!cli_qfileinfo_test(pcli, fnum, level, &buf, &len)) {
02618 printf("ERROR: qfileinfo (%d) failed (%s)\n", level, cli_errstr(pcli));
02619 correct = False;
02620 } else {
02621 printf("qfileinfo: level %d, len = %u\n", level, len);
02622 dump_data(0, buf, len);
02623 printf("\n");
02624 }
02625 SAFE_FREE(buf);
02626 return correct;
02627 }
02628
02629 static BOOL run_w2ktest(int dummy)
02630 {
02631 struct cli_state *cli;
02632 int fnum;
02633 const char *fname = "\\w2ktest\\w2k.tst";
02634 int level;
02635 BOOL correct = True;
02636
02637 printf("starting w2k test\n");
02638
02639 if (!torture_open_connection(&cli, 0)) {
02640 return False;
02641 }
02642
02643 fnum = cli_open(cli, fname,
02644 O_RDWR | O_CREAT , DENY_NONE);
02645
02646 for (level = 1004; level < 1040; level++) {
02647 new_trans(cli, fnum, level);
02648 }
02649
02650 cli_close(cli, fnum);
02651
02652 if (!torture_close_connection(cli)) {
02653 correct = False;
02654 }
02655
02656 printf("w2k test finished\n");
02657
02658 return correct;
02659 }
02660
02661
02662
02663
02664
02665 static BOOL run_oplock1(int dummy)
02666 {
02667 struct cli_state *cli1;
02668 const char *fname = "\\lockt1.lck";
02669 int fnum1;
02670 BOOL correct = True;
02671
02672 printf("starting oplock test 1\n");
02673
02674 if (!torture_open_connection(&cli1, 0)) {
02675 return False;
02676 }
02677
02678 cli_unlink(cli1, fname);
02679
02680 cli_sockopt(cli1, sockops);
02681
02682 cli1->use_oplocks = True;
02683
02684 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02685 if (fnum1 == -1) {
02686 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
02687 return False;
02688 }
02689
02690 cli1->use_oplocks = False;
02691
02692 cli_unlink(cli1, fname);
02693 cli_unlink(cli1, fname);
02694
02695 if (!cli_close(cli1, fnum1)) {
02696 printf("close2 failed (%s)\n", cli_errstr(cli1));
02697 return False;
02698 }
02699
02700 if (!cli_unlink(cli1, fname)) {
02701 printf("unlink failed (%s)\n", cli_errstr(cli1));
02702 return False;
02703 }
02704
02705 if (!torture_close_connection(cli1)) {
02706 correct = False;
02707 }
02708
02709 printf("finished oplock test 1\n");
02710
02711 return correct;
02712 }
02713
02714 static BOOL run_oplock2(int dummy)
02715 {
02716 struct cli_state *cli1, *cli2;
02717 const char *fname = "\\lockt2.lck";
02718 int fnum1, fnum2;
02719 int saved_use_oplocks = use_oplocks;
02720 char buf[4];
02721 BOOL correct = True;
02722 volatile BOOL *shared_correct;
02723
02724 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
02725 *shared_correct = True;
02726
02727 use_level_II_oplocks = True;
02728 use_oplocks = True;
02729
02730 printf("starting oplock test 2\n");
02731
02732 if (!torture_open_connection(&cli1, 0)) {
02733 use_level_II_oplocks = False;
02734 use_oplocks = saved_use_oplocks;
02735 return False;
02736 }
02737
02738 cli1->use_oplocks = True;
02739 cli1->use_level_II_oplocks = True;
02740
02741 if (!torture_open_connection(&cli2, 1)) {
02742 use_level_II_oplocks = False;
02743 use_oplocks = saved_use_oplocks;
02744 return False;
02745 }
02746
02747 cli2->use_oplocks = True;
02748 cli2->use_level_II_oplocks = True;
02749
02750 cli_unlink(cli1, fname);
02751
02752 cli_sockopt(cli1, sockops);
02753 cli_sockopt(cli2, sockops);
02754
02755 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
02756 if (fnum1 == -1) {
02757 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
02758 return False;
02759 }
02760
02761
02762 use_level_II_oplocks = False;
02763 use_oplocks = saved_use_oplocks;
02764
02765 if (fork() == 0) {
02766
02767 fnum2 = cli_open(cli2, fname, O_RDWR, DENY_NONE);
02768 if (fnum2 == -1) {
02769 printf("second open of %s failed (%s)\n", fname, cli_errstr(cli1));
02770 *shared_correct = False;
02771 exit(0);
02772 }
02773
02774 sleep(2);
02775
02776 if (!cli_close(cli2, fnum2)) {
02777 printf("close2 failed (%s)\n", cli_errstr(cli1));
02778 *shared_correct = False;
02779 }
02780
02781 exit(0);
02782 }
02783
02784 sleep(2);
02785
02786
02787
02788
02789 if (cli_read(cli1, fnum1, buf, 0, 4) != 0) {
02790 printf("read on fnum1 failed (%s)\n", cli_errstr(cli1));
02791 correct = False;
02792 }
02793
02794
02795
02796
02797 if (!cli_lock(cli1, fnum1, 0, 4, 0, READ_LOCK)) {
02798 printf("lock failed (%s)\n", cli_errstr(cli1));
02799 correct = False;
02800 }
02801
02802 cli_unlock(cli1, fnum1, 0, 4);
02803
02804 sleep(2);
02805
02806 if (!cli_lock(cli1, fnum1, 0, 4, 0, WRITE_LOCK)) {
02807 printf("lock failed (%s)\n", cli_errstr(cli1));
02808 correct = False;
02809 }
02810
02811 cli_unlock(cli1, fnum1, 0, 4);
02812
02813 sleep(2);
02814
02815 cli_read(cli1, fnum1, buf, 0, 4);
02816
02817 #if 0
02818 if (cli_write(cli1, fnum1, 0, buf, 0, 4) != 4) {
02819 printf("write on fnum1 failed (%s)\n", cli_errstr(cli1));
02820 correct = False;
02821 }
02822 #endif
02823
02824 if (!cli_close(cli1, fnum1)) {
02825 printf("close1 failed (%s)\n", cli_errstr(cli1));
02826 correct = False;
02827 }
02828
02829 sleep(4);
02830
02831 if (!cli_unlink(cli1, fname)) {
02832 printf("unlink failed (%s)\n", cli_errstr(cli1));
02833 correct = False;
02834 }
02835
02836 if (!torture_close_connection(cli1)) {
02837 correct = False;
02838 }
02839
02840 if (!*shared_correct) {
02841 correct = False;
02842 }
02843
02844 printf("finished oplock test 2\n");
02845
02846 return correct;
02847 }
02848
02849
02850 static BOOL oplock3_handler(struct cli_state *cli, int fnum, unsigned char level)
02851 {
02852 printf("got oplock break fnum=%d level=%d\n",
02853 fnum, level);
02854 return cli_oplock_ack(cli, fnum, level);
02855 }
02856
02857 static BOOL run_oplock3(int dummy)
02858 {
02859 struct cli_state *cli;
02860 const char *fname = "\\oplockt3.dat";
02861 int fnum;
02862 char buf[4] = "abcd";
02863 BOOL correct = True;
02864 volatile BOOL *shared_correct;
02865
02866 shared_correct = (volatile BOOL *)shm_setup(sizeof(BOOL));
02867 *shared_correct = True;
02868
02869 printf("starting oplock test 3\n");
02870
02871 if (fork() == 0) {
02872
02873 use_oplocks = True;
02874 use_level_II_oplocks = True;
02875 if (!torture_open_connection(&cli, 0)) {
02876 *shared_correct = False;
02877 exit(0);
02878 }
02879 sleep(2);
02880
02881 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
02882 cli_write(cli, fnum, 0, buf, 0, 4);
02883 exit(0);
02884 }
02885
02886
02887 use_oplocks = True;
02888 use_level_II_oplocks = True;
02889 if (!torture_open_connection(&cli, 1)) {
02890 return False;
02891 }
02892 cli_oplock_handler(cli, oplock3_handler);
02893 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
02894 cli_write(cli, fnum, 0, buf, 0, 4);
02895 cli_close(cli, fnum);
02896 fnum = cli_open(cli, fname, O_RDWR, DENY_NONE);
02897 cli->timeout = 20000;
02898 cli_receive_smb(cli);
02899 printf("finished oplock test 3\n");
02900
02901 return (correct && *shared_correct);
02902
02903
02904 }
02905
02906
02907
02908
02909
02910
02911 static BOOL run_deletetest(int dummy)
02912 {
02913 struct cli_state *cli1 = NULL;
02914 struct cli_state *cli2 = NULL;
02915 const char *fname = "\\delete.file";
02916 int fnum1 = -1;
02917 int fnum2 = -1;
02918 BOOL correct = True;
02919
02920 printf("starting delete test\n");
02921
02922 if (!torture_open_connection(&cli1, 0)) {
02923 return False;
02924 }
02925
02926 cli_sockopt(cli1, sockops);
02927
02928
02929
02930 cli_setatr(cli1, fname, 0, 0);
02931 cli_unlink(cli1, fname);
02932
02933 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS|DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
02934 0, FILE_OVERWRITE_IF,
02935 FILE_DELETE_ON_CLOSE, 0);
02936
02937 if (fnum1 == -1) {
02938 printf("[1] open of %s failed (%s)\n", fname, cli_errstr(cli1));
02939 correct = False;
02940 goto fail;
02941 }
02942
02943 #if 0
02944 {
02945 uint32 *accinfo = NULL;
02946 uint32 len;
02947 cli_qfileinfo_test(cli1, fnum1, SMB_FILE_ACCESS_INFORMATION, (char **)&accinfo, &len);
02948 if (accinfo)
02949 printf("access mode = 0x%lx\n", *accinfo);
02950 SAFE_FREE(accinfo);
02951 }
02952 #endif
02953
02954 if (!cli_close(cli1, fnum1)) {
02955 printf("[1] close failed (%s)\n", cli_errstr(cli1));
02956 correct = False;
02957 goto fail;
02958 }
02959
02960 fnum1 = cli_open(cli1, fname, O_RDWR, DENY_NONE);
02961 if (fnum1 != -1) {
02962 printf("[1] open of %s succeeded (should fail)\n", fname);
02963 correct = False;
02964 goto fail;
02965 }
02966
02967 printf("first delete on close test succeeded.\n");
02968
02969
02970
02971 cli_setatr(cli1, fname, 0, 0);
02972 cli_unlink(cli1, fname);
02973
02974 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS,
02975 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE,
02976 FILE_OVERWRITE_IF, 0, 0);
02977
02978 if (fnum1 == -1) {
02979 printf("[2] open of %s failed (%s)\n", fname, cli_errstr(cli1));
02980 correct = False;
02981 goto fail;
02982 }
02983
02984 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
02985 printf("[2] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
02986 correct = False;
02987 goto fail;
02988 }
02989
02990 if (!cli_close(cli1, fnum1)) {
02991 printf("[2] close failed (%s)\n", cli_errstr(cli1));
02992 correct = False;
02993 goto fail;
02994 }
02995
02996 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
02997 if (fnum1 != -1) {
02998 printf("[2] open of %s succeeded should have been deleted on close !\n", fname);
02999 if (!cli_close(cli1, fnum1)) {
03000 printf("[2] close failed (%s)\n", cli_errstr(cli1));
03001 correct = False;
03002 goto fail;
03003 }
03004 cli_unlink(cli1, fname);
03005 } else
03006 printf("second delete on close test succeeded.\n");
03007
03008
03009 cli_setatr(cli1, fname, 0, 0);
03010 cli_unlink(cli1, fname);
03011
03012 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
03013 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
03014
03015 if (fnum1 == -1) {
03016 printf("[3] open - 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03017 correct = False;
03018 goto fail;
03019 }
03020
03021
03022
03023
03024 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03025 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, 0);
03026
03027 if (fnum2 != -1) {
03028 printf("[3] open - 2 of %s succeeded - should have failed.\n", fname);
03029 correct = False;
03030 goto fail;
03031 }
03032
03033
03034
03035 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03036 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
03037
03038 if (fnum2 == -1) {
03039 printf("[3] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
03040 correct = False;
03041 goto fail;
03042 }
03043
03044 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
03045 printf("[3] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
03046 correct = False;
03047 goto fail;
03048 }
03049
03050 if (!cli_close(cli1, fnum1)) {
03051 printf("[3] close 1 failed (%s)\n", cli_errstr(cli1));
03052 correct = False;
03053 goto fail;
03054 }
03055
03056 if (!cli_close(cli1, fnum2)) {
03057 printf("[3] close 2 failed (%s)\n", cli_errstr(cli1));
03058 correct = False;
03059 goto fail;
03060 }
03061
03062
03063
03064 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
03065 if (fnum1 != -1) {
03066 printf("[3] open of %s succeeded should have been deleted on close !\n", fname);
03067 if (!cli_close(cli1, fnum1)) {
03068 printf("[3] close failed (%s)\n", cli_errstr(cli1));
03069 }
03070 cli_unlink(cli1, fname);
03071 correct = False;
03072 goto fail;
03073 } else
03074 printf("third delete on close test succeeded.\n");
03075
03076
03077 cli_setatr(cli1, fname, 0, 0);
03078 cli_unlink(cli1, fname);
03079
03080 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
03081 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
03082
03083 if (fnum1 == -1) {
03084 printf("[4] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03085 correct = False;
03086 goto fail;
03087 }
03088
03089
03090 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
03091 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN, 0, 0);
03092 if (fnum2 == -1) {
03093 printf("[4] open - 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
03094 correct = False;
03095 goto fail;
03096 }
03097
03098 if (!cli_close(cli1, fnum2)) {
03099 printf("[4] close - 1 failed (%s)\n", cli_errstr(cli1));
03100 correct = False;
03101 goto fail;
03102 }
03103
03104 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
03105 printf("[4] setting delete_on_close failed (%s)\n", cli_errstr(cli1));
03106 correct = False;
03107 goto fail;
03108 }
03109
03110
03111 fnum2 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS,
03112 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
03113 FILE_OPEN, 0, 0);
03114 if (fnum2 != -1) {
03115 printf("[4] open - 3 of %s succeeded ! Should have failed.\n", fname );
03116 correct = False;
03117 goto fail;
03118 } else
03119 printf("fourth delete on close test succeeded.\n");
03120
03121 if (!cli_close(cli1, fnum1)) {
03122 printf("[4] close - 2 failed (%s)\n", cli_errstr(cli1));
03123 correct = False;
03124 goto fail;
03125 }
03126
03127
03128 cli_setatr(cli1, fname, 0, 0);
03129 cli_unlink(cli1, fname);
03130
03131 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT, DENY_NONE);
03132 if (fnum1 == -1) {
03133 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03134 correct = False;
03135 goto fail;
03136 }
03137
03138
03139
03140 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
03141 printf("[5] setting delete_on_close on OpenX file succeeded - should fail !\n");
03142 correct = False;
03143 goto fail;
03144 }
03145
03146 if (!cli_close(cli1, fnum1)) {
03147 printf("[5] close - 2 failed (%s)\n", cli_errstr(cli1));
03148 correct = False;
03149 goto fail;
03150 }
03151
03152 printf("fifth delete on close test succeeded.\n");
03153
03154
03155 cli_setatr(cli1, fname, 0, 0);
03156 cli_unlink(cli1, fname);
03157
03158 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
03159 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
03160 FILE_OVERWRITE_IF, 0, 0);
03161
03162 if (fnum1 == -1) {
03163 printf("[6] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03164 correct = False;
03165 goto fail;
03166 }
03167
03168
03169
03170 if (cli_nt_delete_on_close(cli1, fnum1, True)) {
03171 printf("[6] setting delete_on_close on file with no delete access succeeded - should fail !\n");
03172 correct = False;
03173 goto fail;
03174 }
03175
03176 if (!cli_close(cli1, fnum1)) {
03177 printf("[6] close - 2 failed (%s)\n", cli_errstr(cli1));
03178 correct = False;
03179 goto fail;
03180 }
03181
03182 printf("sixth delete on close test succeeded.\n");
03183
03184
03185 cli_setatr(cli1, fname, 0, 0);
03186 cli_unlink(cli1, fname);
03187
03188 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
03189 FILE_ATTRIBUTE_NORMAL, 0, FILE_OVERWRITE_IF, 0, 0);
03190
03191 if (fnum1 == -1) {
03192 printf("[7] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03193 correct = False;
03194 goto fail;
03195 }
03196
03197 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
03198 printf("[7] setting delete_on_close on file failed !\n");
03199 correct = False;
03200 goto fail;
03201 }
03202
03203 if (!cli_nt_delete_on_close(cli1, fnum1, False)) {
03204 printf("[7] unsetting delete_on_close on file failed !\n");
03205 correct = False;
03206 goto fail;
03207 }
03208
03209 if (!cli_close(cli1, fnum1)) {
03210 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
03211 correct = False;
03212 goto fail;
03213 }
03214
03215
03216
03217 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
03218 if (fnum1 == -1) {
03219 printf("[5] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03220 correct = False;
03221 goto fail;
03222 }
03223
03224 if (!cli_close(cli1, fnum1)) {
03225 printf("[7] close - 2 failed (%s)\n", cli_errstr(cli1));
03226 correct = False;
03227 goto fail;
03228 }
03229
03230 printf("seventh delete on close test succeeded.\n");
03231
03232
03233 cli_setatr(cli1, fname, 0, 0);
03234 cli_unlink(cli1, fname);
03235
03236 if (!torture_open_connection(&cli2, 1)) {
03237 printf("[8] failed to open second connection.\n");
03238 correct = False;
03239 goto fail;
03240 }
03241
03242 cli_sockopt(cli1, sockops);
03243
03244 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
03245 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
03246 FILE_OVERWRITE_IF, 0, 0);
03247
03248 if (fnum1 == -1) {
03249 printf("[8] open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03250 correct = False;
03251 goto fail;
03252 }
03253
03254 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
03255 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
03256 FILE_OPEN, 0, 0);
03257
03258 if (fnum2 == -1) {
03259 printf("[8] open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03260 correct = False;
03261 goto fail;
03262 }
03263
03264 if (!cli_nt_delete_on_close(cli1, fnum1, True)) {
03265 printf("[8] setting delete_on_close on file failed !\n");
03266 correct = False;
03267 goto fail;
03268 }
03269
03270 if (!cli_close(cli1, fnum1)) {
03271 printf("[8] close - 1 failed (%s)\n", cli_errstr(cli1));
03272 correct = False;
03273 goto fail;
03274 }
03275
03276 if (!cli_close(cli2, fnum2)) {
03277 printf("[8] close - 2 failed (%s)\n", cli_errstr(cli2));
03278 correct = False;
03279 goto fail;
03280 }
03281
03282
03283 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
03284 if (fnum1 != -1) {
03285 printf("[8] open of %s succeeded should have been deleted on close !\n", fname);
03286 goto fail;
03287 correct = False;
03288 } else
03289 printf("eighth delete on close test succeeded.\n");
03290
03291
03292 fnum1 = cli_nt_create_full(cli1, fname, 0,FILE_READ_DATA|FILE_WRITE_DATA,
03293 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
03294
03295 if (fnum1 != -1) {
03296 printf("[9] open of %s succeeded should have failed!\n", fname);
03297 correct = False;
03298 goto fail;
03299 }
03300
03301 printf("ninth delete on close test succeeded.\n");
03302
03303 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA|DELETE_ACCESS,
03304 FILE_ATTRIBUTE_NORMAL, FILE_SHARE_NONE, FILE_OVERWRITE_IF, FILE_DELETE_ON_CLOSE, 0);
03305 if (fnum1 == -1) {
03306 printf("[10] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03307 correct = False;
03308 goto fail;
03309 }
03310
03311
03312 if (!cli_close(cli1, fnum1)) {
03313 printf("[10] close failed (%s)\n", cli_errstr(cli1));
03314 correct = False;
03315 goto fail;
03316 }
03317
03318
03319 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_NONE);
03320 if (fnum1 != -1) {
03321 printf("[10] open of %s succeeded should have been deleted on close !\n", fname);
03322 goto fail;
03323 correct = False;
03324 } else
03325 printf("tenth delete on close test succeeded.\n");
03326
03327 cli_setatr(cli1, fname, 0, 0);
03328 cli_unlink(cli1, fname);
03329
03330
03331
03332
03333
03334 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA,
03335 FILE_ATTRIBUTE_READONLY, FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03336 if (fnum1 == -1) {
03337 printf("[11] open of %s failed (%s)\n", fname, cli_errstr(cli1));
03338 correct = False;
03339 goto fail;
03340 }
03341
03342 if (!cli_close(cli1, fnum1)) {
03343 printf("[11] close failed (%s)\n", cli_errstr(cli1));
03344 correct = False;
03345 goto fail;
03346 }
03347
03348
03349 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES|DELETE_ACCESS,
03350 0, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
03351 FILE_OVERWRITE_IF, 0, 0);
03352
03353 if (fnum1 != -1) {
03354 printf("[11] open of %s succeeded should have been denied with ACCESS_DENIED!\n", fname);
03355 cli_close(cli1, fnum1);
03356 goto fail;
03357 correct = False;
03358 } else {
03359 NTSTATUS nterr = cli_nt_error(cli1);
03360 if (!NT_STATUS_EQUAL(nterr,NT_STATUS_ACCESS_DENIED)) {
03361 printf("[11] open of %s should have been denied with ACCESS_DENIED! Got error %s\n", fname, nt_errstr(nterr));
03362 goto fail;
03363 correct = False;
03364 } else {
03365 printf("eleventh delete on close test succeeded.\n");
03366 }
03367 }
03368
03369 printf("finished delete test\n");
03370
03371 fail:
03372
03373
03374
03375
03376 if (fnum1 != -1) cli_close(cli1, fnum1);
03377 if (fnum2 != -1) cli_close(cli1, fnum2);
03378 cli_setatr(cli1, fname, 0, 0);
03379 cli_unlink(cli1, fname);
03380
03381 if (cli1 && !torture_close_connection(cli1)) {
03382 correct = False;
03383 }
03384 if (cli2 && !torture_close_connection(cli2)) {
03385 correct = False;
03386 }
03387 return correct;
03388 }
03389
03390
03391
03392
03393
03394 static BOOL run_properties(int dummy)
03395 {
03396 static struct cli_state *cli;
03397 BOOL correct = True;
03398
03399 printf("starting properties test\n");
03400
03401 ZERO_STRUCT(cli);
03402
03403 if (!torture_open_connection(&cli, 0)) {
03404 return False;
03405 }
03406
03407 cli_sockopt(cli, sockops);
03408
03409 d_printf("Capabilities 0x%08x\n", cli->capabilities);
03410
03411 if (!torture_close_connection(cli)) {
03412 correct = False;
03413 }
03414
03415 return correct;
03416 }
03417
03418
03419
03420
03421 #define FIRST_DESIRED_ACCESS FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA|\
03422 FILE_READ_EA| \
03423 FILE_WRITE_EA|FILE_READ_ATTRIBUTES| \
03424 FILE_WRITE_ATTRIBUTES| \
03425 DELETE_ACCESS|READ_CONTROL_ACCESS|\
03426 WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS
03427
03428 #define SECOND_DESIRED_ACCESS FILE_READ_ATTRIBUTES| \
03429 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
03430 WRITE_OWNER_ACCESS
03431
03432 #if 0
03433 #define THIRD_DESIRED_ACCESS FILE_READ_ATTRIBUTES| \
03434 READ_CONTROL_ACCESS|WRITE_DAC_ACCESS|\
03435 FILE_READ_DATA|\
03436 WRITE_OWNER_ACCESS
03437 #endif
03438
03439
03440
03441
03442 static BOOL run_xcopy(int dummy)
03443 {
03444 static struct cli_state *cli1;
03445 const char *fname = "\\test.txt";
03446 BOOL correct = True;
03447 int fnum1, fnum2;
03448
03449 printf("starting xcopy test\n");
03450
03451 if (!torture_open_connection(&cli1, 0)) {
03452 return False;
03453 }
03454
03455 fnum1 = cli_nt_create_full(cli1, fname, 0,
03456 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
03457 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
03458 0x4044, 0);
03459
03460 if (fnum1 == -1) {
03461 printf("First open failed - %s\n", cli_errstr(cli1));
03462 return False;
03463 }
03464
03465 fnum2 = cli_nt_create_full(cli1, fname, 0,
03466 SECOND_DESIRED_ACCESS, 0,
03467 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, FILE_OPEN,
03468 0x200000, 0);
03469 if (fnum2 == -1) {
03470 printf("second open failed - %s\n", cli_errstr(cli1));
03471 return False;
03472 }
03473
03474 if (!torture_close_connection(cli1)) {
03475 correct = False;
03476 }
03477
03478 return correct;
03479 }
03480
03481
03482
03483
03484 static BOOL run_rename(int dummy)
03485 {
03486 static struct cli_state *cli1;
03487 const char *fname = "\\test.txt";
03488 const char *fname1 = "\\test1.txt";
03489 BOOL correct = True;
03490 int fnum1;
03491
03492 printf("starting rename test\n");
03493
03494 if (!torture_open_connection(&cli1, 0)) {
03495 return False;
03496 }
03497
03498 cli_unlink(cli1, fname);
03499 cli_unlink(cli1, fname1);
03500 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03501 FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
03502
03503 if (fnum1 == -1) {
03504 printf("First open failed - %s\n", cli_errstr(cli1));
03505 return False;
03506 }
03507
03508 if (!cli_rename(cli1, fname, fname1)) {
03509 printf("First rename failed (SHARE_READ) (this is correct) - %s\n", cli_errstr(cli1));
03510 } else {
03511 printf("First rename succeeded (SHARE_READ) - this should have failed !\n");
03512 correct = False;
03513 }
03514
03515 if (!cli_close(cli1, fnum1)) {
03516 printf("close - 1 failed (%s)\n", cli_errstr(cli1));
03517 return False;
03518 }
03519
03520 cli_unlink(cli1, fname);
03521 cli_unlink(cli1, fname1);
03522 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03523 #if 0
03524 FILE_SHARE_DELETE|FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03525 #else
03526 FILE_SHARE_DELETE|FILE_SHARE_READ, FILE_OVERWRITE_IF, 0, 0);
03527 #endif
03528
03529 if (fnum1 == -1) {
03530 printf("Second open failed - %s\n", cli_errstr(cli1));
03531 return False;
03532 }
03533
03534 if (!cli_rename(cli1, fname, fname1)) {
03535 printf("Second rename failed (SHARE_DELETE | SHARE_READ) - this should have succeeded - %s\n", cli_errstr(cli1));
03536 correct = False;
03537 } else {
03538 printf("Second rename succeeded (SHARE_DELETE | SHARE_READ)\n");
03539 }
03540
03541 if (!cli_close(cli1, fnum1)) {
03542 printf("close - 2 failed (%s)\n", cli_errstr(cli1));
03543 return False;
03544 }
03545
03546 cli_unlink(cli1, fname);
03547 cli_unlink(cli1, fname1);
03548
03549 fnum1 = cli_nt_create_full(cli1, fname, 0, READ_CONTROL_ACCESS, FILE_ATTRIBUTE_NORMAL,
03550 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03551
03552 if (fnum1 == -1) {
03553 printf("Third open failed - %s\n", cli_errstr(cli1));
03554 return False;
03555 }
03556
03557
03558 #if 0
03559 {
03560 int fnum2;
03561
03562 fnum2 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS, FILE_ATTRIBUTE_NORMAL,
03563 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03564
03565 if (fnum2 == -1) {
03566 printf("Fourth open failed - %s\n", cli_errstr(cli1));
03567 return False;
03568 }
03569 if (!cli_nt_delete_on_close(cli1, fnum2, True)) {
03570 printf("[8] setting delete_on_close on file failed !\n");
03571 return False;
03572 }
03573
03574 if (!cli_close(cli1, fnum2)) {
03575 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
03576 return False;
03577 }
03578 }
03579 #endif
03580
03581 if (!cli_rename(cli1, fname, fname1)) {
03582 printf("Third rename failed (SHARE_NONE) - this should have succeeded - %s\n", cli_errstr(cli1));
03583 correct = False;
03584 } else {
03585 printf("Third rename succeeded (SHARE_NONE)\n");
03586 }
03587
03588 if (!cli_close(cli1, fnum1)) {
03589 printf("close - 3 failed (%s)\n", cli_errstr(cli1));
03590 return False;
03591 }
03592
03593 cli_unlink(cli1, fname);
03594 cli_unlink(cli1, fname1);
03595
03596
03597
03598 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03599 FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
03600
03601 if (fnum1 == -1) {
03602 printf("Fourth open failed - %s\n", cli_errstr(cli1));
03603 return False;
03604 }
03605
03606 if (!cli_rename(cli1, fname, fname1)) {
03607 printf("Fourth rename failed (SHARE_READ | SHARE_WRITE) (this is correct) - %s\n", cli_errstr(cli1));
03608 } else {
03609 printf("Fourth rename succeeded (SHARE_READ | SHARE_WRITE) - this should have failed !\n");
03610 correct = False;
03611 }
03612
03613 if (!cli_close(cli1, fnum1)) {
03614 printf("close - 4 failed (%s)\n", cli_errstr(cli1));
03615 return False;
03616 }
03617
03618 cli_unlink(cli1, fname);
03619 cli_unlink(cli1, fname1);
03620
03621
03622
03623 fnum1 = cli_nt_create_full(cli1, fname, 0, GENERIC_READ_ACCESS, FILE_ATTRIBUTE_NORMAL,
03624 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
03625
03626 if (fnum1 == -1) {
03627 printf("Fifth open failed - %s\n", cli_errstr(cli1));
03628 return False;
03629 }
03630
03631 if (!cli_rename(cli1, fname, fname1)) {
03632 printf("Fifth rename failed (SHARE_READ | SHARE_WRITE | SHARE_DELETE) - this should have failed ! \n");
03633 correct = False;
03634 } else {
03635 printf("Fifth rename succeeded (SHARE_READ | SHARE_WRITE | SHARE_DELETE) (this is correct) - %s\n", cli_errstr(cli1));
03636 }
03637
03638
03639
03640
03641
03642
03643
03644
03645
03646
03647
03648
03649
03650
03651
03652
03653
03654
03655
03656
03657 if (!cli_close(cli1, fnum1)) {
03658 printf("close - 5 failed (%s)\n", cli_errstr(cli1));
03659 return False;
03660 }
03661
03662 cli_unlink(cli1, fname);
03663 cli_unlink(cli1, fname1);
03664
03665 if (!torture_close_connection(cli1)) {
03666 correct = False;
03667 }
03668
03669 return correct;
03670 }
03671
03672 static BOOL run_pipe_number(int dummy)
03673 {
03674 struct cli_state *cli1;
03675 const char *pipe_name = "\\SPOOLSS";
03676 int fnum;
03677 int num_pipes = 0;
03678
03679 printf("starting pipenumber test\n");
03680 if (!torture_open_connection(&cli1, 0)) {
03681 return False;
03682 }
03683
03684 cli_sockopt(cli1, sockops);
03685 while(1) {
03686 fnum = cli_nt_create_full(cli1, pipe_name, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
03687 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN_IF, 0, 0);
03688
03689 if (fnum == -1) {
03690 printf("Open of pipe %s failed with error (%s)\n", pipe_name, cli_errstr(cli1));
03691 break;
03692 }
03693 num_pipes++;
03694 printf("\r%6d", num_pipes);
03695 }
03696
03697 printf("pipe_number test - we can open %d %s pipes.\n", num_pipes, pipe_name );
03698 torture_close_connection(cli1);
03699 return True;
03700 }
03701
03702
03703
03704
03705 static BOOL run_opentest(int dummy)
03706 {
03707 static struct cli_state *cli1;
03708 static struct cli_state *cli2;
03709 const char *fname = "\\readonly.file";
03710 int fnum1, fnum2;
03711 char buf[20];
03712 SMB_OFF_T fsize;
03713 BOOL correct = True;
03714 char *tmp_path;
03715
03716 printf("starting open test\n");
03717
03718 if (!torture_open_connection(&cli1, 0)) {
03719 return False;
03720 }
03721
03722 cli_setatr(cli1, fname, 0, 0);
03723 cli_unlink(cli1, fname);
03724
03725 cli_sockopt(cli1, sockops);
03726
03727 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
03728 if (fnum1 == -1) {
03729 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
03730 return False;
03731 }
03732
03733 if (!cli_close(cli1, fnum1)) {
03734 printf("close2 failed (%s)\n", cli_errstr(cli1));
03735 return False;
03736 }
03737
03738 if (!cli_setatr(cli1, fname, aRONLY, 0)) {
03739 printf("cli_setatr failed (%s)\n", cli_errstr(cli1));
03740 return False;
03741 }
03742
03743 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
03744 if (fnum1 == -1) {
03745 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
03746 return False;
03747 }
03748
03749
03750 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
03751
03752 if (check_error(__LINE__, cli1, ERRDOS, ERRnoaccess,
03753 NT_STATUS_ACCESS_DENIED)) {
03754 printf("correct error code ERRDOS/ERRnoaccess returned\n");
03755 }
03756
03757 printf("finished open test 1\n");
03758
03759 cli_close(cli1, fnum1);
03760
03761
03762
03763 cli_setatr(cli1, fname, 0, 0);
03764
03765 fnum1 = cli_open(cli1, fname, O_RDONLY, DENY_WRITE);
03766 if (fnum1 == -1) {
03767 printf("open of %s failed (%s)\n", fname, cli_errstr(cli1));
03768 return False;
03769 }
03770
03771
03772 fnum2 = cli_open(cli1, fname, O_RDWR, DENY_ALL);
03773
03774 if (check_error(__LINE__, cli1, ERRDOS, ERRbadshare,
03775 NT_STATUS_SHARING_VIOLATION)) {
03776 printf("correct error code ERRDOS/ERRbadshare returned\n");
03777 }
03778
03779 if (!cli_close(cli1, fnum1)) {
03780 printf("close2 failed (%s)\n", cli_errstr(cli1));
03781 return False;
03782 }
03783
03784 cli_unlink(cli1, fname);
03785
03786 printf("finished open test 2\n");
03787
03788
03789
03790 fnum1 = cli_open(cli1, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
03791 if (fnum1 == -1) {
03792 printf("(3) open (1) of %s failed (%s)\n", fname, cli_errstr(cli1));
03793 return False;
03794 }
03795
03796
03797
03798 memset(buf, '\0', 20);
03799
03800 if (cli_write(cli1, fnum1, 0, buf, 0, 20) != 20) {
03801 printf("write failed (%s)\n", cli_errstr(cli1));
03802 correct = False;
03803 }
03804
03805 if (!cli_close(cli1, fnum1)) {
03806 printf("(3) close1 failed (%s)\n", cli_errstr(cli1));
03807 return False;
03808 }
03809
03810
03811 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
03812 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
03813 return False;
03814 }
03815
03816 if (fsize != 20) {
03817 printf("(3) file size != 20\n");
03818 return False;
03819 }
03820
03821
03822
03823 fnum1 = cli_open(cli1, fname, O_RDONLY|O_TRUNC, DENY_NONE);
03824 if (fnum1 == -1) {
03825 printf("(3) open (2) of %s failed (%s)\n", fname, cli_errstr(cli1));
03826 return False;
03827 }
03828
03829 if (!cli_close(cli1, fnum1)) {
03830 printf("close2 failed (%s)\n", cli_errstr(cli1));
03831 return False;
03832 }
03833
03834
03835 if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
03836 printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
03837 return False;
03838 }
03839
03840 if (fsize != 0) {
03841 printf("(3) file size != 0\n");
03842 return False;
03843 }
03844 printf("finished open test 3\n");
03845
03846 cli_unlink(cli1, fname);
03847
03848
03849 printf("testing ctemp\n");
03850 fnum1 = cli_ctemp(cli1, "\\", &tmp_path);
03851 if (fnum1 == -1) {
03852 printf("ctemp failed (%s)\n", cli_errstr(cli1));
03853 return False;
03854 }
03855 printf("ctemp gave path %s\n", tmp_path);
03856 if (!cli_close(cli1, fnum1)) {
03857 printf("close of temp failed (%s)\n", cli_errstr(cli1));
03858 }
03859 if (!cli_unlink(cli1, tmp_path)) {
03860 printf("unlink of temp failed (%s)\n", cli_errstr(cli1));
03861 }
03862
03863
03864
03865 if (!torture_open_connection(&cli2, 1)) {
03866 return False;
03867 }
03868
03869 cli_setatr(cli2, fname, 0, 0);
03870 cli_unlink(cli2, fname);
03871
03872 cli_sockopt(cli2, sockops);
03873
03874 printf("TEST #1 testing 2 non-io opens (no delete)\n");
03875
03876 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03877 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03878
03879 if (fnum1 == -1) {
03880 printf("test 1 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03881 return False;
03882 }
03883
03884 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03885 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
03886
03887 if (fnum2 == -1) {
03888 printf("test 1 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03889 return False;
03890 }
03891
03892 if (!cli_close(cli1, fnum1)) {
03893 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03894 return False;
03895 }
03896 if (!cli_close(cli2, fnum2)) {
03897 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03898 return False;
03899 }
03900
03901 printf("non-io open test #1 passed.\n");
03902
03903 cli_unlink(cli1, fname);
03904
03905 printf("TEST #2 testing 2 non-io opens (first with delete)\n");
03906
03907 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03908 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03909
03910 if (fnum1 == -1) {
03911 printf("test 2 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03912 return False;
03913 }
03914
03915 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03916 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
03917
03918 if (fnum2 == -1) {
03919 printf("test 2 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03920 return False;
03921 }
03922
03923 if (!cli_close(cli1, fnum1)) {
03924 printf("test 1 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03925 return False;
03926 }
03927 if (!cli_close(cli2, fnum2)) {
03928 printf("test 1 close 2 of %s failed (%s)\n", fname, cli_errstr(cli1));
03929 return False;
03930 }
03931
03932 printf("non-io open test #2 passed.\n");
03933
03934 cli_unlink(cli1, fname);
03935
03936 printf("TEST #3 testing 2 non-io opens (second with delete)\n");
03937
03938 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03939 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03940
03941 if (fnum1 == -1) {
03942 printf("test 3 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03943 return False;
03944 }
03945
03946 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03947 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
03948
03949 if (fnum2 == -1) {
03950 printf("test 3 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03951 return False;
03952 }
03953
03954 if (!cli_close(cli1, fnum1)) {
03955 printf("test 3 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03956 return False;
03957 }
03958 if (!cli_close(cli2, fnum2)) {
03959 printf("test 3 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
03960 return False;
03961 }
03962
03963 printf("non-io open test #3 passed.\n");
03964
03965 cli_unlink(cli1, fname);
03966
03967 printf("TEST #4 testing 2 non-io opens (both with delete)\n");
03968
03969 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03970 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
03971
03972 if (fnum1 == -1) {
03973 printf("test 4 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03974 return False;
03975 }
03976
03977 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03978 FILE_SHARE_NONE, FILE_OPEN_IF, 0, 0);
03979
03980 if (fnum2 != -1) {
03981 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
03982 return False;
03983 }
03984
03985 printf("test 3 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
03986
03987 if (!cli_close(cli1, fnum1)) {
03988 printf("test 4 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
03989 return False;
03990 }
03991
03992 printf("non-io open test #4 passed.\n");
03993
03994 cli_unlink(cli1, fname);
03995
03996 printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
03997
03998 fnum1 = cli_nt_create_full(cli1, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
03999 FILE_SHARE_DELETE, FILE_OVERWRITE_IF, 0, 0);
04000
04001 if (fnum1 == -1) {
04002 printf("test 5 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04003 return False;
04004 }
04005
04006 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
04007 FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
04008
04009 if (fnum2 == -1) {
04010 printf("test 5 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
04011 return False;
04012 }
04013
04014 if (!cli_close(cli1, fnum1)) {
04015 printf("test 5 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04016 return False;
04017 }
04018
04019 if (!cli_close(cli2, fnum2)) {
04020 printf("test 5 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
04021 return False;
04022 }
04023
04024 printf("non-io open test #5 passed.\n");
04025
04026 printf("TEST #6 testing 1 non-io open, one io open\n");
04027
04028 cli_unlink(cli1, fname);
04029
04030 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
04031 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
04032
04033 if (fnum1 == -1) {
04034 printf("test 6 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04035 return False;
04036 }
04037
04038 fnum2 = cli_nt_create_full(cli2, fname, 0, FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
04039 FILE_SHARE_READ, FILE_OPEN_IF, 0, 0);
04040
04041 if (fnum2 == -1) {
04042 printf("test 6 open 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
04043 return False;
04044 }
04045
04046 if (!cli_close(cli1, fnum1)) {
04047 printf("test 6 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04048 return False;
04049 }
04050
04051 if (!cli_close(cli2, fnum2)) {
04052 printf("test 6 close 2 of %s failed (%s)\n", fname, cli_errstr(cli2));
04053 return False;
04054 }
04055
04056 printf("non-io open test #6 passed.\n");
04057
04058 printf("TEST #7 testing 1 non-io open, one io open with delete\n");
04059
04060 cli_unlink(cli1, fname);
04061
04062 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
04063 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
04064
04065 if (fnum1 == -1) {
04066 printf("test 7 open 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04067 return False;
04068 }
04069
04070 fnum2 = cli_nt_create_full(cli2, fname, 0, DELETE_ACCESS|FILE_READ_ATTRIBUTES, FILE_ATTRIBUTE_NORMAL,
04071 FILE_SHARE_READ|FILE_SHARE_DELETE, FILE_OPEN_IF, 0, 0);
04072
04073 if (fnum2 != -1) {
04074 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, cli_errstr(cli2));
04075 return False;
04076 }
04077
04078 printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, cli_errstr(cli2), "sharing violation");
04079
04080 if (!cli_close(cli1, fnum1)) {
04081 printf("test 7 close 1 of %s failed (%s)\n", fname, cli_errstr(cli1));
04082 return False;
04083 }
04084
04085 printf("non-io open test #7 passed.\n");
04086
04087 cli_unlink(cli1, fname);
04088
04089 if (!torture_close_connection(cli1)) {
04090 correct = False;
04091 }
04092 if (!torture_close_connection(cli2)) {
04093 correct = False;
04094 }
04095
04096 return correct;
04097 }
04098
04099 static uint32 open_attrs_table[] = {
04100 FILE_ATTRIBUTE_NORMAL,
04101 FILE_ATTRIBUTE_ARCHIVE,
04102 FILE_ATTRIBUTE_READONLY,
04103 FILE_ATTRIBUTE_HIDDEN,
04104 FILE_ATTRIBUTE_SYSTEM,
04105
04106 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY,
04107 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN,
04108 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM,
04109 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
04110 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
04111 FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
04112
04113 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN,
04114 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM,
04115 FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM,
04116 FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,
04117 };
04118
04119 struct trunc_open_results {
04120 unsigned int num;
04121 uint32 init_attr;
04122 uint32 trunc_attr;
04123 uint32 result_attr;
04124 };
04125
04126 static struct trunc_open_results attr_results[] = {
04127 { 0, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
04128 { 1, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
04129 { 2, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
04130 { 16, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_NORMAL, FILE_ATTRIBUTE_ARCHIVE },
04131 { 17, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_ARCHIVE },
04132 { 18, FILE_ATTRIBUTE_ARCHIVE, FILE_ATTRIBUTE_READONLY, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY },
04133 { 51, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04134 { 54, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04135 { 56, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
04136 { 68, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04137 { 71, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04138 { 73, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
04139 { 99, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04140 { 102, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04141 { 104, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
04142 { 116, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04143 { 119, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04144 { 121, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM },
04145 { 170, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN },
04146 { 173, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM },
04147 { 227, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04148 { 230, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN },
04149 { 232, FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN },
04150 { 244, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04151 { 247, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_SYSTEM },
04152 { 249, FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_SYSTEM }
04153 };
04154
04155 static BOOL run_openattrtest(int dummy)
04156 {
04157 static struct cli_state *cli1;
04158 const char *fname = "\\openattr.file";
04159 int fnum1;
04160 BOOL correct = True;
04161 uint16 attr;
04162 unsigned int i, j, k, l;
04163
04164 printf("starting open attr test\n");
04165
04166 if (!torture_open_connection(&cli1, 0)) {
04167 return False;
04168 }
04169
04170 cli_sockopt(cli1, sockops);
04171
04172 for (k = 0, i = 0; i < sizeof(open_attrs_table)/sizeof(uint32); i++) {
04173 cli_setatr(cli1, fname, 0, 0);
04174 cli_unlink(cli1, fname);
04175 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_WRITE_DATA, open_attrs_table[i],
04176 FILE_SHARE_NONE, FILE_OVERWRITE_IF, 0, 0);
04177
04178 if (fnum1 == -1) {
04179 printf("open %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
04180 return False;
04181 }
04182
04183 if (!cli_close(cli1, fnum1)) {
04184 printf("close %d (1) of %s failed (%s)\n", i, fname, cli_errstr(cli1));
04185 return False;
04186 }
04187
04188 for (j = 0; j < sizeof(open_attrs_table)/sizeof(uint32); j++) {
04189 fnum1 = cli_nt_create_full(cli1, fname, 0, FILE_READ_DATA|FILE_WRITE_DATA, open_attrs_table[j],
04190 FILE_SHARE_NONE, FILE_OVERWRITE, 0, 0);
04191
04192 if (fnum1 == -1) {
04193 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
04194 if (attr_results[l].num == k) {
04195 printf("[%d] trunc open 0x%x -> 0x%x of %s failed - should have succeeded !(0x%x:%s)\n",
04196 k, open_attrs_table[i],
04197 open_attrs_table[j],
04198 fname, NT_STATUS_V(cli_nt_error(cli1)), cli_errstr(cli1));
04199 correct = False;
04200 }
04201 }
04202 if (NT_STATUS_V(cli_nt_error(cli1)) != NT_STATUS_V(NT_STATUS_ACCESS_DENIED)) {
04203 printf("[%d] trunc open 0x%x -> 0x%x failed with wrong error code %s\n",
04204 k, open_attrs_table[i], open_attrs_table[j],
04205 cli_errstr(cli1));
04206 correct = False;
04207 }
04208 #if 0
04209 printf("[%d] trunc open 0x%x -> 0x%x failed\n", k, open_attrs_table[i], open_attrs_table[j]);
04210 #endif
04211 k++;
04212 continue;
04213 }
04214
04215 if (!cli_close(cli1, fnum1)) {
04216 printf("close %d (2) of %s failed (%s)\n", j, fname, cli_errstr(cli1));
04217 return False;
04218 }
04219
04220 if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
04221 printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
04222 return False;
04223 }
04224
04225 #if 0
04226 printf("[%d] getatr check [0x%x] trunc [0x%x] got attr 0x%x\n",
04227 k, open_attrs_table[i], open_attrs_table[j], attr );
04228 #endif
04229
04230 for (l = 0; l < sizeof(attr_results)/sizeof(struct trunc_open_results); l++) {
04231 if (attr_results[l].num == k) {
04232 if (attr != attr_results[l].result_attr ||
04233 open_attrs_table[i] != attr_results[l].init_attr ||
04234 open_attrs_table[j] != attr_results[l].trunc_attr) {
04235 printf("getatr check failed. [0x%x] trunc [0x%x] got attr 0x%x, should be 0x%x\n",
04236 open_attrs_table[i],
04237 open_attrs_table[j],
04238 (unsigned int)attr,
04239 attr_results[l].result_attr);
04240 correct = False;
04241 }
04242 break;
04243 }
04244 }
04245 k++;
04246 }
04247 }
04248
04249 cli_setatr(cli1, fname, 0, 0);
04250 cli_unlink(cli1, fname);
04251
04252 printf("open attr test %s.\n", correct ? "passed" : "failed");
04253
04254 if (!torture_close_connection(cli1)) {
04255 correct = False;
04256 }
04257 return correct;
04258 }
04259
04260 static void list_fn(const char *mnt, file_info *finfo, const char *name, void *state)
04261 {
04262
04263 }
04264
04265
04266
04267
04268 static BOOL run_dirtest(int dummy)
04269 {
04270 int i;
04271 static struct cli_state *cli;
04272 int fnum;
04273 double t1;
04274 BOOL correct = True;
04275
04276 printf("starting directory test\n");
04277
04278 if (!torture_open_connection(&cli, 0)) {
04279 return False;
04280 }
04281
04282 cli_sockopt(cli, sockops);
04283
04284 srandom(0);
04285 for (i=0;i<torture_numops;i++) {
04286 fstring fname;
04287 slprintf(fname, sizeof(fname), "\\%x", (int)random());
04288 fnum = cli_open(cli, fname, O_RDWR|O_CREAT, DENY_NONE);
04289 if (fnum == -1) {
04290 fprintf(stderr,"Failed to open %s\n", fname);
04291 return False;
04292 }
04293 cli_close(cli, fnum);
04294 }
04295
04296 t1 = end_timer();
04297
04298 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
04299 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
04300 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
04301
04302 printf("dirtest core %g seconds\n", end_timer() - t1);
04303
04304 srandom(0);
04305 for (i=0;i<torture_numops;i++) {
04306 fstring fname;
04307 slprintf(fname, sizeof(fname), "\\%x", (int)random());
04308 cli_unlink(cli, fname);
04309 }
04310
04311 if (!torture_close_connection(cli)) {
04312 correct = False;
04313 }
04314
04315 printf("finished dirtest\n");
04316
04317 return correct;
04318 }
04319
04320 static void del_fn(const char *mnt, file_info *finfo, const char *mask, void *state)
04321 {
04322 struct cli_state *pcli = (struct cli_state *)state;
04323 fstring fname;
04324 slprintf(fname, sizeof(fname), "\\LISTDIR\\%s", finfo->name);
04325
04326 if (strcmp(finfo->name, ".") == 0 || strcmp(finfo->name, "..") == 0)
04327 return;
04328
04329 if (finfo->mode & aDIR) {
04330 if (!cli_rmdir(pcli, fname))
04331 printf("del_fn: failed to rmdir %s\n,", fname );
04332 } else {
04333 if (!cli_unlink(pcli, fname))
04334 printf("del_fn: failed to unlink %s\n,", fname );
04335 }
04336 }
04337
04338
04339
04340
04341
04342 BOOL torture_ioctl_test(int dummy)
04343 {
04344 static struct cli_state *cli;
04345 uint16 device, function;
04346 int fnum;
04347 const char *fname = "\\ioctl.dat";
04348 DATA_BLOB blob;
04349 NTSTATUS status;
04350
04351 if (!torture_open_connection(&cli, 0)) {
04352 return False;
04353 }
04354
04355 printf("starting ioctl test\n");
04356
04357 cli_unlink(cli, fname);
04358
04359 fnum = cli_open(cli, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
04360 if (fnum == -1) {
04361 printf("open of %s failed (%s)\n", fname, cli_errstr(cli));
04362 return False;
04363 }
04364
04365 status = cli_raw_ioctl(cli, fnum, 0x2d0000 | (0x0420<<2), &blob);
04366 printf("ioctl device info: %s\n", cli_errstr(cli));
04367
04368 status = cli_raw_ioctl(cli, fnum, IOCTL_QUERY_JOB_INFO, &blob);
04369 printf("ioctl job info: %s\n", cli_errstr(cli));
04370
04371 for (device=0;device<0x100;device++) {
04372 printf("testing device=0x%x\n", device);
04373 for (function=0;function<0x100;function++) {
04374 uint32 code = (device<<16) | function;
04375
04376 status = cli_raw_ioctl(cli, fnum, code, &blob);
04377
04378 if (NT_STATUS_IS_OK(status)) {
04379 printf("ioctl 0x%x OK : %d bytes\n", (int)code,
04380 (int)blob.length);
04381 data_blob_free(&blob);
04382 }
04383 }
04384 }
04385
04386 if (!torture_close_connection(cli)) {
04387 return False;
04388 }
04389
04390 return True;
04391 }
04392
04393
04394
04395
04396
04397 BOOL torture_chkpath_test(int dummy)
04398 {
04399 static struct cli_state *cli;
04400 int fnum;
04401 BOOL ret;
04402
04403 if (!torture_open_connection(&cli, 0)) {
04404 return False;
04405 }
04406
04407 printf("starting chkpath test\n");
04408
04409
04410 cli_rmdir(cli, "\\chkpath.dir\\dir2");
04411 cli_unlink(cli, "\\chkpath.dir\\*");
04412 cli_rmdir(cli, "\\chkpath.dir");
04413
04414 if (!cli_mkdir(cli, "\\chkpath.dir")) {
04415 printf("mkdir1 failed : %s\n", cli_errstr(cli));
04416 return False;
04417 }
04418
04419 if (!cli_mkdir(cli, "\\chkpath.dir\\dir2")) {
04420 printf("mkdir2 failed : %s\n", cli_errstr(cli));
04421 return False;
04422 }
04423
04424 fnum = cli_open(cli, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
04425 if (fnum == -1) {
04426 printf("open1 failed (%s)\n", cli_errstr(cli));
04427 return False;
04428 }
04429 cli_close(cli, fnum);
04430
04431 if (!cli_chkpath(cli, "\\chkpath.dir")) {
04432 printf("chkpath1 failed: %s\n", cli_errstr(cli));
04433 ret = False;
04434 }
04435
04436 if (!cli_chkpath(cli, "\\chkpath.dir\\dir2")) {
04437 printf("chkpath2 failed: %s\n", cli_errstr(cli));
04438 ret = False;
04439 }
04440
04441 if (!cli_chkpath(cli, "\\chkpath.dir\\foo.txt")) {
04442 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
04443 NT_STATUS_NOT_A_DIRECTORY);
04444 } else {
04445 printf("* chkpath on a file should fail\n");
04446 ret = False;
04447 }
04448
04449 if (!cli_chkpath(cli, "\\chkpath.dir\\bar.txt")) {
04450 ret = check_error(__LINE__, cli, ERRDOS, ERRbadfile,
04451 NT_STATUS_OBJECT_NAME_NOT_FOUND);
04452 } else {
04453 printf("* chkpath on a non existant file should fail\n");
04454 ret = False;
04455 }
04456
04457 if (!cli_chkpath(cli, "\\chkpath.dir\\dirxx\\bar.txt")) {
04458 ret = check_error(__LINE__, cli, ERRDOS, ERRbadpath,
04459 NT_STATUS_OBJECT_PATH_NOT_FOUND);
04460 } else {
04461 printf("* chkpath on a non existent component should fail\n");
04462 ret = False;
04463 }
04464
04465 cli_rmdir(cli, "\\chkpath.dir\\dir2");
04466 cli_unlink(cli, "\\chkpath.dir\\*");
04467 cli_rmdir(cli, "\\chkpath.dir");
04468
04469 if (!torture_close_connection(cli)) {
04470 return False;
04471 }
04472
04473 return ret;
04474 }
04475
04476 static BOOL run_eatest(int dummy)
04477 {
04478 static struct cli_state *cli;
04479 const char *fname = "\\eatest.txt";
04480 BOOL correct = True;
04481 int fnum, i;
04482 size_t num_eas;
04483 struct ea_struct *ea_list = NULL;
04484 TALLOC_CTX *mem_ctx = talloc_init("eatest");
04485
04486 printf("starting eatest\n");
04487
04488 if (!torture_open_connection(&cli, 0)) {
04489 talloc_destroy(mem_ctx);
04490 return False;
04491 }
04492
04493 cli_unlink(cli, fname);
04494 fnum = cli_nt_create_full(cli, fname, 0,
04495 FIRST_DESIRED_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
04496 FILE_SHARE_NONE, FILE_OVERWRITE_IF,
04497 0x4044, 0);
04498
04499 if (fnum == -1) {
04500 printf("open failed - %s\n", cli_errstr(cli));
04501 talloc_destroy(mem_ctx);
04502 return False;
04503 }
04504
04505 for (i = 0; i < 10; i++) {
04506 fstring ea_name, ea_val;
04507
04508 slprintf(ea_name, sizeof(ea_name), "EA_%d", i);
04509 memset(ea_val, (char)i+1, i+1);
04510 if (!cli_set_ea_fnum(cli, fnum, ea_name, ea_val, i+1)) {
04511 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
04512 talloc_destroy(mem_ctx);
04513 return False;
04514 }
04515 }
04516
04517 cli_close(cli, fnum);
04518 for (i = 0; i < 10; i++) {
04519 fstring ea_name, ea_val;
04520
04521 slprintf(ea_name, sizeof(ea_name), "EA_%d", i+10);
04522 memset(ea_val, (char)i+1, i+1);
04523 if (!cli_set_ea_path(cli, fname, ea_name, ea_val, i+1)) {
04524 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
04525 talloc_destroy(mem_ctx);
04526 return False;
04527 }
04528 }
04529
04530 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
04531 printf("ea_get list failed - %s\n", cli_errstr(cli));
04532 correct = False;
04533 }
04534
04535 printf("num_eas = %d\n", (int)num_eas);
04536
04537 if (num_eas != 20) {
04538 printf("Should be 20 EA's stored... failing.\n");
04539 correct = False;
04540 }
04541
04542 for (i = 0; i < num_eas; i++) {
04543 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
04544 dump_data(0, (char *)ea_list[i].value.data,
04545 ea_list[i].value.length);
04546 }
04547
04548
04549 printf("Now deleting all EA's - case indepenent....\n");
04550
04551 #if 1
04552 cli_set_ea_path(cli, fname, "", "", 0);
04553 #else
04554 for (i = 0; i < 20; i++) {
04555 fstring ea_name;
04556 slprintf(ea_name, sizeof(ea_name), "ea_%d", i);
04557 if (!cli_set_ea_path(cli, fname, ea_name, "", 0)) {
04558 printf("ea_set of name %s failed - %s\n", ea_name, cli_errstr(cli));
04559 talloc_destroy(mem_ctx);
04560 return False;
04561 }
04562 }
04563 #endif
04564
04565 if (!cli_get_ea_list_path(cli, fname, mem_ctx, &num_eas, &ea_list)) {
04566 printf("ea_get list failed - %s\n", cli_errstr(cli));
04567 correct = False;
04568 }
04569
04570 printf("num_eas = %d\n", (int)num_eas);
04571 for (i = 0; i < num_eas; i++) {
04572 printf("%d: ea_name = %s. Val = ", i, ea_list[i].name);
04573 dump_data(0, (char *)ea_list[i].value.data,
04574 ea_list[i].value.length);
04575 }
04576
04577 if (num_eas != 0) {
04578 printf("deleting EA's failed.\n");
04579 correct = False;
04580 }
04581
04582
04583 if (!cli_set_ea_path(cli, fname, "foo", "", 0)) {
04584 printf("deleting non-existant EA 'foo' should succeed. %s\n", cli_errstr(cli));
04585 correct = False;
04586 }
04587
04588 talloc_destroy(mem_ctx);
04589 if (!torture_close_connection(cli)) {
04590 correct = False;
04591 }
04592
04593 return correct;
04594 }
04595
04596 static BOOL run_dirtest1(int dummy)
04597 {
04598 int i;
04599 static struct cli_state *cli;
04600 int fnum, num_seen;
04601 BOOL correct = True;
04602
04603 printf("starting directory test\n");
04604
04605 if (!torture_open_connection(&cli, 0)) {
04606 return False;
04607 }
04608
04609 cli_sockopt(cli, sockops);
04610
04611 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
04612 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
04613 cli_rmdir(cli, "\\LISTDIR");
04614 cli_mkdir(cli, "\\LISTDIR");
04615
04616
04617 for (i=0;i<1000;i++) {
04618 fstring fname;
04619 slprintf(fname, sizeof(fname), "\\LISTDIR\\f%d", i);
04620 fnum = cli_nt_create_full(cli, fname, 0, GENERIC_ALL_ACCESS, FILE_ATTRIBUTE_ARCHIVE,
04621 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OVERWRITE_IF, 0, 0);
04622 if (fnum == -1) {
04623 fprintf(stderr,"Failed to open %s\n", fname);
04624 return False;
04625 }
04626 cli_close(cli, fnum);
04627 }
04628 for (i=0;i<1000;i++) {
04629 fstring fname;
04630 slprintf(fname, sizeof(fname), "\\LISTDIR\\d%d", i);
04631 if (!cli_mkdir(cli, fname)) {
04632 fprintf(stderr,"Failed to open %s\n", fname);
04633 return False;
04634 }
04635 }
04636
04637
04638 num_seen = cli_list_old(cli, "\\LISTDIR\\*", aDIR, list_fn, NULL);
04639 printf("num_seen = %d\n", num_seen );
04640
04641 if (num_seen != 2002)
04642 correct = False;
04643
04644
04645
04646
04647 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aDIR<<8)|aDIR, list_fn, NULL);
04648 printf("num_seen = %d\n", num_seen );
04649 if (num_seen != 1002)
04650 correct = False;
04651
04652 num_seen = cli_list_old(cli, "\\LISTDIR\\*", (aARCH<<8)|aDIR, list_fn, NULL);
04653 printf("num_seen = %d\n", num_seen );
04654 if (num_seen != 1000)
04655 correct = False;
04656
04657
04658 cli_list(cli, "\\LISTDIR\\*", 0, del_fn, cli);
04659 cli_list(cli, "\\LISTDIR\\*", aDIR, del_fn, cli);
04660 cli_rmdir(cli, "\\LISTDIR");
04661
04662 #if 0
04663 printf("Matched %d\n", cli_list(cli, "a*.*", 0, list_fn, NULL));
04664 printf("Matched %d\n", cli_list(cli, "b*.*", 0, list_fn, NULL));
04665 printf("Matched %d\n", cli_list(cli, "xyzabc", 0, list_fn, NULL));
04666 #endif
04667
04668 if (!torture_close_connection(cli)) {
04669 correct = False;
04670 }
04671
04672 printf("finished dirtest1\n");
04673
04674 return correct;
04675 }
04676
04677 static BOOL run_error_map_extract(int dummy) {
04678
04679 static struct cli_state *c_dos;
04680 static struct cli_state *c_nt;
04681
04682 uint32 error;
04683
04684 uint32 flgs2, errnum;
04685 uint8 errclass;
04686
04687 NTSTATUS nt_status;
04688
04689 fstring user;
04690
04691
04692
04693 if (!(c_nt = open_nbt_connection())) {
04694 return False;
04695 }
04696
04697 c_nt->use_spnego = False;
04698
04699 if (!cli_negprot(c_nt)) {
04700 printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
04701 cli_shutdown(c_nt);
04702 return False;
04703 }
04704
04705 if (!NT_STATUS_IS_OK(cli_session_setup(c_nt, "", "", 0, "", 0,
04706 workgroup))) {
04707 printf("%s rejected the NT-error initial session setup (%s)\n",host, cli_errstr(c_nt));
04708 return False;
04709 }
04710
04711
04712
04713 if (!(c_dos = open_nbt_connection())) {
04714 return False;
04715 }
04716
04717 c_dos->use_spnego = False;
04718 c_dos->force_dos_errors = True;
04719
04720 if (!cli_negprot(c_dos)) {
04721 printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
04722 cli_shutdown(c_dos);
04723 return False;
04724 }
04725
04726 if (!NT_STATUS_IS_OK(cli_session_setup(c_dos, "", "", 0, "", 0,
04727 workgroup))) {
04728 printf("%s rejected the DOS-error initial session setup (%s)\n",host, cli_errstr(c_dos));
04729 return False;
04730 }
04731
04732 for (error=(0xc0000000 | 0x1); error < (0xc0000000| 0xFFF); error++) {
04733 fstr_sprintf(user, "%X", error);
04734
04735 if (NT_STATUS_IS_OK(cli_session_setup(c_nt, user,
04736 password, strlen(password),
04737 password, strlen(password),
04738 workgroup))) {
04739 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
04740 }
04741
04742 flgs2 = SVAL(c_nt->inbuf,smb_flg2);
04743
04744
04745 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
04746 nt_status = NT_STATUS(IVAL(c_nt->inbuf,smb_rcls));
04747 } else {
04748 printf("/** Dos error on NT connection! (%s) */\n",
04749 cli_errstr(c_nt));
04750 nt_status = NT_STATUS(0xc0000000);
04751 }
04752
04753 if (NT_STATUS_IS_OK(cli_session_setup(c_dos, user,
04754 password, strlen(password),
04755 password, strlen(password),
04756 workgroup))) {
04757 printf("/** Session setup succeeded. This shouldn't happen...*/\n");
04758 }
04759 flgs2 = SVAL(c_dos->inbuf,smb_flg2), errnum;
04760
04761
04762 if (flgs2 & FLAGS2_32_BIT_ERROR_CODES) {
04763 printf("/** NT error on DOS connection! (%s) */\n",
04764 cli_errstr(c_nt));
04765 errnum = errclass = 0;
04766 } else {
04767 cli_dos_error(c_dos, &errclass, &errnum);
04768 }
04769
04770 if (NT_STATUS_V(nt_status) != error) {
04771 printf("/*\t{ This NT error code was 'sqashed'\n\t from %s to %s \n\t during the session setup }\n*/\n",
04772 get_nt_error_c_code(NT_STATUS(error)),
04773 get_nt_error_c_code(nt_status));
04774 }
04775
04776 printf("\t{%s,\t%s,\t%s},\n",
04777 smb_dos_err_class(errclass),
04778 smb_dos_err_name(errclass, errnum),
04779 get_nt_error_c_code(NT_STATUS(error)));
04780 }
04781 return True;
04782 }
04783
04784 static BOOL run_sesssetup_bench(int dummy)
04785 {
04786 static struct cli_state *c;
04787 NTSTATUS status;
04788 int i;
04789
04790 if (!(c = open_nbt_connection())) {
04791 return false;
04792 }
04793
04794 if (!cli_negprot(c)) {
04795 printf("%s rejected the NT-error negprot (%s)\n", host,
04796 cli_errstr(c));
04797 cli_shutdown(c);
04798 return false;
04799 }
04800
04801 for (i=0; i<torture_numops; i++) {
04802 status = cli_session_setup(
04803 c, username,
04804 password, strlen(password),
04805 password, strlen(password),
04806 workgroup);
04807 if (!NT_STATUS_IS_OK(status)) {
04808 d_printf("(%s) cli_session_setup failed: %s\n",
04809 __location__, nt_errstr(status));
04810 return false;
04811 }
04812
04813 if (!cli_ulogoff(c)) {
04814 d_printf("(%s) cli_ulogoff failed: %s\n",
04815 __location__, cli_errstr(c));
04816 return false;
04817 }
04818
04819 c->vuid = 0;
04820 }
04821
04822 return True;
04823 }
04824
04825 static BOOL run_local_substitute(int dummy)
04826 {
04827 TALLOC_CTX *mem_ctx;
04828 int diff = 0;
04829
04830 if ((mem_ctx = talloc_init("run_local_subst")) == NULL) {
04831 printf("talloc_init failed\n");
04832 return False;
04833 }
04834
04835 diff |= strcmp(talloc_sub_specified(mem_ctx, "%U", "bla", "", -1, -1),
04836 "bla");
04837 diff |= strcmp(talloc_sub_specified(mem_ctx, "%u%U", "bla", "", -1, -1),
04838 "blabla");
04839 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, -1),
04840 "NO_GROUP");
04841 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, -1),
04842 "NO_GROUP");
04843 diff |= strcmp(talloc_sub_specified(mem_ctx, "%g", "", "", -1, 0),
04844 gidtoname(0));
04845 diff |= strcmp(talloc_sub_specified(mem_ctx, "%G", "", "", -1, 0),
04846 gidtoname(0));
04847 diff |= strcmp(talloc_sub_specified(mem_ctx, "%D%u", "u", "dom", -1, 0),
04848 "domu");
04849 diff |= strcmp(talloc_sub_specified(mem_ctx, "%i %I", "", "", -1, -1),
04850 "0.0.0.0 0.0.0.0");
04851
04852
04853
04854 diff |= strcmp(talloc_sub_basic(mem_ctx, "BLA", "dom", "%U%D"),
04855 "blaDOM");
04856
04857 TALLOC_FREE(mem_ctx);
04858 return (diff == 0);
04859 }
04860
04861 static BOOL run_local_gencache(int dummy)
04862 {
04863 char *val;
04864 time_t tm;
04865
04866 if (!gencache_init()) {
04867 d_printf("%s: gencache_init() failed\n", __location__);
04868 return False;
04869 }
04870
04871 if (!gencache_set("foo", "bar", time(NULL) + 1000)) {
04872 d_printf("%s: gencache_set() failed\n", __location__);
04873 return False;
04874 }
04875
04876 if (!gencache_get("foo", &val, &tm)) {
04877 d_printf("%s: gencache_get() failed\n", __location__);
04878 return False;
04879 }
04880
04881 if (strcmp(val, "bar") != 0) {
04882 d_printf("%s: gencache_get() returned %s, expected %s\n",
04883 __location__, val, "bar");
04884 SAFE_FREE(val);
04885 return False;
04886 }
04887
04888 SAFE_FREE(val);
04889
04890 if (!gencache_del("foo")) {
04891 d_printf("%s: gencache_del() failed\n", __location__);
04892 return False;
04893 }
04894 if (gencache_del("foo")) {
04895 d_printf("%s: second gencache_del() succeeded\n",
04896 __location__);
04897 return False;
04898 }
04899
04900 if (gencache_get("foo", &val, &tm)) {
04901 d_printf("%s: gencache_get() on deleted entry "
04902 "succeeded\n", __location__);
04903 return False;
04904 }
04905
04906 if (!gencache_shutdown()) {
04907 d_printf("%s: gencache_shutdown() failed\n", __location__);
04908 return False;
04909 }
04910
04911 if (gencache_shutdown()) {
04912 d_printf("%s: second gencache_shutdown() succeeded\n",
04913 __location__);
04914 return False;
04915 }
04916
04917 return True;
04918 }
04919
04920 static double create_procs(BOOL (*fn)(int), BOOL *result)
04921 {
04922 int i, status;
04923 volatile pid_t *child_status;
04924 volatile BOOL *child_status_out;
04925 int synccount;
04926 int tries = 8;
04927
04928 synccount = 0;
04929
04930 child_status = (volatile pid_t *)shm_setup(sizeof(pid_t)*nprocs);
04931 if (!child_status) {
04932 printf("Failed to setup shared memory\n");
04933 return -1;
04934 }
04935
04936 child_status_out = (volatile BOOL *)shm_setup(sizeof(BOOL)*nprocs);
04937 if (!child_status_out) {
04938 printf("Failed to setup result status shared memory\n");
04939 return -1;
04940 }
04941
04942 for (i = 0; i < nprocs; i++) {
04943 child_status[i] = 0;
04944 child_status_out[i] = True;
04945 }
04946
04947 start_timer();
04948
04949 for (i=0;i<nprocs;i++) {
04950 procnum = i;
04951 if (fork() == 0) {
04952 pid_t mypid = getpid();
04953 sys_srandom(((int)mypid) ^ ((int)time(NULL)));
04954
04955 slprintf(myname,sizeof(myname),"CLIENT%d", i);
04956
04957 while (1) {
04958 if (torture_open_connection(¤t_cli, i)) break;
04959 if (tries-- == 0) {
04960 printf("pid %d failed to start\n", (int)getpid());
04961 _exit(1);
04962 }
04963 smb_msleep(10);
04964 }
04965
04966 child_status[i] = getpid();
04967
04968 while (child_status[i] && end_timer() < 5) smb_msleep(2);
04969
04970 child_status_out[i] = fn(i);
04971 _exit(0);
04972 }
04973 }
04974
04975 do {
04976 synccount = 0;
04977 for (i=0;i<nprocs;i++) {
04978 if (child_status[i]) synccount++;
04979 }
04980 if (synccount == nprocs) break;
04981 smb_msleep(10);
04982 } while (end_timer() < 30);
04983
04984 if (synccount != nprocs) {
04985 printf("FAILED TO START %d CLIENTS (started %d)\n", nprocs, synccount);
04986 *result = False;
04987 return end_timer();
04988 }
04989
04990
04991 start_timer();
04992
04993 for (i=0;i<nprocs;i++) {
04994 child_status[i] = 0;
04995 }
04996
04997 printf("%d clients started\n", nprocs);
04998
04999 for (i=0;i<nprocs;i++) {
05000 while (waitpid(0, &status, 0) == -1 && errno == EINTR) ;
05001 }
05002
05003 printf("\n");
05004
05005 for (i=0;i<nprocs;i++) {
05006 if (!child_status_out[i]) {
05007 *result = False;
05008 }
05009 }
05010 return end_timer();
05011 }
05012
05013 #define FLAG_MULTIPROC 1
05014
05015 static struct {
05016 const char *name;
05017 BOOL (*fn)(int);
05018 unsigned flags;
05019 } torture_ops[] = {
05020 {"FDPASS", run_fdpasstest, 0},
05021 {"LOCK1", run_locktest1, 0},
05022 {"LOCK2", run_locktest2, 0},
05023 {"LOCK3", run_locktest3, 0},
05024 {"LOCK4", run_locktest4, 0},
05025 {"LOCK5", run_locktest5, 0},
05026 {"LOCK6", run_locktest6, 0},
05027 {"LOCK7", run_locktest7, 0},
05028 {"UNLINK", run_unlinktest, 0},
05029 {"BROWSE", run_browsetest, 0},
05030 {"ATTR", run_attrtest, 0},
05031 {"TRANS2", run_trans2test, 0},
05032 {"MAXFID", run_maxfidtest, FLAG_MULTIPROC},
05033 {"TORTURE",run_torture, FLAG_MULTIPROC},
05034 {"RANDOMIPC", run_randomipc, 0},
05035 {"NEGNOWAIT", run_negprot_nowait, 0},
05036 {"NBENCH", run_nbench, 0},
05037 {"OPLOCK1", run_oplock1, 0},
05038 {"OPLOCK2", run_oplock2, 0},
05039 {"OPLOCK3", run_oplock3, 0},
05040 {"DIR", run_dirtest, 0},
05041 {"DIR1", run_dirtest1, 0},
05042 {"DENY1", torture_denytest1, 0},
05043 {"DENY2", torture_denytest2, 0},
05044 {"TCON", run_tcon_test, 0},
05045 {"TCONDEV", run_tcon_devtype_test, 0},
05046 {"RW1", run_readwritetest, 0},
05047 {"RW2", run_readwritemulti, FLAG_MULTIPROC},
05048 {"RW3", run_readwritelarge, 0},
05049 {"OPEN", run_opentest, 0},
05050 #if 1
05051 {"OPENATTR", run_openattrtest, 0},
05052 #endif
05053 {"XCOPY", run_xcopy, 0},
05054 {"RENAME", run_rename, 0},
05055 {"DELETE", run_deletetest, 0},
05056 {"PROPERTIES", run_properties, 0},
05057 {"MANGLE", torture_mangle, 0},
05058 {"W2K", run_w2ktest, 0},
05059 {"TRANS2SCAN", torture_trans2_scan, 0},
05060 {"NTTRANSSCAN", torture_nttrans_scan, 0},
05061 {"UTABLE", torture_utable, 0},
05062 {"CASETABLE", torture_casetable, 0},
05063 {"ERRMAPEXTRACT", run_error_map_extract, 0},
05064 {"PIPE_NUMBER", run_pipe_number, 0},
05065 {"TCON2", run_tcon2_test, 0},
05066 {"IOCTL", torture_ioctl_test, 0},
05067 {"CHKPATH", torture_chkpath_test, 0},
05068 {"FDSESS", run_fdsesstest, 0},
05069 { "EATEST", run_eatest, 0},
05070 { "SESSSETUP_BENCH", run_sesssetup_bench, 0},
05071 { "LOCAL-SUBSTITUTE", run_local_substitute, 0},
05072 { "LOCAL-GENCACHE", run_local_gencache, 0},
05073 {NULL, NULL, 0}};
05074
05075
05076
05077
05078
05079
05080 static BOOL run_test(const char *name)
05081 {
05082 BOOL ret = True;
05083 BOOL result = True;
05084 BOOL found = False;
05085 int i;
05086 double t;
05087 if (strequal(name,"ALL")) {
05088 for (i=0;torture_ops[i].name;i++) {
05089 run_test(torture_ops[i].name);
05090 }
05091 found = True;
05092 }
05093
05094 for (i=0;torture_ops[i].name;i++) {
05095 fstr_sprintf(randomfname, "\\XX%x",
05096 (unsigned)random());
05097
05098 if (strequal(name, torture_ops[i].name)) {
05099 found = True;
05100 printf("Running %s\n", name);
05101 if (torture_ops[i].flags & FLAG_MULTIPROC) {
05102 t = create_procs(torture_ops[i].fn, &result);
05103 if (!result) {
05104 ret = False;
05105 printf("TEST %s FAILED!\n", name);
05106 }
05107
05108 } else {
05109 start_timer();
05110 if (!torture_ops[i].fn(0)) {
05111 ret = False;
05112 printf("TEST %s FAILED!\n", name);
05113 }
05114 t = end_timer();
05115 }
05116 printf("%s took %g secs\n\n", name, t);
05117 }
05118 }
05119
05120 if (!found) {
05121 printf("Did not find a test named %s\n", name);
05122 ret = False;
05123 }
05124
05125 return ret;
05126 }
05127
05128
05129 static void usage(void)
05130 {
05131 int i;
05132
05133 printf("WARNING samba4 test suite is much more complete nowadays.\n");
05134 printf("Please use samba4 torture.\n\n");
05135
05136 printf("Usage: smbtorture //server/share <options> TEST1 TEST2 ...\n");
05137
05138 printf("\t-d debuglevel\n");
05139 printf("\t-U user%%pass\n");
05140 printf("\t-k use kerberos\n");
05141 printf("\t-N numprocs\n");
05142 printf("\t-n my_netbios_name\n");
05143 printf("\t-W workgroup\n");
05144 printf("\t-o num_operations\n");
05145 printf("\t-O socket_options\n");
05146 printf("\t-m maximum protocol\n");
05147 printf("\t-L use oplocks\n");
05148 printf("\t-c CLIENT.TXT specify client load file for NBENCH\n");
05149 printf("\t-A showall\n");
05150 printf("\t-p port\n");
05151 printf("\t-s seed\n");
05152 printf("\t-b unclist_filename specify multiple shares for multiple connections\n");
05153 printf("\n\n");
05154
05155 printf("tests are:");
05156 for (i=0;torture_ops[i].name;i++) {
05157 printf(" %s", torture_ops[i].name);
05158 }
05159 printf("\n");
05160
05161 printf("default test is ALL\n");
05162
05163 exit(1);
05164 }
05165
05166
05167
05168
05169 int main(int argc,char *argv[])
05170 {
05171 int opt, i;
05172 char *p;
05173 int gotuser = 0;
05174 int gotpass = 0;
05175 BOOL correct = True;
05176
05177 dbf = x_stdout;
05178
05179 #ifdef HAVE_SETBUFFER
05180 setbuffer(stdout, NULL, 0);
05181 #endif
05182
05183 load_case_tables();
05184
05185 lp_load(dyn_CONFIGFILE,True,False,False,True);
05186 load_interfaces();
05187
05188 if (argc < 2) {
05189 usage();
05190 }
05191
05192 for(p = argv[1]; *p; p++)
05193 if(*p == '\\')
05194 *p = '/';
05195
05196 if (strncmp(argv[1], "//", 2)) {
05197 usage();
05198 }
05199
05200 fstrcpy(host, &argv[1][2]);
05201 p = strchr_m(&host[2],'/');
05202 if (!p) {
05203 usage();
05204 }
05205 *p = 0;
05206 fstrcpy(share, p+1);
05207
05208 get_myname(myname);
05209
05210 if (*username == 0 && getenv("LOGNAME")) {
05211 fstrcpy(username,getenv("LOGNAME"));
05212 }
05213
05214 argc--;
05215 argv++;
05216
05217 srandom(time(NULL));
05218
05219 fstrcpy(workgroup, lp_workgroup());
05220
05221 while ((opt = getopt(argc, argv, "p:hW:U:n:N:O:o:m:Ld:Ac:ks:b:")) != EOF) {
05222 switch (opt) {
05223 case 'p':
05224 port_to_use = atoi(optarg);
05225 break;
05226 case 's':
05227 srandom(atoi(optarg));
05228 break;
05229 case 'W':
05230 fstrcpy(workgroup,optarg);
05231 break;
05232 case 'm':
05233 max_protocol = interpret_protocol(optarg, max_protocol);
05234 break;
05235 case 'N':
05236 nprocs = atoi(optarg);
05237 break;
05238 case 'o':
05239 torture_numops = atoi(optarg);
05240 break;
05241 case 'd':
05242 DEBUGLEVEL = atoi(optarg);
05243 break;
05244 case 'O':
05245 sockops = optarg;
05246 break;
05247 case 'L':
05248 use_oplocks = True;
05249 break;
05250 case 'A':
05251 torture_showall = True;
05252 break;
05253 case 'n':
05254 fstrcpy(myname, optarg);
05255 break;
05256 case 'c':
05257 client_txt = optarg;
05258 break;
05259 case 'k':
05260 #ifdef HAVE_KRB5
05261 use_kerberos = True;
05262 #else
05263 d_printf("No kerberos support compiled in\n");
05264 exit(1);
05265 #endif
05266 break;
05267 case 'U':
05268 gotuser = 1;
05269 fstrcpy(username,optarg);
05270 p = strchr_m(username,'%');
05271 if (p) {
05272 *p = 0;
05273 fstrcpy(password, p+1);
05274 gotpass = 1;
05275 }
05276 break;
05277 case 'b':
05278 fstrcpy(multishare_conn_fname, optarg);
05279 use_multishare_conn = True;
05280 break;
05281 default:
05282 printf("Unknown option %c (%d)\n", (char)opt, opt);
05283 usage();
05284 }
05285 }
05286
05287 if(use_kerberos && !gotuser) gotpass = True;
05288
05289 while (!gotpass) {
05290 p = getpass("Password:");
05291 if (p) {
05292 fstrcpy(password, p);
05293 gotpass = 1;
05294 }
05295 }
05296
05297 printf("host=%s share=%s user=%s myname=%s\n",
05298 host, share, username, myname);
05299
05300 if (argc == optind) {
05301 correct = run_test("ALL");
05302 } else {
05303 for (i=optind;i<argc;i++) {
05304 if (!run_test(argv[i])) {
05305 correct = False;
05306 }
05307 }
05308 }
05309
05310 if (correct) {
05311 return(0);
05312 } else {
05313 return(1);
05314 }
05315 }