changed git call from https to git readonly
[atutor.git] / mods / wiki / plugins / auth / users_ldap.php
1 <?php
2
3 /*
4    Check username and password by connecting to LDAP server.
5 */
6
7
8 #-- config
9 define("EWIKI_LDAP_SERVER", "ldap.example.com");
10 define("EWIKI_LDAP_RDN", 'cn=$USER,ou=users,dc=example,dc=com');
11 define("EWIKI_LDAP_FILTER", "");    // sn=* ???
12 define("EWIKI_LDAP_RING", 2);
13
14
15 #-- glue
16 $ewiki_plugins["auth_userdb"][] = "ewiki_auth_userdb_ldap";
17
18
19
20 function ewiki_auth_userdb_ldap($username, $password=NULL) {
21
22    #-- connect   
23    if ($conn = ldap_connect(EWIKI_LDAP_SERVER)) {
24
25       #-- vars
26       $rdn = preg_replace('/[$%_]+\{USER\}|[$%]+USER[$%]?/i', $username, EWIKI_LDAP_RDN);
27       $search = EWIKI_LDAP_SEARCH;
28
29       #-- bind to domain
30       if (ldap_bind($conn, $rdn, $password)) {
31
32          #-- connected == authenticated
33          if (!$search || ldap_count_entries($conn, ldap_search($conn, $rdn, $search)) ) {
34
35             ldap_close($conn);
36
37             #-- return password array() as true value for userdb plugins
38             return(array($password, EWIKI_LDAP_RING));
39          }
40
41       }
42
43       ldap_close($conn);
44    }
45    return(false);
46 }
47
48 ?>