Overview

Packages

  • None
  • Passwd

Classes

  • Passwd
  • Passwd_Driver
  • Passwd_Driver_Adsi
  • Passwd_Driver_Composite
  • Passwd_Driver_Expect
  • Passwd_Driver_Expectpecl
  • Passwd_Driver_Horde
  • Passwd_Driver_Http
  • Passwd_Driver_Kolab
  • Passwd_Driver_Ldap
  • Passwd_Driver_Pine
  • Passwd_Driver_Poppassd
  • Passwd_Driver_Procopen
  • Passwd_Driver_Pspasswd
  • Passwd_Driver_Servuftp
  • Passwd_Driver_Smbldap
  • Passwd_Driver_Smbpasswd
  • Passwd_Driver_Soap
  • Passwd_Driver_Sql
  • Passwd_Driver_Vmailmgr
  • Passwd_Driver_Vpopmail
  • Passwd_Exception
  • Passwd_Factory_Driver
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The serv-u ftp class attempts to change a user's password via the SITE PSWD
  4:  * command used by Serv-u ftpd for windows.
  5:  *
  6:  * Copyright 2000-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
 10:  *
 11:  * @author  Lucas Nelan (screen@brainkrash.com)
 12:  * @package Passwd
 13:  */
 14: class Passwd_Driver_Servuftp extends Passwd_Driver
 15: {
 16:     const CONNECTED   = '220';
 17:     const GOODBYE     = '221';
 18:     const PASSWORDOK  = '230';
 19:     const USERNAMEOK  = '331';
 20:     const PASSWORDBAD = '530';
 21: 
 22:     protected $_fp;
 23: 
 24:     /**
 25:      * Constructor.
 26:      *
 27:      * @param array $params  A hash containing connection parameters.
 28:      *
 29:      * @throws Passwd_Exception
 30:      */
 31:     public function __construct($params = array())
 32:     {
 33:         if (empty($params['host']) || empty($params['port'])) {
 34:             throw new Passwd_Exception(_("Password module is missing required parameters."));
 35:         }
 36:         parent::__construct(array_merge(array('timeout' => 30), $params));
 37:     }
 38: 
 39:     /**
 40:      * Changes the user's password.
 41:      *
 42:      * @param string $user_name     The user for which to change the password.
 43:      * @param string $old_password  The old (current) user password.
 44:      * @param string $new_password  The new user password to set.
 45:      *
 46:      * @throws Passwd_Exception
 47:      */
 48:     protected function changePassword($user_name, $old_password, $new_password)
 49:     {
 50:         if ($this->_connect() != self::CONNECTED) {
 51:             throw new Passwd_Exception(_("Connection failed"));
 52:         }
 53:         if ($this->_sendCommand('user', $user_name) != self::USERNAMEOK) {
 54:             $this->_disconnect();
 55:             throw new Passwd_Exception(_("Unknown user"));
 56:         }
 57:         if ($this->_sendCommand('pass', $old_password) != self::PASSWORDOK) {
 58:             $this->_disconnect();
 59:             throw new Passwd_Exception(_("Incorrect password"));
 60:         }
 61:         if ($this->_sendCommand('site pswd', '"' . $old_password . '" "' . $new_password . '"') != self::PASSWORDOK) {
 62:             $this->_disconnect();
 63:             throw new Passwd_Exception(_("Cannot change password"));
 64:         }
 65:         $this->_disconnect();
 66:     }
 67: 
 68:     protected function _connect()
 69:     {
 70:         $this->_fp = fsockopen($this->_params['host'], $this->_params['port'],
 71:                                $errno, $errstr, $this->_params['timeout']);
 72:         if (!$this->_fp) {
 73:             throw new Passwd_Exception($errstr);
 74:         }
 75:         return $this->_getPrompt();
 76:     }
 77: 
 78:     protected function _disconnect()
 79:     {
 80:         if ($this->_fp) {
 81:             fputs($this->_fp, "quit\n");
 82:             fclose($this->_fp);
 83:         }
 84:     }
 85: 
 86:     protected function _getPrompt()
 87:     {
 88:         $prompt = fgets($this->_fp, 4096);
 89: 
 90:         if (preg_match('/^[1-5][0-9][0-9]/', $prompt, $res)) {
 91:             return $res[1];
 92:         }
 93:     }
 94: 
 95:     protected function _sendCommand($cmd, $arg)
 96:     {
 97:         $line = $cmd . ' ' . $arg . "\r\n";
 98:         fputs($this->_fp, $line);
 99:         return $this->_getPrompt();
100:     }
101: }
102: 
API documentation generated by ApiGen