Source for file XML.php
Documentation is available at XML.php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
* A framework for authentication and authorization in PHP applications
* LiveUser is an authentication/permission framework designed
* to be flexible and easily extendable.
* Since it is impossible to have a
* "one size fits all" it takes a container
* approach which should enable it to
* be versatile enough to meet most needs.
* LICENSE: This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* @category authentication
* @author Markus Wolff <wolff@21st.de>
* @author Helgi Þormar Þorbjörnsson <dufuz@php.net>
* @author Lukas Smith <smith@pooteeweet.org>
* @author Arnaud Limbourg <arnaud@php.net>
* @author Pierre-Alain Joye <pajoye@php.net>
* @author Bjoern Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version CVS: $Id: XML.php,v 1.44 2006/08/22 17:11:43 lsmith Exp $
* @link http://pear.php.net/LiveUser
* Require parent class definition and XML::Tree class.
require_once 'LiveUser/Auth/Common.php';
require_once 'XML/Tree.php';
* XML driver for authentication
* This is a XML backend driver for the LiveUser class.
* @category authentication
* @author Björn Kraus <krausbn@php.net>
* @copyright 2002-2006 Markus Wolff
* @license http://www.gnu.org/licenses/lgpl.txt
* @version Release: @package_version@
* @link http://pear.php.net/LiveUser
* XML file in which the auth data is stored.
* XML::Tree object of the user logged in.
* Load the storage container
* @param array array containing the configuration.
* @param string name of the container that should be used
* @return bool true on success or false on failure
function init(&$conf, $containerName)
parent ::init($conf, $containerName);
"Perm initialisation failed. Can't find xml file.");
$this->file = getenv('DOCUMENT_ROOT') . $this->file;
$tree = & new XML_Tree ($this->file);
$err = & $tree->getTreeFromFile ();
if (PEAR ::isError ($err)) {
"Perm initialisation failed. Can't get tree from file");
if (!is_a($this->tree, 'xml_tree')) {
array ('container' => 'storage layer configuration missing'));
* Writes current values for user back to the database.
* @return bool true on success or false on failure
function _updateUserData ()
foreach ($this->userObj->children as $value) {
if ($value->name == $this->alias['lastlogin']) {
$el = & $this->userObj->getElement (array ($index));
$errorMsg = 'Auth freeze failure. Cannot write to the xml file';
$fp = fopen($this->file, 'wb');
$errorMsg = "Auth freeze failure. Failed to open the xml file.";
if (!flock($fp, LOCK_EX )) {
$errorMsg = "Auth freeze failure. Couldn't get an exclusive lock on the file.";
if (!fwrite($fp, $this->tree->get ())) {
$errorMsg = "Auth freeze failure. Write error when writing back the file.";
array (), 'Cannot read XML Auth file: '. $errorMsg);
* Reads user data from the given data source
* If only $handle is given, it will read the data
* from the first user with that handle and return
* If $handle and $passwd are given, it will try to
* find the first user with both handle and password
* matching and return true on success (this allows
* multiple users having the same handle but different
* passwords - yep, some people want this).
* if only an auth_user_id is passed it will try to read the data based on the id
* If no match is found, false is being returned.
* @param string user handle
* @param string user password
* @param bool|intif the user data should be read using the auth user id
* @return bool true on success or false on failure
function readUserData($handle = '', $passwd = '', $auth_user_id = false )
foreach ($this->tree->root ->children as $user) {
foreach ($user->children as $value) {
$result[$names[$value->name ]] = $value->content;
&& $auth_user_id === $result['auth_user_id']
} elseif (array_key_exists('handle', $result) && $handle === $result['handle']) {
&& $this->encryptPW($passwd) === $result['passwd']
// dont look for any further matching handles
$this->userObj = & $this->tree->root ->getElement (array ($index));
* Properly disconnect from resources
* @return bool true on success or false on failure
Documentation generated on Mon, 28 Jan 2008 03:30:34 -0500 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|