Fixed the nastiest locking bug to track down.... smb_pids are sent in the
authorJeremy Allison <jra@samba.org>
Mon, 2 Jul 2001 02:42:41 +0000 (02:42 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 2 Jul 2001 02:42:41 +0000 (02:42 +0000)
lockingX calls - use that instead of smb_pid in the packet.
Jeremy.

source/include/smb_macros.h
source/locking/locking.c
source/locking/posix.c
source/smbd/blocking.c
source/smbd/process.c
source/smbd/reply.c

index 2e74d7e69f55f7f9f6332d44b3d1299b4e05b197..cad6229f1aef32e730b682e22a11ae07f2463ec7 100644 (file)
 #define SMB_LPID_OFFSET(indx) (10 * (indx))
 #define SMB_LKOFF_OFFSET(indx) ( 2 + (10 * (indx)))
 #define SMB_LKLEN_OFFSET(indx) ( 6 + (10 * (indx)))
+#define SMB_LARGE__LPID_OFFSET(indx) (20 * (indx))
 #define SMB_LARGE_LKOFF_OFFSET_HIGH(indx) (4 + (20 * (indx)))
 #define SMB_LARGE_LKOFF_OFFSET_LOW(indx) (8 + (20 * (indx)))
 #define SMB_LARGE_LKLEN_OFFSET_HIGH(indx) (12 + (20 * (indx)))
index a75388081e95603d333cbb615be5fdc57f179e8b..067b1dc0ddf9fc8e1f5f4079e460a6051a96ee57 100644 (file)
@@ -37,7 +37,7 @@
 
 #include "includes.h"
 extern int DEBUGLEVEL;
-int global_smbpid;
+uint16 global_smbpid;
 
 /* the locking database handle */
 static TDB_CONTEXT *tdb;
@@ -99,7 +99,7 @@ BOOL is_locked(files_struct *fsp,connection_struct *conn,
  Utility function called by locking requests.
 ****************************************************************************/
 
-BOOL do_lock(files_struct *fsp,connection_struct *conn,
+BOOL do_lock(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
              SMB_BIG_UINT count,SMB_BIG_UINT offset,enum brl_type lock_type,
              int *eclass,uint32 *ecode)
 {
@@ -119,7 +119,7 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
 
        if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
                ok = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
-                             global_smbpid, sys_getpid(), conn->cnum, 
+                             lock_pid, sys_getpid(), conn->cnum, 
                              offset, count, 
                              lock_type);
 
@@ -139,7 +139,7 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
                                 * lock entry.
                                 */
                                (void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
-                                                               global_smbpid, sys_getpid(), conn->cnum, 
+                                                               lock_pid, sys_getpid(), conn->cnum, 
                                                                offset, count);
                        }
                }
@@ -157,7 +157,7 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
  Utility function called by unlocking requests.
 ****************************************************************************/
 
-BOOL do_unlock(files_struct *fsp,connection_struct *conn,
+BOOL do_unlock(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
                SMB_BIG_UINT count,SMB_BIG_UINT offset, 
               int *eclass,uint32 *ecode)
 {
@@ -182,7 +182,7 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn,
         */
 
        ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
-                       global_smbpid, sys_getpid(), conn->cnum, offset, count);
+                       lock_pid, sys_getpid(), conn->cnum, offset, count);
    
        if (!ok) {
                DEBUG(10,("do_unlock: returning ERRlock.\n" ));
index 9cfe25ed9d5617e383b6fbec49efb69d0d016e1f..2a8a7aacd73f9bcb93629b568f86f2eb0a466b9b 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "includes.h"
 extern int DEBUGLEVEL;
-extern int global_smbpid;
 
 /*
  * The POSIX locking database handle.
index 843f3d07a686c115eaa32bb76fd425163d336b16..48d3c8a24a8da19333e5a4ffe017ccc3984a4a7a 100644 (file)
@@ -196,6 +196,7 @@ static void reply_lockingX_error(blocking_lock_record *blr, int eclass, int32 ec
   connection_struct *conn = conn_find(SVAL(inbuf,smb_tid));
   uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
   SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0;
+  uint16 lock_pid;
   unsigned char locktype = CVAL(inbuf,smb_vwv3);
   BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
   char *data;
@@ -219,6 +220,7 @@ static void reply_lockingX_error(blocking_lock_record *blr, int eclass, int32 ec
     uint32 dummy2;
     BOOL err;
 
+    lock_pid = get_lock_pid( data, i, large_file_format);
     count = get_lock_count( data, i, large_file_format);
     offset = get_lock_offset( data, i, large_file_format, &err);
 
@@ -227,7 +229,7 @@ static void reply_lockingX_error(blocking_lock_record *blr, int eclass, int32 ec
      * request would never have been queued. JRA.
      */
 
-    do_unlock(fsp,conn,count,offset,&dummy1,&dummy2);
+    do_unlock(fsp,conn,lock_pid,count,offset,&dummy1,&dummy2);
   }
 
   generic_blocking_lock_error(blr, eclass, ecode);
@@ -280,7 +282,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, (SMB_BIG_UINT)numtoread, (SMB_BIG_UINT)startpos, READ_LOCK, &eclass, &ecode)) {
+  if(!do_lock( fsp, conn, SVAL(inbuf,smb_pid), (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
@@ -346,7 +348,7 @@ static BOOL process_lock(blocking_lock_record *blr)
   offset = IVAL(inbuf,smb_vwv3);
 
   errno = 0;
-  if (!do_lock(fsp, conn, (SMB_BIG_UINT)count, (SMB_BIG_UINT)offset, WRITE_LOCK, &eclass, &ecode)) {
+  if (!do_lock(fsp, conn, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)count, (SMB_BIG_UINT)offset, WRITE_LOCK, &eclass, &ecode)) {
     if((errno != EACCES) && (errno != EAGAIN)) {
 
       /*
@@ -395,6 +397,7 @@ static BOOL process_lockingX(blocking_lock_record *blr)
   uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
   uint16 num_locks = SVAL(inbuf,smb_vwv7);
   SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0;
+  uint16 lock_pid;
   BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES);
   char *data;
   int eclass=0;
@@ -410,6 +413,7 @@ static BOOL process_lockingX(blocking_lock_record *blr)
   for(; blr->lock_num < num_locks; blr->lock_num++) {
     BOOL err;
 
+    lock_pid = get_lock_pid( data, blr->lock_num, large_file_format);
     count = get_lock_count( data, blr->lock_num, large_file_format);
     offset = get_lock_offset( data, blr->lock_num, large_file_format, &err);
 
@@ -418,7 +422,7 @@ static BOOL process_lockingX(blocking_lock_record *blr)
      * request would never have been queued. JRA.
      */
     errno = 0;
-    if(!do_lock(fsp,conn,count,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK),
+    if(!do_lock(fsp,conn,count,lock_pid,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK),
                 &eclass, &ecode))
       break;
   }
index f43c675289c26a24fe4f85512595419894fddc85..dd2318b58a845d3519e5c6d533fc06590d989ff0 100644 (file)
@@ -612,7 +612,7 @@ static int switch_message(int type,char *inbuf,char *outbuf,int size,int bufsize
 {
   static pid_t pid= (pid_t)-1;
   int outsize = 0;
-  extern int global_smbpid;
+  extern uint16 global_smbpid;
 
   type &= 0xff;
 
index b66149e7daea8cf5c984575a8f9766b5c43fde85..2539537bfcdd0ec5930141a6e5d74740156683a8 100644 (file)
@@ -2290,7 +2290,7 @@ int reply_lockread(connection_struct *conn, char *inbuf,char *outbuf, int length
    * for a write lock. JRA.
    */
 
-  if(!do_lock( fsp, conn, (SMB_BIG_UINT)numtoread, (SMB_BIG_UINT)startpos, WRITE_LOCK, &eclass, &ecode)) {
+  if(!do_lock( fsp, conn, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)numtoread, (SMB_BIG_UINT)startpos, WRITE_LOCK, &eclass, &ecode)) {
     if((ecode == ERRlock) && lp_blocking_locks(SNUM(conn))) {
       /*
        * A blocking lock was requested. Package up
@@ -2605,7 +2605,7 @@ int reply_writeunlock(connection_struct *conn, char *inbuf,char *outbuf, int siz
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
 
-  if(!do_unlock(fsp, conn, (SMB_BIG_UINT)numtowrite, (SMB_BIG_UINT)startpos, &eclass, &ecode)) {
+  if(!do_unlock(fsp, conn, SVAL(inbuf,smb_pid), (SMB_BIG_UINT)numtowrite, (SMB_BIG_UINT)startpos, &eclass, &ecode)) {
     END_PROFILE(SMBwriteunlock);
     return(ERROR(eclass,ecode));
   }
@@ -3089,7 +3089,7 @@ int reply_lock(connection_struct *conn,
        DEBUG(3,("lock fd=%d fnum=%d offset=%.0f count=%.0f\n",
                 fsp->fd, fsp->fnum, (double)offset, (double)count));
 
-       if (!do_lock(fsp, conn, count, offset, WRITE_LOCK, &eclass, &ecode)) {
+       if (!do_lock(fsp, conn, SVAL(inbuf,smb_pid), count, offset, WRITE_LOCK, &eclass, &ecode)) {
           if((ecode == ERRlock) && lp_blocking_locks(SNUM(conn))) {
            /*
              * A blocking lock was requested. Package up
@@ -3128,7 +3128,7 @@ int reply_unlock(connection_struct *conn, char *inbuf,char *outbuf, int size, in
   count = (SMB_BIG_UINT)IVAL(inbuf,smb_vwv1);
   offset = (SMB_BIG_UINT)IVAL(inbuf,smb_vwv3);
 
-  if(!do_unlock(fsp, conn, count, offset, &eclass, &ecode)) {
+  if(!do_unlock(fsp, conn, SVAL(inbuf,smb_pid), count, offset, &eclass, &ecode)) {
     END_PROFILE(SMBunlock);
     return (ERROR(eclass,ecode));
   }
@@ -4247,6 +4247,18 @@ int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   return(outsize);
 }
 
+/****************************************************************************
+ Get a lock pid, dealing with large count requests.
+****************************************************************************/
+
+uint16 get_lock_pid( char *data, int data_offset, BOOL large_file_format)
+{
+       if(!large_file_format)
+               return SVAL(data,SMB_LPID_OFFSET(data_offset));
+       else
+               return SVAL(data,SMB_LARGE__LPID_OFFSET(data_offset));
+}
+
 /****************************************************************************
  Get a lock count, dealing with large count requests.
 ****************************************************************************/
@@ -4346,6 +4358,7 @@ int reply_lockingX(connection_struct *conn, char *inbuf,char *outbuf,int length,
   uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
   uint16 num_locks = SVAL(inbuf,smb_vwv7);
   SMB_BIG_UINT count = 0, offset = 0;
+  uint16 lock_pid;
   int32 lock_timeout = IVAL(inbuf,smb_vwv4);
   int i;
   char *data;
@@ -4418,6 +4431,7 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
   /* Data now points at the beginning of the list
      of smb_unlkrng structs */
   for(i = 0; i < (int)num_ulocks; i++) {
+    lock_pid = get_lock_pid( data, i, large_file_format);
     count = get_lock_count( data, i, large_file_format);
     offset = get_lock_offset( data, i, large_file_format, &err);
 
@@ -4429,10 +4443,10 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
       return ERROR(ERRDOS,ERRnoaccess);
     }
 
-    DEBUG(10,("reply_lockingX: unlock start=%.0f, len=%.0f for file %s\n",
-          (double)offset, (double)count, fsp->fsp_name ));
+    DEBUG(10,("reply_lockingX: unlock start=%.0f, len=%.0f for pid %u, file %s\n",
+          (unsigned int)lock_pid, (double)offset, (double)count, fsp->fsp_name ));
 
-    if(!do_unlock(fsp,conn,count,offset, &eclass, &ecode)) {
+    if(!do_unlock(fsp,conn,lock_pid,count,offset, &eclass, &ecode)) {
       END_PROFILE(SMBlockingX);
       return ERROR(eclass,ecode);
     }
@@ -4448,6 +4462,7 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
      of smb_lkrng structs */
 
   for(i = 0; i < (int)num_locks; i++) {
+    lock_pid = get_lock_pid( data, i, large_file_format);
     count = get_lock_count( data, i, large_file_format);
     offset = get_lock_offset( data, i, large_file_format, &err);
 
@@ -4459,10 +4474,10 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
       return ERROR(ERRDOS,ERRnoaccess);
     }
  
-    DEBUG(10,("reply_lockingX: lock start=%.0f, len=%.0f for file %s\n",
-          (double)offset, (double)count, fsp->fsp_name ));
+    DEBUG(10,("reply_lockingX: lock start=%.0f, len=%.0f for pid %u, file %s\n",
+          (unsigned int)lock_pid, (double)offset, (double)count, fsp->fsp_name ));
 
-    if(!do_lock(fsp,conn,count,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK),
+    if(!do_lock(fsp,conn,lock_pid, count,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK),
                 &eclass, &ecode)) {
       if((ecode == ERRlock) && (lock_timeout != 0) && lp_blocking_locks(SNUM(conn))) {
         /*
@@ -4488,6 +4503,7 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
      * will delete it (and we shouldn't) .....
      */
     for(i--; i >= 0; i--) {
+      lock_pid = get_lock_pid( data, i, large_file_format);
       count = get_lock_count( data, i, large_file_format);
       offset = get_lock_offset( data, i, large_file_format, &err);
 
@@ -4499,7 +4515,7 @@ no oplock granted on this file (%s).\n", fsp->fnum, fsp->fsp_name));
         return ERROR(ERRDOS,ERRnoaccess);
       }
  
-      do_unlock(fsp,conn,count,offset,&dummy1,&dummy2);
+      do_unlock(fsp,conn,lock_pid,count,offset,&dummy1,&dummy2);
     }
     END_PROFILE(SMBlockingX);
     return ERROR(eclass,ecode);