r11626: Fix unhandled enum in case statement warnings by noting appropriately
[bbaumbach/samba-autobuild/.git] / source4 / libcli / raw / rawsetfileinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RAW_SFILEINFO_* calls
4    Copyright (C) James Myers 2003
5    Copyright (C) Andrew Tridgell 2003
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "libcli/raw/libcliraw.h"
24
25 /****************************************************************************
26  Handle setfileinfo/setpathinfo trans2 backend.
27 ****************************************************************************/
28 static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree,
29                                     TALLOC_CTX *mem_ctx,
30                                     union smb_setfileinfo *parms, 
31                                     DATA_BLOB *blob)
32 {       
33         uint_t len;
34
35 #define NEED_BLOB(n) do { \
36           *blob = data_blob_talloc(mem_ctx, NULL, n); \
37           if (blob->data == NULL) return False; \
38         } while (0)
39
40         switch (parms->generic.level) {
41         case RAW_SFILEINFO_GENERIC:
42         case RAW_SFILEINFO_SETATTR:
43         case RAW_SFILEINFO_SETATTRE:
44         case RAW_SFILEINFO_SEC_DESC:
45                 /* not handled here */
46                 return False;
47
48         case RAW_SFILEINFO_STANDARD:
49                 NEED_BLOB(12);
50                 raw_push_dos_date2(tree->session->transport, 
51                                   blob->data, 0, parms->standard.in.create_time);
52                 raw_push_dos_date2(tree->session->transport, 
53                                   blob->data, 4, parms->standard.in.access_time);
54                 raw_push_dos_date2(tree->session->transport, 
55                                   blob->data, 8, parms->standard.in.write_time);
56                 return True;
57
58         case RAW_SFILEINFO_EA_SET:
59                 NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas));
60                 ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas);
61                 return True;
62
63         case RAW_SFILEINFO_BASIC_INFO:
64         case RAW_SFILEINFO_BASIC_INFORMATION:
65                 NEED_BLOB(40);
66                 smbcli_push_nttime(blob->data,  0, parms->basic_info.in.create_time);
67                 smbcli_push_nttime(blob->data,  8, parms->basic_info.in.access_time);
68                 smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time);
69                 smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time);
70                 SIVAL(blob->data,           32, parms->basic_info.in.attrib);
71                 SIVAL(blob->data,           36, 0); /* padding */
72                 return True;
73
74         case RAW_SFILEINFO_UNIX_BASIC:
75                 NEED_BLOB(92);
76                 SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file);
77                 SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes);
78                 smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time);
79                 smbcli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time);
80                 smbcli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time);
81                 SBVAL(blob->data, 40, parms->unix_basic.in.uid);
82                 SBVAL(blob->data, 48, parms->unix_basic.in.gid);
83                 SIVAL(blob->data, 56, parms->unix_basic.in.file_type);
84                 SBVAL(blob->data, 60, parms->unix_basic.in.dev_major);
85                 SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor);
86                 SBVAL(blob->data, 76, parms->unix_basic.in.unique_id);
87                 SBVAL(blob->data, 84, parms->unix_basic.in.nlink);
88                 return True;
89
90         case RAW_SFILEINFO_DISPOSITION_INFO:
91         case RAW_SFILEINFO_DISPOSITION_INFORMATION:
92                 NEED_BLOB(4);
93                 SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
94                 return True;
95
96         case RAW_SFILEINFO_ALLOCATION_INFO:
97         case RAW_SFILEINFO_ALLOCATION_INFORMATION:
98                 NEED_BLOB(8);
99                 SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
100                 return True;
101
102         case RAW_SFILEINFO_END_OF_FILE_INFO:
103         case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
104                 NEED_BLOB(8);
105                 SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
106                 return True;
107
108         case RAW_SFILEINFO_RENAME_INFORMATION:
109                 NEED_BLOB(12);
110                 SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
111                 SIVAL(blob->data, 4, parms->rename_information.in.root_fid);
112                 len = smbcli_blob_append_string(tree->session, mem_ctx, blob,
113                                              parms->rename_information.in.new_name, 
114                                              STR_UNICODE|STR_TERMINATE);
115                 SIVAL(blob->data, 8, len - 2);
116                 return True;
117
118         case RAW_SFILEINFO_POSITION_INFORMATION:
119                 NEED_BLOB(8);
120                 SBVAL(blob->data, 0, parms->position_information.in.position);
121                 return True;
122
123         case RAW_SFILEINFO_MODE_INFORMATION:
124                 NEED_BLOB(4);
125                 SIVAL(blob->data, 0, parms->mode_information.in.mode);
126                 return True;
127                 
128                 /* Unhandled levels */
129
130         case RAW_SFILEINFO_UNIX_LINK:
131         case RAW_SFILEINFO_UNIX_HLINK:
132         case RAW_SFILEINFO_1023:
133         case RAW_SFILEINFO_1025:
134         case RAW_SFILEINFO_1029:
135         case RAW_SFILEINFO_1032:
136         case RAW_SFILEINFO_1039:
137         case RAW_SFILEINFO_1040:
138                 break;
139         }
140
141         return False;
142 }
143
144 /****************************************************************************
145  Very raw set file info - takes data blob (async send)
146 ****************************************************************************/
147 static struct smbcli_request *smb_raw_setfileinfo_blob_send(struct smbcli_tree *tree,
148                                                          TALLOC_CTX *mem_ctx,
149                                                          uint16_t fnum,
150                                                          uint16_t info_level,
151                                                          DATA_BLOB *blob)
152 {
153         struct smb_trans2 tp;
154         uint16_t setup = TRANSACT2_SETFILEINFO;
155         
156         tp.in.max_setup = 0;
157         tp.in.flags = 0; 
158         tp.in.timeout = 0;
159         tp.in.setup_count = 1;
160         tp.in.max_param = 2;
161         tp.in.max_data = 0;
162         tp.in.setup = &setup;
163         
164         tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
165         if (!tp.in.params.data) {
166                 return NULL;
167         }
168         SSVAL(tp.in.params.data, 0, fnum);
169         SSVAL(tp.in.params.data, 2, info_level);
170         SSVAL(tp.in.params.data, 4, 0); /* reserved */
171
172         tp.in.data = *blob;
173
174         return smb_raw_trans2_send(tree, &tp);
175 }
176
177 /****************************************************************************
178  Very raw set path info - takes data blob
179 ****************************************************************************/
180 static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree *tree,
181                                                             TALLOC_CTX *mem_ctx,
182                                                             const char *fname,
183                                                             uint16_t info_level,
184                                                             DATA_BLOB *blob)
185 {
186         struct smb_trans2 tp;
187         uint16_t setup = TRANSACT2_SETPATHINFO;
188         
189         tp.in.max_setup = 0;
190         tp.in.flags = 0; 
191         tp.in.timeout = 0;
192         tp.in.setup_count = 1;
193         tp.in.max_param = 2;
194         tp.in.max_data = 0;
195         tp.in.setup = &setup;
196         
197         tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
198         if (!tp.in.params.data) {
199                 return NULL;
200         }
201         SSVAL(tp.in.params.data, 0, info_level);
202         SIVAL(tp.in.params.data, 2, 0);
203         smbcli_blob_append_string(tree->session, mem_ctx, 
204                                   &tp.in.params,
205                                   fname, STR_TERMINATE);
206
207         tp.in.data = *blob;
208
209         return smb_raw_trans2_send(tree, &tp);
210 }
211                 
212 /****************************************************************************
213  Handle setattr (async send)
214 ****************************************************************************/
215 static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree,
216                                                 union smb_setfileinfo *parms)
217 {
218         struct smbcli_request *req;
219
220         req = smbcli_request_setup(tree, SMBsetatr, 8, 0);
221         if (!req) return NULL;
222         
223         SSVAL(req->out.vwv,         VWV(0), parms->setattr.in.attrib);
224         raw_push_dos_date3(tree->session->transport, 
225                           req->out.vwv, VWV(1), parms->setattr.in.write_time);
226         memset(req->out.vwv + VWV(3), 0, 10); /* reserved */
227         smbcli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE);
228         smbcli_req_append_ascii4(req, "", STR_TERMINATE);
229         
230         if (!smbcli_request_send(req)) {
231                 smbcli_request_destroy(req);
232                 return NULL;
233         }
234
235         return req;
236 }
237                 
238 /****************************************************************************
239  Handle setattrE. (async send)
240 ****************************************************************************/
241 static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree,
242                                                  union smb_setfileinfo *parms)
243 {
244         struct smbcli_request *req;
245
246         req = smbcli_request_setup(tree, SMBsetattrE, 7, 0);
247         if (!req) return NULL;
248         
249         SSVAL(req->out.vwv,         VWV(0), parms->setattre.file.fnum);
250         raw_push_dos_date2(tree->session->transport, 
251                           req->out.vwv, VWV(1), parms->setattre.in.create_time);
252         raw_push_dos_date2(tree->session->transport, 
253                           req->out.vwv, VWV(3), parms->setattre.in.access_time);
254         raw_push_dos_date2(tree->session->transport, 
255                           req->out.vwv, VWV(5), parms->setattre.in.write_time);
256
257         if (!smbcli_request_send(req)) {
258                 smbcli_request_destroy(req);
259                 return NULL;
260         }
261
262         return req;
263 }
264
265 /****************************************************************************
266  Set file info (async send)
267 ****************************************************************************/
268 struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree,
269                                              union smb_setfileinfo *parms)
270 {
271         DATA_BLOB blob;
272         TALLOC_CTX *mem_ctx;
273         struct smbcli_request *req;
274
275         if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
276                 return smb_raw_setattrE_send(tree, parms);
277         }
278         if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) {
279                 return smb_raw_set_secdesc_send(tree, parms);
280         }
281         if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
282                 return NULL;
283         }
284
285         mem_ctx = talloc_init("setpathinfo");
286         if (!mem_ctx) return NULL;
287
288         if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
289                 talloc_free(mem_ctx);
290                 return NULL;
291         }
292         
293         /* send request and process the output */
294         req = smb_raw_setfileinfo_blob_send(tree, 
295                                             mem_ctx,
296                                             parms->generic.file.fnum, 
297                                             parms->generic.level, 
298                                             &blob);
299
300         talloc_free(mem_ctx);
301         return req;
302 }
303
304 /****************************************************************************
305  Set file info (async send)
306 ****************************************************************************/
307 NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree,
308                              union smb_setfileinfo *parms)
309 {
310         struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms);
311         return smbcli_request_simple_recv(req);
312 }
313
314
315 /****************************************************************************
316  Set path info (async send)
317 ****************************************************************************/
318 struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree,
319                                              union smb_setfileinfo *parms)
320 {
321         DATA_BLOB blob;
322         TALLOC_CTX *mem_ctx;
323         struct smbcli_request *req;
324
325         if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
326                 return smb_raw_setattr_send(tree, parms);
327         }
328         if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
329                 return NULL;
330         }
331
332         mem_ctx = talloc_init("setpathinfo");
333         if (!mem_ctx) return NULL;
334
335         if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
336                 talloc_free(mem_ctx);
337                 return NULL;
338         }
339
340         /* send request and process the output */
341         req = smb_raw_setpathinfo_blob_send(tree, 
342                                             mem_ctx,
343                                             parms->generic.file.fname, 
344                                             parms->generic.level,
345                                             &blob);
346
347         talloc_free(mem_ctx);
348         return req;
349 }
350
351 /****************************************************************************
352  Set path info (sync interface)
353 ****************************************************************************/
354 NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree,
355                              union smb_setfileinfo *parms)
356 {
357         struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms);
358         return smbcli_request_simple_recv(req);
359 }