1 | <?php |
---|
2 | /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */ |
---|
3 | |
---|
4 | /** |
---|
5 | * Storage driver for use against Samba password files |
---|
6 | * |
---|
7 | * PHP versions 4 and 5 |
---|
8 | * |
---|
9 | * LICENSE: This source file is subject to version 3.01 of the PHP license |
---|
10 | * that is available through the world-wide-web at the following URI: |
---|
11 | * http://www.php.net/license/3_01.txt. If you did not receive a copy of |
---|
12 | * the PHP License and are unable to obtain it through the web, please |
---|
13 | * send a note to license@php.net so we can mail you a copy immediately. |
---|
14 | * |
---|
15 | * @category Authentication |
---|
16 | * @package Auth |
---|
17 | * @author Michael Bretterklieber <michael@bretterklieber.com> |
---|
18 | * @author Adam Ashley <aashley@php.net> |
---|
19 | * @copyright 2001-2006 The PHP Group |
---|
20 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
21 | * @version CVS: $Id$ |
---|
22 | * @link http://pear.php.net/package/Auth |
---|
23 | * @since File available since Release 1.2.3 |
---|
24 | */ |
---|
25 | |
---|
26 | /** |
---|
27 | * Include PEAR File_SMBPasswd |
---|
28 | */ |
---|
29 | require_once "File/SMBPasswd.php"; |
---|
30 | /** |
---|
31 | * Include Auth_Container Base file |
---|
32 | */ |
---|
33 | require_once "Auth/Container.php"; |
---|
34 | /** |
---|
35 | * Include PEAR class for error handling |
---|
36 | */ |
---|
37 | require_once "PEAR.php"; |
---|
38 | |
---|
39 | /** |
---|
40 | * Storage driver for fetching login data from an SAMBA smbpasswd file. |
---|
41 | * |
---|
42 | * This storage container can handle SAMBA smbpasswd files. |
---|
43 | * |
---|
44 | * Example: |
---|
45 | * $a = new Auth("SMBPasswd", '/usr/local/private/smbpasswd'); |
---|
46 | * $a->start(); |
---|
47 | * if ($a->getAuth()) { |
---|
48 | * printf ("AUTH OK<br>\n"); |
---|
49 | * $a->logout(); |
---|
50 | * } |
---|
51 | * |
---|
52 | * @category Authentication |
---|
53 | * @package Auth |
---|
54 | * @author Michael Bretterklieber <michael@bretterklieber.com> |
---|
55 | * @author Adam Ashley <aashley@php.net> |
---|
56 | * @package Auth |
---|
57 | * @copyright 2001-2006 The PHP Group |
---|
58 | * @license http://www.php.net/license/3_01.txt PHP License 3.01 |
---|
59 | * @version Release: 1.4.2 File: $Revision: 8713 $ |
---|
60 | * @link http://pear.php.net/package/Auth |
---|
61 | * @since Class available since Release 1.2.3 |
---|
62 | */ |
---|
63 | class Auth_Container_SMBPasswd extends Auth_Container |
---|
64 | { |
---|
65 | |
---|
66 | // {{{ properties |
---|
67 | |
---|
68 | /** |
---|
69 | * File_SMBPasswd object |
---|
70 | * @var object |
---|
71 | */ |
---|
72 | var $pwfile; |
---|
73 | |
---|
74 | // }}} |
---|
75 | |
---|
76 | // {{{ Auth_Container_SMBPasswd() [constructor] |
---|
77 | |
---|
78 | /** |
---|
79 | * Constructor of the container class |
---|
80 | * |
---|
81 | * @param $filename string filename for a passwd type file |
---|
82 | * @return object Returns an error object if something went wrong |
---|
83 | */ |
---|
84 | function Auth_Container_SMBPasswd($filename) |
---|
85 | { |
---|
86 | $this->pwfile = new File_SMBPasswd($filename,0); |
---|
87 | |
---|
88 | if (!$this->pwfile->load()) { |
---|
89 | PEAR::raiseError("Error while reading file contents.", 41, PEAR_ERROR_DIE); |
---|
90 | return; |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | // }}} |
---|
96 | // {{{ fetchData() |
---|
97 | |
---|
98 | /** |
---|
99 | * Get user information from pwfile |
---|
100 | * |
---|
101 | * @param string Username |
---|
102 | * @param string Password |
---|
103 | * @return boolean |
---|
104 | */ |
---|
105 | function fetchData($username, $password) |
---|
106 | { |
---|
107 | return $this->pwfile->verifyAccount($username, $password); |
---|
108 | } |
---|
109 | |
---|
110 | // }}} |
---|
111 | // {{{ listUsers() |
---|
112 | |
---|
113 | function listUsers() |
---|
114 | { |
---|
115 | return $this->pwfile->getAccounts(); |
---|
116 | } |
---|
117 | |
---|
118 | // }}} |
---|
119 | // {{{ addUser() |
---|
120 | |
---|
121 | /** |
---|
122 | * Add a new user to the storage container |
---|
123 | * |
---|
124 | * @param string Username |
---|
125 | * @param string Password |
---|
126 | * @param array Additional information |
---|
127 | * |
---|
128 | * @return boolean |
---|
129 | */ |
---|
130 | function addUser($username, $password, $additional = '') |
---|
131 | { |
---|
132 | $res = $this->pwfile->addUser($user, $additional['userid'], $pass); |
---|
133 | if ($res === true) { |
---|
134 | return $this->pwfile->save(); |
---|
135 | } |
---|
136 | return $res; |
---|
137 | } |
---|
138 | |
---|
139 | // }}} |
---|
140 | // {{{ removeUser() |
---|
141 | |
---|
142 | /** |
---|
143 | * Remove user from the storage container |
---|
144 | * |
---|
145 | * @param string Username |
---|
146 | */ |
---|
147 | function removeUser($username) |
---|
148 | { |
---|
149 | $res = $this->pwfile->delUser($username); |
---|
150 | if ($res === true) { |
---|
151 | return $this->pwfile->save(); |
---|
152 | } |
---|
153 | return $res; |
---|
154 | } |
---|
155 | |
---|
156 | // }}} |
---|
157 | // {{{ changePassword() |
---|
158 | |
---|
159 | /** |
---|
160 | * Change password for user in the storage container |
---|
161 | * |
---|
162 | * @param string Username |
---|
163 | * @param string The new password |
---|
164 | */ |
---|
165 | function changePassword($username, $password) |
---|
166 | { |
---|
167 | $res = $this->pwfile->modUser($username, '', $password); |
---|
168 | if ($res === true) { |
---|
169 | return $this->pwfile->save(); |
---|
170 | } |
---|
171 | return $res; |
---|
172 | } |
---|
173 | |
---|
174 | // }}} |
---|
175 | |
---|
176 | } |
---|
177 | ?> |
---|