This commit was generated by cvs2svn to compensate for changes in r30,
[kai/samba-autobuild/.git] / source4 / torture / raw / chkpath.c
1 /* 
2    Unix SMB/CIFS implementation.
3    chkpath 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 BASEDIR "\\rawchkpath"
24
25 #define CHECK_STATUS(status, correct) do { \
26         if (!NT_STATUS_EQUAL(status, correct)) { \
27                 printf("(%d) Incorrect status %s - should be %s\n", \
28                        __LINE__, nt_errstr(status), nt_errstr(correct)); \
29                 ret = False; \
30                 goto done; \
31         }} while (0)
32
33
34 static BOOL test_chkpath(struct cli_state *cli, TALLOC_CTX *mem_ctx)
35 {
36         struct smb_chkpath io;
37         NTSTATUS status;
38         BOOL ret = True;
39         int fnum = -1;
40
41         io.in.path = BASEDIR;
42
43         status = smb_raw_chkpath(cli->tree, &io);
44         CHECK_STATUS(status, NT_STATUS_OK);
45
46         io.in.path = BASEDIR "\\nodir";
47         status = smb_raw_chkpath(cli->tree, &io);
48         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_NOT_FOUND);
49
50         fnum = create_complex_file(cli, mem_ctx, BASEDIR "\\test.txt");
51         if (fnum == -1) {
52                 printf("failed to open test.txt - %s\n", cli_errstr(cli));
53                 ret = False;
54                 goto done;
55         }
56
57         io.in.path = BASEDIR "\\test.txt";
58         printf("testing %s\n", io.in.path);
59         status = smb_raw_chkpath(cli->tree, &io);
60         CHECK_STATUS(status, NT_STATUS_NOT_A_DIRECTORY);
61         
62         if (!torture_set_file_attribute(cli->tree, BASEDIR, FILE_ATTRIBUTE_HIDDEN)) {
63                 printf("failed to set basedir hidden\n");
64                 ret = False;
65                 goto done;
66         }
67
68         io.in.path = BASEDIR;
69         printf("testing %s\n", io.in.path);
70         status = smb_raw_chkpath(cli->tree, &io);
71         CHECK_STATUS(status, NT_STATUS_OK);
72
73         io.in.path = "";
74         printf("testing %s\n", io.in.path);
75         status = smb_raw_chkpath(cli->tree, &io);
76         CHECK_STATUS(status, NT_STATUS_OK);
77
78         io.in.path = ".";
79         printf("testing %s\n", io.in.path);
80         status = smb_raw_chkpath(cli->tree, &io);
81         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
82
83         io.in.path = "\\";
84         printf("testing %s\n", io.in.path);
85         status = smb_raw_chkpath(cli->tree, &io);
86         CHECK_STATUS(status, NT_STATUS_OK);
87
88         io.in.path = "\\.";
89         printf("testing %s\n", io.in.path);
90         status = smb_raw_chkpath(cli->tree, &io);
91         CHECK_STATUS(status, NT_STATUS_OBJECT_NAME_INVALID);
92
93         io.in.path = "\\..";
94         printf("testing %s\n", io.in.path);
95         status = smb_raw_chkpath(cli->tree, &io);
96         CHECK_STATUS(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
97
98         io.in.path = BASEDIR "\\..";
99         printf("testing %s\n", io.in.path);
100         status = smb_raw_chkpath(cli->tree, &io);
101         CHECK_STATUS(status, NT_STATUS_OK);
102
103 done:
104         cli_close(cli, fnum);
105         return ret;
106 }
107
108 /* 
109    basic testing of chkpath calls 
110 */
111 BOOL torture_raw_chkpath(int dummy)
112 {
113         struct cli_state *cli;
114         BOOL ret = True;
115         TALLOC_CTX *mem_ctx;
116
117         if (!torture_open_connection(&cli)) {
118                 return False;
119         }
120
121         mem_ctx = talloc_init("torture_raw_chkpath");
122
123         if (cli_deltree(cli, BASEDIR) == -1) {
124                 printf("Failed to clean " BASEDIR "\n");
125                 return False;
126         }
127         if (!cli_mkdir(cli, BASEDIR)) {
128                 printf("Failed to create " BASEDIR " - %s\n", cli_errstr(cli));
129                 return False;
130         }
131
132         if (!test_chkpath(cli, mem_ctx)) {
133                 ret = False;
134         }
135
136         smb_raw_exit(cli->session);
137         cli_deltree(cli, BASEDIR);
138
139         torture_close_connection(cli);
140         talloc_destroy(mem_ctx);
141         return ret;
142 }