Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
Initializes an LDAP connection.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
LDAP | 6.0 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No |
Parameter | Description | Example |
---|---|---|
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. If you start with 0 here, you can later use LDAP.StartTLS to enable TLS. |
1 |
Port | The port to use. If zero or undefined, the default port is used. e.g. 636 for LDAPS or 389 for LDAP. |
3889 |
Returns reference number or error.
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
Example script to connect and bind:
# ========================================
# Purpose:
# Common routine to bind to the LDAP server
# Returns:
# $error = Error code if unsuccessful
# $error = 0 for success
# $resultText = Text summary of the success or error
# Parameters:
# $serverName
# $serverDomain
# Called from:
# (script) All "worker" LDAP scripts
# Author:
# John Munro (HJM) from Deutsche Schule Tokyo Yokohama
# Notes:
# none
# History:
# 2021-05-20 HJM - created
# ========================================
#
Set Variable [ $! ; Value: #Assign ( Get ( ScriptParameter ) ) ]
Set Variable [ $bindUsername ; Value: "filemakerbind" ]
Set Variable [ $bindPassword ; Value: “xxxxxxxxx” ]
#
Set Error Capture [ On ]
#
# If debugging these parameters will be empty so fill with test data
If [ $serverName = "" ]
Set Variable [ $serverName ; Value: "sys-xxx” ]
End If
If [ $serverDomain = "" ]
Set Variable [ $serverDomain ; Value: “xxx.com” ]
End If
#
Set Variable [ $serverFQDN ; Value: $serverName & "." & $serverDomain ]
#
# Connect
Set Variable [ $ssl ; Value: 1 ]
Set Variable [ $port ; Value: 636 ]
Set Variable [ $result ; Value: MBS( "LDAP.Connect" ; $serverFQDN ; $ssl ; $port ) ]
If [ MBS( "IsError" ) ]
// Show Custom Dialog [ "LDAP Error" ; "Failed to connect to Domain Controller." & ¶ & $result ]
Exit Script [ Text Result: # ( "error" ; $result ) & # ( "resultText" ; "LDAP error. Failed to connect to Domain Controller." & ¶ & $result ) ]
End If
#
# Login
Set Variable [ $ldap ; Value: $result ]
Set Variable [ $result ; Value: MBS("LDAP.Bind"; $ldap; $bindUsername & "@" & $serverDomain ; $bindPassword ; "simple") ]
If [ MBS( "IsError" ) ]
// Show Custom Dialog [ "LDAP Error" ; "Failed to authenticate." & ¶ & $result ]
Exit Script [ Text Result: # ( "error" ; $result ) & # ( "resultText" ; "LDAP error. Failed to authenticate." & ¶ & $result ) ]
End If
#
# Return error free result
Exit Script [ Text Result: # ( "error" ; 0 ) & # ( "resultText" ; "Bind successful" ) & # ( "ldap" ; $ldap ) ]
This function checks for a license.
Created 15th December 2015, last changed 1st December 2022