Posts

Showing posts with the label php5-ldap

php5-ldap - Useful ldap snipet

This is a super useful php snipet to debug the ldap search: #============================================================================== # Configuration #============================================================================== # LDAP $ldap_url = "ldaps://ldap.server1 ldaps://ldap.server2"; $ldap_binddn = "cn=manager,dc=example,dc=com"; $ldap_bindpw = "P@ssw0rd"; $ldap_base = " dc=example,dc=com "; #$ldap_filter = "(&(objectClass=person)(uid={login}))"; $ldap_filter = "(&(objectClass=user)(sAMAccountName={login})(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"; $login = "genius"; # Connect to LDAP $ldap = ldap_connect($ldap_url); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); # Bind if ( isset($ldap_binddn) && isset($ldap_bindpw) ) { $bind = ldap_bind($ldap, $ldap_binddn, $ldap_bindpw); } else { $bind = ldap_b...

php5-ldap - Search a user in Active Directory

This php snipet helps me to produce an ldap search against an Active Directory using php5-ldap: <?php #============================================================================== # Configuration #============================================================================== # LDAP $ldap_url = "ldaps://<ldap server 1 ip> ldaps://<ldap server 2 ip>"; #$ldap_binddn = "cn=manager,dc=example,dc=com"; $ldap_binddn = "CN=Admin,OU=ArtificialUsers,DC=MyDomain,DC=COM"; $ldap_bindpw = "P@ssw0rd"; $ldap_base = "DC=MyDomain,DC=COM"; $ldap_filter = "(&(objectClass=user)(sAMAccountName={login})(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"; #============================================================================== # POST parameters #============================================================================== # Initiate vars $result = ""; $login = ""; $ldap = "...

PHP - Using php5-ldap to interact with Microsoft Active Directory from Linux

Image
To make the php5-ldap library contactable with a Microsoft Windows Active Directory server, make sure: 1. Install OpenLDAP library: sudo apt-get install slapd ldap-utils 2. Modify the config file of ldap at /etc/ldap/ldap.conf , !important: # # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. #BASE   dc=example,dc=com #URI    ldap://ldap.example.com ldap://ldap-master.example.com:666 #SIZELIMIT      12 #TIMELIMIT      15 #DEREF          never # TLS certificates (needed for GnuTLS) # TLS_CACERT    /etc/ssl/certs/ca-certificates.crt # add this TLS_REQCERT never 3. Write a test script and run: <?php $ldap = ldap_connect("ldaps://172.18.1.2"); ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3); ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0); $password="P@ssw0rd"; $binddn = "CN=Admin,OU=ArtificialUsers,DC=MyDomain,DC...