Connecting to an OpenLDAP server in vbScript via openDSObject

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 cannot understand the syntax to make this work against OpenLDAP Server:

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

Honestly, I'm a little n00b when it comes to LDAP, so I don’t understand what dc vs cn vs ou is (I know that they are behind the unit of organization, common name, etc.), but I don’t know ' t get when you need to relate this to requests.

As soon as I connect to the Active Directory server, the following code will request 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 understand that the name sAMAccountName is specific to AD, so a different syntax is needed for openLDAP code.

User "ldapuser" with the password "password", which is stored here: NU = Users, DC = domain, DC = COM

LDAP ?

+3
2

, , :

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
+1

Thanx .
, ( ) 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
+1

Source: https://habr.com/ru/post/1705684/


All Articles