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.
23 #include "libcli/raw/libcliraw.h"
25 /****************************************************************************
26 Handle setfileinfo/setpathinfo trans2 backend.
27 ****************************************************************************/
28 static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree,
30 union smb_setfileinfo *parms,
35 #define NEED_BLOB(n) do { \
36 *blob = data_blob_talloc(mem_ctx, NULL, n); \
37 if (blob->data == NULL) return False; \
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 */
48 case RAW_SFILEINFO_STANDARD:
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);
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);
63 case RAW_SFILEINFO_BASIC_INFO:
64 case RAW_SFILEINFO_BASIC_INFORMATION:
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 */
74 case RAW_SFILEINFO_UNIX_BASIC:
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);
90 case RAW_SFILEINFO_DISPOSITION_INFO:
91 case RAW_SFILEINFO_DISPOSITION_INFORMATION:
93 SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close);
96 case RAW_SFILEINFO_ALLOCATION_INFO:
97 case RAW_SFILEINFO_ALLOCATION_INFORMATION:
99 SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size);
102 case RAW_SFILEINFO_END_OF_FILE_INFO:
103 case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
105 SBVAL(blob->data, 0, parms->end_of_file_info.in.size);
108 case RAW_SFILEINFO_RENAME_INFORMATION:
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);
118 case RAW_SFILEINFO_POSITION_INFORMATION:
120 SBVAL(blob->data, 0, parms->position_information.in.position);
123 case RAW_SFILEINFO_MODE_INFORMATION:
125 SIVAL(blob->data, 0, parms->mode_information.in.mode);
128 /* Unhandled levels */
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:
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,
153 struct smb_trans2 tp;
154 uint16_t setup = TRANSACT2_SETFILEINFO;
159 tp.in.setup_count = 1;
162 tp.in.setup = &setup;
164 tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
165 if (!tp.in.params.data) {
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 */
174 return smb_raw_trans2_send(tree, &tp);
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,
186 struct smb_trans2 tp;
187 uint16_t setup = TRANSACT2_SETPATHINFO;
192 tp.in.setup_count = 1;
195 tp.in.setup = &setup;
197 tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
198 if (!tp.in.params.data) {
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,
205 fname, STR_TERMINATE);
209 return smb_raw_trans2_send(tree, &tp);
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)
218 struct smbcli_request *req;
220 req = smbcli_request_setup(tree, SMBsetatr, 8, 0);
221 if (!req) return NULL;
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);
230 if (!smbcli_request_send(req)) {
231 smbcli_request_destroy(req);
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)
244 struct smbcli_request *req;
246 req = smbcli_request_setup(tree, SMBsetattrE, 7, 0);
247 if (!req) return NULL;
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);
257 if (!smbcli_request_send(req)) {
258 smbcli_request_destroy(req);
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)
273 struct smbcli_request *req;
275 if (parms->generic.level == RAW_SFILEINFO_SETATTRE) {
276 return smb_raw_setattrE_send(tree, parms);
278 if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) {
279 return smb_raw_set_secdesc_send(tree, parms);
281 if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
285 mem_ctx = talloc_init("setpathinfo");
286 if (!mem_ctx) return NULL;
288 if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
289 talloc_free(mem_ctx);
293 /* send request and process the output */
294 req = smb_raw_setfileinfo_blob_send(tree,
296 parms->generic.file.fnum,
297 parms->generic.level,
300 talloc_free(mem_ctx);
304 /****************************************************************************
305 Set file info (async send)
306 ****************************************************************************/
307 NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree,
308 union smb_setfileinfo *parms)
310 struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms);
311 return smbcli_request_simple_recv(req);
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)
323 struct smbcli_request *req;
325 if (parms->generic.level == RAW_SFILEINFO_SETATTR) {
326 return smb_raw_setattr_send(tree, parms);
328 if (parms->generic.level >= RAW_SFILEINFO_GENERIC) {
332 mem_ctx = talloc_init("setpathinfo");
333 if (!mem_ctx) return NULL;
335 if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) {
336 talloc_free(mem_ctx);
340 /* send request and process the output */
341 req = smb_raw_setpathinfo_blob_send(tree,
343 parms->generic.file.fname,
344 parms->generic.level,
347 talloc_free(mem_ctx);
351 /****************************************************************************
352 Set path info (sync interface)
353 ****************************************************************************/
354 NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree,
355 union smb_setfileinfo *parms)
357 struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms);
358 return smbcli_request_simple_recv(req);