diff -r 000000000000 -r 472198dc918e backend_isode_ldap.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backend_isode_ldap.php Thu May 13 09:31:01 2010 -0500 @@ -0,0 +1,106 @@ +hostname = $config['ldapHostname']; + if(array_key_exists('ldapPort', $config)) + $this->port = $config['ldapPort']; + if(array_key_exists('ldapBindDN', $config)) + $this->bind_dn = $config['ldapBindDN']; + if(array_key_exists('ldapBindPass', $config)) + $this->bind_pw = $config['ldapBindPass']; + if(array_key_exists('ldapBaseDN', $config)) + $this->base_dn = $config['ldapBaseDN']; + + if($config['debug']) + $this->debug = TRUE; + + $this->ldap = ldap_connect($this->hostname, $this->port) + or die("Cannot connect to DSA"); + + ldap_set_option($this->ldap, LDAP_OPT_PROTOCOL_VERSION, 3); + + ldap_bind($this->ldap, $this->bind_dn, $this->bind_pw) + or die("Cannot bind to DSA"); + } + + function validate($user, $pass) + { + if(strcspn($user, " \"#+,;<=>\\") !== strlen($user)) + return "Your username contains invalid characters."; + return NULL; + } + + function exists($user) + { + $dn = "uid=" . $user . "," . $this->base_dn; + $res = @ldap_read($this->ldap, $dn, "objectClass=inetOrgPerson"); + if($res === FALSE) + return FALSE; + return TRUE; + } + + function create($user, $pass) + { + $dn = "uid=" . $user . "," . $this->base_dn; + + $attrs["objectClass"] = $this->objectClass; + $attrs["uid"] = $user; + $attrs["userPassword"] = $pass; + + # X.500 person class requires a Surname. + $attrs["sn"] = $user; + + # Something else (?) requires a CommonName. + $attrs["cn"] = $attrs["sn"]; + + if (@ldap_add($this->ldap, $dn, $attrs)) + { + return TRUE; + } + else + { + if($this->debug) + { + $errno = ldap_errno($this->ldap); + echo "

Exciting error number " . $errno . ": " . ldap_err2str($errno) . "

"; + echo "

DN: " . $dn . "

"; + echo "

Attrs:

";
+				print_r($attrs);
+				echo "

"; + } + return FALSE; + } + } + + + function close() + { + ldap_unbind($this->ldap); + } +} + +?>