1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | SMB NT transaction handling
|
---|
4 | Copyright (C) Jeremy Allison 1994-2007
|
---|
5 | Copyright (C) Stefan (metze) Metzmacher 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 3 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, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 | #include "smbd/globals.h"
|
---|
23 |
|
---|
24 | extern const struct generic_mapping file_generic_mapping;
|
---|
25 |
|
---|
26 | static char *nttrans_realloc(char **ptr, size_t size)
|
---|
27 | {
|
---|
28 | if (ptr==NULL) {
|
---|
29 | smb_panic("nttrans_realloc() called with NULL ptr");
|
---|
30 | }
|
---|
31 |
|
---|
32 | *ptr = (char *)SMB_REALLOC(*ptr, size);
|
---|
33 | if(*ptr == NULL) {
|
---|
34 | return NULL;
|
---|
35 | }
|
---|
36 | memset(*ptr,'\0',size);
|
---|
37 | return *ptr;
|
---|
38 | }
|
---|
39 |
|
---|
40 | /****************************************************************************
|
---|
41 | Send the required number of replies back.
|
---|
42 | We assume all fields other than the data fields are
|
---|
43 | set correctly for the type of call.
|
---|
44 | HACK ! Always assumes smb_setup field is zero.
|
---|
45 | ****************************************************************************/
|
---|
46 |
|
---|
47 | void send_nt_replies(connection_struct *conn,
|
---|
48 | struct smb_request *req, NTSTATUS nt_error,
|
---|
49 | char *params, int paramsize,
|
---|
50 | char *pdata, int datasize)
|
---|
51 | {
|
---|
52 | int data_to_send = datasize;
|
---|
53 | int params_to_send = paramsize;
|
---|
54 | int useable_space;
|
---|
55 | char *pp = params;
|
---|
56 | char *pd = pdata;
|
---|
57 | int params_sent_thistime, data_sent_thistime, total_sent_thistime;
|
---|
58 | int alignment_offset = 3;
|
---|
59 | int data_alignment_offset = 0;
|
---|
60 | struct smbd_server_connection *sconn = smbd_server_conn;
|
---|
61 | int max_send = sconn->smb1.sessions.max_send;
|
---|
62 |
|
---|
63 | /*
|
---|
64 | * If there genuinely are no parameters or data to send just send
|
---|
65 | * the empty packet.
|
---|
66 | */
|
---|
67 |
|
---|
68 | if(params_to_send == 0 && data_to_send == 0) {
|
---|
69 | reply_outbuf(req, 18, 0);
|
---|
70 | if (NT_STATUS_V(nt_error)) {
|
---|
71 | error_packet_set((char *)req->outbuf,
|
---|
72 | 0, 0, nt_error,
|
---|
73 | __LINE__,__FILE__);
|
---|
74 | }
|
---|
75 | show_msg((char *)req->outbuf);
|
---|
76 | if (!srv_send_smb(smbd_server_fd(),
|
---|
77 | (char *)req->outbuf,
|
---|
78 | true, req->seqnum+1,
|
---|
79 | IS_CONN_ENCRYPTED(conn),
|
---|
80 | &req->pcd)) {
|
---|
81 | exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
|
---|
82 | }
|
---|
83 | TALLOC_FREE(req->outbuf);
|
---|
84 | return;
|
---|
85 | }
|
---|
86 |
|
---|
87 | /*
|
---|
88 | * When sending params and data ensure that both are nicely aligned.
|
---|
89 | * Only do this alignment when there is also data to send - else
|
---|
90 | * can cause NT redirector problems.
|
---|
91 | */
|
---|
92 |
|
---|
93 | if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
|
---|
94 | data_alignment_offset = 4 - (params_to_send % 4);
|
---|
95 | }
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Space is bufsize minus Netbios over TCP header minus SMB header.
|
---|
99 | * The alignment_offset is to align the param bytes on a four byte
|
---|
100 | * boundary (2 bytes for data len, one byte pad).
|
---|
101 | * NT needs this to work correctly.
|
---|
102 | */
|
---|
103 |
|
---|
104 | useable_space = max_send - (smb_size
|
---|
105 | + 2 * 18 /* wct */
|
---|
106 | + alignment_offset
|
---|
107 | + data_alignment_offset);
|
---|
108 |
|
---|
109 | if (useable_space < 0) {
|
---|
110 | char *msg = talloc_asprintf(
|
---|
111 | talloc_tos(),
|
---|
112 | "send_nt_replies failed sanity useable_space = %d!!!",
|
---|
113 | useable_space);
|
---|
114 | DEBUG(0, ("%s\n", msg));
|
---|
115 | exit_server_cleanly(msg);
|
---|
116 | }
|
---|
117 |
|
---|
118 | while (params_to_send || data_to_send) {
|
---|
119 |
|
---|
120 | /*
|
---|
121 | * Calculate whether we will totally or partially fill this packet.
|
---|
122 | */
|
---|
123 |
|
---|
124 | total_sent_thistime = params_to_send + data_to_send;
|
---|
125 |
|
---|
126 | /*
|
---|
127 | * We can never send more than useable_space.
|
---|
128 | */
|
---|
129 |
|
---|
130 | total_sent_thistime = MIN(total_sent_thistime, useable_space);
|
---|
131 |
|
---|
132 | reply_outbuf(req, 18,
|
---|
133 | total_sent_thistime + alignment_offset
|
---|
134 | + data_alignment_offset);
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * We might have had SMBnttranss in req->inbuf, fix that.
|
---|
138 | */
|
---|
139 | SCVAL(req->outbuf, smb_com, SMBnttrans);
|
---|
140 |
|
---|
141 | /*
|
---|
142 | * Set total params and data to be sent.
|
---|
143 | */
|
---|
144 |
|
---|
145 | SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
|
---|
146 | SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
|
---|
147 |
|
---|
148 | /*
|
---|
149 | * Calculate how many parameters and data we can fit into
|
---|
150 | * this packet. Parameters get precedence.
|
---|
151 | */
|
---|
152 |
|
---|
153 | params_sent_thistime = MIN(params_to_send,useable_space);
|
---|
154 | data_sent_thistime = useable_space - params_sent_thistime;
|
---|
155 | data_sent_thistime = MIN(data_sent_thistime,data_to_send);
|
---|
156 |
|
---|
157 | SIVAL(req->outbuf, smb_ntr_ParameterCount,
|
---|
158 | params_sent_thistime);
|
---|
159 |
|
---|
160 | if(params_sent_thistime == 0) {
|
---|
161 | SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
|
---|
162 | SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
|
---|
163 | } else {
|
---|
164 | /*
|
---|
165 | * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
|
---|
166 | * parameter bytes, however the first 4 bytes of outbuf are
|
---|
167 | * the Netbios over TCP header. Thus use smb_base() to subtract
|
---|
168 | * them from the calculation.
|
---|
169 | */
|
---|
170 |
|
---|
171 | SIVAL(req->outbuf,smb_ntr_ParameterOffset,
|
---|
172 | ((smb_buf(req->outbuf)+alignment_offset)
|
---|
173 | - smb_base(req->outbuf)));
|
---|
174 | /*
|
---|
175 | * Absolute displacement of param bytes sent in this packet.
|
---|
176 | */
|
---|
177 |
|
---|
178 | SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
|
---|
179 | pp - params);
|
---|
180 | }
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * Deal with the data portion.
|
---|
184 | */
|
---|
185 |
|
---|
186 | SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
|
---|
187 |
|
---|
188 | if(data_sent_thistime == 0) {
|
---|
189 | SIVAL(req->outbuf,smb_ntr_DataOffset,0);
|
---|
190 | SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
|
---|
191 | } else {
|
---|
192 | /*
|
---|
193 | * The offset of the data bytes is the offset of the
|
---|
194 | * parameter bytes plus the number of parameters being sent this time.
|
---|
195 | */
|
---|
196 |
|
---|
197 | SIVAL(req->outbuf, smb_ntr_DataOffset,
|
---|
198 | ((smb_buf(req->outbuf)+alignment_offset) -
|
---|
199 | smb_base(req->outbuf))
|
---|
200 | + params_sent_thistime + data_alignment_offset);
|
---|
201 | SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
|
---|
202 | }
|
---|
203 |
|
---|
204 | /*
|
---|
205 | * Copy the param bytes into the packet.
|
---|
206 | */
|
---|
207 |
|
---|
208 | if(params_sent_thistime) {
|
---|
209 | if (alignment_offset != 0) {
|
---|
210 | memset(smb_buf(req->outbuf), 0,
|
---|
211 | alignment_offset);
|
---|
212 | }
|
---|
213 | memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
|
---|
214 | params_sent_thistime);
|
---|
215 | }
|
---|
216 |
|
---|
217 | /*
|
---|
218 | * Copy in the data bytes
|
---|
219 | */
|
---|
220 |
|
---|
221 | if(data_sent_thistime) {
|
---|
222 | if (data_alignment_offset != 0) {
|
---|
223 | memset((smb_buf(req->outbuf)+alignment_offset+
|
---|
224 | params_sent_thistime), 0,
|
---|
225 | data_alignment_offset);
|
---|
226 | }
|
---|
227 | memcpy(smb_buf(req->outbuf)+alignment_offset
|
---|
228 | +params_sent_thistime+data_alignment_offset,
|
---|
229 | pd,data_sent_thistime);
|
---|
230 | }
|
---|
231 |
|
---|
232 | DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
|
---|
233 | params_sent_thistime, data_sent_thistime, useable_space));
|
---|
234 | DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
|
---|
235 | params_to_send, data_to_send, paramsize, datasize));
|
---|
236 |
|
---|
237 | if (NT_STATUS_V(nt_error)) {
|
---|
238 | error_packet_set((char *)req->outbuf,
|
---|
239 | 0, 0, nt_error,
|
---|
240 | __LINE__,__FILE__);
|
---|
241 | }
|
---|
242 |
|
---|
243 | /* Send the packet */
|
---|
244 | show_msg((char *)req->outbuf);
|
---|
245 | if (!srv_send_smb(smbd_server_fd(),
|
---|
246 | (char *)req->outbuf,
|
---|
247 | true, req->seqnum+1,
|
---|
248 | IS_CONN_ENCRYPTED(conn),
|
---|
249 | &req->pcd)) {
|
---|
250 | exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
|
---|
251 | }
|
---|
252 |
|
---|
253 | TALLOC_FREE(req->outbuf);
|
---|
254 |
|
---|
255 | pp += params_sent_thistime;
|
---|
256 | pd += data_sent_thistime;
|
---|
257 |
|
---|
258 | params_to_send -= params_sent_thistime;
|
---|
259 | data_to_send -= data_sent_thistime;
|
---|
260 |
|
---|
261 | /*
|
---|
262 | * Sanity check
|
---|
263 | */
|
---|
264 |
|
---|
265 | if(params_to_send < 0 || data_to_send < 0) {
|
---|
266 | DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
|
---|
267 | params_to_send, data_to_send));
|
---|
268 | exit_server_cleanly("send_nt_replies: internal error");
|
---|
269 | }
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | /****************************************************************************
|
---|
274 | Reply to an NT create and X call on a pipe
|
---|
275 | ****************************************************************************/
|
---|
276 |
|
---|
277 | static void nt_open_pipe(char *fname, connection_struct *conn,
|
---|
278 | struct smb_request *req, int *ppnum)
|
---|
279 | {
|
---|
280 | files_struct *fsp;
|
---|
281 | NTSTATUS status;
|
---|
282 |
|
---|
283 | DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
|
---|
284 |
|
---|
285 | /* Strip \\ off the name. */
|
---|
286 | fname++;
|
---|
287 |
|
---|
288 | status = open_np_file(req, fname, &fsp);
|
---|
289 | if (!NT_STATUS_IS_OK(status)) {
|
---|
290 | if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
|
---|
291 | reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
|
---|
292 | ERRDOS, ERRbadpipe);
|
---|
293 | return;
|
---|
294 | }
|
---|
295 | reply_nterror(req, status);
|
---|
296 | return;
|
---|
297 | }
|
---|
298 |
|
---|
299 | *ppnum = fsp->fnum;
|
---|
300 | return;
|
---|
301 | }
|
---|
302 |
|
---|
303 | /****************************************************************************
|
---|
304 | Reply to an NT create and X call for pipes.
|
---|
305 | ****************************************************************************/
|
---|
306 |
|
---|
307 | static void do_ntcreate_pipe_open(connection_struct *conn,
|
---|
308 | struct smb_request *req)
|
---|
309 | {
|
---|
310 | char *fname = NULL;
|
---|
311 | int pnum = -1;
|
---|
312 | char *p = NULL;
|
---|
313 | uint32 flags = IVAL(req->vwv+3, 1);
|
---|
314 | TALLOC_CTX *ctx = talloc_tos();
|
---|
315 |
|
---|
316 | srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
|
---|
317 |
|
---|
318 | if (!fname) {
|
---|
319 | reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
|
---|
320 | ERRDOS, ERRbadpipe);
|
---|
321 | return;
|
---|
322 | }
|
---|
323 | nt_open_pipe(fname, conn, req, &pnum);
|
---|
324 |
|
---|
325 | if (req->outbuf) {
|
---|
326 | /* error reply */
|
---|
327 | return;
|
---|
328 | }
|
---|
329 |
|
---|
330 | /*
|
---|
331 | * Deal with pipe return.
|
---|
332 | */
|
---|
333 |
|
---|
334 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
335 | /* This is very strange. We
|
---|
336 | * return 50 words, but only set
|
---|
337 | * the wcnt to 42 ? It's definately
|
---|
338 | * what happens on the wire....
|
---|
339 | */
|
---|
340 | reply_outbuf(req, 50, 0);
|
---|
341 | SCVAL(req->outbuf,smb_wct,42);
|
---|
342 | } else {
|
---|
343 | reply_outbuf(req, 34, 0);
|
---|
344 | }
|
---|
345 |
|
---|
346 | p = (char *)req->outbuf + smb_vwv2;
|
---|
347 | p++;
|
---|
348 | SSVAL(p,0,pnum);
|
---|
349 | p += 2;
|
---|
350 | SIVAL(p,0,FILE_WAS_OPENED);
|
---|
351 | p += 4;
|
---|
352 | p += 32;
|
---|
353 | SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
|
---|
354 | p += 20;
|
---|
355 | /* File type. */
|
---|
356 | SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
|
---|
357 | /* Device state. */
|
---|
358 | SSVAL(p,2, 0x5FF); /* ? */
|
---|
359 | p += 4;
|
---|
360 |
|
---|
361 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
362 | p += 25;
|
---|
363 | SIVAL(p,0,FILE_GENERIC_ALL);
|
---|
364 | /*
|
---|
365 | * For pipes W2K3 seems to return
|
---|
366 | * 0x12019B next.
|
---|
367 | * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
|
---|
368 | */
|
---|
369 | SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
|
---|
370 | }
|
---|
371 |
|
---|
372 | DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
|
---|
373 |
|
---|
374 | chain_reply(req);
|
---|
375 | }
|
---|
376 |
|
---|
377 | struct case_semantics_state {
|
---|
378 | connection_struct *conn;
|
---|
379 | bool case_sensitive;
|
---|
380 | bool case_preserve;
|
---|
381 | bool short_case_preserve;
|
---|
382 | };
|
---|
383 |
|
---|
384 | /****************************************************************************
|
---|
385 | Restore case semantics.
|
---|
386 | ****************************************************************************/
|
---|
387 |
|
---|
388 | static int restore_case_semantics(struct case_semantics_state *state)
|
---|
389 | {
|
---|
390 | state->conn->case_sensitive = state->case_sensitive;
|
---|
391 | state->conn->case_preserve = state->case_preserve;
|
---|
392 | state->conn->short_case_preserve = state->short_case_preserve;
|
---|
393 | return 0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /****************************************************************************
|
---|
397 | Save case semantics.
|
---|
398 | ****************************************************************************/
|
---|
399 |
|
---|
400 | static struct case_semantics_state *set_posix_case_semantics(TALLOC_CTX *mem_ctx,
|
---|
401 | connection_struct *conn)
|
---|
402 | {
|
---|
403 | struct case_semantics_state *result;
|
---|
404 |
|
---|
405 | if (!(result = talloc(mem_ctx, struct case_semantics_state))) {
|
---|
406 | return NULL;
|
---|
407 | }
|
---|
408 |
|
---|
409 | result->conn = conn;
|
---|
410 | result->case_sensitive = conn->case_sensitive;
|
---|
411 | result->case_preserve = conn->case_preserve;
|
---|
412 | result->short_case_preserve = conn->short_case_preserve;
|
---|
413 |
|
---|
414 | /* Set to POSIX. */
|
---|
415 | conn->case_sensitive = True;
|
---|
416 | conn->case_preserve = True;
|
---|
417 | conn->short_case_preserve = True;
|
---|
418 |
|
---|
419 | talloc_set_destructor(result, restore_case_semantics);
|
---|
420 |
|
---|
421 | return result;
|
---|
422 | }
|
---|
423 |
|
---|
424 | /****************************************************************************
|
---|
425 | Reply to an NT create and X call.
|
---|
426 | ****************************************************************************/
|
---|
427 |
|
---|
428 | void reply_ntcreate_and_X(struct smb_request *req)
|
---|
429 | {
|
---|
430 | connection_struct *conn = req->conn;
|
---|
431 | struct smb_filename *smb_fname = NULL;
|
---|
432 | char *fname = NULL;
|
---|
433 | uint32 flags;
|
---|
434 | uint32 access_mask;
|
---|
435 | uint32 file_attributes;
|
---|
436 | uint32 share_access;
|
---|
437 | uint32 create_disposition;
|
---|
438 | uint32 create_options;
|
---|
439 | uint16 root_dir_fid;
|
---|
440 | uint64_t allocation_size;
|
---|
441 | /* Breakout the oplock request bits so we can set the
|
---|
442 | reply bits separately. */
|
---|
443 | uint32 fattr=0;
|
---|
444 | SMB_OFF_T file_len = 0;
|
---|
445 | int info = 0;
|
---|
446 | files_struct *fsp = NULL;
|
---|
447 | char *p = NULL;
|
---|
448 | struct timespec create_timespec;
|
---|
449 | struct timespec c_timespec;
|
---|
450 | struct timespec a_timespec;
|
---|
451 | struct timespec m_timespec;
|
---|
452 | struct timespec write_time_ts;
|
---|
453 | NTSTATUS status;
|
---|
454 | int oplock_request;
|
---|
455 | uint8_t oplock_granted = NO_OPLOCK_RETURN;
|
---|
456 | struct case_semantics_state *case_state = NULL;
|
---|
457 | TALLOC_CTX *ctx = talloc_tos();
|
---|
458 |
|
---|
459 | START_PROFILE(SMBntcreateX);
|
---|
460 |
|
---|
461 | if (req->wct < 24) {
|
---|
462 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
463 | goto out;
|
---|
464 | }
|
---|
465 |
|
---|
466 | flags = IVAL(req->vwv+3, 1);
|
---|
467 | access_mask = IVAL(req->vwv+7, 1);
|
---|
468 | file_attributes = IVAL(req->vwv+13, 1);
|
---|
469 | share_access = IVAL(req->vwv+15, 1);
|
---|
470 | create_disposition = IVAL(req->vwv+17, 1);
|
---|
471 | create_options = IVAL(req->vwv+19, 1);
|
---|
472 | root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
|
---|
473 |
|
---|
474 | allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
|
---|
475 | #ifdef LARGE_SMB_OFF_T
|
---|
476 | allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
|
---|
477 | #endif
|
---|
478 |
|
---|
479 | srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
|
---|
480 | STR_TERMINATE, &status);
|
---|
481 |
|
---|
482 | if (!NT_STATUS_IS_OK(status)) {
|
---|
483 | reply_nterror(req, status);
|
---|
484 | goto out;
|
---|
485 | }
|
---|
486 |
|
---|
487 | DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
|
---|
488 | "file_attributes = 0x%x, share_access = 0x%x, "
|
---|
489 | "create_disposition = 0x%x create_options = 0x%x "
|
---|
490 | "root_dir_fid = 0x%x, fname = %s\n",
|
---|
491 | (unsigned int)flags,
|
---|
492 | (unsigned int)access_mask,
|
---|
493 | (unsigned int)file_attributes,
|
---|
494 | (unsigned int)share_access,
|
---|
495 | (unsigned int)create_disposition,
|
---|
496 | (unsigned int)create_options,
|
---|
497 | (unsigned int)root_dir_fid,
|
---|
498 | fname));
|
---|
499 |
|
---|
500 | /*
|
---|
501 | * we need to remove ignored bits when they come directly from the client
|
---|
502 | * because we reuse some of them for internal stuff
|
---|
503 | */
|
---|
504 | create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
|
---|
505 |
|
---|
506 | /*
|
---|
507 | * If it's an IPC, use the pipe handler.
|
---|
508 | */
|
---|
509 |
|
---|
510 | if (IS_IPC(conn)) {
|
---|
511 | if (lp_nt_pipe_support()) {
|
---|
512 | do_ntcreate_pipe_open(conn, req);
|
---|
513 | goto out;
|
---|
514 | }
|
---|
515 | reply_nterror(req, NT_STATUS_ACCESS_DENIED);
|
---|
516 | goto out;
|
---|
517 | }
|
---|
518 |
|
---|
519 | oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
|
---|
520 | if (oplock_request) {
|
---|
521 | oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
|
---|
522 | ? BATCH_OPLOCK : 0;
|
---|
523 | }
|
---|
524 |
|
---|
525 | if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
|
---|
526 | case_state = set_posix_case_semantics(ctx, conn);
|
---|
527 | if (!case_state) {
|
---|
528 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
529 | goto out;
|
---|
530 | }
|
---|
531 | }
|
---|
532 |
|
---|
533 | status = filename_convert(ctx,
|
---|
534 | conn,
|
---|
535 | req->flags2 & FLAGS2_DFS_PATHNAMES,
|
---|
536 | fname,
|
---|
537 | 0,
|
---|
538 | NULL,
|
---|
539 | &smb_fname);
|
---|
540 |
|
---|
541 | TALLOC_FREE(case_state);
|
---|
542 |
|
---|
543 | if (!NT_STATUS_IS_OK(status)) {
|
---|
544 | if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
|
---|
545 | reply_botherror(req,
|
---|
546 | NT_STATUS_PATH_NOT_COVERED,
|
---|
547 | ERRSRV, ERRbadpath);
|
---|
548 | goto out;
|
---|
549 | }
|
---|
550 | reply_nterror(req, status);
|
---|
551 | goto out;
|
---|
552 | }
|
---|
553 |
|
---|
554 | /*
|
---|
555 | * Bug #6898 - clients using Windows opens should
|
---|
556 | * never be able to set this attribute into the
|
---|
557 | * VFS.
|
---|
558 | */
|
---|
559 | file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
|
---|
560 |
|
---|
561 | status = SMB_VFS_CREATE_FILE(
|
---|
562 | conn, /* conn */
|
---|
563 | req, /* req */
|
---|
564 | root_dir_fid, /* root_dir_fid */
|
---|
565 | smb_fname, /* fname */
|
---|
566 | access_mask, /* access_mask */
|
---|
567 | share_access, /* share_access */
|
---|
568 | create_disposition, /* create_disposition*/
|
---|
569 | create_options, /* create_options */
|
---|
570 | file_attributes, /* file_attributes */
|
---|
571 | oplock_request, /* oplock_request */
|
---|
572 | allocation_size, /* allocation_size */
|
---|
573 | NULL, /* sd */
|
---|
574 | NULL, /* ea_list */
|
---|
575 | &fsp, /* result */
|
---|
576 | &info); /* pinfo */
|
---|
577 |
|
---|
578 | if (!NT_STATUS_IS_OK(status)) {
|
---|
579 | if (open_was_deferred(req->mid)) {
|
---|
580 | /* We have re-scheduled this call, no error. */
|
---|
581 | goto out;
|
---|
582 | }
|
---|
583 | reply_openerror(req, status);
|
---|
584 | goto out;
|
---|
585 | }
|
---|
586 |
|
---|
587 | /* Ensure we're pointing at the correct stat struct. */
|
---|
588 | TALLOC_FREE(smb_fname);
|
---|
589 | smb_fname = fsp->fsp_name;
|
---|
590 |
|
---|
591 | /*
|
---|
592 | * If the caller set the extended oplock request bit
|
---|
593 | * and we granted one (by whatever means) - set the
|
---|
594 | * correct bit for extended oplock reply.
|
---|
595 | */
|
---|
596 |
|
---|
597 | if (oplock_request &&
|
---|
598 | (lp_fake_oplocks(SNUM(conn))
|
---|
599 | || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
|
---|
600 |
|
---|
601 | /*
|
---|
602 | * Exclusive oplock granted
|
---|
603 | */
|
---|
604 |
|
---|
605 | if (flags & REQUEST_BATCH_OPLOCK) {
|
---|
606 | oplock_granted = BATCH_OPLOCK_RETURN;
|
---|
607 | } else {
|
---|
608 | oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
|
---|
609 | }
|
---|
610 | } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
|
---|
611 | oplock_granted = LEVEL_II_OPLOCK_RETURN;
|
---|
612 | } else {
|
---|
613 | oplock_granted = NO_OPLOCK_RETURN;
|
---|
614 | }
|
---|
615 |
|
---|
616 | file_len = smb_fname->st.st_ex_size;
|
---|
617 |
|
---|
618 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
619 | /* This is very strange. We
|
---|
620 | * return 50 words, but only set
|
---|
621 | * the wcnt to 42 ? It's definately
|
---|
622 | * what happens on the wire....
|
---|
623 | */
|
---|
624 | reply_outbuf(req, 50, 0);
|
---|
625 | SCVAL(req->outbuf,smb_wct,42);
|
---|
626 | } else {
|
---|
627 | reply_outbuf(req, 34, 0);
|
---|
628 | }
|
---|
629 |
|
---|
630 | p = (char *)req->outbuf + smb_vwv2;
|
---|
631 |
|
---|
632 | SCVAL(p, 0, oplock_granted);
|
---|
633 |
|
---|
634 | p++;
|
---|
635 | SSVAL(p,0,fsp->fnum);
|
---|
636 | p += 2;
|
---|
637 | if ((create_disposition == FILE_SUPERSEDE)
|
---|
638 | && (info == FILE_WAS_OVERWRITTEN)) {
|
---|
639 | SIVAL(p,0,FILE_WAS_SUPERSEDED);
|
---|
640 | } else {
|
---|
641 | SIVAL(p,0,info);
|
---|
642 | }
|
---|
643 | p += 4;
|
---|
644 |
|
---|
645 | fattr = dos_mode(conn, smb_fname);
|
---|
646 | if (fattr == 0) {
|
---|
647 | fattr = FILE_ATTRIBUTE_NORMAL;
|
---|
648 | }
|
---|
649 |
|
---|
650 | /* Deal with other possible opens having a modified
|
---|
651 | write time. JRA. */
|
---|
652 | ZERO_STRUCT(write_time_ts);
|
---|
653 | get_file_infos(fsp->file_id, NULL, &write_time_ts);
|
---|
654 | if (!null_timespec(write_time_ts)) {
|
---|
655 | update_stat_ex_mtime(&smb_fname->st, write_time_ts);
|
---|
656 | }
|
---|
657 |
|
---|
658 | /* Create time. */
|
---|
659 | create_timespec = get_create_timespec(conn, fsp, smb_fname);
|
---|
660 | a_timespec = smb_fname->st.st_ex_atime;
|
---|
661 | m_timespec = smb_fname->st.st_ex_mtime;
|
---|
662 | c_timespec = get_change_timespec(conn, fsp, smb_fname);
|
---|
663 |
|
---|
664 | if (lp_dos_filetime_resolution(SNUM(conn))) {
|
---|
665 | dos_filetime_timespec(&create_timespec);
|
---|
666 | dos_filetime_timespec(&a_timespec);
|
---|
667 | dos_filetime_timespec(&m_timespec);
|
---|
668 | dos_filetime_timespec(&c_timespec);
|
---|
669 | }
|
---|
670 |
|
---|
671 | put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
|
---|
672 | p += 8;
|
---|
673 | put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
|
---|
674 | p += 8;
|
---|
675 | put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
|
---|
676 | p += 8;
|
---|
677 | put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
|
---|
678 | p += 8;
|
---|
679 | SIVAL(p,0,fattr); /* File Attributes. */
|
---|
680 | p += 4;
|
---|
681 | SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
|
---|
682 | p += 8;
|
---|
683 | SOFF_T(p,0,file_len);
|
---|
684 | p += 8;
|
---|
685 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
686 | uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
|
---|
687 | size_t num_names = 0;
|
---|
688 | unsigned int num_streams;
|
---|
689 | struct stream_struct *streams = NULL;
|
---|
690 |
|
---|
691 | /* Do we have any EA's ? */
|
---|
692 | status = get_ea_names_from_file(ctx, conn, fsp,
|
---|
693 | smb_fname->base_name, NULL, &num_names);
|
---|
694 | if (NT_STATUS_IS_OK(status) && num_names) {
|
---|
695 | file_status &= ~NO_EAS;
|
---|
696 | }
|
---|
697 | status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
|
---|
698 | &num_streams, &streams);
|
---|
699 | /* There is always one stream, ::$DATA. */
|
---|
700 | if (NT_STATUS_IS_OK(status) && num_streams > 1) {
|
---|
701 | file_status &= ~NO_SUBSTREAMS;
|
---|
702 | }
|
---|
703 | TALLOC_FREE(streams);
|
---|
704 | SSVAL(p,2,file_status);
|
---|
705 | }
|
---|
706 | p += 4;
|
---|
707 | SCVAL(p,0,fsp->is_directory ? 1 : 0);
|
---|
708 |
|
---|
709 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
710 | uint32 perms = 0;
|
---|
711 | p += 25;
|
---|
712 | if (fsp->is_directory ||
|
---|
713 | can_write_to_file(conn, smb_fname)) {
|
---|
714 | perms = FILE_GENERIC_ALL;
|
---|
715 | } else {
|
---|
716 | perms = FILE_GENERIC_READ|FILE_EXECUTE;
|
---|
717 | }
|
---|
718 | SIVAL(p,0,perms);
|
---|
719 | }
|
---|
720 |
|
---|
721 | DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
|
---|
722 | fsp->fnum, smb_fname_str_dbg(smb_fname)));
|
---|
723 |
|
---|
724 | chain_reply(req);
|
---|
725 | out:
|
---|
726 | END_PROFILE(SMBntcreateX);
|
---|
727 | return;
|
---|
728 | }
|
---|
729 |
|
---|
730 | /****************************************************************************
|
---|
731 | Reply to a NT_TRANSACT_CREATE call to open a pipe.
|
---|
732 | ****************************************************************************/
|
---|
733 |
|
---|
734 | static void do_nt_transact_create_pipe(connection_struct *conn,
|
---|
735 | struct smb_request *req,
|
---|
736 | uint16 **ppsetup, uint32 setup_count,
|
---|
737 | char **ppparams, uint32 parameter_count,
|
---|
738 | char **ppdata, uint32 data_count)
|
---|
739 | {
|
---|
740 | char *fname = NULL;
|
---|
741 | char *params = *ppparams;
|
---|
742 | int pnum = -1;
|
---|
743 | char *p = NULL;
|
---|
744 | NTSTATUS status;
|
---|
745 | size_t param_len;
|
---|
746 | uint32 flags;
|
---|
747 | TALLOC_CTX *ctx = talloc_tos();
|
---|
748 |
|
---|
749 | /*
|
---|
750 | * Ensure minimum number of parameters sent.
|
---|
751 | */
|
---|
752 |
|
---|
753 | if(parameter_count < 54) {
|
---|
754 | DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
|
---|
755 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
756 | return;
|
---|
757 | }
|
---|
758 |
|
---|
759 | flags = IVAL(params,0);
|
---|
760 |
|
---|
761 | srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
|
---|
762 | parameter_count-53, STR_TERMINATE,
|
---|
763 | &status);
|
---|
764 | if (!NT_STATUS_IS_OK(status)) {
|
---|
765 | reply_nterror(req, status);
|
---|
766 | return;
|
---|
767 | }
|
---|
768 |
|
---|
769 | nt_open_pipe(fname, conn, req, &pnum);
|
---|
770 |
|
---|
771 | if (req->outbuf) {
|
---|
772 | /* Error return */
|
---|
773 | return;
|
---|
774 | }
|
---|
775 |
|
---|
776 | /* Realloc the size of parameters and data we will return */
|
---|
777 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
778 | /* Extended response is 32 more byyes. */
|
---|
779 | param_len = 101;
|
---|
780 | } else {
|
---|
781 | param_len = 69;
|
---|
782 | }
|
---|
783 | params = nttrans_realloc(ppparams, param_len);
|
---|
784 | if(params == NULL) {
|
---|
785 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
786 | return;
|
---|
787 | }
|
---|
788 |
|
---|
789 | p = params;
|
---|
790 | SCVAL(p,0,NO_OPLOCK_RETURN);
|
---|
791 |
|
---|
792 | p += 2;
|
---|
793 | SSVAL(p,0,pnum);
|
---|
794 | p += 2;
|
---|
795 | SIVAL(p,0,FILE_WAS_OPENED);
|
---|
796 | p += 8;
|
---|
797 |
|
---|
798 | p += 32;
|
---|
799 | SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
|
---|
800 | p += 20;
|
---|
801 | /* File type. */
|
---|
802 | SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
|
---|
803 | /* Device state. */
|
---|
804 | SSVAL(p,2, 0x5FF); /* ? */
|
---|
805 | p += 4;
|
---|
806 |
|
---|
807 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
808 | p += 25;
|
---|
809 | SIVAL(p,0,FILE_GENERIC_ALL);
|
---|
810 | /*
|
---|
811 | * For pipes W2K3 seems to return
|
---|
812 | * 0x12019B next.
|
---|
813 | * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
|
---|
814 | */
|
---|
815 | SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
|
---|
816 | }
|
---|
817 |
|
---|
818 | DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
|
---|
819 |
|
---|
820 | /* Send the required number of replies */
|
---|
821 | send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
|
---|
822 |
|
---|
823 | return;
|
---|
824 | }
|
---|
825 |
|
---|
826 | /****************************************************************************
|
---|
827 | Internal fn to set security descriptors.
|
---|
828 | ****************************************************************************/
|
---|
829 |
|
---|
830 | static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
|
---|
831 | uint32 security_info_sent)
|
---|
832 | {
|
---|
833 | SEC_DESC *psd = NULL;
|
---|
834 | NTSTATUS status;
|
---|
835 |
|
---|
836 | if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
|
---|
837 | return NT_STATUS_OK;
|
---|
838 | }
|
---|
839 |
|
---|
840 | status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
|
---|
841 |
|
---|
842 | if (!NT_STATUS_IS_OK(status)) {
|
---|
843 | return status;
|
---|
844 | }
|
---|
845 |
|
---|
846 | if (psd->owner_sid == NULL) {
|
---|
847 | security_info_sent &= ~OWNER_SECURITY_INFORMATION;
|
---|
848 | }
|
---|
849 | if (psd->group_sid == NULL) {
|
---|
850 | security_info_sent &= ~GROUP_SECURITY_INFORMATION;
|
---|
851 | }
|
---|
852 |
|
---|
853 | /* Convert all the generic bits. */
|
---|
854 | security_acl_map_generic(psd->dacl, &file_generic_mapping);
|
---|
855 | security_acl_map_generic(psd->sacl, &file_generic_mapping);
|
---|
856 |
|
---|
857 | if (DEBUGLEVEL >= 10) {
|
---|
858 | DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
|
---|
859 | NDR_PRINT_DEBUG(security_descriptor, psd);
|
---|
860 | }
|
---|
861 |
|
---|
862 | status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
|
---|
863 |
|
---|
864 | TALLOC_FREE(psd);
|
---|
865 |
|
---|
866 | return status;
|
---|
867 | }
|
---|
868 |
|
---|
869 | /****************************************************************************
|
---|
870 | Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
|
---|
871 | ****************************************************************************/
|
---|
872 |
|
---|
873 | struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
|
---|
874 | {
|
---|
875 | struct ea_list *ea_list_head = NULL;
|
---|
876 | size_t offset = 0;
|
---|
877 |
|
---|
878 | if (data_size < 4) {
|
---|
879 | return NULL;
|
---|
880 | }
|
---|
881 |
|
---|
882 | while (offset + 4 <= data_size) {
|
---|
883 | size_t next_offset = IVAL(pdata,offset);
|
---|
884 | struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
|
---|
885 |
|
---|
886 | if (!eal) {
|
---|
887 | return NULL;
|
---|
888 | }
|
---|
889 |
|
---|
890 | DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
|
---|
891 | if (next_offset == 0) {
|
---|
892 | break;
|
---|
893 | }
|
---|
894 | offset += next_offset;
|
---|
895 | }
|
---|
896 |
|
---|
897 | return ea_list_head;
|
---|
898 | }
|
---|
899 |
|
---|
900 | /****************************************************************************
|
---|
901 | Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
|
---|
902 | ****************************************************************************/
|
---|
903 |
|
---|
904 | static void call_nt_transact_create(connection_struct *conn,
|
---|
905 | struct smb_request *req,
|
---|
906 | uint16 **ppsetup, uint32 setup_count,
|
---|
907 | char **ppparams, uint32 parameter_count,
|
---|
908 | char **ppdata, uint32 data_count,
|
---|
909 | uint32 max_data_count)
|
---|
910 | {
|
---|
911 | struct smb_filename *smb_fname = NULL;
|
---|
912 | char *fname = NULL;
|
---|
913 | char *params = *ppparams;
|
---|
914 | char *data = *ppdata;
|
---|
915 | /* Breakout the oplock request bits so we can set the reply bits separately. */
|
---|
916 | uint32 fattr=0;
|
---|
917 | SMB_OFF_T file_len = 0;
|
---|
918 | int info = 0;
|
---|
919 | files_struct *fsp = NULL;
|
---|
920 | char *p = NULL;
|
---|
921 | uint32 flags;
|
---|
922 | uint32 access_mask;
|
---|
923 | uint32 file_attributes;
|
---|
924 | uint32 share_access;
|
---|
925 | uint32 create_disposition;
|
---|
926 | uint32 create_options;
|
---|
927 | uint32 sd_len;
|
---|
928 | struct security_descriptor *sd = NULL;
|
---|
929 | uint32 ea_len;
|
---|
930 | uint16 root_dir_fid;
|
---|
931 | struct timespec create_timespec;
|
---|
932 | struct timespec c_timespec;
|
---|
933 | struct timespec a_timespec;
|
---|
934 | struct timespec m_timespec;
|
---|
935 | struct timespec write_time_ts;
|
---|
936 | struct ea_list *ea_list = NULL;
|
---|
937 | NTSTATUS status;
|
---|
938 | size_t param_len;
|
---|
939 | uint64_t allocation_size;
|
---|
940 | int oplock_request;
|
---|
941 | uint8_t oplock_granted;
|
---|
942 | struct case_semantics_state *case_state = NULL;
|
---|
943 | TALLOC_CTX *ctx = talloc_tos();
|
---|
944 |
|
---|
945 | DEBUG(5,("call_nt_transact_create\n"));
|
---|
946 |
|
---|
947 | /*
|
---|
948 | * If it's an IPC, use the pipe handler.
|
---|
949 | */
|
---|
950 |
|
---|
951 | if (IS_IPC(conn)) {
|
---|
952 | if (lp_nt_pipe_support()) {
|
---|
953 | do_nt_transact_create_pipe(
|
---|
954 | conn, req,
|
---|
955 | ppsetup, setup_count,
|
---|
956 | ppparams, parameter_count,
|
---|
957 | ppdata, data_count);
|
---|
958 | goto out;
|
---|
959 | }
|
---|
960 | reply_nterror(req, NT_STATUS_ACCESS_DENIED);
|
---|
961 | goto out;
|
---|
962 | }
|
---|
963 |
|
---|
964 | /*
|
---|
965 | * Ensure minimum number of parameters sent.
|
---|
966 | */
|
---|
967 |
|
---|
968 | if(parameter_count < 54) {
|
---|
969 | DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
|
---|
970 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
971 | goto out;
|
---|
972 | }
|
---|
973 |
|
---|
974 | flags = IVAL(params,0);
|
---|
975 | access_mask = IVAL(params,8);
|
---|
976 | file_attributes = IVAL(params,20);
|
---|
977 | share_access = IVAL(params,24);
|
---|
978 | create_disposition = IVAL(params,28);
|
---|
979 | create_options = IVAL(params,32);
|
---|
980 | sd_len = IVAL(params,36);
|
---|
981 | ea_len = IVAL(params,40);
|
---|
982 | root_dir_fid = (uint16)IVAL(params,4);
|
---|
983 | allocation_size = (uint64_t)IVAL(params,12);
|
---|
984 | #ifdef LARGE_SMB_OFF_T
|
---|
985 | allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
|
---|
986 | #endif
|
---|
987 |
|
---|
988 | /*
|
---|
989 | * we need to remove ignored bits when they come directly from the client
|
---|
990 | * because we reuse some of them for internal stuff
|
---|
991 | */
|
---|
992 | create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
|
---|
993 |
|
---|
994 | /* Ensure the data_len is correct for the sd and ea values given. */
|
---|
995 | if ((ea_len + sd_len > data_count)
|
---|
996 | || (ea_len > data_count) || (sd_len > data_count)
|
---|
997 | || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
|
---|
998 | DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
|
---|
999 | "%u, data_count = %u\n", (unsigned int)ea_len,
|
---|
1000 | (unsigned int)sd_len, (unsigned int)data_count));
|
---|
1001 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1002 | goto out;
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | if (sd_len) {
|
---|
1006 | DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
|
---|
1007 | sd_len));
|
---|
1008 |
|
---|
1009 | status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
|
---|
1010 | &sd);
|
---|
1011 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1012 | DEBUG(10, ("call_nt_transact_create: "
|
---|
1013 | "unmarshall_sec_desc failed: %s\n",
|
---|
1014 | nt_errstr(status)));
|
---|
1015 | reply_nterror(req, status);
|
---|
1016 | goto out;
|
---|
1017 | }
|
---|
1018 | }
|
---|
1019 |
|
---|
1020 | if (ea_len) {
|
---|
1021 | if (!lp_ea_support(SNUM(conn))) {
|
---|
1022 | DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
|
---|
1023 | "EA's not supported.\n",
|
---|
1024 | (unsigned int)ea_len));
|
---|
1025 | reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
|
---|
1026 | goto out;
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | if (ea_len < 10) {
|
---|
1030 | DEBUG(10,("call_nt_transact_create - ea_len = %u - "
|
---|
1031 | "too small (should be more than 10)\n",
|
---|
1032 | (unsigned int)ea_len ));
|
---|
1033 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1034 | goto out;
|
---|
1035 | }
|
---|
1036 |
|
---|
1037 | /* We have already checked that ea_len <= data_count here. */
|
---|
1038 | ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
|
---|
1039 | ea_len);
|
---|
1040 | if (ea_list == NULL) {
|
---|
1041 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1042 | goto out;
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | srvstr_get_path(ctx, params, req->flags2, &fname,
|
---|
1047 | params+53, parameter_count-53,
|
---|
1048 | STR_TERMINATE, &status);
|
---|
1049 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1050 | reply_nterror(req, status);
|
---|
1051 | goto out;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
|
---|
1055 | case_state = set_posix_case_semantics(ctx, conn);
|
---|
1056 | if (!case_state) {
|
---|
1057 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
1058 | goto out;
|
---|
1059 | }
|
---|
1060 | }
|
---|
1061 |
|
---|
1062 | status = filename_convert(ctx,
|
---|
1063 | conn,
|
---|
1064 | req->flags2 & FLAGS2_DFS_PATHNAMES,
|
---|
1065 | fname,
|
---|
1066 | 0,
|
---|
1067 | NULL,
|
---|
1068 | &smb_fname);
|
---|
1069 |
|
---|
1070 | TALLOC_FREE(case_state);
|
---|
1071 |
|
---|
1072 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1073 | if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
|
---|
1074 | reply_botherror(req,
|
---|
1075 | NT_STATUS_PATH_NOT_COVERED,
|
---|
1076 | ERRSRV, ERRbadpath);
|
---|
1077 | goto out;
|
---|
1078 | }
|
---|
1079 | reply_nterror(req, status);
|
---|
1080 | goto out;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
|
---|
1084 | if (oplock_request) {
|
---|
1085 | oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
|
---|
1086 | ? BATCH_OPLOCK : 0;
|
---|
1087 | }
|
---|
1088 |
|
---|
1089 | /*
|
---|
1090 | * Bug #6898 - clients using Windows opens should
|
---|
1091 | * never be able to set this attribute into the
|
---|
1092 | * VFS.
|
---|
1093 | */
|
---|
1094 | file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
|
---|
1095 |
|
---|
1096 | status = SMB_VFS_CREATE_FILE(
|
---|
1097 | conn, /* conn */
|
---|
1098 | req, /* req */
|
---|
1099 | root_dir_fid, /* root_dir_fid */
|
---|
1100 | smb_fname, /* fname */
|
---|
1101 | access_mask, /* access_mask */
|
---|
1102 | share_access, /* share_access */
|
---|
1103 | create_disposition, /* create_disposition*/
|
---|
1104 | create_options, /* create_options */
|
---|
1105 | file_attributes, /* file_attributes */
|
---|
1106 | oplock_request, /* oplock_request */
|
---|
1107 | allocation_size, /* allocation_size */
|
---|
1108 | sd, /* sd */
|
---|
1109 | ea_list, /* ea_list */
|
---|
1110 | &fsp, /* result */
|
---|
1111 | &info); /* pinfo */
|
---|
1112 |
|
---|
1113 | if(!NT_STATUS_IS_OK(status)) {
|
---|
1114 | if (open_was_deferred(req->mid)) {
|
---|
1115 | /* We have re-scheduled this call, no error. */
|
---|
1116 | return;
|
---|
1117 | }
|
---|
1118 | reply_openerror(req, status);
|
---|
1119 | goto out;
|
---|
1120 | }
|
---|
1121 |
|
---|
1122 | /* Ensure we're pointing at the correct stat struct. */
|
---|
1123 | TALLOC_FREE(smb_fname);
|
---|
1124 | smb_fname = fsp->fsp_name;
|
---|
1125 |
|
---|
1126 | /*
|
---|
1127 | * If the caller set the extended oplock request bit
|
---|
1128 | * and we granted one (by whatever means) - set the
|
---|
1129 | * correct bit for extended oplock reply.
|
---|
1130 | */
|
---|
1131 |
|
---|
1132 | if (oplock_request &&
|
---|
1133 | (lp_fake_oplocks(SNUM(conn))
|
---|
1134 | || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
|
---|
1135 |
|
---|
1136 | /*
|
---|
1137 | * Exclusive oplock granted
|
---|
1138 | */
|
---|
1139 |
|
---|
1140 | if (flags & REQUEST_BATCH_OPLOCK) {
|
---|
1141 | oplock_granted = BATCH_OPLOCK_RETURN;
|
---|
1142 | } else {
|
---|
1143 | oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
|
---|
1144 | }
|
---|
1145 | } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
|
---|
1146 | oplock_granted = LEVEL_II_OPLOCK_RETURN;
|
---|
1147 | } else {
|
---|
1148 | oplock_granted = NO_OPLOCK_RETURN;
|
---|
1149 | }
|
---|
1150 |
|
---|
1151 | file_len = smb_fname->st.st_ex_size;
|
---|
1152 |
|
---|
1153 | /* Realloc the size of parameters and data we will return */
|
---|
1154 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
1155 | /* Extended response is 32 more byyes. */
|
---|
1156 | param_len = 101;
|
---|
1157 | } else {
|
---|
1158 | param_len = 69;
|
---|
1159 | }
|
---|
1160 | params = nttrans_realloc(ppparams, param_len);
|
---|
1161 | if(params == NULL) {
|
---|
1162 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
1163 | goto out;
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | p = params;
|
---|
1167 | SCVAL(p, 0, oplock_granted);
|
---|
1168 |
|
---|
1169 | p += 2;
|
---|
1170 | SSVAL(p,0,fsp->fnum);
|
---|
1171 | p += 2;
|
---|
1172 | if ((create_disposition == FILE_SUPERSEDE)
|
---|
1173 | && (info == FILE_WAS_OVERWRITTEN)) {
|
---|
1174 | SIVAL(p,0,FILE_WAS_SUPERSEDED);
|
---|
1175 | } else {
|
---|
1176 | SIVAL(p,0,info);
|
---|
1177 | }
|
---|
1178 | p += 8;
|
---|
1179 |
|
---|
1180 | fattr = dos_mode(conn, smb_fname);
|
---|
1181 | if (fattr == 0) {
|
---|
1182 | fattr = FILE_ATTRIBUTE_NORMAL;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | /* Deal with other possible opens having a modified
|
---|
1186 | write time. JRA. */
|
---|
1187 | ZERO_STRUCT(write_time_ts);
|
---|
1188 | get_file_infos(fsp->file_id, NULL, &write_time_ts);
|
---|
1189 | if (!null_timespec(write_time_ts)) {
|
---|
1190 | update_stat_ex_mtime(&smb_fname->st, write_time_ts);
|
---|
1191 | }
|
---|
1192 |
|
---|
1193 | /* Create time. */
|
---|
1194 | create_timespec = get_create_timespec(conn, fsp, smb_fname);
|
---|
1195 | a_timespec = smb_fname->st.st_ex_atime;
|
---|
1196 | m_timespec = smb_fname->st.st_ex_mtime;
|
---|
1197 | c_timespec = get_change_timespec(conn, fsp, smb_fname);
|
---|
1198 |
|
---|
1199 | if (lp_dos_filetime_resolution(SNUM(conn))) {
|
---|
1200 | dos_filetime_timespec(&create_timespec);
|
---|
1201 | dos_filetime_timespec(&a_timespec);
|
---|
1202 | dos_filetime_timespec(&m_timespec);
|
---|
1203 | dos_filetime_timespec(&c_timespec);
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 | put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
|
---|
1207 | p += 8;
|
---|
1208 | put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
|
---|
1209 | p += 8;
|
---|
1210 | put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
|
---|
1211 | p += 8;
|
---|
1212 | put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
|
---|
1213 | p += 8;
|
---|
1214 | SIVAL(p,0,fattr); /* File Attributes. */
|
---|
1215 | p += 4;
|
---|
1216 | SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
|
---|
1217 | p += 8;
|
---|
1218 | SOFF_T(p,0,file_len);
|
---|
1219 | p += 8;
|
---|
1220 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
1221 | SSVAL(p,2,0x7);
|
---|
1222 | }
|
---|
1223 | p += 4;
|
---|
1224 | SCVAL(p,0,fsp->is_directory ? 1 : 0);
|
---|
1225 |
|
---|
1226 | if (flags & EXTENDED_RESPONSE_REQUIRED) {
|
---|
1227 | uint32 perms = 0;
|
---|
1228 | p += 25;
|
---|
1229 | if (fsp->is_directory ||
|
---|
1230 | can_write_to_file(conn, smb_fname)) {
|
---|
1231 | perms = FILE_GENERIC_ALL;
|
---|
1232 | } else {
|
---|
1233 | perms = FILE_GENERIC_READ|FILE_EXECUTE;
|
---|
1234 | }
|
---|
1235 | SIVAL(p,0,perms);
|
---|
1236 | }
|
---|
1237 |
|
---|
1238 | DEBUG(5,("call_nt_transact_create: open name = %s\n",
|
---|
1239 | smb_fname_str_dbg(smb_fname)));
|
---|
1240 |
|
---|
1241 | /* Send the required number of replies */
|
---|
1242 | send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
|
---|
1243 | out:
|
---|
1244 | return;
|
---|
1245 | }
|
---|
1246 |
|
---|
1247 | /****************************************************************************
|
---|
1248 | Reply to a NT CANCEL request.
|
---|
1249 | conn POINTER CAN BE NULL HERE !
|
---|
1250 | ****************************************************************************/
|
---|
1251 |
|
---|
1252 | void reply_ntcancel(struct smb_request *req)
|
---|
1253 | {
|
---|
1254 | /*
|
---|
1255 | * Go through and cancel any pending change notifies.
|
---|
1256 | */
|
---|
1257 |
|
---|
1258 | START_PROFILE(SMBntcancel);
|
---|
1259 | srv_cancel_sign_response(smbd_server_conn);
|
---|
1260 | remove_pending_change_notify_requests_by_mid(req->mid);
|
---|
1261 | remove_pending_lock_requests_by_mid(req->mid);
|
---|
1262 |
|
---|
1263 | DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
|
---|
1264 |
|
---|
1265 | END_PROFILE(SMBntcancel);
|
---|
1266 | return;
|
---|
1267 | }
|
---|
1268 |
|
---|
1269 | /****************************************************************************
|
---|
1270 | Copy a file.
|
---|
1271 | ****************************************************************************/
|
---|
1272 |
|
---|
1273 | static NTSTATUS copy_internals(TALLOC_CTX *ctx,
|
---|
1274 | connection_struct *conn,
|
---|
1275 | struct smb_request *req,
|
---|
1276 | struct smb_filename *smb_fname_src,
|
---|
1277 | struct smb_filename *smb_fname_dst,
|
---|
1278 | uint32 attrs)
|
---|
1279 | {
|
---|
1280 | files_struct *fsp1,*fsp2;
|
---|
1281 | uint32 fattr;
|
---|
1282 | int info;
|
---|
1283 | SMB_OFF_T ret=-1;
|
---|
1284 | NTSTATUS status = NT_STATUS_OK;
|
---|
1285 | char *parent;
|
---|
1286 |
|
---|
1287 | if (!CAN_WRITE(conn)) {
|
---|
1288 | status = NT_STATUS_MEDIA_WRITE_PROTECTED;
|
---|
1289 | goto out;
|
---|
1290 | }
|
---|
1291 |
|
---|
1292 | /* Source must already exist. */
|
---|
1293 | if (!VALID_STAT(smb_fname_src->st)) {
|
---|
1294 | status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
|
---|
1295 | goto out;
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | /* Ensure attributes match. */
|
---|
1299 | fattr = dos_mode(conn, smb_fname_src);
|
---|
1300 | if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
|
---|
1301 | status = NT_STATUS_NO_SUCH_FILE;
|
---|
1302 | goto out;
|
---|
1303 | }
|
---|
1304 |
|
---|
1305 | /* Disallow if dst file already exists. */
|
---|
1306 | if (VALID_STAT(smb_fname_dst->st)) {
|
---|
1307 | status = NT_STATUS_OBJECT_NAME_COLLISION;
|
---|
1308 | goto out;
|
---|
1309 | }
|
---|
1310 |
|
---|
1311 | /* No links from a directory. */
|
---|
1312 | if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
|
---|
1313 | status = NT_STATUS_FILE_IS_A_DIRECTORY;
|
---|
1314 | goto out;
|
---|
1315 | }
|
---|
1316 |
|
---|
1317 | DEBUG(10,("copy_internals: doing file copy %s to %s\n",
|
---|
1318 | smb_fname_str_dbg(smb_fname_src),
|
---|
1319 | smb_fname_str_dbg(smb_fname_dst)));
|
---|
1320 |
|
---|
1321 | status = SMB_VFS_CREATE_FILE(
|
---|
1322 | conn, /* conn */
|
---|
1323 | req, /* req */
|
---|
1324 | 0, /* root_dir_fid */
|
---|
1325 | smb_fname_src, /* fname */
|
---|
1326 | FILE_READ_DATA, /* access_mask */
|
---|
1327 | (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
|
---|
1328 | FILE_SHARE_DELETE),
|
---|
1329 | FILE_OPEN, /* create_disposition*/
|
---|
1330 | 0, /* create_options */
|
---|
1331 | FILE_ATTRIBUTE_NORMAL, /* file_attributes */
|
---|
1332 | NO_OPLOCK, /* oplock_request */
|
---|
1333 | 0, /* allocation_size */
|
---|
1334 | NULL, /* sd */
|
---|
1335 | NULL, /* ea_list */
|
---|
1336 | &fsp1, /* result */
|
---|
1337 | &info); /* pinfo */
|
---|
1338 |
|
---|
1339 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1340 | goto out;
|
---|
1341 | }
|
---|
1342 |
|
---|
1343 | status = SMB_VFS_CREATE_FILE(
|
---|
1344 | conn, /* conn */
|
---|
1345 | req, /* req */
|
---|
1346 | 0, /* root_dir_fid */
|
---|
1347 | smb_fname_dst, /* fname */
|
---|
1348 | FILE_WRITE_DATA, /* access_mask */
|
---|
1349 | (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
|
---|
1350 | FILE_SHARE_DELETE),
|
---|
1351 | FILE_CREATE, /* create_disposition*/
|
---|
1352 | 0, /* create_options */
|
---|
1353 | fattr, /* file_attributes */
|
---|
1354 | NO_OPLOCK, /* oplock_request */
|
---|
1355 | 0, /* allocation_size */
|
---|
1356 | NULL, /* sd */
|
---|
1357 | NULL, /* ea_list */
|
---|
1358 | &fsp2, /* result */
|
---|
1359 | &info); /* pinfo */
|
---|
1360 |
|
---|
1361 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1362 | close_file(NULL, fsp1, ERROR_CLOSE);
|
---|
1363 | goto out;
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | if (smb_fname_src->st.st_ex_size) {
|
---|
1367 | ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | /*
|
---|
1371 | * As we are opening fsp1 read-only we only expect
|
---|
1372 | * an error on close on fsp2 if we are out of space.
|
---|
1373 | * Thus we don't look at the error return from the
|
---|
1374 | * close of fsp1.
|
---|
1375 | */
|
---|
1376 | close_file(NULL, fsp1, NORMAL_CLOSE);
|
---|
1377 |
|
---|
1378 | /* Ensure the modtime is set correctly on the destination file. */
|
---|
1379 | set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
|
---|
1380 |
|
---|
1381 | status = close_file(NULL, fsp2, NORMAL_CLOSE);
|
---|
1382 |
|
---|
1383 | /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
|
---|
1384 | creates the file. This isn't the correct thing to do in the copy
|
---|
1385 | case. JRA */
|
---|
1386 | if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
|
---|
1387 | NULL)) {
|
---|
1388 | status = NT_STATUS_NO_MEMORY;
|
---|
1389 | goto out;
|
---|
1390 | }
|
---|
1391 | file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
|
---|
1392 | TALLOC_FREE(parent);
|
---|
1393 |
|
---|
1394 | if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
|
---|
1395 | status = NT_STATUS_DISK_FULL;
|
---|
1396 | goto out;
|
---|
1397 | }
|
---|
1398 | out:
|
---|
1399 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1400 | DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
|
---|
1401 | nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
|
---|
1402 | smb_fname_str_dbg(smb_fname_dst)));
|
---|
1403 | }
|
---|
1404 |
|
---|
1405 | return status;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /****************************************************************************
|
---|
1409 | Reply to a NT rename request.
|
---|
1410 | ****************************************************************************/
|
---|
1411 |
|
---|
1412 | void reply_ntrename(struct smb_request *req)
|
---|
1413 | {
|
---|
1414 | connection_struct *conn = req->conn;
|
---|
1415 | struct smb_filename *smb_fname_old = NULL;
|
---|
1416 | struct smb_filename *smb_fname_new = NULL;
|
---|
1417 | char *oldname = NULL;
|
---|
1418 | char *newname = NULL;
|
---|
1419 | const char *p;
|
---|
1420 | NTSTATUS status;
|
---|
1421 | bool src_has_wcard = False;
|
---|
1422 | bool dest_has_wcard = False;
|
---|
1423 | uint32 attrs;
|
---|
1424 | uint32_t ucf_flags_src = 0;
|
---|
1425 | uint32_t ucf_flags_dst = 0;
|
---|
1426 | uint16 rename_type;
|
---|
1427 | TALLOC_CTX *ctx = talloc_tos();
|
---|
1428 |
|
---|
1429 | START_PROFILE(SMBntrename);
|
---|
1430 |
|
---|
1431 | if (req->wct < 4) {
|
---|
1432 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1433 | goto out;
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | attrs = SVAL(req->vwv+0, 0);
|
---|
1437 | rename_type = SVAL(req->vwv+1, 0);
|
---|
1438 |
|
---|
1439 | p = (const char *)req->buf + 1;
|
---|
1440 | p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
|
---|
1441 | &status, &src_has_wcard);
|
---|
1442 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1443 | reply_nterror(req, status);
|
---|
1444 | goto out;
|
---|
1445 | }
|
---|
1446 |
|
---|
1447 | if (ms_has_wild(oldname)) {
|
---|
1448 | reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
|
---|
1449 | goto out;
|
---|
1450 | }
|
---|
1451 |
|
---|
1452 | p++;
|
---|
1453 | p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
|
---|
1454 | &status, &dest_has_wcard);
|
---|
1455 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1456 | reply_nterror(req, status);
|
---|
1457 | goto out;
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 | /* The newname must begin with a ':' if the oldname contains a ':'. */
|
---|
1461 | if (strchr_m(oldname, ':') && (newname[0] != ':')) {
|
---|
1462 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1463 | goto out;
|
---|
1464 | }
|
---|
1465 |
|
---|
1466 | /*
|
---|
1467 | * If this is a rename operation, allow wildcards and save the
|
---|
1468 | * destination's last component.
|
---|
1469 | */
|
---|
1470 | if (rename_type == RENAME_FLAG_RENAME) {
|
---|
1471 | ucf_flags_src = UCF_COND_ALLOW_WCARD_LCOMP;
|
---|
1472 | ucf_flags_dst = UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | /* rename_internals() calls unix_convert(), so don't call it here. */
|
---|
1476 | status = filename_convert(ctx, conn,
|
---|
1477 | req->flags2 & FLAGS2_DFS_PATHNAMES,
|
---|
1478 | oldname,
|
---|
1479 | ucf_flags_src,
|
---|
1480 | NULL,
|
---|
1481 | &smb_fname_old);
|
---|
1482 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1483 | if (NT_STATUS_EQUAL(status,
|
---|
1484 | NT_STATUS_PATH_NOT_COVERED)) {
|
---|
1485 | reply_botherror(req,
|
---|
1486 | NT_STATUS_PATH_NOT_COVERED,
|
---|
1487 | ERRSRV, ERRbadpath);
|
---|
1488 | goto out;
|
---|
1489 | }
|
---|
1490 | reply_nterror(req, status);
|
---|
1491 | goto out;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 | status = filename_convert(ctx, conn,
|
---|
1495 | req->flags2 & FLAGS2_DFS_PATHNAMES,
|
---|
1496 | newname,
|
---|
1497 | ucf_flags_dst,
|
---|
1498 | &dest_has_wcard,
|
---|
1499 | &smb_fname_new);
|
---|
1500 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1501 | if (NT_STATUS_EQUAL(status,
|
---|
1502 | NT_STATUS_PATH_NOT_COVERED)) {
|
---|
1503 | reply_botherror(req,
|
---|
1504 | NT_STATUS_PATH_NOT_COVERED,
|
---|
1505 | ERRSRV, ERRbadpath);
|
---|
1506 | goto out;
|
---|
1507 | }
|
---|
1508 | reply_nterror(req, status);
|
---|
1509 | goto out;
|
---|
1510 | }
|
---|
1511 |
|
---|
1512 | DEBUG(3,("reply_ntrename: %s -> %s\n",
|
---|
1513 | smb_fname_str_dbg(smb_fname_old),
|
---|
1514 | smb_fname_str_dbg(smb_fname_new)));
|
---|
1515 |
|
---|
1516 | switch(rename_type) {
|
---|
1517 | case RENAME_FLAG_RENAME:
|
---|
1518 | status = rename_internals(ctx, conn, req,
|
---|
1519 | smb_fname_old, smb_fname_new,
|
---|
1520 | attrs, False, src_has_wcard,
|
---|
1521 | dest_has_wcard,
|
---|
1522 | DELETE_ACCESS);
|
---|
1523 | break;
|
---|
1524 | case RENAME_FLAG_HARD_LINK:
|
---|
1525 | if (src_has_wcard || dest_has_wcard) {
|
---|
1526 | /* No wildcards. */
|
---|
1527 | status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
|
---|
1528 | } else {
|
---|
1529 | status = hardlink_internals(ctx, conn,
|
---|
1530 | smb_fname_old,
|
---|
1531 | smb_fname_new);
|
---|
1532 | }
|
---|
1533 | break;
|
---|
1534 | case RENAME_FLAG_COPY:
|
---|
1535 | if (src_has_wcard || dest_has_wcard) {
|
---|
1536 | /* No wildcards. */
|
---|
1537 | status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
|
---|
1538 | } else {
|
---|
1539 | status = copy_internals(ctx, conn, req,
|
---|
1540 | smb_fname_old,
|
---|
1541 | smb_fname_new,
|
---|
1542 | attrs);
|
---|
1543 | }
|
---|
1544 | break;
|
---|
1545 | case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
|
---|
1546 | status = NT_STATUS_INVALID_PARAMETER;
|
---|
1547 | break;
|
---|
1548 | default:
|
---|
1549 | status = NT_STATUS_ACCESS_DENIED; /* Default error. */
|
---|
1550 | break;
|
---|
1551 | }
|
---|
1552 |
|
---|
1553 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1554 | if (open_was_deferred(req->mid)) {
|
---|
1555 | /* We have re-scheduled this call. */
|
---|
1556 | goto out;
|
---|
1557 | }
|
---|
1558 |
|
---|
1559 | reply_nterror(req, status);
|
---|
1560 | goto out;
|
---|
1561 | }
|
---|
1562 |
|
---|
1563 | reply_outbuf(req, 0, 0);
|
---|
1564 | out:
|
---|
1565 | END_PROFILE(SMBntrename);
|
---|
1566 | return;
|
---|
1567 | }
|
---|
1568 |
|
---|
1569 | /****************************************************************************
|
---|
1570 | Reply to a notify change - queue the request and
|
---|
1571 | don't allow a directory to be opened.
|
---|
1572 | ****************************************************************************/
|
---|
1573 |
|
---|
1574 | static void smbd_smb1_notify_reply(struct smb_request *req,
|
---|
1575 | NTSTATUS error_code,
|
---|
1576 | uint8_t *buf, size_t len)
|
---|
1577 | {
|
---|
1578 | send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | static void call_nt_transact_notify_change(connection_struct *conn,
|
---|
1582 | struct smb_request *req,
|
---|
1583 | uint16 **ppsetup,
|
---|
1584 | uint32 setup_count,
|
---|
1585 | char **ppparams,
|
---|
1586 | uint32 parameter_count,
|
---|
1587 | char **ppdata, uint32 data_count,
|
---|
1588 | uint32 max_data_count,
|
---|
1589 | uint32 max_param_count)
|
---|
1590 | {
|
---|
1591 | uint16 *setup = *ppsetup;
|
---|
1592 | files_struct *fsp;
|
---|
1593 | uint32 filter;
|
---|
1594 | NTSTATUS status;
|
---|
1595 | bool recursive;
|
---|
1596 |
|
---|
1597 | if(setup_count < 6) {
|
---|
1598 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1599 | return;
|
---|
1600 | }
|
---|
1601 |
|
---|
1602 | fsp = file_fsp(req, SVAL(setup,4));
|
---|
1603 | filter = IVAL(setup, 0);
|
---|
1604 | recursive = (SVAL(setup, 6) != 0) ? True : False;
|
---|
1605 |
|
---|
1606 | DEBUG(3,("call_nt_transact_notify_change\n"));
|
---|
1607 |
|
---|
1608 | if(!fsp) {
|
---|
1609 | reply_nterror(req, NT_STATUS_INVALID_HANDLE);
|
---|
1610 | return;
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | {
|
---|
1614 | char *filter_string;
|
---|
1615 |
|
---|
1616 | if (!(filter_string = notify_filter_string(NULL, filter))) {
|
---|
1617 | reply_nterror(req,NT_STATUS_NO_MEMORY);
|
---|
1618 | return;
|
---|
1619 | }
|
---|
1620 |
|
---|
1621 | DEBUG(3,("call_nt_transact_notify_change: notify change "
|
---|
1622 | "called on %s, filter = %s, recursive = %d\n",
|
---|
1623 | fsp_str_dbg(fsp), filter_string, recursive));
|
---|
1624 |
|
---|
1625 | TALLOC_FREE(filter_string);
|
---|
1626 | }
|
---|
1627 |
|
---|
1628 | if((!fsp->is_directory) || (conn != fsp->conn)) {
|
---|
1629 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1630 | return;
|
---|
1631 | }
|
---|
1632 |
|
---|
1633 | if (fsp->notify == NULL) {
|
---|
1634 |
|
---|
1635 | status = change_notify_create(fsp, filter, recursive);
|
---|
1636 |
|
---|
1637 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1638 | DEBUG(10, ("change_notify_create returned %s\n",
|
---|
1639 | nt_errstr(status)));
|
---|
1640 | reply_nterror(req, status);
|
---|
1641 | return;
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 |
|
---|
1645 | if (fsp->notify->num_changes != 0) {
|
---|
1646 |
|
---|
1647 | /*
|
---|
1648 | * We've got changes pending, respond immediately
|
---|
1649 | */
|
---|
1650 |
|
---|
1651 | /*
|
---|
1652 | * TODO: write a torture test to check the filtering behaviour
|
---|
1653 | * here.
|
---|
1654 | */
|
---|
1655 |
|
---|
1656 | change_notify_reply(fsp->conn, req,
|
---|
1657 | NT_STATUS_OK,
|
---|
1658 | max_param_count,
|
---|
1659 | fsp->notify,
|
---|
1660 | smbd_smb1_notify_reply);
|
---|
1661 |
|
---|
1662 | /*
|
---|
1663 | * change_notify_reply() above has independently sent its
|
---|
1664 | * results
|
---|
1665 | */
|
---|
1666 | return;
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | /*
|
---|
1670 | * No changes pending, queue the request
|
---|
1671 | */
|
---|
1672 |
|
---|
1673 | status = change_notify_add_request(req,
|
---|
1674 | max_param_count,
|
---|
1675 | filter,
|
---|
1676 | recursive, fsp,
|
---|
1677 | smbd_smb1_notify_reply);
|
---|
1678 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1679 | reply_nterror(req, status);
|
---|
1680 | }
|
---|
1681 | return;
|
---|
1682 | }
|
---|
1683 |
|
---|
1684 | /****************************************************************************
|
---|
1685 | Reply to an NT transact rename command.
|
---|
1686 | ****************************************************************************/
|
---|
1687 |
|
---|
1688 | static void call_nt_transact_rename(connection_struct *conn,
|
---|
1689 | struct smb_request *req,
|
---|
1690 | uint16 **ppsetup, uint32 setup_count,
|
---|
1691 | char **ppparams, uint32 parameter_count,
|
---|
1692 | char **ppdata, uint32 data_count,
|
---|
1693 | uint32 max_data_count)
|
---|
1694 | {
|
---|
1695 | char *params = *ppparams;
|
---|
1696 | char *new_name = NULL;
|
---|
1697 | files_struct *fsp = NULL;
|
---|
1698 | bool dest_has_wcard = False;
|
---|
1699 | NTSTATUS status;
|
---|
1700 | TALLOC_CTX *ctx = talloc_tos();
|
---|
1701 |
|
---|
1702 | if(parameter_count < 5) {
|
---|
1703 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1704 | return;
|
---|
1705 | }
|
---|
1706 |
|
---|
1707 | fsp = file_fsp(req, SVAL(params, 0));
|
---|
1708 | if (!check_fsp(conn, req, fsp)) {
|
---|
1709 | return;
|
---|
1710 | }
|
---|
1711 | srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
|
---|
1712 | parameter_count - 4,
|
---|
1713 | STR_TERMINATE, &status, &dest_has_wcard);
|
---|
1714 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1715 | reply_nterror(req, status);
|
---|
1716 | return;
|
---|
1717 | }
|
---|
1718 |
|
---|
1719 | /*
|
---|
1720 | * W2K3 ignores this request as the RAW-RENAME test
|
---|
1721 | * demonstrates, so we do.
|
---|
1722 | */
|
---|
1723 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
|
---|
1724 |
|
---|
1725 | DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
|
---|
1726 | fsp_str_dbg(fsp), new_name));
|
---|
1727 |
|
---|
1728 | return;
|
---|
1729 | }
|
---|
1730 |
|
---|
1731 | /******************************************************************************
|
---|
1732 | Fake up a completely empty SD.
|
---|
1733 | *******************************************************************************/
|
---|
1734 |
|
---|
1735 | static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
|
---|
1736 | {
|
---|
1737 | size_t sd_size;
|
---|
1738 |
|
---|
1739 | *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
|
---|
1740 | if(!*ppsd) {
|
---|
1741 | DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
|
---|
1742 | return NT_STATUS_NO_MEMORY;
|
---|
1743 | }
|
---|
1744 |
|
---|
1745 | return NT_STATUS_OK;
|
---|
1746 | }
|
---|
1747 |
|
---|
1748 | /****************************************************************************
|
---|
1749 | Reply to query a security descriptor.
|
---|
1750 | ****************************************************************************/
|
---|
1751 |
|
---|
1752 | static void call_nt_transact_query_security_desc(connection_struct *conn,
|
---|
1753 | struct smb_request *req,
|
---|
1754 | uint16 **ppsetup,
|
---|
1755 | uint32 setup_count,
|
---|
1756 | char **ppparams,
|
---|
1757 | uint32 parameter_count,
|
---|
1758 | char **ppdata,
|
---|
1759 | uint32 data_count,
|
---|
1760 | uint32 max_data_count)
|
---|
1761 | {
|
---|
1762 | char *params = *ppparams;
|
---|
1763 | char *data = *ppdata;
|
---|
1764 | SEC_DESC *psd = NULL;
|
---|
1765 | size_t sd_size;
|
---|
1766 | uint32 security_info_wanted;
|
---|
1767 | files_struct *fsp = NULL;
|
---|
1768 | NTSTATUS status;
|
---|
1769 | DATA_BLOB blob;
|
---|
1770 |
|
---|
1771 | if(parameter_count < 8) {
|
---|
1772 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1773 | return;
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | fsp = file_fsp(req, SVAL(params,0));
|
---|
1777 | if(!fsp) {
|
---|
1778 | reply_nterror(req, NT_STATUS_INVALID_HANDLE);
|
---|
1779 | return;
|
---|
1780 | }
|
---|
1781 |
|
---|
1782 | security_info_wanted = IVAL(params,4);
|
---|
1783 |
|
---|
1784 | DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
|
---|
1785 | "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
|
---|
1786 | (unsigned int)security_info_wanted));
|
---|
1787 |
|
---|
1788 | params = nttrans_realloc(ppparams, 4);
|
---|
1789 | if(params == NULL) {
|
---|
1790 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
1791 | return;
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 | /*
|
---|
1795 | * Get the permissions to return.
|
---|
1796 | */
|
---|
1797 |
|
---|
1798 | if (!lp_nt_acl_support(SNUM(conn))) {
|
---|
1799 | status = get_null_nt_acl(talloc_tos(), &psd);
|
---|
1800 | } else {
|
---|
1801 | status = SMB_VFS_FGET_NT_ACL(
|
---|
1802 | fsp, security_info_wanted, &psd);
|
---|
1803 | }
|
---|
1804 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1805 | reply_nterror(req, status);
|
---|
1806 | return;
|
---|
1807 | }
|
---|
1808 |
|
---|
1809 | /* If the SACL/DACL is NULL, but was requested, we mark that it is
|
---|
1810 | * present in the reply to match Windows behavior */
|
---|
1811 | if (psd->sacl == NULL &&
|
---|
1812 | security_info_wanted & SACL_SECURITY_INFORMATION)
|
---|
1813 | psd->type |= SEC_DESC_SACL_PRESENT;
|
---|
1814 | if (psd->dacl == NULL &&
|
---|
1815 | security_info_wanted & DACL_SECURITY_INFORMATION)
|
---|
1816 | psd->type |= SEC_DESC_DACL_PRESENT;
|
---|
1817 |
|
---|
1818 | sd_size = ndr_size_security_descriptor(psd, NULL, 0);
|
---|
1819 |
|
---|
1820 | DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
|
---|
1821 |
|
---|
1822 | if (DEBUGLEVEL >= 10) {
|
---|
1823 | DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
|
---|
1824 | fsp_str_dbg(fsp)));
|
---|
1825 | NDR_PRINT_DEBUG(security_descriptor, psd);
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | SIVAL(params,0,(uint32)sd_size);
|
---|
1829 |
|
---|
1830 | if (max_data_count < sd_size) {
|
---|
1831 | send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
|
---|
1832 | params, 4, *ppdata, 0);
|
---|
1833 | return;
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | /*
|
---|
1837 | * Allocate the data we will point this at.
|
---|
1838 | */
|
---|
1839 |
|
---|
1840 | data = nttrans_realloc(ppdata, sd_size);
|
---|
1841 | if(data == NULL) {
|
---|
1842 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
1843 | return;
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | status = marshall_sec_desc(talloc_tos(), psd,
|
---|
1847 | &blob.data, &blob.length);
|
---|
1848 |
|
---|
1849 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1850 | reply_nterror(req, status);
|
---|
1851 | return;
|
---|
1852 | }
|
---|
1853 |
|
---|
1854 | SMB_ASSERT(sd_size == blob.length);
|
---|
1855 | memcpy(data, blob.data, sd_size);
|
---|
1856 |
|
---|
1857 | send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
|
---|
1858 |
|
---|
1859 | return;
|
---|
1860 | }
|
---|
1861 |
|
---|
1862 | /****************************************************************************
|
---|
1863 | Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
|
---|
1864 | ****************************************************************************/
|
---|
1865 |
|
---|
1866 | static void call_nt_transact_set_security_desc(connection_struct *conn,
|
---|
1867 | struct smb_request *req,
|
---|
1868 | uint16 **ppsetup,
|
---|
1869 | uint32 setup_count,
|
---|
1870 | char **ppparams,
|
---|
1871 | uint32 parameter_count,
|
---|
1872 | char **ppdata,
|
---|
1873 | uint32 data_count,
|
---|
1874 | uint32 max_data_count)
|
---|
1875 | {
|
---|
1876 | char *params= *ppparams;
|
---|
1877 | char *data = *ppdata;
|
---|
1878 | files_struct *fsp = NULL;
|
---|
1879 | uint32 security_info_sent = 0;
|
---|
1880 | NTSTATUS status;
|
---|
1881 |
|
---|
1882 | if(parameter_count < 8) {
|
---|
1883 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1884 | return;
|
---|
1885 | }
|
---|
1886 |
|
---|
1887 | if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
|
---|
1888 | reply_nterror(req, NT_STATUS_INVALID_HANDLE);
|
---|
1889 | return;
|
---|
1890 | }
|
---|
1891 |
|
---|
1892 | if(!lp_nt_acl_support(SNUM(conn))) {
|
---|
1893 | goto done;
|
---|
1894 | }
|
---|
1895 |
|
---|
1896 | security_info_sent = IVAL(params,4);
|
---|
1897 |
|
---|
1898 | DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
|
---|
1899 | fsp_str_dbg(fsp), (unsigned int)security_info_sent));
|
---|
1900 |
|
---|
1901 | if (data_count == 0) {
|
---|
1902 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
1903 | return;
|
---|
1904 | }
|
---|
1905 |
|
---|
1906 | status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
|
---|
1907 |
|
---|
1908 | if (!NT_STATUS_IS_OK(status)) {
|
---|
1909 | reply_nterror(req, status);
|
---|
1910 | return;
|
---|
1911 | }
|
---|
1912 |
|
---|
1913 | done:
|
---|
1914 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
|
---|
1915 | return;
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | /****************************************************************************
|
---|
1919 | Reply to NT IOCTL
|
---|
1920 | ****************************************************************************/
|
---|
1921 |
|
---|
1922 | static void call_nt_transact_ioctl(connection_struct *conn,
|
---|
1923 | struct smb_request *req,
|
---|
1924 | uint16 **ppsetup, uint32 setup_count,
|
---|
1925 | char **ppparams, uint32 parameter_count,
|
---|
1926 | char **ppdata, uint32 data_count,
|
---|
1927 | uint32 max_data_count)
|
---|
1928 | {
|
---|
1929 | uint32 function;
|
---|
1930 | uint16 fidnum;
|
---|
1931 | files_struct *fsp;
|
---|
1932 | uint8 isFSctl;
|
---|
1933 | uint8 compfilter;
|
---|
1934 | char *pdata = *ppdata;
|
---|
1935 |
|
---|
1936 | if (setup_count != 8) {
|
---|
1937 | DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
|
---|
1938 | reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
|
---|
1939 | return;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 | function = IVAL(*ppsetup, 0);
|
---|
1943 | fidnum = SVAL(*ppsetup, 4);
|
---|
1944 | isFSctl = CVAL(*ppsetup, 6);
|
---|
1945 | compfilter = CVAL(*ppsetup, 7);
|
---|
1946 |
|
---|
1947 | DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
|
---|
1948 | function, fidnum, isFSctl, compfilter));
|
---|
1949 |
|
---|
1950 | fsp=file_fsp(req, fidnum);
|
---|
1951 | /* this check is done in each implemented function case for now
|
---|
1952 | because I don't want to break anything... --metze
|
---|
1953 | FSP_BELONGS_CONN(fsp,conn);*/
|
---|
1954 |
|
---|
1955 | SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
|
---|
1956 |
|
---|
1957 | switch (function) {
|
---|
1958 | case FSCTL_SET_SPARSE:
|
---|
1959 | /* pretend this succeeded - tho strictly we should
|
---|
1960 | mark the file sparse (if the local fs supports it)
|
---|
1961 | so we can know if we need to pre-allocate or not */
|
---|
1962 |
|
---|
1963 | DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
|
---|
1964 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
|
---|
1965 | return;
|
---|
1966 |
|
---|
1967 | case FSCTL_CREATE_OR_GET_OBJECT_ID:
|
---|
1968 | {
|
---|
1969 | unsigned char objid[16];
|
---|
1970 |
|
---|
1971 | /* This should return the object-id on this file.
|
---|
1972 | * I think I'll make this be the inode+dev. JRA.
|
---|
1973 | */
|
---|
1974 |
|
---|
1975 | DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
|
---|
1976 |
|
---|
1977 | if (!fsp_belongs_conn(conn, req, fsp)) {
|
---|
1978 | return;
|
---|
1979 | }
|
---|
1980 |
|
---|
1981 | data_count = 64;
|
---|
1982 | pdata = nttrans_realloc(ppdata, data_count);
|
---|
1983 | if (pdata == NULL) {
|
---|
1984 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
1985 | return;
|
---|
1986 | }
|
---|
1987 |
|
---|
1988 | /* For backwards compatibility only store the dev/inode. */
|
---|
1989 | push_file_id_16(pdata, &fsp->file_id);
|
---|
1990 | memcpy(pdata+16,create_volume_objectid(conn,objid),16);
|
---|
1991 | push_file_id_16(pdata+32, &fsp->file_id);
|
---|
1992 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
|
---|
1993 | pdata, data_count);
|
---|
1994 | return;
|
---|
1995 | }
|
---|
1996 |
|
---|
1997 | case FSCTL_GET_REPARSE_POINT:
|
---|
1998 | /* pretend this fail - my winXP does it like this
|
---|
1999 | * --metze
|
---|
2000 | */
|
---|
2001 |
|
---|
2002 | DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
|
---|
2003 | reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
|
---|
2004 | return;
|
---|
2005 |
|
---|
2006 | case FSCTL_SET_REPARSE_POINT:
|
---|
2007 | /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
|
---|
2008 | * --metze
|
---|
2009 | */
|
---|
2010 |
|
---|
2011 | DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
|
---|
2012 | reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
|
---|
2013 | return;
|
---|
2014 |
|
---|
2015 | case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
|
---|
2016 | {
|
---|
2017 | /*
|
---|
2018 | * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
|
---|
2019 | * and return their volume names. If max_data_count is 16, then it is just
|
---|
2020 | * asking for the number of volumes and length of the combined names.
|
---|
2021 | *
|
---|
2022 | * pdata is the data allocated by our caller, but that uses
|
---|
2023 | * total_data_count (which is 0 in our case) rather than max_data_count.
|
---|
2024 | * Allocate the correct amount and return the pointer to let
|
---|
2025 | * it be deallocated when we return.
|
---|
2026 | */
|
---|
2027 | SHADOW_COPY_DATA *shadow_data = NULL;
|
---|
2028 | TALLOC_CTX *shadow_mem_ctx = NULL;
|
---|
2029 | bool labels = False;
|
---|
2030 | uint32 labels_data_count = 0;
|
---|
2031 | uint32 i;
|
---|
2032 | char *cur_pdata;
|
---|
2033 |
|
---|
2034 | if (!fsp_belongs_conn(conn, req, fsp)) {
|
---|
2035 | return;
|
---|
2036 | }
|
---|
2037 |
|
---|
2038 | if (max_data_count < 16) {
|
---|
2039 | DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
|
---|
2040 | max_data_count));
|
---|
2041 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2042 | return;
|
---|
2043 | }
|
---|
2044 |
|
---|
2045 | if (max_data_count > 16) {
|
---|
2046 | labels = True;
|
---|
2047 | }
|
---|
2048 |
|
---|
2049 | shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
|
---|
2050 | if (shadow_mem_ctx == NULL) {
|
---|
2051 | DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
|
---|
2052 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2053 | return;
|
---|
2054 | }
|
---|
2055 |
|
---|
2056 | shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
|
---|
2057 | if (shadow_data == NULL) {
|
---|
2058 | DEBUG(0,("TALLOC_ZERO() failed!\n"));
|
---|
2059 | talloc_destroy(shadow_mem_ctx);
|
---|
2060 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2061 | return;
|
---|
2062 | }
|
---|
2063 |
|
---|
2064 | shadow_data->mem_ctx = shadow_mem_ctx;
|
---|
2065 |
|
---|
2066 | /*
|
---|
2067 | * Call the VFS routine to actually do the work.
|
---|
2068 | */
|
---|
2069 | if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
|
---|
2070 | talloc_destroy(shadow_data->mem_ctx);
|
---|
2071 | if (errno == ENOSYS) {
|
---|
2072 | DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
|
---|
2073 | conn->connectpath));
|
---|
2074 | reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
|
---|
2075 | return;
|
---|
2076 | } else {
|
---|
2077 | DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
|
---|
2078 | conn->connectpath));
|
---|
2079 | reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
|
---|
2080 | return;
|
---|
2081 | }
|
---|
2082 | }
|
---|
2083 |
|
---|
2084 | labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
|
---|
2085 |
|
---|
2086 | if (!labels) {
|
---|
2087 | data_count = 16;
|
---|
2088 | } else {
|
---|
2089 | data_count = 12+labels_data_count+4;
|
---|
2090 | }
|
---|
2091 |
|
---|
2092 | if (max_data_count<data_count) {
|
---|
2093 | DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
|
---|
2094 | max_data_count,data_count));
|
---|
2095 | talloc_destroy(shadow_data->mem_ctx);
|
---|
2096 | reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
|
---|
2097 | return;
|
---|
2098 | }
|
---|
2099 |
|
---|
2100 | pdata = nttrans_realloc(ppdata, data_count);
|
---|
2101 | if (pdata == NULL) {
|
---|
2102 | talloc_destroy(shadow_data->mem_ctx);
|
---|
2103 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2104 | return;
|
---|
2105 | }
|
---|
2106 |
|
---|
2107 | cur_pdata = pdata;
|
---|
2108 |
|
---|
2109 | /* num_volumes 4 bytes */
|
---|
2110 | SIVAL(pdata,0,shadow_data->num_volumes);
|
---|
2111 |
|
---|
2112 | if (labels) {
|
---|
2113 | /* num_labels 4 bytes */
|
---|
2114 | SIVAL(pdata,4,shadow_data->num_volumes);
|
---|
2115 | }
|
---|
2116 |
|
---|
2117 | /* needed_data_count 4 bytes */
|
---|
2118 | SIVAL(pdata, 8, labels_data_count+4);
|
---|
2119 |
|
---|
2120 | cur_pdata+=12;
|
---|
2121 |
|
---|
2122 | DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
|
---|
2123 | shadow_data->num_volumes, fsp_str_dbg(fsp)));
|
---|
2124 | if (labels && shadow_data->labels) {
|
---|
2125 | for (i=0;i<shadow_data->num_volumes;i++) {
|
---|
2126 | srvstr_push(pdata, req->flags2,
|
---|
2127 | cur_pdata, shadow_data->labels[i],
|
---|
2128 | 2*sizeof(SHADOW_COPY_LABEL),
|
---|
2129 | STR_UNICODE|STR_TERMINATE);
|
---|
2130 | cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
|
---|
2131 | DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
|
---|
2132 | }
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 | talloc_destroy(shadow_data->mem_ctx);
|
---|
2136 |
|
---|
2137 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
|
---|
2138 | pdata, data_count);
|
---|
2139 |
|
---|
2140 | return;
|
---|
2141 | }
|
---|
2142 |
|
---|
2143 | case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
|
---|
2144 | {
|
---|
2145 | /* pretend this succeeded -
|
---|
2146 | *
|
---|
2147 | * we have to send back a list with all files owned by this SID
|
---|
2148 | *
|
---|
2149 | * but I have to check that --metze
|
---|
2150 | */
|
---|
2151 | DOM_SID sid;
|
---|
2152 | uid_t uid;
|
---|
2153 | size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
|
---|
2154 |
|
---|
2155 | DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
|
---|
2156 |
|
---|
2157 | if (!fsp_belongs_conn(conn, req, fsp)) {
|
---|
2158 | return;
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | /* unknown 4 bytes: this is not the length of the sid :-( */
|
---|
2162 | /*unknown = IVAL(pdata,0);*/
|
---|
2163 |
|
---|
2164 | if (!sid_parse(pdata+4,sid_len,&sid)) {
|
---|
2165 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2166 | return;
|
---|
2167 | }
|
---|
2168 |
|
---|
2169 | DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
|
---|
2170 |
|
---|
2171 | if (!sid_to_uid(&sid, &uid)) {
|
---|
2172 | DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
|
---|
2173 | sid_string_dbg(&sid),
|
---|
2174 | (unsigned long)sid_len));
|
---|
2175 | uid = (-1);
|
---|
2176 | }
|
---|
2177 |
|
---|
2178 | /* we can take a look at the find source :-)
|
---|
2179 | *
|
---|
2180 | * find ./ -uid $uid -name '*' is what we need here
|
---|
2181 | *
|
---|
2182 | *
|
---|
2183 | * and send 4bytes len and then NULL terminated unicode strings
|
---|
2184 | * for each file
|
---|
2185 | *
|
---|
2186 | * but I don't know how to deal with the paged results
|
---|
2187 | * (maybe we can hang the result anywhere in the fsp struct)
|
---|
2188 | *
|
---|
2189 | * we don't send all files at once
|
---|
2190 | * and at the next we should *not* start from the beginning,
|
---|
2191 | * so we have to cache the result
|
---|
2192 | *
|
---|
2193 | * --metze
|
---|
2194 | */
|
---|
2195 |
|
---|
2196 | /* this works for now... */
|
---|
2197 | send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
|
---|
2198 | return;
|
---|
2199 | }
|
---|
2200 | default:
|
---|
2201 | if (!logged_ioctl_message) {
|
---|
2202 | logged_ioctl_message = true; /* Only print this once... */
|
---|
2203 | DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
|
---|
2204 | function));
|
---|
2205 | }
|
---|
2206 | }
|
---|
2207 |
|
---|
2208 | reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
|
---|
2209 | }
|
---|
2210 |
|
---|
2211 |
|
---|
2212 | #ifdef HAVE_SYS_QUOTAS
|
---|
2213 | /****************************************************************************
|
---|
2214 | Reply to get user quota
|
---|
2215 | ****************************************************************************/
|
---|
2216 |
|
---|
2217 | static void call_nt_transact_get_user_quota(connection_struct *conn,
|
---|
2218 | struct smb_request *req,
|
---|
2219 | uint16 **ppsetup,
|
---|
2220 | uint32 setup_count,
|
---|
2221 | char **ppparams,
|
---|
2222 | uint32 parameter_count,
|
---|
2223 | char **ppdata,
|
---|
2224 | uint32 data_count,
|
---|
2225 | uint32 max_data_count)
|
---|
2226 | {
|
---|
2227 | NTSTATUS nt_status = NT_STATUS_OK;
|
---|
2228 | char *params = *ppparams;
|
---|
2229 | char *pdata = *ppdata;
|
---|
2230 | char *entry;
|
---|
2231 | int data_len=0,param_len=0;
|
---|
2232 | int qt_len=0;
|
---|
2233 | int entry_len = 0;
|
---|
2234 | files_struct *fsp = NULL;
|
---|
2235 | uint16 level = 0;
|
---|
2236 | size_t sid_len;
|
---|
2237 | DOM_SID sid;
|
---|
2238 | bool start_enum = True;
|
---|
2239 | SMB_NTQUOTA_STRUCT qt;
|
---|
2240 | SMB_NTQUOTA_LIST *tmp_list;
|
---|
2241 | SMB_NTQUOTA_HANDLE *qt_handle = NULL;
|
---|
2242 |
|
---|
2243 | ZERO_STRUCT(qt);
|
---|
2244 |
|
---|
2245 | /* access check */
|
---|
2246 | if (conn->server_info->utok.uid != 0) {
|
---|
2247 | DEBUG(1,("get_user_quota: access_denied service [%s] user "
|
---|
2248 | "[%s]\n", lp_servicename(SNUM(conn)),
|
---|
2249 | conn->server_info->unix_name));
|
---|
2250 | reply_nterror(req, NT_STATUS_ACCESS_DENIED);
|
---|
2251 | return;
|
---|
2252 | }
|
---|
2253 |
|
---|
2254 | /*
|
---|
2255 | * Ensure minimum number of parameters sent.
|
---|
2256 | */
|
---|
2257 |
|
---|
2258 | if (parameter_count < 4) {
|
---|
2259 | DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
|
---|
2260 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2261 | return;
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | /* maybe we can check the quota_fnum */
|
---|
2265 | fsp = file_fsp(req, SVAL(params,0));
|
---|
2266 | if (!check_fsp_ntquota_handle(conn, req, fsp)) {
|
---|
2267 | DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
|
---|
2268 | reply_nterror(req, NT_STATUS_INVALID_HANDLE);
|
---|
2269 | return;
|
---|
2270 | }
|
---|
2271 |
|
---|
2272 | /* the NULL pointer checking for fsp->fake_file_handle->pd
|
---|
2273 | * is done by CHECK_NTQUOTA_HANDLE_OK()
|
---|
2274 | */
|
---|
2275 | qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
|
---|
2276 |
|
---|
2277 | level = SVAL(params,2);
|
---|
2278 |
|
---|
2279 | /* unknown 12 bytes leading in params */
|
---|
2280 |
|
---|
2281 | switch (level) {
|
---|
2282 | case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
|
---|
2283 | /* seems that we should continue with the enum here --metze */
|
---|
2284 |
|
---|
2285 | if (qt_handle->quota_list!=NULL &&
|
---|
2286 | qt_handle->tmp_list==NULL) {
|
---|
2287 |
|
---|
2288 | /* free the list */
|
---|
2289 | free_ntquota_list(&(qt_handle->quota_list));
|
---|
2290 |
|
---|
2291 | /* Realloc the size of parameters and data we will return */
|
---|
2292 | param_len = 4;
|
---|
2293 | params = nttrans_realloc(ppparams, param_len);
|
---|
2294 | if(params == NULL) {
|
---|
2295 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2296 | return;
|
---|
2297 | }
|
---|
2298 |
|
---|
2299 | data_len = 0;
|
---|
2300 | SIVAL(params,0,data_len);
|
---|
2301 |
|
---|
2302 | break;
|
---|
2303 | }
|
---|
2304 |
|
---|
2305 | start_enum = False;
|
---|
2306 |
|
---|
2307 | case TRANSACT_GET_USER_QUOTA_LIST_START:
|
---|
2308 |
|
---|
2309 | if (qt_handle->quota_list==NULL &&
|
---|
2310 | qt_handle->tmp_list==NULL) {
|
---|
2311 | start_enum = True;
|
---|
2312 | }
|
---|
2313 |
|
---|
2314 | if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
|
---|
2315 | reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
|
---|
2316 | return;
|
---|
2317 | }
|
---|
2318 |
|
---|
2319 | /* Realloc the size of parameters and data we will return */
|
---|
2320 | param_len = 4;
|
---|
2321 | params = nttrans_realloc(ppparams, param_len);
|
---|
2322 | if(params == NULL) {
|
---|
2323 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2324 | return;
|
---|
2325 | }
|
---|
2326 |
|
---|
2327 | /* we should not trust the value in max_data_count*/
|
---|
2328 | max_data_count = MIN(max_data_count,2048);
|
---|
2329 |
|
---|
2330 | pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
|
---|
2331 | if(pdata == NULL) {
|
---|
2332 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2333 | return;
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | entry = pdata;
|
---|
2337 |
|
---|
2338 | /* set params Size of returned Quota Data 4 bytes*/
|
---|
2339 | /* but set it later when we know it */
|
---|
2340 |
|
---|
2341 | /* for each entry push the data */
|
---|
2342 |
|
---|
2343 | if (start_enum) {
|
---|
2344 | qt_handle->tmp_list = qt_handle->quota_list;
|
---|
2345 | }
|
---|
2346 |
|
---|
2347 | tmp_list = qt_handle->tmp_list;
|
---|
2348 |
|
---|
2349 | for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
|
---|
2350 | tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
|
---|
2351 |
|
---|
2352 | sid_len = ndr_size_dom_sid(
|
---|
2353 | &tmp_list->quotas->sid, NULL, 0);
|
---|
2354 | entry_len = 40 + sid_len;
|
---|
2355 |
|
---|
2356 | /* nextoffset entry 4 bytes */
|
---|
2357 | SIVAL(entry,0,entry_len);
|
---|
2358 |
|
---|
2359 | /* then the len of the SID 4 bytes */
|
---|
2360 | SIVAL(entry,4,sid_len);
|
---|
2361 |
|
---|
2362 | /* unknown data 8 bytes uint64_t */
|
---|
2363 | SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
|
---|
2364 |
|
---|
2365 | /* the used disk space 8 bytes uint64_t */
|
---|
2366 | SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
|
---|
2367 |
|
---|
2368 | /* the soft quotas 8 bytes uint64_t */
|
---|
2369 | SBIG_UINT(entry,24,tmp_list->quotas->softlim);
|
---|
2370 |
|
---|
2371 | /* the hard quotas 8 bytes uint64_t */
|
---|
2372 | SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
|
---|
2373 |
|
---|
2374 | /* and now the SID */
|
---|
2375 | sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
|
---|
2376 | }
|
---|
2377 |
|
---|
2378 | qt_handle->tmp_list = tmp_list;
|
---|
2379 |
|
---|
2380 | /* overwrite the offset of the last entry */
|
---|
2381 | SIVAL(entry-entry_len,0,0);
|
---|
2382 |
|
---|
2383 | data_len = 4+qt_len;
|
---|
2384 | /* overwrite the params quota_data_len */
|
---|
2385 | SIVAL(params,0,data_len);
|
---|
2386 |
|
---|
2387 | break;
|
---|
2388 |
|
---|
2389 | case TRANSACT_GET_USER_QUOTA_FOR_SID:
|
---|
2390 |
|
---|
2391 | /* unknown 4 bytes IVAL(pdata,0) */
|
---|
2392 |
|
---|
2393 | if (data_count < 8) {
|
---|
2394 | DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
|
---|
2395 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2396 | return;
|
---|
2397 | }
|
---|
2398 |
|
---|
2399 | sid_len = IVAL(pdata,4);
|
---|
2400 | /* Ensure this is less than 1mb. */
|
---|
2401 | if (sid_len > (1024*1024)) {
|
---|
2402 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2403 | return;
|
---|
2404 | }
|
---|
2405 |
|
---|
2406 | if (data_count < 8+sid_len) {
|
---|
2407 | DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
|
---|
2408 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2409 | return;
|
---|
2410 | }
|
---|
2411 |
|
---|
2412 | data_len = 4+40+sid_len;
|
---|
2413 |
|
---|
2414 | if (max_data_count < data_len) {
|
---|
2415 | DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
|
---|
2416 | max_data_count, data_len));
|
---|
2417 | param_len = 4;
|
---|
2418 | SIVAL(params,0,data_len);
|
---|
2419 | data_len = 0;
|
---|
2420 | nt_status = NT_STATUS_BUFFER_TOO_SMALL;
|
---|
2421 | break;
|
---|
2422 | }
|
---|
2423 |
|
---|
2424 | if (!sid_parse(pdata+8,sid_len,&sid)) {
|
---|
2425 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2426 | return;
|
---|
2427 | }
|
---|
2428 |
|
---|
2429 | if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
|
---|
2430 | ZERO_STRUCT(qt);
|
---|
2431 | /*
|
---|
2432 | * we have to return zero's in all fields
|
---|
2433 | * instead of returning an error here
|
---|
2434 | * --metze
|
---|
2435 | */
|
---|
2436 | }
|
---|
2437 |
|
---|
2438 | /* Realloc the size of parameters and data we will return */
|
---|
2439 | param_len = 4;
|
---|
2440 | params = nttrans_realloc(ppparams, param_len);
|
---|
2441 | if(params == NULL) {
|
---|
2442 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2443 | return;
|
---|
2444 | }
|
---|
2445 |
|
---|
2446 | pdata = nttrans_realloc(ppdata, data_len);
|
---|
2447 | if(pdata == NULL) {
|
---|
2448 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2449 | return;
|
---|
2450 | }
|
---|
2451 |
|
---|
2452 | entry = pdata;
|
---|
2453 |
|
---|
2454 | /* set params Size of returned Quota Data 4 bytes*/
|
---|
2455 | SIVAL(params,0,data_len);
|
---|
2456 |
|
---|
2457 | /* nextoffset entry 4 bytes */
|
---|
2458 | SIVAL(entry,0,0);
|
---|
2459 |
|
---|
2460 | /* then the len of the SID 4 bytes */
|
---|
2461 | SIVAL(entry,4,sid_len);
|
---|
2462 |
|
---|
2463 | /* unknown data 8 bytes uint64_t */
|
---|
2464 | SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
|
---|
2465 |
|
---|
2466 | /* the used disk space 8 bytes uint64_t */
|
---|
2467 | SBIG_UINT(entry,16,qt.usedspace);
|
---|
2468 |
|
---|
2469 | /* the soft quotas 8 bytes uint64_t */
|
---|
2470 | SBIG_UINT(entry,24,qt.softlim);
|
---|
2471 |
|
---|
2472 | /* the hard quotas 8 bytes uint64_t */
|
---|
2473 | SBIG_UINT(entry,32,qt.hardlim);
|
---|
2474 |
|
---|
2475 | /* and now the SID */
|
---|
2476 | sid_linearize(entry+40, sid_len, &sid);
|
---|
2477 |
|
---|
2478 | break;
|
---|
2479 |
|
---|
2480 | default:
|
---|
2481 | DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
|
---|
2482 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2483 | return;
|
---|
2484 | break;
|
---|
2485 | }
|
---|
2486 |
|
---|
2487 | send_nt_replies(conn, req, nt_status, params, param_len,
|
---|
2488 | pdata, data_len);
|
---|
2489 | }
|
---|
2490 |
|
---|
2491 | /****************************************************************************
|
---|
2492 | Reply to set user quota
|
---|
2493 | ****************************************************************************/
|
---|
2494 |
|
---|
2495 | static void call_nt_transact_set_user_quota(connection_struct *conn,
|
---|
2496 | struct smb_request *req,
|
---|
2497 | uint16 **ppsetup,
|
---|
2498 | uint32 setup_count,
|
---|
2499 | char **ppparams,
|
---|
2500 | uint32 parameter_count,
|
---|
2501 | char **ppdata,
|
---|
2502 | uint32 data_count,
|
---|
2503 | uint32 max_data_count)
|
---|
2504 | {
|
---|
2505 | char *params = *ppparams;
|
---|
2506 | char *pdata = *ppdata;
|
---|
2507 | int data_len=0,param_len=0;
|
---|
2508 | SMB_NTQUOTA_STRUCT qt;
|
---|
2509 | size_t sid_len;
|
---|
2510 | DOM_SID sid;
|
---|
2511 | files_struct *fsp = NULL;
|
---|
2512 |
|
---|
2513 | ZERO_STRUCT(qt);
|
---|
2514 |
|
---|
2515 | /* access check */
|
---|
2516 | if (conn->server_info->utok.uid != 0) {
|
---|
2517 | DEBUG(1,("set_user_quota: access_denied service [%s] user "
|
---|
2518 | "[%s]\n", lp_servicename(SNUM(conn)),
|
---|
2519 | conn->server_info->unix_name));
|
---|
2520 | reply_nterror(req, NT_STATUS_ACCESS_DENIED);
|
---|
2521 | return;
|
---|
2522 | }
|
---|
2523 |
|
---|
2524 | /*
|
---|
2525 | * Ensure minimum number of parameters sent.
|
---|
2526 | */
|
---|
2527 |
|
---|
2528 | if (parameter_count < 2) {
|
---|
2529 | DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
|
---|
2530 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2531 | return;
|
---|
2532 | }
|
---|
2533 |
|
---|
2534 | /* maybe we can check the quota_fnum */
|
---|
2535 | fsp = file_fsp(req, SVAL(params,0));
|
---|
2536 | if (!check_fsp_ntquota_handle(conn, req, fsp)) {
|
---|
2537 | DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
|
---|
2538 | reply_nterror(req, NT_STATUS_INVALID_HANDLE);
|
---|
2539 | return;
|
---|
2540 | }
|
---|
2541 |
|
---|
2542 | if (data_count < 40) {
|
---|
2543 | DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
|
---|
2544 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2545 | return;
|
---|
2546 | }
|
---|
2547 |
|
---|
2548 | /* offset to next quota record.
|
---|
2549 | * 4 bytes IVAL(pdata,0)
|
---|
2550 | * unused here...
|
---|
2551 | */
|
---|
2552 |
|
---|
2553 | /* sid len */
|
---|
2554 | sid_len = IVAL(pdata,4);
|
---|
2555 |
|
---|
2556 | if (data_count < 40+sid_len) {
|
---|
2557 | DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
|
---|
2558 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2559 | return;
|
---|
2560 | }
|
---|
2561 |
|
---|
2562 | /* unknown 8 bytes in pdata
|
---|
2563 | * maybe its the change time in NTTIME
|
---|
2564 | */
|
---|
2565 |
|
---|
2566 | /* the used space 8 bytes (uint64_t)*/
|
---|
2567 | qt.usedspace = (uint64_t)IVAL(pdata,16);
|
---|
2568 | #ifdef LARGE_SMB_OFF_T
|
---|
2569 | qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
|
---|
2570 | #else /* LARGE_SMB_OFF_T */
|
---|
2571 | if ((IVAL(pdata,20) != 0)&&
|
---|
2572 | ((qt.usedspace != 0xFFFFFFFF)||
|
---|
2573 | (IVAL(pdata,20)!=0xFFFFFFFF))) {
|
---|
2574 | /* more than 32 bits? */
|
---|
2575 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2576 | return;
|
---|
2577 | }
|
---|
2578 | #endif /* LARGE_SMB_OFF_T */
|
---|
2579 |
|
---|
2580 | /* the soft quotas 8 bytes (uint64_t)*/
|
---|
2581 | qt.softlim = (uint64_t)IVAL(pdata,24);
|
---|
2582 | #ifdef LARGE_SMB_OFF_T
|
---|
2583 | qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
|
---|
2584 | #else /* LARGE_SMB_OFF_T */
|
---|
2585 | if ((IVAL(pdata,28) != 0)&&
|
---|
2586 | ((qt.softlim != 0xFFFFFFFF)||
|
---|
2587 | (IVAL(pdata,28)!=0xFFFFFFFF))) {
|
---|
2588 | /* more than 32 bits? */
|
---|
2589 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2590 | return;
|
---|
2591 | }
|
---|
2592 | #endif /* LARGE_SMB_OFF_T */
|
---|
2593 |
|
---|
2594 | /* the hard quotas 8 bytes (uint64_t)*/
|
---|
2595 | qt.hardlim = (uint64_t)IVAL(pdata,32);
|
---|
2596 | #ifdef LARGE_SMB_OFF_T
|
---|
2597 | qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
|
---|
2598 | #else /* LARGE_SMB_OFF_T */
|
---|
2599 | if ((IVAL(pdata,36) != 0)&&
|
---|
2600 | ((qt.hardlim != 0xFFFFFFFF)||
|
---|
2601 | (IVAL(pdata,36)!=0xFFFFFFFF))) {
|
---|
2602 | /* more than 32 bits? */
|
---|
2603 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2604 | return;
|
---|
2605 | }
|
---|
2606 | #endif /* LARGE_SMB_OFF_T */
|
---|
2607 |
|
---|
2608 | if (!sid_parse(pdata+40,sid_len,&sid)) {
|
---|
2609 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2610 | return;
|
---|
2611 | }
|
---|
2612 |
|
---|
2613 | DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
|
---|
2614 |
|
---|
2615 | /* 44 unknown bytes left... */
|
---|
2616 |
|
---|
2617 | if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
|
---|
2618 | reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
|
---|
2619 | return;
|
---|
2620 | }
|
---|
2621 |
|
---|
2622 | send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
|
---|
2623 | pdata, data_len);
|
---|
2624 | }
|
---|
2625 | #endif /* HAVE_SYS_QUOTAS */
|
---|
2626 |
|
---|
2627 | static void handle_nttrans(connection_struct *conn,
|
---|
2628 | struct trans_state *state,
|
---|
2629 | struct smb_request *req)
|
---|
2630 | {
|
---|
2631 | if (get_Protocol() >= PROTOCOL_NT1) {
|
---|
2632 | req->flags2 |= 0x40; /* IS_LONG_NAME */
|
---|
2633 | SSVAL(req->inbuf,smb_flg2,req->flags2);
|
---|
2634 | }
|
---|
2635 |
|
---|
2636 |
|
---|
2637 | SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
|
---|
2638 |
|
---|
2639 | /* Now we must call the relevant NT_TRANS function */
|
---|
2640 | switch(state->call) {
|
---|
2641 | case NT_TRANSACT_CREATE:
|
---|
2642 | {
|
---|
2643 | START_PROFILE(NT_transact_create);
|
---|
2644 | call_nt_transact_create(
|
---|
2645 | conn, req,
|
---|
2646 | &state->setup, state->setup_count,
|
---|
2647 | &state->param, state->total_param,
|
---|
2648 | &state->data, state->total_data,
|
---|
2649 | state->max_data_return);
|
---|
2650 | END_PROFILE(NT_transact_create);
|
---|
2651 | break;
|
---|
2652 | }
|
---|
2653 |
|
---|
2654 | case NT_TRANSACT_IOCTL:
|
---|
2655 | {
|
---|
2656 | START_PROFILE(NT_transact_ioctl);
|
---|
2657 | call_nt_transact_ioctl(
|
---|
2658 | conn, req,
|
---|
2659 | &state->setup, state->setup_count,
|
---|
2660 | &state->param, state->total_param,
|
---|
2661 | &state->data, state->total_data,
|
---|
2662 | state->max_data_return);
|
---|
2663 | END_PROFILE(NT_transact_ioctl);
|
---|
2664 | break;
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 | case NT_TRANSACT_SET_SECURITY_DESC:
|
---|
2668 | {
|
---|
2669 | START_PROFILE(NT_transact_set_security_desc);
|
---|
2670 | call_nt_transact_set_security_desc(
|
---|
2671 | conn, req,
|
---|
2672 | &state->setup, state->setup_count,
|
---|
2673 | &state->param, state->total_param,
|
---|
2674 | &state->data, state->total_data,
|
---|
2675 | state->max_data_return);
|
---|
2676 | END_PROFILE(NT_transact_set_security_desc);
|
---|
2677 | break;
|
---|
2678 | }
|
---|
2679 |
|
---|
2680 | case NT_TRANSACT_NOTIFY_CHANGE:
|
---|
2681 | {
|
---|
2682 | START_PROFILE(NT_transact_notify_change);
|
---|
2683 | call_nt_transact_notify_change(
|
---|
2684 | conn, req,
|
---|
2685 | &state->setup, state->setup_count,
|
---|
2686 | &state->param, state->total_param,
|
---|
2687 | &state->data, state->total_data,
|
---|
2688 | state->max_data_return,
|
---|
2689 | state->max_param_return);
|
---|
2690 | END_PROFILE(NT_transact_notify_change);
|
---|
2691 | break;
|
---|
2692 | }
|
---|
2693 |
|
---|
2694 | case NT_TRANSACT_RENAME:
|
---|
2695 | {
|
---|
2696 | START_PROFILE(NT_transact_rename);
|
---|
2697 | call_nt_transact_rename(
|
---|
2698 | conn, req,
|
---|
2699 | &state->setup, state->setup_count,
|
---|
2700 | &state->param, state->total_param,
|
---|
2701 | &state->data, state->total_data,
|
---|
2702 | state->max_data_return);
|
---|
2703 | END_PROFILE(NT_transact_rename);
|
---|
2704 | break;
|
---|
2705 | }
|
---|
2706 |
|
---|
2707 | case NT_TRANSACT_QUERY_SECURITY_DESC:
|
---|
2708 | {
|
---|
2709 | START_PROFILE(NT_transact_query_security_desc);
|
---|
2710 | call_nt_transact_query_security_desc(
|
---|
2711 | conn, req,
|
---|
2712 | &state->setup, state->setup_count,
|
---|
2713 | &state->param, state->total_param,
|
---|
2714 | &state->data, state->total_data,
|
---|
2715 | state->max_data_return);
|
---|
2716 | END_PROFILE(NT_transact_query_security_desc);
|
---|
2717 | break;
|
---|
2718 | }
|
---|
2719 |
|
---|
2720 | #ifdef HAVE_SYS_QUOTAS
|
---|
2721 | case NT_TRANSACT_GET_USER_QUOTA:
|
---|
2722 | {
|
---|
2723 | START_PROFILE(NT_transact_get_user_quota);
|
---|
2724 | call_nt_transact_get_user_quota(
|
---|
2725 | conn, req,
|
---|
2726 | &state->setup, state->setup_count,
|
---|
2727 | &state->param, state->total_param,
|
---|
2728 | &state->data, state->total_data,
|
---|
2729 | state->max_data_return);
|
---|
2730 | END_PROFILE(NT_transact_get_user_quota);
|
---|
2731 | break;
|
---|
2732 | }
|
---|
2733 |
|
---|
2734 | case NT_TRANSACT_SET_USER_QUOTA:
|
---|
2735 | {
|
---|
2736 | START_PROFILE(NT_transact_set_user_quota);
|
---|
2737 | call_nt_transact_set_user_quota(
|
---|
2738 | conn, req,
|
---|
2739 | &state->setup, state->setup_count,
|
---|
2740 | &state->param, state->total_param,
|
---|
2741 | &state->data, state->total_data,
|
---|
2742 | state->max_data_return);
|
---|
2743 | END_PROFILE(NT_transact_set_user_quota);
|
---|
2744 | break;
|
---|
2745 | }
|
---|
2746 | #endif /* HAVE_SYS_QUOTAS */
|
---|
2747 |
|
---|
2748 | default:
|
---|
2749 | /* Error in request */
|
---|
2750 | DEBUG(0,("handle_nttrans: Unknown request %d in "
|
---|
2751 | "nttrans call\n", state->call));
|
---|
2752 | reply_nterror(req, NT_STATUS_INVALID_LEVEL);
|
---|
2753 | return;
|
---|
2754 | }
|
---|
2755 | return;
|
---|
2756 | }
|
---|
2757 |
|
---|
2758 | /****************************************************************************
|
---|
2759 | Reply to a SMBNTtrans.
|
---|
2760 | ****************************************************************************/
|
---|
2761 |
|
---|
2762 | void reply_nttrans(struct smb_request *req)
|
---|
2763 | {
|
---|
2764 | connection_struct *conn = req->conn;
|
---|
2765 | uint32_t pscnt;
|
---|
2766 | uint32_t psoff;
|
---|
2767 | uint32_t dscnt;
|
---|
2768 | uint32_t dsoff;
|
---|
2769 | uint16 function_code;
|
---|
2770 | NTSTATUS result;
|
---|
2771 | struct trans_state *state;
|
---|
2772 |
|
---|
2773 | START_PROFILE(SMBnttrans);
|
---|
2774 |
|
---|
2775 | if (req->wct < 19) {
|
---|
2776 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2777 | END_PROFILE(SMBnttrans);
|
---|
2778 | return;
|
---|
2779 | }
|
---|
2780 |
|
---|
2781 | pscnt = IVAL(req->vwv+9, 1);
|
---|
2782 | psoff = IVAL(req->vwv+11, 1);
|
---|
2783 | dscnt = IVAL(req->vwv+13, 1);
|
---|
2784 | dsoff = IVAL(req->vwv+15, 1);
|
---|
2785 | function_code = SVAL(req->vwv+18, 0);
|
---|
2786 |
|
---|
2787 | if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
|
---|
2788 | reply_nterror(req, NT_STATUS_ACCESS_DENIED);
|
---|
2789 | END_PROFILE(SMBnttrans);
|
---|
2790 | return;
|
---|
2791 | }
|
---|
2792 |
|
---|
2793 | result = allow_new_trans(conn->pending_trans, req->mid);
|
---|
2794 | if (!NT_STATUS_IS_OK(result)) {
|
---|
2795 | DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
|
---|
2796 | reply_nterror(req, result);
|
---|
2797 | END_PROFILE(SMBnttrans);
|
---|
2798 | return;
|
---|
2799 | }
|
---|
2800 |
|
---|
2801 | if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
|
---|
2802 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2803 | END_PROFILE(SMBnttrans);
|
---|
2804 | return;
|
---|
2805 | }
|
---|
2806 |
|
---|
2807 | state->cmd = SMBnttrans;
|
---|
2808 |
|
---|
2809 | state->mid = req->mid;
|
---|
2810 | state->vuid = req->vuid;
|
---|
2811 | state->total_data = IVAL(req->vwv+3, 1);
|
---|
2812 | state->data = NULL;
|
---|
2813 | state->total_param = IVAL(req->vwv+1, 1);
|
---|
2814 | state->param = NULL;
|
---|
2815 | state->max_data_return = IVAL(req->vwv+7, 1);
|
---|
2816 | state->max_param_return = IVAL(req->vwv+5, 1);
|
---|
2817 |
|
---|
2818 | /* setup count is in *words* */
|
---|
2819 | state->setup_count = 2*CVAL(req->vwv+17, 1);
|
---|
2820 | state->setup = NULL;
|
---|
2821 | state->call = function_code;
|
---|
2822 |
|
---|
2823 | DEBUG(10, ("num_setup=%u, "
|
---|
2824 | "param_total=%u, this_param=%u, max_param=%u, "
|
---|
2825 | "data_total=%u, this_data=%u, max_data=%u, "
|
---|
2826 | "param_offset=%u, data_offset=%u\n",
|
---|
2827 | (unsigned)state->setup_count,
|
---|
2828 | (unsigned)state->total_param, (unsigned)pscnt,
|
---|
2829 | (unsigned)state->max_param_return,
|
---|
2830 | (unsigned)state->total_data, (unsigned)dscnt,
|
---|
2831 | (unsigned)state->max_data_return,
|
---|
2832 | (unsigned)psoff, (unsigned)dsoff));
|
---|
2833 |
|
---|
2834 | /*
|
---|
2835 | * All nttrans messages we handle have smb_wct == 19 +
|
---|
2836 | * state->setup_count. Ensure this is so as a sanity check.
|
---|
2837 | */
|
---|
2838 |
|
---|
2839 | if(req->wct != 19 + (state->setup_count/2)) {
|
---|
2840 | DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
|
---|
2841 | req->wct, 19 + (state->setup_count/2)));
|
---|
2842 | goto bad_param;
|
---|
2843 | }
|
---|
2844 |
|
---|
2845 | /* Don't allow more than 128mb for each value. */
|
---|
2846 | if ((state->total_data > (1024*1024*128)) ||
|
---|
2847 | (state->total_param > (1024*1024*128))) {
|
---|
2848 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2849 | END_PROFILE(SMBnttrans);
|
---|
2850 | return;
|
---|
2851 | }
|
---|
2852 |
|
---|
2853 | if ((dscnt > state->total_data) || (pscnt > state->total_param))
|
---|
2854 | goto bad_param;
|
---|
2855 |
|
---|
2856 | if (state->total_data) {
|
---|
2857 |
|
---|
2858 | if (trans_oob(state->total_data, 0, dscnt)
|
---|
2859 | || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
|
---|
2860 | goto bad_param;
|
---|
2861 | }
|
---|
2862 |
|
---|
2863 | /* Can't use talloc here, the core routines do realloc on the
|
---|
2864 | * params and data. */
|
---|
2865 | if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
|
---|
2866 | DEBUG(0,("reply_nttrans: data malloc fail for %u "
|
---|
2867 | "bytes !\n", (unsigned int)state->total_data));
|
---|
2868 | TALLOC_FREE(state);
|
---|
2869 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2870 | END_PROFILE(SMBnttrans);
|
---|
2871 | return;
|
---|
2872 | }
|
---|
2873 |
|
---|
2874 | memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
|
---|
2875 | }
|
---|
2876 |
|
---|
2877 | if (state->total_param) {
|
---|
2878 |
|
---|
2879 | if (trans_oob(state->total_param, 0, pscnt)
|
---|
2880 | || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
|
---|
2881 | goto bad_param;
|
---|
2882 | }
|
---|
2883 |
|
---|
2884 | /* Can't use talloc here, the core routines do realloc on the
|
---|
2885 | * params and data. */
|
---|
2886 | if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
|
---|
2887 | DEBUG(0,("reply_nttrans: param malloc fail for %u "
|
---|
2888 | "bytes !\n", (unsigned int)state->total_param));
|
---|
2889 | SAFE_FREE(state->data);
|
---|
2890 | TALLOC_FREE(state);
|
---|
2891 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2892 | END_PROFILE(SMBnttrans);
|
---|
2893 | return;
|
---|
2894 | }
|
---|
2895 |
|
---|
2896 | memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
|
---|
2897 | }
|
---|
2898 |
|
---|
2899 | state->received_data = dscnt;
|
---|
2900 | state->received_param = pscnt;
|
---|
2901 |
|
---|
2902 | if(state->setup_count > 0) {
|
---|
2903 | DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
|
---|
2904 | state->setup_count));
|
---|
2905 |
|
---|
2906 | /*
|
---|
2907 | * No overflow possible here, state->setup_count is an
|
---|
2908 | * unsigned int, being filled by a single byte from
|
---|
2909 | * CVAL(req->vwv+13, 0) above. The cast in the comparison
|
---|
2910 | * below is not necessary, it's here to clarify things. The
|
---|
2911 | * validity of req->vwv and req->wct has been checked in
|
---|
2912 | * init_smb_request already.
|
---|
2913 | */
|
---|
2914 | if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
|
---|
2915 | goto bad_param;
|
---|
2916 | }
|
---|
2917 |
|
---|
2918 | state->setup = (uint16 *)TALLOC(state, state->setup_count);
|
---|
2919 | if (state->setup == NULL) {
|
---|
2920 | DEBUG(0,("reply_nttrans : Out of memory\n"));
|
---|
2921 | SAFE_FREE(state->data);
|
---|
2922 | SAFE_FREE(state->param);
|
---|
2923 | TALLOC_FREE(state);
|
---|
2924 | reply_nterror(req, NT_STATUS_NO_MEMORY);
|
---|
2925 | END_PROFILE(SMBnttrans);
|
---|
2926 | return;
|
---|
2927 | }
|
---|
2928 |
|
---|
2929 | memcpy(state->setup, req->vwv+19, state->setup_count);
|
---|
2930 | dump_data(10, (uint8 *)state->setup, state->setup_count);
|
---|
2931 | }
|
---|
2932 |
|
---|
2933 | if ((state->received_data == state->total_data) &&
|
---|
2934 | (state->received_param == state->total_param)) {
|
---|
2935 | handle_nttrans(conn, state, req);
|
---|
2936 | SAFE_FREE(state->param);
|
---|
2937 | SAFE_FREE(state->data);
|
---|
2938 | TALLOC_FREE(state);
|
---|
2939 | END_PROFILE(SMBnttrans);
|
---|
2940 | return;
|
---|
2941 | }
|
---|
2942 |
|
---|
2943 | DLIST_ADD(conn->pending_trans, state);
|
---|
2944 |
|
---|
2945 | /* We need to send an interim response then receive the rest
|
---|
2946 | of the parameter/data bytes */
|
---|
2947 | reply_outbuf(req, 0, 0);
|
---|
2948 | show_msg((char *)req->outbuf);
|
---|
2949 | END_PROFILE(SMBnttrans);
|
---|
2950 | return;
|
---|
2951 |
|
---|
2952 | bad_param:
|
---|
2953 |
|
---|
2954 | DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
|
---|
2955 | SAFE_FREE(state->data);
|
---|
2956 | SAFE_FREE(state->param);
|
---|
2957 | TALLOC_FREE(state);
|
---|
2958 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2959 | END_PROFILE(SMBnttrans);
|
---|
2960 | return;
|
---|
2961 | }
|
---|
2962 |
|
---|
2963 | /****************************************************************************
|
---|
2964 | Reply to a SMBnttranss
|
---|
2965 | ****************************************************************************/
|
---|
2966 |
|
---|
2967 | void reply_nttranss(struct smb_request *req)
|
---|
2968 | {
|
---|
2969 | connection_struct *conn = req->conn;
|
---|
2970 | uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
|
---|
2971 | struct trans_state *state;
|
---|
2972 |
|
---|
2973 | START_PROFILE(SMBnttranss);
|
---|
2974 |
|
---|
2975 | show_msg((char *)req->inbuf);
|
---|
2976 |
|
---|
2977 | if (req->wct < 18) {
|
---|
2978 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2979 | END_PROFILE(SMBnttranss);
|
---|
2980 | return;
|
---|
2981 | }
|
---|
2982 |
|
---|
2983 | for (state = conn->pending_trans; state != NULL;
|
---|
2984 | state = state->next) {
|
---|
2985 | if (state->mid == req->mid) {
|
---|
2986 | break;
|
---|
2987 | }
|
---|
2988 | }
|
---|
2989 |
|
---|
2990 | if ((state == NULL) || (state->cmd != SMBnttrans)) {
|
---|
2991 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
2992 | END_PROFILE(SMBnttranss);
|
---|
2993 | return;
|
---|
2994 | }
|
---|
2995 |
|
---|
2996 | /* Revise state->total_param and state->total_data in case they have
|
---|
2997 | changed downwards */
|
---|
2998 | if (IVAL(req->vwv+1, 1) < state->total_param) {
|
---|
2999 | state->total_param = IVAL(req->vwv+1, 1);
|
---|
3000 | }
|
---|
3001 | if (IVAL(req->vwv+3, 1) < state->total_data) {
|
---|
3002 | state->total_data = IVAL(req->vwv+3, 1);
|
---|
3003 | }
|
---|
3004 |
|
---|
3005 | pcnt = IVAL(req->vwv+5, 1);
|
---|
3006 | poff = IVAL(req->vwv+7, 1);
|
---|
3007 | pdisp = IVAL(req->vwv+9, 1);
|
---|
3008 |
|
---|
3009 | dcnt = IVAL(req->vwv+11, 1);
|
---|
3010 | doff = IVAL(req->vwv+13, 1);
|
---|
3011 | ddisp = IVAL(req->vwv+15, 1);
|
---|
3012 |
|
---|
3013 | state->received_param += pcnt;
|
---|
3014 | state->received_data += dcnt;
|
---|
3015 |
|
---|
3016 | if ((state->received_data > state->total_data) ||
|
---|
3017 | (state->received_param > state->total_param))
|
---|
3018 | goto bad_param;
|
---|
3019 |
|
---|
3020 | if (pcnt) {
|
---|
3021 | if (trans_oob(state->total_param, pdisp, pcnt)
|
---|
3022 | || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
|
---|
3023 | goto bad_param;
|
---|
3024 | }
|
---|
3025 | memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
|
---|
3026 | }
|
---|
3027 |
|
---|
3028 | if (dcnt) {
|
---|
3029 | if (trans_oob(state->total_data, ddisp, dcnt)
|
---|
3030 | || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
|
---|
3031 | goto bad_param;
|
---|
3032 | }
|
---|
3033 | memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
|
---|
3034 | }
|
---|
3035 |
|
---|
3036 | if ((state->received_param < state->total_param) ||
|
---|
3037 | (state->received_data < state->total_data)) {
|
---|
3038 | END_PROFILE(SMBnttranss);
|
---|
3039 | return;
|
---|
3040 | }
|
---|
3041 |
|
---|
3042 | handle_nttrans(conn, state, req);
|
---|
3043 |
|
---|
3044 | DLIST_REMOVE(conn->pending_trans, state);
|
---|
3045 | SAFE_FREE(state->data);
|
---|
3046 | SAFE_FREE(state->param);
|
---|
3047 | TALLOC_FREE(state);
|
---|
3048 | END_PROFILE(SMBnttranss);
|
---|
3049 | return;
|
---|
3050 |
|
---|
3051 | bad_param:
|
---|
3052 |
|
---|
3053 | DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
|
---|
3054 | DLIST_REMOVE(conn->pending_trans, state);
|
---|
3055 | SAFE_FREE(state->data);
|
---|
3056 | SAFE_FREE(state->param);
|
---|
3057 | TALLOC_FREE(state);
|
---|
3058 | reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
|
---|
3059 | END_PROFILE(SMBnttranss);
|
---|
3060 | return;
|
---|
3061 | }
|
---|