Skip to content
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
28 changes: 20 additions & 8 deletions Src/NCCommon/Util/SecurityUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,32 @@ static extern bool LogonUser(
public static bool VerifyWindowsUserForRole(string nodeName, string userName, string password, WindowsBuiltInRole role)
{
bool isAdministrator = false;
IntPtr token;
IntPtr token = IntPtr.Zero;
try
{
LogonUser(userName, nodeName, password, 3, 0, out token);
WindowsIdentity identity = new WindowsIdentity(token);
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (principal.IsInRole(role))
if (!LogonUser(userName, nodeName, password, 3, 0, out token))
{
isAdministrator = true;
return false;
}
using (WindowsIdentity identity = new WindowsIdentity(token))
{
WindowsPrincipal principal = new WindowsPrincipal(identity);
if (principal.IsInRole(role))
{
isAdministrator = true;
}
}
}
catch (Exception ex)
catch
{

return false;
}
finally
{
if (token != IntPtr.Zero)
{
Marshal.Release(token);
}
}
return isAdministrator;
}
Expand Down