验证域用户凭据

3
我需要一种验证Windows平台上本地C++用户/密码对的方法。 输入为用户和密码,用户可以是DOMAIN\user格式。
基本上,我需要编写一个函数: 如果用户/密码是有效的本地帐户,则返回true(第1部分) 如果用户/密码在所给域中有效,则也返回true(第2部分) 否则返回false。
使用 KB180548 我解决了(第1部分)(但我还必须检查用户名是否为有效用户,因为对于空密码的用户失败 - 不太好的解决方法,但它有效)。
然而,对于除“。”之外的任何域,上述KB示例代码对于任何用户/密码对都有效(但结果不正确)。
我已尝试使用ldap_bind_s,但它对于不正确的用户/密码对成功(可怕的访客账户?)。 此外,对于“.”域,它将对有效用户/密码失败,并显示LDAP_SERVER_DOWN(可能是因为本地主机不是域控制器?)
可能有些概念对我来说不清楚。 我希望至少我的问题能够清楚地解释。 只要它可以在C++本地代码中实现,我就不会困住在任何方法上。

这个问题 C#: 如何验证域凭据? 似乎已经解决了(除了没有被接受的答案)。不幸的是,它是用C#编写的。

编辑:来吧,Stack Overflow,你从未让我失望过...

2个回答

1

一段旧的代码,我无法测试,所以原样呈现:

//---------------------------------------------------------
// quick ADSI sample - binding to a user 
//---------------------------------------------------------

//---------------------------------------------------------
// should use unicode - saves a lot of conversion work
//---------------------------------------------------------
#define _UNICODE

//---------------------------------------------------------
// libraries needed to use ADSI
//---------------------------------------------------------
#pragma comment( lib, "Activeds.lib" )
#pragma comment( lib, "Adsiid.lib" )

//---------------------------------------------------------
// ADSI header
//---------------------------------------------------------
#include <activeds.h>

int wmain( int argc, wchar_t *argv[] )
{
  //-----------------------------------------------------
  // HRESULT hr is the return code value from all ADSI
  // calls - using the SUCCEEDED MACRO to check for 
  // success
  //-----------------------------------------------------
  HRESULT hr;

  //-----------------------------------------------------
  // pointer to our IADsUser object
  //-----------------------------------------------------
  IADsUser *pUser = NULL;

  //-----------------------------------------------------
  // path to the user we are going to try to update
  // make sure you replace this with something
  // specific to your environment
  // Form : WinNT://<domain name>/<object name>,<object class>
  //-----------------------------------------------------
  LPWSTR pszADsPath = L"WinNT://yourdomain/object name,user";
  // 
  // See available forms :
  // http://msdn.microsoft.com/en-us/library/aa746534(v=VS.85).aspx

  //-----------------------------------------------------
  // intialize the COM subsystem before doing any work
  //-----------------------------------------------------
  CoInitialize(NULL);

  //-----------------------------------------------------
  // try to get the user
  // http://msdn.microsoft.com/en-us/library/aa772184(v=VS.85).aspx
  //-----------------------------------------------------
  hr = ADsGetObject(pszADsPath, IID_IADsUser,(void**)&pUser);

  // Here Test hr
  //http://msdn.microsoft.com/en-us/library/aa772195(v=VS.85).aspx

  //-----------------------------------------------------
  // kill the COM subsystem we were using
  //-----------------------------------------------------
  CoUninitialize();

  return 0;
}

1

如果您所说的“.”域是指不受信任的域无法运行代码,则这是设计上的限制。

几年前,当我们使用支持票证时,微软的最佳解决方案是使用WNetUseConnection()。


我认为这是最接近的答案。我发现在加入域的PC上,我的代码可以工作。但在测试PC上(通过VPN连接到与域控制器相同的局域网),代码失败了。 - user581243

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接