[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/authmysql/ -> auth.php (summary)

(no description)

File Size: 1110 lines (39 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

auth_plugin_authmysql:: (33 methods):
  __construct()
  _chkcnf()
  checkPass()
  getUserData()
  createUser()
  modifyUser()
  deleteUsers()
  getUserCount()
  retrieveUsers()
  joinGroup()
  leaveGroup()
  isCaseSensitive()
  _addUserToGroup()
  _delUserFromGroup()
  _getGroups()
  _getUserID()
  _addUser()
  _delUser()
  _flushUserInfoCache()
  _cacheExists()
  _getUserInfo()
  _retrieveUserInfo()
  _updateUserInfo()
  _getGroupID()
  _openDB()
  _closeDB()
  _queryDB()
  _modifyDB()
  _lockTables()
  _unlockTables()
  _createSQLFilter()
  _escape()
  _debug()


Class: auth_plugin_authmysql  - X-Ref

MySQL authentication backend

__construct()   X-Ref
Constructor

checks if the mysql interface is available, otherwise it will
set the variable $success of the basis class to false

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>

_chkcnf($keys, $wop = false)   X-Ref
Check if the given config strings are set

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string[] $keys
param: bool  $wop is this a check for a write operation?

checkPass($user, $pass)   X-Ref
Checks if the given user exists and the given plaintext password
is correct. Furtheron it might be checked wether the user is
member of the right group

Depending on which SQL string is defined in the config, password
checking is done here (getpass) or by the database (passcheck)

author: Andreas Gohr <andi@splitbrain.org>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string $user user who would like access
param: string $pass user's clear text password to check

getUserData($user, $requireGroups=true)   X-Ref
Return user info

author: Andreas Gohr <andi@splitbrain.org>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: array|bool
param: string $user user login to get data for
param: bool $requireGroups  when true, group membership information should be included in the returned array;

createUser($user, $pwd, $name, $mail, $grps = null)   X-Ref
Create a new User. Returns false if the user already exists,
null when an error occurred 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).

author: Andreas Gohr <andi@splitbrain.org>
author: Chris Smith <chris@jalakai.co.uk>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool|null
param: string $user  nick of the user
param: string $pwd   clear text password
param: string $name  full name of the user
param: string $mail  email address
param: array  $grps  array of groups the user should become member of

modifyUser($user, $changes)   X-Ref
Modify user data

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.

The password must be provided unencrypted. Pasword encryption is done
automatically if configured.

If one or more groups can't be updated, an error will be set. In
this case the dataset might already be changed and we can't rollback
the changes. Transactions would be really useful here.

modifyUser() may be called without SQL statements defined that are
needed to change group membership (for example if only the user profile
should be modified). In this case we assure that we don't touch groups
even when $changes['grps'] is set by mistake.

author: Chris Smith <chris@jalakai.co.uk>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool   true on success, false on error
param: string $user    nick of the user to be changed
param: array  $changes array of field/value pairs to be changed (password will be clear text)

deleteUsers($users)   X-Ref
[public function]

Remove one or more users from the list of registered users

author: Christopher Smith <chris@jalakai.co.uk>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: int             the number of users deleted
param: array  $users   array of users to be deleted

getUserCount($filter = array()   X-Ref
Counts users which meet certain $filter criteria.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: int count of found users
param: array $filter  filter criteria in item/pattern pairs

retrieveUsers($first = 0, $limit = 0, $filter = array()   X-Ref
Bulk retrieval of user data

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: array userinfo (refer getUserData for internal userinfo details)
param: int          $first  index of first user to be returned
param: int          $limit  max number of users to be returned
param: array $filter array of field/pattern pairs

joinGroup($user, $group)   X-Ref
Give user membership of a group

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool   true on success, false on error
param: string $user
param: string $group

leaveGroup($user, $group)   X-Ref
Remove user from a group

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string $user  user that leaves a group
param: string $group group to leave

isCaseSensitive()   X-Ref
MySQL is case-insensitive


_addUserToGroup($user, $group, $force = false)   X-Ref
Adds a user to a group.

If $force is set to true non existing groups would be created.

The database connection must already be established. Otherwise
this function does nothing and returns 'false'. It is strongly
recommended to call this function only after all participating
tables (group and usergroup) have been locked.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool   true on success, false on error
param: string $user    user to add to a group
param: string $group   name of the group
param: bool   $force   create missing groups

_delUserFromGroup($user, $group)   X-Ref
Remove user from a group

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool   true on success, false on error
param: string $user  user that leaves a group
param: string $group group to leave

_getGroups($user)   X-Ref
Retrieves a list of groups the user is a member off.

The database connection must already be established
for this function to work. Otherwise it will return
false.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool|array false on error, all groups on success
param: string $user user whose groups should be listed

_getUserID($user)   X-Ref
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.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: mixed  user id
param: string $user user whose id is desired

_addUser($user, $pwd, $name, $mail, $grps)   X-Ref
Adds a new User to the database.

The database connection must already be established
for this function to work. Otherwise it will return
false.

author: Andreas Gohr <andi@splitbrain.org>
author: Chris Smith <chris@jalakai.co.uk>
author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string $user  login of the user
param: string $pwd   encrypted password
param: string $name  full name of the user
param: string $mail  email address
param: array  $grps  array of groups the user should become member of

_delUser($user)   X-Ref
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.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string $user username of the user to be deleted

_flushUserInfoCache($user=null)   X-Ref
Flush cached user information

author: Christopher Smith <chris@jalakai.co.uk>
param: string  $user username of the user whose data is to be removed from the cache

_cacheExists($user, $requireGroups=true)   X-Ref
Quick lookup to see if a user's information has been cached

This test does not need a database connection or read lock

author: Christopher Smith <chris@jalakai.co.uk>
return: bool    existence of required user information in the cache
param: string  $user  username to be looked up in the cache
param: bool    $requireGroups  true, if cached info should include group memberships

_getUserInfo($user, $requireGroups=true, $useCache=true)   X-Ref
Get a user's information

The database connection must already be established for this function to work.

author: Christopher Smith <chris@jalakai.co.uk>
return: mixed   false|array     false if the user doesn't exist
param: string  $user  username of the user whose information is being reterieved
param: bool    $requireGroups  true if group memberships should be included
param: bool    $useCache       true if ok to return cached data & to cache returned data

_retrieveUserInfo($user)   X-Ref
retrieveUserInfo

Gets the data for a specific user. The database connection
must already be established for this function to work.
Otherwise it will return 'false'.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: false|array false on error, user info on success
param: string $user  user's nick to get data for

_updateUserInfo($user, $changes)   X-Ref
Updates the user info in the database

Update a user data structure in the database according changes
given in an array. The user name can only be changes if it didn't
exists already. If the new user name exists the update procedure
will be aborted. The database keeps unchanged.

The database connection has already to be established for this
function to work. Otherwise it will return 'false'.

The password will be encrypted if necessary.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool true on success or false on error
param: string $user    user's nick being updated
param: array $changes  array of items to change as pairs of item and value

_getGroupID($group)   X-Ref
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.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: false|string group id
param: string $group   group name which id is desired

_openDB()   X-Ref
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.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool

_closeDB()   X-Ref
Closes a database connection.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>

_queryDB($query)   X-Ref
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
table such as SELECT.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: array|false with the result table
param: string $query  SQL string that contains the query

_modifyDB($query)   X-Ref
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.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: int|bool insert id or 0, false on error
param: string $query  SQL string that contains the query

_lockTables($mode)   X-Ref
Locked a list of tables for exclusive access so that modifications
to the database can't be disturbed by other threads. The list
could be set with $conf['plugin']['authmysql']['TablesToLock'] = array()

If aliases for tables are used in SQL statements, also this aliases
must be locked. For eg. you use a table 'user' and the alias 'u' in
some sql queries, the array must looks like this (order is important):
array("user", "user AS u");

MySQL V3 is not able to handle transactions with COMMIT/ROLLBACK
so that this functionality is simulated by this function. Nevertheless
it is not as powerful as transactions, it is a good compromise in safty.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool
param: string $mode  could be 'READ' or 'WRITE'

_unlockTables()   X-Ref
Unlock locked tables. All existing locks of this thread will be
abrogated.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: bool

_createSQLFilter($sql, $filter)   X-Ref
Transforms the filter settings in an filter string for a SQL database
The database connection must already be established, otherwise the
original SQL string without filter criteria will be returned.

author: Matthias Grimm <matthiasgrimm@users.sourceforge.net>
return: string SQL string with attached $filter criteria on success, original SQL string on error
param: string $sql     SQL string to which the $filter criteria should be added
param: array $filter  array of filter criteria as pairs of item and pattern

_escape($string, $like = false)   X-Ref
Escape a string for insertion into the database

author: Andreas Gohr <andi@splitbrain.org>
return: string
param: string  $string The string to escape
param: boolean $like   Escape wildcard chars as well?

_debug($message, $err, $line, $file)   X-Ref
Wrapper around msg() but outputs only when debug is enabled

return: void
param: string $message
param: int    $err
param: int    $line
param: string $file