Class File_Passwd_Unix

Description

Manipulate standard Unix passwd files.

Usage Example:


1 $passwd = &File_Passwd::factory('Unix');
2 $passwd->setFile('/my/passwd/file');
3 $passwd->load();
4 $passwd->addUser('mike', 'secret');
5 $passwd->save();

Output of listUser()

  • using the 'name map':
      array
       + user  => array
                   + pass  => crypted_passwd or 'x' if shadowed
                   + uid   => user id
                   + gid   => group id
                   + gecos => comments
                   + home  => home directory
                   + shell => standard shell
 

  • without 'name map':
      array
       + user  => array
                   + 0  => crypted_passwd
                   + 1  => ...
                   + 2  => ...
 

Located in Program_Root/Passwd/Unix.php (line 68)

File_Passwd_Common
   |
   --File_Passwd_Unix
Method Summary
 File_Passwd_Unix File_Passwd_Unix ([string $file = 'passwd'])
 mixed addUser (string $user, string $pass, [array $extra = array()])
 mixed changePasswd (string $user, string $pass)
 array getMap ()
 string getMode ()
 boolean isShadowed ()
 array listModes ()
 mixed modUser (string $user, [array $properties = array()])
 mixed parse ()
 mixed save ()
 mixed setMap ([mixed $map = array()])
 mixed setMode (string $mode)
 boolean useMap ([boolean $bool = null])
 mixed verifyPasswd (string $user, string $pass)
 mixed _genPass (string $pass, [string $salt = null])
Variables
Methods
Constructor File_Passwd_Unix (line 116)

Constructor

  • access: public
File_Passwd_Unix File_Passwd_Unix ([string $file = 'passwd'])
  • string $file: path to passwd file
addUser (line 339)

Add an user

The username must start with an alphabetical character and must NOT contain any other characters than alphanumerics, the underline and dash.

If you use the 'name map' you should also use these naming in the supplied extra array, because your values would get mixed up if they are in the wrong order, which is always true if you DON'T use the 'name map'!

So be warned and USE the 'name map'!

If the passwd file is shadowed, the user will be added though, but with an 'x' as password, and a PEAR_Error will be returned, too.

Returns a PEAR_Error if:

  • user already exists
  • user contains illegal characters
  • encryption mode is not supported
  • passwords are shadowed in another file
  • any element of the $extra array contains a colon (':')

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed addUser (string $user, string $pass, [array $extra = array()])
  • string $user: the name of the user to add
  • string $pass: the password of the user to add
  • array $extra: extra properties of user to add
changePasswd (line 444)

Change the password of a certain user

Returns a PEAR_Error if:

  • user doesn't exists
  • passwords are shadowed in another file
  • encryption mode is not supported

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed changePasswd (string $user, string $pass)
  • string $user: the user whose password should be changed
  • string $pass: the new plaintext password
getMap (line 295)

Get the 'name map' which is used for the extra properties of the user

  • access: public
array getMap ()
getMode (line 234)

Get actual encryption mode

  • access: public
string getMode ()
isShadowed (line 305)

If the passwords of this passwd file are shadowed in another file.

  • access: public
boolean isShadowed ()
listModes (line 224)

Get supported encryption modes

   array
    + md5
    + des
 

  • access: public
array listModes ()
modUser (line 412)

Modify properties of a certain user

  • DON'T MODIFY THE PASSWORD WITH THIS METHOD!
You should use this method only if the 'name map' is used, too.

Returns a PEAR_Error if:

  • user doesn't exist
  • any property contains a colon (':')

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed modUser (string $user, [array $properties = array()])
  • string $user: the user to modify
  • array $properties: an associative array of properties to modify
parse (line 157)

Parse the Unix password file

Returns a PEAR_Error if passwd file has invalid format.

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed parse ()

Redefinition of:
File_Passwd_Common::parse()
Parse the content of the file
save (line 134)

Apply changes an rewrite passwd file

Returns a PEAR_Error if:

  • directory in which the file should reside couldn't be created
  • file couldn't be opened in write mode
  • file couldn't be locked exclusively
  • file couldn't be unlocked
  • file couldn't be closed

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed save ()

Redefinition of:
File_Passwd_Common::save()
Apply changes and rewrite passwd file
setMap (line 281)

Set the 'name map' to use with the extra properties of the user

This map is used for naming the associative array of the extra properties.

Returns a PEAR_Error if $map was not of type array.

  • return: true on success or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed setMap ([mixed $map = array()])
setMode (line 203)

Set the encryption mode

Supported encryption modes are des and md5.

Returns a PEAR_Error if supplied encryption mode is not supported.

  • return: true on succes or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed setMode (string $mode)
  • string $mode: encryption mode to use; either md5 or des
useMap (line 262)

Whether to use the 'name map' of the extra properties or not

Default Unix passwd files look like:

 user:password:user_id:group_id:home_dir:shell
 

The default 'name map' for properties except user and password looks like:

  • uid
  • gid
  • gecos
  • home
  • shell
If you want to change the naming of the standard map use File_Passwd_Unix::setMap(array()).

  • return: always true if you set a value (true/false) OR the actual value if called without param
  • access: public
boolean useMap ([boolean $bool = null])
  • boolean $bool: whether to use the 'name map' or not
verifyPasswd (line 476)

Verify the password of a certain user

Returns a PEAR_Error if:

  • user doesn't exist
  • encryption mode is not supported

  • return: true if passwors equal, false if they don't or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed verifyPasswd (string $user, string $pass)
  • string $user: the user whose password should be verified
  • string $pass: the password to verify
_genPass (line 499)

Generate crypted password from the plaintext password

Returns a PEAR_Error if actual encryption mode is not supported.

  • return: the crypted password or PEAR_Error
  • access: public
  • throws: PEAR_Error
mixed _genPass (string $pass, [string $salt = null])
  • string $pass: the plaintext password
  • string $salt: the crypted password from which to gain the salt

Inherited Methods

Inherited From File_Passwd_Common

File_Passwd_Common::delUser()
File_Passwd_Common::getFile()
File_Passwd_Common::listUser()
File_Passwd_Common::load()
File_Passwd_Common::parse()
File_Passwd_Common::save()
File_Passwd_Common::setFile()
File_Passwd_Common::userExists()
File_Passwd_Common::_close()
File_Passwd_Common::_open()
File_Passwd_Common::_save()
File_Passwd_Common::__clone()
File_Passwd_Common::__construct()

Documention generated on Sat, 20 Sep 2003 16:14:43 +0200 by phpDocumentor 1.2.1