]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
DEVEL15-windows-smb-file-lock-20070209
authorAsanka Herath <asanka@secure-endpoints.com>
Sat, 10 Feb 2007 00:00:44 +0000 (00:00 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Sat, 10 Feb 2007 00:00:44 +0000 (00:00 +0000)
When processing exclusive locks for files that were opened read-only,
obtain a read-lock instead of a write-lock.

In NTCreateX, if the file is being opened as OPEN_ALWAYS and the file
already exists, do not require write permission

(cherry picked from commit 25c7f567f2c831d62152104c3b84ec31d9fd330f)

src/WINNT/afsd/cm_vnodeops.c
src/WINNT/afsd/smb3.c

index 6d33c4ae9076deaa180d6270c7e55c7eb6421ea0..3fbc933ee1634d4a557ea004ff586da6188d0212 100644 (file)
@@ -209,7 +209,7 @@ void cm_Gen8Dot3NameInt(const char * longname, cm_dirFid_t * pfid,
                 break;
         if (tc)
             validExtension = 1;
-    }       
+    }
 
     /* Copy name characters */
     for (i = 0, name = longname;
@@ -353,8 +353,11 @@ long cm_CheckNTOpen(cm_scache_t *scp, unsigned int desiredAccess,
     if (desiredAccess & AFS_ACCESS_READ)
         rights |= (scp->fileType == CM_SCACHETYPE_DIRECTORY ? PRSFS_LOOKUP : PRSFS_READ);
 
-    if ((desiredAccess & AFS_ACCESS_WRITE)
-         || createDisp == 4)
+    /* We used to require PRSFS_WRITE if createDisp was 4
+       (OPEN_ALWAYS) even if AFS_ACCESS_WRITE was not requested.
+       However, we don't need to do that since the existence of the
+       scp implies that we don't need to create it. */
+    if (desiredAccess & AFS_ACCESS_WRITE)
         rights |= PRSFS_WRITE;
 
     lock_ObtainMutex(&scp->mx);
index e4c598bbf5c0b7ef7666f986fc8c7e3be5ef1dfa..7f1f5fe61d8611c6fd6f6e7c112cdd63f2dc0d76 100644 (file)
@@ -5728,6 +5728,14 @@ long smb_ReceiveV3LockingX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
     NumberOfUnlocks = smb_GetSMBParm(inp, 6);
     NumberOfLocks = smb_GetSMBParm(inp, 7);
 
+    if (!(fidp->flags & SMB_FID_OPENWRITE) &&
+        !(LockType & LOCKING_ANDX_SHARED_LOCK)) {
+        /* somebody wants exclusive locks on a file that they only
+           opened for reading.  We downgrade this to a shared lock. */
+        osi_Log0(smb_logp, "smb_ReceiveV3Locking reinterpreting exclusive lock as shared for read-only fid");
+        LockType |= LOCKING_ANDX_SHARED_LOCK;
+    }
+
     if ((LockType & LOCKING_ANDX_CANCEL_LOCK) ||
         (LockType & LOCKING_ANDX_CHANGE_LOCKTYPE)) {
 
@@ -6382,7 +6390,7 @@ long smb_ReceiveNTCreateX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
     BOOL foundscp;
     cm_req_t req;
     int created = 0;
-    cm_lock_data_t *ldp = NULL;                                                                               
+    cm_lock_data_t *ldp = NULL;
 
     cm_InitReq(&req);
 
@@ -7038,7 +7046,12 @@ long smb_ReceiveNTCreateX(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp)
         LLength.HighPart = 0;
         LLength.LowPart = SMB_FID_QLOCK_LENGTH;
 
-        if (fidflags & SMB_FID_SHARE_READ) {
+        /* If we are not opening the file for writing, then we don't
+           try to get an exclusive lock.  Noone else should be able to
+           get an exclusive lock on the file anyway, although someone
+           else can get a shared lock. */
+        if ((fidflags & SMB_FID_SHARE_READ) ||
+            !(fidflags & SMB_FID_OPENWRITE)) {
             sLockType = LOCKING_ANDX_SHARED_LOCK;
         } else {
             sLockType = 0;
@@ -7681,7 +7694,10 @@ long smb_ReceiveNTTranCreate(smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *out
         LLength.HighPart = 0;
         LLength.LowPart = SMB_FID_QLOCK_LENGTH;
 
-        if (fidflags & SMB_FID_SHARE_READ) {
+        /* Similar to what we do in handling NTCreateX.  We get a
+           shared lock if we are only opening the file for reading. */
+        if ((fidflags & SMB_FID_SHARE_READ) ||
+            !(fidflags & SMB_FID_OPENWRITE)) {
             sLockType = LOCKING_ANDX_SHARED_LOCK;
         } else {
             sLockType = 0;