我在通过LDAP检索具有DistinguishedName的某些组的信息时遇到问题。这个问题似乎与他们有特殊的性格有关。
这里有两个例子,一个有效,一个无效:
所有测试组
全部在463\"567y\\22\"&2#%&!测试组
以及他们的dn:
CN=所有测试组,OU=组,DC=部分,DC=测试,DC=com
CN=所有463\"567y\\22\"/2#%&!测试组,OU=组,DC=一些,DC=测试,DC=com
我知道dn是正确的,因为我从users-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
至于我所尝试的。。。我试着将组编码为URI格式,我试着用它们的转义等价物替换特殊字符:
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")
我还尝试过通过regex来拉出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,运行在基于WindowsServer2008r2的域上。
编辑:
Active Directory错误"80040e37"
传递了一个无效的目录路径名
是当我设法传递一个带有特殊字符的错误消息时给出的。
您需要根据RFC 4515搜索过滤器的字符串表示来转义字符串
通常,您需要转义RFC 4515搜索过滤器的字符串表示中列出的项目,我建议您也转义任何非UTF8字符。
我还发现了一些可能有助于你开始的方法。
我相信你试图找到的合适的逃逸值是:全部在463"567y\5c22"\c2\a4&2#%&!测试组
最后,退出它。开始填充搜索"描述"或其他非命名属性。(任何不属于DN的属性)使您的DN永远不会更改。任何用户都不应该看到一个DN,它应该只是一个条目的路径。如果你继续这种做法,你会遇到许多"搁置"工具的问题。
我尝试过,但甚至无法在两个不同的供应商工具中创建条目。