WHATSNEW: SMB3 Directory Leases
[samba4-gss.git] / source3 / smbd / smb2_setinfo.c
blob84c651b1794a449ed6cc29ed859e8fc1e0ea1311
1 /*
2 Unix SMB/CIFS implementation.
3 Core SMB2 server
5 Copyright (C) Stefan Metzmacher 2009
6 Copyright (C) Jeremy Allison 2010
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "locking/share_mode_lock.h"
24 #include "smbd/smbd.h"
25 #include "smbd/globals.h"
26 #include "../libcli/smb/smb_common.h"
27 #include "trans2.h"
28 #include "../lib/util/tevent_ntstatus.h"
29 #include "../librpc/gen_ndr/open_files.h"
30 #include "source3/lib/dbwrap/dbwrap_watch.h"
31 #include "messages.h"
32 #include "librpc/gen_ndr/ndr_quota.h"
33 #include "libcli/security/security.h"
35 #undef DBGC_CLASS
36 #define DBGC_CLASS DBGC_SMB2
38 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
39 struct tevent_context *ev,
40 struct smbd_smb2_request *smb2req,
41 struct files_struct *in_fsp,
42 uint8_t in_info_type,
43 uint8_t in_file_info_class,
44 DATA_BLOB in_input_buffer,
45 uint32_t in_additional_information);
46 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req);
48 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq);
49 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req)
51 struct smbXsrv_connection *xconn = req->xconn;
52 NTSTATUS status;
53 const uint8_t *inbody;
54 uint8_t in_info_type;
55 uint8_t in_file_info_class;
56 uint16_t in_input_buffer_offset;
57 uint32_t in_input_buffer_length;
58 DATA_BLOB in_input_buffer;
59 uint32_t in_additional_information;
60 uint64_t in_file_id_persistent;
61 uint64_t in_file_id_volatile;
62 struct files_struct *in_fsp;
63 struct tevent_req *subreq;
65 status = smbd_smb2_request_verify_sizes(req, 0x21);
66 if (!NT_STATUS_IS_OK(status)) {
67 return smbd_smb2_request_error(req, status);
69 inbody = SMBD_SMB2_IN_BODY_PTR(req);
71 in_info_type = CVAL(inbody, 0x02);
72 in_file_info_class = CVAL(inbody, 0x03);
73 in_input_buffer_length = IVAL(inbody, 0x04);
74 in_input_buffer_offset = SVAL(inbody, 0x08);
75 /* 0x0A 2 bytes reserved */
76 in_additional_information = IVAL(inbody, 0x0C);
77 in_file_id_persistent = BVAL(inbody, 0x10);
78 in_file_id_volatile = BVAL(inbody, 0x18);
80 if (in_input_buffer_offset == 0 && in_input_buffer_length == 0) {
81 /* This is ok */
82 } else if (in_input_buffer_offset !=
83 (SMB2_HDR_BODY + SMBD_SMB2_IN_BODY_LEN(req))) {
84 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
87 if (in_input_buffer_length > SMBD_SMB2_IN_DYN_LEN(req)) {
88 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
91 in_input_buffer.data = SMBD_SMB2_IN_DYN_PTR(req);
92 in_input_buffer.length = in_input_buffer_length;
94 if (in_input_buffer.length > xconn->smb2.server.max_trans) {
95 DEBUG(2,("smbd_smb2_request_process_setinfo: "
96 "client ignored max trans: %s: 0x%08X: 0x%08X\n",
97 __location__, (unsigned)in_input_buffer.length,
98 (unsigned)xconn->smb2.server.max_trans));
99 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
102 status = smbd_smb2_request_verify_creditcharge(req,
103 in_input_buffer.length);
104 if (!NT_STATUS_IS_OK(status)) {
105 return smbd_smb2_request_error(req, status);
108 in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
109 if (in_fsp == NULL) {
110 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
113 subreq = smbd_smb2_setinfo_send(req, req->sconn->ev_ctx,
114 req, in_fsp,
115 in_info_type,
116 in_file_info_class,
117 in_input_buffer,
118 in_additional_information);
119 if (subreq == NULL) {
120 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
122 tevent_req_set_callback(subreq, smbd_smb2_request_setinfo_done, req);
125 * Windows never sends async interim responses if a rename triggers a
126 * lease break. See test smb2.lease.compound_rename_middle.
128 return smbd_smb2_request_pending_queue(req, subreq, 0);
131 static void smbd_smb2_request_setinfo_done(struct tevent_req *subreq)
133 struct smbd_smb2_request *req = tevent_req_callback_data(subreq,
134 struct smbd_smb2_request);
135 DATA_BLOB outbody;
136 NTSTATUS status;
137 NTSTATUS error; /* transport error */
139 status = smbd_smb2_setinfo_recv(subreq);
140 TALLOC_FREE(subreq);
141 if (!NT_STATUS_IS_OK(status)) {
142 error = smbd_smb2_request_error(req, status);
143 if (!NT_STATUS_IS_OK(error)) {
144 smbd_server_connection_terminate(req->xconn,
145 nt_errstr(error));
146 return;
148 return;
151 outbody = smbd_smb2_generate_outbody(req, 0x02);
152 if (outbody.data == NULL) {
153 error = smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
154 if (!NT_STATUS_IS_OK(error)) {
155 smbd_server_connection_terminate(req->xconn,
156 nt_errstr(error));
157 return;
159 return;
162 SSVAL(outbody.data, 0x00, 0x02); /* struct size */
164 error = smbd_smb2_request_done(req, outbody, NULL);
165 if (!NT_STATUS_IS_OK(error)) {
166 smbd_server_connection_terminate(req->xconn,
167 nt_errstr(error));
168 return;
172 struct smbd_smb2_setinfo_state {
173 struct tevent_context *ev;
174 struct smbd_smb2_request *smb2req;
175 struct files_struct *fsp;
176 struct share_mode_lock *lck;
177 struct files_struct *dstfsp;
178 uint16_t file_info_level;
179 DATA_BLOB data;
180 bool delay;
181 bool rename_dst_check_done;
184 static void smbd_smb2_setinfo_lease_break_check(struct tevent_req *req);
186 static void smbd_smb2_setinfo_cleanup(struct tevent_req *req,
187 enum tevent_req_state req_state)
189 struct smbd_smb2_setinfo_state *state = tevent_req_data(
190 req, struct smbd_smb2_setinfo_state);
192 if (req_state == TEVENT_REQ_DONE) {
193 return;
195 TALLOC_FREE(state->lck);
198 static struct tevent_req *smbd_smb2_setinfo_send(TALLOC_CTX *mem_ctx,
199 struct tevent_context *ev,
200 struct smbd_smb2_request *smb2req,
201 struct files_struct *fsp,
202 uint8_t in_info_type,
203 uint8_t in_file_info_class,
204 DATA_BLOB in_input_buffer,
205 uint32_t in_additional_information)
207 struct tevent_req *req = NULL;
208 struct smbd_smb2_setinfo_state *state = NULL;
209 struct smb_request *smbreq = NULL;
210 connection_struct *conn = smb2req->tcon->compat;
211 NTSTATUS status;
212 int ret;
214 req = tevent_req_create(mem_ctx, &state,
215 struct smbd_smb2_setinfo_state);
216 if (req == NULL) {
217 return NULL;
219 state->ev = ev;
220 state->smb2req = smb2req;
221 state->fsp = fsp;
222 state->data = in_input_buffer;
224 tevent_req_set_cleanup_fn(req, smbd_smb2_setinfo_cleanup);
226 DEBUG(10,("smbd_smb2_setinfo_send: %s - %s\n",
227 fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
229 smbreq = smbd_smb2_fake_smb_request(smb2req, fsp);
230 if (tevent_req_nomem(smbreq, req)) {
231 return tevent_req_post(req, ev);
234 if (IS_IPC(conn)) {
235 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
236 return tevent_req_post(req, ev);
239 switch (in_info_type) {
240 case SMB2_0_INFO_FILE:
242 uint16_t file_info_level;
244 file_info_level = in_file_info_class + 1000;
245 if (file_info_level == SMB_FILE_RENAME_INFORMATION) {
246 /* SMB2_FILE_RENAME_INFORMATION_INTERNAL == 0xFF00 + in_file_info_class */
247 file_info_level = SMB2_FILE_RENAME_INFORMATION_INTERNAL;
249 state->file_info_level = file_info_level;
251 if (fsp_get_pathref_fd(fsp) == -1) {
253 * This is actually a SETFILEINFO on a directory
254 * handle (returned from an NT SMB). NT5.0 seems
255 * to do this call. JRA.
257 ret = vfs_stat(fsp->conn, fsp->fsp_name);
258 if (ret != 0) {
259 DBG_WARNING("vfs_stat() of %s failed (%s)\n",
260 fsp_str_dbg(fsp),
261 strerror(errno));
262 status = map_nt_error_from_unix(errno);
263 tevent_req_nterror(req, status);
264 return tevent_req_post(req, ev);
266 } else if (fsp->print_file) {
268 * Doing a DELETE_ON_CLOSE should cancel a print job.
270 if ((file_info_level == SMB_SET_FILE_DISPOSITION_INFO)
271 && in_input_buffer.length >= 1
272 && CVAL(in_input_buffer.data,0)) {
273 fsp->fsp_flags.delete_on_close = true;
275 DEBUG(3,("smbd_smb2_setinfo_send: "
276 "Cancelling print job (%s)\n",
277 fsp_str_dbg(fsp)));
279 tevent_req_done(req);
280 return tevent_req_post(req, ev);
282 tevent_req_nterror(req, NT_STATUS_OBJECT_PATH_INVALID);
283 return tevent_req_post(req, ev);
284 } else {
286 * Original code - this is an open file.
289 status = vfs_stat_fsp(fsp);
290 if (!NT_STATUS_IS_OK(status)) {
291 DEBUG(3,("smbd_smb2_setinfo_send: fstat "
292 "of %s failed (%s)\n",
293 fsp_fnum_dbg(fsp),
294 nt_errstr(status)));
295 tevent_req_nterror(req, status);
296 return tevent_req_post(req, ev);
300 smbd_smb2_setinfo_lease_break_check(req);
301 if (!tevent_req_is_in_progress(req)) {
302 return tevent_req_post(req, ev);
304 SMB_ASSERT(state->delay);
305 return req;
308 case SMB2_0_INFO_FILESYSTEM:
310 uint16_t file_info_level = in_file_info_class + 1000;
312 status = smbd_do_setfsinfo(conn, smbreq, state,
313 file_info_level,
314 fsp,
315 &in_input_buffer);
316 if (!NT_STATUS_IS_OK(status)) {
317 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
318 status = NT_STATUS_INVALID_INFO_CLASS;
320 tevent_req_nterror(req, status);
321 return tevent_req_post(req, ev);
323 break;
326 case SMB2_0_INFO_SECURITY:
328 if (!CAN_WRITE(conn)) {
329 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
330 return tevent_req_post(req, ev);
333 status = set_sd_blob(fsp,
334 in_input_buffer.data,
335 in_input_buffer.length,
336 in_additional_information &
337 SMB_SUPPORTED_SECINFO_FLAGS);
338 if (!NT_STATUS_IS_OK(status)) {
339 tevent_req_nterror(req, status);
340 return tevent_req_post(req, ev);
342 break;
345 case SMB2_0_INFO_QUOTA:
347 #ifdef HAVE_SYS_QUOTAS
348 struct file_quota_information info = {0};
349 SMB_NTQUOTA_STRUCT qt = {0};
350 enum ndr_err_code err;
352 if (!fsp->fake_file_handle) {
353 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
354 return tevent_req_post(req, ev);
356 err = ndr_pull_struct_blob(
357 &in_input_buffer, state, &info,
358 (ndr_pull_flags_fn_t)ndr_pull_file_quota_information);
359 if (!NDR_ERR_CODE_IS_SUCCESS(err)) {
360 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
361 return tevent_req_post(req, ev);
364 qt.usedspace = info.quota_used;
366 qt.softlim = info.quota_threshold;
368 qt.hardlim = info.quota_limit;
370 qt.sid = info.sid;
371 ret = vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &qt.sid, &qt);
372 if (ret !=0 ) {
373 status = map_nt_error_from_unix(errno);
374 tevent_req_nterror(req, status);
375 return tevent_req_post(req, ev);
377 status = NT_STATUS_OK;
378 break;
379 #else
380 tevent_req_nterror(req, NT_STATUS_NOT_SUPPORTED);
381 return tevent_req_post(req, ev);
382 #endif
384 default:
385 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
386 return tevent_req_post(req, ev);
389 tevent_req_done(req);
390 return tevent_req_post(req, ev);
393 static void smbd_smb2_setinfo_lease_break_fsp_check(struct tevent_req *req);
394 static void smbd_smb2_setinfo_lease_break_fsp_done(struct tevent_req *subreq);
395 static void smbd_smb2_setinfo_rename_dst_check(struct tevent_req *req);
396 static void smbd_smb2_setinfo_rename_dst_delay_done(struct tevent_req *subreq);
398 static void smbd_smb2_setinfo_lease_break_check(struct tevent_req *req)
400 struct smbd_smb2_setinfo_state *state = tevent_req_data(
401 req, struct smbd_smb2_setinfo_state);
402 int ret_size;
403 NTSTATUS status;
405 state->delay = false;
407 smbd_smb2_setinfo_rename_dst_check(req);
408 if (!tevent_req_is_in_progress(req)) {
409 return;
411 if (state->delay) {
412 DBG_DEBUG("Waiting for h-lease breaks on rename destination\n");
413 return;
416 smbd_smb2_setinfo_lease_break_fsp_check(req);
417 if (!tevent_req_is_in_progress(req)) {
418 return;
420 if (state->delay) {
421 TALLOC_FREE(state->lck);
422 DBG_DEBUG("Waiting for h-lease breaks on fsp [%s]\n",
423 fsp_str_dbg(state->fsp));
424 return;
427 status = smbd_do_setfilepathinfo(state->fsp->conn,
428 state->smb2req->smb1req,
429 state,
430 state->file_info_level,
431 state->fsp,
432 &state->lck,
433 state->fsp->fsp_name,
434 (char *)state->data.data,
435 state->data.length,
436 &ret_size);
437 TALLOC_FREE(state->lck);
438 if (!NT_STATUS_IS_OK(status)) {
439 if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_LEVEL)) {
440 status = NT_STATUS_INVALID_INFO_CLASS;
442 tevent_req_nterror(req, status);
443 return;
446 tevent_req_done(req);
449 static void smbd_smb2_setinfo_lease_break_fsp_check(struct tevent_req *req)
451 struct smbd_smb2_setinfo_state *state = tevent_req_data(
452 req, struct smbd_smb2_setinfo_state);
453 struct smbd_smb2_request *smb2req = state->smb2req;
454 struct files_struct *fsp = state->fsp;
455 uint16_t file_info_level = state->file_info_level;
456 struct tevent_req *subreq = NULL;
457 struct timeval timeout;
458 bool rename;
459 bool delete_on_close;
460 NTSTATUS status;
462 rename = (file_info_level == SMB2_FILE_RENAME_INFORMATION_INTERNAL);
464 if (file_info_level == SMB_FILE_DISPOSITION_INFORMATION) {
465 status = smb_check_file_disposition_info(
466 fsp,
467 (char *)state->data.data,
468 state->data.length,
469 &delete_on_close);
470 if (tevent_req_nterror(req, status)) {
471 return;
475 if (!rename && !delete_on_close) {
476 return;
479 state->lck = get_existing_share_mode_lock(state, fsp->file_id);
480 if (state->lck == NULL) {
481 tevent_req_nterror(req, NT_STATUS_UNSUCCESSFUL);
482 return;
485 timeout = tevent_timeval_set(OPLOCK_BREAK_TIMEOUT, 0);
486 timeout = timeval_sum(&smb2req->request_time, &timeout);
488 subreq = delay_for_handle_lease_break_send(state,
489 state->ev,
490 timeout,
491 fsp,
492 rename,
493 &state->lck);
494 if (tevent_req_nomem(subreq, req)) {
495 return;
497 if (tevent_req_is_in_progress(subreq)) {
498 state->delay = true;
499 tevent_req_set_callback(subreq,
500 smbd_smb2_setinfo_lease_break_fsp_done,
501 req);
502 return;
505 status = delay_for_handle_lease_break_recv(subreq, state, &state->lck);
506 TALLOC_FREE(subreq);
507 if (tevent_req_nterror(req, status)) {
508 return;
512 static void smbd_smb2_setinfo_lease_break_fsp_done(struct tevent_req *subreq)
514 struct tevent_req *req = tevent_req_callback_data(
515 subreq, struct tevent_req);
516 struct smbd_smb2_setinfo_state *state = tevent_req_data(
517 req, struct smbd_smb2_setinfo_state);
518 int ret_size;
519 NTSTATUS status;
520 bool ok;
522 status = delay_for_handle_lease_break_recv(subreq, state, &state->lck);
523 TALLOC_FREE(subreq);
524 if (tevent_req_nterror(req, status)) {
525 return;
529 * Make sure we run as the user again
531 ok = change_to_user_and_service(
532 state->smb2req->tcon->compat,
533 state->smb2req->session->global->session_wire_id);
534 if (!ok) {
535 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
536 return;
539 /* Do the setinfo again under the lock. */
540 status = smbd_do_setfilepathinfo(state->fsp->conn,
541 state->smb2req->smb1req,
542 state,
543 state->file_info_level,
544 state->fsp,
545 &state->lck,
546 state->fsp->fsp_name,
547 (char *)state->data.data,
548 state->data.length,
549 &ret_size);
550 TALLOC_FREE(state->lck);
551 if (tevent_req_nterror(req, status)) {
552 return;
555 tevent_req_done(req);
558 static void smbd_smb2_setinfo_rename_dst_check(struct tevent_req *req)
560 struct smbd_smb2_setinfo_state *state = tevent_req_data(
561 req, struct smbd_smb2_setinfo_state);
562 struct tevent_req *subreq = NULL;
563 struct timeval timeout;
564 bool overwrite = false;
565 struct files_struct *fsp = state->fsp;
566 struct files_struct *dst_dirfsp = NULL;
567 struct smb_filename *smb_fname_dst = NULL;
568 char *dst_original_lcomp = NULL;
569 bool has_other_open;
570 NTSTATUS status;
571 NTSTATUS close_status;
573 if (state->file_info_level != SMB2_FILE_RENAME_INFORMATION_INTERNAL) {
574 return;
577 if (state->rename_dst_check_done) {
578 return;
581 status = smb2_parse_file_rename_information(state,
582 fsp->conn,
583 state->smb2req->smb1req,
584 (char *)state->data.data,
585 state->data.length,
586 fsp,
587 fsp->fsp_name,
588 &overwrite,
589 &dst_dirfsp,
590 &smb_fname_dst,
591 &dst_original_lcomp);
592 if (tevent_req_nterror(req, status)) {
593 return;
595 TALLOC_FREE(dst_original_lcomp);
597 if (!VALID_STAT(smb_fname_dst->st)) {
598 /* Doesn't exist, nothing to do here */
599 return;
601 if (strequal(fsp->fsp_name->base_name, smb_fname_dst->base_name) &&
602 strequal(fsp->fsp_name->stream_name, smb_fname_dst->stream_name))
604 return;
606 if (!overwrite) {
607 /* Return the correct error */
608 tevent_req_nterror(req, NT_STATUS_OBJECT_NAME_COLLISION);
609 return;
612 status = SMB_VFS_CREATE_FILE(
613 fsp->conn,
614 NULL,
615 dst_dirfsp,
616 smb_fname_dst,
617 FILE_READ_ATTRIBUTES,
618 FILE_SHARE_READ
619 | FILE_SHARE_WRITE
620 | FILE_SHARE_DELETE,
621 FILE_OPEN, /* create_disposition*/
622 0, /* create_options */
623 FILE_ATTRIBUTE_NORMAL,
624 INTERNAL_OPEN_ONLY, /* oplock_request */
625 NULL, /* lease */
626 0, /* allocation_size */
627 0, /* private_flags */
628 NULL, /* sd */
629 NULL, /* ea_list */
630 &state->dstfsp, /* result */
631 NULL, /* psbuf */
632 NULL,
633 NULL); /* create context */
634 if (!NT_STATUS_IS_OK(status)) {
635 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
636 /* A race, file was deleted */
637 return;
639 tevent_req_nterror(req, status);
640 return;
643 state->lck = get_existing_share_mode_lock(state, state->dstfsp->file_id);
644 if (state->lck == NULL) {
645 close_status = close_file_free(NULL, &state->dstfsp, ERROR_CLOSE);
646 if (!NT_STATUS_IS_OK(close_status)) {
647 DBG_ERR("close_file_free failed\n");
649 return;
652 timeout = tevent_timeval_set(OPLOCK_BREAK_TIMEOUT, 0);
653 timeout = timeval_sum(&state->smb2req->request_time, &timeout);
655 subreq = delay_for_handle_lease_break_send(state,
656 state->ev,
657 timeout,
658 state->dstfsp,
659 false,
660 &state->lck);
661 if (subreq == NULL) {
662 close_status = close_file_free(NULL, &state->dstfsp, ERROR_CLOSE);
663 if (!NT_STATUS_IS_OK(close_status)) {
664 DBG_ERR("close_file_free failed\n");
666 tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
667 return;
669 if (tevent_req_is_in_progress(subreq)) {
670 state->delay = true;
671 tevent_req_set_callback(subreq,
672 smbd_smb2_setinfo_rename_dst_delay_done,
673 req);
674 return;
677 status = delay_for_handle_lease_break_recv(subreq, state, &state->lck);
678 TALLOC_FREE(subreq);
679 if (!NT_STATUS_IS_OK(status)) {
680 close_status = close_file_free(NULL, &state->dstfsp, ERROR_CLOSE);
681 if (!NT_STATUS_IS_OK(close_status)) {
682 DBG_ERR("close_file_free failed\n");
684 tevent_req_nterror(req, status);
685 return;
688 has_other_open = has_other_nonposix_opens(state->lck, state->dstfsp);
689 TALLOC_FREE(state->lck);
691 status = close_file_free(NULL, &state->dstfsp, NORMAL_CLOSE);
692 if (tevent_req_nterror(req, status)) {
693 DBG_ERR("close_file_free failed\n");
694 return;
697 if (has_other_open) {
698 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
699 return;
701 state->rename_dst_check_done = true;
702 return;
705 static void smbd_smb2_setinfo_rename_dst_delay_done(struct tevent_req *subreq)
707 struct tevent_req *req = tevent_req_callback_data(
708 subreq, struct tevent_req);
709 struct smbd_smb2_setinfo_state *state = tevent_req_data(
710 req, struct smbd_smb2_setinfo_state);
711 struct smbXsrv_session *session = state->smb2req->session;
712 bool has_other_open;
713 NTSTATUS close_status;
714 NTSTATUS status;
715 bool ok;
717 status = delay_for_handle_lease_break_recv(subreq, state, &state->lck);
718 TALLOC_FREE(subreq);
719 if (!NT_STATUS_IS_OK(status)) {
720 close_status = close_file_free(NULL,
721 &state->dstfsp,
722 NORMAL_CLOSE);
723 if (!NT_STATUS_IS_OK(close_status)) {
724 DBG_ERR("close_file_free failed\n");
726 tevent_req_nterror(req, status);
727 return;
731 * Make sure we run as the user again
733 ok = change_to_user_and_service(state->dstfsp->conn,
734 session->global->session_wire_id);
735 if (!ok) {
736 close_status = close_file_free(NULL,
737 &state->dstfsp,
738 NORMAL_CLOSE);
739 if (!NT_STATUS_IS_OK(close_status)) {
740 DBG_ERR("close_file_free failed\n");
742 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
743 return;
746 has_other_open = has_other_nonposix_opens(state->lck, state->dstfsp);
747 TALLOC_FREE(state->lck);
749 status = close_file_free(NULL, &state->dstfsp, NORMAL_CLOSE);
750 if (tevent_req_nterror(req, status)) {
751 DBG_ERR("close_file_free failed\n");
752 return;
755 if (has_other_open) {
756 tevent_req_nterror(req, NT_STATUS_ACCESS_DENIED);
757 return;
761 * We've finished breaking H-lease on the rename destination, now
762 * trigger the fsp check.
764 state->rename_dst_check_done = true;
765 smbd_smb2_setinfo_lease_break_check(req);
768 static NTSTATUS smbd_smb2_setinfo_recv(struct tevent_req *req)
770 NTSTATUS status;
772 if (tevent_req_is_nterror(req, &status)) {
773 tevent_req_received(req);
774 return status;
777 tevent_req_received(req);
778 return NT_STATUS_OK;