【问题标题】:How can i format an LDAP Filter that includes special characters? ('Classic' ASP)如何格式化包含特殊字符的 LDAP 过滤器? (“经典”ASP)
【发布时间】:2013-11-20 11:37:15
【问题描述】:

我无法通过 LDAP 检索我拥有 DistinguishedName 的某些组的信息。 这个问题似乎与他们有特殊字符有关。

这里有两个例子,一个有效,一个无效:
全部在测试组
全部在 463\"567y\\22\"¤&/2#%&!测试组

和他们的域名:
CN=所有在测试组中,OU=Groups,DC=some,DC=test,DC=com
CN=全部在 463\"567y\\22\"¤&/2#%&!测试组,OU=Groups,DC=some,DC=test,DC=com

我知道 dn 是正确的,因为我从用户 managedObjects 属性中检索它们,并在 AD 中验证了它们,并且还使用 ADSI Edit。

现在,关于我使用什么代码来检索信息,请注意,此代码在没有特殊字符的组上工作正常:

Dim strGroupdisplayName, strGroupsAMAccountname, strGroupmail


Function GetGroupInfofromDN(group_str)
on error resume next
DIM objGroup, objDNNamespace, strLDAPGroup
strLDAPGroup = "LDAP://" + group_str
Set objDNNamespace = GetObject("LDAP:")
Set objGroup = objDNNamespace.OpenDSObject(strLDAPGroup, strADUsername, strADPassword,0)
objGroup.GetInfo
strGroupdisplayName = ""
strGroupsAMAccountname = ""
strGroupmail = ""
strGroupdisplayName = ObjGroup.Get("displayName")
strGroupsAMAccountname = ObjGroup.Get("sAMAccountname")
strGroupmail = ObjGroup.Get("mail")
set objGroup = Nothing
End Function

至于我尝试过的...

strTemp = replace(strTemp, "\", "\5c")
strTemp = replace(strTemp, "(", "\28")
strTemp = replace(strTemp, "|", "\7c")
strTemp = replace(strTemp, "<", "\3c")
strTemp = replace(strTemp, "/", "\2f")
strTemp = replace(strTemp, ")", "\29")
strTemp = replace(strTemp, "=", "\3d")
strTemp = replace(strTemp, "~", "\7e")
strTemp = replace(strTemp, "&", "\26")
strTemp = replace(strTemp, ">", "\3e")
strTemp = replace(strTemp, "*", "\2a")

我还尝试通过正则表达式拉出 CN= 部分并仅对其进行更改。

坦率地说,我不知道我应该在这里做什么。

我也试过另一种方法:

set connAD = Server.CreateObject("ADODB.Connection")
connAD.Provider = "ADsDSOObject"
connAD.Properties("User ID") = strADUsername 
connAD.Properties("Password") = strADPassword
connAD.Properties("Encrypt Password") = true
connAD.Open

Function getADUserInfo(strUID)

    strGeneralLookupError = false
    strBase = "<LDAP://DC=SOME,DC=TEST,DC=COM>"
    strFilter = "(distinguishedName=" & strUID & ")" 
    strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber, distinguishedName, managedObjects"
    strScope = "subtree"    
    strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope
    set rsADUserInfo = Server.CreateObject("ADODB.Recordset")
    set rsADUserInfo = connAD.Execute(strFullCommand)
    set getADUserInfo = rsADUserInfo
    set rsADUserInfo = Nothing
End Function

Sub getUserData(p_strUserID)

    strADLookupSuccess = true
    set rsUserData = Server.CreateObject("ADODB.Recordset")
    set rsUserData = getADUserInfo(p_strUserID)
    if not rsUserData.EOF then
        strUserADsPath = rsUserData("ADsPath")
        strUserdistinguishedName = rsUserData("distinguishedName")
    else
        strADLookupSuccess = false
    end if
    rsUserData.Close
    set rsUserData = Nothing
End Sub

dim strUserADsPath, strUserdistinguishedName, rsUserData, rsADUserInfo, strADLookupSuccess
getUserData("CN=All in 463\"567y\\\\22\"¤&/2\#%&! Test Group,OU=Groups,DC=some,DC=test,DC=com")

connAD.Close
set connAD = Nothing

有什么建议吗?到目前为止我读过的所有东西都提到了特殊字符,但转义它们似乎不起作用......

此外,这是经典 ASP,针对基于 Windows Server 2008 r2 的域运行。

编辑:

Active Directory 错误“80040e37”

传递了一个无效的目录路径名

当我设法通过特殊字符时给出错误消息。

【问题讨论】:

  • 为什么要创建这种格式的 DN?
  • 当然,DN 是在创建组时设置的,虽然我可能不会创建一个如此时髦的格式,但我们会使用斜杠、哈希或 & 符号并不是牵强附会。我们也偶尔使用引号。例如:All in Team Leaders(俄亥俄州),所有“快乐”的员工。 (糟糕的组示例,但我们确实使用了这些字符!)我们也使用@符号。虽然限制使用的字符很容易,但当我们已经在运营几千个组时,为时已晚。 (此时重命名不是一个选项)关于特殊字符转义到这个级别的任何想法?

标签: asp-classic ldap ldap-query


【解决方案1】:

你需要根据RFC 4515 String Representation of Search Filters转义字符串

通常,您需要转义 RFC 4515 String Representation of Search Filters 中列出的项目,我建议您也可以转义任何非 UTF8 字符。

我还找到了一些 methods that may be helpful 来帮助您入门。

我相信您试图找到的正确转义值是: 全部在 463"567y\5c22"\c2\a4&/2#%&!测试组

最后,放弃它。 开始填充搜索描述或其他一些非命名属性。 (任何不属于 DN 的属性)让您的 DN 永不改变。任何用户都不应该看到应该只是条目路径的 DN。如果您继续这种做法,您将遇到许多“现成”工具的问题。

我尝试过,甚至无法在两个不同的供应商工具中创建条目。

【讨论】:

  • 这是我需要的正确方向的推动!为了解决这个问题,我将 ADSI Edit 字符串与“managedBy”给出的字符串进行了比较,注意了不同的字符,阅读了有关转义内容和方式的链接,最后只转义了字符“/”(转义为“\/ ”)。我现在有一个实际上是通过 LDAP 找到的乱码列表。谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多