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:  * Passwd base class.
  4:  *
  5:  * Copyright 2000-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (GPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
  9:  *
 10:  * @author Mike Cochrane <mike@graftonhall.co.nz>
 11:  * @package Passwd
 12:  */
 13: class Passwd
 14: {
 15:     static public function getBackends()
 16:     {
 17:         $allbackends = Horde::loadConfiguration('backends.php', 'backends', 'passwd');
 18:         if (!isset($allbackends) || !is_array($allbackends)) {
 19:             throw new Passwd_Exception(_("No backends configured in backends.php"));
 20:         }
 21: 
 22:         $backends = array();
 23:         foreach ($allbackends as $name => $backend) {
 24:             if (!empty($backend['disabled'])) {
 25:                 continue;
 26:             }
 27: 
 28:             /* Make sure the 'params' entry exists. */
 29:             if (!isset($backend['params'])) {
 30:                 $backend['params'] = array();
 31:             }
 32: 
 33:             if (!empty($backend['preferred'])) {
 34:                 if (is_array($backend['preferred'])) {
 35:                     foreach ($backend['preferred'] as $val) {
 36:                         if (($val == $_SERVER['SERVER_NAME']) ||
 37:                             ($val == $_SERVER['HTTP_HOST'])) {
 38:                             $backends[$name] = $backend;
 39:                         }
 40:                     }
 41:                 } elseif (($backend['preferred'] == $_SERVER['SERVER_NAME']) ||
 42:                           ($backend['preferred'] == $_SERVER['HTTP_HOST'])) {
 43:                     $backends[$name] = $backend;
 44:                 }
 45:             } else {
 46:                 $backends[$name] = $backend;
 47:             }
 48:         }
 49: 
 50:         /* Check for valid backend configuration. */
 51:         if (empty($backends)) {
 52:             throw new Passwd_Exception(_("No backend configured for this host"));
 53:         }
 54: 
 55:         return $backends;
 56:     }
 57: 
 58:     /**
 59:      * Determines if the given backend is the "preferred" backend for this web
 60:      * server.
 61:      *
 62:      * This decision is based on the global 'SERVER_NAME' and 'HTTP_HOST'
 63:      * server variables and the contents of the 'preferred' field in the
 64:      * backend's definition.  The 'preferred' field may take a single value or
 65:      * an array of multiple values.
 66:      *
 67:      * @param array $backend  A complete backend entry from the $backends hash.
 68:      *
 69:      * @return boolean  True if this entry is "preferred".
 70:      */
 71:     static public function isPreferredBackend($backend)
 72:     {
 73:         if (!empty($backend['preferred'])) {
 74:             if (is_array($backend['preferred'])) {
 75:                 foreach ($backend['preferred'] as $backend) {
 76:                     if ($backend == $_SERVER['SERVER_NAME'] ||
 77:                         $backend == $_SERVER['HTTP_HOST']) {
 78:                         return true;
 79:                     }
 80:                 }
 81:             } elseif ($backend['preferred'] == $_SERVER['SERVER_NAME'] ||
 82:                       $backend['preferred'] == $_SERVER['HTTP_HOST']) {
 83:                 return true;
 84:             }
 85:         }
 86: 
 87:         return false;
 88:     }
 89: 
 90:     /**
 91:      * Changes the cached Horde credentials.
 92:      *
 93:      * Should be called only after a successful change of the password in the
 94:      * actual backend storage.
 95:      *
 96:      * @param string $username      The username we're changing.
 97:      * @param string $oldpassword   The old user password.
 98:      * @param string $new_password  The new user password to set.
 99:      */
100:     static public function resetCredentials($old_password, $new_password)
101:     {
102:         if ($GLOBALS['registry']->getAuthCredential('password') == $old_password) {
103:             $GLOBALS['registry']->setAuthCredential('password', $new_password);
104:         }
105:     }
106: }
107: 
API documentation generated by ApiGen