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); MutexLocker stateLocker(fStateLock);
fOpenState->fDelegation = NULL; fOpenState->fDelegation = NULL;
ReleaseOpenState();
delete fDelegation;
fDelegation = NULL;
}
void
Inode::ReleaseOpenState()
{
if (fOpenState->ReleaseReference() == 1) { if (fOpenState->ReleaseReference() == 1) {
fFileSystem->RemoveOpenFile(fOpenState); fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL; fOpenState = NULL;
} }
delete fDelegation;
fDelegation = NULL;
} }
@@ -93,6 +93,8 @@ public:
protected: protected:
Inode(); Inode();
void ReleaseOpenState();
status_t CreateState(const char* name, int mode, status_t CreateState(const char* name, int mode,
int perms, OpenState* state, int perms, OpenState* state,
OpenDelegationData* data); OpenDelegationData* data);
@@ -130,13 +130,24 @@ Inode::Open(int mode, OpenFileCookie* cookie)
status_t result = OpenFile(fOpenState, O_RDWR, &data); status_t result = OpenFile(fOpenState, O_RDWR, &data);
if (result != B_OK) { if (result != B_OK) {
locker.Lock(); locker.Lock();
if (fOpenState->ReleaseReference() == 1) { ReleaseOpenState();
fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL;
}
return result; return result;
} }
fOpenState->fMode = O_RDWR; 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(); SyncAndCommit();
MutexLocker _(fStateLock); MutexLocker _(fStateLock);
if (cookie->fOpenState != NULL) { ReleaseOpenState();
if (cookie->fOpenState->ReleaseReference() == 1) {
fFileSystem->RemoveOpenFile(fOpenState);
fOpenState = NULL;
}
}
return B_OK; return B_OK;
} }