first public release of samba4 code
[amitay/samba.git] / source4 / torture / raw / mkdir.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RAW_MKDIR_* and RAW_RMDIR_* individual test suite
4    Copyright (C) Andrew Tridgell 2003
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 #define CHECK_STATUS(status, correct) do { \
24         if (!NT_STATUS_EQUAL(status, correct)) { \
25                 printf("(%d) Incorrect status %s - should be %s\n", \
26                        __LINE__, nt_errstr(status), nt_errstr(correct)); \
27                 ret = False; \
28                 goto done; \
29         }} while (0)
30
31 /*
32   test mkdir ops
33 */
34 static BOOL test_mkdir(struct cli_state *cli, TALLOC_CTX *mem_ctx)
35 {
36         union smb_mkdir md;
37         struct smb_rmdir rd;
38         const char *path = "\\test_mkdir.dir";
39         NTSTATUS status;
40         BOOL ret = True;
41
42         /* cleanup */
43         cli_rmdir(cli, path);
44         cli_unlink(cli, path);
45
46         /* 
47            basic mkdir
48         */
49         md.mkdir.level = RAW_MKDIR_MKDIR;
50         md.mkdir.in.path = path;
51
52         status = smb_raw_mkdir(cli->tree, &md);
53         CHECK_STATUS(status, NT_STATUS_OK);
54
55         printf("testing mkdir collision\n");
56
57         /* 2nd create */
58         status = smb_raw_mkdir(cli->tree, &md);
59         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
60
61         /* basic rmdir */
62         rd.in.path = path;
63         status = smb_raw_rmdir(cli->tree, &rd);
64         CHECK_STATUS(status, NT_STATUS_OK);
65
66         status = smb_raw_rmdir(cli->tree, &rd);
67         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
68
69         printf("testing mkdir collision with file\n");
70
71         /* name collision with a file */
72         cli_close(cli, create_complex_file(cli, mem_ctx, path));
73         status = smb_raw_mkdir(cli->tree, &md);
74         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_COLLISION);
75
76         printf("testing rmdir with file\n");
77
78         /* delete a file with rmdir */
79         status = smb_raw_rmdir(cli->tree, &rd);
80         CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
81
82         cli_unlink(cli, path);
83
84         printf("testing invalid dir\n");
85
86         /* create an invalid dir */
87         md.mkdir.in.path = "..\\..\\..";
88         status = smb_raw_mkdir(cli->tree, &md);
89         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
90         
91         printf("testing t2mkdir\n");
92
93         /* try a t2mkdir - need to work out why this fails! */
94         md.t2mkdir.level = RAW_MKDIR_T2MKDIR;
95         md.t2mkdir.in.path = path;
96         md.t2mkdir.in.num_eas = 0;      
97         status = smb_raw_mkdir(cli->tree, &md);
98         CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
99
100         printf("testing t2mkdir with EAs\n");
101
102         /* with EAs */
103         md.t2mkdir.in.num_eas = 1;
104         md.t2mkdir.in.eas = talloc(mem_ctx, sizeof(md.t2mkdir.in.eas[0]));
105         md.t2mkdir.in.eas[0].flags = 0;
106         md.t2mkdir.in.eas[0].name.s = "EAONE";
107         md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1);
108         status = smb_raw_mkdir(cli->tree, &md);
109         CHECK_STATUS(status, NT_STATUS_UNSUCCESSFUL);
110
111
112 done:
113         cli_rmdir(cli, path);
114         cli_unlink(cli, path);
115         return ret;
116 }
117
118
119 /* 
120    basic testing of all RAW_MKDIR_* calls 
121 */
122 BOOL torture_raw_mkdir(int dummy)
123 {
124         struct cli_state *cli;
125         BOOL ret = True;
126         TALLOC_CTX *mem_ctx;
127
128         if (!torture_open_connection(&cli)) {
129                 return False;
130         }
131
132         mem_ctx = talloc_init("torture_raw_mkdir");
133
134         if (!test_mkdir(cli, mem_ctx)) {
135                 ret = False;
136         }
137
138         torture_close_connection(cli);
139         talloc_destroy(mem_ctx);
140         return ret;
141 }