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.14 2003/10/29 13:42:40 mike 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.14 $
  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.     {
  56.         $this->pwfile = $filename;
  57.     }
  58.  
  59.     // }}}
  60.     // {{{ fetchData()
  61.  
  62.     /**
  63.      * Authenticate an user
  64.      *
  65.      * @param   string  username
  66.      * @param   string  password
  67.      * @return  mixed   boolean|PEAR_Error
  68.      */
  69.     function fetchData($user$pass)
  70.     {
  71.         return File_Passwd::staticAuth('Cvs'$this->pwfile$user$pass);
  72.     }
  73.  
  74.     // }}}
  75.     // {{{ listUsers()
  76.     
  77.     /**
  78.      * List all available users
  79.      * 
  80.      * @return   array 
  81.      */
  82.     function listUsers()
  83.     {
  84.         $pw_obj &$this->_load();
  85.         if (PEAR::isError($pw_obj)) {
  86.             return array();
  87.         }
  88.  
  89.         $users  $pw_obj->listUser();
  90.         if (!is_array($users)) {
  91.             return array();
  92.         }
  93.  
  94.         foreach ($users as $key => $value{
  95.             $retVal[= array("username" => $key
  96.                               "password" => $value['passwd'],
  97.                               "cvsuser"  => $value['system']);
  98.         }
  99.  
  100.         return $retVal;
  101.     }
  102.  
  103.     // }}}
  104.     // {{{ addUser()
  105.  
  106.     /**
  107.      * Add a new user to the storage container
  108.      *
  109.      * @param string username
  110.      * @param string password
  111.      * @param mixed  CVS username
  112.      *
  113.      * @return boolean 
  114.      */
  115.     function addUser($user$pass$additional='')
  116.     {
  117.         $cvs = (string) (is_array($additional&& isset($additional['cvsuser'])) 
  118.                $additional['cvsuser'$additional;
  119.  
  120.         $pw_obj &$this->_load();
  121.         if (PEAR::isError($pw_obj)) {
  122.             return false;
  123.         }
  124.         
  125.         $res $pw_obj->addUser($user$pass$cvs);
  126.         if(PEAR::isError($res)){
  127.             return false;
  128.         }
  129.         
  130.         $res $pw_obj->save();
  131.         if (PEAR::isError($res)) {
  132.             return false;
  133.         }
  134.         
  135.         return true;
  136.     }
  137.  
  138.     // }}}
  139.     // {{{ removeUser()
  140.  
  141.     /**
  142.      * Remove user from the storage container
  143.      *
  144.      * @param   string  Username
  145.      * @return  boolean 
  146.      */
  147.     function removeUser($user)
  148.     {
  149.         $pw_obj &$this->_load();
  150.         if (PEAR::isError($pw_obj)) {
  151.             return false;
  152.         }
  153.         
  154.         
  155.         $res $pw_obj->delUser($user);
  156.         if(PEAR::isError($res)){
  157.             return false;
  158.         }
  159.         
  160.         $res $pw_obj->save();
  161.         if (PEAR::isError($res)) {
  162.             return false;
  163.         }
  164.         
  165.         return true;
  166.     }
  167.  
  168.     // }}}
  169.     // {{{ _load()
  170.     
  171.     /**
  172.      * Load and initialize the File_Passwd object
  173.      * 
  174.      * @return  object  File_Passwd_Cvs|PEAR_Error
  175.      */
  176.     function &_load()
  177.     {
  178.         static $pw_obj;
  179.         
  180.         if (!isset($pw_obj)) {
  181.             $pw_obj = File_Passwd::factory('Cvs');
  182.             if (PEAR::isError($pw_obj)) {
  183.                 return $pw_obj;
  184.             }
  185.             
  186.             $pw_obj->setFile($this->pwfile);
  187.             
  188.             $res $pw_obj->load();
  189.             if (PEAR::isError($res)) {
  190.                 return $res;
  191.             }
  192.         }
  193.         
  194.         return $pw_obj;
  195.     }
  196.  
  197.     // }}}
  198. }
  199. ?>

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