From ecdc5aca34b0f0dc6bf67eb95f8e6506c556ca26 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Tue, 25 Apr 2006 07:40:48 +0000 Subject: [PATCH] viced-write-locking-fix-20060425 According to src/libacl/prs_fs.h the PRSFS_LOCK privilege is only supposed to control read-locks. The PRSFS_WRITE and PRSFS_INSERT privileges are supposed to control write-locks. --- src/viced/afsfileprocs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/viced/afsfileprocs.c b/src/viced/afsfileprocs.c index db687f1888..ce40366c70 100644 --- a/src/viced/afsfileprocs.c +++ b/src/viced/afsfileprocs.c @@ -1690,14 +1690,11 @@ Alloc_NewVnode(Vnode * parentptr, DirHandle * dir, Volume * volptr, * SAFS_ReleaseLock) */ static afs_int32 -HandleLocking(Vnode * targetptr, afs_int32 rights, ViceLockType LockingType) +HandleLocking(Vnode * targetptr, struct client *client, afs_int32 rights, ViceLockType LockingType) { int Time; /* Used for time */ int writeVnode = targetptr->changed_oldTime; /* save original status */ - /* Does the caller has Lock priviledges; root extends locks, however */ - if (LockingType != LockExtend && !(rights & PRSFS_LOCK)) - return (EACCES); targetptr->changed_oldTime = 1; /* locking doesn't affect any time stamp */ Time = FT_ApproxTime(); switch (LockingType) { @@ -1708,12 +1705,19 @@ HandleLocking(Vnode * targetptr, afs_int32 rights, ViceLockType LockingType) 0; Time += AFS_LOCKWAIT; if (LockingType == LockRead) { + if ( !(rights & PRSFS_LOCK) ) + return(EACCES); + if (targetptr->disk.lock.lockCount >= 0) { ++(targetptr->disk.lock.lockCount); targetptr->disk.lock.lockTime = Time; } else return (EAGAIN); } else if (LockingType == LockWrite) { + if ( !(rights & PRSFS_WRITE) && + !(OWNSp(client, targetptr) && (rights & PRSFS_INSERT)) ) + return(EACCES); + if (targetptr->disk.lock.lockCount == 0) { targetptr->disk.lock.lockCount = -1; targetptr->disk.lock.lockTime = Time; @@ -4996,7 +5000,7 @@ SAFSS_SetLock(struct rx_call *acall, struct AFSFid *Fid, ViceLockType type, SetVolumeSync(Sync, volptr); /* Handle the particular type of set locking, type */ - errorCode = HandleLocking(targetptr, rights, type); + errorCode = HandleLocking(targetptr, client, rights, type); Bad_SetLock: /* Write the all modified vnodes (parent, new files) and volume back */ @@ -5122,7 +5126,7 @@ SAFSS_ExtendLock(struct rx_call *acall, struct AFSFid *Fid, SetVolumeSync(Sync, volptr); /* Handle the actual lock extension */ - errorCode = HandleLocking(targetptr, rights, LockExtend); + errorCode = HandleLocking(targetptr, client, rights, LockExtend); Bad_ExtendLock: /* Put back file's vnode and volume */ @@ -5249,7 +5253,7 @@ SAFSS_ReleaseLock(struct rx_call *acall, struct AFSFid *Fid, SetVolumeSync(Sync, volptr); /* Handle the actual lock release */ - if ((errorCode = HandleLocking(targetptr, rights, LockRelease))) + if ((errorCode = HandleLocking(targetptr, client, rights, LockRelease))) goto Bad_ReleaseLock; /* if no more locks left, a callback would be triggered here */