Posted by lindsaym on Wed 2nd Dec 13:46 (modification of post by lindsaym view diff)
diff | download | new post
- function login_user( $username, $passphrase, $from_cookie = false ) {
- // perform a login check for username and passphrase
- // returns the user's user_id
- $username = $this->checkAlphaNum($username);
- $pass = $from_cookie? $this->checkSlashes($passphrase) : $this->checkSlashes($this->encval($passphrase));
- #XXX: START LDAP EDIT ML.11/23/2009
- //CHECK THE PROTECTED USER ARRAY AGAINST THE SUBMITTED USER FORM
- //If the user is in the protected array the ALL LDAP/AD functions will be skipped
- // and normal ZT DB authenication will be done
- foreach ($this->ldap_to_ZT_protected_users as $value){
- if($value == $username){
- $userSkip = TRUE;
- break;
- }else{
- $userSkip = FALSE;
- }
- }
- //CHECK TO SEE IF LDAP AUTH IS SET AND THE USERSKIP VAR IS FALSE
- if ($this->LDAP_login && !$userSkip){
- ldapConnect($this->ldap_server, $this->ldap_port, $this->ldap_tls_enable);
- #THIS IS WHERE THE LDAP AUTH AND REPLICATION HAPPENS
- //Create the user's RDN to bind to
- if($this->ADcompat){
- //$userDN = $username . "@" . $this->ldap_AD_domain;
- $userDN = $this->ldap_user_dn_prefix . "=" . $username . "@" . $this->ldap_AD_domain . "," . $this->ldap_user_dn;
- }else{
- $userDN = $this->ldap_user_dn_prefix . "=" . $username . "," . $this->ldap_user_dn;
- }
- if($this->full_LDAP_support){//IF TRUE THEN ALL ASPECTS OF USER MANAGEMENT WILL BE HANDLED BY LDAP
- $validUser = ldap_auth_user($userDN, $passphrase, $this->ldap_failover_support); //auth the user agianst LDAP return 0 on fail
- if($validUser == 1){
- //Verify group membership or return 0
- if(ldap_verify_group($userDN, $this->ldap_base_dn, $this->ldap_requiredGroup_dn, $this->ldap_groupMemberSearch)){
- //sync the ldap group membership and usertable. return the ldap response array
- }else{
- ldapClose();
- return 0; //not a group member denied and not replicated
- }
- }elseif($validUser == 999){ //if 999 is returned then we have hit a failover mark
- //AUTH AGAINST ZT DB
- $query = "select user_id from ".$this->table_users
- ." where login = '$username' and passphrase = $pass and active > 0";
- $user_id = $this->db_get($query);
- $this->addDebug("zentrack.class.php:login_user($user_id)",$query,2);
- if( $user_id ) { $this->getUser($user_id); };
- return($user_id);
- }else{
- //insert the access denied message here
- ldapClose();
- return 0;
- }
- //TIME FOR HOUSE CLEANING, DELETE OR MARK USERS INACTIVE IN ZT DB IF NOT IN LDAP GROUP
- //RELEASE THE LDAP CONNECTION, ALL DONE
- ldapClose();
- }else{ //IF FALSE THEN LDAP WILL ONLY DO THE INITIAL AUTHENTICATION AND PASSWORD SYNC TO ZT
- //THIS SECTION OF CODE WILL ONLY UPDATE THE ZT DB PASSWORD, USER _MUST_ EXIST IN ZT DB
- if(!ldap_auth_user($userDN, $passphrase, $this->ldap_failover_support)){ //auth the user agianst LDAP return 0 on fail
- //insert the access denied message here
- ldapClose();
- return 0;
- }else{ //Sync the password only
- //Make sure the user is in the DB
- $query = "SELECT `user_id` FROM `". $this->table_users .
- "` WHERE `login` = \"" . $username . "\" LIMIT 1";
- $user_id = $this->db_get($query);
- if(!$user_id){
- echo "<font color=\"ff0000\"><b>User: $username Does not exist in Zentrack User Table" .
- ", please contact your Systems Administrator</font></b><br>";
- return(0); //exit and throw back to the login prompt
- }else{ //go ahead and sync the password
- $query = "UPDATE `". $this->table_users . "` SET " .
- "`passphrase`=" . $pass . " WHERE " .
- "`user_id`=" . $user_id . " LIMIT 1";
- $insertionResult = $this->db_result($query);
- if(!$insertionResult){
- echo "<font color=\"ff0000\"><b>User password sync failed" .
- ", please contact your Systems Administrator</font></b><br>";
- //echo "$that->dbErrMsg <br>";
- return(0);
- }
- }
- }
- //RELEASE THE LDAP CONNECTION, ALL DONE
- ldapClose();
- }
- }
- #XXX: END LDAP EDIT ML.11/23/2009
- $query = "select user_id from ".$this->table_users
- ." where login = '$username' and passphrase = $pass and active > 0";
- $user_id = $this->db_get($query);
- $this->addDebug("zentrack.class.php:login_user($user_id)",$query,2);
- if( $user_id ) { $this->getUser($user_id); };
- return($user_id);
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.