]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiUser/Db.php
var --> public
[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, cvs, 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         if (!$this->_prefs) {
55             if ($prefs) $this->_prefs = $prefs;
56         }
57         if (!isset($this->_prefs->_method))
58             _PassUser::_PassUser($UserName);
59         elseif (!$this->isValidName($UserName)) {
60             trigger_error(_("Invalid username."), E_USER_WARNING);
61             return false;
62         }
63         $this->_authmethod = 'Db';
64         //$this->getAuthDbh();
65         //$this->_auth_crypt_method = @$GLOBALS['DBAuthParams']['auth_crypt_method'];
66         $dbi =& $GLOBALS['request']->_dbi;
67         $dbtype = $dbi->getParam('dbtype');
68         if ($dbtype == 'ADODB') {
69             include_once 'lib/WikiUser/AdoDb.php';
70             return new _AdoDbPassUser($UserName, $this->_prefs);
71         } elseif ($dbtype == 'SQL') {
72             include_once 'lib/WikiUser/PearDb.php';
73             return new _PearDbPassUser($UserName, $this->_prefs);
74         } elseif ($dbtype == 'PDO') {
75             include_once 'lib/WikiUser/PdoDb.php';
76             return new _PdoDbPassUser($UserName, $this->_prefs);
77         }
78         return false;
79     }
80
81     /* Since we properly quote the username, we allow most chars here.
82        Just " ; and ' is forbidden, max length: 48 as defined in the schema.
83     */
84     function isValidName($userid = false)
85     {
86         if (!$userid) $userid = $this->_userid;
87         if (strcspn($userid, ";'\"") != strlen($userid)) return false;
88         if (strlen($userid) > 48) return false;
89         return true;
90     }
91
92     function mayChangePass()
93     {
94         return !isset($this->_authupdate);
95     }
96
97 }
98
99 // Local Variables:
100 // mode: php
101 // tab-width: 8
102 // c-basic-offset: 4
103 // c-hanging-comment-ender-p: nil
104 // indent-tabs-mode: nil
105 // End: