break;
if (tc)
validExtension = 1;
- }
+ }
/* Copy name characters */
for (i = 0, name = longname;
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);
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)) {
BOOL foundscp;
cm_req_t req;
int created = 0;
- cm_lock_data_t *ldp = NULL;
+ cm_lock_data_t *ldp = NULL;
cm_InitReq(&req);
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;
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;