r15836: Test an invalid DOS share mode.
[ira/wip.git] / source4 / torture / basic / base.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB torture tester
4    Copyright (C) Andrew Tridgell 1997-2003
5    Copyright (C) Jelmer Vernooij 2006
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "torture/basic/proto.h"
25 #include "libcli/libcli.h"
26 #include "torture/util.h"
27 #include "system/filesys.h"
28 #include "system/time.h"
29 #include "libcli/resolve/resolve.h"
30 #include "librpc/gen_ndr/ndr_nbt.h"
31 #include "lib/events/events.h"
32 #include "lib/cmdline/popt_common.h"
33
34
35 #define CHECK_MAX_FAILURES(label) do { if (++failures >= torture_failures) goto label; } while (0)
36
37
38 static struct smbcli_state *open_nbt_connection(void)
39 {
40         struct nbt_name called, calling;
41         struct smbcli_state *cli;
42         const char *host = lp_parm_string(-1, "torture", "host");
43
44         make_nbt_name_client(&calling, lp_netbios_name());
45
46         nbt_choose_called_name(NULL, &called, host, NBT_NAME_SERVER);
47
48         cli = smbcli_state_init(NULL);
49         if (!cli) {
50                 printf("Failed initialize smbcli_struct to connect with %s\n", host);
51                 goto failed;
52         }
53
54         if (!smbcli_socket_connect(cli, host)) {
55                 printf("Failed to connect with %s\n", host);
56                 goto failed;
57         }
58
59         if (!smbcli_transport_establish(cli, &calling, &called)) {
60                 printf("%s rejected the session\n",host);
61                 goto failed;
62         }
63
64         return cli;
65
66 failed:
67         talloc_free(cli);
68         return NULL;
69 }
70
71 static BOOL tcon_devtest(struct smbcli_state *cli,
72                          const char *myshare, const char *devtype,
73                          NTSTATUS expected_error)
74 {
75         BOOL status;
76         BOOL ret;
77         const char *password = lp_parm_string(-1, "torture", "password");
78
79         status = NT_STATUS_IS_OK(smbcli_tconX(cli, myshare, devtype, 
80                                                 password));
81
82         printf("Trying share %s with devtype %s\n", myshare, devtype);
83
84         if (NT_STATUS_IS_OK(expected_error)) {
85                 if (status) {
86                         ret = True;
87                 } else {
88                         printf("tconX to share %s with type %s "
89                                "should have succeeded but failed\n",
90                                myshare, devtype);
91                         ret = False;
92                 }
93                 smbcli_tdis(cli);
94         } else {
95                 if (status) {
96                         printf("tconx to share %s with type %s "
97                                "should have failed but succeeded\n",
98                                myshare, devtype);
99                         ret = False;
100                 } else {
101                         if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),
102                                             expected_error)) {
103                                 ret = True;
104                         } else {
105                                 printf("Returned unexpected error\n");
106                                 ret = False;
107                         }
108                 }
109         }
110         return ret;
111 }
112
113
114
115 /**
116 test whether fnums and tids open on one VC are available on another (a major
117 security hole)
118 */
119 static BOOL run_fdpasstest(struct torture_context *torture)
120 {
121         struct smbcli_state *cli1, *cli2;
122         const char *fname = "\\fdpass.tst";
123         int fnum1, oldtid;
124         uint8_t buf[1024];
125
126         if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
127                 return False;
128         }
129
130         printf("starting fdpasstest\n");
131
132         smbcli_unlink(cli1->tree, fname);
133
134         printf("Opening a file on connection 1\n");
135
136         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
137         if (fnum1 == -1) {
138                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
139                 return False;
140         }
141
142         printf("writing to file on connection 1\n");
143
144         if (smbcli_write(cli1->tree, fnum1, 0, "hello world\n", 0, 13) != 13) {
145                 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
146                 return False;
147         }
148
149         oldtid = cli2->tree->tid;
150         cli2->session->vuid = cli1->session->vuid;
151         cli2->tree->tid = cli1->tree->tid;
152         cli2->session->pid = cli1->session->pid;
153
154         printf("reading from file on connection 2\n");
155
156         if (smbcli_read(cli2->tree, fnum1, buf, 0, 13) == 13) {
157                 printf("read succeeded! nasty security hole [%s]\n",
158                        buf);
159                 return False;
160         }
161
162         smbcli_close(cli1->tree, fnum1);
163         smbcli_unlink(cli1->tree, fname);
164
165         cli2->tree->tid = oldtid;
166
167         torture_close_connection(cli1);
168         torture_close_connection(cli2);
169
170         printf("finished fdpasstest\n");
171         return True;
172 }
173
174 /**
175   This checks how the getatr calls works
176 */
177 static BOOL run_attrtest(struct torture_context *torture)
178 {
179         struct smbcli_state *cli;
180         int fnum;
181         time_t t, t2;
182         const char *fname = "\\attrib123456789.tst";
183         BOOL correct = True;
184
185         printf("starting attrib test\n");
186
187         if (!torture_open_connection(&cli)) {
188                 return False;
189         }
190
191         smbcli_unlink(cli->tree, fname);
192         fnum = smbcli_open(cli->tree, fname, 
193                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
194         smbcli_close(cli->tree, fnum);
195
196         if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
197                 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
198                 correct = False;
199         }
200
201         printf("New file time is %s", ctime(&t));
202
203         if (abs(t - time(NULL)) > 60*60*24*10) {
204                 printf("ERROR: SMBgetatr bug. time is %s",
205                        ctime(&t));
206                 t = time(NULL);
207                 correct = False;
208         }
209
210         t2 = t-60*60*24; /* 1 day ago */
211
212         printf("Setting file time to %s", ctime(&t2));
213
214         if (NT_STATUS_IS_ERR(smbcli_setatr(cli->tree, fname, 0, t2))) {
215                 printf("setatr failed (%s)\n", smbcli_errstr(cli->tree));
216                 correct = True;
217         }
218
219         if (NT_STATUS_IS_ERR(smbcli_getatr(cli->tree, fname, NULL, NULL, &t))) {
220                 printf("getatr failed (%s)\n", smbcli_errstr(cli->tree));
221                 correct = True;
222         }
223
224         printf("Retrieved file time as %s", ctime(&t));
225
226         if (t != t2) {
227                 printf("ERROR: getatr/setatr bug. times are\n%s",
228                        ctime(&t));
229                 printf("%s", ctime(&t2));
230                 correct = True;
231         }
232
233         smbcli_unlink(cli->tree, fname);
234
235         if (!torture_close_connection(cli)) {
236                 correct = False;
237         }
238
239         printf("attrib test finished\n");
240
241         return correct;
242 }
243
244 /**
245   This checks a couple of trans2 calls
246 */
247 static BOOL run_trans2test(struct torture_context *torture)
248 {
249         struct smbcli_state *cli;
250         int fnum;
251         size_t size;
252         time_t c_time, a_time, m_time, w_time, m_time2;
253         const char *fname = "\\trans2.tst";
254         const char *dname = "\\trans2";
255         const char *fname2 = "\\trans2\\trans2.tst";
256         const char *pname;
257         BOOL correct = True;
258
259         printf("starting trans2 test\n");
260
261         if (!torture_open_connection(&cli)) {
262                 return False;
263         }
264
265         smbcli_unlink(cli->tree, fname);
266
267         printf("Testing qfileinfo\n");
268         
269         fnum = smbcli_open(cli->tree, fname, 
270                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
271         if (NT_STATUS_IS_ERR(smbcli_qfileinfo(cli->tree, fnum, NULL, &size, &c_time, &a_time, &m_time,
272                            NULL, NULL))) {
273                 printf("ERROR: qfileinfo failed (%s)\n", smbcli_errstr(cli->tree));
274                 correct = False;
275         }
276
277         printf("Testing NAME_INFO\n");
278
279         if (NT_STATUS_IS_ERR(smbcli_qfilename(cli->tree, fnum, &pname))) {
280                 printf("ERROR: qfilename failed (%s)\n", smbcli_errstr(cli->tree));
281                 correct = False;
282         }
283
284         if (!pname || strcmp(pname, fname)) {
285                 printf("qfilename gave different name? [%s] [%s]\n",
286                        fname, pname);
287                 correct = False;
288         }
289
290         smbcli_close(cli->tree, fnum);
291         smbcli_unlink(cli->tree, fname);
292
293         fnum = smbcli_open(cli->tree, fname, 
294                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
295         if (fnum == -1) {
296                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
297                 return False;
298         }
299         smbcli_close(cli->tree, fnum);
300
301         printf("Checking for sticky create times\n");
302
303         if (NT_STATUS_IS_ERR(smbcli_qpathinfo(cli->tree, fname, &c_time, &a_time, &m_time, &size, NULL))) {
304                 printf("ERROR: qpathinfo failed (%s)\n", smbcli_errstr(cli->tree));
305                 correct = False;
306         } else {
307                 if (c_time != m_time) {
308                         printf("create time=%s", ctime(&c_time));
309                         printf("modify time=%s", ctime(&m_time));
310                         printf("This system appears to have sticky create times\n");
311                 }
312                 if (a_time % (60*60) == 0) {
313                         printf("access time=%s", ctime(&a_time));
314                         printf("This system appears to set a midnight access time\n");
315                         correct = False;
316                 }
317
318                 if (abs(m_time - time(NULL)) > 60*60*24*7) {
319                         printf("ERROR: totally incorrect times - maybe word reversed? mtime=%s", ctime(&m_time));
320                         correct = False;
321                 }
322         }
323
324
325         smbcli_unlink(cli->tree, fname);
326         fnum = smbcli_open(cli->tree, fname, 
327                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
328         smbcli_close(cli->tree, fnum);
329         if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, fname, &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
330                 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
331                 correct = False;
332         } else {
333                 if (w_time < 60*60*24*2) {
334                         printf("write time=%s", ctime(&w_time));
335                         printf("This system appears to set a initial 0 write time\n");
336                         correct = False;
337                 }
338         }
339
340         smbcli_unlink(cli->tree, fname);
341
342
343         /* check if the server updates the directory modification time
344            when creating a new file */
345         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, dname))) {
346                 printf("ERROR: mkdir failed (%s)\n", smbcli_errstr(cli->tree));
347                 correct = False;
348         }
349         sleep(3);
350         if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time, &w_time, &size, NULL, NULL))) {
351                 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
352                 correct = False;
353         }
354
355         fnum = smbcli_open(cli->tree, fname2, 
356                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
357         smbcli_write(cli->tree, fnum,  0, &fnum, 0, sizeof(fnum));
358         smbcli_close(cli->tree, fnum);
359         if (NT_STATUS_IS_ERR(smbcli_qpathinfo2(cli->tree, "\\trans2\\", &c_time, &a_time, &m_time2, &w_time, &size, NULL, NULL))) {
360                 printf("ERROR: qpathinfo2 failed (%s)\n", smbcli_errstr(cli->tree));
361                 correct = False;
362         } else {
363                 if (m_time2 == m_time) {
364                         printf("This system does not update directory modification times\n");
365                         correct = False;
366                 }
367         }
368         smbcli_unlink(cli->tree, fname2);
369         smbcli_rmdir(cli->tree, dname);
370
371         if (!torture_close_connection(cli)) {
372                 correct = False;
373         }
374
375         printf("trans2 test finished\n");
376
377         return correct;
378 }
379
380 /* send smb negprot commands, not reading the response */
381 static BOOL run_negprot_nowait(struct torture_context *torture)
382 {
383         int i;
384         struct smbcli_state *cli, *cli2;
385         BOOL correct = True;
386
387         printf("starting negprot nowait test\n");
388
389         cli = open_nbt_connection();
390         if (!cli) {
391                 return False;
392         }
393
394         printf("Filling send buffer\n");
395
396         for (i=0;i<100;i++) {
397                 struct smbcli_request *req;
398                 req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
399                 event_loop_once(cli->transport->socket->event.ctx);
400                 if (req->state == SMBCLI_REQUEST_ERROR) {
401                         if (i > 0) {
402                                 printf("Failed to fill pipe packet[%d] - %s (ignored)\n", i+1, nt_errstr(req->status));
403                                 break;
404                         } else {
405                                 printf("Failed to fill pipe - %s \n", nt_errstr(req->status));
406                                 torture_close_connection(cli);
407                                 return False;
408                         }
409                 }
410         }
411
412         printf("Opening secondary connection\n");
413         if (!torture_open_connection(&cli2)) {
414                 printf("Failed to open secondary connection\n");
415                 correct = False;
416         }
417
418         if (!torture_close_connection(cli2)) {
419                 printf("Failed to close secondary connection\n");
420                 correct = False;
421         }
422
423         torture_close_connection(cli);
424
425         printf("finished negprot nowait test\n");
426
427         return correct;
428 }
429
430 /**
431   this checks to see if a secondary tconx can use open files from an
432   earlier tconx
433  */
434 static BOOL run_tcon_test(struct torture_context *torture)
435 {
436         struct smbcli_state *cli;
437         const char *fname = "\\tcontest.tmp";
438         int fnum1;
439         uint16_t cnum1, cnum2, cnum3;
440         uint16_t vuid1, vuid2;
441         uint8_t buf[4];
442         BOOL ret = True;
443         struct smbcli_tree *tree1;
444         const char *host = lp_parm_string(-1, "torture", "host");
445         const char *share = lp_parm_string(-1, "torture", "share");
446         const char *password = lp_parm_string(-1, "torture", "password");
447
448         if (!torture_open_connection(&cli)) {
449                 return False;
450         }
451
452         printf("starting tcontest\n");
453
454         if (smbcli_deltree(cli->tree, fname) == -1) {
455                 printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
456         }
457
458         fnum1 = smbcli_open(cli->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
459         if (fnum1 == -1) {
460                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
461                 return False;
462         }
463
464         cnum1 = cli->tree->tid;
465         vuid1 = cli->session->vuid;
466
467         memset(&buf, 0, 4); /* init buf so valgrind won't complain */
468         if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) != 4) {
469                 printf("initial write failed (%s)\n", smbcli_errstr(cli->tree));
470                 return False;
471         }
472
473         tree1 = cli->tree;      /* save old tree connection */
474         if (NT_STATUS_IS_ERR(smbcli_tconX(cli, share, "?????", password))) {
475                 printf("%s refused 2nd tree connect (%s)\n", host,
476                            smbcli_errstr(cli->tree));
477                 talloc_free(cli);
478                 return False;
479         }
480
481         cnum2 = cli->tree->tid;
482         cnum3 = MAX(cnum1, cnum2) + 1; /* any invalid number */
483         vuid2 = cli->session->vuid + 1;
484
485         /* try a write with the wrong tid */
486         cli->tree->tid = cnum2;
487
488         if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
489                 printf("* server allows write with wrong TID\n");
490                 ret = False;
491         } else {
492                 printf("server fails write with wrong TID : %s\n", smbcli_errstr(cli->tree));
493         }
494
495
496         /* try a write with an invalid tid */
497         cli->tree->tid = cnum3;
498
499         if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
500                 printf("* server allows write with invalid TID\n");
501                 ret = False;
502         } else {
503                 printf("server fails write with invalid TID : %s\n", smbcli_errstr(cli->tree));
504         }
505
506         /* try a write with an invalid vuid */
507         cli->session->vuid = vuid2;
508         cli->tree->tid = cnum1;
509
510         if (smbcli_write(cli->tree, fnum1, 0, buf, 130, 4) == 4) {
511                 printf("* server allows write with invalid VUID\n");
512                 ret = False;
513         } else {
514                 printf("server fails write with invalid VUID : %s\n", smbcli_errstr(cli->tree));
515         }
516
517         cli->session->vuid = vuid1;
518         cli->tree->tid = cnum1;
519
520         if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum1))) {
521                 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
522                 return False;
523         }
524
525         cli->tree->tid = cnum2;
526
527         if (NT_STATUS_IS_ERR(smbcli_tdis(cli))) {
528                 printf("secondary tdis failed (%s)\n", smbcli_errstr(cli->tree));
529                 return False;
530         }
531
532         cli->tree = tree1;  /* restore initial tree */
533         cli->tree->tid = cnum1;
534
535         smbcli_unlink(tree1, fname);
536
537         if (!torture_close_connection(cli)) {
538                 return False;
539         }
540
541         return ret;
542 }
543
544 /**
545  checks for correct tconX support
546  */
547 static BOOL run_tcon_devtype_test(struct torture_context *torture)
548 {
549         struct smbcli_state *cli1 = NULL;
550         NTSTATUS status;
551         BOOL ret = True;
552         const char *host = lp_parm_string(-1, "torture", "host");
553         const char *share = lp_parm_string(-1, "torture", "share");
554         
555         status = smbcli_full_connection(NULL,
556                                         &cli1, host, 
557                                         share, NULL,
558                                         cmdline_credentials, NULL);
559
560         if (!NT_STATUS_IS_OK(status)) {
561                 printf("could not open connection\n");
562                 return False;
563         }
564
565         if (!tcon_devtest(cli1, "IPC$", "A:", NT_STATUS_BAD_DEVICE_TYPE))
566                 ret = False;
567
568         if (!tcon_devtest(cli1, "IPC$", "?????", NT_STATUS_OK))
569                 ret = False;
570
571         if (!tcon_devtest(cli1, "IPC$", "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
572                 ret = False;
573
574         if (!tcon_devtest(cli1, "IPC$", "IPC", NT_STATUS_OK))
575                 ret = False;
576                         
577         if (!tcon_devtest(cli1, "IPC$", "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
578                 ret = False;
579
580         if (!tcon_devtest(cli1, share, "A:", NT_STATUS_OK))
581                 ret = False;
582
583         if (!tcon_devtest(cli1, share, "?????", NT_STATUS_OK))
584                 ret = False;
585
586         if (!tcon_devtest(cli1, share, "LPT:", NT_STATUS_BAD_DEVICE_TYPE))
587                 ret = False;
588
589         if (!tcon_devtest(cli1, share, "IPC", NT_STATUS_BAD_DEVICE_TYPE))
590                 ret = False;
591                         
592         if (!tcon_devtest(cli1, share, "FOOBA", NT_STATUS_BAD_DEVICE_TYPE))
593                 ret = False;
594
595         talloc_free(cli1);
596
597         if (ret)
598                 printf("Passed tcondevtest\n");
599
600         return ret;
601 }
602
603 static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
604 {
605         const char *lockfname = "\\torture2.lck";
606         int fnum1;
607         int fnum2;
608         int i;
609         uint8_t buf[131072];
610         uint8_t buf_rd[131072];
611         BOOL correct = True;
612         ssize_t bytes_read, bytes_written;
613
614         if (smbcli_deltree(c1->tree, lockfname) == -1) {
615                 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
616         }
617
618         fnum1 = smbcli_open(c1->tree, lockfname, O_RDWR | O_CREAT | O_EXCL, 
619                          DENY_NONE);
620         if (fnum1 == -1) {
621                 printf("first open read/write of %s failed (%s)\n",
622                                 lockfname, smbcli_errstr(c1->tree));
623                 return False;
624         }
625         fnum2 = smbcli_open(c2->tree, lockfname, O_RDONLY, 
626                          DENY_NONE);
627         if (fnum2 == -1) {
628                 printf("second open read-only of %s failed (%s)\n",
629                                 lockfname, smbcli_errstr(c2->tree));
630                 smbcli_close(c1->tree, fnum1);
631                 return False;
632         }
633
634         printf("Checking data integrity over %d ops\n", torture_numops);
635
636         for (i=0;i<torture_numops;i++)
637         {
638                 size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;
639                 if (i % 10 == 0) {
640                         printf("%d\r", i); fflush(stdout);
641                 }
642
643                 generate_random_buffer(buf, buf_size);
644
645                 if ((bytes_written = smbcli_write(c1->tree, fnum1, 0, buf, 0, buf_size)) != buf_size) {
646                         printf("write failed (%s)\n", smbcli_errstr(c1->tree));
647                         printf("wrote %d, expected %d\n", (int)bytes_written, (int)buf_size); 
648                         correct = False;
649                         break;
650                 }
651
652                 if ((bytes_read = smbcli_read(c2->tree, fnum2, buf_rd, 0, buf_size)) != buf_size) {
653                         printf("read failed (%s)\n", smbcli_errstr(c2->tree));
654                         printf("read %d, expected %d\n", (int)bytes_read, (int)buf_size); 
655                         correct = False;
656                         break;
657                 }
658
659                 if (memcmp(buf_rd, buf, buf_size) != 0)
660                 {
661                         printf("read/write compare failed\n");
662                         correct = False;
663                         break;
664                 }
665         }
666
667         if (NT_STATUS_IS_ERR(smbcli_close(c2->tree, fnum2))) {
668                 printf("close failed (%s)\n", smbcli_errstr(c2->tree));
669                 correct = False;
670         }
671         if (NT_STATUS_IS_ERR(smbcli_close(c1->tree, fnum1))) {
672                 printf("close failed (%s)\n", smbcli_errstr(c1->tree));
673                 correct = False;
674         }
675
676         if (NT_STATUS_IS_ERR(smbcli_unlink(c1->tree, lockfname))) {
677                 printf("unlink failed (%s)\n", smbcli_errstr(c1->tree));
678                 correct = False;
679         }
680
681         return correct;
682 }
683
684
685
686 #define BOOLSTR(b) ((b) ? "Yes" : "No")
687
688 static BOOL run_readwritetest(struct torture_context *torture)
689 {
690         struct smbcli_state *cli1, *cli2;
691         BOOL test1, test2 = True;
692
693         if (!torture_open_connection(&cli1) || !torture_open_connection(&cli2)) {
694                 return False;
695         }
696
697         printf("starting readwritetest\n");
698
699         test1 = rw_torture2(cli1, cli2);
700         printf("Passed readwritetest v1: %s\n", BOOLSTR(test1));
701
702         if (test1) {
703                 test2 = rw_torture2(cli1, cli1);
704                 printf("Passed readwritetest v2: %s\n", BOOLSTR(test2));
705         }
706
707         if (!torture_close_connection(cli1)) {
708                 test1 = False;
709         }
710
711         if (!torture_close_connection(cli2)) {
712                 test2 = False;
713         }
714
715         return (test1 && test2);
716 }
717
718
719
720
721
722 /*
723 test the timing of deferred open requests
724 */
725 static BOOL run_deferopen(struct smbcli_state *cli, int dummy)
726 {
727         const char *fname = "\\defer_open_test.dat";
728         int retries=4;
729         int i = 0;
730         BOOL correct = True;
731
732         if (retries <= 0) {
733                 printf("failed to connect\n");
734                 return False;
735         }
736
737         printf("Testing deferred open requests.\n");
738
739         while (i < 4) {
740                 int fnum = -1;
741
742                 do {
743                         struct timeval tv;
744                         tv = timeval_current();
745                         fnum = smbcli_nt_create_full(cli->tree, fname, 0, 
746                                                      SEC_RIGHTS_FILE_ALL,
747                                                      FILE_ATTRIBUTE_NORMAL, 
748                                                      NTCREATEX_SHARE_ACCESS_NONE,
749                                                      NTCREATEX_DISP_OPEN_IF, 0, 0);
750                         if (fnum != -1) {
751                                 break;
752                         }
753                         if (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
754                                 double e = timeval_elapsed(&tv);
755                                 if (e < 0.5 || e > 1.5) {
756                                         fprintf(stderr,"Timing incorrect %.2f violation\n",
757                                                 e);
758                                 }
759                         }
760                 } while (NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION));
761
762                 if (fnum == -1) {
763                         fprintf(stderr,"Failed to open %s, error=%s\n", fname, smbcli_errstr(cli->tree));
764                         return False;
765                 }
766
767                 printf("pid %u open %d\n", getpid(), i);
768
769                 sleep(10);
770                 i++;
771                 if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
772                         fprintf(stderr,"Failed to close %s, error=%s\n", fname, smbcli_errstr(cli->tree));
773                         return False;
774                 }
775                 sleep(2);
776         }
777
778         if (NT_STATUS_IS_ERR(smbcli_unlink(cli->tree, fname))) {
779                 /* All until the last unlink will fail with sharing violation. */
780                 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli->tree),NT_STATUS_SHARING_VIOLATION)) {
781                         printf("unlink of %s failed (%s)\n", fname, smbcli_errstr(cli->tree));
782                         correct = False;
783                 }
784         }
785
786         printf("deferred test finished\n");
787         if (!torture_close_connection(cli)) {
788                 correct = False;
789         }
790         return correct;
791 }
792
793 /**
794   Try with a wrong vuid and check error message.
795  */
796
797 static BOOL run_vuidtest(struct torture_context *torture)
798 {
799         struct smbcli_state *cli;
800         const char *fname = "\\vuid.tst";
801         int fnum;
802         size_t size;
803         time_t c_time, a_time, m_time;
804         BOOL correct = True;
805
806         uint16_t orig_vuid;
807         NTSTATUS result;
808
809         printf("starting vuid test\n");
810
811         if (!torture_open_connection(&cli)) {
812                 return False;
813         }
814
815         smbcli_unlink(cli->tree, fname);
816
817         fnum = smbcli_open(cli->tree, fname, 
818                         O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
819
820         orig_vuid = cli->session->vuid;
821
822         cli->session->vuid += 1234;
823
824         printf("Testing qfileinfo with wrong vuid\n");
825         
826         if (NT_STATUS_IS_OK(result = smbcli_qfileinfo(cli->tree, fnum, NULL,
827                                                    &size, &c_time, &a_time,
828                                                    &m_time, NULL, NULL))) {
829                 printf("ERROR: qfileinfo passed with wrong vuid\n");
830                 correct = False;
831         }
832
833         if (!NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
834                              NT_STATUS_DOS(ERRSRV, ERRbaduid)) &&
835             !NT_STATUS_EQUAL(cli->transport->error.e.nt_status, 
836                              NT_STATUS_INVALID_HANDLE)) {
837                 printf("ERROR: qfileinfo should have returned DOS error "
838                        "ERRSRV:ERRbaduid\n  but returned %s\n",
839                        smbcli_errstr(cli->tree));
840                 correct = False;
841         }
842
843         cli->session->vuid -= 1234;
844
845         if (NT_STATUS_IS_ERR(smbcli_close(cli->tree, fnum))) {
846                 printf("close failed (%s)\n", smbcli_errstr(cli->tree));
847                 correct = False;
848         }
849
850         smbcli_unlink(cli->tree, fname);
851
852         if (!torture_close_connection(cli)) {
853                 correct = False;
854         }
855
856         printf("vuid test finished\n");
857
858         return correct;
859 }
860
861 /*
862   Test open mode returns on read-only files.
863  */
864  static BOOL run_opentest(struct torture_context *torture)
865 {
866         static struct smbcli_state *cli1;
867         static struct smbcli_state *cli2;
868         const char *fname = "\\readonly.file";
869         char *control_char_fname;
870         int fnum1, fnum2;
871         uint8_t buf[20];
872         size_t fsize;
873         BOOL correct = True;
874         char *tmp_path;
875         int failures = 0;
876         int i;
877
878         printf("starting open test\n");
879         
880         if (!torture_open_connection(&cli1)) {
881                 return False;
882         }
883         
884         asprintf(&control_char_fname, "\\readonly.afile");
885         for (i = 1; i <= 0x1f; i++) {
886                 control_char_fname[10] = i;
887                 fnum1 = smbcli_nt_create_full(cli1->tree, control_char_fname, 0, SEC_FILE_WRITE_DATA, FILE_ATTRIBUTE_NORMAL,
888                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
889                 
890                 if (!check_error(__location__, cli1, ERRDOS, ERRinvalidname, 
891                                 NT_STATUS_OBJECT_NAME_INVALID)) {
892                         printf("Error code should be NT_STATUS_OBJECT_NAME_INVALID, was %s for file with %d char\n",
893                                         smbcli_errstr(cli1->tree), i);
894                         failures++;
895                 }
896
897                 if (fnum1 != -1) {
898                         smbcli_close(cli1->tree, fnum1);
899                 }
900                 smbcli_setatr(cli1->tree, control_char_fname, 0, 0);
901                 smbcli_unlink(cli1->tree, control_char_fname);
902         }
903         free(control_char_fname);
904
905         if (!failures)
906                 printf("Create file with control char names passed.\n");
907
908         smbcli_setatr(cli1->tree, fname, 0, 0);
909         smbcli_unlink(cli1->tree, fname);
910         
911         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
912         if (fnum1 == -1) {
913                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
914                 return False;
915         }
916
917         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
918                 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
919                 return False;
920         }
921         
922         if (NT_STATUS_IS_ERR(smbcli_setatr(cli1->tree, fname, FILE_ATTRIBUTE_READONLY, 0))) {
923                 printf("smbcli_setatr failed (%s)\n", smbcli_errstr(cli1->tree));
924                 CHECK_MAX_FAILURES(error_test1);
925                 return False;
926         }
927         
928         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
929         if (fnum1 == -1) {
930                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
931                 CHECK_MAX_FAILURES(error_test1);
932                 return False;
933         }
934         
935         /* This will fail - but the error should be ERRnoaccess, not ERRbadshare. */
936         fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
937         
938         if (check_error(__location__, cli1, ERRDOS, ERRnoaccess, 
939                         NT_STATUS_ACCESS_DENIED)) {
940                 printf("correct error code ERRDOS/ERRnoaccess returned\n");
941         }
942         
943         printf("finished open test 1\n");
944 error_test1:
945         smbcli_close(cli1->tree, fnum1);
946         
947         /* Now try not readonly and ensure ERRbadshare is returned. */
948         
949         smbcli_setatr(cli1->tree, fname, 0, 0);
950         
951         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_WRITE);
952         if (fnum1 == -1) {
953                 printf("open of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
954                 return False;
955         }
956         
957         /* This will fail - but the error should be ERRshare. */
958         fnum2 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_ALL);
959         
960         if (check_error(__location__, cli1, ERRDOS, ERRbadshare, 
961                         NT_STATUS_SHARING_VIOLATION)) {
962                 printf("correct error code ERRDOS/ERRbadshare returned\n");
963         }
964         
965         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
966                 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
967                 return False;
968         }
969         
970         smbcli_unlink(cli1->tree, fname);
971         
972         printf("finished open test 2\n");
973         
974         /* Test truncate open disposition on file opened for read. */
975         
976         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
977         if (fnum1 == -1) {
978                 printf("(3) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
979                 return False;
980         }
981         
982         /* write 20 bytes. */
983         
984         memset(buf, '\0', 20);
985
986         if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
987                 printf("write failed (%s)\n", smbcli_errstr(cli1->tree));
988                 correct = False;
989         }
990
991         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
992                 printf("(3) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
993                 return False;
994         }
995         
996         /* Ensure size == 20. */
997         if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
998                 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
999                 CHECK_MAX_FAILURES(error_test3);
1000                 return False;
1001         }
1002         
1003         if (fsize != 20) {
1004                 printf("(3) file size != 20\n");
1005                 CHECK_MAX_FAILURES(error_test3);
1006                 return False;
1007         }
1008
1009         /* Now test if we can truncate a file opened for readonly. */
1010         
1011         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY|O_TRUNC, DENY_NONE);
1012         if (fnum1 == -1) {
1013                 printf("(3) open (2) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1014                 CHECK_MAX_FAILURES(error_test3);
1015                 return False;
1016         }
1017         
1018         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1019                 printf("close2 failed (%s)\n", smbcli_errstr(cli1->tree));
1020                 return False;
1021         }
1022
1023         /* Ensure size == 0. */
1024         if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1025                 printf("(3) getatr failed (%s)\n", smbcli_errstr(cli1->tree));
1026                 CHECK_MAX_FAILURES(error_test3);
1027                 return False;
1028         }
1029
1030         if (fsize != 0) {
1031                 printf("(3) file size != 0\n");
1032                 CHECK_MAX_FAILURES(error_test3);
1033                 return False;
1034         }
1035         printf("finished open test 3\n");
1036 error_test3:    
1037         smbcli_unlink(cli1->tree, fname);
1038
1039
1040         printf("testing ctemp\n");
1041         fnum1 = smbcli_ctemp(cli1->tree, "\\", &tmp_path);
1042         if (fnum1 == -1) {
1043                 printf("ctemp failed (%s)\n", smbcli_errstr(cli1->tree));
1044                 CHECK_MAX_FAILURES(error_test4);
1045                 return False;
1046         }
1047         printf("ctemp gave path %s\n", tmp_path);
1048         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1049                 printf("close of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1050         }
1051         if (NT_STATUS_IS_ERR(smbcli_unlink(cli1->tree, tmp_path))) {
1052                 printf("unlink of temp failed (%s)\n", smbcli_errstr(cli1->tree));
1053         }
1054 error_test4:    
1055         /* Test the non-io opens... */
1056
1057         if (!torture_open_connection(&cli2)) {
1058                 return False;
1059         }
1060         
1061         smbcli_setatr(cli2->tree, fname, 0, 0);
1062         smbcli_unlink(cli2->tree, fname);
1063         
1064         printf("TEST #1 testing 2 non-io opens (no delete)\n");
1065         
1066         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1067                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1068
1069         if (fnum1 == -1) {
1070                 printf("test 1 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1071                 CHECK_MAX_FAILURES(error_test10);
1072                 return False;
1073         }
1074
1075         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1076                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1077         if (fnum2 == -1) {
1078                 printf("test 1 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1079                 CHECK_MAX_FAILURES(error_test10);
1080                 return False;
1081         }
1082
1083         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1084                 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1085                 return False;
1086         }
1087         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1088                 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1089                 return False;
1090         }
1091
1092         printf("non-io open test #1 passed.\n");
1093 error_test10:
1094         smbcli_unlink(cli1->tree, fname);
1095
1096         printf("TEST #2 testing 2 non-io opens (first with delete)\n");
1097         
1098         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1099                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1100
1101         if (fnum1 == -1) {
1102                 printf("test 2 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1103                 CHECK_MAX_FAILURES(error_test20);
1104                 return False;
1105         }
1106
1107         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1108                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1109
1110         if (fnum2 == -1) {
1111                 printf("test 2 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1112                 CHECK_MAX_FAILURES(error_test20);
1113                 return False;
1114         }
1115
1116         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1117                 printf("test 1 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1118                 return False;
1119         }
1120         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1121                 printf("test 1 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1122                 return False;
1123         }
1124
1125         printf("non-io open test #2 passed.\n");
1126 error_test20:
1127         smbcli_unlink(cli1->tree, fname);
1128
1129         printf("TEST #3 testing 2 non-io opens (second with delete)\n");
1130         
1131         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1132                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1133
1134         if (fnum1 == -1) {
1135                 printf("test 3 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1136                 CHECK_MAX_FAILURES(error_test30);
1137                 return False;
1138         }
1139
1140         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1141                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1142
1143         if (fnum2 == -1) {
1144                 printf("test 3 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1145                 CHECK_MAX_FAILURES(error_test30);
1146                 return False;
1147         }
1148
1149         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1150                 printf("test 3 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1151                 return False;
1152         }
1153         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1154                 printf("test 3 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1155                 return False;
1156         }
1157
1158         printf("non-io open test #3 passed.\n");
1159 error_test30:
1160         smbcli_unlink(cli1->tree, fname);
1161
1162         printf("TEST #4 testing 2 non-io opens (both with delete)\n");
1163         
1164         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1165                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1166
1167         if (fnum1 == -1) {
1168                 printf("test 4 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1169                 CHECK_MAX_FAILURES(error_test40);
1170                 return False;
1171         }
1172
1173         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1174                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1175
1176         if (fnum2 != -1) {
1177                 printf("test 4 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1178                 CHECK_MAX_FAILURES(error_test40);
1179                 return False;
1180         }
1181
1182         printf("test 4 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1183
1184         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1185                 printf("test 4 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1186                 return False;
1187         }
1188
1189         printf("non-io open test #4 passed.\n");
1190 error_test40:
1191         smbcli_unlink(cli1->tree, fname);
1192
1193         printf("TEST #5 testing 2 non-io opens (both with delete - both with file share delete)\n");
1194         
1195         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1196                                    NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1197
1198         if (fnum1 == -1) {
1199                 printf("test 5 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1200                 CHECK_MAX_FAILURES(error_test50);
1201                 return False;
1202         }
1203
1204         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1205                                    NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1206
1207         if (fnum2 == -1) {
1208                 printf("test 5 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1209                 CHECK_MAX_FAILURES(error_test50);
1210                 return False;
1211         }
1212
1213         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1214                 printf("test 5 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1215                 return False;
1216         }
1217
1218         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1219                 printf("test 5 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1220                 return False;
1221         }
1222
1223         printf("non-io open test #5 passed.\n");
1224 error_test50:
1225         printf("TEST #6 testing 1 non-io open, one io open\n");
1226         
1227         smbcli_unlink(cli1->tree, fname);
1228
1229         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1230                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1231
1232         if (fnum1 == -1) {
1233                 printf("test 6 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1234                 CHECK_MAX_FAILURES(error_test60);
1235                 return False;
1236         }
1237
1238         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1239                                    NTCREATEX_SHARE_ACCESS_READ, NTCREATEX_DISP_OPEN_IF, 0, 0);
1240
1241         if (fnum2 == -1) {
1242                 printf("test 6 open 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1243                 CHECK_MAX_FAILURES(error_test60);
1244                 return False;
1245         }
1246
1247         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1248                 printf("test 6 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1249                 return False;
1250         }
1251
1252         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
1253                 printf("test 6 close 2 of %s failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1254                 return False;
1255         }
1256
1257         printf("non-io open test #6 passed.\n");
1258 error_test60:
1259         printf("TEST #7 testing 1 non-io open, one io open with delete\n");
1260
1261         smbcli_unlink(cli1->tree, fname);
1262
1263         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SEC_FILE_READ_DATA, FILE_ATTRIBUTE_NORMAL,
1264                                    NTCREATEX_SHARE_ACCESS_NONE, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
1265
1266         if (fnum1 == -1) {
1267                 printf("test 7 open 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1268                 CHECK_MAX_FAILURES(error_test70);
1269                 return False;
1270         }
1271
1272         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SEC_STD_DELETE|SEC_FILE_READ_ATTRIBUTE, FILE_ATTRIBUTE_NORMAL,
1273                                    NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN_IF, 0, 0);
1274
1275         if (fnum2 != -1) {
1276                 printf("test 7 open 2 of %s SUCCEEDED - should have failed (%s)\n", fname, smbcli_errstr(cli2->tree));
1277                 CHECK_MAX_FAILURES(error_test70);
1278                 return False;
1279         }
1280
1281         printf("test 7 open 2 of %s gave %s (correct error should be %s)\n", fname, smbcli_errstr(cli2->tree), "sharing violation");
1282
1283         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1284                 printf("test 7 close 1 of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1285                 return False;
1286         }
1287
1288         printf("non-io open test #7 passed.\n");
1289
1290 error_test70:
1291
1292         printf("TEST #8 testing one normal open, followed by lock, followed by open with truncate\n");
1293
1294         smbcli_unlink(cli1->tree, fname);
1295
1296         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
1297         if (fnum1 == -1) {
1298                 printf("(8) open (1) of %s failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1299                 return False;
1300         }
1301         
1302         /* write 20 bytes. */
1303         
1304         memset(buf, '\0', 20);
1305
1306         if (smbcli_write(cli1->tree, fnum1, 0, buf, 0, 20) != 20) {
1307                 printf("(8) write failed (%s)\n", smbcli_errstr(cli1->tree));
1308                 correct = False;
1309         }
1310
1311         /* Ensure size == 20. */
1312         if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1313                 printf("(8) getatr (1) failed (%s)\n", smbcli_errstr(cli1->tree));
1314                 CHECK_MAX_FAILURES(error_test80);
1315                 return False;
1316         }
1317         
1318         if (fsize != 20) {
1319                 printf("(8) file size != 20\n");
1320                 CHECK_MAX_FAILURES(error_test80);
1321                 return False;
1322         }
1323
1324         /* Get an exclusive lock on the open file. */
1325         if (NT_STATUS_IS_ERR(smbcli_lock(cli1->tree, fnum1, 0, 4, 0, WRITE_LOCK))) {
1326                 printf("(8) lock1 failed (%s)\n", smbcli_errstr(cli1->tree));
1327                 CHECK_MAX_FAILURES(error_test80);
1328                 return False;
1329         }
1330
1331         fnum2 = smbcli_open(cli1->tree, fname, O_RDWR|O_TRUNC, DENY_NONE);
1332         if (fnum1 == -1) {
1333                 printf("(8) open (2) of %s with truncate failed (%s)\n", fname, smbcli_errstr(cli1->tree));
1334                 return False;
1335         }
1336
1337         /* Ensure size == 0. */
1338         if (NT_STATUS_IS_ERR(smbcli_getatr(cli1->tree, fname, NULL, &fsize, NULL))) {
1339                 printf("(8) getatr (2) failed (%s)\n", smbcli_errstr(cli1->tree));
1340                 CHECK_MAX_FAILURES(error_test80);
1341                 return False;
1342         }
1343         
1344         if (fsize != 0) {
1345                 printf("(8) file size != 0\n");
1346                 CHECK_MAX_FAILURES(error_test80);
1347                 return False;
1348         }
1349
1350         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
1351                 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1352                 return False;
1353         }
1354         
1355         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
1356                 printf("(8) close1 failed (%s)\n", smbcli_errstr(cli1->tree));
1357                 return False;
1358         }
1359         
1360 error_test80:
1361
1362         printf("open test #8 passed.\n");
1363
1364         smbcli_unlink(cli1->tree, fname);
1365
1366         if (!torture_close_connection(cli1)) {
1367                 correct = False;
1368         }
1369         if (!torture_close_connection(cli2)) {
1370                 correct = False;
1371         }
1372         
1373         return correct;
1374 }
1375
1376 /* FIRST_DESIRED_ACCESS   0xf019f */
1377 #define FIRST_DESIRED_ACCESS   SEC_FILE_READ_DATA|SEC_FILE_WRITE_DATA|SEC_FILE_APPEND_DATA|\
1378                                SEC_FILE_READ_EA|                           /* 0xf */ \
1379                                SEC_FILE_WRITE_EA|SEC_FILE_READ_ATTRIBUTE|     /* 0x90 */ \
1380                                SEC_FILE_WRITE_ATTRIBUTE|                  /* 0x100 */ \
1381                                SEC_STD_DELETE|SEC_STD_READ_CONTROL|\
1382                                SEC_STD_WRITE_DAC|SEC_STD_WRITE_OWNER     /* 0xf0000 */
1383 /* SECOND_DESIRED_ACCESS  0xe0080 */
1384 #define SECOND_DESIRED_ACCESS  SEC_FILE_READ_ATTRIBUTE|                   /* 0x80 */ \
1385                                SEC_STD_READ_CONTROL|SEC_STD_WRITE_DAC|\
1386                                SEC_STD_WRITE_OWNER                      /* 0xe0000 */
1387
1388 #if 0
1389 #define THIRD_DESIRED_ACCESS   FILE_READ_ATTRIBUTE|                   /* 0x80 */ \
1390                                READ_CONTROL|WRITE_DAC|\
1391                                SEC_FILE_READ_DATA|\
1392                                WRITE_OWNER                      /* */
1393 #endif
1394
1395
1396
1397 /**
1398   Test ntcreate calls made by xcopy
1399  */
1400 static BOOL run_xcopy(struct torture_context *torture)
1401 {
1402         struct smbcli_state *cli1;
1403         const char *fname = "\\test.txt";
1404         BOOL correct = True;
1405         int fnum1, fnum2;
1406
1407         printf("starting xcopy test\n");
1408         
1409         if (!torture_open_connection(&cli1)) {
1410                 return False;
1411         }
1412         
1413         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
1414                                       FIRST_DESIRED_ACCESS, 
1415                                       FILE_ATTRIBUTE_ARCHIVE,
1416                                       NTCREATEX_SHARE_ACCESS_NONE, 
1417                                       NTCREATEX_DISP_OVERWRITE_IF, 
1418                                       0x4044, 0);
1419
1420         if (fnum1 == -1) {
1421                 printf("First open failed - %s\n", smbcli_errstr(cli1->tree));
1422                 return False;
1423         }
1424
1425         fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0,
1426                                    SECOND_DESIRED_ACCESS, 0,
1427                                    NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 
1428                                    0x200000, 0);
1429         if (fnum2 == -1) {
1430                 printf("second open failed - %s\n", smbcli_errstr(cli1->tree));
1431                 return False;
1432         }
1433         
1434         if (!torture_close_connection(cli1)) {
1435                 correct = False;
1436         }
1437         
1438         return correct;
1439 }
1440
1441 static BOOL run_iometer(struct torture_context *torture)
1442 {
1443         struct smbcli_state *cli;
1444         const char *fname = "\\iobw.tst";
1445         int fnum;
1446         size_t filesize;
1447         NTSTATUS status;
1448         char buf[2048];
1449         int ops;
1450         BOOL result = False;
1451
1452         printf("Starting iometer test\n");
1453
1454         memset(buf, 0, sizeof(buf));
1455
1456         if (!torture_open_connection(&cli)) {
1457                 return False;
1458         }
1459
1460         status = smbcli_getatr(cli->tree, fname, NULL, &filesize, NULL);
1461         if (!NT_STATUS_IS_OK(status)) {
1462                 printf("smbcli_getatr failed: %s\n", nt_errstr(status));
1463                 goto done;
1464         }
1465
1466         printf("size: %d\n", filesize);
1467
1468         filesize -= (sizeof(buf) - 1);
1469
1470         fnum = smbcli_nt_create_full(cli->tree, fname, 0x16,
1471                                      0x2019f, 0, 0x3, 3, 0x42, 0x3);
1472         if (fnum == -1) {
1473                 printf("open failed: %s\n", smbcli_errstr(cli->tree));
1474                 goto done;
1475         }
1476
1477         ops = 0;
1478
1479         while (True) {
1480                 int i, num_reads, num_writes;
1481
1482                 num_reads = random() % 10;
1483                 num_writes = random() % 3;
1484
1485                 for (i=0; i<num_reads; i++) {
1486                         ssize_t res;
1487                         if (ops++ > torture_numops) {
1488                                 result = True;
1489                                 goto done;
1490                         }
1491                         res = smbcli_read(cli->tree, fnum, buf,
1492                                           random() % filesize, sizeof(buf));
1493                         if (res != sizeof(buf)) {
1494                                 printf("read failed: %s\n",
1495                                        smbcli_errstr(cli->tree));
1496                                 goto done;
1497                         }
1498                 }
1499                 for (i=0; i<num_writes; i++) {
1500                         ssize_t res;
1501                         if (ops++ > torture_numops) {
1502                                 result = True;
1503                                 goto done;
1504                         }
1505                         res = smbcli_write(cli->tree, fnum, 0, buf,
1506                                           random() % filesize, sizeof(buf));
1507                         if (res != sizeof(buf)) {
1508                                 printf("read failed: %s\n",
1509                                        smbcli_errstr(cli->tree));
1510                                 goto done;
1511                         }
1512                 }
1513         }
1514
1515         result = True;
1516  done:
1517
1518         if (!torture_close_connection(cli)) {
1519                 printf("close_connection failed: %s\n",
1520                        smbcli_errstr(cli->tree));
1521                 return False;
1522         }
1523
1524         return result;
1525 }
1526
1527 /**
1528   tries variants of chkpath
1529  */
1530 static BOOL torture_chkpath_test(struct torture_context *torture)
1531 {
1532         struct smbcli_state *cli;
1533         int fnum;
1534         BOOL ret;
1535
1536         if (!torture_open_connection(&cli)) {
1537                 return False;
1538         }
1539
1540         printf("starting chkpath test\n");
1541
1542         printf("Testing valid and invalid paths\n");
1543
1544         /* cleanup from an old run */
1545         smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1546         smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1547         smbcli_rmdir(cli->tree, "\\chkpath.dir");
1548
1549         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir"))) {
1550                 printf("mkdir1 failed : %s\n", smbcli_errstr(cli->tree));
1551                 return False;
1552         }
1553
1554         if (NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, "\\chkpath.dir\\dir2"))) {
1555                 printf("mkdir2 failed : %s\n", smbcli_errstr(cli->tree));
1556                 return False;
1557         }
1558
1559         fnum = smbcli_open(cli->tree, "\\chkpath.dir\\foo.txt", O_RDWR|O_CREAT|O_EXCL, DENY_NONE);
1560         if (fnum == -1) {
1561                 printf("open1 failed (%s)\n", smbcli_errstr(cli->tree));
1562                 return False;
1563         }
1564         smbcli_close(cli->tree, fnum);
1565
1566         if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir"))) {
1567                 printf("chkpath1 failed: %s\n", smbcli_errstr(cli->tree));
1568                 ret = False;
1569         }
1570
1571         if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dir2"))) {
1572                 printf("chkpath2 failed: %s\n", smbcli_errstr(cli->tree));
1573                 ret = False;
1574         }
1575
1576         if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\foo.txt"))) {
1577                 ret = check_error(__location__, cli, ERRDOS, ERRbadpath, 
1578                                   NT_STATUS_NOT_A_DIRECTORY);
1579         } else {
1580                 printf("* chkpath on a file should fail\n");
1581                 ret = False;
1582         }
1583
1584         if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\bar.txt"))) {
1585                 ret = check_error(__location__, cli, ERRDOS, ERRbadpath, 
1586                                   NT_STATUS_OBJECT_NAME_NOT_FOUND);
1587         } else {
1588                 printf("* chkpath on a non existent file should fail\n");
1589                 ret = False;
1590         }
1591
1592         if (NT_STATUS_IS_ERR(smbcli_chkpath(cli->tree, "\\chkpath.dir\\dirxx\\bar.txt"))) {
1593                 ret = check_error(__location__, cli, ERRDOS, ERRbadpath, 
1594                                   NT_STATUS_OBJECT_PATH_NOT_FOUND);
1595         } else {
1596                 printf("* chkpath on a non existent component should fail\n");
1597                 ret = False;
1598         }
1599
1600         smbcli_rmdir(cli->tree, "\\chkpath.dir\\dir2");
1601         smbcli_unlink(cli->tree, "\\chkpath.dir\\*");
1602         smbcli_rmdir(cli->tree, "\\chkpath.dir");
1603
1604         if (!torture_close_connection(cli)) {
1605                 return False;
1606         }
1607
1608         return ret;
1609 }
1610
1611 /*
1612  * This is a test to excercise some weird Samba3 error paths.
1613  */
1614
1615 static BOOL torture_samba3_errorpaths(struct torture_context *torture)
1616 {
1617         BOOL nt_status_support;
1618         struct smbcli_state *cli_nt = NULL, *cli_dos = NULL;
1619         BOOL result = False;
1620         int fnum;
1621         const char *os2_fname = ".+,;=[].";
1622         const char *dirname = "samba3_errordir";
1623         union smb_open io;
1624         TALLOC_CTX *mem_ctx = talloc_init(NULL);
1625         NTSTATUS status;
1626
1627         if (mem_ctx == NULL) {
1628                 printf("talloc_init failed\n");
1629                 return False;
1630         }
1631
1632         nt_status_support = lp_nt_status_support();
1633
1634         if (!lp_set_cmdline("nt status support", "yes")) {
1635                 printf("Could not set 'nt status support = yes'\n");
1636                 goto fail;
1637         }
1638
1639         if (!torture_open_connection(&cli_nt)) {
1640                 goto fail;
1641         }
1642
1643         if (!lp_set_cmdline("nt status support", "no")) {
1644                 printf("Could not set 'nt status support = yes'\n");
1645                 goto fail;
1646         }
1647
1648         if (!torture_open_connection(&cli_dos)) {
1649                 goto fail;
1650         }
1651
1652         if (!lp_set_cmdline("nt status support",
1653                             nt_status_support ? "yes":"no")) {
1654                 printf("Could not reset 'nt status support = yes'");
1655                 goto fail;
1656         }
1657
1658         smbcli_unlink(cli_nt->tree, os2_fname);
1659         smbcli_rmdir(cli_nt->tree, dirname);
1660
1661         if (!NT_STATUS_IS_OK(smbcli_mkdir(cli_nt->tree, dirname))) {
1662                 printf("smbcli_mkdir(%s) failed: %s\n", dirname,
1663                        smbcli_errstr(cli_nt->tree));
1664                 goto fail;
1665         }
1666
1667         io.generic.level = RAW_OPEN_NTCREATEX;
1668         io.ntcreatex.in.flags = NTCREATEX_FLAGS_EXTENDED;
1669         io.ntcreatex.in.root_fid = 0;
1670         io.ntcreatex.in.access_mask = SEC_RIGHTS_FILE_ALL;
1671         io.ntcreatex.in.alloc_size = 1024*1024;
1672         io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_DIRECTORY;
1673         io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_NONE;
1674         io.ntcreatex.in.open_disposition = NTCREATEX_DISP_CREATE;
1675         io.ntcreatex.in.create_options = 0;
1676         io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_ANONYMOUS;
1677         io.ntcreatex.in.security_flags = 0;
1678         io.ntcreatex.in.fname = dirname;
1679
1680         status = smb_raw_open(cli_nt->tree, mem_ctx, &io);
1681         if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1682                 printf("(%s) incorrect status %s should be %s\n",
1683                        __location__, nt_errstr(status),
1684                        nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1685                 goto fail;
1686         }
1687         status = smb_raw_open(cli_dos->tree, mem_ctx, &io);
1688         if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRfilexists))) {
1689                 printf("(%s) incorrect status %s should be %s\n",
1690                        __location__, nt_errstr(status),
1691                        nt_errstr(NT_STATUS_DOS(ERRDOS, ERRfilexists)));
1692                 goto fail;
1693         }
1694
1695         status = smbcli_mkdir(cli_nt->tree, dirname);
1696         if (!NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
1697                 printf("(%s) incorrect status %s should be %s\n",
1698                        __location__, nt_errstr(status),
1699                        nt_errstr(NT_STATUS_OBJECT_NAME_COLLISION));
1700                 goto fail;
1701         }
1702         status = smbcli_mkdir(cli_dos->tree, dirname);
1703         if (!NT_STATUS_EQUAL(status, NT_STATUS_DOS(ERRDOS, ERRnoaccess))) {
1704                 printf("(%s) incorrect status %s should be %s\n",
1705                        __location__, nt_errstr(status),
1706                        nt_errstr(NT_STATUS_DOS(ERRDOS, ERRnoaccess)));
1707                 goto fail;
1708         }
1709
1710         {
1711                 /* Test an invalid DOS deny mode */
1712                 const char *fname = "test.txt";
1713
1714                 fnum = smbcli_open(cli_nt->tree, fname, O_RDWR | O_CREAT, 5);
1715                 if (fnum != -1) {
1716                         printf("Open(%s) with invalid deny mode succeeded -- "
1717                                "expected failure\n", fname);
1718                         smbcli_close(cli_nt->tree, fnum);
1719                         goto fail;
1720                 }
1721                 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1722                                      NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1723                         printf("Expected DOS error ERRDOS/ERRbadaccess, "
1724                                "got %s\n", smbcli_errstr(cli_nt->tree));
1725                         goto fail;
1726                 }
1727
1728                 fnum = smbcli_open(cli_dos->tree, fname, O_RDWR | O_CREAT, 5);
1729                 if (fnum != -1) {
1730                         printf("Open(%s) with invalid deny mode succeeded -- "
1731                                "expected failure\n", fname);
1732                         smbcli_close(cli_nt->tree, fnum);
1733                         goto fail;
1734                 }
1735                 if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1736                                      NT_STATUS_DOS(ERRDOS,ERRbadaccess))) {
1737                         printf("Expected DOS error ERRDOS:ERRbadaccess, "
1738                                "got %s\n", smbcli_errstr(cli_nt->tree));
1739                         goto fail;
1740                 }
1741         }
1742
1743         if (!lp_parm_bool(-1, "target", "samba3", False)) {
1744                 goto done;
1745         }
1746
1747         fnum = smbcli_open(cli_dos->tree, os2_fname, 
1748                            O_RDWR | O_CREAT | O_TRUNC,
1749                            DENY_NONE);
1750         if (fnum != -1) {
1751                 printf("Open(%s) succeeded -- expected failure\n",
1752                        os2_fname);
1753                 smbcli_close(cli_dos->tree, fnum);
1754                 goto fail;
1755         }
1756
1757         if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_dos->tree),
1758                              NT_STATUS_DOS(ERRDOS, ERRcannotopen))) {
1759                 printf("Expected DOS error ERRDOS/ERRcannotopen, got %s\n",
1760                        smbcli_errstr(cli_dos->tree));
1761                 goto fail;
1762         }
1763
1764         fnum = smbcli_open(cli_nt->tree, os2_fname, 
1765                            O_RDWR | O_CREAT | O_TRUNC,
1766                            DENY_NONE);
1767         if (fnum != -1) {
1768                 printf("Open(%s) succeeded -- expected failure\n",
1769                        os2_fname);
1770                 smbcli_close(cli_nt->tree, fnum);
1771                 goto fail;
1772         }
1773
1774         if (!NT_STATUS_EQUAL(smbcli_nt_error(cli_nt->tree),
1775                              NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
1776                 printf("Expected error NT_STATUS_OBJECT_NAME_NOT_FOUND, "
1777                        "got %s\n", smbcli_errstr(cli_nt->tree));
1778                 goto fail;
1779         }
1780
1781  done:
1782         result = True;
1783
1784  fail:
1785         if (cli_dos != NULL) {
1786                 torture_close_connection(cli_dos);
1787         }
1788         if (cli_nt != NULL) {
1789                 torture_close_connection(cli_nt);
1790         }
1791         
1792         return result;
1793 }
1794
1795
1796 NTSTATUS torture_base_init(void)
1797 {
1798         register_torture_op("BASE-FDPASS", run_fdpasstest, 0);
1799         register_torture_op("BASE-LOCK1",  torture_locktest1,  0);
1800         register_torture_op("BASE-LOCK2",  torture_locktest2,  0);
1801         register_torture_op("BASE-LOCK3",  torture_locktest3,  0);
1802         register_torture_op("BASE-LOCK4",  torture_locktest4,  0);
1803         register_torture_op("BASE-LOCK5",  torture_locktest5,  0);
1804         register_torture_op("BASE-LOCK6",  torture_locktest6,  0);
1805         register_torture_op("BASE-LOCK7",  torture_locktest7,  0);
1806         register_torture_op("BASE-UNLINK", torture_unlinktest, 0);
1807         register_torture_op("BASE-ATTR",   run_attrtest,   0);
1808         register_torture_op("BASE-TRANS2", run_trans2test, 0);
1809         register_torture_op("BASE-NEGNOWAIT", run_negprot_nowait, 0);
1810         register_torture_op("BASE-DIR1",  torture_dirtest1, 0);
1811         register_torture_op("BASE-DIR2",  torture_dirtest2, 0);
1812         register_torture_op("BASE-DENY1",  torture_denytest1, 0);
1813         register_torture_op("BASE-DENY2",  torture_denytest2, 0);
1814         register_torture_op("BASE-DENY3",  torture_denytest3, 0);
1815         register_torture_op("BASE-DENYDOS",  torture_denydos_sharing, 0);
1816         register_torture_op("BASE-NTDENY1",  NULL, torture_ntdenytest1);
1817         register_torture_op("BASE-NTDENY2",  torture_ntdenytest2, 0);
1818         register_torture_op("BASE-TCON",  run_tcon_test, 0);
1819         register_torture_op("BASE-TCONDEV",  run_tcon_devtype_test, 0);
1820         register_torture_op("BASE-VUID", run_vuidtest, 0);
1821         register_torture_op("BASE-RW1",  run_readwritetest, 0);
1822         register_torture_op("BASE-OPEN", run_opentest, 0);
1823         register_torture_op("BASE-DEFER_OPEN", NULL, run_deferopen);
1824         register_torture_op("BASE-XCOPY", run_xcopy, 0);
1825         register_torture_op("BASE-IOMETER", run_iometer, 0);
1826         register_torture_op("BASE-RENAME", torture_test_rename, 0);
1827         register_torture_op("BASE-DELETE", torture_test_delete, 0);
1828         register_torture_op("BASE-PROPERTIES", torture_test_properties, 0);
1829         register_torture_op("BASE-MANGLE", torture_mangle, 0);
1830         register_torture_op("BASE-OPENATTR", torture_openattrtest, 0);
1831         register_torture_op("BASE-CHARSET", torture_charset, 0);
1832         register_torture_op("BASE-CHKPATH",  torture_chkpath_test, 0);
1833         register_torture_op("BASE-SECLEAK",  torture_sec_leak, 0);
1834         register_torture_op("BASE-DISCONNECT",  torture_disconnect, 0);
1835         register_torture_op("BASE-DELAYWRITE", torture_delay_write, 0);
1836         register_torture_op("BASE-SAMBA3ERROR", torture_samba3_errorpaths, 0);
1837
1838         register_torture_op("SCAN-CASETABLE", torture_casetable, 0);
1839         register_torture_op("SCAN-UTABLE", torture_utable, 0);
1840         register_torture_op("SCAN-SMB", torture_smb_scan, 0);
1841         register_torture_op("SCAN-ALIASES", torture_trans2_aliases, 0);
1842         register_torture_op("SCAN-TRANS2", torture_trans2_scan, 0);
1843         register_torture_op("SCAN-NTTRANS", torture_nttrans_scan, 0);
1844
1845         return NT_STATUS_OK;
1846 }