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 ADSI class changes a user's password on any Windows Machine/NT-Domain
 4:  * using the ADSI COM Interface.
 5:  *
 6:  * NOTES:
 7:  *
 8:  * - If you plan to implement passwd over Active Direcory you must use the
 9:  *   LDAP driver and not this one! This driver is designed for standalone
10:  *   machines or NT4 domains, only.
11:  *
12:  * - The host server must be Win32 with ADSI support.
13:  *
14:  * Sample backend configuration:
15:  * <code>
16:  * $backends['adsi'] = array(
17:  *    'name' => 'Sample ADSI backend',
18:  *    'preferred' => 'localhost',
19:  *    'policy' => array(
20:  *        'minLength' => 8,
21:  *        'maxLength' => 14
22:  *    ),
23:  *    'driver' => 'adsi',
24:  *    'params' => array(
25:  *        'target' => 'YOUR_MACHINE/DOMAIN_NAME_HERE'
26:  *    )
27:  * )
28:  * </code>
29:  *
30:  * Backend parameters:
31:  * target = Target Windows machine/domain name (Required)
32:  *
33:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
34:  *
35:  * See the enclosed file COPYING for license information (GPL). If you
36:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
37:  *
38:  * @author  Luiz R Malheiros <malheiros@gmail.com>
39:  * @package Passwd
40:  */
41: class Passwd_Driver_Adsi extends Passwd_Driver
42: {
43:     /**
44:      * Changes the user's password.
45:      *
46:      * @param string $user_name     The user for which to change the password.
47:      * @param string $old_password  The old (current) user password.
48:      * @param string $new_password  The new user password to set.
49:      *
50:      * @throws Passwd_Exception
51:      */
52:     public function changePassword($user_name, $old_password, $new_password)
53:     {
54:         if (empty($this->_params['target'])) {
55:             throw new Passwd_Exception(_("Password module is missing target parameter."));
56:         }
57: 
58:         $root = new COM('WinNT:');
59:         $adsi = $root->OpenDSObject(
60:             'WinNT://' . $this->_params['target'] . '/' . $user_name . ',user',
61:             $this->_params['target'] . '\\' . $user_name,
62:             $old_password,
63:             1);
64: 
65:         if (!$adsi) {
66:             throw new Passwd_Exception(_("Access Denied."));
67:         }
68:         if ($result = $adsi->ChangePassword($old_password, $new_password)) {
69:             throw new Passwd_Exception(sprintf(_("ADSI error %s."), $result));
70:         }
71:     }
72: }
73: 
API documentation generated by ApiGen