File_Passwd
[ class tree: File_Passwd ] [ index: File_Passwd ] [ all elements ]

Class: File_Passwd_Unix

Source Location: /File_Passwd-1.1.7/Passwd/Unix.php

Class Overview

File_Passwd_Common
   |
   --File_Passwd_Unix

Manipulate standard Unix passwd files.


Author(s):

Version:

  • $Revision: 1.17 $

Methods


Inherited Variables

Inherited Methods

Class: File_Passwd_Common

File_Passwd_Common::__construct()
Constructor (ZE2)
File_Passwd_Common::delUser()
Delete a certain user
File_Passwd_Common::getFile()
Get path of passwd file
File_Passwd_Common::listUser()
List user
File_Passwd_Common::load()
Loads the file
File_Passwd_Common::parse()
Parse the content of the file
File_Passwd_Common::save()
Apply changes and rewrite passwd file
File_Passwd_Common::setFile()
Set path to passwd file
File_Passwd_Common::userExists()
Check if a certain user already exists
File_Passwd_Common::_auth()
Base method for File_Passwd::staticAuth()
File_Passwd_Common::_close()
Closes a prior opened and locked file handle
File_Passwd_Common::_open()
Opens a file, locks it exclusively and returns the filehandle
File_Passwd_Common::_save()
Save the modified content to the passwd file

Class Details

[line 68]
Manipulate standard Unix passwd files.

<u>Usage Example:</u>

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

<u>Output of listUser()</u>

  • 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  => ...

  • Author: Michael Wallner <mike@php.net>
  • Version: $Revision: 1.17 $
  • Access: public


[ Top ]


Method Detail

File_Passwd_Unix (Constructor)   [line 116]

File_Passwd_Unix File_Passwd_Unix( [string $file = 'passwd'])

Constructor
  • Access: public

Parameters:

string   $file     path to passwd file

[ Top ]

addUser   [line 407]

mixed addUser( string $user, string $pass, [array $extra = array()])

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
  • Throws: PEAR_Error
  • Access: public

Parameters:

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

[ Top ]

changePasswd   [line 533]

mixed changePasswd( string $user, string $pass)

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
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $user     the user whose password should be changed
string   $pass     the new plaintext password

[ Top ]

generatePasswd   [line 639]

mixed generatePasswd( string $pass, [string $mode = FILE_PASSWD_MD5], [string $salt = null])

Generate Password

Returns PEAR_Error FILE_PASSD_E_INVALID_ENC_MODE if the supplied encryption mode is not supported.

  • Return: The crypted password on success or PEAR_Error on failure.
  • See: File_Passwd
  • Access: public

Parameters:

string   $pass     The plaintext password.
string   $mode     The encryption mode to use.
string   $salt     The salt to use.

[ Top ]

getMap   [line 361]

array getMap( )

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

[ Top ]

getMode   [line 285]

string getMode( )

Get actual encryption mode

[ Top ]

isShadowed   [line 372]

boolean isShadowed( )

If the passwords of this passwd file are shadowed in another file.
  • Access: public

[ Top ]

listModes   [line 271]

array listModes( )

Get supported encryption modes

   array
    + md5
    + des


[ Top ]

modUser   [line 493]

mixed modUser( string $user, [array $properties = array()])

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 (':')


Parameters:

string   $user     the user to modify
array   $properties     an associative array of properties to modify

[ Top ]

parse   [line 192]

mixed parse( )

Parse the Unix password file

Returns a PEAR_Error if passwd file has invalid format.

  • Return: true on success or PEAR_Error
  • Throws: PEAR_Error
  • Access: public

Overrides File_Passwd_Common::parse() (Parse the content of the file)
[ Top ]

save   [line 168]

mixed save( )

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
  • Throws: PEAR_Error
  • Access: public

Overrides File_Passwd_Common::save() (Apply changes and rewrite passwd file)
[ Top ]

setMap   [line 340]

mixed setMap( [ $map = array()])

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.


Parameters:

   $map     

[ Top ]

setMode   [line 243]

mixed setMode( string $mode)

Set the encryption mode

Supported encryption modes are des and md5.

Returns a PEAR_Error if supplied encryption mode is not supported.


Parameters:

string   $mode     encryption mode to use; either md5 or des

[ Top ]

staticAuth   [line 140]

mixed staticAuth( string $file, string $user, string $pass, string $mode)

Fast authentication of a certain user

Returns a PEAR_Error if:

  • file doesn't exist
  • file couldn't be opened in read mode
  • file couldn't be locked exclusively
  • file couldn't be unlocked (only if auth fails)
  • file couldn't be closed (only if auth fails)
  • invalid encryption mode $mode was provided

  • Return: true if authenticated, false if not or PEAR_Error
  • Access: public

Parameters:

string   $file     path to passwd file
string   $user     user to authenticate
string   $pass     plaintext password
string   $mode     encryption mode to use (des or md5)

[ Top ]

useMap   [line 317]

boolean useMap( [boolean $bool = null])

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

Default Unix passwd files look like:

 user:password:user_id:group_id:gecos: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()).


Parameters:

boolean   $bool     whether to use the 'name map' or not

[ Top ]

verifyPasswd   [line 576]

mixed verifyPasswd( string $user, string $pass)

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
  • Throws: PEAR_Error
  • Access: public

Parameters:

string   $user     the user whose password should be verified
string   $pass     the password to verify

[ Top ]


Documentation generated on Sun, 04 Jan 2009 13:00:12 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.