use*_*708 3 ldap ldap-query asp-classic
我在通过 LDAP 检索我具有 DistinguishedName 的某些组的信息时遇到问题。\n该问题似乎与它们具有特殊字符有关。
\n\n这里有两个例子,一个有效,一个无效:
\nAll in Test Group
\nAll in 463\\"567y\\\\22\\"\xc2\xa4&/2#%&! 测试组
及其 DN:
\nCN=测试组中的所有内容、OU=Groups、DC=some、DC=test、DC=com
\nCN=463\\"567y\\\\22\\"\xc2 中的所有内容\xa4&/2#%&! 测试组、OU=组、DC=某些、DC=测试、DC=com
我知道 dn\ 是正确的,因为我从用户的 ManagedObjects 属性中检索它们,并已在 AD 中验证它们并使用 ADSI 编辑。
\n\n现在,看看我使用什么代码来检索信息,请注意,此代码在没有特殊字符的组上运行良好:
\n\nDim strGroupdisplayName, strGroupsAMAccountname, strGroupmail\n\n\nFunction GetGroupInfofromDN(group_str)\non error resume next\nDIM objGroup, objDNNamespace, strLDAPGroup\nstrLDAPGroup = "LDAP://" + group_str\nSet objDNNamespace = GetObject("LDAP:")\nSet objGroup = objDNNamespace.OpenDSObject(strLDAPGroup, strADUsername, strADPassword,0)\nobjGroup.GetInfo\nstrGroupdisplayName = ""\nstrGroupsAMAccountname = ""\nstrGroupmail = ""\nstrGroupdisplayName = ObjGroup.Get("displayName")\nstrGroupsAMAccountname = ObjGroup.Get("sAMAccountname")\nstrGroupmail = ObjGroup.Get("mail")\nset objGroup = Nothing\nEnd Function\nRun Code Online (Sandbox Code Playgroud)\n\n至于我尝试过的...我尝试将组编码为 URI 格式,我尝试用转义的等效字符替换特殊字符:
\n\nstrTemp = replace(strTemp, "\\", "\\5c")\nstrTemp = replace(strTemp, "(", "\\28")\nstrTemp = replace(strTemp, "|", "\\7c")\nstrTemp = replace(strTemp, "<", "\\3c")\nstrTemp = replace(strTemp, "/", "\\2f")\nstrTemp = replace(strTemp, ")", "\\29")\nstrTemp = replace(strTemp, "=", "\\3d")\nstrTemp = replace(strTemp, "~", "\\7e")\nstrTemp = replace(strTemp, "&", "\\26")\nstrTemp = replace(strTemp, ">", "\\3e")\nstrTemp = replace(strTemp, "*", "\\2a")\nRun Code Online (Sandbox Code Playgroud)\n\n我还尝试通过正则表达式提取 CN= 部分并仅更改它。
\n\n坦率地说,我不知道自己应该在这里做什么。
\n\n我还尝试过另一种方法:
\n\nset connAD = Server.CreateObject("ADODB.Connection")\nconnAD.Provider = "ADsDSOObject"\nconnAD.Properties("User ID") = strADUsername \nconnAD.Properties("Password") = strADPassword\nconnAD.Properties("Encrypt Password") = true\nconnAD.Open\n\nFunction getADUserInfo(strUID)\n\n strGeneralLookupError = false\n strBase = "<LDAP://DC=SOME,DC=TEST,DC=COM>"\n strFilter = "(distinguishedName=" & strUID & ")" \n strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber, distinguishedName, managedObjects"\n strScope = "subtree" \n strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope\n set rsADUserInfo = Server.CreateObject("ADODB.Recordset")\n set rsADUserInfo = connAD.Execute(strFullCommand)\n set getADUserInfo = rsADUserInfo\n set rsADUserInfo = Nothing\nEnd Function\n\nSub getUserData(p_strUserID)\n\n strADLookupSuccess = true\n set rsUserData = Server.CreateObject("ADODB.Recordset")\n set rsUserData = getADUserInfo(p_strUserID)\n if not rsUserData.EOF then\n strUserADsPath = rsUserData("ADsPath")\n strUserdistinguishedName = rsUserData("distinguishedName")\n else\n strADLookupSuccess = false\n end if\n rsUserData.Close\n set rsUserData = Nothing\nEnd Sub\n\ndim strUserADsPath, strUserdistinguishedName, rsUserData, rsADUserInfo, strADLookupSuccess\ngetUserData("CN=All in 463\\"567y\\\\\\\\22\\"\xc2\xa4&/2\\#%&! Test Group,OU=Groups,DC=some,DC=test,DC=com")\n\nconnAD.Close\nset connAD = Nothing\nRun Code Online (Sandbox Code Playgroud)\n\n有什么建议么?到目前为止我读过的所有内容都提到了特殊字符,但转义它们似乎不起作用......
\n\n此外,这是经典 ASP,针对基于 Windows Server 2008 r2 的域运行。
\n\n编辑:
\n\n\n\n\nActive Directory 错误“80040e37”
\n\n传递了无效的目录路径名
\n
当我设法传递带有特殊字符的错误消息时,是否给出了错误消息。
\n您需要根据RFC 4515 搜索过滤器的字符串表示法对字符串进行转义
一般来说,您需要转义RFC 4515 搜索过滤器字符串表示形式中列出的项目,我建议也转义任何非 UTF8 字符。
我还发现了一些可能有助于您入门的方法。
我相信您试图找到的正确转义值是: All in 463"567y\5c22"\c2\a4&/2#%&! 测试组
最后,放弃吧。开始填充对描述或某些其他非命名属性的搜索。(不属于 DN 一部分的任何属性)使您的 DN 永远不会改变。任何用户都不应该看到 DN,它应该只是条目的路径。如果继续这种做法,您将遇到许多“现成”工具的问题。
我尝试过,甚至无法在两个不同的供应商工具中创建该条目。
| 归档时间: |
|
| 查看次数: |
21371 次 |
| 最近记录: |