Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  

LDAP.Connect

Initializes an LDAP connection.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
LDAP 6.0 Yes Yes Yes Yes No

MBS( "LDAP.Connect"; IP; SSL; Port )

Parameters

Parameter Description Example value
IP The IP or domain name of the server.
If prefixed with ldap:// or ldaps://, the plugin will remove that prefix.
If prefix is ldaps://, the plugin will assume SSL is enabled.
"192.168.2.222"
SSL Whether to use SSL.
1 to enable or 0 to not enable.
1
Port The port to use.
If zero or undefined, the default port is used.
e.g. 636 for LDAPS or 389 for LDAP.
0

Result

Returns reference number or error.

Description

Initializes an LDAP connection.
Returns the references number which you pass to other LDAP functions.
Please call LDAP.Release later to close connection.

Examples

Connect to local LDAP server:

MBS( "LDAP.Connect"; "localhost"; 0; 389 )

Connect to LDAP server:

MBS( "LDAP.Connect"; "ldap.internal"; 1)

Connect via IP and special port:

MBS( "LDAP.Connect"; "192.168.1.123"; 1; 3636)

Connect using URL:

MBS( "LDAP.Connect"; "ldaps://192.168.1.123")

Connect and Query:

Delete All Records [No dialog]
#Connect
Set Variable [$r; Value:MBS("LDAP.Connect"; LDAP Query::Server; LDAP Query::SSL; LDAP Query::Port)]
If [MBS("IsError")]
    Show Custom Dialog ["LDAP error"; "Failed to connect." & ¶ & $r]
    Exit Script []
Else
    Set Variable [$ldap; Value:$r]
    #Login
    Set Variable [$r; Value:MBS("LDAP.Bind"; $ldap; LDAP Query::UserName; LDAP Query::Password; LDAP Query::AuthMethod)]
    If [MBS("IsError")]
        Show Custom Dialog ["LDAP error"; "Failed to authenticate." & ¶ & $r]
    Else
        #Search
        Set Variable [$r; Value:MBS("LDAP.Search"; $ldap; LDAP Query::Base; LDAP Query::Scope; LDAP Query::Filter; ""; 0; 20; 999)]
        #Check results
        Set Variable [$EntryCount; Value:MBS("LDAP.SearchResult.Count"; $ldap)]
        #Walk over all entries
        Set Field [LDAP Query::Entry Count; $EntryCount]
        If [$EntryCount > 0]
            Set Variable [$EntryIndex; Value:0]
            Loop
                Set Variable [$EntryName; Value:MBS("LDAP.SearchResult.DistinguishedName"; $ldap; $EntryIndex)]
                #Walk over all attributes
                Set Variable [$AttributeCount; Value:MBS("LDAP.SearchResult.AttributeCount"; $ldap; $EntryIndex)]
                If [$AttributeCount]
                    Set Variable [$AttributeIndex; Value:0]
                    Loop
                        #Check attribute name and value:
                        Set Variable [$AttributeName; Value:MBS("LDAP.SearchResult.AttributeName"; $ldap; $EntryIndex; $AttributeIndex)]
                        Set Variable [$AttributeValues; Value:MBS("LDAP.SearchResult.AttributeValues"; $ldap; $EntryIndex; $AttributeIndex; 1)]
                        #Store in a record:
                        New Record/Request
                        Set Field [LDAP Query::Entry; $EntryName]
                        Set Field [LDAP Query::Attribute; $AttributeName]
                        Set Field [LDAP Query::Values; $AttributeValues]
                        Commit Records/Requests [No dialog]
                        #next attribute
                        Set Variable [$AttributeIndex; Value:$AttributeIndex + 1]
                        Exit Loop If [$AttributeIndex = $AttributeCount]
                    End Loop
                End If
                #next entry
                Set Variable [$EntryIndex; Value:$EntryIndex + 1]
                Exit Loop If [$EntryIndex = $EntryCount]
            End Loop
        End If
    End If
    #Cleanup
    Set Variable [$r; Value:MBS("LDAP.Release"; $ldap)]
End If

See also

Example Databases


LDAP.Bind   -   LDAP.Delete

Feedback: Report problem or ask question.




Links
MBS Xojo Plugins