[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[sfrench/samba-autobuild/.git] / source / libsmb / clifsinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3    FS info functions
4    Copyright (C) Stefan (metze) Metzmacher      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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21
22 /****************************************************************************
23  Get UNIX extensions version info.
24 ****************************************************************************/
25                                                                                                                    
26 BOOL cli_unix_extensions_version(struct cli_state *cli, uint16 *pmajor, uint16 *pminor,
27                                         uint32 *pcaplow, uint32 *pcaphigh)
28 {
29         BOOL ret = False;
30         uint16 setup;
31         char param[2];
32         char *rparam=NULL, *rdata=NULL;
33         unsigned int rparam_count=0, rdata_count=0;
34
35         setup = TRANSACT2_QFSINFO;
36         
37         SSVAL(param,0,SMB_QUERY_CIFS_UNIX_INFO);
38
39         if (!cli_send_trans(cli, SMBtrans2, 
40                     NULL, 
41                     0, 0,
42                     &setup, 1, 0,
43                     param, 2, 0,
44                     NULL, 0, 560)) {
45                 goto cleanup;
46         }
47         
48         if (!cli_receive_trans(cli, SMBtrans2,
49                               &rparam, &rparam_count,
50                               &rdata, &rdata_count)) {
51                 goto cleanup;
52         }
53
54         if (cli_is_error(cli)) {
55                 ret = False;
56                 goto cleanup;
57         } else {
58                 ret = True;
59         }
60
61         if (rdata_count < 12) {
62                 goto cleanup;
63         }
64
65         *pmajor = SVAL(rdata,0);
66         *pminor = SVAL(rdata,2);
67         cli->posix_capabilities = *pcaplow = IVAL(rdata,4);
68         *pcaphigh = IVAL(rdata,8);
69
70         /* todo: but not yet needed 
71          *       return the other stuff
72          */
73
74 cleanup:
75         SAFE_FREE(rparam);
76         SAFE_FREE(rdata);
77
78         return ret;     
79 }
80
81 /****************************************************************************
82  Set UNIX extensions capabilities.
83 ****************************************************************************/
84                                                                                                                    
85 BOOL cli_set_unix_extensions_capabilities(struct cli_state *cli, uint16 major, uint16 minor,
86                                         uint32 caplow, uint32 caphigh)
87 {
88         BOOL ret = False;
89         uint16 setup;
90         char param[4];
91         char data[12];
92         char *rparam=NULL, *rdata=NULL;
93         unsigned int rparam_count=0, rdata_count=0;
94
95         setup = TRANSACT2_SETFSINFO;
96         
97         SSVAL(param,0,0);
98         SSVAL(param,2,SMB_SET_CIFS_UNIX_INFO);
99
100         SSVAL(data,0,major);
101         SSVAL(data,2,minor);
102         SIVAL(data,4,caplow);
103         SIVAL(data,8,caphigh);
104
105         if (!cli_send_trans(cli, SMBtrans2, 
106                     NULL, 
107                     0, 0,
108                     &setup, 1, 0,
109                     param, 4, 0,
110                     data, 12, 560)) {
111                 goto cleanup;
112         }
113         
114         if (!cli_receive_trans(cli, SMBtrans2,
115                               &rparam, &rparam_count,
116                               &rdata, &rdata_count)) {
117                 goto cleanup;
118         }
119
120         if (cli_is_error(cli)) {
121                 ret = False;
122                 goto cleanup;
123         } else {
124                 ret = True;
125         }
126
127 cleanup:
128         SAFE_FREE(rparam);
129         SAFE_FREE(rdata);
130
131         return ret;     
132 }
133
134 BOOL cli_get_fs_attr_info(struct cli_state *cli, uint32 *fs_attr)
135 {
136         BOOL ret = False;
137         uint16 setup;
138         char param[2];
139         char *rparam=NULL, *rdata=NULL;
140         unsigned int rparam_count=0, rdata_count=0;
141
142         if (!cli||!fs_attr)
143                 smb_panic("cli_get_fs_attr_info() called with NULL Pionter!");
144
145         setup = TRANSACT2_QFSINFO;
146         
147         SSVAL(param,0,SMB_QUERY_FS_ATTRIBUTE_INFO);
148
149         if (!cli_send_trans(cli, SMBtrans2, 
150                     NULL, 
151                     0, 0,
152                     &setup, 1, 0,
153                     param, 2, 0,
154                     NULL, 0, 560)) {
155                 goto cleanup;
156         }
157         
158         if (!cli_receive_trans(cli, SMBtrans2,
159                               &rparam, &rparam_count,
160                               &rdata, &rdata_count)) {
161                 goto cleanup;
162         }
163
164         if (cli_is_error(cli)) {
165                 ret = False;
166                 goto cleanup;
167         } else {
168                 ret = True;
169         }
170
171         if (rdata_count < 12) {
172                 goto cleanup;
173         }
174
175         *fs_attr = IVAL(rdata,0);
176
177         /* todo: but not yet needed 
178          *       return the other stuff
179          */
180
181 cleanup:
182         SAFE_FREE(rparam);
183         SAFE_FREE(rdata);
184
185         return ret;     
186 }
187
188 BOOL cli_get_fs_volume_info_old(struct cli_state *cli, fstring volume_name, uint32 *pserial_number)
189 {
190         BOOL ret = False;
191         uint16 setup;
192         char param[2];
193         char *rparam=NULL, *rdata=NULL;
194         unsigned int rparam_count=0, rdata_count=0;
195         unsigned char nlen;
196
197         setup = TRANSACT2_QFSINFO;
198         
199         SSVAL(param,0,SMB_INFO_VOLUME);
200
201         if (!cli_send_trans(cli, SMBtrans2, 
202                     NULL, 
203                     0, 0,
204                     &setup, 1, 0,
205                     param, 2, 0,
206                     NULL, 0, 560)) {
207                 goto cleanup;
208         }
209         
210         if (!cli_receive_trans(cli, SMBtrans2,
211                               &rparam, &rparam_count,
212                               &rdata, &rdata_count)) {
213                 goto cleanup;
214         }
215
216         if (cli_is_error(cli)) {
217                 ret = False;
218                 goto cleanup;
219         } else {
220                 ret = True;
221         }
222
223         if (rdata_count < 5) {
224                 goto cleanup;
225         }
226
227         if (pserial_number) {
228                 *pserial_number = IVAL(rdata,0);
229         }
230         nlen = CVAL(rdata,l2_vol_cch);
231         clistr_pull(cli, volume_name, rdata + l2_vol_szVolLabel, sizeof(fstring), nlen, STR_NOALIGN);
232
233         /* todo: but not yet needed 
234          *       return the other stuff
235          */
236
237 cleanup:
238         SAFE_FREE(rparam);
239         SAFE_FREE(rdata);
240
241         return ret;     
242 }
243
244 BOOL cli_get_fs_volume_info(struct cli_state *cli, fstring volume_name, uint32 *pserial_number, time_t *pdate)
245 {
246         BOOL ret = False;
247         uint16 setup;
248         char param[2];
249         char *rparam=NULL, *rdata=NULL;
250         unsigned int rparam_count=0, rdata_count=0;
251         unsigned int nlen;
252
253         setup = TRANSACT2_QFSINFO;
254         
255         SSVAL(param,0,SMB_QUERY_FS_VOLUME_INFO);
256
257         if (!cli_send_trans(cli, SMBtrans2, 
258                     NULL, 
259                     0, 0,
260                     &setup, 1, 0,
261                     param, 2, 0,
262                     NULL, 0, 560)) {
263                 goto cleanup;
264         }
265         
266         if (!cli_receive_trans(cli, SMBtrans2,
267                               &rparam, &rparam_count,
268                               &rdata, &rdata_count)) {
269                 goto cleanup;
270         }
271
272         if (cli_is_error(cli)) {
273                 ret = False;
274                 goto cleanup;
275         } else {
276                 ret = True;
277         }
278
279         if (rdata_count < 19) {
280                 goto cleanup;
281         }
282
283         if (pdate) {
284                 struct timespec ts;
285                 ts = interpret_long_date(rdata);
286                 *pdate = ts.tv_sec;
287         }
288         if (pserial_number) {
289                 *pserial_number = IVAL(rdata,8);
290         }
291         nlen = IVAL(rdata,12);
292         clistr_pull(cli, volume_name, rdata + 18, sizeof(fstring), nlen, STR_UNICODE);
293
294         /* todo: but not yet needed 
295          *       return the other stuff
296          */
297
298 cleanup:
299         SAFE_FREE(rparam);
300         SAFE_FREE(rdata);
301
302         return ret;     
303 }