| 94 |
jpm |
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.1 2003/05/13 19:23:54 mbretter 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.1 $
|
|
|
42 |
*/
|
|
|
43 |
class Auth_Container_SMBPasswd extends Auth_Container
|
|
|
44 |
{
|
|
|
45 |
/**
|
|
|
46 |
* File_SMBPasswd object
|
|
|
47 |
* @var object
|
|
|
48 |
*/
|
|
|
49 |
var $pwfile;
|
|
|
50 |
|
|
|
51 |
// {{{ Constructor
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Constructor of the container class
|
|
|
55 |
*
|
|
|
56 |
* @param $filename string filename for a passwd type file
|
|
|
57 |
* @return object Returns an error object if something went wrong
|
|
|
58 |
*/
|
|
|
59 |
function Auth_Container_SMBPasswd($filename)
|
|
|
60 |
{
|
|
|
61 |
$this->pwfile = new File_SMBPasswd($filename,0);
|
|
|
62 |
|
|
|
63 |
if (!$this->pwfile->load()) {
|
|
|
64 |
PEAR::raiseError("Error while reading file contents.", 41, PEAR_ERROR_DIE);
|
|
|
65 |
return;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
// }}}
|
|
|
71 |
// {{{ fetchData()
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
* Get user information from pwfile
|
|
|
75 |
*
|
|
|
76 |
* @param string Username
|
|
|
77 |
* @param string Password
|
|
|
78 |
* @return boolean
|
|
|
79 |
*/
|
|
|
80 |
function fetchData($username, $password)
|
|
|
81 |
{
|
|
|
82 |
return $this->pwfile->verifyAccount($username, $password);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
// }}}
|
|
|
86 |
// {{{ listUsers()
|
|
|
87 |
|
|
|
88 |
function listUsers()
|
|
|
89 |
{
|
|
|
90 |
return $this->pwfile->getAccounts();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
// }}}
|
|
|
94 |
// {{{ addUser()
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
* Add a new user to the storage container
|
|
|
98 |
*
|
|
|
99 |
* @param string Username
|
|
|
100 |
* @param string Password
|
|
|
101 |
* @param array Additional information
|
|
|
102 |
*
|
|
|
103 |
* @return boolean
|
|
|
104 |
*/
|
|
|
105 |
function addUser($username, $password, $additional = '')
|
|
|
106 |
{
|
|
|
107 |
$res = $this->pwfile->addUser($user, $additional['userid'], $pass);
|
|
|
108 |
if ($res === true) {
|
|
|
109 |
return $this->pwfile->save();
|
|
|
110 |
}
|
|
|
111 |
return $res;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
// }}}
|
|
|
115 |
// {{{ removeUser()
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Remove user from the storage container
|
|
|
119 |
*
|
|
|
120 |
* @param string Username
|
|
|
121 |
*/
|
|
|
122 |
function removeUser($username)
|
|
|
123 |
{
|
|
|
124 |
$res = $this->pwfile->delUser($username);
|
|
|
125 |
if ($res === true) {
|
|
|
126 |
return $this->pwfile->save();
|
|
|
127 |
}
|
|
|
128 |
return $res;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
// }}}
|
|
|
132 |
|
|
|
133 |
}
|
|
|
134 |
?>
|