sync 3.0 into HEAD for the last time
[vlendec/samba-autobuild/.git] / source3 / smbd / blocking.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Blocking Locking functions
4    Copyright (C) Jeremy Allison 1998-2003
5    
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.
10    
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.
15    
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.
19 */
20
21 #include "includes.h"
22
23 extern char *OutBuffer;
24
25 /****************************************************************************
26  This is the structure to queue to implement blocking locks.
27  notify. It consists of the requesting SMB and the expiry time.
28 *****************************************************************************/
29
30 typedef struct {
31         ubi_slNode msg_next;
32         int com_type;
33         files_struct *fsp;
34         time_t expire_time;
35         int lock_num;
36         SMB_BIG_UINT offset;
37         SMB_BIG_UINT count;
38         uint16 lock_pid;
39         char *inbuf;
40         int length;
41 } blocking_lock_record;
42
43 static ubi_slList blocking_lock_queue = { NULL, (ubi_slNodePtr)&blocking_lock_queue, 0};
44
45 /****************************************************************************
46  Destructor for the above structure.
47 ****************************************************************************/
48
49 static void free_blocking_lock_record(blocking_lock_record *blr)
50 {
51         SAFE_FREE(blr->inbuf);
52         SAFE_FREE(blr);
53 }
54
55 /****************************************************************************
56  Get the files_struct given a particular queued SMB.
57 *****************************************************************************/
58
59 static files_struct *get_fsp_from_pkt(char *inbuf)
60 {
61         switch(CVAL(inbuf,smb_com)) {
62                 case SMBlock:
63                 case SMBlockread:
64                         return file_fsp(inbuf,smb_vwv0);
65                 case SMBlockingX:
66                         return file_fsp(inbuf,smb_vwv2);
67                 default:
68                         DEBUG(0,("get_fsp_from_pkt: PANIC - unknown type on blocking lock queue - exiting.!\n"));
69                         exit_server("PANIC - unknown type on blocking lock queue");
70         }
71         return NULL; /* Keep compiler happy. */
72 }
73
74 /****************************************************************************
75  Determine if this is a secondary element of a chained SMB.
76   **************************************************************************/
77
78 static BOOL in_chained_smb(void)
79 {
80         return (chain_size != 0);
81 }
82
83 static void received_unlock_msg(int msg_type, pid_t src, void *buf, size_t len);
84
85 /****************************************************************************
86  Function to push a blocking lock request onto the lock queue.
87 ****************************************************************************/
88
89 BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout,
90                 int lock_num, uint16 lock_pid, SMB_BIG_UINT offset, SMB_BIG_UINT count)
91 {
92         static BOOL set_lock_msg;
93         blocking_lock_record *blr;
94         NTSTATUS status;
95
96         if(in_chained_smb() ) {
97                 DEBUG(0,("push_blocking_lock_request: cannot queue a chained request (currently).\n"));
98                 return False;
99         }
100
101         /*
102          * Now queue an entry on the blocking lock queue. We setup
103          * the expiration time here.
104          */
105
106         if((blr = (blocking_lock_record *)malloc(sizeof(blocking_lock_record))) == NULL) {
107                 DEBUG(0,("push_blocking_lock_request: Malloc fail !\n" ));
108                 return False;
109         }
110
111         if((blr->inbuf = (char *)malloc(length)) == NULL) {
112                 DEBUG(0,("push_blocking_lock_request: Malloc fail (2)!\n" ));
113                 SAFE_FREE(blr);
114                 return False;
115         }
116
117         blr->com_type = CVAL(inbuf,smb_com);
118         blr->fsp = get_fsp_from_pkt(inbuf);
119         blr->expire_time = (lock_timeout == -1) ? (time_t)-1 : time(NULL) + (time_t)lock_timeout;
120         blr->lock_num = lock_num;
121         blr->lock_pid = lock_pid;
122         blr->offset = offset;
123         blr->count = count;
124         memcpy(blr->inbuf, inbuf, length);
125         blr->length = length;
126
127         /* Add a pending lock record for this. */
128         status = brl_lock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum,
129                         lock_pid, sys_getpid(), blr->fsp->conn->cnum,
130                         offset, count, PENDING_LOCK);
131
132         if (!NT_STATUS_IS_OK(status)) {
133                 DEBUG(0,("push_blocking_lock_request: failed to add PENDING_LOCK record.\n"));
134                 free_blocking_lock_record(blr);
135                 return False;
136         }
137
138         ubi_slAddTail(&blocking_lock_queue, blr);
139
140         /* Ensure we'll receive messages when this is unlocked. */
141         if (!set_lock_msg) {
142                 message_register(MSG_SMB_UNLOCK, received_unlock_msg);
143                 set_lock_msg = True;
144         }
145
146         DEBUG(3,("push_blocking_lock_request: lock request length=%d blocked with expiry time %d (+%d) \
147 for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout,
148                 blr->fsp->fnum, blr->fsp->fsp_name ));
149
150         /* Push the MID of this packet on the signing queue. */
151         srv_defer_sign_response(SVAL(inbuf,smb_mid), True);
152
153         return True;
154 }
155
156 /****************************************************************************
157  Return a smd with a given size.
158 *****************************************************************************/
159
160 static void send_blocking_reply(char *outbuf, int outsize)
161 {
162         if(outsize > 4)
163                 smb_setlen(outbuf,outsize - 4);
164
165         if (!send_smb(smbd_server_fd(),outbuf))
166                 exit_server("send_blocking_reply: send_smb failed.");
167 }
168
169 /****************************************************************************
170  Return a lockingX success SMB.
171 *****************************************************************************/
172
173 static void reply_lockingX_success(blocking_lock_record *blr)
174 {
175         char *outbuf = OutBuffer;
176         int bufsize = BUFFER_SIZE;
177         char *inbuf = blr->inbuf;
178         int outsize = 0;
179
180         construct_reply_common(inbuf, outbuf);
181         set_message(outbuf,2,0,True);
182
183         /*
184          * As this message is a lockingX call we must handle
185          * any following chained message correctly.
186          * This is normally handled in construct_reply(),
187          * but as that calls switch_message, we can't use
188          * that here and must set up the chain info manually.
189          */
190
191         outsize = chain_reply(inbuf,outbuf,blr->length,bufsize);
192
193         outsize += chain_size;
194
195         send_blocking_reply(outbuf,outsize);
196 }
197
198 /****************************************************************************
199  Return a generic lock fail error blocking call.
200 *****************************************************************************/
201
202 static void generic_blocking_lock_error(blocking_lock_record *blr, NTSTATUS status)
203 {
204         char *outbuf = OutBuffer;
205         char *inbuf = blr->inbuf;
206         construct_reply_common(inbuf, outbuf);
207
208         /* whenever a timeout is given w2k maps LOCK_NOT_GRANTED to
209            FILE_LOCK_CONFLICT! (tridge) */
210         if (NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED)) {
211                 status = NT_STATUS_FILE_LOCK_CONFLICT;
212         }
213
214         ERROR_NT(status);
215         if (!send_smb(smbd_server_fd(),outbuf))
216                 exit_server("generic_blocking_lock_error: send_smb failed.");
217 }
218
219 /****************************************************************************
220  Return a lock fail error for a lockingX call. Undo all the locks we have 
221  obtained first.
222 *****************************************************************************/
223
224 static void reply_lockingX_error(blocking_lock_record *blr, NTSTATUS status)
225 {
226         char *inbuf = blr->inbuf;
227         files_struct *fsp = blr->fsp;
228         connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
229         uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
230         SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0;
231         uint16 lock_pid;
232         unsigned char locktype = CVAL(inbuf,smb_vwv3);
233         BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
234         char *data;
235         int i;
236
237         data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks);
238         
239         /* 
240          * Data now points at the beginning of the list
241          * of smb_lkrng structs.
242          */
243
244         /*
245          * Ensure we don't do a remove on the lock that just failed,
246          * as under POSIX rules, if we have a lock already there, we
247          * will delete it (and we shouldn't) .....
248          */
249         
250         for(i = blr->lock_num - 1; i >= 0; i--) {
251                 BOOL err;
252                 
253                 lock_pid = get_lock_pid( data, i, large_file_format);
254                 count = get_lock_count( data, i, large_file_format);
255                 offset = get_lock_offset( data, i, large_file_format, &err);
256                 
257                 /*
258                  * We know err cannot be set as if it was the lock
259                  * request would never have been queued. JRA.
260                  */
261                 
262                 do_unlock(fsp,conn,lock_pid,count,offset);
263         }
264         
265         generic_blocking_lock_error(blr, status);
266 }
267
268 /****************************************************************************
269  Return a lock fail error.
270 *****************************************************************************/
271
272 static void blocking_lock_reply_error(blocking_lock_record *blr, NTSTATUS status)
273 {
274         switch(blr->com_type) {
275         case SMBlock:
276         case SMBlockread:
277                 generic_blocking_lock_error(blr, status);
278                 break;
279         case SMBlockingX:
280                 reply_lockingX_error(blr, status);
281                 break;
282         default:
283                 DEBUG(0,("blocking_lock_reply_error: PANIC - unknown type on blocking lock queue - exiting.!\n"));
284                 exit_server("PANIC - unknown type on blocking lock queue");
285         }
286 }
287
288 /****************************************************************************
289  Attempt to finish off getting all pending blocking locks for a lockread call.
290  Returns True if we want to be removed from the list.
291 *****************************************************************************/
292
293 static BOOL process_lockread(blocking_lock_record *blr)
294 {
295         char *outbuf = OutBuffer;
296         char *inbuf = blr->inbuf;
297         ssize_t nread = -1;
298         char *data, *p;
299         int outsize = 0;
300         SMB_BIG_UINT startpos;
301         size_t numtoread;
302         NTSTATUS status;
303         connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
304         files_struct *fsp = blr->fsp;
305
306         numtoread = SVAL(inbuf,smb_vwv1);
307         startpos = (SMB_BIG_UINT)IVAL(inbuf,smb_vwv2);
308         
309         numtoread = MIN(BUFFER_SIZE-outsize,numtoread);
310         data = smb_buf(outbuf) + 3;
311  
312         status = do_lock_spin( fsp, conn, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)numtoread, 
313                           startpos, READ_LOCK);
314         if (NT_STATUS_V(status)) {
315                 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
316                         !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
317                         /*
318                          * We have other than a "can't get lock"
319                          * error. Send an error.
320                          * Return True so we get dequeued.
321                          */
322                         generic_blocking_lock_error(blr, status);
323                         return True;
324                 }
325
326                 /*
327                  * Still waiting for lock....
328                  */
329                 
330                 DEBUG(10,("process_lockread: failed to get lock for file = %s. Still waiting....\n",
331                           fsp->fsp_name));
332                 return False;
333         }
334
335         nread = read_file(fsp,data,startpos,numtoread);
336
337         if (nread < 0) {
338                 generic_blocking_lock_error(blr,NT_STATUS_ACCESS_DENIED);
339                 return True;
340         }
341         
342         construct_reply_common(inbuf, outbuf);
343         outsize = set_message(outbuf,5,0,True);
344         
345         outsize += nread;
346         SSVAL(outbuf,smb_vwv0,nread);
347         SSVAL(outbuf,smb_vwv5,nread+3);
348         p = smb_buf(outbuf);
349         *p++ = 1;
350         SSVAL(p,0,nread); p += 2;
351         set_message_end(outbuf, p+nread);
352         
353         DEBUG(3, ( "process_lockread file = %s, fnum=%d num=%d nread=%d\n",
354                    fsp->fsp_name, fsp->fnum, (int)numtoread, (int)nread ) );
355         
356         send_blocking_reply(outbuf,outsize);
357         return True;
358 }
359
360 /****************************************************************************
361  Attempt to finish off getting all pending blocking locks for a lock call.
362  Returns True if we want to be removed from the list.
363 *****************************************************************************/
364
365 static BOOL process_lock(blocking_lock_record *blr)
366 {
367         char *outbuf = OutBuffer;
368         char *inbuf = blr->inbuf;
369         int outsize;
370         SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
371         NTSTATUS status;
372         connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
373         files_struct *fsp = blr->fsp;
374
375         count = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv1);
376         offset = IVAL_TO_SMB_OFF_T(inbuf,smb_vwv3);
377
378         errno = 0;
379         status = do_lock_spin(fsp, conn, SVAL(inbuf,smb_pid), count, 
380                          offset, WRITE_LOCK);
381         if (NT_STATUS_IS_ERR(status)) {
382                 if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
383                         !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
384                         /*
385                          * We have other than a "can't get lock"
386                          * error. Send an error.
387                          * Return True so we get dequeued.
388                          */
389                         
390                         blocking_lock_reply_error(blr, status);
391                         return True;
392                 }
393                 /*
394                  * Still can't get the lock - keep waiting.
395                  */
396                 DEBUG(10,("process_lock: failed to get lock for file = %s. Still waiting....\n",
397                           fsp->fsp_name));
398                 return False;
399         }
400
401         /*
402          * Success - we got the lock.
403          */
404         
405         DEBUG(3,("process_lock : file=%s fnum=%d offset=%.0f count=%.0f\n",
406                  fsp->fsp_name, fsp->fnum, (double)offset, (double)count));
407         
408         construct_reply_common(inbuf, outbuf);
409         outsize = set_message(outbuf,0,0,True);
410         send_blocking_reply(outbuf,outsize);
411         return True;
412 }
413
414 /****************************************************************************
415  Attempt to finish off getting all pending blocking locks for a lockingX call.
416  Returns True if we want to be removed from the list.
417 *****************************************************************************/
418
419 static BOOL process_lockingX(blocking_lock_record *blr)
420 {
421         char *inbuf = blr->inbuf;
422         unsigned char locktype = CVAL(inbuf,smb_vwv3);
423         files_struct *fsp = blr->fsp;
424         connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
425         uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
426         uint16 num_locks = SVAL(inbuf,smb_vwv7);
427         SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
428         uint16 lock_pid;
429         BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
430         char *data;
431         NTSTATUS status = NT_STATUS_OK;
432
433         data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks);
434
435         /* 
436          * Data now points at the beginning of the list
437          * of smb_lkrng structs.
438          */
439         
440         for(; blr->lock_num < num_locks; blr->lock_num++) {
441                 BOOL err;
442
443                 lock_pid = get_lock_pid( data, blr->lock_num, large_file_format);
444                 count = get_lock_count( data, blr->lock_num, large_file_format);
445                 offset = get_lock_offset( data, blr->lock_num, large_file_format, &err);
446                 
447                 /*
448                  * We know err cannot be set as if it was the lock
449                  * request would never have been queued. JRA.
450                  */
451                 errno = 0;
452                 status = do_lock_spin(fsp,conn,lock_pid,count,offset, 
453                                  ((locktype & 1) ? READ_LOCK : WRITE_LOCK));
454                 if (NT_STATUS_IS_ERR(status)) break;
455         }
456
457         if(blr->lock_num == num_locks) {
458                 /*
459                  * Success - we got all the locks.
460                  */
461                 
462                 DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n",
463                          fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) );
464
465                 reply_lockingX_success(blr);
466                 return True;
467         } else if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) &&
468                         !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) {
469                         /*
470                          * We have other than a "can't get lock"
471                          * error. Free any locks we had and return an error.
472                          * Return True so we get dequeued.
473                          */
474                 
475                 blocking_lock_reply_error(blr, status);
476                 return True;
477         }
478
479         /*
480          * Still can't get all the locks - keep waiting.
481          */
482         
483         DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \
484 Waiting....\n", 
485                   blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum));
486         
487         return False;
488 }
489
490 /****************************************************************************
491  Process a blocking lock SMB.
492  Returns True if we want to be removed from the list.
493 *****************************************************************************/
494
495 static BOOL blocking_lock_record_process(blocking_lock_record *blr)
496 {
497         switch(blr->com_type) {
498                 case SMBlock:
499                         return process_lock(blr);
500                 case SMBlockread:
501                         return process_lockread(blr);
502                 case SMBlockingX:
503                         return process_lockingX(blr);
504                 default:
505                         DEBUG(0,("blocking_lock_record_process: PANIC - unknown type on blocking lock queue - exiting.!\n"));
506                         exit_server("PANIC - unknown type on blocking lock queue");
507         }
508         return False; /* Keep compiler happy. */
509 }
510
511 /****************************************************************************
512  Delete entries by fnum from the blocking lock pending queue.
513 *****************************************************************************/
514
515 void remove_pending_lock_requests_by_fid(files_struct *fsp)
516 {
517         blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst( &blocking_lock_queue );
518         blocking_lock_record *prev = NULL;
519
520         while(blr != NULL) {
521                 if(blr->fsp->fnum == fsp->fnum) {
522
523                         DEBUG(10,("remove_pending_lock_requests_by_fid - removing request type %d for \
524 file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum ));
525
526                         brl_unlock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum,
527                                 blr->lock_pid, sys_getpid(), blr->fsp->conn->cnum,
528                                 blr->offset, blr->count, True, NULL, NULL);
529
530                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
531                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
532                         continue;
533                 }
534
535                 prev = blr;
536                 blr = (blocking_lock_record *)ubi_slNext(blr);
537         }
538 }
539
540 /****************************************************************************
541  Delete entries by mid from the blocking lock pending queue. Always send reply.
542 *****************************************************************************/
543
544 void remove_pending_lock_requests_by_mid(int mid)
545 {
546         blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst( &blocking_lock_queue );
547         blocking_lock_record *prev = NULL;
548
549         while(blr != NULL) {
550                 if(SVAL(blr->inbuf,smb_mid) == mid) {
551                         files_struct *fsp = blr->fsp;
552
553                         DEBUG(10,("remove_pending_lock_requests_by_mid - removing request type %d for \
554 file %s fnum = %d\n", blr->com_type, fsp->fsp_name, fsp->fnum ));
555
556                         blocking_lock_reply_error(blr,NT_STATUS_CANCELLED);
557                         brl_unlock(blr->fsp->dev, blr->fsp->inode, blr->fsp->fnum,
558                                 blr->lock_pid, sys_getpid(), blr->fsp->conn->cnum,
559                                 blr->offset, blr->count, True, NULL, NULL);
560                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
561                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
562                         continue;
563                 }
564
565                 prev = blr;
566                 blr = (blocking_lock_record *)ubi_slNext(blr);
567         }
568 }
569
570 /****************************************************************************
571   Set a flag as an unlock request affects one of our pending locks.
572 *****************************************************************************/
573
574 static void received_unlock_msg(int msg_type, pid_t src, void *buf, size_t len)
575 {
576         DEBUG(10,("received_unlock_msg\n"));
577         process_blocking_lock_queue(time(NULL));
578 }
579
580 /****************************************************************************
581  Return the number of seconds to the next blocking locks timeout, or default_timeout
582 *****************************************************************************/
583
584 unsigned blocking_locks_timeout(unsigned default_timeout)
585 {
586         unsigned timeout = default_timeout;
587         time_t t;
588         blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst(&blocking_lock_queue);
589
590         /* note that we avoid the time() syscall if there are no blocking locks */
591         if (!blr)
592                 return timeout;
593
594         t = time(NULL);
595
596         while (blr) {
597                 if ((blr->expire_time != (time_t)-1) &&
598                                         (timeout > (blr->expire_time - t))) {
599                         timeout = blr->expire_time - t;
600                 }
601                 blr = (blocking_lock_record *)ubi_slNext(blr);
602         }
603
604         if (timeout < 1)
605                 timeout = 1;
606
607         return timeout;
608 }
609
610 /****************************************************************************
611  Process the blocking lock queue. Note that this is only called as root.
612 *****************************************************************************/
613
614 void process_blocking_lock_queue(time_t t)
615 {
616         blocking_lock_record *blr = (blocking_lock_record *)ubi_slFirst( &blocking_lock_queue );
617         blocking_lock_record *prev = NULL;
618
619         if(blr == NULL)
620                 return;
621
622         /*
623          * Go through the queue and see if we can get any of the locks.
624          */
625
626         while(blr != NULL) {
627                 connection_struct *conn = NULL;
628                 uint16 vuid;
629                 files_struct *fsp = NULL;
630
631                 /*
632                  * Ensure we don't have any old chain_fsp values
633                  * sitting around....
634                  */
635                 chain_size = 0;
636                 file_chain_reset();
637                 fsp = blr->fsp;
638
639                 conn = conn_find(SVAL(blr->inbuf,smb_tid));
640                 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID :
641                                 SVAL(blr->inbuf,smb_uid);
642
643                 DEBUG(5,("process_blocking_lock_queue: examining pending lock fnum = %d for file %s\n",
644                         fsp->fnum, fsp->fsp_name ));
645
646                 if((blr->expire_time != -1) && (blr->expire_time <= t)) {
647                         /*
648                          * Lock expired - throw away all previously
649                          * obtained locks and return lock error.
650                          */
651                         DEBUG(5,("process_blocking_lock_queue: pending lock fnum = %d for file %s timed out.\n",
652                                 fsp->fnum, fsp->fsp_name ));
653
654                         brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
655                                 blr->lock_pid, sys_getpid(), conn->cnum,
656                                 blr->offset, blr->count, True, NULL, NULL);
657
658                         blocking_lock_reply_error(blr,NT_STATUS_FILE_LOCK_CONFLICT);
659                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
660                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
661                         continue;
662                 }
663
664                 if(!change_to_user(conn,vuid)) {
665                         DEBUG(0,("process_blocking_lock_queue: Unable to become user vuid=%d.\n",
666                                 vuid ));
667                         /*
668                          * Remove the entry and return an error to the client.
669                          */
670                         blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED);
671
672                         brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
673                                         blr->lock_pid, sys_getpid(), conn->cnum,
674                                         blr->offset, blr->count, True, NULL, NULL);
675
676                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
677                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
678                         continue;
679                 }
680
681                 if(!set_current_service(conn,True)) {
682                         DEBUG(0,("process_blocking_lock_queue: Unable to become service Error was %s.\n", strerror(errno) ));
683                         /*
684                          * Remove the entry and return an error to the client.
685                          */
686                         blocking_lock_reply_error(blr,NT_STATUS_ACCESS_DENIED);
687
688                         brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
689                                         blr->lock_pid, sys_getpid(), conn->cnum,
690                                         blr->offset, blr->count, True, NULL, NULL);
691
692                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
693                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
694                         change_to_root_user();
695                         continue;
696                 }
697
698                 /*
699                  * Go through the remaining locks and try and obtain them.
700                  * The call returns True if all locks were obtained successfully
701                  * and False if we still need to wait.
702                  */
703
704                 if(blocking_lock_record_process(blr)) {
705
706                         brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
707                                         blr->lock_pid, sys_getpid(), conn->cnum,
708                                         blr->offset, blr->count, True, NULL, NULL);
709
710                         free_blocking_lock_record((blocking_lock_record *)ubi_slRemNext( &blocking_lock_queue, prev));
711                         blr = (blocking_lock_record *)(prev ? ubi_slNext(prev) : ubi_slFirst(&blocking_lock_queue));
712                         change_to_root_user();
713                         continue;
714                 }
715
716                 change_to_root_user();
717
718                 /*
719                  * Move to the next in the list.
720                  */
721                 prev = blr;
722                 blr = (blocking_lock_record *)ubi_slNext(blr);
723         }
724 }