Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback and error logging if running pgina as admin without domain p… #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions Plugins/LocalMachine/LocalAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,19 @@ private static bool IsUserInGroup(UserPrincipal user, GroupPrincipal group)

continue;
}
catch (System.Runtime.InteropServices.COMException e)
{
m_logger.ErrorFormat("COMException when checking group membership for user {0} in group {1}." +
" This usually means that you have a domain user/group in your local group. but you are running pGina-service with a local/machine admin." +
" I strongly recommend that you fix this problem as soon as possible by delete the domain user/group or run de service as a domain user with admin rights on this pc.",
user.Name, group.Name);
m_logger.Error(e);
// Sanity check to avoid infinite loops
errorCount++;
if (errorCount > 1000) return false;

continue;
}
if (ok)
{
Principal principal = membersEnum.Current;
Expand Down Expand Up @@ -838,30 +850,40 @@ public static bool UserExists(string strUserName)
private static List<GroupPrincipal> GetGroups(UserPrincipal user)
{
List<GroupPrincipal> result = new List<GroupPrincipal>();
PrincipalSearchResult<Principal> sResult;
try
{
// Get all groups using a PrincipalSearcher and
GroupPrincipal filter = new GroupPrincipal(m_machinePrincipal);
using (PrincipalSearcher searcher = new PrincipalSearcher(filter))
{
sResult = searcher.FindAll();
}
}
catch
{
// fallback for machine running pgina as local/machine admin and have groups from a domain.
// Failed to process gateway for ******* message: Unable to sync users local group membership: System.Runtime.InteropServices.COMException (0x80070035): The network path was not found.
sResult = user.GetGroups();
}

// Get all groups using a PrincipalSearcher and
GroupPrincipal filter = new GroupPrincipal(m_machinePrincipal);
using (PrincipalSearcher searcher = new PrincipalSearcher(filter))
foreach (Principal p in sResult)
{
PrincipalSearchResult<Principal> sResult = searcher.FindAll();
foreach (Principal p in sResult)
if (p is GroupPrincipal)
{
if (p is GroupPrincipal)
{
GroupPrincipal gp = (GroupPrincipal)p;
if (LocalAccount.IsUserInGroup(user, gp))
result.Add(gp);
else
gp.Dispose();
}
GroupPrincipal gp = (GroupPrincipal)p;
if (LocalAccount.IsUserInGroup(user, gp))
result.Add(gp);
else
{
p.Dispose();
}
gp.Dispose();
}
else
{
p.Dispose();
}
}

return result;
}

}
}