【发布时间】: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