Skip to content

Commit

Permalink
Temporary fix: look up vnode path earlier in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
wilbaker committed Sep 15, 2018
1 parent efa70da commit bc6f896
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions ProjFS.Mac/PrjFSKext/PrjFSKext/KauthHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static bool TrySendRequestAndWaitForResponse(
const VirtualizationRoot* root,
MessageType messageType,
const vnode_t vnode,
const char* vnodePath,
int pid,
const char* procname,
int* kauthResult,
Expand Down Expand Up @@ -253,14 +254,23 @@ static int HandleVnodeOperation(
vnode_t currentVnode = reinterpret_cast<vnode_t>(arg1);
// arg2 is the (vnode_t) parent vnode
int* kauthError = reinterpret_cast<int*>(arg3);
int kauthResult = KAUTH_RESULT_DEFER;

const char* vnodePath = nullptr;
char vnodePathBuffer[PrjFSMaxPath];
int vnodePathLength = PrjFSMaxPath;

VirtualizationRoot* root = nullptr;
vtype vnodeType;
uint32_t currentVnodeFileFlags;
int pid;
char procname[MAXCOMLEN + 1];

int kauthResult = KAUTH_RESULT_DEFER;

// TODO(Mac): Issue #271 - Reduce reliance on vn_getpath
if (0 == vn_getpath(currentVnode, vnodePathBuffer, &vnodePathLength))
{
vnodePath = vnodePathBuffer;
}

if (!ShouldHandleVnodeOpEvent(
context,
Expand Down Expand Up @@ -292,6 +302,7 @@ static int HandleVnodeOperation(
root,
MessageType_KtoU_EnumerateDirectory,
currentVnode,
vnodePath,
pid,
procname,
&kauthResult,
Expand All @@ -308,6 +319,7 @@ static int HandleVnodeOperation(
root,
MessageType_KtoU_NotifyDirectoryPreDelete,
currentVnode,
vnodePath,
pid,
procname,
&kauthResult,
Expand All @@ -325,6 +337,7 @@ static int HandleVnodeOperation(
root,
MessageType_KtoU_NotifyFilePreDelete,
currentVnode,
vnodePath,
pid,
procname,
&kauthResult,
Expand All @@ -351,6 +364,7 @@ static int HandleVnodeOperation(
root,
MessageType_KtoU_HydrateFile,
currentVnode,
vnodePath,
pid,
procname,
&kauthResult,
Expand Down Expand Up @@ -428,6 +442,7 @@ static int HandleFileOpOperation(
root,
messageType,
currentVnodeFromPath,
newPath,
pid,
procname,
&kauthResult,
Expand All @@ -439,7 +454,7 @@ static int HandleFileOpOperation(
else if (KAUTH_FILEOP_CLOSE == action)
{
vnode_t currentVnode = reinterpret_cast<vnode_t>(arg0);
// arg1 is the (const char *) path
const char* path = (const char*)arg1;
int closeFlags = static_cast<int>(arg2);

if (vnode_isdir(currentVnode))
Expand Down Expand Up @@ -476,6 +491,7 @@ static int HandleFileOpOperation(
root,
MessageType_KtoU_NotifyFileModified,
currentVnode,
path,
pid,
procname,
&kauthResult,
Expand All @@ -492,6 +508,7 @@ static int HandleFileOpOperation(
root,
MessageType_KtoU_NotifyFileCreated,
currentVnode,
path,
pid,
procname,
&kauthResult,
Expand Down Expand Up @@ -647,6 +664,7 @@ static bool TrySendRequestAndWaitForResponse(
const VirtualizationRoot* root,
MessageType messageType,
const vnode_t vnode,
const char* vnodePath,
int pid,
const char* procname,
int* kauthResult,
Expand All @@ -657,11 +675,10 @@ static bool TrySendRequestAndWaitForResponse(
OutstandingMessage message;
message.receivedResponse = false;

char vnodePath[PrjFSMaxPath];
int vnodePathLength = PrjFSMaxPath;
if (vn_getpath(vnode, vnodePath, &vnodePathLength))
if (nullptr == vnodePath)
{
KextLog_Error("Unable to resolve a vnode to its path");
// Default error code is EACCES. See errno.h for more codes.
*kauthError = EAGAIN;
*kauthResult = KAUTH_RESULT_DENY;
return false;
}
Expand Down

0 comments on commit bc6f896

Please sign in to comment.