Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR
[bbaumbach/samba-autobuild/.git] / source / smbd / blocking.c
index 5e7d4a0c879f916a88421fa8c900fe287944d024..e8dc29f80ac793d9a20950b0ee39a59813ca7a19 100644 (file)
@@ -21,8 +21,6 @@
 
 #include "includes.h"
 extern int DEBUGLEVEL;
-extern int Client;
-extern int chain_size;
 extern char *OutBuffer;
 
 /****************************************************************************
@@ -119,8 +117,8 @@ BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int
   ubi_slAddTail(&blocking_lock_queue, blr);
 
 
-  DEBUG(3,("push_blocking_lock_request: lock request length=%d blocked with expiry time %d \
-for fnum = %d, name = %s\n", length, (int)blr->expire_time, 
+  DEBUG(3,("push_blocking_lock_request: lock request length=%d blocked with expiry time %d (+%d) \
+for fnum = %d, name = %s\n", length, (int)blr->expire_time, lock_timeout,
         blr->fsp->fnum, blr->fsp->fsp_name ));
 
   return True;
@@ -135,7 +133,7 @@ static void send_blocking_reply(char *outbuf, int outsize)
   if(outsize > 4)
     smb_setlen(outbuf,outsize - 4);
 
-  send_smb(Client,outbuf);
+  send_smb(smbd_server_fd(),outbuf);
 }
 
 /****************************************************************************
@@ -181,7 +179,7 @@ static void generic_blocking_lock_error(blocking_lock_record *blr, int eclass, i
     SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
 
   ERROR(eclass,ecode);
-  send_smb(Client,outbuf);
+  send_smb(smbd_server_fd(),outbuf);
 }
 
 /****************************************************************************
@@ -195,7 +193,7 @@ static void reply_lockingX_error(blocking_lock_record *blr, int eclass, int32 ec
   files_struct *fsp = blr->fsp;
   connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
   uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
-  SMB_OFF_T count = (SMB_OFF_T) 0, offset = (SMB_OFF_T) 0;
+  SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0;
   unsigned char locktype = CVAL(inbuf,smb_vwv3);
   BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
   char *data;
@@ -208,12 +206,18 @@ static void reply_lockingX_error(blocking_lock_record *blr, int eclass, int32 ec
    * of smb_lkrng structs.
    */
 
-  for(i = blr->lock_num; i >= 0; i--) {
+  /*
+   * Ensure we don't do a remove on the lock that just failed,
+   * as under POSIX rules, if we have a lock already there, we
+   * will delete it (and we shouldn't) .....
+   */
+
+  for(i = blr->lock_num - 1; i >= 0; i--) {
     int dummy1;
     uint32 dummy2;
     BOOL err;
 
-    count = get_lock_count( data, i, large_file_format, &err);
+    count = get_lock_count( data, i, large_file_format);
     offset = get_lock_offset( data, i, large_file_format, &err);
 
     /*
@@ -274,7 +278,7 @@ static BOOL process_lockread(blocking_lock_record *blr)
   numtoread = MIN(BUFFER_SIZE-outsize,numtoread);
   data = smb_buf(outbuf) + 3;
  
-  if(!do_lock( fsp, conn, numtoread, startpos, READ_LOCK, &eclass, &ecode)) {
+  if(!do_lock( fsp, conn, (SMB_BIG_UINT)numtoread, (SMB_BIG_UINT)startpos, READ_LOCK, &eclass, &ecode)) {
     if((errno != EACCES) && (errno != EAGAIN)) {
       /*
        * We have other than a "can't get lock" POSIX
@@ -337,7 +341,7 @@ static BOOL process_lock(blocking_lock_record *blr)
   offset = IVAL(inbuf,smb_vwv3);
 
   errno = 0;
-  if (!do_lock(fsp, conn, count, offset, WRITE_LOCK, &eclass, &ecode)) {
+  if (!do_lock(fsp, conn, (SMB_BIG_UINT)count, (SMB_BIG_UINT)offset, WRITE_LOCK, &eclass, &ecode)) {
     if((errno != EACCES) && (errno != EAGAIN)) {
 
       /*
@@ -385,7 +389,7 @@ static BOOL process_lockingX(blocking_lock_record *blr)
   connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
   uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
   uint16 num_locks = SVAL(inbuf,smb_vwv7);
-  SMB_OFF_T count = 0, offset = 0;
+  SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
   BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
   char *data;
   int eclass=0;
@@ -401,7 +405,7 @@ static BOOL process_lockingX(blocking_lock_record *blr)
   for(; blr->lock_num < num_locks; blr->lock_num++) {
     BOOL err;
 
-    count = get_lock_count( data, blr->lock_num, large_file_format, &err);
+    count = get_lock_count( data, blr->lock_num, large_file_format);
     offset = get_lock_offset( data, blr->lock_num, large_file_format, &err);
 
     /*