225a73736e92d9fdf58e1f7b32cb4e01cd7f9654
[abartlet/samba.git/.git] / source4 / torture / basic / delete.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    delete on close testing
5
6    Copyright (C) Andrew Tridgell 2003
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24
25
26 /*
27   Test delete on close semantics.
28  */
29 BOOL torture_test_delete(int dummy)
30 {
31         struct smbcli_state *cli1;
32         struct smbcli_state *cli2 = NULL;
33         const char *fname = "\\delete.file";
34         int fnum1 = -1;
35         int fnum2 = -1;
36         BOOL correct = True;
37         NTSTATUS status;
38         
39         printf("starting delete test\n");
40         
41         if (!torture_open_connection(&cli1)) {
42                 return False;
43         }
44
45         /* Test 1 - this should delete the file on close. */
46         
47         smbcli_setatr(cli1->tree, fname, 0, 0);
48         smbcli_unlink(cli1->tree, fname);
49         
50         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_NORMAL,
51                                    NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 
52                                    NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
53         
54         if (fnum1 == -1) {
55                 printf("(%s) open of %s failed (%s)\n", 
56                        __location__, fname, smbcli_errstr(cli1->tree));
57                 correct = False;
58                 goto fail;
59         }
60         
61         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
62                 printf("(%s) close failed (%s)\n", 
63                        __location__, smbcli_errstr(cli1->tree));
64                 correct = False;
65                 goto fail;
66         }
67
68         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR, DENY_NONE);
69         if (fnum1 != -1) {
70                 printf("(%s) open of %s succeeded (should fail)\n", 
71                        __location__, fname);
72                 correct = False;
73                 goto fail;
74         }
75         
76         printf("first delete on close test succeeded.\n");
77         
78         /* Test 2 - this should delete the file on close. */
79         
80         smbcli_setatr(cli1->tree, fname, 0, 0);
81         smbcli_unlink(cli1->tree, fname);
82         
83         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS,
84                                    FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_NONE, 
85                                    NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
86         
87         if (fnum1 == -1) {
88                 printf("(%s) open of %s failed (%s)\n", 
89                        __location__, fname, smbcli_errstr(cli1->tree));
90                 correct = False;
91                 goto fail;
92         }
93         
94         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
95                 printf("(%s) setting delete_on_close failed (%s)\n", 
96                        __location__, smbcli_errstr(cli1->tree));
97                 correct = False;
98                 goto fail;
99         }
100         
101         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
102                 printf("(%s) close failed (%s)\n", 
103                        __location__, smbcli_errstr(cli1->tree));
104                 correct = False;
105                 goto fail;
106         }
107         
108         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE);
109         if (fnum1 != -1) {
110                 printf("(%s) open of %s succeeded should have been deleted on close !\n", 
111                        __location__, fname);
112                 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
113                         printf("(%s) close failed (%s)\n", 
114                                __location__, smbcli_errstr(cli1->tree));
115                         correct = False;
116                         goto fail;
117                 }
118                 smbcli_unlink(cli1->tree, fname);
119         } else
120                 printf("second delete on close test succeeded.\n");
121         
122         /* Test 3 - ... */
123         smbcli_setatr(cli1->tree, fname, 0, 0);
124         smbcli_unlink(cli1->tree, fname);
125
126         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
127                                       GENERIC_RIGHTS_FILE_ALL_ACCESS, 
128                                       FILE_ATTRIBUTE_NORMAL,
129                                       NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, 
130                                       NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
131
132         if (fnum1 == -1) {
133                 printf("(%s) open - 1 of %s failed (%s)\n", 
134                        __location__, fname, smbcli_errstr(cli1->tree));
135                 correct = False;
136                 goto fail;
137         }
138
139         /* This should fail with a sharing violation - open for delete is only compatible
140            with SHARE_DELETE. */
141
142         fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, 
143                                       GENERIC_RIGHTS_FILE_READ, 
144                                       FILE_ATTRIBUTE_NORMAL,
145                                       NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, 
146                                       NTCREATEX_DISP_OPEN, 0, 0);
147
148         if (fnum2 != -1) {
149                 printf("(%s) open  - 2 of %s succeeded - should have failed.\n", 
150                        __location__, fname);
151                 correct = False;
152                 goto fail;
153         }
154
155         /* This should succeed. */
156
157         fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, GENERIC_RIGHTS_FILE_READ, FILE_ATTRIBUTE_NORMAL,
158                         NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OPEN, 0, 0);
159
160         if (fnum2 == -1) {
161                 printf("(%s) open  - 2 of %s failed (%s)\n", 
162                        __location__, fname, smbcli_errstr(cli1->tree));
163                 correct = False;
164                 goto fail;
165         }
166
167         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
168                 printf("(%s) setting delete_on_close failed (%s)\n", 
169                        __location__, smbcli_errstr(cli1->tree));
170                 correct = False;
171                 goto fail;
172         }
173         
174         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
175                 printf("(%s) close 1 failed (%s)\n", 
176                        __location__, smbcli_errstr(cli1->tree));
177                 correct = False;
178                 goto fail;
179         }
180         
181         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
182                 printf("(%s) close 2 failed (%s)\n", 
183                        __location__, smbcli_errstr(cli1->tree));
184                 correct = False;
185                 goto fail;
186         }
187         
188         /* This should fail - file should no longer be there. */
189
190         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE);
191         if (fnum1 != -1) {
192                 printf("(%s) open of %s succeeded should have been deleted on close !\n", 
193                        __location__, fname);
194                 if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
195                         printf("(%s) close failed (%s)\n", 
196                                __location__, smbcli_errstr(cli1->tree));
197                 }
198                 smbcli_unlink(cli1->tree, fname);
199                 correct = False;
200                 goto fail;
201         } else
202                 printf("third delete on close test succeeded.\n");
203
204         /* Test 4 ... */
205         smbcli_setatr(cli1->tree, fname, 0, 0);
206         status = smbcli_unlink(cli1->tree, fname);
207         if (NT_STATUS_IS_OK(status)) {
208                 printf("(%s) succeeded unlink of %s\n", __location__, fname);
209                 correct = False;
210                 goto fail;
211         }
212
213         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
214                                    SA_RIGHT_FILE_READ_DATA  | 
215                                    SA_RIGHT_FILE_WRITE_DATA |
216                                    STD_RIGHT_DELETE_ACCESS,
217                                    FILE_ATTRIBUTE_NORMAL, 
218                                    NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE, 
219                                    NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
220                                                                 
221         if (fnum1 == -1) {
222                 printf("(%s) open of %s failed (%s)\n", 
223                        __location__, fname, smbcli_errstr(cli1->tree));
224                 correct = False;
225                 goto fail;
226         }
227
228         /* This should succeed. */
229         fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, GENERIC_RIGHTS_FILE_READ,
230                                       FILE_ATTRIBUTE_NORMAL, 
231                                       NTCREATEX_SHARE_ACCESS_READ  | 
232                                       NTCREATEX_SHARE_ACCESS_WRITE |
233                                       NTCREATEX_SHARE_ACCESS_DELETE, 
234                                       NTCREATEX_DISP_OPEN, 0, 0);
235         if (fnum2 == -1) {
236                 printf("(%s) open  - 2 of %s failed (%s)\n", 
237                        __location__, fname, smbcli_errstr(cli1->tree));
238                 correct = False;
239                 goto fail;
240         }
241         
242         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum2))) {
243                 printf("(%s) close - 1 failed (%s)\n", 
244                        __location__, smbcli_errstr(cli1->tree));
245                 correct = False;
246                 goto fail;
247         }
248         
249         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
250                 printf("(%s) setting delete_on_close failed (%s)\n", 
251                        __location__, smbcli_errstr(cli1->tree));
252                 correct = False;
253                 goto fail;
254         }
255         
256         /* This should fail - no more opens once delete on close set. */
257         fnum2 = smbcli_nt_create_full(cli1->tree, fname, 0, 
258                                       GENERIC_RIGHTS_FILE_READ,
259                                       FILE_ATTRIBUTE_NORMAL, 
260                                       NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
261                                       NTCREATEX_DISP_OPEN, 0, 0);
262         if (fnum2 != -1) {
263                 printf("(%s) open  - 3 of %s succeeded ! Should have failed.\n",
264                        __location__, fname );
265                 correct = False;
266                 goto fail;
267         } else
268                 printf("fourth delete on close test succeeded.\n");
269         
270         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
271                 printf("(%s) close - 2 failed (%s)\n", 
272                        __location__, smbcli_errstr(cli1->tree));
273                 correct = False;
274                 goto fail;
275         }
276         
277         /* Test 5 ... */
278         smbcli_setatr(cli1->tree, fname, 0, 0);
279         smbcli_unlink(cli1->tree, fname);
280         
281         fnum1 = smbcli_open(cli1->tree, fname, O_RDWR|O_CREAT, DENY_NONE);
282         if (fnum1 == -1) {
283                 printf("(%s) open of %s failed (%s)\n", 
284                        __location__, fname, smbcli_errstr(cli1->tree));
285                 correct = False;
286                 goto fail;
287         }
288
289         /* This should fail - only allowed on NT opens with DELETE access. */
290
291         if (NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
292                 printf("(%s) setting delete_on_close on OpenX file succeeded - should fail !\n",
293                        __location__);
294                 correct = False;
295                 goto fail;
296         }
297
298         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
299                 printf("(%s) close - 2 failed (%s)\n", 
300                        __location__, smbcli_errstr(cli1->tree));
301                 correct = False;
302                 goto fail;
303         }
304         
305         printf("fifth delete on close test succeeded.\n");
306         
307         /* Test 6 ... */
308         smbcli_setatr(cli1->tree, fname, 0, 0);
309         smbcli_unlink(cli1->tree, fname);
310         
311         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
312                                    SA_RIGHT_FILE_READ_DATA | SA_RIGHT_FILE_WRITE_DATA,
313                                    FILE_ATTRIBUTE_NORMAL, 
314                                    NTCREATEX_SHARE_ACCESS_READ  |
315                                    NTCREATEX_SHARE_ACCESS_WRITE |
316                                    NTCREATEX_SHARE_ACCESS_DELETE,
317                                    NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
318         
319         if (fnum1 == -1) {
320                 printf("(%s) open of %s failed (%s)\n", 
321                        __location__, fname, smbcli_errstr(cli1->tree));
322                 correct = False;
323                 goto fail;
324         }
325         
326         /* This should fail - only allowed on NT opens with DELETE access. */
327         
328         if (NT_STATUS_IS_OK(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
329                 printf("(%s) setting delete_on_close on file with no delete access succeeded - should fail !\n",
330                        __location__);
331                 correct = False;
332                 goto fail;
333         }
334
335         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
336                 printf("(%s) close - 2 failed (%s)\n", 
337                        __location__, smbcli_errstr(cli1->tree));
338                 correct = False;
339                 goto fail;
340         }
341
342         printf("sixth delete on close test succeeded.\n");
343         
344         /* Test 7 ... */
345         smbcli_setatr(cli1->tree, fname, 0, 0);
346         smbcli_unlink(cli1->tree, fname);
347         
348         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
349                                    SA_RIGHT_FILE_READ_DATA  | 
350                                    SA_RIGHT_FILE_WRITE_DATA |
351                                    STD_RIGHT_DELETE_ACCESS,
352                                    FILE_ATTRIBUTE_NORMAL, 0, NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
353                                                                 
354         if (fnum1 == -1) {
355                 printf("(%s) open of %s failed (%s)\n", 
356                        __location__, fname, smbcli_errstr(cli1->tree));
357                 correct = False;
358                 goto fail;
359         }
360
361         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
362                 printf("(%s) setting delete_on_close on file failed !\n",
363                        __location__);
364                 correct = False;
365                 goto fail;
366         }
367         
368         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, False))) {
369                 printf("(%s) unsetting delete_on_close on file failed !\n",
370                        __location__);
371                 correct = False;
372                 goto fail;
373         }
374
375         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
376                 printf("(%s) close - 2 failed (%s)\n", 
377                        __location__, smbcli_errstr(cli1->tree));
378                 correct = False;
379                 goto fail;
380         }
381         
382         /* This next open should succeed - we reset the flag. */
383         
384         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE);
385         if (fnum1 == -1) {
386                 printf("(%s) open of %s failed (%s)\n", 
387                        __location__, fname, smbcli_errstr(cli1->tree));
388                 correct = False;
389                 goto fail;
390         }
391
392         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
393                 printf("(%s) close - 2 failed (%s)\n", 
394                        __location__, smbcli_errstr(cli1->tree));
395                 correct = False;
396                 goto fail;
397         }
398
399         printf("seventh delete on close test succeeded.\n");
400         
401         /* Test 7 ... */
402         smbcli_setatr(cli1->tree, fname, 0, 0);
403         smbcli_unlink(cli1->tree, fname);
404         
405         if (!torture_open_connection(&cli2)) {
406                 printf("(%s) failed to open second connection.\n",
407                        __location__);
408                 correct = False;
409                 goto fail;
410         }
411
412         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
413                                    FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
414                                    NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
415         
416         if (fnum1 == -1) {
417                 printf("(%s) open of %s failed (%s)\n", 
418                        __location__, fname, smbcli_errstr(cli1->tree));
419                 correct = False;
420                 goto fail;
421         }
422
423         fnum2 = smbcli_nt_create_full(cli2->tree, fname, 0, SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
424                                    FILE_ATTRIBUTE_NORMAL, NTCREATEX_SHARE_ACCESS_READ|NTCREATEX_SHARE_ACCESS_WRITE|NTCREATEX_SHARE_ACCESS_DELETE,
425                                    NTCREATEX_DISP_OPEN, 0, 0);
426         
427         if (fnum2 == -1) {
428                 printf("(%s) open of %s failed (%s)\n", 
429                        __location__, fname, smbcli_errstr(cli1->tree));
430                 correct = False;
431                 goto fail;
432         }
433
434         if (NT_STATUS_IS_ERR(smbcli_nt_delete_on_close(cli1->tree, fnum1, True))) {
435                 printf("(%s) setting delete_on_close on file failed !\n",
436                        __location__);
437                 correct = False;
438                 goto fail;
439         }
440         
441         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
442                 printf("(%s) close - 1 failed (%s)\n", 
443                        __location__, smbcli_errstr(cli1->tree));
444                 correct = False;
445                 goto fail;
446         }
447
448         if (NT_STATUS_IS_ERR(smbcli_close(cli2->tree, fnum2))) {
449                 printf("(%s) close - 2 failed (%s)\n", 
450                        __location__, smbcli_errstr(cli2->tree));
451                 correct = False;
452                 goto fail;
453         }
454
455         /* This should fail.. */
456         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE);
457         if (fnum1 != -1) {
458                 printf("(%s) open of %s succeeded should have been deleted on close !\n",
459                        __location__, fname);
460                 goto fail;
461                 correct = False;
462         } else
463                 printf("eighth delete on close test succeeded.\n");
464
465         /* This should fail - we need to set DELETE_ACCESS. */
466         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0,
467                                       SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA,
468                                       FILE_ATTRIBUTE_NORMAL, 
469                                       NTCREATEX_SHARE_ACCESS_NONE, 
470                                       NTCREATEX_DISP_OVERWRITE_IF, 
471                                       NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
472         
473         if (fnum1 != -1) {
474                 printf("(%s) open of %s succeeded should have failed!\n", 
475                        __location__, fname);
476                 correct = False;
477                 goto fail;
478         }
479
480         printf("ninth delete on close test succeeded.\n");
481
482         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
483                                       SA_RIGHT_FILE_READ_DATA|SA_RIGHT_FILE_WRITE_DATA|STD_RIGHT_DELETE_ACCESS,
484                                       FILE_ATTRIBUTE_NORMAL, 
485                                       NTCREATEX_SHARE_ACCESS_NONE, 
486                                       NTCREATEX_DISP_OVERWRITE_IF, 
487                                       NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
488         if (fnum1 == -1) {
489                 printf("(%s) open of %s failed (%s)\n", 
490                        __location__, fname, smbcli_errstr(cli1->tree));
491                 correct = False;
492                 goto fail;
493         }
494
495         /* This should delete the file. */
496         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
497                 printf("(%s) close failed (%s)\n", 
498                        __location__, smbcli_errstr(cli1->tree));
499                 correct = False;
500                 goto fail;
501         }
502
503         /* This should fail.. */
504         fnum1 = smbcli_open(cli1->tree, fname, O_RDONLY, DENY_NONE);
505         if (fnum1 != -1) {
506                 printf("(%s) open of %s succeeded should have been deleted on close !\n",
507                        __location__, fname);
508                 goto fail;
509                 correct = False;
510         } else
511                 printf("tenth delete on close test succeeded.\n");
512
513         /* test 11 - does having read only attribute still allow delete on close. */
514
515         smbcli_setatr(cli1->tree, fname, 0, 0);
516         smbcli_unlink(cli1->tree, fname);
517                                                                                                                                         
518         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, 
519                                       GENERIC_RIGHTS_FILE_ALL_ACCESS,
520                                       FILE_ATTRIBUTE_READONLY, 
521                                       NTCREATEX_SHARE_ACCESS_NONE, 
522                                       NTCREATEX_DISP_OVERWRITE_IF, 0, 0);
523         
524         if (fnum1 == -1) {
525                 printf("(%s) open of %s failed (%s)\n", 
526                        __location__, fname, smbcli_errstr(cli1->tree));
527                 correct = False;
528                 goto fail;
529         }
530
531         status = smbcli_nt_delete_on_close(cli1->tree, fnum1, True);
532
533         if (NT_STATUS_V(status) != NT_STATUS_V(NT_STATUS_CANNOT_DELETE)) {
534                 printf("(%s) setting delete_on_close should fail with NT_STATUS_CANNOT_DELETE. Got %s instead)\n", 
535                        __location__, smbcli_errstr(cli1->tree));
536                 correct = False;
537                 goto fail;
538         }
539
540         if (NT_STATUS_IS_ERR(smbcli_close(cli1->tree, fnum1))) {
541                 printf("(%s) close failed (%s)\n", 
542                        __location__, smbcli_errstr(cli1->tree));
543                 correct = False;
544                 goto fail;
545         }
546
547         smbcli_setatr(cli1->tree, fname, 0, 0);
548         smbcli_unlink(cli1->tree, fname);
549                                                                                                                                         
550         printf("eleventh delete on close test succeeded.\n");
551
552         /* test 12 - does having read only attribute still allow delete on close at time of open. */
553
554         fnum1 = smbcli_nt_create_full(cli1->tree, fname, 0, GENERIC_RIGHTS_FILE_ALL_ACCESS, FILE_ATTRIBUTE_READONLY,
555                                    NTCREATEX_SHARE_ACCESS_DELETE, NTCREATEX_DISP_OVERWRITE_IF, 
556                                    NTCREATEX_OPTIONS_DELETE_ON_CLOSE, 0);
557         
558         if (fnum1 != -1) {
559                 printf("(%s) open of %s succeeded. Should fail with NT_STATUS_CANNOT_DELETE.\n", 
560                        __location__, fname);
561                 smbcli_close(cli1->tree, fnum1);
562                 correct = False;
563                 goto fail;
564         } else {
565                 status = smbcli_nt_error(cli1->tree);
566                 if (NT_STATUS_V(status) != NT_STATUS_V(NT_STATUS_CANNOT_DELETE)) {
567                         printf("(%s) setting delete_on_close on open should fail with NT_STATUS_CANNOT_DELETE. Got %s instead)\n", 
568                                __location__, smbcli_errstr(cli1->tree));
569                         correct = False;
570                         goto fail;
571                 }
572         }
573         
574         printf("twelvth delete on close test succeeded.\n");
575
576         printf("finished delete test\n");
577
578   fail:
579         /* FIXME: This will crash if we aborted before cli2 got
580          * intialized, because these functions don't handle
581          * uninitialized connections. */
582                 
583         smbcli_close(cli1->tree, fnum1);
584         smbcli_close(cli1->tree, fnum2);
585         smbcli_setatr(cli1->tree, fname, 0, 0);
586         smbcli_unlink(cli1->tree, fname);
587
588         if (!torture_close_connection(cli1)) {
589                 correct = False;
590         }
591         if (!torture_close_connection(cli2)) {
592                 correct = False;
593         }
594         return correct;
595 }
596