我正在尝试诊断客户端站点上运行的服务器应用程序的问题。所述应用程序针对 AD 环境中的域控制器验证用户凭据。我们看到的行为是定期没有用户可以通过服务器进行身份验证。
我们基本上已经将失败追溯到“绑定”失败。为了进一步诊断问题,我构建了一个超级简单的工具,它执行两种类型的绑定:一种使用 LDAP 服务器绑定,另一种使用 WinNT 绑定。我们的服务器应用程序只进行 LDAP 绑定,但为了添加控件,我加入了 WinNT 绑定。
public static void DoWinNTBind(string domain, string login, string password)
{
Logger.Log("Starting WinNT Bind to {0}",domain);
try
{
var serverPath = String.Format("WinNT://{0}",domain);
Logger.Log("Creating DirectoryEntry object for {0} on domain {1}", login, serverPath);
using (DirectoryEntry de = new DirectoryEntry(serverPath, login, password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing))
{
if (!de.NativeObject.Equals(null))
{
Logger.Log("WinNT Bind Success");
}
else
{
Logger.Log("WinNT Bind Failed");
}
}
}
catch(Exception ex)
{
Logger.Log("{0} occured during WinNT Bind: {1}",ex.GetType().Name,ex.Message);
Logger.Log("Stack: {0}",ex.StackTrace);
}
}
public static void DoLDAPBind(string domain,string login, string password)
{
Logger.Log("Starting LDAP Bind to {0}",domain);
try
{
var serverPath = String.Format("LDAP://{0}",domain);
Logger.Log("Creating DirectoryEntry object for {0} on domain {1}", login, serverPath);
using (DirectoryEntry de = new DirectoryEntry(serverPath, login, password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing))
{
if (!de.NativeObject.Equals(null))
{
Logger.Log("LDAP Bind Success");
}
else
{
Logger.Log("LDAP Bind Failed");
}
}
}
catch(Exception ex)
{
Logger.Log("{0} occured during LDAP Bind: {1}",ex.GetType().Name,ex.Message);
Logger.Log("Stack: {0}",ex.StackTrace);
}
}
如您所见,除了使用 System.DirectoryServices.DirectoryEntry 连接到 DC 之外,没有太多代码。
生成的日志文件是(名称和域被屏蔽)。
2010 年 6 月 29 日下午 2:52:17:为 user1 执行 AD 绑定 2010 年 6 月 29 日下午 2:52:17:启动 LDAP 绑定到 xxx.xxx 2010 年 6 月 29 日下午 2:52:17:创建 DirectoryEntry域 LDAP://xxx.xxx 上的对象 2010 年 6 月 29 日下午 2:52:17:LDAP 绑定期间发生 DirectoryServicesCOMException:登录失败:未知用户名或密码错误。
2010 年 6 月 29 日下午 2:52:17:堆栈:在 System.DirectoryServices.DirectoryEntry.Bind() 在 System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) 在 System.DirectoryServices.DirectoryEntry.get_NativeObject() 在 AdmitOne.Superglue C:\Projects\Galapagos\branches\Contract\2.0_SN_Peer\Src\Tools\Superglue\ActiveDirectoryHelper.cs:line 47 6/29/2010 2:52 中的 .ActiveDirectoryHelper.DoLDAPBind(String domain, String login, String password):下午 17 点:开始 WinNT 绑定到 xxx.xxx 2010 年 6 月 29 日下午 2:52:17:在域 WinNT://xxx.xxx 上为 user1 创建 DirectoryEntry 对象 2010 年 6 月 29 日下午 2:52:18:WinNT 绑定成功
所以相同的用户名使用LDAP绑定失败,但使用WinNT成功!
在我们的本地测试环境中,我们看不到这种行为,LDAP 和 WinNT 都成功且没有问题。
所以我被困住了。我想说这是他们的广告环境的问题,但没有确凿证据,我不能。
我首先询问堆栈,以确保我的绑定代码是正确的。之后,我可能需要重新询问 Serverfault,这是询问 AD 特定问题的更合适的地方。