]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Db.php
Remove CVS backend
[SourceForge/phpwiki.git] / lib / WikiUser / Db.php
1 <?php
2
3 /*
4  * Copyright (C) 2004 ReiniUrban
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /**
24  * Baseclass for PearDB and ADODB PassUser's
25  * Authenticate against a database, to be able to use shared users.
26  *   internal: no different $DbAuthParams['dsn'] defined, or
27  *   external: different $DbAuthParams['dsn']
28  * The magic is done in the symbolic SQL statements in config/config.ini, similar to
29  * libnss-mysql.
30  *
31  * We support only the SQL and ADODB backends.
32  * The other WikiDB backends (flat, dba, ...) should be used for pages,
33  * not for auth stuff. If one would like to use e.g. dba for auth, he should
34  * use PearDB (SQL) with the right $DBAuthParam['auth_dsn'].
35  * (Not supported yet, since we require SQL. SQLite would make since when
36  * it will come to PHP)
37  *
38  * @tables: user, pref
39  *
40  * Preferences are handled in the parent class _PassUser, because the
41  * previous classes may also use DB pref_select and pref_update.
42  *
43  * Flat files auth is handled by the auth method "File".
44  */
45 class _DbPassUser
46     extends _PassUser
47 {
48     public $_authselect, $_authupdate, $_authcreate;
49
50     // This can only be called from _PassUser, because the parent class
51     // sets the auth_dbi and pref methods, before this class is initialized.
52     function _DbPassUser($UserName = '', $prefs = false)
53     {
54         /**
55          * @var WikiRequest $request
56          */
57         global $request;
58
59         if (!$this->_prefs) {
60             if ($prefs) $this->_prefs = $prefs;
61         }
62         if (!isset($this->_prefs->_method))
63             _PassUser::_PassUser($UserName);
64         elseif (!$this->isValidName($UserName)) {
65             trigger_error(_("Invalid username."), E_USER_WARNING);
66             return false;
67         }
68         $this->_authmethod = 'Db';
69         //$this->getAuthDbh();
70         //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
71         $dbi =& $request->_dbi;
72         $dbtype = $dbi->getParam('dbtype');
73         if ($dbtype == 'ADODB') {
74             include_once 'lib/WikiUser/AdoDb.php';
75             return new _AdoDbPassUser($UserName, $this->_prefs);
76         } elseif ($dbtype == 'SQL') {
77             include_once 'lib/WikiUser/PearDb.php';
78             return new _PearDbPassUser($UserName, $this->_prefs);
79         } elseif ($dbtype == 'PDO') {
80             include_once 'lib/WikiUser/PdoDb.php';
81             return new _PdoDbPassUser($UserName, $this->_prefs);
82         }
83         return false;
84     }
85
86     /* Since we properly quote the username, we allow most chars here.
87        Just " ; and ' is forbidden, max length: 48 as defined in the schema.
88     */
89     function isValidName($userid = false)
90     {
91         if (!$userid) $userid = $this->_userid;
92         if (strcspn($userid, ";'\"") != strlen($userid)) return false;
93         if (strlen($userid) > 48) return false;
94         return true;
95     }
96
97     function mayChangePass()
98     {
99         return !isset($this->_authupdate);
100     }
101
102 }
103
104 // Local Variables:
105 // mode: php
106 // tab-width: 8
107 // c-basic-offset: 4
108 // c-hanging-comment-ender-p: nil
109 // indent-tabs-mode: nil
110 // End: