r24872: Use torture API a bit more
[kai/samba.git] / source4 / torture / smb2 / dir.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 dir list test suite
5
6    Copyright (C) Andrew Tridgell 2005
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
26 #include "torture/torture.h"
27 #include "torture/smb2/proto.h"
28
29 /*
30   test find continue
31 */
32 static BOOL torture_smb2_find_dir(struct smb2_tree *tree)
33 {
34         struct smb2_handle handle;
35         NTSTATUS status;
36         int i;
37         struct smb2_find f;
38         BOOL ret = True;
39         union smb_search_data *d;
40         uint_t count;
41
42         status = smb2_util_roothandle(tree, &handle);
43         if (!NT_STATUS_IS_OK(status)) {
44                 return False;
45         }
46
47         ZERO_STRUCT(f);
48         f.in.file.handle        = handle;
49         f.in.pattern            = "*";
50         f.in.continue_flags     = SMB2_CONTINUE_FLAG_SINGLE;
51         f.in.max_response_size  = 0x100;
52         f.in.level              = SMB2_FIND_BOTH_DIRECTORY_INFO;
53
54         do {
55                 status = smb2_find_level(tree, tree, &f, &count, &d);
56                 if (!NT_STATUS_IS_OK(status)) {
57                         printf("SMB2_FIND_ID_BOTH_DIRECTORY_INFO failed - %s\n", nt_errstr(status));
58                         break;
59                 }
60
61                 printf("Got %d files\n", count);
62                 for (i=0;i<count;i++) {
63                         printf("\t'%s'\n", 
64                                d[i].both_directory_info.name.s);
65                 }
66                 f.in.continue_flags = 0;
67                 f.in.max_response_size  = 4096;
68         } while (count != 0);
69
70
71         return ret;
72 }
73
74
75 /* 
76    basic testing of directory listing with continue
77 */
78 BOOL torture_smb2_dir(struct torture_context *torture)
79 {
80         TALLOC_CTX *mem_ctx = talloc_new(NULL);
81         struct smb2_tree *tree;
82         BOOL ret = True;
83
84         if (!torture_smb2_connection(mem_ctx, &tree)) {
85                 return False;
86         }
87
88         ret &= torture_smb2_find_dir(tree);
89
90         talloc_free(mem_ctx);
91
92         return ret;
93 }