r17915: Saturn fixes
[Samba/gbeck.git] / source / smbd / blocking.c
bloba8db498ef5a2aaa64871d0098c18aca3277eb2f5
1 /*
2 Unix SMB/CIFS implementation.
3 Blocking Locking functions
4 Copyright (C) Jeremy Allison 1998-2003
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
23 /****************************************************************************
24 This is the structure to queue to implement blocking locks.
25 notify. It consists of the requesting SMB and the expiry time.
26 *****************************************************************************/
28 typedef struct _blocking_lock_record {
29 struct _blocking_lock_record *next;
30 struct _blocking_lock_record *prev;
31 int com_type;
32 files_struct *fsp;
33 time_t expire_time;
34 int lock_num;
35 SMB_BIG_UINT offset;
36 SMB_BIG_UINT count;
37 uint16 lock_pid;
38 enum brl_flavour lock_flav;
39 enum brl_type lock_type;
40 char *inbuf;
41 int length;
42 } blocking_lock_record;
44 static blocking_lock_record *blocking_lock_queue;
46 /****************************************************************************
47 Destructor for the above structure.
48 ****************************************************************************/
50 static void free_blocking_lock_record(blocking_lock_record *blr)
52 DLIST_REMOVE(blocking_lock_queue, blr);
53 SAFE_FREE(blr->inbuf);
54 SAFE_FREE(blr);
57 /****************************************************************************
58 Determine if this is a secondary element of a chained SMB.
59 **************************************************************************/
61 static BOOL in_chained_smb(void)
63 return (chain_size != 0);
66 static void received_unlock_msg(int msg_type, struct process_id src,
67 void *buf, size_t len);
69 /****************************************************************************
70 Function to push a blocking lock request onto the lock queue.
71 ****************************************************************************/
73 BOOL push_blocking_lock_request( char *inbuf, int length,
74 files_struct *fsp,
75 int lock_timeout,
76 int lock_num,
77 uint16 lock_pid,
78 enum brl_type lock_type,
79 enum brl_flavour lock_flav,
80 SMB_BIG_UINT offset, SMB_BIG_UINT count)
82 static BOOL set_lock_msg;
83 blocking_lock_record *blr, *tmp;
84 BOOL my_lock_ctx = False;
85 struct byte_range_lock *br_lck = NULL;
86 NTSTATUS status;
88 if(in_chained_smb() ) {
89 DEBUG(0,("push_blocking_lock_request: cannot queue a chained request (currently).\n"));
90 return False;
94 * Now queue an entry on the blocking lock queue. We setup
95 * the expiration time here.
98 if((blr = SMB_MALLOC_P(blocking_lock_record)) == NULL) {
99 DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
100 return False;
103 blr->next = NULL;
104 blr->prev = NULL;
106 if((blr->inbuf = (char *)SMB_MALLOC(length)) == NULL) {
107 DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
108 SAFE_FREE(blr);
109 return False;
112 blr->com_type = CVAL(inbuf,smb_com);
113 blr->fsp = fsp;
114 blr->expire_time = (lock_timeout == -1) ? (time_t)-1 : time(NULL) + (time_t)lock_timeout;
115 blr->lock_num = lock_num;
116 blr->lock_pid = lock_pid;
117 blr->lock_flav = lock_flav;
118 blr->lock_type = lock_type;
119 blr->offset = offset;
120 blr->count = count;
121 memcpy(blr->inbuf, inbuf, length);
122 blr->length = length;
124 br_lck = brl_get_locks(blr->fsp);
125 if (!br_lck) {
126 free_blocking_lock_record(blr);
127 return False;
130 /* Add a pending lock record for this. */
131 status = brl_lock(br_lck,
132 lock_pid,
133 procid_self(),
134 offset,
135 count,
136 PENDING_LOCK,
137 blr->lock_flav,
138 &my_lock_ctx);
139 byte_range_lock_destructor(br_lck);
141 if (!NT_STATUS_IS_OK(status)) {
142 DEBUG(0,("push_blocking_lock_request: failed to add PENDING_LOCK record.\n"));
143 free_blocking_lock_record(blr);
144 return False;
147 DLIST_ADD_END(blocking_lock_queue, blr, tmp);
149 /* Ensure we'll receive messages when this is unlocked. */
150 if (!set_lock_msg) {
151 message_register(MSG_SMB_UNLOCK, received_unlock_msg);
152 set_lock_msg = True;
155 DEBUG(3,("push_blocking_lock_request: lock request length=%d blocked with expiry time %d (+%d) \
156 for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout,
157 blr->fsp->fnum, blr->fsp->fsp_name ));
159 /* Push the MID of this packet on the signing queue. */
160 srv_defer_sign_response(SVAL(inbuf,smb_mid));
162 return True;
165 /****************************************************************************
166 Return a smd with a given size.
167 *****************************************************************************/
169 static void send_blocking_reply(char *outbuf, int outsize)
171 if(outsize > 4)
172 smb_setlen(outbuf,outsize - 4);
174 if (!send_smb(smbd_server_fd(),outbuf))
175 exit_server("send_blocking_reply: send_smb failed.");
178 /****************************************************************************
179 Return a lockingX success SMB.
180 *****************************************************************************/
182 static void reply_lockingX_success(blocking_lock_record *blr)
184 char *outbuf = get_OutBuffer();
185 int bufsize = BUFFER_SIZE;
186 char *inbuf = blr->inbuf;
187 int outsize = 0;
189 construct_reply_common(inbuf, outbuf);
190 set_message(outbuf,2,0,True);
193 * As this message is a lockingX call we must handle
194 * any following chained message correctly.
195 * This is normally handled in construct_reply(),
196 * but as that calls switch_message, we can't use
197 * that here and must set up the chain info manually.
200 outsize = chain_reply(inbuf,outbuf,blr->length,bufsize);
202 outsize += chain_size;
204 send_blocking_reply(outbuf,outsize);
207 /****************************************************************************
208 Return a generic lock fail error blocking call.
209 *****************************************************************************/
211 static void generic_blocking_lock_error(blocking_lock_record *blr, NTSTATUS status)
213 char *outbuf = get_OutBuffer();
214 char *inbuf = blr->inbuf;
215 construct_reply_common(inbuf, outbuf);
217 /* whenever a timeout is given w2k maps LOCK_NOT_GRANTED to
218 FILE_LOCK_CONFLICT! (tridge) */
219 if (NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED)) {
220 status = NT_STATUS_FILE_LOCK_CONFLICT;
223 ERROR_NT(status);
224 if (!send_smb(smbd_server_fd(),outbuf))
225 exit_server("generic_blocking_lock_error: send_smb failed.");
228 /****************************************************************************
229 Return a lock fail error for a lockingX call. Undo all the locks we have
230 obtained first.
231 *****************************************************************************/
233 static void reply_lockingX_error(blocking_lock_record *blr, NTSTATUS status)
235 char *inbuf = blr->inbuf;
236 files_struct *fsp = blr->fsp;
237 uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
238 SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0;
239 uint16 lock_pid;
240 unsigned char locktype = CVAL(inbuf,smb_vwv3);
241 BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
242 char *data;
243 int i;
245 data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks);
248 * Data now points at the beginning of the list
249 * of smb_lkrng structs.
253 * Ensure we don't do a remove on the lock that just failed,
254 * as under POSIX rules, if we have a lock already there, we
255 * will delete it (and we shouldn't) .....
258 for(i = blr->lock_num - 1; i >= 0; i--) {
259 BOOL err;
261 lock_pid = get_lock_pid( data, i, large_file_format);
262 count = get_lock_count( data, i, large_file_format);
263 offset = get_lock_offset( data, i, large_file_format, &err);
266 * We know err cannot be set as if it was the lock
267 * request would never have been queued. JRA.
270 do_unlock(fsp,
271 lock_pid,
272 count,
273 offset,
274 WINDOWS_LOCK);
277 generic_blocking_lock_error(blr, status);
280 /****************************************************************************
281 Return a lock fail error.
282 *****************************************************************************/
284 static void blocking_lock_reply_error(blocking_lock_record *blr, NTSTATUS status)
286 switch(blr->com_type) {
287 #if 0
288 /* We no longer push blocking lock requests for anything but lockingX and trans2. */
289 case SMBlock:
290 case SMBlockread:
291 generic_blocking_lock_error(blr, status);
292 break;
293 #endif
294 case SMBlockingX:
295 reply_lockingX_error(blr, status);
296 break;
297 case SMBtrans2:
298 case SMBtranss2:
300 char *outbuf = get_OutBuffer();
301 char *inbuf = blr->inbuf;
302 construct_reply_common(inbuf, outbuf);
303 /* construct_reply_common has done us the favor to pre-fill the
304 * command field with SMBtranss2 which is wrong :-)
306 SCVAL(outbuf,smb_com,SMBtrans2);
307 ERROR_NT(status);
308 if (!send_smb(smbd_server_fd(),outbuf)) {
309 exit_server("blocking_lock_reply_error: send_smb failed.");
311 break;
313 default:
314 DEBUG(0,("blocking_lock_reply_error: PANIC - unknown type on blocking lock queue - exiting.!\n"));
315 exit_server("PANIC - unknown type on blocking lock queue");
319 #if 0
320 /* We no longer push blocking lock requests for anything but lockingX and trans2. */
322 /****************************************************************************
323 Attempt to finish off getting all pending blocking locks for a lockread call.
324 Returns True if we want to be removed from the list.
325 *****************************************************************************/
327 static BOOL process_lockread(blocking_lock_record *blr)
329 char *outbuf = get_OutBuffer();
330 char *inbuf = blr->inbuf;
331 ssize_t nread = -1;
332 char *data, *p;
333 int outsize = 0;
334 SMB_BIG_UINT startpos;
335 size_t numtoread;
336 NTSTATUS status;
337 files_struct *fsp = blr->fsp;
338 BOOL my_lock_ctx = False;
340 numtoread = SVAL(inbuf,smb_vwv1);
341 startpos = (SMB_BIG_UINT)IVAL(inbuf,smb_vwv2);
343 numtoread = MIN(BUFFER_SIZE-outsize,numtoread);
344 data = smb_buf(outbuf) + 3;
346 status = do_lock_spin(fsp,
347 SVAL(inbuf,smb_pid),
348 (SMB_BIG_UINT)numtoread,
349 startpos,
350 READ_LOCK,
351 WINDOWS_LOCK,
352 &my_lock_ctx);
354 if (NT_STATUS_V(status)) {
355 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
356 !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
358 * We have other than a "can't get lock"
359 * error. Send an error.
360 * Return True so we get dequeued.
362 generic_blocking_lock_error(blr, status);
363 return True;
367 * Still waiting for lock....
370 DEBUG(10,("process_lockread: failed to get lock for file = %s. Still waiting....\n",
371 fsp->fsp_name));
372 return False;
375 nread = read_file(fsp,data,startpos,numtoread);
377 if (nread < 0) {
378 generic_blocking_lock_error(blr,NT_STATUS_ACCESS_DENIED);
379 return True;
382 construct_reply_common(inbuf, outbuf);
383 outsize = set_message(outbuf,5,0,True);
385 outsize += nread;
386 SSVAL(outbuf,smb_vwv0,nread);
387 SSVAL(outbuf,smb_vwv5,nread+3);
388 p = smb_buf(outbuf);
389 *p++ = 1;
390 SSVAL(p,0,nread); p += 2;
391 set_message_end(outbuf, p+nread);
393 DEBUG(3, ( "process_lockread file = %s, fnum=%d num=%lu nread=%ld\n",
394 fsp->fsp_name, fsp->fnum, (unsigned long)numtoread, (long)nread ) );
396 send_blocking_reply(outbuf,outsize);
397 return True;
400 /****************************************************************************
401 Attempt to finish off getting all pending blocking locks for a lock call.
402 Returns True if we want to be removed from the list.
403 *****************************************************************************/
405 static BOOL process_lock(blocking_lock_record *blr)
407 char *outbuf = get_OutBuffer();
408 char *inbuf = blr->inbuf;
409 int outsize;
410 SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
411 NTSTATUS status;
412 files_struct *fsp = blr->fsp;
413 BOOL my_lock_ctx = False;
415 count = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv1);
416 offset = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3);
418 errno = 0;
419 status = do_lock_spin(fsp,
420 SVAL(inbuf,smb_pid),
421 count,
422 offset,
423 WRITE_LOCK,
424 WINDOWS_LOCK,
425 &my_lock_ctx);
427 if (NT_STATUS_IS_ERR(status)) {
428 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
429 !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
431 * We have other than a "can't get lock"
432 * error. Send an error.
433 * Return True so we get dequeued.
436 blocking_lock_reply_error(blr, status);
437 return True;
440 * Still can't get the lock - keep waiting.
442 DEBUG(10,("process_lock: failed to get lock for file = %s. Still waiting....\n",
443 fsp->fsp_name));
444 return False;
448 * Success - we got the lock.
451 DEBUG(3,("process_lock : file=%s fnum=%d offset=%.0f count=%.0f\n",
452 fsp->fsp_name, fsp->fnum, (double)offset, (double)count));
454 construct_reply_common(inbuf, outbuf);
455 outsize = set_message(outbuf,0,0,True);
456 send_blocking_reply(outbuf,outsize);
457 return True;
459 #endif
461 /****************************************************************************
462 Attempt to finish off getting all pending blocking locks for a lockingX call.
463 Returns True if we want to be removed from the list.
464 *****************************************************************************/
466 static BOOL process_lockingX(blocking_lock_record *blr)
468 char *inbuf = blr->inbuf;
469 unsigned char locktype = CVAL(inbuf,smb_vwv3);
470 files_struct *fsp = blr->fsp;
471 uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
472 uint16 num_locks = SVAL(inbuf,smb_vwv7);
473 SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
474 uint16 lock_pid;
475 BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
476 char *data;
477 BOOL my_lock_ctx = False;
478 NTSTATUS status = NT_STATUS_OK;
480 data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks);
483 * Data now points at the beginning of the list
484 * of smb_lkrng structs.
487 for(; blr->lock_num < num_locks; blr->lock_num++) {
488 BOOL err;
490 lock_pid = get_lock_pid( data, blr->lock_num, large_file_format);
491 count = get_lock_count( data, blr->lock_num, large_file_format);
492 offset = get_lock_offset( data, blr->lock_num, large_file_format, &err);
495 * We know err cannot be set as if it was the lock
496 * request would never have been queued. JRA.
498 errno = 0;
499 status = do_lock_spin(fsp,
500 lock_pid,
501 count,
502 offset,
503 ((locktype & 1) ? READ_LOCK : WRITE_LOCK),
504 WINDOWS_LOCK,
505 &my_lock_ctx);
507 if (NT_STATUS_IS_ERR(status)) {
508 break;
512 if(blr->lock_num == num_locks) {
514 * Success - we got all the locks.
517 DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n",
518 fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) );
520 reply_lockingX_success(blr);
521 return True;
522 } else if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
523 !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
525 * We have other than a "can't get lock"
526 * error. Free any locks we had and return an error.
527 * Return True so we get dequeued.
530 blocking_lock_reply_error(blr, status);
531 return True;
535 * Still can't get all the locks - keep waiting.
538 DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \
539 Waiting....\n",
540 blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum));
542 return False;
545 /****************************************************************************
546 Attempt to get the posix lock request from a SMBtrans2 call.
547 Returns True if we want to be removed from the list.
548 *****************************************************************************/
550 static BOOL process_trans2(blocking_lock_record *blr)
552 extern int max_send;
553 char *inbuf = blr->inbuf;
554 char *outbuf;
555 BOOL my_lock_ctx = False;
556 char params[2];
557 NTSTATUS status;
559 status = do_lock(blr->fsp,
560 blr->lock_pid,
561 blr->count,
562 blr->offset,
563 blr->lock_type,
564 blr->lock_flav,
565 &my_lock_ctx);
567 if (!NT_STATUS_IS_OK(status)) {
568 if (ERROR_WAS_LOCK_DENIED(status)) {
569 /* Still can't get the lock, just keep waiting. */
570 return False;
573 * We have other than a "can't get lock"
574 * error. Send an error and return True so we get dequeued.
576 blocking_lock_reply_error(blr, status);
577 return True;
580 /* We finally got the lock, return success. */
581 outbuf = get_OutBuffer();
582 construct_reply_common(inbuf, outbuf);
583 SCVAL(outbuf,smb_com,SMBtrans2);
584 SSVAL(params,0,0);
585 send_trans2_replies(outbuf, max_send, params, 2, NULL, 0);
586 return True;
590 /****************************************************************************
591 Process a blocking lock SMB.
592 Returns True if we want to be removed from the list.
593 *****************************************************************************/
595 static BOOL blocking_lock_record_process(blocking_lock_record *blr)
597 switch(blr->com_type) {
598 #if 0
599 /* We no longer push blocking lock requests for anything but lockingX and trans2. */
600 case SMBlock:
601 return process_lock(blr);
602 case SMBlockread:
603 return process_lockread(blr);
604 #endif
605 case SMBlockingX:
606 return process_lockingX(blr);
607 case SMBtrans2:
608 case SMBtranss2:
609 return process_trans2(blr);
610 default:
611 DEBUG(0,("blocking_lock_record_process: PANIC - unknown type on blocking lock queue - exiting.!\n"));
612 exit_server("PANIC - unknown type on blocking lock queue");
614 return False; /* Keep compiler happy. */
617 /****************************************************************************
618 Delete entries by fnum from the blocking lock pending queue.
619 *****************************************************************************/
621 void remove_pending_lock_requests_by_fid(files_struct *fsp)
623 blocking_lock_record *blr, *next = NULL;
625 for(blr = blocking_lock_queue; blr; blr = next) {
626 next = blr->next;
627 if(blr->fsp->fnum == fsp->fnum) {
628 struct byte_range_lock *br_lck = brl_get_locks(fsp);
630 if (br_lck) {
631 DEBUG(10,("remove_pending_lock_requests_by_fid - removing request type %d for \
632 file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum ));
634 brl_remove_pending_lock(br_lck,
635 blr->lock_pid,
636 procid_self(),
637 blr->offset,
638 blr->count,
639 blr->lock_flav);
640 byte_range_lock_destructor(br_lck);
644 free_blocking_lock_record(blr);
649 /****************************************************************************
650 Delete entries by mid from the blocking lock pending queue. Always send reply.
651 *****************************************************************************/
653 void remove_pending_lock_requests_by_mid(int mid)
655 blocking_lock_record *blr, *next = NULL;
657 for(blr = blocking_lock_queue; blr; blr = next) {
658 next = blr->next;
659 if(SVAL(blr->inbuf,smb_mid) == mid) {
660 files_struct *fsp = blr->fsp;
661 struct byte_range_lock *br_lck = brl_get_locks(fsp);
663 if (br_lck) {
664 DEBUG(10,("remove_pending_lock_requests_by_mid - removing request type %d for \
665 file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum ));
667 brl_remove_pending_lock(br_lck,
668 blr->lock_pid,
669 procid_self(),
670 blr->offset,
671 blr->count,
672 blr->lock_flav);
673 byte_range_lock_destructor(br_lck);
676 blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
677 free_blocking_lock_record(blr);
682 /****************************************************************************
683 Set a flag as an unlock request affects one of our pending locks.
684 *****************************************************************************/
686 static void received_unlock_msg(int msg_type, struct process_id src,
687 void *buf, size_t len)
689 DEBUG(10,("received_unlock_msg\n"));
690 process_blocking_lock_queue(time(NULL));
693 /****************************************************************************
694 Return the number of seconds to the next blocking locks timeout, or default_timeout
695 *****************************************************************************/
697 unsigned blocking_locks_timeout(unsigned default_timeout)
699 unsigned timeout = default_timeout;
700 time_t t;
701 blocking_lock_record *blr = blocking_lock_queue;
703 /* note that we avoid the time() syscall if there are no blocking locks */
704 if (!blr)
705 return timeout;
707 t = time(NULL);
709 for (; blr; blr = blr->next) {
710 if ((blr->expire_time != (time_t)-1) &&
711 (timeout > (blr->expire_time - t))) {
712 timeout = blr->expire_time - t;
716 if (timeout < 1)
717 timeout = 1;
719 return timeout;
722 /****************************************************************************
723 Process the blocking lock queue. Note that this is only called as root.
724 *****************************************************************************/
726 void process_blocking_lock_queue(time_t t)
728 blocking_lock_record *blr, *next = NULL;
731 * Go through the queue and see if we can get any of the locks.
734 for (blr = blocking_lock_queue; blr; blr = next) {
735 connection_struct *conn = NULL;
736 uint16 vuid;
737 files_struct *fsp = NULL;
739 next = blr->next;
742 * Ensure we don't have any old chain_fsp values
743 * sitting around....
745 chain_size = 0;
746 file_chain_reset();
747 fsp = blr->fsp;
749 conn = conn_find(SVAL(blr->inbuf,smb_tid));
750 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID :
751 SVAL(blr->inbuf,smb_uid);
753 DEBUG(5,("process_blocking_lock_queue: examining pending lock fnum = %d for file %s\n",
754 fsp->fnum, fsp->fsp_name ));
756 if((blr->expire_time != -1) && (blr->expire_time <= t)) {
757 struct byte_range_lock *br_lck = brl_get_locks(fsp);
760 * Lock expired - throw away all previously
761 * obtained locks and return lock error.
764 if (br_lck) {
765 DEBUG(5,("process_blocking_lock_queue: pending lock fnum = %d for file %s timed out.\n",
766 fsp->fnum, fsp->fsp_name ));
768 brl_remove_pending_lock(br_lck,
769 blr->lock_pid,
770 procid_self(),
771 blr->offset,
772 blr->count,
773 blr->lock_flav);
774 byte_range_lock_destructor(br_lck);
777 blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
778 free_blocking_lock_record(blr);
779 continue;
782 if(!change_to_user(conn,vuid)) {
783 struct byte_range_lock *br_lck = brl_get_locks(fsp);
786 * Remove the entry and return an error to the client.
789 if (br_lck) {
790 brl_remove_pending_lock(br_lck,
791 blr->lock_pid,
792 procid_self(),
793 blr->offset,
794 blr->count,
795 blr->lock_flav);
796 byte_range_lock_destructor(br_lck);
799 DEBUG(0,("process_blocking_lock_queue: Unable to become user vuid=%d.\n",
800 vuid ));
801 blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED);
802 free_blocking_lock_record(blr);
803 continue;
806 if(!set_current_service(conn,SVAL(blr->inbuf,smb_flg),True)) {
807 struct byte_range_lock *br_lck = brl_get_locks(fsp);
810 * Remove the entry and return an error to the client.
813 if (br_lck) {
814 brl_remove_pending_lock(br_lck,
815 blr->lock_pid,
816 procid_self(),
817 blr->offset,
818 blr->count,
819 blr->lock_flav);
820 byte_range_lock_destructor(br_lck);
823 DEBUG(0,("process_blocking_lock_queue: Unable to become service Error was %s.\n", strerror(errno) ));
824 blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED);
825 free_blocking_lock_record(blr);
826 change_to_root_user();
827 continue;
831 * Go through the remaining locks and try and obtain them.
832 * The call returns True if all locks were obtained successfully
833 * and False if we still need to wait.
836 if(blocking_lock_record_process(blr)) {
837 struct byte_range_lock *br_lck = brl_get_locks(fsp);
839 if (br_lck) {
840 brl_remove_pending_lock(br_lck,
841 blr->lock_pid,
842 procid_self(),
843 blr->offset,
844 blr->count,
845 blr->lock_flav);
846 byte_range_lock_destructor(br_lck);
849 free_blocking_lock_record(blr);
851 change_to_root_user();