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.16 2004/07/03 17:39:22 yavo 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.16 $
  37.  */
  38. {
  39.     /**
  40.      * Path to passwd file
  41.      * 
  42.      * @var string 
  43.      */
  44.     var $pwfile = '';
  45.  
  46.     // {{{ Constructor
  47.  
  48.     /**
  49.      * Constructor of the container class
  50.      *
  51.      * @param  string $filename             path to passwd file
  52.      * @return object Auth_Container_File   new Auth_Container_File object
  53.      */
  54.     function Auth_Container_File($filename{
  55.         // Only file is a valid option here
  56.         if(is_array($filename)) {
  57.             $filename $filename['file'];
  58.         }
  59.         $this->pwfile = $filename;
  60.     }
  61.  
  62.     // }}}
  63.     // {{{ fetchData()
  64.  
  65.     /**
  66.      * Authenticate an user
  67.      *
  68.      * @param   string  username
  69.      * @param   string  password
  70.      * @return  mixed   boolean|PEAR_Error
  71.      */
  72.     function fetchData($user$pass)
  73.     {
  74.         return File_Passwd::staticAuth('Cvs'$this->pwfile$user$pass);
  75.     }
  76.  
  77.     // }}}
  78.     // {{{ listUsers()
  79.     
  80.     /**
  81.      * List all available users
  82.      * 
  83.      * @return   array 
  84.      */
  85.     function listUsers()
  86.     {
  87.         $pw_obj &$this->_load();
  88.         if (PEAR::isError($pw_obj)) {
  89.             return array();
  90.         }
  91.  
  92.         $users  $pw_obj->listUser();
  93.         if (!is_array($users)) {
  94.             return array();
  95.         }
  96.  
  97.         foreach ($users as $key => $value{
  98.             $retVal[= array("username" => $key
  99.                               "password" => $value['passwd'],
  100.                               "cvsuser"  => $value['system']);
  101.         }
  102.  
  103.         return $retVal;
  104.     }
  105.  
  106.     // }}}
  107.     // {{{ addUser()
  108.  
  109.     /**
  110.      * Add a new user to the storage container
  111.      *
  112.      * @param string username
  113.      * @param string password
  114.      * @param mixed  CVS username
  115.      *
  116.      * @return boolean 
  117.      */
  118.     function addUser($user$pass$additional='')
  119.     {
  120.         $cvs = (string) (is_array($additional&& isset($additional['cvsuser'])) 
  121.                $additional['cvsuser'$additional;
  122.  
  123.         $pw_obj &$this->_load();
  124.         if (PEAR::isError($pw_obj)) {
  125.             return false;
  126.         }
  127.         
  128.         $res $pw_obj->addUser($user$pass$cvs);
  129.         if (PEAR::isError($res)) {
  130.             return false;
  131.         }
  132.         
  133.         $res $pw_obj->save();
  134.         if (PEAR::isError($res)) {
  135.             return false;
  136.         }
  137.         
  138.         return true;
  139.     }
  140.  
  141.     // }}}
  142.     // {{{ removeUser()
  143.  
  144.     /**
  145.      * Remove user from the storage container
  146.      *
  147.      * @param   string  Username
  148.      * @return  boolean 
  149.      */
  150.     function removeUser($user)
  151.     {
  152.         $pw_obj &$this->_load();
  153.         if (PEAR::isError($pw_obj)) {
  154.             return false;
  155.         }
  156.         
  157.         
  158.         $res $pw_obj->delUser($user);
  159.         if (PEAR::isError($res)) {
  160.             return false;
  161.         }
  162.         
  163.         $res $pw_obj->save();
  164.         if (PEAR::isError($res)) {
  165.             return false;
  166.         }
  167.         
  168.         return true;
  169.     }
  170.  
  171.     // }}}
  172.     // {{{ changePassword()
  173.  
  174.     /**
  175.      * Change password for user in the storage container
  176.      *
  177.      * @param string Username
  178.      * @param string The new password
  179.      */
  180.     function changePassword($username$password)
  181.     {
  182.         $pw_obj &$this->_load();
  183.         if (PEAR::isError($pw_obj)) {
  184.             return false;
  185.         }
  186.         
  187.         $res $pw_obj->changePasswd($user$pass);
  188.         if (PEAR::isError($res)) {
  189.             return false;
  190.         }
  191.         
  192.         $res $pw_obj->save();
  193.         if (PEAR::isError($res)) {
  194.             return false;
  195.         }
  196.         
  197.         return true;
  198.     }
  199.  
  200.     // }}}
  201.     // {{{ _load()
  202.     
  203.     /**
  204.      * Load and initialize the File_Passwd object
  205.      * 
  206.      * @return  object  File_Passwd_Cvs|PEAR_Error
  207.      */
  208.     function &_load()
  209.     {
  210.         static $pw_obj;
  211.         
  212.         if (!isset($pw_obj)) {
  213.             $pw_obj = File_Passwd::factory('Cvs');
  214.             if (PEAR::isError($pw_obj)) {
  215.                 return $pw_obj;
  216.             }
  217.             
  218.             $pw_obj->setFile($this->pwfile);
  219.             
  220.             $res $pw_obj->load();
  221.             if (PEAR::isError($res)) {
  222.                 return $res;
  223.             }
  224.         }
  225.         
  226.         return $pw_obj;
  227.     }
  228.  
  229.     // }}}
  230. }
  231. ?>

Documentation generated on Mon, 11 Mar 2019 13:52:32 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.