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"
29 struct smbd_smb2_lock_element
{
35 struct smbd_smb2_lock_state
{
36 struct smbd_smb2_request
*smb2req
;
37 struct smb_request
*smb1req
;
38 struct blocking_lock_record
*blr
;
40 struct smbd_lock_element
*locks
;
43 static void remove_pending_lock(struct smbd_smb2_lock_state
*state
,
44 struct blocking_lock_record
*blr
);
46 static struct tevent_req
*smbd_smb2_lock_send(TALLOC_CTX
*mem_ctx
,
47 struct tevent_context
*ev
,
48 struct smbd_smb2_request
*smb2req
,
49 struct files_struct
*in_fsp
,
51 uint16_t in_lock_count
,
52 struct smbd_smb2_lock_element
*in_locks
);
53 static NTSTATUS
smbd_smb2_lock_recv(struct tevent_req
*req
);
55 static void smbd_smb2_request_lock_done(struct tevent_req
*subreq
);
56 NTSTATUS
smbd_smb2_request_process_lock(struct smbd_smb2_request
*req
)
59 const uint8_t *inbody
;
60 const int i
= req
->current_idx
;
62 uint16_t in_lock_count
;
63 uint64_t in_file_id_persistent
;
64 uint64_t in_file_id_volatile
;
65 struct files_struct
*in_fsp
;
66 struct smbd_smb2_lock_element
*in_locks
;
67 struct tevent_req
*subreq
;
68 const uint8_t *lock_buffer
;
72 status
= smbd_smb2_request_verify_sizes(req
, 0x30);
73 if (!NT_STATUS_IS_OK(status
)) {
74 return smbd_smb2_request_error(req
, status
);
76 inhdr
= (const uint8_t *)req
->in
.vector
[i
+0].iov_base
;
77 inbody
= (const uint8_t *)req
->in
.vector
[i
+1].iov_base
;
79 in_smbpid
= IVAL(inhdr
, SMB2_HDR_PID
);
81 in_lock_count
= CVAL(inbody
, 0x02);
82 /* 0x04 - 4 bytes reserved */
83 in_file_id_persistent
= BVAL(inbody
, 0x08);
84 in_file_id_volatile
= BVAL(inbody
, 0x10);
86 if (in_lock_count
< 1) {
87 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
90 if (((in_lock_count
- 1) * 0x18) > req
->in
.vector
[i
+2].iov_len
) {
91 return smbd_smb2_request_error(req
, NT_STATUS_INVALID_PARAMETER
);
94 in_locks
= talloc_array(req
, struct smbd_smb2_lock_element
,
96 if (in_locks
== NULL
) {
97 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
101 lock_buffer
= inbody
+ 0x18;
103 in_locks
[l
].offset
= BVAL(lock_buffer
, 0x00);
104 in_locks
[l
].length
= BVAL(lock_buffer
, 0x08);
105 in_locks
[l
].flags
= IVAL(lock_buffer
, 0x10);
106 /* 0x14 - 4 reserved bytes */
108 lock_buffer
= (const uint8_t *)req
->in
.vector
[i
+2].iov_base
;
110 for (l
=1; l
< in_lock_count
; l
++) {
111 in_locks
[l
].offset
= BVAL(lock_buffer
, 0x00);
112 in_locks
[l
].length
= BVAL(lock_buffer
, 0x08);
113 in_locks
[l
].flags
= IVAL(lock_buffer
, 0x10);
114 /* 0x14 - 4 reserved bytes */
119 in_fsp
= file_fsp_smb2(req
, in_file_id_persistent
, in_file_id_volatile
);
120 if (in_fsp
== NULL
) {
121 return smbd_smb2_request_error(req
, NT_STATUS_FILE_CLOSED
);
124 subreq
= smbd_smb2_lock_send(req
, req
->sconn
->ev_ctx
,
129 if (subreq
== NULL
) {
130 return smbd_smb2_request_error(req
, NT_STATUS_NO_MEMORY
);
132 tevent_req_set_callback(subreq
, smbd_smb2_request_lock_done
, req
);
134 return smbd_smb2_request_pending_queue(req
, subreq
, 500);
137 static void smbd_smb2_request_lock_done(struct tevent_req
*subreq
)
139 struct smbd_smb2_request
*smb2req
= tevent_req_callback_data(subreq
,
140 struct smbd_smb2_request
);
143 NTSTATUS error
; /* transport error */
145 if (smb2req
->cancelled
) {
146 const uint8_t *inhdr
= (const uint8_t *)
147 smb2req
->in
.vector
[smb2req
->current_idx
].iov_base
;
148 uint64_t mid
= BVAL(inhdr
, SMB2_HDR_MESSAGE_ID
);
149 struct smbd_smb2_lock_state
*state
;
151 DEBUG(10,("smbd_smb2_request_lock_done: cancelled mid %llu\n",
152 (unsigned long long)mid
));
154 state
= tevent_req_data(smb2req
->subreq
,
155 struct smbd_smb2_lock_state
);
158 SMB_ASSERT(state
->blr
);
160 remove_pending_lock(state
, state
->blr
);
162 error
= smbd_smb2_request_error(smb2req
, NT_STATUS_CANCELLED
);
163 if (!NT_STATUS_IS_OK(error
)) {
164 smbd_server_connection_terminate(smb2req
->sconn
,
171 status
= smbd_smb2_lock_recv(subreq
);
173 if (!NT_STATUS_IS_OK(status
)) {
174 error
= smbd_smb2_request_error(smb2req
, status
);
175 if (!NT_STATUS_IS_OK(error
)) {
176 smbd_server_connection_terminate(smb2req
->sconn
,
183 outbody
= data_blob_talloc(smb2req
->out
.vector
, NULL
, 0x04);
184 if (outbody
.data
== NULL
) {
185 error
= smbd_smb2_request_error(smb2req
, NT_STATUS_NO_MEMORY
);
186 if (!NT_STATUS_IS_OK(error
)) {
187 smbd_server_connection_terminate(smb2req
->sconn
,
194 SSVAL(outbody
.data
, 0x00, 0x04); /* struct size */
195 SSVAL(outbody
.data
, 0x02, 0); /* reserved */
197 error
= smbd_smb2_request_done(smb2req
, outbody
, NULL
);
198 if (!NT_STATUS_IS_OK(error
)) {
199 smbd_server_connection_terminate(smb2req
->sconn
,
205 static struct tevent_req
*smbd_smb2_lock_send(TALLOC_CTX
*mem_ctx
,
206 struct tevent_context
*ev
,
207 struct smbd_smb2_request
*smb2req
,
208 struct files_struct
*fsp
,
210 uint16_t in_lock_count
,
211 struct smbd_smb2_lock_element
*in_locks
)
213 struct tevent_req
*req
;
214 struct smbd_smb2_lock_state
*state
;
215 struct smb_request
*smb1req
;
216 int32_t timeout
= -1;
217 bool isunlock
= false;
219 struct smbd_lock_element
*locks
;
223 req
= tevent_req_create(mem_ctx
, &state
,
224 struct smbd_smb2_lock_state
);
228 state
->smb2req
= smb2req
;
229 smb2req
->subreq
= req
; /* So we can find this when going async. */
231 smb1req
= smbd_smb2_fake_smb_request(smb2req
);
232 if (tevent_req_nomem(smb1req
, req
)) {
233 return tevent_req_post(req
, ev
);
235 state
->smb1req
= smb1req
;
237 DEBUG(10,("smbd_smb2_lock_send: %s - fnum[%d]\n",
238 fsp_str_dbg(fsp
), fsp
->fnum
));
240 locks
= talloc_array(state
, struct smbd_lock_element
, in_lock_count
);
242 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
243 return tevent_req_post(req
, ev
);
246 switch (in_locks
[0].flags
) {
247 case SMB2_LOCK_FLAG_SHARED
:
248 case SMB2_LOCK_FLAG_EXCLUSIVE
:
249 if (in_lock_count
> 1) {
250 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
251 return tevent_req_post(req
, ev
);
256 case SMB2_LOCK_FLAG_SHARED
|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
:
257 case SMB2_LOCK_FLAG_EXCLUSIVE
|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
:
261 case SMB2_LOCK_FLAG_UNLOCK
:
262 /* only the first lock gives the UNLOCK bit - see
269 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
270 return tevent_req_post(req
, ev
);
273 for (i
=0; i
<in_lock_count
; i
++) {
274 bool invalid
= false;
276 switch (in_locks
[i
].flags
) {
277 case SMB2_LOCK_FLAG_SHARED
:
278 case SMB2_LOCK_FLAG_EXCLUSIVE
:
284 tevent_req_nterror(req
,
285 NT_STATUS_INVALID_PARAMETER
);
286 return tevent_req_post(req
, ev
);
290 case SMB2_LOCK_FLAG_SHARED
|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
:
291 case SMB2_LOCK_FLAG_EXCLUSIVE
|SMB2_LOCK_FLAG_FAIL_IMMEDIATELY
:
297 case SMB2_LOCK_FLAG_UNLOCK
:
299 tevent_req_nterror(req
,
300 NT_STATUS_INVALID_PARAMETER
);
301 return tevent_req_post(req
, ev
);
308 * is the first element was a UNLOCK
309 * we need to deferr the error response
310 * to the backend, because we need to process
311 * all unlock elements before
316 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
317 return tevent_req_post(req
, ev
);
320 locks
[i
].smblctx
= fsp
->fnum
;
321 locks
[i
].offset
= in_locks
[i
].offset
;
322 locks
[i
].count
= in_locks
[i
].length
;
324 if (in_locks
[i
].flags
& SMB2_LOCK_FLAG_EXCLUSIVE
) {
325 locks
[i
].brltype
= WRITE_LOCK
;
326 } else if (in_locks
[i
].flags
& SMB2_LOCK_FLAG_SHARED
) {
327 locks
[i
].brltype
= READ_LOCK
;
328 } else if (invalid
) {
330 * this is an invalid UNLOCK element
331 * and the backend needs to test for
332 * brltype != UNLOCK_LOCK and return
333 * NT_STATUS_INVALID_PARAMER
335 locks
[i
].brltype
= READ_LOCK
;
337 locks
[i
].brltype
= UNLOCK_LOCK
;
340 DEBUG(10,("smbd_smb2_lock_send: index %d offset=%llu, count=%llu, "
341 "smblctx = %llu type %d\n",
343 (unsigned long long)locks
[i
].offset
,
344 (unsigned long long)locks
[i
].count
,
345 (unsigned long long)locks
[i
].smblctx
,
346 (int)locks
[i
].brltype
));
349 state
->locks
= locks
;
350 state
->lock_count
= in_lock_count
;
353 status
= smbd_do_locking(smb1req
, fsp
,
362 status
= smbd_do_locking(smb1req
, fsp
,
371 if (!NT_STATUS_IS_OK(status
)) {
372 if (NT_STATUS_EQUAL(status
, NT_STATUS_FILE_LOCK_CONFLICT
)) {
373 status
= NT_STATUS_LOCK_NOT_GRANTED
;
375 tevent_req_nterror(req
, status
);
376 return tevent_req_post(req
, ev
);
383 tevent_req_done(req
);
384 return tevent_req_post(req
, ev
);
387 static NTSTATUS
smbd_smb2_lock_recv(struct tevent_req
*req
)
391 if (tevent_req_is_nterror(req
, &status
)) {
392 tevent_req_received(req
);
396 tevent_req_received(req
);
400 /****************************************************************
401 Cancel an outstanding blocking lock request.
402 *****************************************************************/
404 static bool smbd_smb2_lock_cancel(struct tevent_req
*req
)
406 struct smbd_smb2_request
*smb2req
= NULL
;
407 struct smbd_smb2_lock_state
*state
= tevent_req_data(req
,
408 struct smbd_smb2_lock_state
);
413 if (!state
->smb2req
) {
417 smb2req
= state
->smb2req
;
418 smb2req
->cancelled
= true;
420 tevent_req_done(req
);
424 /****************************************************************
425 Got a message saying someone unlocked a file. Re-schedule all
426 blocking lock requests as we don't know if anything overlapped.
427 *****************************************************************/
429 static void received_unlock_msg(struct messaging_context
*msg
,
432 struct server_id server_id
,
435 struct smbd_server_connection
*sconn
=
436 talloc_get_type_abort(private_data
,
437 struct smbd_server_connection
);
439 DEBUG(10,("received_unlock_msg (SMB2)\n"));
441 process_blocking_lock_queue_smb2(sconn
, timeval_current());
444 /****************************************************************
445 Function to get the blr on a pending record.
446 *****************************************************************/
448 struct blocking_lock_record
*get_pending_smb2req_blr(struct smbd_smb2_request
*smb2req
)
450 struct smbd_smb2_lock_state
*state
= NULL
;
451 const uint8_t *inhdr
;
456 if (smb2req
->subreq
== NULL
) {
459 if (!tevent_req_is_in_progress(smb2req
->subreq
)) {
462 inhdr
= (const uint8_t *)smb2req
->in
.vector
[smb2req
->current_idx
].iov_base
;
463 if (SVAL(inhdr
, SMB2_HDR_OPCODE
) != SMB2_OP_LOCK
) {
466 state
= tevent_req_data(smb2req
->subreq
,
467 struct smbd_smb2_lock_state
);
473 /****************************************************************
474 Set up the next brl timeout.
475 *****************************************************************/
477 static bool recalc_smb2_brl_timeout(struct smbd_server_connection
*sconn
)
479 struct smbd_smb2_request
*smb2req
;
480 struct timeval next_timeout
= timeval_zero();
481 int max_brl_timeout
= lp_parm_int(-1, "brl", "recalctime", 5);
483 TALLOC_FREE(sconn
->smb2
.locks
.brl_timeout
);
485 for (smb2req
= sconn
->smb2
.requests
; smb2req
; smb2req
= smb2req
->next
) {
486 struct blocking_lock_record
*blr
=
487 get_pending_smb2req_blr(smb2req
);
491 if (timeval_is_zero(&blr
->expire_time
)) {
493 * If we're blocked on pid 0xFFFFFFFFFFFFFFFFLL this is
494 * a POSIX lock, so calculate a timeout of
495 * 10 seconds into the future.
497 if (blr
->blocking_smblctx
== 0xFFFFFFFFFFFFFFFFLL
) {
498 struct timeval psx_to
= timeval_current_ofs(10, 0);
499 next_timeout
= timeval_brl_min(&next_timeout
, &psx_to
);
505 next_timeout
= timeval_brl_min(&next_timeout
, &blr
->expire_time
);
508 if (timeval_is_zero(&next_timeout
)) {
509 DEBUG(10, ("recalc_smb2_brl_timeout:Next "
510 "timeout = Infinite.\n"));
515 * To account for unclean shutdowns by clients we need a
516 * maximum timeout that we use for checking pending locks. If
517 * we have any pending locks at all, then check if the pending
518 * lock can continue at least every brl:recalctime seconds
519 * (default 5 seconds).
521 * This saves us needing to do a message_send_all() in the
522 * SIGCHLD handler in the parent daemon. That
523 * message_send_all() caused O(n^2) work to be done when IP
524 * failovers happened in clustered Samba, which could make the
525 * entire system unusable for many minutes.
528 if (max_brl_timeout
> 0) {
529 struct timeval min_to
= timeval_current_ofs(max_brl_timeout
, 0);
530 next_timeout
= timeval_brl_min(&next_timeout
, &min_to
);
534 struct timeval cur
, from_now
;
536 cur
= timeval_current();
537 from_now
= timeval_until(&cur
, &next_timeout
);
538 DEBUG(10, ("recalc_smb2_brl_timeout: Next "
539 "timeout = %d.%d seconds from now.\n",
540 (int)from_now
.tv_sec
, (int)from_now
.tv_usec
));
543 sconn
->smb2
.locks
.brl_timeout
= tevent_add_timer(
549 if (!sconn
->smb2
.locks
.brl_timeout
) {
555 /****************************************************************
556 Get an SMB2 lock reqeust to go async. lock_timeout should
558 *****************************************************************/
560 bool push_blocking_lock_request_smb2( struct byte_range_lock
*br_lck
,
561 struct smb_request
*smb1req
,
566 enum brl_type lock_type
,
567 enum brl_flavour lock_flav
,
570 uint64_t blocking_smblctx
)
572 struct smbd_server_connection
*sconn
= smb1req
->sconn
;
573 struct smbd_smb2_request
*smb2req
= smb1req
->smb2req
;
574 struct tevent_req
*req
= NULL
;
575 struct smbd_smb2_lock_state
*state
= NULL
;
576 struct blocking_lock_record
*blr
= NULL
;
577 NTSTATUS status
= NT_STATUS_OK
;
582 req
= smb2req
->subreq
;
586 if (!tevent_req_is_in_progress(smb2req
->subreq
)) {
589 state
= tevent_req_data(req
, struct smbd_smb2_lock_state
);
594 blr
= talloc_zero(state
, struct blocking_lock_record
);
600 if (lock_timeout
== -1) {
601 blr
->expire_time
.tv_sec
= 0;
602 blr
->expire_time
.tv_usec
= 0; /* Never expire. */
604 blr
->expire_time
= timeval_current_ofs_msec(lock_timeout
);
607 blr
->lock_num
= lock_num
;
608 blr
->smblctx
= smblctx
;
609 blr
->blocking_smblctx
= blocking_smblctx
;
610 blr
->lock_flav
= lock_flav
;
611 blr
->lock_type
= lock_type
;
612 blr
->offset
= offset
;
615 /* Specific brl_lock() implementations can fill this in. */
616 blr
->blr_private
= NULL
;
618 /* Add a pending lock record for this. */
619 status
= brl_lock(sconn
->msg_ctx
,
622 messaging_server_id(sconn
->msg_ctx
),
625 lock_type
== READ_LOCK
? PENDING_READ_LOCK
: PENDING_WRITE_LOCK
,
631 if (!NT_STATUS_IS_OK(status
)) {
632 DEBUG(0,("push_blocking_lock_request_smb2: "
633 "failed to add PENDING_LOCK record.\n"));
639 DEBUG(10,("push_blocking_lock_request_smb2: file %s timeout %d\n",
643 recalc_smb2_brl_timeout(sconn
);
645 /* Ensure we'll receive messages when this is unlocked. */
646 if (!sconn
->smb2
.locks
.blocking_lock_unlock_state
) {
647 messaging_register(sconn
->msg_ctx
, sconn
,
648 MSG_SMB_UNLOCK
, received_unlock_msg
);
649 sconn
->smb2
.locks
.blocking_lock_unlock_state
= true;
652 /* allow this request to be canceled */
653 tevent_req_set_cancel_fn(req
, smbd_smb2_lock_cancel
);
658 /****************************************************************
659 Remove a pending lock record under lock.
660 *****************************************************************/
662 static void remove_pending_lock(struct smbd_smb2_lock_state
*state
,
663 struct blocking_lock_record
*blr
)
666 struct byte_range_lock
*br_lck
= brl_get_locks(
669 DEBUG(10, ("remove_pending_lock: BLR = %p\n", blr
));
672 brl_lock_cancel(br_lck
,
674 messaging_server_id(blr
->fsp
->conn
->sconn
->msg_ctx
),
682 /* Remove the locks we already got. */
684 for(i
= blr
->lock_num
- 1; i
>= 0; i
--) {
685 struct smbd_lock_element
*e
= &state
->locks
[i
];
687 do_unlock(blr
->fsp
->conn
->sconn
->msg_ctx
,
696 /****************************************************************
697 Re-proccess a blocking lock request.
698 This is equivalent to process_lockingX() inside smbd/blocking.c
699 *****************************************************************/
701 static void reprocess_blocked_smb2_lock(struct smbd_smb2_request
*smb2req
,
702 struct timeval tv_curr
)
704 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
705 struct blocking_lock_record
*blr
= NULL
;
706 struct smbd_smb2_lock_state
*state
= NULL
;
707 files_struct
*fsp
= NULL
;
709 if (!smb2req
->subreq
) {
712 state
= tevent_req_data(smb2req
->subreq
, struct smbd_smb2_lock_state
);
720 /* Try and finish off getting all the outstanding locks. */
722 for (; blr
->lock_num
< state
->lock_count
; blr
->lock_num
++) {
723 struct byte_range_lock
*br_lck
= NULL
;
724 struct smbd_lock_element
*e
= &state
->locks
[blr
->lock_num
];
726 br_lck
= do_lock(fsp
->conn
->sconn
->msg_ctx
,
735 &blr
->blocking_smblctx
,
740 if (NT_STATUS_IS_ERR(status
)) {
745 if(blr
->lock_num
== state
->lock_count
) {
747 * Success - we got all the locks.
750 DEBUG(3,("reprocess_blocked_smb2_lock SUCCESS file = %s, "
751 "fnum=%d num_locks=%d\n",
754 (int)state
->lock_count
));
756 tevent_req_done(smb2req
->subreq
);
760 if (!NT_STATUS_EQUAL(status
,NT_STATUS_LOCK_NOT_GRANTED
) &&
761 !NT_STATUS_EQUAL(status
,NT_STATUS_FILE_LOCK_CONFLICT
)) {
763 * We have other than a "can't get lock"
764 * error. Return an error.
766 remove_pending_lock(state
, blr
);
767 tevent_req_nterror(smb2req
->subreq
, status
);
772 * We couldn't get the locks for this record on the list.
773 * If the time has expired, return a lock error.
776 if (!timeval_is_zero(&blr
->expire_time
) &&
777 timeval_compare(&blr
->expire_time
, &tv_curr
) <= 0) {
778 remove_pending_lock(state
, blr
);
779 tevent_req_nterror(smb2req
->subreq
, NT_STATUS_LOCK_NOT_GRANTED
);
784 * Still can't get all the locks - keep waiting.
787 DEBUG(10,("reprocess_blocked_smb2_lock: only got %d locks of %d needed "
788 "for file %s, fnum = %d. Still waiting....\n",
790 (int)state
->lock_count
,
798 /****************************************************************
799 Attempt to proccess all outstanding blocking locks pending on
801 *****************************************************************/
803 void process_blocking_lock_queue_smb2(
804 struct smbd_server_connection
*sconn
, struct timeval tv_curr
)
806 struct smbd_smb2_request
*smb2req
, *nextreq
;
808 for (smb2req
= sconn
->smb2
.requests
; smb2req
; smb2req
= nextreq
) {
809 const uint8_t *inhdr
;
811 nextreq
= smb2req
->next
;
813 if (smb2req
->subreq
== NULL
) {
814 /* This message has been processed. */
817 if (!tevent_req_is_in_progress(smb2req
->subreq
)) {
818 /* This message has been processed. */
822 inhdr
= (const uint8_t *)smb2req
->in
.vector
[smb2req
->current_idx
].iov_base
;
823 if (SVAL(inhdr
, SMB2_HDR_OPCODE
) == SMB2_OP_LOCK
) {
824 reprocess_blocked_smb2_lock(smb2req
, tv_curr
);
828 recalc_smb2_brl_timeout(sconn
);
831 /****************************************************************************
832 Remove any locks on this fd. Called from file_close().
833 ****************************************************************************/
835 void cancel_pending_lock_requests_by_fid_smb2(files_struct
*fsp
,
836 struct byte_range_lock
*br_lck
,
837 enum file_close_type close_type
)
839 struct smbd_server_connection
*sconn
= fsp
->conn
->sconn
;
840 struct smbd_smb2_request
*smb2req
, *nextreq
;
842 for (smb2req
= sconn
->smb2
.requests
; smb2req
; smb2req
= nextreq
) {
843 struct smbd_smb2_lock_state
*state
= NULL
;
844 files_struct
*fsp_curr
= NULL
;
845 int i
= smb2req
->current_idx
;
846 struct blocking_lock_record
*blr
= NULL
;
847 const uint8_t *inhdr
;
849 nextreq
= smb2req
->next
;
851 if (smb2req
->subreq
== NULL
) {
852 /* This message has been processed. */
855 if (!tevent_req_is_in_progress(smb2req
->subreq
)) {
856 /* This message has been processed. */
860 inhdr
= (const uint8_t *)smb2req
->in
.vector
[i
].iov_base
;
861 if (SVAL(inhdr
, SMB2_HDR_OPCODE
) != SMB2_OP_LOCK
) {
862 /* Not a lock call. */
866 state
= tevent_req_data(smb2req
->subreq
,
867 struct smbd_smb2_lock_state
);
869 /* Strange - is this even possible ? */
873 fsp_curr
= smb2req
->compat_chain_fsp
;
874 if (fsp_curr
== NULL
) {
875 /* Strange - is this even possible ? */
879 if (fsp_curr
!= fsp
) {
880 /* It's not our fid */
886 /* Remove the entries from the lock db. */
887 brl_lock_cancel(br_lck
,
889 messaging_server_id(sconn
->msg_ctx
),
895 /* Finally end the request. */
896 if (close_type
== SHUTDOWN_CLOSE
) {
897 tevent_req_done(smb2req
->subreq
);
899 tevent_req_nterror(smb2req
->subreq
,
900 NT_STATUS_RANGE_NOT_LOCKED
);