2 Unix SMB/CIFS implementation.
4 Copyright (C) James Myers 2003
5 Copyright (C) Andrew Tridgell 2003
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.
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.
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.
24 /****************************************************************************
25 Handle qfileinfo/qpathinfo trans2 backend.
26 ****************************************************************************/
27 static BOOL smb_raw_setinfo_backend(struct cli_tree *tree,
29 union smb_setfileinfo *parms,
34 #define NEED_BLOB(n) do { \
35 *blob = data_blob_talloc(mem_ctx, NULL, n); \
36 if (blob->data == NULL) return False; \
39 switch (parms->generic.level) {
40 case RAW_SFILEINFO_GENERIC:
41 case RAW_SFILEINFO_SETATTR:
42 case RAW_SFILEINFO_SETATTRE:
43 /* not handled here */
46 case RAW_SFILEINFO_STANDARD:
48 put_dos_date2(blob->data, 0, parms->standard.in.create_time);
49 put_dos_date2(blob->data, 4, parms->standard.in.access_time);
50 put_dos_date2(blob->data, 8, parms->standard.in.write_time);
53 case RAW_SFILEINFO_EA_SET:
54 NEED_BLOB(ea_list_size(1, &parms->ea_set.in.ea));
55 ea_put_list(blob->data, 1, &parms->ea_set.in.ea);
58 case RAW_SFILEINFO_BASIC_INFO:
59 case RAW_SFILEINFO_BASIC_INFORMATION:
61 cli_push_nttime(blob->data, 0, &parms->basic_info.in.create_time);
62 cli_push_nttime(blob->data, 8, &parms->basic_info.in.access_time);
63 cli_push_nttime(blob->data, 16, &parms->basic_info.in.write_time);
64 cli_push_nttime(blob->data, 24, &parms->basic_info.in.change_time);
65 SIVAL(blob->data, 32, parms->basic_info.in.attrib);
66 SIVAL(blob->data, 36, 0); /* padding */
69 case RAW_SFILEINFO_UNIX_BASIC:
71 SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file);
72 SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes);
73 cli_push_nttime(blob->data, 16, &parms->unix_basic.in.status_change_time);
74 cli_push_nttime(blob->data, 24, &parms->unix_basic.in.access_time);
75 cli_push_nttime(blob->data, 32, &parms->unix_basic.in.change_time);
76 SBVAL(blob->data, 40, parms->unix_basic.in.uid);
77 SBVAL(blob->data, 48, parms->unix_basic.in.gid);
78 SIVAL(blob->data, 56, parms->unix_basic.in.file_type);
79 SBVAL(blob->data, 60, parms->unix_basic.in.dev_major);
80 SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor);
81 SBVAL(blob->data, 76, parms->unix_basic.in.unique_id);
82 SBVAL(blob->data, 84, parms->unix_basic.in.nlink);
85 case RAW_SFILEINFO_DISPOSITION_INFO:
86 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
88 SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
91 case RAW_SFILEINFO_ALLOCATION_INFO:
92 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
94 SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
97 case RAW_SFILEINFO_END_OF_FILE_INFO:
98 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
100 SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
103 case RAW_SFILEINFO_RENAME_INFORMATION:
105 SIVAL(blob->data, 0, parms->rename_information.in.overwrite);
106 SIVAL(blob->data, 4, parms->rename_information.in.root_fid);
107 len = cli_blob_append_string(tree->session, mem_ctx, blob,
108 parms->rename_information.in.new_name,
109 STR_UNICODE|STR_TERMINATE);
110 SIVAL(blob->data, 8, len - 2);
113 case RAW_SFILEINFO_POSITION_INFORMATION:
115 SBVAL(blob->data, 0, parms->position_information.in.position);
118 case RAW_SFILEINFO_MODE_INFORMATION:
120 SIVAL(blob->data, 0, parms->mode_information.in.mode);
127 /****************************************************************************
128 Very raw set file info - takes data blob (async send)
129 ****************************************************************************/
130 static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree,
136 struct smb_trans2 tp;
137 uint16 setup = TRANSACT2_SETFILEINFO;
142 tp.in.setup_count = 1;
145 tp.in.setup = &setup;
147 tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
148 if (!tp.in.params.data) {
151 SSVAL(tp.in.params.data, 0, fnum);
152 SSVAL(tp.in.params.data, 2, info_level);
153 SSVAL(tp.in.params.data, 4, 0); /* reserved */
157 return smb_raw_trans2_send(tree, &tp);
160 /****************************************************************************
161 Very raw set path info - takes data blob
162 ****************************************************************************/
163 static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree,
169 struct smb_trans2 tp;
170 uint16 setup = TRANSACT2_SETPATHINFO;
175 tp.in.setup_count = 1;
178 tp.in.setup = &setup;
180 tp.in.params = data_blob_talloc(mem_ctx, NULL, 4);
181 if (!tp.in.params.data) {
184 SSVAL(tp.in.params.data, 0, info_level);
185 SSVAL(tp.in.params.data, 2, 0);
186 cli_blob_append_string(tree->session, mem_ctx,
188 fname, STR_TERMINATE);
192 return smb_raw_trans2_send(tree, &tp);
195 /****************************************************************************
196 Handle setattr (async send)
197 ****************************************************************************/
198 static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree,
199 union smb_setfileinfo *parms)
201 struct cli_request *req;
203 req = cli_request_setup(tree, SMBsetatr, 8, 0);
204 if (!req) return NULL;
206 SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib);
207 put_dos_date3(req->out.vwv, VWV(1), parms->setattr.in.write_time);
208 memset(req->out.vwv + VWV(3), 0, 10); /* reserved */
209 cli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE);
210 cli_req_append_ascii4(req, "", STR_TERMINATE);
212 if (!cli_request_send(req)) {
213 cli_request_destroy(req);
220 /****************************************************************************
221 Handle setattrE. (async send)
222 ****************************************************************************/
223 static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree,
224 union smb_setfileinfo *parms)
226 struct cli_request *req;
228 req = cli_request_setup(tree, SMBsetattrE, 7, 0);
229 if (!req) return NULL;
231 SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum);
232 put_dos_date2(req->out.vwv, VWV(1), parms->setattre.in.create_time);
233 put_dos_date2(req->out.vwv, VWV(3), parms->setattre.in.access_time);
234 put_dos_date2(req->out.vwv, VWV(5), parms->setattre.in.write_time);
236 if (!cli_request_send(req)) {
237 cli_request_destroy(req);
244 /****************************************************************************
245 Set file info (async send)
246 ****************************************************************************/
247 struct cli_request *smb_raw_setfileinfo_send(struct cli_tree *tree,
248 union smb_setfileinfo *parms)
252 struct cli_request *req;
254 if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
255 return smb_raw_setattrE_send(tree, parms);
257 if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
261 mem_ctx = talloc_init("setpathinfo");
262 if (!mem_ctx) return NULL;
264 if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
265 talloc_destroy(mem_ctx);
269 /* send request and process the output */
270 req = smb_raw_setfileinfo_blob_send(tree,
272 parms->generic.file.fnum,
273 parms->generic.level,
276 talloc_destroy(mem_ctx);
280 /****************************************************************************
281 Set file info (async send)
282 ****************************************************************************/
283 NTSTATUS smb_raw_setfileinfo(struct cli_tree *tree,
284 union smb_setfileinfo *parms)
286 struct cli_request *req = smb_raw_setfileinfo_send(tree, parms);
287 return cli_request_simple_recv(req);
291 /****************************************************************************
292 Set path info (async send)
293 ****************************************************************************/
294 struct cli_request *smb_raw_setpathinfo_send(struct cli_tree *tree,
295 union smb_setfileinfo *parms)
299 struct cli_request *req;
301 if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
302 return smb_raw_setattr_send(tree, parms);
304 if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
308 mem_ctx = talloc_init("setpathinfo");
309 if (!mem_ctx) return NULL;
311 if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
312 talloc_destroy(mem_ctx);
316 /* send request and process the output */
317 req = smb_raw_setpathinfo_blob_send(tree,
319 parms->generic.file.fname,
320 parms->generic.level,
323 talloc_destroy(mem_ctx);
327 /****************************************************************************
328 Set path info (sync interface)
329 ****************************************************************************/
330 NTSTATUS smb_raw_setpathinfo(struct cli_tree *tree,
331 union smb_setfileinfo *parms)
333 struct cli_request *req = smb_raw_setpathinfo_send(tree, parms);
334 return cli_request_simple_recv(req);