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.3 2006/02/28 02:19:22 aashley 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.  * @author   Adam Ashley <aashley@php.net>
  41.  * @package  Auth
  42.  * @version  $Revision: 1.3 $
  43.  */
  44. {
  45.  
  46.     // {{{ properties
  47.  
  48.     /**
  49.      * File_SMBPasswd object
  50.      * @var object 
  51.      */
  52.     var $pwfile;
  53.  
  54.     // }}}
  55.  
  56.     // {{{ Auth_Container_SMBPasswd() [constructor]
  57.  
  58.     /**
  59.      * Constructor of the container class
  60.      *
  61.      * @param  $filename   string filename for a passwd type file
  62.      * @return object Returns an error object if something went wrong
  63.      */
  64.     function Auth_Container_SMBPasswd($filename)
  65.     {
  66.         $this->pwfile = new File_SMBPasswd($filename,0);
  67.  
  68.         if (!$this->pwfile->load()) {
  69.             PEAR::raiseError("Error while reading file contents."41PEAR_ERROR_DIE);
  70.             return;
  71.         }
  72.  
  73.     }
  74.  
  75.     // }}}
  76.     // {{{ fetchData()
  77.  
  78.     /**
  79.      * Get user information from pwfile
  80.      *
  81.      * @param   string Username
  82.      * @param   string Password
  83.      * @return  boolean 
  84.      */
  85.     function fetchData($username$password)
  86.     {
  87.         return $this->pwfile->verifyAccount($username$password);
  88.     }
  89.  
  90.     // }}}
  91.     // {{{ listUsers()
  92.     
  93.     function listUsers()
  94.     {
  95.         return $this->pwfile->getAccounts();
  96.     }
  97.  
  98.     // }}}
  99.     // {{{ addUser()
  100.  
  101.     /**
  102.      * Add a new user to the storage container
  103.      *
  104.      * @param string Username
  105.      * @param string Password
  106.      * @param array  Additional information
  107.      *
  108.      * @return boolean 
  109.      */
  110.     function addUser($username$password$additional '')
  111.     {
  112.         $res $this->pwfile->addUser($user$additional['userid']$pass);
  113.         if ($res === true{
  114.             return $this->pwfile->save();
  115.         }
  116.         return $res;
  117.     }
  118.  
  119.     // }}}
  120.     // {{{ removeUser()
  121.  
  122.     /**
  123.      * Remove user from the storage container
  124.      *
  125.      * @param string Username
  126.      */
  127.     function removeUser($username)
  128.     {
  129.         $res $this->pwfile->delUser($username);
  130.         if ($res === true{
  131.             return $this->pwfile->save();
  132.         }
  133.         return $res;
  134.     }
  135.  
  136.     // }}}
  137.     // {{{ changePassword()
  138.  
  139.     /**
  140.      * Change password for user in the storage container
  141.      *
  142.      * @param string Username
  143.      * @param string The new password
  144.      */
  145.     function changePassword($username$password)
  146.     {
  147.          $res $this->pwfile->modUser($username''$password);
  148.          if ($res === true{
  149.              return $this->pwfile->save();
  150.          }
  151.          return $res;
  152.     }
  153.  
  154.     // }}}
  155.  
  156. }
  157. ?>

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