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

Source for file SMBPasswd.php

Documentation is available at SMBPasswd.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: Michael Bretterklieber <michael@bretterklieber.com>         |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: SMBPasswd.php,v 1.2 2004/03/28 23:19:50 yavo Exp $
  20. //
  21.  
  22. require_once "File/SMBPasswd.php";
  23. require_once "Auth/Container.php";
  24. require_once "PEAR.php";
  25.  
  26. /**
  27.  * Storage driver for fetching login data from an SAMBA smbpasswd file.
  28.  *
  29.  * This storage container can handle SAMBA smbpasswd files.
  30.  *
  31.  * Example:
  32.  * $a = new Auth("SMBPasswd", '/usr/local/private/smbpasswd');
  33.  * $a->start();
  34.  * if ($a->getAuth()) {
  35.  *     printf ("AUTH OK<br>\n");
  36.  *     $a->logout();
  37.  * }
  38.  *
  39.  * @author   Michael Bretterklieber <michael@bretterklieber.com>
  40.  * @package  Auth
  41.  * @version  $Revision: 1.2 $
  42.  */
  43. {
  44.     /**
  45.      * File_SMBPasswd object
  46.      * @var object 
  47.      */
  48.     var $pwfile;
  49.  
  50.     // {{{ Constructor
  51.  
  52.     /**
  53.      * Constructor of the container class
  54.      *
  55.      * @param  $filename   string filename for a passwd type file
  56.      * @return object Returns an error object if something went wrong
  57.      */
  58.     function Auth_Container_SMBPasswd($filename)
  59.     {
  60.         $this->pwfile = new File_SMBPasswd($filename,0);
  61.  
  62.         if (!$this->pwfile->load()) {
  63.             PEAR::raiseError("Error while reading file contents."41PEAR_ERROR_DIE);
  64.             return;
  65.         }
  66.  
  67.     }
  68.  
  69.     // }}}
  70.     // {{{ fetchData()
  71.  
  72.     /**
  73.      * Get user information from pwfile
  74.      *
  75.      * @param   string Username
  76.      * @param   string Password
  77.      * @return  boolean 
  78.      */
  79.     function fetchData($username$password)
  80.     {
  81.         return $this->pwfile->verifyAccount($username$password);
  82.     }
  83.  
  84.     // }}}
  85.     // {{{ listUsers()
  86.     
  87.     function listUsers()
  88.     {
  89.         return $this->pwfile->getAccounts();
  90.     }
  91.  
  92.     // }}}
  93.     // {{{ addUser()
  94.  
  95.     /**
  96.      * Add a new user to the storage container
  97.      *
  98.      * @param string Username
  99.      * @param string Password
  100.      * @param array  Additional information
  101.      *
  102.      * @return boolean 
  103.      */
  104.     function addUser($username$password$additional '')
  105.     {
  106.         $res $this->pwfile->addUser($user$additional['userid']$pass);
  107.         if ($res === true{
  108.             return $this->pwfile->save();
  109.         }
  110.         return $res;
  111.     }
  112.  
  113.     // }}}
  114.     // {{{ removeUser()
  115.  
  116.     /**
  117.      * Remove user from the storage container
  118.      *
  119.      * @param string Username
  120.      */
  121.     function removeUser($username)
  122.     {
  123.         $res $this->pwfile->delUser($username);
  124.         if ($res === true{
  125.             return $this->pwfile->save();
  126.         }
  127.         return $res;
  128.     }
  129.  
  130.     // }}}
  131.     // {{{ changePassword()
  132.  
  133.     /**
  134.      * Change password for user in the storage container
  135.      *
  136.      * @param string Username
  137.      * @param string The new password
  138.      */
  139.     function changePassword($username$password)
  140.     {
  141.          $res $this->pwfile->modUser($username''$password);
  142.          if ($res === true{
  143.              return $this->pwfile->save();
  144.          }
  145.          return $res;
  146.     }
  147.  
  148.     // }}}
  149.  
  150. }
  151. ?>

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