Advertisement
Guest User

Untitled

a guest
Apr 10th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. $domain = 'acme.local';
  3. $username = 'aduser';
  4. $password = 'replaceWithPassword';
  5. $ldapconfig['host'] = '192.168.21';
  6. $ldapconfig['port'] = 389;
  7. $ldapconfig['basedn'] = 'dc=acme,dc=local';
  8.  
  9. $ldap_dn = "DC=acme,DC=local";
  10.  
  11. //print_r($ldapconfig);
  12.  
  13. $ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
  14. ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  15. ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  16.  
  17. if ($ds) {
  18. echo("ldap connect completed\n");
  19.  
  20. ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
  21. ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  22.  
  23. $bind=ldap_bind($ds, $username.'@'.$domain, $password);
  24.  
  25. if ($bind) {
  26. echo "LDAP bind successful...$bind <br />";
  27.  
  28. $attributes= array( "sn", "givenname", "mail", "samaccountname");
  29. $filter = '(&(objectCategory=person)(samaccountname=*))';
  30.  
  31. $results = ldap_search($ds, $ldap_dn, $filter, $attributes);
  32.  
  33. if ($retval) {
  34. echo("Login correct <br />");
  35. $info = ldap_get_entries($ds, $results);
  36. print_r($info);
  37.  
  38. for ($i=0; $i<$entries["count"]; $i++)
  39. {
  40. echo $entries[$i]["displayname"]
  41. [0]."(".$entries[$i]["l"][0].")<br />";
  42. }
  43. } else {
  44. echo("Login incorrect <br />".ldap_error($retval));
  45. }
  46. }else {
  47. echo "ERROR: LDAP bind failed...<br />";
  48. }
  49. ldap_unbind($bind);
  50. }
  51.  
  52. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement