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