HordePasswdDriverPostfixadmin

From xbe wiki

Jump to: navigation, search

I did the same in passwd as in vacation - wrote an own driver. In the case of passwd i use the mysql ENCRYPT() function and the own sql driver from passwd doesn't seem to support that. To make it easy, i just changed the default sql module, made it less generic ;-)

[edit] File: lib/Driver/sql.php

<?php

class Passwd_Driver_sql extends Passwd_Driver {

    /**
     * SQL connection object.
     *
     * @var DB
     */
    var $_db;

    /**
     * State of SQL connection.
     *
     * @var boolean
     */
    var $_connected false;

    /**
     * Constructs a new Passwd_Driver_sql object.
     *
     * @param array $params  A hash containing connection parameters.
     */
    function Passwd_Driver_sql($params = array())
    {
    }

    /**
     * Connect to the database.
     *
     * @return boolean  True on success or PEAR_Error on failure.
     */
    function _connect()
    {
       $conn mysql_connect("localhost","***","***");
       mysql_select_db("***");
        return true;
    }

    function _lookup($user$old_password)
    {
        /* Connect to the database */
        $res $this->_connect();
        $user Auth::getAuth();

        $old_password mysql_escape_string($old_password);
        $strQuery "select * from mailbox where `username`='{$user}' and `clear`=encrypt('{$old_password}', LEFT(`clear`,2) )";
        $rs mysql_query($strQuery);
        if(mysql_num_rows($rs) > 0) {
                return true;
        }else{
                return PEAR::raiseError(_("User not found"));
        }
    }

    /**
     * Modify (update) a mysql password record for a user.
     *
     * @param string $user          The user whose record we will udpate.
     * @param string $new_password  The new password value to set.
     *
     * @return boolean  True or False based on success of the modify.
     */
    function _modify($user$new_password)
    {
        /* Connect to the database. */
        $res $this->_connect();
        $user Auth::getAuth();

        $strQuery "update mailbox set `clear`=encrypt('".mysql_escape_string($new_password)."',LEFT(`clear`,2)) where username='{$user}' limit 1";
        $rs mysql_query($strQuery);
        if(mysql_affected_rows($rs) > 0) {
                return true;
        }else{
                return false;
        }
    }

    function _parseQuery($string$user$password)
    {
    }

    /**
     * Change the user's password.
     *
     * @param string $username      The user for which to change the password.
     * @param string $old_password  The old (current) user password.
     * @param string $new_password  The new user password to set.
     *
     * @return boolean  True or false based on success of the change.
     */
    function changePassword($username,  $old_password$new_password)
    {
        /* Check the current password. */
        $res $this->_lookup($username$old_password);
        if (is_a($res'PEAR_Error'))  {
            return $res;
        }

        return $this->_modify($username$new_password);
    }

}

?>

Makes it all just easy. Passwd has also this old horde style backend select thing were i never know which backend it actually picks and I have no idea how to explicitly set a specific backend. vacation has this made better where I can choose the a backend in the config section. Man..

Personal tools