fba7b8464f79f74d323f06b457cd9cb29a0438bd
[abartlet/samba.git/.git] / source / torture / smb2 / create.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 create test suite
5
6    Copyright (C) Andrew Tridgell 2008
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 3 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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "libcli/smb2/smb2.h"
24 #include "libcli/smb2/smb2_calls.h"
25 #include "torture/torture.h"
26 #include "torture/smb2/proto.h"
27 #include "param/param.h"
28 #include "librpc/gen_ndr/ndr_security.h"
29
30 #define FNAME "test_create.dat"
31
32 #define CHECK_STATUS(status, correct) do { \
33         if (!NT_STATUS_EQUAL(status, correct)) { \
34                 printf("(%s) Incorrect status %s - should be %s\n", \
35                        __location__, nt_errstr(status), nt_errstr(correct)); \
36                 return false; \
37         }} while (0)
38
39 /*
40   test some interesting combinations found by gentest
41  */
42 bool torture_smb2_create_gentest(struct torture_context *torture, struct smb2_tree *tree)
43 {
44         struct smb2_create io;
45         NTSTATUS status;
46         TALLOC_CTX *tmp_ctx = talloc_new(tree);
47
48         ZERO_STRUCT(io);
49         io.in.desired_access     = SEC_FLAG_MAXIMUM_ALLOWED;
50         io.in.file_attributes    = FILE_ATTRIBUTE_NORMAL;
51         io.in.create_disposition = NTCREATEX_DISP_OVERWRITE_IF;
52         io.in.share_access = 
53                 NTCREATEX_SHARE_ACCESS_DELETE|
54                 NTCREATEX_SHARE_ACCESS_READ|
55                 NTCREATEX_SHARE_ACCESS_WRITE;
56         io.in.create_options = 0;
57         io.in.fname = FNAME;
58
59         status = smb2_create(tree, tmp_ctx, &io);
60         CHECK_STATUS(status, NT_STATUS_OK);
61
62         status = smb2_util_close(tree, io.out.file.handle);
63         CHECK_STATUS(status, NT_STATUS_OK);
64
65         io.in.create_options = 0xF0000000;
66         status = smb2_create(tree, tmp_ctx, &io);
67         CHECK_STATUS(status, NT_STATUS_INVALID_PARAMETER);
68
69         io.in.create_options = 0x00100000;
70         status = smb2_create(tree, tmp_ctx, &io);
71         CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED);
72
73         io.in.create_options = 0xF0100000;
74         status = smb2_create(tree, tmp_ctx, &io);
75         CHECK_STATUS(status, NT_STATUS_NOT_SUPPORTED);
76
77         talloc_free(tmp_ctx);
78         
79         return true;
80 }
81
82 /* 
83    basic testing of SMB2 create calls
84 */
85 bool torture_smb2_create(struct torture_context *torture)
86 {
87         TALLOC_CTX *mem_ctx = talloc_new(NULL);
88         struct smb2_tree *tree;
89         bool ret = true;
90
91         if (!torture_smb2_connection(torture, &tree)) {
92                 return false;
93         }
94
95         ret &= torture_smb2_create_gentest(torture, tree);
96
97         smb2_deltree(tree, FNAME);
98
99         talloc_free(mem_ctx);
100
101         return ret;
102 }