Subversion Repositories Applications.papyrus

Rev

Rev 1173 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1173 Rev 1713
Line 12... Line 12...
12
 * the PHP License and are unable to obtain it through the web, please
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.
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
14
 *
15
 * @category   Authentication
15
 * @category   Authentication
16
 * @package    Auth
16
 * @package    Auth
17
 * @author     Stefan Ekman <stekman@sedata.org> 
17
 * @author     Stefan Ekman <stekman@sedata.org>
18
 * @author     Martin Jansen <mj@php.net>
18
 * @author     Martin Jansen <mj@php.net>
19
 * @author     Mika Tuupola <tuupola@appelsiini.net> 
19
 * @author     Mika Tuupola <tuupola@appelsiini.net>
20
 * @author     Michael Wallner <mike@php.net>
20
 * @author     Michael Wallner <mike@php.net>
21
 * @author     Adam Ashley <aashley@php.net>
21
 * @author     Adam Ashley <aashley@php.net>
22
 * @copyright  2001-2006 The PHP Group
22
 * @copyright  2001-2006 The PHP Group
23
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
23
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
24
 * @version    CVS: $Id: File.php,v 1.2 2006-12-14 15:04:28 jp_milcent Exp $
24
 * @version    CVS: $Id: File.php,v 1.3 2007-11-19 15:11:00 jp_milcent Exp $
25
 * @link       http://pear.php.net/package/Auth
25
 * @link       http://pear.php.net/package/Auth
26
 */
26
 */
Line 27... Line 27...
27
 
27
 
28
/**
28
/**
Line 43... Line 43...
43
 *
43
 *
44
 * This storage container can handle CVS pserver style passwd files.
44
 * This storage container can handle CVS pserver style passwd files.
45
 *
45
 *
46
 * @category   Authentication
46
 * @category   Authentication
47
 * @package    Auth
47
 * @package    Auth
48
 * @author     Stefan Ekman <stekman@sedata.org> 
48
 * @author     Stefan Ekman <stekman@sedata.org>
49
 * @author     Martin Jansen <mj@php.net>
49
 * @author     Martin Jansen <mj@php.net>
50
 * @author     Mika Tuupola <tuupola@appelsiini.net> 
50
 * @author     Mika Tuupola <tuupola@appelsiini.net>
51
 * @author     Michael Wallner <mike@php.net>
51
 * @author     Michael Wallner <mike@php.net>
52
 * @author     Adam Ashley <aashley@php.net>
52
 * @author     Adam Ashley <aashley@php.net>
53
 * @copyright  2001-2006 The PHP Group
53
 * @copyright  2001-2006 The PHP Group
54
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
54
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
55
 * @version    Release: 1.4.3  File: $Revision: 1.2 $
55
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
56
 * @link       http://pear.php.net/package/Auth
56
 * @link       http://pear.php.net/package/Auth
57
 */
57
 */
58
class Auth_Container_File extends Auth_Container
58
class Auth_Container_File extends Auth_Container
59
{
59
{
Line 60... Line 60...
60
 
60
 
Line 61... Line 61...
61
    // {{{ properties
61
    // {{{ properties
62
 
62
 
63
    /**
63
    /**
64
     * Path to passwd file
64
     * Path to passwd file
65
     * 
65
     *
66
     * @var string
66
     * @var string
Line 67... Line 67...
67
     */
67
     */
Line 83... Line 83...
83
     * @param  string $filename             path to passwd file
83
     * @param  string $filename             path to passwd file
84
     * @return object Auth_Container_File   new Auth_Container_File object
84
     * @return object Auth_Container_File   new Auth_Container_File object
85
     */
85
     */
86
    function Auth_Container_File($filename) {
86
    function Auth_Container_File($filename) {
87
        $this->_setDefaults();
87
        $this->_setDefaults();
88
        
88
 
89
        // Only file is a valid option here
89
        // Only file is a valid option here
90
        if(is_array($filename)) {
90
        if(is_array($filename)) {
91
            $this->pwfile = $filename['file'];
91
            $this->pwfile = $filename['file'];
92
            $this->_parseOptions($filename);
92
            $this->_parseOptions($filename);
93
        } else {
93
        } else {
Line 105... Line 105...
105
     * @param   string  password
105
     * @param   string  password
106
     * @return  mixed   boolean|PEAR_Error
106
     * @return  mixed   boolean|PEAR_Error
107
     */
107
     */
108
    function fetchData($user, $pass)
108
    function fetchData($user, $pass)
109
    {
109
    {
-
 
110
        $this->log('Auth_Container_File::fetchData() called.', AUTH_LOG_DEBUG);
110
        return File_Passwd::staticAuth($this->options['type'], $this->pwfile, $user, $pass);
111
        return File_Passwd::staticAuth($this->options['type'], $this->pwfile, $user, $pass);
111
    }
112
    }
Line 112... Line 113...
112
 
113
 
113
    // }}}
114
    // }}}
114
    // {{{ listUsers()
115
    // {{{ listUsers()
115
    
116
 
116
    /**
117
    /**
117
     * List all available users
118
     * List all available users
118
     * 
119
     *
119
     * @return   array
120
     * @return   array
120
     */
121
     */
121
    function listUsers()
122
    function listUsers()
-
 
123
    {
-
 
124
        $this->log('Auth_Container_File::listUsers() called.', AUTH_LOG_DEBUG);
122
    {
125
 
123
        $pw_obj = &$this->_load();
126
        $pw_obj = &$this->_load();
124
        if (PEAR::isError($pw_obj)) {
127
        if (PEAR::isError($pw_obj)) {
125
            return array();
128
            return array();
Line 129... Line 132...
129
        if (!is_array($users)) {
132
        if (!is_array($users)) {
130
            return array();
133
            return array();
131
        }
134
        }
Line 132... Line 135...
132
 
135
 
133
        foreach ($users as $key => $value) {
136
        foreach ($users as $key => $value) {
134
            $retVal[] = array("username" => $key, 
137
            $retVal[] = array("username" => $key,
135
                              "password" => $value['passwd'],
138
                              "password" => $value['passwd'],
136
                              "cvsuser"  => $value['system']);
139
                              "cvsuser"  => $value['system']);
Line -... Line 140...
-
 
140
        }
-
 
141
 
137
        }
142
        $this->log('Found '.count($retVal).' users.', AUTH_LOG_DEBUG);
138
 
143
 
Line 139... Line 144...
139
        return $retVal;
144
        return $retVal;
140
    }
145
    }
Line 151... Line 156...
151
     *
156
     *
152
     * @return boolean
157
     * @return boolean
153
     */
158
     */
154
    function addUser($user, $pass, $additional='')
159
    function addUser($user, $pass, $additional='')
155
    {
160
    {
-
 
161
        $this->log('Auth_Container_File::addUser() called.', AUTH_LOG_DEBUG);
156
        $params = array($user, $pass);
162
        $params = array($user, $pass);
157
        if (is_array($additional)) {
163
        if (is_array($additional)) {
158
            foreach ($additional as $item) {
164
            foreach ($additional as $item) {
159
                $params[] = $item;
165
                $params[] = $item;
160
            }
166
            }
Line 164... Line 170...
164
 
170
 
165
        $pw_obj = &$this->_load();
171
        $pw_obj = &$this->_load();
166
        if (PEAR::isError($pw_obj)) {
172
        if (PEAR::isError($pw_obj)) {
167
            return false;
173
            return false;
168
        }
174
        }
169
        
175
 
170
        $res = call_user_func_array(array(&$pw_obj, 'addUser'), $params);
176
        $res = call_user_func_array(array(&$pw_obj, 'addUser'), $params);
171
        if (PEAR::isError($res)) {
177
        if (PEAR::isError($res)) {
172
            return false;
178
            return false;
173
        }
179
        }
174
        
180
 
175
        $res = $pw_obj->save();
181
        $res = $pw_obj->save();
176
        if (PEAR::isError($res)) {
182
        if (PEAR::isError($res)) {
177
            return false;
183
            return false;
178
        }
184
        }
179
        
185
 
180
        return true;
186
        return true;
Line 181... Line 187...
181
    }
187
    }
182
 
188
 
Line 189... Line 195...
189
     * @param   string  Username
195
     * @param   string  Username
190
     * @return  boolean
196
     * @return  boolean
191
     */
197
     */
192
    function removeUser($user)
198
    function removeUser($user)
193
    {
199
    {
-
 
200
        $this->log('Auth_Container_File::removeUser() called.', AUTH_LOG_DEBUG);
194
        $pw_obj = &$this->_load();
201
        $pw_obj = &$this->_load();
195
        if (PEAR::isError($pw_obj)) {
202
        if (PEAR::isError($pw_obj)) {
196
            return false;
203
            return false;
197
        }
204
        }
198
        
205
 
199
        $res = $pw_obj->delUser($user);
206
        $res = $pw_obj->delUser($user);
200
        if (PEAR::isError($res)) {
207
        if (PEAR::isError($res)) {
201
            return false;
208
            return false;
202
        }
209
        }
203
        
210
 
204
        $res = $pw_obj->save();
211
        $res = $pw_obj->save();
205
        if (PEAR::isError($res)) {
212
        if (PEAR::isError($res)) {
206
            return false;
213
            return false;
207
        }
214
        }
208
        
215
 
209
        return true;
216
        return true;
210
    }
217
    }
Line 211... Line 218...
211
 
218
 
212
    // }}}
219
    // }}}
Line 213... Line 220...
213
    // {{{ changePassword()
220
    // {{{ changePassword()
214
 
221
 
215
    /**
222
    /**
216
     * Change password for user in the storage container
223
     * Change password for user in the storage container
217
     *
224
     *
218
     * @param string Username
225
     * @param string Username
219
     * @param string The new password 
226
     * @param string The new password
220
     */
227
     */
-
 
228
    function changePassword($username, $password)
221
    function changePassword($username, $password)
229
    {
222
    {
230
        $this->log('Auth_Container_File::changePassword() called.', AUTH_LOG_DEBUG);
223
        $pw_obj = &$this->_load();
231
        $pw_obj = &$this->_load();
224
        if (PEAR::isError($pw_obj)) {
232
        if (PEAR::isError($pw_obj)) {
225
            return false;
233
            return false;
226
        }
234
        }
227
        
235
 
228
        $res = $pw_obj->changePasswd($username, $password);
236
        $res = $pw_obj->changePasswd($username, $password);
229
        if (PEAR::isError($res)) {
237
        if (PEAR::isError($res)) {
230
            return false;
238
            return false;
231
        }
239
        }
232
        
240
 
233
        $res = $pw_obj->save();
241
        $res = $pw_obj->save();
234
        if (PEAR::isError($res)) {
242
        if (PEAR::isError($res)) {
235
            return false;
243
            return false;
236
        }
244
        }
237
        
245
 
Line 238... Line 246...
238
        return true;
246
        return true;
239
    }
247
    }
240
 
248
 
241
    // }}}
249
    // }}}
242
    // {{{ _load()
250
    // {{{ _load()
243
    
251
 
244
    /**
252
    /**
245
     * Load and initialize the File_Passwd object
253
     * Load and initialize the File_Passwd object
246
     * 
254
     *
247
     * @return  object  File_Passwd_Cvs|PEAR_Error
255
     * @return  object  File_Passwd_Cvs|PEAR_Error
248
     */
256
     */
249
    function &_load()
257
    function &_load()
250
    {
258
    {
-
 
259
        static $pw_obj;
251
        static $pw_obj;
260
 
252
        
261
        if (!isset($pw_obj)) {
253
        if (!isset($pw_obj)) {
262
            $this->log('Instanciating File_Password object of type '.$this->options['type'], AUTH_LOG_DEBUG);
254
            $pw_obj = File_Passwd::factory($this->options['type']);
263
            $pw_obj = File_Passwd::factory($this->options['type']);
255
            if (PEAR::isError($pw_obj)) {
264
            if (PEAR::isError($pw_obj)) {
256
                return $pw_obj;
265
                return $pw_obj;
257
            }
266
            }
258
            
267
 
259
            $pw_obj->setFile($this->pwfile);
268
            $pw_obj->setFile($this->pwfile);
260
            
269
 
261
            $res = $pw_obj->load();
270
            $res = $pw_obj->load();
262
            if (PEAR::isError($res)) {
271
            if (PEAR::isError($res)) {
263
                return $res;
272
                return $res;
264
            }
273
            }
265
        }
274
        }
Line 266... Line 275...
266
        
275
 
267
        return $pw_obj;
276
        return $pw_obj;