【问题标题】:What is the proper way to get some specific user attributes from Active Directory via LDAP C API?通过 LDAP C API 从 Active Directory 获取某些特定用户属性的正确方法是什么?
【发布时间】:2016-05-21 04:54:16
【问题描述】:

我正在尝试使用 Windows LDAP API 从 Active Directory 获取一些用户属性。我正在使用:

  • Active Directory 版本:Windows Server 2012 附带的版本
  • LDAP 版本:3
  • Wldap32.lib 版本:Windows 10 x64 自带的版本

例如:

PCHAR myAttributes[4];

myAttributes[0] = "DistinguishedName";
myAttributes[1] = "DisplayName";
myAttributes[2] = "PasswordExpired";
myAttributes[3] = "mail";

ldap_search_s(
    myLdapConnection,   // Ldap connection
    myDomain,           // DN to start search
    LDAP_SCOPE_SUBTREE, // Scope
    myFilter,           // Filter
    myAttributes,       // Retrieve list of attributes
    0,                  // Get both attributes and values
    &mySearchResult     // [out] Search results
); 

它返回DistinguishedName、DisplayName 和mail 属性,但不返回PasswordExpired 属性。

我查询了其他一些属性,但它似乎没有返回具有布尔值的属性以及 EmailAddress 属性。

  1. 为什么不返回PasswordExpired属性?
  2. EmailAddress 呢?
  3. EmailAddress 和 mail 有区别吗?

【问题讨论】:

    标签: c windows active-directory ldap


    【解决方案1】:
    1. Active Directory 中没有 PasswordExpired LDAP 属性。要构建您的查询,请查看标准 Active Directory 架构 https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx 中属性名称的 URL。要检查给定帐户的密码是否过期,您需要检查 userAccountControl 属性,该属性实际上是存储用户帐户https://msdn.microsoft.com/en-us/library/ms680832(v=vs.85).aspx 不同状态标志的值。如果您不必坚持使用 LDAP https://msdn.microsoft.com/en-us/library/aa746343(v=vs.85).aspx

    2. ,则有 IADsUser 界面将为您翻译所有内容
    3. 您将在邮件属性中找到当前的主电子邮件地址。没有 EmailAddress LDAP 属性,除非您的意思是 E-mail-Addresses,它是 CN 与邮件相同的架构属性,所以没有区别。

    4. 见上文。一般来说,如果您没有令人信服的理由坚持使用 C/LDAP,我建议您改用 .Net Framework。否则你有很多工作要做——不仅仅是解释位标志,比如密码过期,还可能使用不同的身份验证方法、不同的结构捕获时间和日期、考虑时区、UTF、追逐推荐和其他你可能会做的事情需要取决于您想要实现的复杂性。您将在 .Net Framework 中更快地提高生产力。有关详细信息,请参阅 DirectoryServices https://msdn.microsoft.com/en-us/library/mt481534(v=vs.110).aspx 命名空间或安全命名空间 https://msdn.microsoft.com/en-us/library/mt481561(v=vs.110).aspx。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-09-07
      相关资源
      最近更新 更多