nfs4: Check if user is allowed to use open state

This commit is contained in:
Pawel Dziepak
2012-08-07 00:22:34 +02:00
parent 224d602294
commit 49935f9b4f
3 changed files with 28 additions and 13 deletions
+10 -3
View File
@@ -805,13 +805,20 @@ Inode::ReturnDelegation(bool truncate)
MutexLocker stateLocker(fStateLock);
fOpenState->fDelegation = NULL;
ReleaseOpenState();
delete fDelegation;
fDelegation = NULL;
}
void
Inode::ReleaseOpenState()
{
if (fOpenState->ReleaseReference() == 1) {
fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL;
}
delete fDelegation;
fDelegation = NULL;
}
@@ -93,6 +93,8 @@ public:
protected:
Inode();
void ReleaseOpenState();
status_t CreateState(const char* name, int mode,
int perms, OpenState* state,
OpenDelegationData* data);
@@ -130,13 +130,24 @@ Inode::Open(int mode, OpenFileCookie* cookie)
status_t result = OpenFile(fOpenState, O_RDWR, &data);
if (result != B_OK) {
locker.Lock();
if (fOpenState->ReleaseReference() == 1) {
fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL;
}
ReleaseOpenState();
return result;
}
fOpenState->fMode = O_RDWR;
} else {
int newMode = mode & O_RWMASK;
uint32 allowed = 0;
if (newMode == O_RDWR || newMode == O_RDONLY)
allowed |= R_OK;
if (newMode == O_RDWR || newMode == O_WRONLY)
allowed |= W_OK;
status_t result = Access(allowed);
if (result != B_OK) {
locker.Lock();
ReleaseOpenState();
return result;
}
}
}
@@ -173,12 +184,7 @@ Inode::Close(OpenFileCookie* cookie)
SyncAndCommit();
MutexLocker _(fStateLock);
if (cookie->fOpenState != NULL) {
if (cookie->fOpenState->ReleaseReference() == 1) {
fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL;
}
}
ReleaseOpenState();
return B_OK;
}