nfs4: Make Inode::Access() use cached attributes
This commit is contained in:
@@ -445,6 +445,32 @@ Inode::ReadLink(void* buffer, size_t* length)
|
||||
status_t
|
||||
Inode::Access(int mode)
|
||||
{
|
||||
int acc = 0;
|
||||
|
||||
if (fFileSystem->IsAttrSupported(FATTR4_MODE)) {
|
||||
status_t result = _UpdateAttrCache();
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
// Root squashing and owner mapping problems may make this function
|
||||
// return false values. However, since due to race condition it can
|
||||
// not be used for anything critical, it is not a serius problem.
|
||||
|
||||
mode_t nodeMode = fAttrCache.st_mode;
|
||||
uint8 userMode = (nodeMode & S_IRWXU) >> 6;
|
||||
uint8 groupMode = (nodeMode & S_IRWXG) >> 3;
|
||||
uint8 otherMode = (nodeMode & S_IRWXO);
|
||||
|
||||
uid_t uid = geteuid();
|
||||
if (uid == 0)
|
||||
acc = userMode | groupMode | otherMode | R_OK | W_OK;
|
||||
else if (uid == fAttrCache.st_uid)
|
||||
acc = userMode;
|
||||
else if (getegid() == fAttrCache.st_gid)
|
||||
acc = groupMode;
|
||||
else
|
||||
acc = otherMode;
|
||||
} else {
|
||||
do {
|
||||
RPC::Server* serv = fFileSystem->Server();
|
||||
Request request(serv);
|
||||
@@ -469,7 +495,6 @@ Inode::Access(int mode)
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
|
||||
int acc = 0;
|
||||
if ((allowed & ACCESS4_READ) != 0)
|
||||
acc |= R_OK;
|
||||
|
||||
@@ -482,11 +507,14 @@ Inode::Access(int mode)
|
||||
if ((allowed & ACCESS4_MODIFY) != 0)
|
||||
acc |= W_OK;
|
||||
|
||||
break;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
if ((mode & acc) != mode)
|
||||
return B_NOT_ALLOWED;
|
||||
|
||||
return B_OK;
|
||||
} while (true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user