Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tmds committed Nov 18, 2021
1 parent 712e45c commit e3d8546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,13 @@ internal static partial class Interop
{
internal static partial class Sys
{
internal static bool IsMemberOfGroup(uint gid)
internal static unsafe bool IsMemberOfGroup(uint gid)
{
if (gid == GetEGid())
{
return true;
}

uint[]? groups = GetGroups();
if (groups == null)
{
return false;
}

return Array.IndexOf(groups, gid) >= 0;
}

[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
private static partial uint GetEGid();

private static unsafe uint[]? GetGroups()
{
const int InitialGroupsLength =
#if DEBUG
1;
Expand All @@ -47,7 +33,7 @@ internal static bool IsMemberOfGroup(uint gid)
if (rv >= 0)
{
// success
return groups.Slice(0, rv).ToArray();
return groups.Slice(0, rv).IndexOf(gid) >= 0;
}
else if (rv == -1 && Interop.Sys.GetLastError() == Interop.Error.EINVAL)
{
Expand All @@ -56,13 +42,16 @@ internal static bool IsMemberOfGroup(uint gid)
}
else
{
// failure
return null;
// failure (unexpected)
return false;
}
}
while (true);
}

[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetEGid")]
private static partial uint GetEGid();

[GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_GetGroups", SetLastError = true)]
private static unsafe partial int GetGroups(int ngroups, uint* groups);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ private static bool IsExecutable(string fullPath)

if (euid == 0)
{
// We're root.
return true;
return true; // We're root.
}

if (euid == fileinfo.Uid)
Expand Down

0 comments on commit e3d8546

Please sign in to comment.