summaryrefslogtreecommitdiff
path: root/inc/auth
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2006-02-17 23:20:40 +0100
committerAndreas Gohr <andi@splitbrain.org>2006-02-17 23:20:40 +0100
commit98c868589ee0757f176239cf289cbd007bb74852 (patch)
treeeb48a172b0f1a423b93ffff35f8adf8d579383c1 /inc/auth
parent1c73890c5027011d808d38c583561abc309e8086 (diff)
downloadrpg-98c868589ee0757f176239cf289cbd007bb74852.tar.gz
rpg-98c868589ee0757f176239cf289cbd007bb74852.tar.bz2
file cleanups
This patch cleans up the source code to satisfy the coding guidelines (see http://wiki.splitbrain.org/wiki:development#coding_style) It converts files to UNIX lineendings and removes tabs and trailing whitespace. Not all files were cleaned yet. darcs-hash:20060217222040-7ad00-bba3d2bee3b5aa7cbb5184258abd50805cd071bf.gz
Diffstat (limited to 'inc/auth')
-rw-r--r--inc/auth/basic.class.php26
-rw-r--r--inc/auth/ldap.class.php58
-rw-r--r--inc/auth/mysql.class.php144
-rw-r--r--inc/auth/plain.class.php96
-rw-r--r--inc/auth/punbb.class.php6
5 files changed, 165 insertions, 165 deletions
diff --git a/inc/auth/basic.class.php b/inc/auth/basic.class.php
index 6046edea1..faffa4cea 100644
--- a/inc/auth/basic.class.php
+++ b/inc/auth/basic.class.php
@@ -2,12 +2,12 @@
/**
* auth/basic.class.php
*
- * foundation authorisation class
+ * foundation authorisation class
* all auth classes should inherit from this class
*
* @author Chris Smith <chris@jalakai.co.uk>
*/
-
+
class auth_basic {
var $success = true;
@@ -40,11 +40,11 @@ class auth_basic {
* Carry out sanity checks to ensure the object is
* able to operate. Set capabilities in $this->cando
* array here
- *
+ *
* Set $this->success to false if checks fail
*
* @author Christopher Smith <chris@jalakai.co.uk>
- */
+ */
function auth_basic() {
// the base class constructor does nothing, derived class
// constructors do the real work
@@ -166,7 +166,7 @@ class auth_basic {
msg("no valid authorisation system in use", -1);
return false;
}
-
+
/**
* Return user info [ MUST BE OVERRIDDEN ]
*
@@ -184,13 +184,13 @@ class auth_basic {
msg("no valid authorisation system in use", -1);
return false;
}
-
+
/**
* Create a new User [implement only where required/possible]
*
* Returns false if the user already exists, null when an error
* occured and true if everything went well.
- *
+ *
* The new user HAS TO be added to the default group by this
* function!
*
@@ -202,7 +202,7 @@ class auth_basic {
msg("authorisation method does not allow creation of new users", -1);
return null;
}
-
+
/**
* Modify user data [implement only where required/possible]
*
@@ -217,7 +217,7 @@ class auth_basic {
msg("authorisation method does not allow modifying of user data", -1);
return false;
}
-
+
/**
* Delete one or more users [implement only where required/possible]
*
@@ -244,7 +244,7 @@ class auth_basic {
msg("authorisation method does not provide user counts", -1);
return 0;
}
-
+
/**
* Bulk retrieval of user data [implement only where required/possible]
*
@@ -260,10 +260,10 @@ class auth_basic {
msg("authorisation method does not support mass retrieval of user data", -1);
return array();
}
-
+
/**
* Define a group [implement only where required/possible]
- *
+ *
* Set addGroup capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
@@ -276,7 +276,7 @@ class auth_basic {
/**
* Retrieve groups [implement only where required/possible]
- *
+ *
* Set getGroups capability when implemented
*
* @author Chris Smith <chris@jalakai.co.uk>
diff --git a/inc/auth/ldap.class.php b/inc/auth/ldap.class.php
index de1c8570b..49643d3bf 100644
--- a/inc/auth/ldap.class.php
+++ b/inc/auth/ldap.class.php
@@ -2,12 +2,12 @@
/**
* auth/basic.class.php
*
- * foundation authorisation class
+ * foundation authorisation class
* all auth classes should inherit from this class
*
* @author Chris Smith <chris@jalakaic.co.uk>
*/
-
+
class auth_ldap extends auth_basic {
var $cnf = null;
var $con = null;
@@ -28,17 +28,17 @@ class auth_ldap extends auth_basic {
// capabilities are set
}
- /**
- * Check user+password
- *
- * Checks if the given user exists and the given
- * plaintext password is correct by trying to bind
+ /**
+ * Check user+password
+ *
+ * Checks if the given user exists and the given
+ * plaintext password is correct by trying to bind
* to the LDAP server
- *
- * @author Andreas Gohr <andi@splitbrain.org>
- * @return bool
- */
- function checkPass($user,$pass){
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ * @return bool
+ */
+ function checkPass($user,$pass){
// reject empty password
if(empty($pass)) return false;
if(!$this->_openLDAP()) return false;
@@ -108,17 +108,17 @@ class auth_ldap extends auth_basic {
}
return false;
- }
-
- /**
- * Return user info [ MUST BE OVERRIDDEN ]
- *
- * Returns info about the given user needs to contain
- * at least these fields:
- *
- * name string full name of the user
- * mail string email addres of the user
- * grps array list of groups the user is in
+ }
+
+ /**
+ * Return user info [ MUST BE OVERRIDDEN ]
+ *
+ * Returns info about the given user needs to contain
+ * at least these fields:
+ *
+ * name string full name of the user
+ * mail string email addres of the user
+ * grps array list of groups the user is in
*
* This LDAP specific function returns the following
* addional fields:
@@ -130,9 +130,9 @@ class auth_ldap extends auth_basic {
* @author Trouble
* @author Dan Allen <dan.j.allen@gmail.com>
* @auhtor <evaldas.auryla@pheur.org>
- * @return array containing user data or false
+ * @return array containing user data or false
*/
- function getUserData($user) {
+ function getUserData($user) {
global $conf;
if(!$this->_openLDAP()) return false;
@@ -227,8 +227,8 @@ class auth_ldap extends auth_basic {
}
return $info;
- }
-
+ }
+
/**
* Make LDAP filter strings.
*
@@ -237,7 +237,7 @@ class auth_ldap extends auth_basic {
*
* filter string ldap search filter with placeholders
* placeholders array array with the placeholders
- *
+ *
* @author Troels Liebe Bentsen <tlb@rapanden.dk>
* @return string
*/
@@ -254,7 +254,7 @@ class auth_ldap extends auth_basic {
$filter = str_replace('%{'.$match.'}', $value, $filter);
}
return $filter;
- }
+ }
/**
* Opens a connection to the configured LDAP server and sets the wnated
diff --git a/inc/auth/mysql.class.php b/inc/auth/mysql.class.php
index bd8fc42c6..632a97b5d 100644
--- a/inc/auth/mysql.class.php
+++ b/inc/auth/mysql.class.php
@@ -7,19 +7,19 @@
* @author Chris Smith <chris@jalakai.co.uk>
* @author Matthias Grimm <matthias.grimmm@sourceforge.net>
*/
-
-define('DOKU_AUTH', dirname(__FILE__));
+
+define('DOKU_AUTH', dirname(__FILE__));
require_once(DOKU_AUTH.'/basic.class.php');
class auth_mysql extends auth_basic {
-
+
var $dbcon = 0;
var $dbver = 0; // database version
var $dbrev = 0; // database revision
var $dbsub = 0; // database subrevision
var $cnf = null;
var $defaultgroup = "";
-
+
/**
* Constructor
*
@@ -30,17 +30,17 @@ class auth_mysql extends auth_basic {
*/
function auth_mysql() {
global $conf;
-
+
if (method_exists($this, 'auth_basic'))
parent::auth_basic();
-
+
if(!function_exists('mysql_connect')) {
if ($this->cnf['debug'])
msg("MySQL err: PHP MySQL extension not found.",-1);
$this->success = false;
return;
}
-
+
$this->cnf = $conf['auth']['mysql'];
$this->defaultgroup = $conf['defaultgroup'];
@@ -82,7 +82,7 @@ class auth_mysql extends auth_basic {
}
/**
- * Check if the given config strings are set
+ * Check if the given config strings are set
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
* @return bool
@@ -115,16 +115,16 @@ class auth_mysql extends auth_basic {
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+ */
function checkPass($user,$pass){
$rc = false;
-
+
if($this->_openDB()) {
$sql = str_replace('%{user}',addslashes($user),$this->cnf['checkPass']);
$sql = str_replace('%{pass}',addslashes($pass),$sql);
$sql = str_replace('%{dgroup}',addslashes($this->defaultgroup),$sql);
$result = $this->_queryDB($sql);
-
+
if($result !== false && count($result) == 1) {
if($this->cnf['forwardClearPass'] == 1)
$rc = true;
@@ -145,7 +145,7 @@ class auth_mysql extends auth_basic {
* mail string email addres of the user
* grps array list of groups the user is in
*
- * @param $user user's nick to get data for
+ * @param $user user's nick to get data for
*
* @author Andreas Gohr <andi@splitbrain.org>
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
@@ -166,7 +166,7 @@ class auth_mysql extends auth_basic {
*
* Create a new User. Returns false if the user already exists,
* null when an error occured and true if everything went well.
- *
+ *
* The new user will be added to the default group by this
* function if grps are not specified (default behaviour).
*
@@ -188,7 +188,7 @@ class auth_mysql extends auth_basic {
// set defaultgroup if no groups were given
if ($grps == null)
$grps = array($this->defaultgroup);
-
+
$this->_lockTables("WRITE");
$pwd = $this->cnf['forwardClearPass'] ? $pwd : auth_cryptPassword($pwd);
$rc = $this->_addUser($user,$pwd,$name,$mail,$grps);
@@ -198,12 +198,12 @@ class auth_mysql extends auth_basic {
}
return null; // return error
}
-
+
/**
* Modify user data [public function]
*
* An existing user dataset will be modified. Changes are given in an array.
- *
+ *
* The dataset update will be rejected if the user name should be changed
* to an already existing one.
*
@@ -229,10 +229,10 @@ class auth_mysql extends auth_basic {
*/
function modifyUser($user, $changes) {
$rc = false;
-
+
if (!is_array($changes) || !count($changes))
return true; // nothing to change
-
+
if($this->_openDB()) {
$this->_lockTables("WRITE");
@@ -243,17 +243,17 @@ class auth_mysql extends auth_basic {
$groups = $this->_getGroups($user);
$grpadd = array_diff($changes['grps'], $groups);
$grpdel = array_diff($groups, $changes['grps']);
-
+
foreach($grpadd as $group)
if (($this->_addUserToGroup($uid, $group, 1)) == false)
$rc = false;
-
+
foreach($grpdel as $group)
if (($this->_delUserFromGroup($uid, $group)) == false)
$rc = false;
- }
+ }
}
-
+
$this->_unlockTables();
$this->_closeDB();
}
@@ -273,7 +273,7 @@ class auth_mysql extends auth_basic {
*/
function deleteUsers($users) {
$count = 0;
-
+
if($this->_openDB()) {
if (is_array($users) && count($users)) {
$this->_lockTables("WRITE");
@@ -287,7 +287,7 @@ class auth_mysql extends auth_basic {
}
return $count;
}
-
+
/**
* [public function]
*
@@ -300,10 +300,10 @@ class auth_mysql extends auth_basic {
*/
function getUserCount($filter=array()) {
$rc = 0;
-
+
if($this->_openDB()) {
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
-
+
if ($this->dbver >= 4) {
$sql = substr($sql, 6); /* remove 'SELECT' or 'select' */
$sql = "SELECT SQL_CALC_FOUND_ROWS".$sql." LIMIT 1";
@@ -312,12 +312,12 @@ class auth_mysql extends auth_basic {
$rc = $result[0]['FOUND_ROWS()'];
} else if (($result = $this->_queryDB($sql)))
$rc = count($result);
-
+
$this->_closeDB();
}
return $rc;
}
-
+
/**
* Bulk retrieval of user data. [public function]
*
@@ -330,7 +330,7 @@ class auth_mysql extends auth_basic {
*/
function retrieveUsers($first=0,$limit=10,$filter=array()) {
$out = array();
-
+
if($this->_openDB()) {
$this->_lockTables("READ");
$sql = $this->_createSQLFilter($this->cnf['getUsers'], $filter);
@@ -340,7 +340,7 @@ class auth_mysql extends auth_basic {
foreach ($result as $user)
if (($info = $this->_getUserInfo($user['user'])))
$out[$user['user']] = $info;
-
+
$this->_unlockTables();
$this->_closeDB();
}
@@ -349,16 +349,16 @@ class auth_mysql extends auth_basic {
/**
* Give user membership of a group [public function]
- *
+ *
* @param $user
- * @param $group
+ * @param $group
* @return bool true on success, false on error
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function joinGroup($user, $group) {
$rc = false;
-
+
if ($this->_openDB()) {
$this->_lockTables("WRITE");
$uid = $this->_getUserID($user);
@@ -380,7 +380,7 @@ class auth_mysql extends auth_basic {
*/
function leaveGroup($user, $group) {
$rc = false;
-
+
if ($this->_openDB()) {
$this->_lockTables("WRITE");
$uid = $this->_getUserID($user);
@@ -390,7 +390,7 @@ class auth_mysql extends auth_basic {
}
return $rc;
}
-
+
/**
* Adds a user to a group.
*
@@ -410,7 +410,7 @@ class auth_mysql extends auth_basic {
*/
function _addUserToGroup($uid, $group, $force=0) {
$newgroup = 0;
-
+
if (($this->dbcon) && ($uid)) {
$gid = $this->_getGroupID($group);
if (!$gid) {
@@ -421,7 +421,7 @@ class auth_mysql extends auth_basic {
}
if (!$gid) return false; // group didn't exist and can't be created
}
-
+
$sql = str_replace('%{uid}', addslashes($uid),$this->cnf['addUserGroup']);
$sql = str_replace('%{user}', addslashes($user),$sql);
$sql = str_replace('%{gid}', addslashes($gid),$sql);
@@ -448,7 +448,7 @@ class auth_mysql extends auth_basic {
*/
function _delUserFromGroup($uid, $group) {
$rc = false;
-
+
if (($this->dbcon) && ($uid)) {
$gid = $this->_getGroupID($group);
if ($gid) {
@@ -461,7 +461,7 @@ class auth_mysql extends auth_basic {
}
return $rc;
}
-
+
/**
* Retrieves a list of groups the user is a member off.
*
@@ -477,11 +477,11 @@ class auth_mysql extends auth_basic {
*/
function _getGroups($user) {
$groups = array();
-
+
if($this->dbcon) {
$sql = str_replace('%{user}',addslashes($user),$this->cnf['getGroups']);
$result = $this->_queryDB($sql);
-
+
if(count($result)) {
foreach($result as $row)
$groups[] = $row['group'];
@@ -493,7 +493,7 @@ class auth_mysql extends auth_basic {
/**
* Retrieves the user id of a given user name
- *
+ *
* The database connection must already be established
* for this function to work. Otherwise it will return
* 'false'.
@@ -511,7 +511,7 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Adds a new User to the database.
*
@@ -535,16 +535,16 @@ class auth_mysql extends auth_basic {
$sql = str_replace('%{user}', addslashes($user),$this->cnf['addUser']);
$sql = str_replace('%{pass}', addslashes($pwd),$sql);
$sql = str_replace('%{name}', addslashes($name),$sql);
- $sql = str_replace('%{email}',addslashes($mail),$sql);
+ $sql = str_replace('%{email}',addslashes($mail),$sql);
$uid = $this->_modifyDB($sql);
-
+
if ($uid) {
foreach($grps as $group) {
$uid = $this->_getUserID($user);
$gid = $this->_addUserToGroup($uid, $group, 1);
if ($gid === false) break;
}
-
+
if ($gid) return true;
else {
/* remove the new user and all group relations if a group can't
@@ -560,10 +560,10 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Deletes a given user and all his group references.
- *
+ *
* The database connection must already be established
* for this function to work. Otherwise it will return
* 'false'.
@@ -638,7 +638,7 @@ class auth_mysql extends auth_basic {
if($this->dbcon) {
foreach ($changes as $item => $value) {
- if ($item == 'user') {
+ if ($item == 'user') {
if (($this->_getUserID($changes['user']))) {
$err = 1; /* new username already exists */
break; /* abort update */
@@ -673,7 +673,7 @@ class auth_mysql extends auth_basic {
/**
* Retrieves the group id of a given group name
- *
+ *
* The database connection must already be established
* for this function to work. Otherwise it will return
* 'false'.
@@ -691,19 +691,19 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Opens a connection to a database and saves the handle for further
* usage in the object. The successful call to this functions is
* essential for most functions in this object.
- *
+ *
* @return bool
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
*/
function _openDB() {
if (!$this->dbcon) {
- $con = @mysql_connect ($this->cnf['server'], $this->cnf['user'], $this->cnf['password']);
+ $con = @mysql_connect ($this->cnf['server'], $this->cnf['user'], $this->cnf['password']);
if ($con) {
if ((mysql_select_db($this->cnf['database'], $con))) {
if ((preg_match("/^(\d+)\.(\d+)\.(\d+).*/", mysql_get_server_info ($con), $result)) == 1) {
@@ -711,13 +711,13 @@ class auth_mysql extends auth_basic {
$this->dbrev = $result[2];
$this->dbsub = $result[3];
}
- $this->dbcon = $con;
+ $this->dbcon = $con;
return true; // connection and database successfully opened
} else {
mysql_close ($con);
if ($this->cnf['debug'])
msg("MySQL err: No access to database {$this->cnf['database']}.", -1);
- }
+ }
} else if ($this->cnf['debug'])
msg ("MySQL err: Connection to {$this->cnf['user']}@{$this->cnf['server']} not possible.", -1);
@@ -725,7 +725,7 @@ class auth_mysql extends auth_basic {
}
return true; // connection already open
}
-
+
/**
* Closes a database connection.
*
@@ -737,19 +737,19 @@ class auth_mysql extends auth_basic {
$this->dbcon = 0;
}
}
-
+
/**
* Sends a SQL query to the database and transforms the result into
* an associative array.
- *
- * This function is only able to handle queries that returns a
+ *
+ * This function is only able to handle queries that returns a
* table such as SELECT.
*
* @param $query SQL string that contains the query
* @return array with the result table
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+ */
function _queryDB($query) {
if ($this->dbcon) {
$result = @mysql_query($query,$this->dbcon);
@@ -764,10 +764,10 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Sends a SQL query to the database
- *
+ *
* This function is only able to handle queries that returns
* either nothing or an id value such as INPUT, DELETE, UPDATE, etc.
*
@@ -775,7 +775,7 @@ class auth_mysql extends auth_basic {
* @return insert id or 0, false on error
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+ */
function _modifyDB($query) {
if ($this->dbcon) {
$result = @mysql_query($query,$this->dbcon);
@@ -788,7 +788,7 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Locked a list of tables for exclusive access so that modifications
* to the database can't be disturbed by other threads. The list
@@ -806,7 +806,7 @@ class auth_mysql extends auth_basic {
* @param $mode could be 'READ' or 'WRITE'
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+ */
function _lockTables($mode) {
if ($this->dbcon) {
if (is_array($this->cnf['TablesToLock']) && !empty($this->cnf['TablesToLock'])) {
@@ -830,7 +830,7 @@ class auth_mysql extends auth_basic {
* abrogated.
*
* @author Matthias Grimm <matthiasgrimm@users.sourceforge.net>
- */
+ */
function _unlockTables() {
if ($this->dbcon) {
$this->_modifyDB("UNLOCK TABLES");
@@ -838,7 +838,7 @@ class auth_mysql extends auth_basic {
}
return false;
}
-
+
/**
* Transforms the filter settings in an filter string for a SQL database
* The database connection must already be established, otherwise the
@@ -854,7 +854,7 @@ class auth_mysql extends auth_basic {
function _createSQLFilter($sql, $filter) {
$SQLfilter = "";
$cnt = 0;
-
+
if ($this->dbcon) {
foreach ($filter as $item => $pattern) {
$tmp = addslashes('%'.mysql_real_escape_string($pattern, $this->dbcon).'%');
@@ -872,11 +872,11 @@ class auth_mysql extends auth_basic {
$SQLfilter .= str_replace('%{group}',$tmp,$this->cnf['FilterGroup']);
}
}
-
+
// we have to check SQLfilter here and must not use $cnt because if
// any of cnf['Filter????'] is not defined, a malformed SQL string
// would be generated.
-
+
if (strlen($SQLfilter)) {
$glue = strpos(strtolower($sql),"where") ? " AND " : " WHERE ";
$sql = $sql.$glue.$SQLfilter;
@@ -885,8 +885,8 @@ class auth_mysql extends auth_basic {
return $sql;
}
-
-
+
+
}
//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/auth/plain.class.php b/inc/auth/plain.class.php
index 9ab3bc70a..3ed014262 100644
--- a/inc/auth/plain.class.php
+++ b/inc/auth/plain.class.php
@@ -6,8 +6,8 @@
* @author Andreas Gohr <andi@splitbrain.org>
* @author Chris Smith <chris@jalakai.co.uk>
*/
-
-define('DOKU_AUTH', dirname(__FILE__));
+
+define('DOKU_AUTH', dirname(__FILE__));
require_once(DOKU_AUTH.'/basic.class.php');
define('AUTH_USERFILE',DOKU_CONF.'users.auth.php');
@@ -15,22 +15,22 @@ define('AUTH_USERFILE',DOKU_CONF.'users.auth.php');
// we only accept page ids for auth_plain
if(isset($_REQUEST['u']))
$_REQUEST['u'] = cleanID($_REQUEST['u']);
-
+
class auth_plain extends auth_basic {
var $users = null;
var $_pattern = array();
-
- /**
- * Constructor
- *
- * Carry out sanity checks to ensure the object is
- * able to operate. Set capabilities.
- *
+
+ /**
+ * Constructor
+ *
+ * Carry out sanity checks to ensure the object is
+ * able to operate. Set capabilities.
+ *
* @author Christopher Smith <chris@jalakai.co.uk>
- */
- function auth_plain() {
- if (!@is_readable(AUTH_USERFILE)){
+ */
+ function auth_plain() {
+ if (!@is_readable(AUTH_USERFILE)){
$this->success = false;
}else{
if(@is_writable(AUTH_USERFILE)){
@@ -45,7 +45,7 @@ class auth_plain extends auth_basic {
$this->cando['getUsers'] = true;
$this->cando['getUserCount'] = true;
}
- }
+ }
/**
* Check user+password [required auth function]
@@ -57,10 +57,10 @@ class auth_plain extends auth_basic {
* @return bool
*/
function checkPass($user,$pass){
-
+
$userinfo = $this->getUserData($user);
if ($userinfo === false) return false;
-
+
return auth_verifyPassword($pass,$this->users[$user]['pass']);
}
@@ -87,7 +87,7 @@ class auth_plain extends auth_basic {
*
* Returns false if the user already exists, null when an error
* occured and true if everything went well.
- *
+ *
* The new user will be added to the default group by this
* function if grps are not specified (default behaviour).
*
@@ -96,28 +96,28 @@ class auth_plain extends auth_basic {
*/
function createUser($user,$pwd,$name,$mail,$grps=null){
global $conf;
-
+
// user mustn't already exist
if ($this->getUserData($user) !== false) return false;
-
+
$pass = auth_cryptPassword($pwd);
-
+
// set default group if no groups specified
if (!is_array($grps)) $grps = array($conf['defaultgroup']);
// prepare user line
- $groups = join(',',$grps);
+ $groups = join(',',$grps);
$userline = join(':',array($user,$pass,$name,$mail,$groups))."\n";
if (io_saveFile(AUTH_USERFILE,$userline,true)) {
$this->users[$user] = compact('pass','name','mail','grps');
return $pwd;
}
-
+
msg('The '.AUTH_USERFILE.' file is not writable. Please inform the Wiki-Admin',-1);
return null;
}
-
+
/**
* Modify user data
*
@@ -130,7 +130,7 @@ class auth_plain extends auth_basic {
global $conf;
global $ACT;
global $INFO;
-
+
// sanity checks, user must already exist and there must be something to change
if (($userinfo = $this->getUserData($user)) === false) return false;
if (!is_array($changes) || !count($changes)) return true;
@@ -138,31 +138,31 @@ class auth_plain extends auth_basic {
// update userinfo with new data, remembering to encrypt any password
$newuser = $user;
foreach ($changes as $field => $value) {
- if ($field == 'user') {
+ if ($field == 'user') {
$newuser = $value;
continue;
}
if ($field == 'pass') $value = auth_cryptPassword($value);
$userinfo[$field] = $value;
}
-
+
$groups = join(',',$userinfo['grps']);
$userline = join(':',array($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $groups))."\n";
-
+
if (!$this->deleteUsers(array($user))) {
msg('Unable to modify user data. Please inform the Wiki-Admin',-1);
return false;
}
-
+
if (!io_saveFile(AUTH_USERFILE,$userline,true)) {
msg('There was an error modifying your user data. You should register again.',-1);
// FIXME, user has been deleted but not recreated, should force a logout and redirect to login page
$ACT == 'register';
return false;
}
-
+
$this->users[$newuser] = $userinfo;
- return true;
+ return true;
}
/**
@@ -173,18 +173,18 @@ class auth_plain extends auth_basic {
* @return int the number of users deleted
*/
function deleteUsers($users) {
-
+
if (!is_array($users) || empty($users)) return 0;
if ($this->users === null) $this->_loadUserData();
-
+
$deleted = array();
foreach ($users as $user) {
if (isset($this->users[$user])) $deleted[] = preg_quote($user,'/');
}
if (empty($deleted)) return 0;
-
+
$pattern = '/^('.join('|',$deleted).'):/';
if (io_deleteFromFile(AUTH_USERFILE,$pattern,true)) {
@@ -198,7 +198,7 @@ class auth_plain extends auth_basic {
$count -= $count($this->users());
return $count;
}
-
+
/**
* Return a count of the number of user which meet $filter criteria
*
@@ -208,18 +208,18 @@ class auth_plain extends auth_basic {
if($this->users === null) $this->_loadUserData();
- if (!count($filter)) return count($this->users);
-
+ if (!count($filter)) return count($this->users);
+
$count = 0;
$this->_constructPattern($filter);
-
+
foreach ($this->users as $user => $info) {
$count += $this->_filter($user, $info);
}
-
+
return $count;
}
-
+
/**
* Bulk retrieval of user data
*
@@ -234,12 +234,12 @@ class auth_plain extends auth_basic {
if ($this->users === null) $this->_loadUserData();
ksort($this->users);
-
+
$i = 0;
$count = 0;
$out = array();
$this->_constructPattern($filter);
-
+
foreach ($this->users as $user => $info) {
if ($this->_filter($user, $info)) {
if ($i >= $start) {
@@ -253,7 +253,7 @@ class auth_plain extends auth_basic {
return $out;
}
-
+
/**
* Load all user data
*
@@ -265,23 +265,23 @@ class auth_plain extends auth_basic {
$this->users = array();
if(!@file_exists(AUTH_USERFILE)) return;
-
+
$lines = file(AUTH_USERFILE);
foreach($lines as $line){
$line = preg_replace('/#.*$/','',$line); //ignore comments
$line = trim($line);
if(empty($line)) continue;
-
+
$row = split(":",$line,5);
$groups = split(",",$row[4]);
-
+
$this->users[$row[0]]['pass'] = $row[1];
$this->users[$row[0]]['name'] = urldecode($row[2]);
$this->users[$row[0]]['mail'] = $row[3];
$this->users[$row[0]]['grps'] = $groups;
}
}
-
+
/**
* return 1 if $user + $info match $filter criteria, 0 otherwise
*
@@ -300,14 +300,14 @@ class auth_plain extends auth_basic {
}
return 1;
}
-
+
function _constructPattern($filter) {
$this->_pattern = array();
foreach ($filter as $item => $pattern) {
// $this->_pattern[$item] = '/'.preg_quote($pattern,"/").'/'; // don't allow regex characters
$this->_pattern[$item] = '/'.str_replace('/','\/',$pattern).'/'; // allow regex characters
}
- }
+ }
}
//Setup VIM: ex: et ts=2 enc=utf-8 :
diff --git a/inc/auth/punbb.class.php b/inc/auth/punbb.class.php
index 455432d51..9a380728a 100644
--- a/inc/auth/punbb.class.php
+++ b/inc/auth/punbb.class.php
@@ -24,8 +24,8 @@ class auth_punbb extends auth_mysql {
*/
function auth_punbb(){
global $conf;
- $this->cando['external'] = true;
- $this->cando['logoff'] = true;
+ $this->cando['external'] = true;
+ $this->cando['logoff'] = true;
// make sure we use a crypt understood by punbb
if(function_exists('sha1')){
@@ -73,7 +73,7 @@ class auth_punbb extends auth_mysql {
(username, password, email, realname)
VALUES ('%{user}', '%{pass}', '%{email}', '%{name}')";
$conf['auth']['mysql']['addGroup'] = "INSERT INTO ${db_prefix}groups (g_title) VALUES ('%{group}')";
- $conf['auth']['mysql']['addUserGroup']= "UPDATE ${db_prefix}users
+ $conf['auth']['mysql']['addUserGroup']= "UPDATE ${db_prefix}users
SET group_id=%{gid}
WHERE id='%{uid}'";
$conf['auth']['mysql']['delGroup'] = "DELETE FROM ${db_prefix}groups WHERE g_id='%{gid}'";