From: Asanka Herath Date: Sat, 10 Feb 2007 00:00:44 +0000 (+0000) Subject: DEVEL15-windows-smb-file-lock-20070209 X-Git-Tag: openafs-devel-1_5_15~13 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=630a62f4605ef9896b455decb7153c1b163d122f;p=packages%2Fo%2Fopenafs.git DEVEL15-windows-smb-file-lock-20070209 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) --- diff --git a/src/WINNT/afsd/cm_vnodeops.c b/src/WINNT/afsd/cm_vnodeops.c index 6d33c4ae9..3fbc933ee 100644 --- a/src/WINNT/afsd/cm_vnodeops.c +++ b/src/WINNT/afsd/cm_vnodeops.c @@ -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); diff --git a/src/WINNT/afsd/smb3.c b/src/WINNT/afsd/smb3.c index e4c598bbf..7f1f5fe61 100644 --- a/src/WINNT/afsd/smb3.c +++ b/src/WINNT/afsd/smb3.c @@ -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;