2 Unix SMB/CIFS implementation.
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/>.
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "../libcli/smb/smb_common.h"
26 #include "../lib/util/tevent_ntstatus.h"
30 #define DBGC_CLASS DBGC_SMB2
32 struct smbd_smb2_lock_element {
38 struct smbd_smb2_lock_state {
39 struct smbd_smb2_request *smb2req;
40 struct smb_request *smb1req;
41 struct blocking_lock_record *blr;
43 struct smbd_lock_element *locks;
44 uint8_t lock_sequence_value;
45 uint8_t *lock_sequence_element;
48 static void remove_pending_lock(struct smbd_smb2_lock_state *state,
49 struct blocking_lock_record *blr);
51 static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
52 struct tevent_context *ev,
53 struct smbd_smb2_request *smb2req,
54 struct files_struct *in_fsp,
55 uint32_t in_lock_sequence,
56 uint16_t in_lock_count,
57 struct smbd_smb2_lock_element *in_locks);
58 static NTSTATUS smbd_smb2_lock_recv(struct tevent_req *req);
60 static void smbd_smb2_request_lock_done(struct tevent_req *subreq);
61 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req)
63 const uint8_t *inbody;
64 uint16_t in_lock_count;
65 uint32_t in_lock_sequence;
66 uint64_t in_file_id_persistent;
67 uint64_t in_file_id_volatile;
68 struct files_struct *in_fsp;
69 struct smbd_smb2_lock_element *in_locks;
70 struct tevent_req *subreq;
71 const uint8_t *lock_buffer;
75 status = smbd_smb2_request_verify_sizes(req, 0x30);
76 if (!NT_STATUS_IS_OK(status)) {
77 return smbd_smb2_request_error(req, status);
79 inbody = SMBD_SMB2_IN_BODY_PTR(req);
81 in_lock_count = CVAL(inbody, 0x02);
82 if (req->xconn->protocol >= PROTOCOL_SMB2_10) {
83 in_lock_sequence = IVAL(inbody, 0x04);
85 /* 0x04 - 4 bytes reserved */
88 in_file_id_persistent = BVAL(inbody, 0x08);
89 in_file_id_volatile = BVAL(inbody, 0x10);
91 if (in_lock_count < 1) {
92 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
95 if (((in_lock_count - 1) * 0x18) > SMBD_SMB2_IN_DYN_LEN(req)) {
96 return smbd_smb2_request_error(req, NT_STATUS_INVALID_PARAMETER);
99 in_locks = talloc_array(req, struct smbd_smb2_lock_element,
101 if (in_locks == NULL) {
102 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
106 lock_buffer = inbody + 0x18;
108 in_locks[l].offset = BVAL(lock_buffer, 0x00);
109 in_locks[l].length = BVAL(lock_buffer, 0x08);
110 in_locks[l].flags = IVAL(lock_buffer, 0x10);
111 /* 0x14 - 4 reserved bytes */
113 status = req->session->status;
114 if (NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_SESSION_EXPIRED)) {
116 * We need to catch NT_STATUS_NETWORK_SESSION_EXPIRED
117 * for lock requests only.
119 * Unlock requests still need to be processed!
121 * This means smbd_smb2_request_check_session()
122 * can't handle the difference and always
123 * allows SMB2_OP_LOCK.
125 if (in_locks[0].flags != SMB2_LOCK_FLAG_UNLOCK) {
126 return smbd_smb2_request_error(req, status);
130 lock_buffer = SMBD_SMB2_IN_DYN_PTR(req);
132 for (l=1; l < in_lock_count; l++) {
133 in_locks[l].offset = BVAL(lock_buffer, 0x00);
134 in_locks[l].length = BVAL(lock_buffer, 0x08);
135 in_locks[l].flags = IVAL(lock_buffer, 0x10);
136 /* 0x14 - 4 reserved bytes */
141 in_fsp = file_fsp_smb2(req, in_file_id_persistent, in_file_id_volatile);
142 if (in_fsp == NULL) {
143 return smbd_smb2_request_error(req, NT_STATUS_FILE_CLOSED);
146 subreq = smbd_smb2_lock_send(req, req->ev_ctx,
151 if (subreq == NULL) {
152 return smbd_smb2_request_error(req, NT_STATUS_NO_MEMORY);
154 tevent_req_set_callback(subreq, smbd_smb2_request_lock_done, req);
156 return smbd_smb2_request_pending_queue(req, subreq, 500);
159 static void smbd_smb2_request_lock_done(struct tevent_req *subreq)
161 struct smbd_smb2_request *smb2req = tevent_req_callback_data(subreq,
162 struct smbd_smb2_request);
165 NTSTATUS error; /* transport error */
167 status = smbd_smb2_lock_recv(subreq);
169 if (!NT_STATUS_IS_OK(status)) {
170 error = smbd_smb2_request_error(smb2req, status);
171 if (!NT_STATUS_IS_OK(error)) {
172 smbd_server_connection_terminate(smb2req->xconn,
179 outbody = smbd_smb2_generate_outbody(smb2req, 0x04);
180 if (outbody.data == NULL) {
181 error = smbd_smb2_request_error(smb2req, NT_STATUS_NO_MEMORY);
182 if (!NT_STATUS_IS_OK(error)) {
183 smbd_server_connection_terminate(smb2req->xconn,
190 SSVAL(outbody.data, 0x00, 0x04); /* struct size */
191 SSVAL(outbody.data, 0x02, 0); /* reserved */
193 error = smbd_smb2_request_done(smb2req, outbody, NULL);
194 if (!NT_STATUS_IS_OK(error)) {
195 smbd_server_connection_terminate(smb2req->xconn,
201 static struct tevent_req *smbd_smb2_lock_send(TALLOC_CTX *mem_ctx,
202 struct tevent_context *ev,
203 struct smbd_smb2_request *smb2req,
204 struct files_struct *fsp,
205 uint32_t in_lock_sequence,
206 uint16_t in_lock_count,
207 struct smbd_smb2_lock_element *in_locks)
209 struct tevent_req *req;
210 struct smbd_smb2_lock_state *state;
211 struct smb_request *smb1req;
212 int32_t timeout = -1;
213 bool isunlock = false;
215 struct smbd_lock_element *locks;
218 bool check_lock_sequence = false;
219 uint32_t lock_sequence_bucket = 0;
221 req = tevent_req_create(mem_ctx, &state,
222 struct smbd_smb2_lock_state);
226 state->smb2req = smb2req;
227 smb2req->subreq = req; /* So we can find this when going async. */
229 smb1req = smbd_smb2_fake_smb_request(smb2req);
230 if (tevent_req_nomem(smb1req, req)) {
231 return tevent_req_post(req, ev);
233 state->smb1req = smb1req;
235 DEBUG(10,("smbd_smb2_lock_send: %s - %s\n",
236 fsp_str_dbg(fsp), fsp_fnum_dbg(fsp)));
239 * Windows sets check_lock_sequence = true
240 * only for resilient and persistent handles.
242 * According to MS-SMB2 section 3.3.5.14 a server SHOULD activate
243 * processing of lock sequence numbers for EITHER
244 * - protocol dialect 2.1 and resilient handles
246 * - protocol dialect 3.x.
248 * TODO: What about other handles using multi-channel?
250 if (smb2req->xconn->protocol >= PROTOCOL_SMB2_22) {
251 check_lock_sequence = true;
254 if (check_lock_sequence) {
255 state->lock_sequence_value = in_lock_sequence & 0xF;
256 lock_sequence_bucket = in_lock_sequence >> 4;
258 if ((lock_sequence_bucket > 0) &&
259 (lock_sequence_bucket <= sizeof(fsp->op->global->lock_sequence_array)))
261 uint32_t idx = lock_sequence_bucket - 1;
262 uint8_t *array = fsp->op->global->lock_sequence_array;
264 state->lock_sequence_element = &array[idx];
267 if (state->lock_sequence_element != NULL) {
268 if (*state->lock_sequence_element == state->lock_sequence_value)
270 DBG_INFO("replayed smb2 lock request detected: "
271 "file %s, value %u, bucket %u\n",
273 (unsigned)state->lock_sequence_value,
274 (unsigned)lock_sequence_bucket);
275 tevent_req_done(req);
276 return tevent_req_post(req, ev);
278 *state->lock_sequence_element = 0xFF;
281 locks = talloc_array(state, struct smbd_lock_element, in_lock_count);
283 tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
284 return tevent_req_post(req, ev);
287 switch (in_locks[0].flags) {
288 case SMB2_LOCK_FLAG_SHARED:
289 case SMB2_LOCK_FLAG_EXCLUSIVE:
290 if (in_lock_count > 1) {
291 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
292 return tevent_req_post(req, ev);
297 case SMB2_LOCK_FLAG_SHARED|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY:
298 case SMB2_LOCK_FLAG_EXCLUSIVE|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY:
302 case SMB2_LOCK_FLAG_UNLOCK:
303 /* only the first lock gives the UNLOCK bit - see
310 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
311 return tevent_req_post(req, ev);
314 if (!isunlock && (in_lock_count > 1)) {
317 * 3.3.5.14.2 says we SHOULD fail with INVALID_PARAMETER if we
318 * have more than one lock and one of those is blocking.
321 for (i=0; i<in_lock_count; i++) {
322 uint32_t flags = in_locks[i].flags;
324 if ((flags & SMB2_LOCK_FLAG_FAIL_IMMEDIATELY) == 0) {
326 req, NT_STATUS_INVALID_PARAMETER);
327 return tevent_req_post(req, ev);
332 for (i=0; i<in_lock_count; i++) {
333 bool invalid = false;
335 switch (in_locks[i].flags) {
336 case SMB2_LOCK_FLAG_SHARED:
337 case SMB2_LOCK_FLAG_EXCLUSIVE:
344 case SMB2_LOCK_FLAG_SHARED|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY:
345 case SMB2_LOCK_FLAG_EXCLUSIVE|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY:
351 case SMB2_LOCK_FLAG_UNLOCK:
353 tevent_req_nterror(req,
354 NT_STATUS_INVALID_PARAMETER);
355 return tevent_req_post(req, ev);
362 * If the first element was a UNLOCK
363 * we need to defer the error response
364 * to the backend, because we need to process
365 * all unlock elements before
370 tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
371 return tevent_req_post(req, ev);
374 locks[i].smblctx = fsp->op->global->open_persistent_id;
375 locks[i].offset = in_locks[i].offset;
376 locks[i].count = in_locks[i].length;
378 if (in_locks[i].flags & SMB2_LOCK_FLAG_EXCLUSIVE) {
379 locks[i].brltype = WRITE_LOCK;
380 } else if (in_locks[i].flags & SMB2_LOCK_FLAG_SHARED) {
381 locks[i].brltype = READ_LOCK;
382 } else if (invalid) {
384 * this is an invalid UNLOCK element
385 * and the backend needs to test for
386 * brltype != UNLOCK_LOCK and return
387 * NT_STATUS_INVALID_PARAMETER
389 locks[i].brltype = READ_LOCK;
391 locks[i].brltype = UNLOCK_LOCK;
394 DEBUG(10,("smbd_smb2_lock_send: index %d offset=%llu, count=%llu, "
395 "smblctx = %llu type %d\n",
397 (unsigned long long)locks[i].offset,
398 (unsigned long long)locks[i].count,
399 (unsigned long long)locks[i].smblctx,
400 (int)locks[i].brltype ));
403 state->locks = locks;
404 state->lock_count = in_lock_count;
407 status = smbd_do_unlocking(smb1req, fsp,
408 in_lock_count, locks);
411 status = smbd_do_locking(smb1req, fsp,
418 if (!NT_STATUS_IS_OK(status)) {
419 if (NT_STATUS_EQUAL(status, NT_STATUS_FILE_LOCK_CONFLICT)) {
420 status = NT_STATUS_LOCK_NOT_GRANTED;
422 tevent_req_nterror(req, status);
423 return tevent_req_post(req, ev);
427 tevent_req_defer_callback(req, smb2req->ev_ctx);
428 SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(smb2req->profile);
432 if (state->lock_sequence_element != NULL) {
433 *state->lock_sequence_element = state->lock_sequence_value;
436 tevent_req_done(req);
437 return tevent_req_post(req, ev);
440 static NTSTATUS smbd_smb2_lock_recv(struct tevent_req *req)
444 if (tevent_req_is_nterror(req, &status)) {
445 tevent_req_received(req);
449 tevent_req_received(req);
453 /****************************************************************
454 Cancel an outstanding blocking lock request.
455 *****************************************************************/
457 static bool smbd_smb2_lock_cancel(struct tevent_req *req)
459 struct smbd_smb2_request *smb2req = NULL;
460 struct smbd_smb2_lock_state *state = tevent_req_data(req,
461 struct smbd_smb2_lock_state);
466 if (!state->smb2req) {
470 smb2req = state->smb2req;
472 remove_pending_lock(state, state->blr);
475 * If the request is canceled because of logoff, tdis or close
476 * the status is NT_STATUS_RANGE_NOT_LOCKED instead of
477 * NT_STATUS_CANCELLED.
479 * Note that the close case is handled in
480 * cancel_pending_lock_requests_by_fid_smb2(SHUTDOWN_CLOSE)
483 if (!NT_STATUS_IS_OK(smb2req->session->status)) {
484 tevent_req_nterror(req, NT_STATUS_RANGE_NOT_LOCKED);
488 if (!NT_STATUS_IS_OK(smb2req->tcon->status)) {
489 tevent_req_nterror(req, NT_STATUS_RANGE_NOT_LOCKED);
493 tevent_req_nterror(req, NT_STATUS_CANCELLED);
497 /****************************************************************
498 Got a message saying someone unlocked a file. Re-schedule all
499 blocking lock requests as we don't know if anything overlapped.
500 *****************************************************************/
502 static void received_unlock_msg(struct messaging_context *msg,
505 struct server_id server_id,
508 struct smbd_server_connection *sconn =
509 talloc_get_type_abort(private_data,
510 struct smbd_server_connection);
512 DEBUG(10,("received_unlock_msg (SMB2)\n"));
514 process_blocking_lock_queue_smb2(sconn, timeval_current());
517 /****************************************************************
518 Function to get the blr on a pending record.
519 *****************************************************************/
521 struct blocking_lock_record *get_pending_smb2req_blr(struct smbd_smb2_request *smb2req)
523 struct smbd_smb2_lock_state *state = NULL;
524 const uint8_t *inhdr;
529 if (smb2req->subreq == NULL) {
532 if (!tevent_req_is_in_progress(smb2req->subreq)) {
535 inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req);
536 if (SVAL(inhdr, SMB2_HDR_OPCODE) != SMB2_OP_LOCK) {
539 state = tevent_req_data(smb2req->subreq,
540 struct smbd_smb2_lock_state);
546 /****************************************************************
547 Set up the next brl timeout.
548 *****************************************************************/
550 static bool recalc_smb2_brl_timeout(struct smbd_server_connection *sconn)
552 struct smbXsrv_connection *xconn = NULL;
553 struct timeval next_timeout = timeval_zero();
554 int max_brl_timeout = lp_parm_int(-1, "brl", "recalctime", 5);
556 TALLOC_FREE(sconn->smb2.locks.brl_timeout);
558 if (sconn->client != NULL) {
559 xconn = sconn->client->connections;
562 for (; xconn != NULL; xconn = xconn->next) {
563 struct smbd_smb2_request *smb2req, *nextreq;
565 for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
566 struct blocking_lock_record *blr =
567 get_pending_smb2req_blr(smb2req);
569 nextreq = smb2req->next;
575 if (!timeval_is_zero(&blr->expire_time)) {
576 next_timeout = timeval_brl_min(&next_timeout,
582 * If we're blocked on pid 0xFFFFFFFFFFFFFFFFLL this is
583 * a POSIX lock, so calculate a timeout of
584 * 10 seconds into the future.
586 if (blr->blocking_smblctx == 0xFFFFFFFFFFFFFFFFLL) {
587 struct timeval psx_to;
589 psx_to = timeval_current_ofs(10, 0);
590 next_timeout = timeval_brl_min(&next_timeout,
596 if (timeval_is_zero(&next_timeout)) {
597 DEBUG(10, ("recalc_smb2_brl_timeout:Next "
598 "timeout = Infinite.\n"));
603 * To account for unclean shutdowns by clients we need a
604 * maximum timeout that we use for checking pending locks. If
605 * we have any pending locks at all, then check if the pending
606 * lock can continue at least every brl:recalctime seconds
607 * (default 5 seconds).
609 * This saves us needing to do a message_send_all() in the
610 * SIGCHLD handler in the parent daemon. That
611 * message_send_all() caused O(n^2) work to be done when IP
612 * failovers happened in clustered Samba, which could make the
613 * entire system unusable for many minutes.
616 if (max_brl_timeout > 0) {
617 struct timeval min_to = timeval_current_ofs(max_brl_timeout, 0);
618 next_timeout = timeval_brl_min(&next_timeout, &min_to);
622 struct timeval cur, from_now;
624 cur = timeval_current();
625 from_now = timeval_until(&cur, &next_timeout);
626 DEBUG(10, ("recalc_smb2_brl_timeout: Next "
627 "timeout = %d.%d seconds from now.\n",
628 (int)from_now.tv_sec, (int)from_now.tv_usec));
632 * brl_timeout_fn() calls change_to_root_user()
633 * so we can use sconn->root_ev_ctx.
635 sconn->smb2.locks.brl_timeout = tevent_add_timer(
641 if (!sconn->smb2.locks.brl_timeout) {
647 /****************************************************************
648 Get an SMB2 lock request to go async. lock_timeout should
650 *****************************************************************/
652 bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
653 struct smb_request *smb1req,
658 enum brl_type lock_type,
659 enum brl_flavour lock_flav,
662 uint64_t blocking_smblctx)
664 struct smbd_server_connection *sconn = smb1req->sconn;
665 struct smbd_smb2_request *smb2req = smb1req->smb2req;
666 struct tevent_req *req = NULL;
667 struct smbd_smb2_lock_state *state = NULL;
668 struct blocking_lock_record *blr = NULL;
669 NTSTATUS status = NT_STATUS_OK;
674 req = smb2req->subreq;
678 if (!tevent_req_is_in_progress(smb2req->subreq)) {
681 state = tevent_req_data(req, struct smbd_smb2_lock_state);
686 blr = talloc_zero(state, struct blocking_lock_record);
692 if (lock_timeout == -1) {
693 blr->expire_time.tv_sec = 0;
694 blr->expire_time.tv_usec = 0; /* Never expire. */
696 blr->expire_time = timeval_current_ofs_msec(lock_timeout);
699 blr->lock_num = lock_num;
700 blr->smblctx = smblctx;
701 blr->blocking_smblctx = blocking_smblctx;
702 blr->lock_flav = lock_flav;
703 blr->lock_type = lock_type;
704 blr->offset = offset;
707 /* Specific brl_lock() implementations can fill this in. */
708 blr->blr_private = NULL;
710 /* Add a pending lock record for this. */
711 status = brl_lock(sconn->msg_ctx,
714 messaging_server_id(sconn->msg_ctx),
717 lock_type == READ_LOCK ? PENDING_READ_LOCK : PENDING_WRITE_LOCK,
722 if (!NT_STATUS_IS_OK(status)) {
723 DEBUG(0,("push_blocking_lock_request_smb2: "
724 "failed to add PENDING_LOCK record.\n"));
730 DEBUG(10,("push_blocking_lock_request_smb2: file %s timeout %d\n",
734 recalc_smb2_brl_timeout(sconn);
736 /* Ensure we'll receive messages when this is unlocked. */
737 if (!sconn->smb2.locks.blocking_lock_unlock_state) {
738 messaging_register(sconn->msg_ctx, sconn,
739 MSG_SMB_UNLOCK, received_unlock_msg);
740 sconn->smb2.locks.blocking_lock_unlock_state = true;
743 /* allow this request to be canceled */
744 tevent_req_set_cancel_fn(req, smbd_smb2_lock_cancel);
749 /****************************************************************
750 Remove a pending lock record under lock.
751 *****************************************************************/
753 static void remove_pending_lock(struct smbd_smb2_lock_state *state,
754 struct blocking_lock_record *blr)
756 struct byte_range_lock *br_lck = brl_get_locks(
759 DEBUG(10, ("remove_pending_lock: BLR = %p\n", blr));
762 brl_lock_cancel(br_lck,
764 messaging_server_id(blr->fsp->conn->sconn->msg_ctx),
772 /****************************************************************
773 Re-proccess a blocking lock request.
774 This is equivalent to process_lockingX() inside smbd/blocking.c
775 *****************************************************************/
777 static void reprocess_blocked_smb2_lock(struct smbd_smb2_request *smb2req,
778 struct timeval tv_curr)
780 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
781 struct blocking_lock_record *blr = NULL;
782 struct smbd_smb2_lock_state *state = NULL;
783 struct byte_range_lock *br_lck = NULL;
784 struct smbd_lock_element *e = NULL;
785 files_struct *fsp = NULL;
787 if (!smb2req->subreq) {
790 SMBPROFILE_IOBYTES_ASYNC_SET_BUSY(smb2req->profile);
792 state = tevent_req_data(smb2req->subreq, struct smbd_smb2_lock_state);
800 /* We can only have one blocked lock in SMB2. */
801 SMB_ASSERT(state->lock_count == 1);
802 SMB_ASSERT(blr->lock_num == 0);
804 /* Try and get the outstanding lock. */
805 e = &state->locks[blr->lock_num];
807 br_lck = do_lock(fsp->conn->sconn->msg_ctx,
816 &blr->blocking_smblctx);
820 if (NT_STATUS_IS_OK(status)) {
822 * Success - we got the lock.
825 DEBUG(3,("reprocess_blocked_smb2_lock SUCCESS file = %s, "
826 "%s, num_locks=%d\n",
829 (int)state->lock_count));
831 if (state->lock_sequence_element != NULL) {
832 *state->lock_sequence_element = state->lock_sequence_value;
835 remove_pending_lock(state, blr);
836 tevent_req_done(smb2req->subreq);
840 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
841 !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
843 * We have other than a "can't get lock"
844 * error. Return an error.
846 remove_pending_lock(state, blr);
847 tevent_req_nterror(smb2req->subreq, status);
852 * We couldn't get the lock for this record.
853 * If the time has expired, return a lock error.
856 if (!timeval_is_zero(&blr->expire_time) &&
857 timeval_compare(&blr->expire_time, &tv_curr) <= 0) {
858 remove_pending_lock(state, blr);
859 tevent_req_nterror(smb2req->subreq, NT_STATUS_LOCK_NOT_GRANTED);
864 * Still can't get the lock - keep waiting.
867 DEBUG(10,("reprocess_blocked_smb2_lock: failed to get lock "
868 "for file %s, %s. Still waiting....\n",
872 SMBPROFILE_IOBYTES_ASYNC_SET_IDLE(smb2req->profile);
876 /****************************************************************
877 Attempt to proccess all outstanding blocking locks pending on
879 *****************************************************************/
881 void process_blocking_lock_queue_smb2(
882 struct smbd_server_connection *sconn, struct timeval tv_curr)
884 struct smbXsrv_connection *xconn = NULL;
886 if (sconn != NULL && sconn->client != NULL) {
887 xconn = sconn->client->connections;
890 for (; xconn != NULL; xconn = xconn->next) {
891 struct smbd_smb2_request *smb2req, *nextreq;
893 for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
894 const uint8_t *inhdr;
896 nextreq = smb2req->next;
898 if (smb2req->subreq == NULL) {
899 /* This message has been processed. */
902 if (!tevent_req_is_in_progress(smb2req->subreq)) {
903 /* This message has been processed. */
907 inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req);
908 if (SVAL(inhdr, SMB2_HDR_OPCODE) == SMB2_OP_LOCK) {
909 reprocess_blocked_smb2_lock(smb2req, tv_curr);
914 recalc_smb2_brl_timeout(sconn);
917 /****************************************************************************
918 Remove any locks on this fd. Called from file_close().
919 ****************************************************************************/
921 void cancel_pending_lock_requests_by_fid_smb2(files_struct *fsp,
922 struct byte_range_lock *br_lck,
923 enum file_close_type close_type)
925 struct smbd_server_connection *sconn = fsp->conn->sconn;
926 struct smbXsrv_connection *xconn = NULL;
928 if (sconn != NULL && sconn->client != NULL) {
929 xconn = sconn->client->connections;
932 for (; xconn != NULL; xconn = xconn->next) {
933 struct smbd_smb2_request *smb2req, *nextreq;
935 for (smb2req = xconn->smb2.requests; smb2req; smb2req = nextreq) {
936 struct smbd_smb2_lock_state *state = NULL;
937 files_struct *fsp_curr = NULL;
938 struct blocking_lock_record *blr = NULL;
939 const uint8_t *inhdr;
941 nextreq = smb2req->next;
943 if (smb2req->subreq == NULL) {
944 /* This message has been processed. */
947 if (!tevent_req_is_in_progress(smb2req->subreq)) {
948 /* This message has been processed. */
952 inhdr = SMBD_SMB2_IN_HDR_PTR(smb2req);
953 if (SVAL(inhdr, SMB2_HDR_OPCODE) != SMB2_OP_LOCK) {
954 /* Not a lock call. */
958 state = tevent_req_data(smb2req->subreq,
959 struct smbd_smb2_lock_state);
961 /* Strange - is this even possible ? */
965 fsp_curr = smb2req->compat_chain_fsp;
966 if (fsp_curr == NULL) {
967 /* Strange - is this even possible ? */
971 if (fsp_curr != fsp) {
972 /* It's not our fid */
978 /* Remove the entries from the lock db. */
979 brl_lock_cancel(br_lck,
981 messaging_server_id(sconn->msg_ctx),
986 /* Finally end the request. */
987 if (close_type == SHUTDOWN_CLOSE) {
988 tevent_req_done(smb2req->subreq);
990 tevent_req_nterror(smb2req->subreq,
991 NT_STATUS_RANGE_NOT_LOCKED);