r3945: expanded the BASE-PROPERTIES test to print a nicely formatted list of
[samba.git] / source4 / torture / basic / properties.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    show server properties
5
6    Copyright (C) Andrew Tridgell 2004
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 #include "libcli/raw/libcliraw.h"
25
26 struct bitmapping {
27         const char *name;
28         uint32_t value;
29 };
30
31 #define BIT_NAME(x) { #x, x }
32
33 const static struct bitmapping fs_attr_bits[] = {
34         BIT_NAME(FS_ATTR_CASE_SENSITIVE_SEARCH),
35         BIT_NAME(FS_ATTR_CASE_PRESERVED_NAMES),
36         BIT_NAME(FS_ATTR_UNICODE_ON_DISK),
37         BIT_NAME(FS_ATTR_PERSISTANT_ACLS),
38         BIT_NAME(FS_ATTR_COMPRESSION),
39         BIT_NAME(FS_ATTR_QUOTAS),
40         BIT_NAME(FS_ATTR_SPARSE_FILES),
41         BIT_NAME(FS_ATTR_REPARSE_POINTS),
42         BIT_NAME(FS_ATTR_REMOTE_STORAGE),
43         BIT_NAME(FS_ATTR_LFN_SUPPORT),
44         BIT_NAME(FS_ATTR_IS_COMPRESSED),
45         BIT_NAME(FS_ATTR_OBJECT_IDS),
46         BIT_NAME(FS_ATTR_ENCRYPTION),
47         BIT_NAME(FS_ATTR_NAMED_STREAMS),
48         { NULL, 0 }
49 };
50
51 const static struct bitmapping capability_bits[] = {
52         BIT_NAME(CAP_RAW_MODE),
53         BIT_NAME(CAP_MPX_MODE),
54         BIT_NAME(CAP_UNICODE),
55         BIT_NAME(CAP_LARGE_FILES),
56         BIT_NAME(CAP_NT_SMBS),
57         BIT_NAME(CAP_RPC_REMOTE_APIS),
58         BIT_NAME(CAP_STATUS32),
59         BIT_NAME(CAP_LEVEL_II_OPLOCKS),
60         BIT_NAME(CAP_LOCK_AND_READ),
61         BIT_NAME(CAP_NT_FIND),
62         BIT_NAME(CAP_DFS),
63         BIT_NAME(CAP_W2K_SMBS),
64         BIT_NAME(CAP_LARGE_READX),
65         BIT_NAME(CAP_LARGE_WRITEX),
66         BIT_NAME(CAP_UNIX),
67         BIT_NAME(CAP_EXTENDED_SECURITY),
68         { NULL, 0 }
69 };
70
71 static void show_bits(const struct bitmapping *bm, uint32_t value)
72 {
73         int i;
74         for (i=0;bm[i].name;i++) {
75                 if (value & bm[i].value) {
76                         d_printf("\t%s\n", bm[i].name);
77                         value &= ~bm[i].value;
78                 }
79         }
80         if (value != 0) {
81                 d_printf("\tunknown bits: 0x%08x\n", value);
82         }
83 }
84
85
86 /*
87   print out server properties
88  */
89 BOOL torture_test_properties(void)
90 {
91         struct smbcli_state *cli;
92         BOOL correct = True;
93         union smb_fsinfo fs;
94         NTSTATUS status;
95         
96         printf("starting properties test\n");
97         
98         ZERO_STRUCT(cli);
99
100         if (!torture_open_connection(&cli)) {
101                 return False;
102         }
103         
104         d_printf("Capabilities: 0x%08x\n", cli->transport->negotiate.capabilities);
105         show_bits(capability_bits, cli->transport->negotiate.capabilities);
106         d_printf("\n");
107
108         fs.attribute_info.level = RAW_QFS_ATTRIBUTE_INFO;
109         status = smb_raw_fsinfo(cli->tree, cli, &fs);
110         if (!NT_STATUS_IS_OK(status)) {
111                 d_printf("qfsinfo failed - %s\n", nt_errstr(status));
112                 correct = False;
113         } else {
114                 d_printf("Filesystem attributes: 0x%08x\n", 
115                          fs.attribute_info.out.fs_attr);
116                 show_bits(fs_attr_bits, fs.attribute_info.out.fs_attr);
117                 d_printf("max_file_component_length: %d\n", 
118                          fs.attribute_info.out.max_file_component_length);
119                 d_printf("fstype: %s\n", fs.attribute_info.out.fs_type.s);
120         }
121
122         if (!torture_close_connection(cli)) {
123                 correct = False;
124         }
125
126         return correct;
127 }
128
129