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

Source for file File.php

Documentation is available at File.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stefan Ekman <stekman@sedata.org>                           |
  17. // |          Martin Jansen <mj@php.net>                                  |
  18. // |          Mika Tuupola <tuupola@appelsiini.net>                       |
  19. // +----------------------------------------------------------------------+
  20. //
  21. // $Id: File.php,v 1.18 2006/02/28 02:19:22 aashley Exp $
  22. //
  23.  
  24. require_once "File/Passwd.php";
  25. require_once "Auth/Container.php";
  26. require_once "PEAR.php";
  27.  
  28. /**
  29.  * Storage driver for fetching login data from an encrypted password file.
  30.  *
  31.  * This storage container can handle CVS pserver style passwd files.
  32.  *
  33.  * @author   Stefan Ekman <stekman@sedata.org>
  34.  * @author   Michael Wallner <mike@php.net>
  35.  * @package  Auth
  36.  * @version  $Revision: 1.18 $
  37.  */
  38. {
  39.  
  40.     // {{{ properties
  41.  
  42.     /**
  43.      * Path to passwd file
  44.      * 
  45.      * @var string 
  46.      */
  47.     var $pwfile = '';
  48.  
  49.     // }}}
  50.  
  51.     // {{{ Auth_Container_File() [constructor]
  52.  
  53.     /**
  54.      * Constructor of the container class
  55.      *
  56.      * @param  string $filename             path to passwd file
  57.      * @return object Auth_Container_File   new Auth_Container_File object
  58.      */
  59.     function Auth_Container_File($filename{
  60.         // Only file is a valid option here
  61.         if(is_array($filename)) {
  62.             $filename $filename['file'];
  63.         }
  64.         $this->pwfile = $filename;
  65.     }
  66.  
  67.     // }}}
  68.     // {{{ fetchData()
  69.  
  70.     /**
  71.      * Authenticate an user
  72.      *
  73.      * @param   string  username
  74.      * @param   string  password
  75.      * @return  mixed   boolean|PEAR_Error
  76.      */
  77.     function fetchData($user$pass)
  78.     {
  79.         return File_Passwd::staticAuth('Cvs'$this->pwfile$user$pass);
  80.     }
  81.  
  82.     // }}}
  83.     // {{{ listUsers()
  84.     
  85.     /**
  86.      * List all available users
  87.      * 
  88.      * @return   array 
  89.      */
  90.     function listUsers()
  91.     {
  92.         $pw_obj &$this->_load();
  93.         if (PEAR::isError($pw_obj)) {
  94.             return array();
  95.         }
  96.  
  97.         $users  $pw_obj->listUser();
  98.         if (!is_array($users)) {
  99.             return array();
  100.         }
  101.  
  102.         foreach ($users as $key => $value{
  103.             $retVal[= array("username" => $key
  104.                               "password" => $value['passwd'],
  105.                               "cvsuser"  => $value['system']);
  106.         }
  107.  
  108.         return $retVal;
  109.     }
  110.  
  111.     // }}}
  112.     // {{{ addUser()
  113.  
  114.     /**
  115.      * Add a new user to the storage container
  116.      *
  117.      * @param string username
  118.      * @param string password
  119.      * @param mixed  CVS username
  120.      *
  121.      * @return boolean 
  122.      */
  123.     function addUser($user$pass$additional='')
  124.     {
  125.         $cvs = (string) (is_array($additional&& isset($additional['cvsuser'])) 
  126.                $additional['cvsuser'$additional;
  127.  
  128.         $pw_obj &$this->_load();
  129.         if (PEAR::isError($pw_obj)) {
  130.             return false;
  131.         }
  132.         
  133.         $res $pw_obj->addUser($user$pass$cvs);
  134.         if (PEAR::isError($res)) {
  135.             return false;
  136.         }
  137.         
  138.         $res $pw_obj->save();
  139.         if (PEAR::isError($res)) {
  140.             return false;
  141.         }
  142.         
  143.         return true;
  144.     }
  145.  
  146.     // }}}
  147.     // {{{ removeUser()
  148.  
  149.     /**
  150.      * Remove user from the storage container
  151.      *
  152.      * @param   string  Username
  153.      * @return  boolean 
  154.      */
  155.     function removeUser($user)
  156.     {
  157.         $pw_obj &$this->_load();
  158.         if (PEAR::isError($pw_obj)) {
  159.             return false;
  160.         }
  161.         
  162.         $res $pw_obj->delUser($user);
  163.         if (PEAR::isError($res)) {
  164.             return false;
  165.         }
  166.         
  167.         $res $pw_obj->save();
  168.         if (PEAR::isError($res)) {
  169.             return false;
  170.         }
  171.         
  172.         return true;
  173.     }
  174.  
  175.     // }}}
  176.     // {{{ changePassword()
  177.  
  178.     /**
  179.      * Change password for user in the storage container
  180.      *
  181.      * @param string Username
  182.      * @param string The new password
  183.      */
  184.     function changePassword($username$password)
  185.     {
  186.         $pw_obj &$this->_load();
  187.         if (PEAR::isError($pw_obj)) {
  188.             return false;
  189.         }
  190.         
  191.         $res $pw_obj->changePasswd($username$password);
  192.         if (PEAR::isError($res)) {
  193.             return false;
  194.         }
  195.         
  196.         $res $pw_obj->save();
  197.         if (PEAR::isError($res)) {
  198.             return false;
  199.         }
  200.         
  201.         return true;
  202.     }
  203.  
  204.     // }}}
  205.     // {{{ _load()
  206.     
  207.     /**
  208.      * Load and initialize the File_Passwd object
  209.      * 
  210.      * @return  object  File_Passwd_Cvs|PEAR_Error
  211.      */
  212.     function &_load()
  213.     {
  214.         static $pw_obj;
  215.         
  216.         if (!isset($pw_obj)) {
  217.             $pw_obj = File_Passwd::factory('Cvs');
  218.             if (PEAR::isError($pw_obj)) {
  219.                 return $pw_obj;
  220.             }
  221.             
  222.             $pw_obj->setFile($this->pwfile);
  223.             
  224.             $res $pw_obj->load();
  225.             if (PEAR::isError($res)) {
  226.                 return $res;
  227.             }
  228.         }
  229.         
  230.         return $pw_obj;
  231.     }
  232.  
  233.     // }}}
  234.  
  235. }
  236. ?>

Documentation generated on Mon, 11 Mar 2019 14:37:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.