private function deleteLDAP() { global $LDAP_ADMIN_DN, $LDAP_ADMIN_PW, $TOOL_SHORT; // write the values to LDAP if (ldapConnect()) { // bind with appropriate dn to give update access $admin_bind = ldap_bind(getDS(), $LDAP_ADMIN_DN, $LDAP_ADMIN_PW); if ($admin_bind) { $item_dn = "iid={$this->pk},ou=institutions,dc=sakaiproject,dc=org"; $delresult = ldap_delete(getDS(), $item_dn); if ($delresult) { $this->Message = "Removed ldap institution: {$item_dn}"; return true; } else { $this->Message = "Failed to remove ldap inst: {$item_dn}"; } } else { $this->Message = "Critical ERROR: Admin bind failed"; } return false; } return false; }
function auth($dn = "", $netid = "", $password = "") { //echo "<br/>Attempting auth<br/>"; if (!$this->ldap) { // Connect to the ldap server $this->ldap = ldapConnect(); } if ($dn == "") { // Generate the search filter to find the // DN we are trying to log in as $filter = $this->makeFilter("netid", "=", $netid); // Find it... $result = @ldap_search($this->ldap, $this->ldap_login_base, $filter); // Make sure we got one and only one... if ($result) { $count = @ldap_count_entries($this->ldap, $result); if ($count === 1) { $entry = @ldap_get_entries($this->ldap, $result); if (!$entry) { // Uhoh... no entries were returned... something broke $error = ldap_error($this->ldap); print "<p>Error: " . $error . "<br />\n"; return False; } $this->dn = $entry[0]["dn"]; $this->netid = $netid; // Ok, now verify the dn/password combination... ldap_close($this->ldap); $this->ldap = $this->ldapConnect(); $bind = @ldap_bind($this->ldap, $this->dn, $password); if (!$bind) { // User screwed up... $error = ldap_error($this->ldap); print "<p>Error: " . $error . "<br />\n"; return False; } $this->password = $password; $this->cracker = $this->makeCookie($this->dn, $this->password); //echo "<br/>cookie made: {$this->cracker}<br/>"; } elseif ($count === 0) { print "<p>Error: Invalid ID and/or Password.<br />"; return False; } else { print "<p>Attribute netid: '{$netid}' is not unique."; return False; } } else { print "<p>Error: " . ldap_error($this->ldap) . "<br />\n"; return False; } } else { // We were passed a DN, let's see if it works :-) $bind = @ldap_bind($this->ldap, $dn, $password); if (!$bind) { // User screwed up... $error = ldap_error($this->ldap); print "<p>Error: {$error}<br />\n"; return False; } if (strcmp($dn, $this->dn)) { $this->dn = $dn; $this->password = $password; } } return True; }