Subversion Repositories Applications.papyrus

Rev

Rev 1087 | Details | Compare with Previous | Last modification | View Log | RSS feed

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