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