C:\xampp\php\pear\File\Passwd\Cvs.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * File::Passwd::Cvs
 * 
 * PHP versions 4 and 5
 *
 * LICENSE: This source file is subject to version 3.0 of the PHP license
 * that is available through the world-wide-web at the following URI:
 * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
 * the PHP License and are unable to obtain it through the web, please
 * send a note to license@php.net so we can mail you a copy immediately.
 *
 * @category   FileFormats
 * @package    File_Passwd
 * @author     Michael Wallner <mike@php.net>
 * @copyright  2003-2005 Michael Wallner
 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
 * @version    CVS: $Id: Cvs.php,v 1.14 2005/03/30 18:33:33 mike Exp $
 * @link       http://pear.php.net/package/File_Passwd
 */

/**
* Requires File::Passwd::Common
*/
require_once 'File/Passwd/Common.php';

/**
* Manipulate CVS pserver passwd files.

* <kbd><u>
*   A line of a CVS pserver passwd file consists of 2 to 3 colums:
* </u></kbd>
* <pre>
*   user1:1HCoDDWxK9tbM:sys_user1
*   user2:0O0DYYdzjCVxs
*   user3:MIW9UUoifhqRo:sys_user2
* </pre>

* If the third column is specified, the CVS user named in the first column is 
* mapped to the corresponding system user named in the third column.
* That doesn't really affect us - just for your interest :)

* <kbd><u>Output of listUser()</u></kbd>
* <pre>
*      array
*       + user =>  array
*                   + passwd => crypted_passwd
*                   + system => system_user
*       + user =>  array
*                   + passwd => crypted_passwd
*                   + system => system_user
* </pre>

* @author   Michael Wallner <mike@php.net>
* @package  File_Passwd
* @version  $Revision: 1.14 $
* @access   public
*/
class File_Passwd_Cvs extends File_Passwd_Common
{
    
/**
    * Constructor
    *
    * @access public
    */
    
function File_Passwd_Cvs($file 'passwd')
    {
        
parent::__construct($file);
    }
    
    
/**
    * Fast authentication of a certain user
    * 
    * Returns a PEAR_Error if:
    *   o file doesn't exist
    *   o file couldn't be opened in read mode
    *   o file couldn't be locked exclusively
    *   o file couldn't be unlocked (only if auth fails)
    *   o file couldn't be closed (only if auth fails)
    *
    * @static   call this method statically for a reasonable fast authentication
    * @access   public
    * @return   mixed   true if authenticated, false if not or PEAR_Error
    * @param    string  $file   path to passwd file
    * @param    string  $user   user to authenticate
    * @param    string  $pass   plaintext password
    */
    
function staticAuth($file$user$pass)
    {
        
$line File_Passwd_Common::_auth($file$user);
        if (!
$line || PEAR::isError($line)) {
            return 
$line;
        }
        @list(,
$real)   = explode(':'$line);
        return (
File_Passwd_Cvs::generatePassword($pass$real) === $real);
    }
    
    
/**
    * Apply changes and rewrite CVS passwd file
    *
    * Returns a PEAR_Error if:
    *   o directory in which the file should reside couldn't be created
    *   o file couldn't be opened in write mode
    *   o file couldn't be locked exclusively
    *   o file couldn't be unlocked
    *   o file couldn't be closed
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true on success or PEAR_Error
    */
    
function save()
    {
        
$content '';
        foreach (
$this->_users as $user => $v){
            
$content .= $user ':' $v['passwd'];
            if (isset(
$v['system']) && !empty($v['system'])) {
                
$content .= ':' $v['system'];
            }
            
$content .= "\n";
        }
        return 
$this->_save($content);
    }
    
    
/** 
    * Parse the CVS passwd file
    *
    * Returns a PEAR_Error if passwd file has invalid format.
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true on success or PEAR_Error
    */
    
function parse()
    {
        
$this->_users = array();
        foreach (
$this->_contents as $line) {
            
$user explode(':'$line);
            if (
count($user) < 2) {
                return 
PEAR::raiseError(
                    
FILE_PASSWD_E_INVALID_FORMAT_STR,
                    
FILE_PASSWD_E_INVALID_FORMAT
                
);
            }
            @list(
$user$pass$system) = $user;
            
$this->_users[$user]['passwd'] = $pass;
            if (!empty(
$system)) {
                
$this->_users[$user]['system'] = $system;
            }
        }
        
$this->_contents = array();
        return 
true;
    }

    
/**
    * Add an user
    *
    * The username must start with an alphabetical character and must NOT
    * contain any other characters than alphanumerics, the underline and dash.
    * 
    * Returns a PEAR_Error if:
    *   o user already exists
    *   o user or system_user contains illegal characters
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true on success or PEAR_Error
    * @param  string    $user           the name of the user to add
    * @param  string    $pass           the password of the user tot add
    * @param  string    $system_user    the systemuser this user maps to
    */
    
function addUser($user$pass$system_user '')
    {
        if (
$this->userExists($user)) {
            return 
PEAR::raiseError(
                
sprintf(FILE_PASSWD_E_EXISTS_ALREADY_STR'User '$user),
                
FILE_PASSWD_E_EXISTS_ALREADY
            
);
        }
        if (!
preg_match($this->_pcre$user)) {
            return 
PEAR::raiseError(
                
sprintf(FILE_PASSWD_E_INVALID_CHARS_STR'User '$user),
                
FILE_PASSWD_E_INVALID_CHARS
            
);
        }
        @
setType($system_user'string');
        if (!empty(
$system_user) && !preg_match($this->_pcre$system_user)) {
            return 
PEAR::raiseError(
                
sprintf(
                    
FILE_PASSWD_E_INVALID_CHARS_STR
                    
'System user '
                    
$system_user
                
),
                
FILE_PASSWD_E_INVALID_CHARS
            
);
        }
        
$this->_users[$user]['passwd'] = $this->generatePassword($pass);
        
$this->_users[$user]['system'] = $system_user;
        return 
true;
    }
    
    
/**
    * Verify the password of a certain user
    *
    * Returns a PEAR_Error if the user doesn't exist.
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true if passwords equal, false ifthe don't or PEAR_Error
    * @param  string    $user   user whose password should be verified
    * @param  string    $pass   the plaintext password that should be verified
    */
    
function verifyPasswd($user$pass)
    {
        if (!
$this->userExists($user)) {
            return 
PEAR::raiseError(
                
sprintf(FILE_PASSWD_E_EXISTS_NOT_STR'User '$user),
                
FILE_PASSWD_E_EXISTS_NOT
            
);
        }
        
$real $this->_users[$user]['passwd'];
        return (
$real === $this->generatePassword($pass$real));
    }
    
    
/**
    * Change the password of a certain user
    *
    * Returns a PEAR_Error if user doesn't exist.
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true on success or PEAR_Error
    */
    
function changePasswd($user$pass)
    {
        if (!
$this->userExists($user)) {
            return 
PEAR::raiseError(
                
sprintf(FILE_PASSWD_E_EXISTS_NOT_STR'User '$user),
                
FILE_PASSWD_E_EXISTS_NOT
            
);
        }
        
$this->_users[$user]['passwd'] = $this->generatePassword($pass);
        return 
true;
    }
    
    
/**
    * Change the corresponding system user of a certain cvs user
    *
    * Returns a PEAR_Error if:
    *   o user doesn't exist
    *   o system user contains illegal characters
    * 
    * @throws PEAR_Error
    * @access public
    * @return mixed true on success or PEAR_Error
    */
    
function changeSysUser($user$system)
    {
        if (!
$this->userExists($user)) {
            return 
PEAR::raiseError(
                
sprintf(FILE_PASSWD_E_EXISTS_NOT_STR'User '$user),
                
FILE_PASSWD_E_EXISTS_NOT
            
);
        }
        if (!
preg_match($this->_pcre$system)) {
            return 
PEAR::raiseError(
                
sprintf(
                    
FILE_PASSWD_E_INVALID_CHARS_STR
                    
'System user '
                    
$system_user
                
),
                
FILE_PASSWD_E_INVALID_CHARS
            
);
        }
        
$this->_users[$user]['system'] = $system;
        return 
true;
    }
    
    
/**
    * Generate crypted password
    *
    * @static
    * @access public
    * @return string    the crypted password
    * @param  string    $pass   new plaintext password
    * @param  string    $salt   new crypted password from which to gain the salt
    */
    
function generatePasswd($pass$salt null)
    {
        return 
File_Passwd::crypt_des($pass$salt);
    }
    
    
/**
     * @ignore
     * @deprecated
     */
    
function generatePassword($pass$salt null)
    {
        return 
File_Passwd_Cvs::generatePasswd($pass$salt);
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586