通过 openDSObject 在 vbScript 中连接到 OpenLDAP 服务器

发布于 2024-07-15 22:30:54 字数 1159 浏览 11 评论 0原文

我有可以正确连接到 Active Directory 服务器的代码:

Dim oDSObj: Set oDSObj = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDSObj.OpenDSObject("LDAP://ldap.domain.com", "DOMAIN\username", "password", 1)

但是,我似乎无法弄清楚使其在 OpenLDAP 服务器上工作的语法:

Dim oDSObj: Set oDSObj = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDSObj.OpenDSObject("LDAP://ldap.domain.com/ou=Users", "username", "password", 1)

说实话,当它出现时,我有点无知到 LDAP,所以我不明白 dc、cn 和 ou 的含义(我知道它们代表组织单位、通用名称等),但我不明白何时需要将其附加到查询中。

一旦我连接到 Active Directory 服务器,以下代码就会对其进行查询:

dc = ""
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "Ads Provider", "DOMAIN\username", "password"            '
Dim rs: Set rs = oConn.Execute("<LDAP://ldap.domain.com" & dc & ">;(& (objectCategory=person)(objectClass=user)(sAMAccountName=" & GetLDAPUserName(sPerson) & "));name,mail,telephoneNumber;subtree")

但我意识到 sAMAccountName 是 AD 特定的东西,因此 openLDAP 代码将需要不同的语法。

用户是“ldapuser”,密码是“password”,存储在此处: ou=Users,dc=domain,dc=com

连接到 LDAP 服务器并查询帐户信息的代码是什么?

I have code that works correctly to connect to an Active Directory server:

Dim oDSObj: Set oDSObj = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDSObj.OpenDSObject("LDAP://ldap.domain.com", "DOMAIN\username", "password", 1)

However, I can't seem to figure out the syntax to make this work against an OpenLDAP Server:

Dim oDSObj: Set oDSObj = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDSObj.OpenDSObject("LDAP://ldap.domain.com/ou=Users", "username", "password", 1)

To be honest, I'm a bit of a n00b when it comes to LDAP, so I don't understand what dc vs cn vs ou means (I know they stand for org unit, common name etc) but I don't get when you need to tack that on to queries.

Once I connect to the Active Directory server, the following code queries it:

dc = ""
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "Ads Provider", "DOMAIN\username", "password"            '
Dim rs: Set rs = oConn.Execute("<LDAP://ldap.domain.com" & dc & ">;(& (objectCategory=person)(objectClass=user)(sAMAccountName=" & GetLDAPUserName(sPerson) & "));name,mail,telephoneNumber;subtree")

But I realize that sAMAccountName is an AD specific thing, so the openLDAP code will need a different syntax.

The user is 'ldapuser' with a password of 'password', stored here:
ou=Users,dc=domain,dc=com

What is the code to connect to that LDAP server and query for account info?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪 2024-07-22 22:30:54

我终于弄明白了:

sUser = "myusername"
sDN = "cn=" & sUser & ",ou=people,dc=company,dc=com"
sRoot = "LDAP://ldapservername.com/dc=company,dc=com"

Dim oDS: Set oDS = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "password", &H0200)

Dim oConn: Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "Ads Provider", sDN, "password"

Dim rs
Set rs = oConn.Execute("<" & sRoot & ">;(uid=" & sUser & ");cn,mail,telephoneNumber;subtree")

wscript.echo rs("cn").value
wscript.echo rs("mail").value
wscript.echo rs("telephoneNumber").value

I finally figured it out:

sUser = "myusername"
sDN = "cn=" & sUser & ",ou=people,dc=company,dc=com"
sRoot = "LDAP://ldapservername.com/dc=company,dc=com"

Dim oDS: Set oDS = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "password", &H0200)

Dim oConn: Set oConn = CreateObject("ADODB.Connection")
oConn.Provider = "ADSDSOObject"
oConn.Open "Ads Provider", sDN, "password"

Dim rs
Set rs = oConn.Execute("<" & sRoot & ">;(uid=" & sUser & ");cn,mail,telephoneNumber;subtree")

wscript.echo rs("cn").value
wscript.echo rs("mail").value
wscript.echo rs("telephoneNumber").value
浅沫记忆 2024-07-22 22:30:54

非常感谢你的代码迈克尔。
我已将其修改为使用中央 OpenLDAP 服务器简单地验证用户(用户密码)。 这是对我有用的代码(MSAccess 2003):

sUser = "TheUserName"
sDN = "uid=" & sUser & ",o=users,dc=MyDomain,dc=it"
sRoot = "LDAP://MyLDAPServer/o=users,dc=MyDomain,dc=it"

Dim oDS: Set oDS = GetObject("LDAP:")

On Error GoTo AuthError
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "ThePassword", &H200)
On Error GoTo 0

MsgBox "Login Successful"
Exit Sub

AuthError:
If Err.Number = -2147023570 Then
    MsgBox "Wrong Username or password !!!"
End If
On Error GoTo 0

Thanx a lot for your code Michael.
I've modified it to simply authenticate users (user-password) using the central OpenLDAP server. Here is the code that worked for me (MSAccess 2003):

sUser = "TheUserName"
sDN = "uid=" & sUser & ",o=users,dc=MyDomain,dc=it"
sRoot = "LDAP://MyLDAPServer/o=users,dc=MyDomain,dc=it"

Dim oDS: Set oDS = GetObject("LDAP:")

On Error GoTo AuthError
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "ThePassword", &H200)
On Error GoTo 0

MsgBox "Login Successful"
Exit Sub

AuthError:
If Err.Number = -2147023570 Then
    MsgBox "Wrong Username or password !!!"
End If
On Error GoTo 0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文