Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1173 jp_milcent 1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
3
 
4
/**
5
 * Storage driver for use against Samba password files
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: This source file is subject to version 3.01 of the PHP license
10
 * that is available through the world-wide-web at the following URI:
11
 * http://www.php.net/license/3_01.txt.  If you did not receive a copy of
12
 * the PHP License and are unable to obtain it through the web, please
13
 * send a note to license@php.net so we can mail you a copy immediately.
14
 *
15
 * @category   Authentication
16
 * @package    Auth
1713 jp_milcent 17
 * @author     Michael Bretterklieber <michael@bretterklieber.com>
1173 jp_milcent 18
 * @author     Adam Ashley <aashley@php.net>
19
 * @copyright  2001-2006 The PHP Group
20
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
1713 jp_milcent 21
 * @version    CVS: $Id: SMBPasswd.php,v 1.3 2007-11-19 15:11:00 jp_milcent Exp $
1173 jp_milcent 22
 * @link       http://pear.php.net/package/Auth
23
 * @since      File available since Release 1.2.3
24
 */
25
 
26
/**
27
 * Include PEAR File_SMBPasswd
28
 */
29
require_once "File/SMBPasswd.php";
30
/**
31
 * Include Auth_Container Base file
32
 */
33
require_once "Auth/Container.php";
34
/**
35
 * Include PEAR class for error handling
36
 */
37
require_once "PEAR.php";
38
 
39
/**
40
 * Storage driver for fetching login data from an SAMBA smbpasswd file.
41
 *
42
 * This storage container can handle SAMBA smbpasswd files.
43
 *
44
 * Example:
45
 * $a = new Auth("SMBPasswd", '/usr/local/private/smbpasswd');
46
 * $a->start();
47
 * if ($a->getAuth()) {
48
 *     printf ("AUTH OK<br>\n");
49
 *     $a->logout();
50
 * }
51
 *
52
 * @category   Authentication
53
 * @package    Auth
54
 * @author     Michael Bretterklieber <michael@bretterklieber.com>
55
 * @author     Adam Ashley <aashley@php.net>
56
 * @package    Auth
57
 * @copyright  2001-2006 The PHP Group
58
 * @license    http://www.php.net/license/3_01.txt  PHP License 3.01
1713 jp_milcent 59
 * @version    Release: 1.5.4  File: $Revision: 1.3 $
1173 jp_milcent 60
 * @link       http://pear.php.net/package/Auth
61
 * @since      Class available since Release 1.2.3
62
 */
63
class Auth_Container_SMBPasswd extends Auth_Container
64
{
65
 
66
    // {{{ properties
67
 
68
    /**
69
     * File_SMBPasswd object
70
     * @var object
71
     */
72
    var $pwfile;
73
 
74
    // }}}
75
 
76
    // {{{ Auth_Container_SMBPasswd() [constructor]
77
 
78
    /**
79
     * Constructor of the container class
80
     *
81
     * @param  $filename   string filename for a passwd type file
82
     * @return object Returns an error object if something went wrong
83
     */
84
    function Auth_Container_SMBPasswd($filename)
85
    {
86
        $this->pwfile = new File_SMBPasswd($filename,0);
87
 
88
        if (!$this->pwfile->load()) {
89
            PEAR::raiseError("Error while reading file contents.", 41, PEAR_ERROR_DIE);
90
            return;
91
        }
92
 
93
    }
94
 
95
    // }}}
96
    // {{{ fetchData()
97
 
98
    /**
99
     * Get user information from pwfile
100
     *
101
     * @param   string Username
102
     * @param   string Password
103
     * @return  boolean
104
     */
105
    function fetchData($username, $password)
106
    {
1713 jp_milcent 107
        $this->log('Auth_Container_SMBPasswd::fetchData() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 108
        return $this->pwfile->verifyAccount($username, $password);
109
    }
110
 
111
    // }}}
112
    // {{{ listUsers()
1713 jp_milcent 113
 
1173 jp_milcent 114
    function listUsers()
115
    {
1713 jp_milcent 116
        $this->log('Auth_Container_SMBPasswd::fetchData() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 117
        return $this->pwfile->getAccounts();
118
    }
119
 
120
    // }}}
121
    // {{{ addUser()
122
 
123
    /**
124
     * Add a new user to the storage container
125
     *
126
     * @param string Username
127
     * @param string Password
128
     * @param array  Additional information
129
     *
130
     * @return boolean
131
     */
132
    function addUser($username, $password, $additional = '')
133
    {
1713 jp_milcent 134
        $this->log('Auth_Container_SMBPasswd::addUser() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 135
        $res = $this->pwfile->addUser($user, $additional['userid'], $pass);
136
        if ($res === true) {
137
            return $this->pwfile->save();
138
        }
139
        return $res;
140
    }
141
 
142
    // }}}
143
    // {{{ removeUser()
144
 
145
    /**
146
     * Remove user from the storage container
147
     *
148
     * @param string Username
149
     */
150
    function removeUser($username)
151
    {
1713 jp_milcent 152
        $this->log('Auth_Container_SMBPasswd::removeUser() called.', AUTH_LOG_DEBUG);
1173 jp_milcent 153
        $res = $this->pwfile->delUser($username);
154
        if ($res === true) {
155
            return $this->pwfile->save();
156
        }
157
        return $res;
158
    }
159
 
160
    // }}}
161
    // {{{ changePassword()
162
 
163
    /**
164
     * Change password for user in the storage container
165
     *
166
     * @param string Username
1713 jp_milcent 167
     * @param string The new password
1173 jp_milcent 168
     */
169
    function changePassword($username, $password)
170
    {
1713 jp_milcent 171
        $this->log('Auth_Container_SMBPasswd::changePassword() called.', AUTH_LOG_DEBUG);
172
        $res = $this->pwfile->modUser($username, '', $password);
173
        if ($res === true) {
174
            return $this->pwfile->save();
175
        }
176
        return $res;
1173 jp_milcent 177
    }
178
 
179
    // }}}
180
 
181
}
182
?>