-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes an issue where Test-IsADUserPasswordCompromised cmdlet would fa…
…il when a server name was not specified, and NTLM was disabled for the calling user
- Loading branch information
1 parent
9aefb74
commit a5ed018
Showing
9 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Lithnet.ActiveDirectory.PasswordProtection | ||
{ | ||
public static class NativeMethods | ||
{ | ||
[DllImport("Netapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | ||
private static extern int NetServerGetInfo(string serverName, int level, out IntPtr pServerInfo); | ||
|
||
[DllImport("NetApi32.dll")] | ||
private static extern int NetApiBufferFree(IntPtr buffer); | ||
|
||
public static bool IsDc() | ||
{ | ||
var info = GetServerInfo(); | ||
return info.Type.HasFlag(ServerTypes.DomainCtrl) || info.Type.HasFlag(ServerTypes.BackupDomainCtrl); | ||
} | ||
|
||
public static ServerInfo101 GetServerInfo() | ||
{ | ||
return GetServerInfo(null); | ||
} | ||
|
||
public static ServerInfo101 GetServerInfo(string server) | ||
{ | ||
IntPtr pServerInfo = IntPtr.Zero; | ||
|
||
try | ||
{ | ||
int result = NetServerGetInfo(server, 101, out pServerInfo); | ||
|
||
if (result != 0) | ||
{ | ||
throw new Win32Exception(result); | ||
} | ||
|
||
var info = Marshal.PtrToStructure<ServerInfo101>(pServerInfo); | ||
|
||
return info; | ||
} | ||
finally | ||
{ | ||
if (pServerInfo != IntPtr.Zero) | ||
{ | ||
NetApiBufferFree(pServerInfo); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Lithnet.ActiveDirectory.PasswordProtection | ||
{ | ||
[StructLayout(LayoutKind.Sequential)] | ||
public struct ServerInfo101 | ||
{ | ||
public ServerPlatform PlatformId; | ||
|
||
[MarshalAs(UnmanagedType.LPWStr)] | ||
public string Name; | ||
|
||
public int VersionMajor; | ||
|
||
public int VersionMinor; | ||
|
||
public ServerTypes Type; | ||
|
||
[MarshalAs(UnmanagedType.LPWStr)] | ||
public string Comment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Lithnet.ActiveDirectory.PasswordProtection | ||
{ | ||
public enum ServerPlatform | ||
{ | ||
Dos = 300, | ||
Os2 = 400, | ||
Nt = 500, | ||
Osf = 600, | ||
Vms = 700 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
|
||
namespace Lithnet.ActiveDirectory.PasswordProtection | ||
{ | ||
[Flags] | ||
public enum ServerTypes : uint | ||
{ | ||
Workstation = 0x00000001, | ||
Server = 0x00000002, | ||
SqlServer = 0x00000004, | ||
DomainCtrl = 0x00000008, | ||
BackupDomainCtrl = 0x00000010, | ||
TimeSource = 0x00000020, | ||
AppleFilingProtocol = 0x00000040, | ||
Novell = 0x00000080, | ||
DomainMember = 0x00000100, | ||
PrintQueueServer = 0x00000200, | ||
DialinServer = 0x00000400, | ||
XenixServer = 0x00000800, | ||
UnixServer = 0x00000800, | ||
NT = 0x00001000, | ||
WindowsForWorkgroups = 0x00002000, | ||
MicrosoftFileAndPrintServer = 0x00004000, | ||
NTServer = 0x00008000, | ||
BrowserService = 0x00010000, | ||
BackupBrowserService = 0x00020000, | ||
MasterBrowserService = 0x00040000, | ||
DomainMaster = 0x00080000, | ||
OSF1Server = 0x00100000, | ||
VMSServer = 0x00200000, | ||
Windows = 0x00400000, | ||
DFS = 0x00800000, | ||
NTCluster = 0x01000000, | ||
TerminalServer = 0x02000000, | ||
VirtualNTCluster = 0x04000000, | ||
DCE = 0x10000000, | ||
AlternateTransport = 0x20000000, | ||
LocalListOnly = 0x40000000, | ||
PrimaryDomain = 0x80000000, | ||
All = 0xFFFFFFFF | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters