/usr/share/php/Horde/Auth/Customsql.php is in php-horde-auth 2.2.2-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | <?php
/**
* Copyright 2002 Ronnie Garcia <ronnie@mk2.net>
* Copyright 2002-2017 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you did
* not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @author Ronnie Garcia <ronnie@mk2.net>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Joel Vandal <joel@scopserv.com>
* @category Horde
* @license http://opensource.org/licenses/lgpl-2.1.php LGPL-2.1
* @package Auth
*/
/**
* The Horde_Auth_Customsql class provides a sql implementation of the Horde
* authentication system with the possibility to set custom-made queries.
*
* @author Ronnie Garcia <ronnie@mk2.net>
* @author Chuck Hagenbuch <chuck@horde.org>
* @author Joel Vandal <joel@scopserv.com>
* @category Horde
* @copyright 2002 Ronnie Garcia <ronnie@mk2.net>
* @copyright 2002-2017 Horde LLC
* @license http://opensource.org/licenses/lgpl-2.1.php LGPL-2.1
* @package Auth
*/
class Horde_Auth_Customsql extends Horde_Auth_Sql
{
/**
* An array of capabilities, so that the driver can report which
* operations it supports and which it doesn't.
*
* @var array
*/
protected $_capabilities = array(
'add' => true,
'list' => true,
'remove' => true,
'resetpassword' => true,
'update' => true,
'authenticate' => true,
);
/**
* Constructor.
*
* Some special tokens can be used in the SQL query. They are replaced
* at the query stage:
* '\L' will be replaced by the user's login
* '\P' will be replaced by the user's password.
* '\O' will be replaced by the old user's login (required for update)
*
* Eg: "SELECT * FROM users WHERE uid = \L
* AND passwd = \P
* AND billing = 'paid'"
*
* @param array $params Configuration parameters:
* - query_auth: (string) Authenticate the user. ('\L' & '\P')
* - query_add: (string) Add user. ('\L' & '\P')
* - query_getpw: (string) Get one user's password. ('\L')
* - query_update: (string) Update user. ('\O', '\L' & '\P')
* - query_resetpassword: (string) Reset password. ('\L', & '\P')
* - query_remove: (string) Remove user. ('\L')
* - query_list: (string) List user.
* - query_exists: (string) Check for existance of user. ('\L')
*/
public function __construct(array $params = array())
{
foreach (array('query_auth', 'query_add',
'query_update', 'query_resetpassword', 'query_remove',
'query_list') as $val) {
if (empty($params[$val])) {
switch($val) {
case 'query_auth':
$this->_capabilities['authenticate'] = false;
break;
case 'query_add':
$this->_capabilities['add'] = false;
break;
case 'query_update':
$this->_capabilities['update'] = false;
break;
case 'query_resetpassword':
$this->_capabilities['resetpassword'] = false;
break;
case 'query_remove':
$this->_capabilities['remove'] = false;
break;
case 'query_list':
$this->_capabilities['list'] = false;
break;
}
}
}
parent::__construct($params);
}
/**
* Find out if a set of login credentials are valid.
*
* @param string $userId The userId to check.
* @param array $credentials The credentials to use.
*
* @throws Horde_Auth_Exception
*/
protected function _authenticate($userId, $credentials)
{
/* Build a custom query, based on the config file. */
$query = str_replace(
array('\L', '\P'),
array(
$this->_db->quote($userId),
$this->_db->quote(Horde_Auth::getCryptedPassword($credentials['password'], $this->_getPassword($userId), $this->_params['encryption'], $this->_params['show_encryption']))
),
$this->_params['query_auth']
);
try {
if ($this->_db->selectValue($query)) {
return;
}
throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
}
}
/**
* Add a set of authentication credentials.
*
* @param string $userId The userId to add.
* @param array $credentials The credentials to add.
*
* @throws Horde_Auth_Exception
*/
public function addUser($userId, $credentials)
{
/* Build a custom query, based on the config file. */
$query = str_replace(
array('\L', '\P'),
array(
$this->_db->quote($userId),
$this->_db->quote(Horde_Auth::getCryptedPassword($credentials['password'], '', $this->_params['encryption'], $this->_params['show_encryption']))
),
$this->_params['query_add']
);
try {
$this->_db->insert($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
}
/**
* Update a set of authentication credentials.
*
* @param string $oldId The old userId.
* @param string $newId The new userId.
* @param array $credentials The new credentials
*
* @throws Horde_Auth_Exception
*/
public function updateUser($oldId, $newId, $credentials)
{
/* Build a custom query, based on the config file. */
$query = str_replace(
array('\O', '\L', '\P'),
array(
$this->_db->quote($oldId),
$this->_db->quote($newId),
$this->_db->quote(Horde_Auth::getCryptedPassword($credentials['password'], $this->_getPassword($oldId), $this->_params['encryption'], $this->_params['show_encryption']))
),
$this->_params['query_update']
);
try {
$this->_db->update($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
}
/**
* Resets a user's password. Used for example when the user does not
* remember the existing password.
*
* @param string $userId The user id for which to reset the password.
*
* @return string The new password on success.
* @throws Horde_Auth_Exception
*/
public function resetPassword($userId)
{
/* Get a new random password. */
$password = Horde_Auth::genRandomPassword();
/* Build the SQL query. */
$query = str_replace(
array('\L', '\P'),
array(
$this->_db->quote($userId),
$this->_db->quote(Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], $this->_params['show_encryption']))
),
$this->_params['query_resetpassword']
);
try {
$this->_db->update($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
return $password;
}
/**
* Delete a set of authentication credentials.
*
* @param string $userId The userId to delete.
*
* @throws Horde_Auth_Exception
*/
public function removeUser($userId)
{
/* Build a custom query, based on the config file. */
$query = str_replace(
'\L',
$this->_db->quote($userId),
$this->_params['query_remove']
);
try {
$this->_db->delete($query);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
}
/**
* Lists all users in the system.
*
* @param boolean $sort Sort the users?
*
* @return array The array of userIds.
* @throws Horde_Auth_Exception
*/
public function listUsers($sort = false)
{
/* Build a custom query, based on the config file. */
$query = str_replace(
'\L',
$this->_db->quote($this->_params['default_user']),
$this->_params['query_list']
);
try {
$users = $this->_db->selectValues($query);
// Find a way to sort in database with portable SQL
return $this->_sort($users, $sort);
} catch (Horde_Db_Exception $e) {
throw new Horde_Auth_Exception($e);
}
}
/**
* Checks if a userId exists in the system.
*
* @param string $userId User ID for which to check
*
* @return boolean Whether or not the userId already exists.
*/
public function exists($userId)
{
if (empty($this->_params['query_exists'])) {
return parent::exists($userId);
}
/* Build a custom query, based on the config file. */
$query = str_replace(
'\L',
$this->_db->quote($userId),
$this->_params['query_exists']
);
try {
return (bool)$this->_db->selectValue($query);
} catch (Horde_Db_Exception $e) {
return false;
}
}
/**
* Fetch $userId's current password - needed for the salt with some
* encryption schemes when doing authentication or updates.
*
* @param string $userId The userId to query.
*
* @return string $userId's current password.
*/
protected function _getPassword($userId)
{
/* Retrieve the old password in case we need the salt. */
$query = str_replace(
'\L',
$this->_db->quote($userId),
$this->_params['query_getpw']
);
try {
return $this->_db->selectValue($query);
} catch (Horde_Db_Exception $e) {
return null;
}
}
}
|