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