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