From c8f80b4e70ee1b73ecc08cac583d021979af9359 Mon Sep 17 00:00:00 2001 From: Andreas Gohr <andi@splitbrain.org> Date: Sun, 27 Jun 2010 14:43:56 +0200 Subject: [PATCH] Use config_cascade for ACLs and plain auth users FS#1677 --- inc/auth.php | 5 +++-- inc/auth/plain.class.php | 26 ++++++++++++++++---------- inc/init.php | 38 ++++++++++++++++++++++---------------- lib/plugins/acl/admin.php | 11 +++++++---- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/inc/auth.php b/inc/auth.php index 6a4108a7c..49bb2d4d9 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -35,6 +35,7 @@ function auth_setup(){ global $auth; global $AUTH_ACL; global $lang; + global $config_cascade; $AUTH_ACL = array(); if(!$conf['useacl']) return false; @@ -102,8 +103,8 @@ function auth_setup(){ } //load ACL into a global array XXX - if(is_readable(DOKU_CONF.'acl.auth.php')){ - $AUTH_ACL = file(DOKU_CONF.'acl.auth.php'); + if(is_readable($config_cascade['acl']['default'])){ + $AUTH_ACL = file($config_cascade['acl']['default']); //support user wildcard if(isset($_SERVER['REMOTE_USER'])){ $AUTH_ACL = str_replace('%USER%',$_SERVER['REMOTE_USER'],$AUTH_ACL); diff --git a/inc/auth/plain.class.php b/inc/auth/plain.class.php index af4fadb36..ec9e52beb 100644 --- a/inc/auth/plain.class.php +++ b/inc/auth/plain.class.php @@ -7,8 +7,6 @@ * @author Chris Smith <chris@jalakai.co.uk> */ -define('AUTH_USERFILE',DOKU_CONF.'users.auth.php'); - class auth_plain extends auth_basic { var $users = null; @@ -23,10 +21,12 @@ class auth_plain extends auth_basic { * @author Christopher Smith <chris@jalakai.co.uk> */ function auth_plain() { - if (!@is_readable(AUTH_USERFILE)){ + global $config_cascade; + + if (!@is_readable($config_cascade['plainauth.users']['default'])){ $this->success = false; }else{ - if(@is_writable(AUTH_USERFILE)){ + if(@is_writable($config_cascade['plainauth.users']['default'])){ $this->cando['addUser'] = true; $this->cando['delUser'] = true; $this->cando['modLogin'] = true; @@ -89,6 +89,7 @@ class auth_plain extends auth_basic { */ function createUser($user,$pwd,$name,$mail,$grps=null){ global $conf; + global $config_cascade; // user mustn't already exist if ($this->getUserData($user) !== false) return false; @@ -102,12 +103,13 @@ class auth_plain extends auth_basic { $groups = join(',',$grps); $userline = join(':',array($user,$pass,$name,$mail,$groups))."\n"; - if (io_saveFile(AUTH_USERFILE,$userline,true)) { + if (io_saveFile($config_cascade['plainauth.users']['default'],$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); + msg('The '.$config_cascade['plainauth.users']['default']. + ' file is not writable. Please inform the Wiki-Admin',-1); return null; } @@ -123,6 +125,7 @@ class auth_plain extends auth_basic { global $conf; global $ACT; global $INFO; + global $config_cascade; // sanity checks, user must already exist and there must be something to change if (($userinfo = $this->getUserData($user)) === false) return false; @@ -147,7 +150,7 @@ class auth_plain extends auth_basic { return false; } - if (!io_saveFile(AUTH_USERFILE,$userline,true)) { + if (!io_saveFile($config_cascade['plainauth.users']['default'],$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'; @@ -166,6 +169,7 @@ class auth_plain extends auth_basic { * @return int the number of users deleted */ function deleteUsers($users) { + global $config_cascade; if (!is_array($users) || empty($users)) return 0; @@ -180,7 +184,7 @@ class auth_plain extends auth_basic { $pattern = '/^('.join('|',$deleted).'):/'; - if (io_deleteFromFile(AUTH_USERFILE,$pattern,true)) { + if (io_deleteFromFile($config_cascade['plainauth.users']['default'],$pattern,true)) { foreach ($deleted as $user) unset($this->users[$user]); return count($deleted); } @@ -271,11 +275,13 @@ class auth_plain extends auth_basic { * @author Andreas Gohr <andi@splitbrain.org> */ function _loadUserData(){ + global $config_cascade; + $this->users = array(); - if(!@file_exists(AUTH_USERFILE)) return; + if(!@file_exists($config_cascade['plainauth.users']['default'])) return; - $lines = file(AUTH_USERFILE); + $lines = file($config_cascade['plainauth.users']['default']); foreach($lines as $line){ $line = preg_replace('/#.*$/','',$line); //ignore comments $line = trim($line); diff --git a/inc/init.php b/inc/init.php index 9a3eaf9c9..21382cdb0 100644 --- a/inc/init.php +++ b/inc/init.php @@ -77,26 +77,32 @@ if (empty($config_cascade)) { 'local' => array(DOKU_CONF.'license.local.php'), ), 'mediameta' => array( - 'default' => array(DOKU_CONF.'mediameta.php'), - 'local' => array(DOKU_CONF.'mediameta.local.php'), - ), + 'default' => array(DOKU_CONF.'mediameta.php'), + 'local' => array(DOKU_CONF.'mediameta.local.php'), + ), 'mime' => array( - 'default' => array(DOKU_CONF.'mime.conf'), - 'local' => array(DOKU_CONF.'mime.local.conf'), - ), + 'default' => array(DOKU_CONF.'mime.conf'), + 'local' => array(DOKU_CONF.'mime.local.conf'), + ), 'scheme' => array( - 'default' => array(DOKU_CONF.'scheme.conf'), - 'local' => array(DOKU_CONF.'scheme.local.conf'), - ), + 'default' => array(DOKU_CONF.'scheme.conf'), + 'local' => array(DOKU_CONF.'scheme.local.conf'), + ), 'smileys' => array( - 'default' => array(DOKU_CONF.'smileys.conf'), - 'local' => array(DOKU_CONF.'smileys.local.conf'), - ), + 'default' => array(DOKU_CONF.'smileys.conf'), + 'local' => array(DOKU_CONF.'smileys.local.conf'), + ), 'wordblock' => array( - 'default' => array(DOKU_CONF.'wordblock.conf'), - 'local' => array(DOKU_CONF.'wordblock.local.conf'), - ), - ); + 'default' => array(DOKU_CONF.'wordblock.conf'), + 'local' => array(DOKU_CONF.'wordblock.local.conf'), + ), + 'acl' => array( + 'default' => DOKU_CONF.'acl.auth.php', + ), + 'plainauth.users' => array( + 'default' => DOKU_CONF.'users.auth.php', + ), + ); } //prepare config array() diff --git a/lib/plugins/acl/admin.php b/lib/plugins/acl/admin.php index 673ffbc96..84932f7ac 100644 --- a/lib/plugins/acl/admin.php +++ b/lib/plugins/acl/admin.php @@ -69,6 +69,7 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { global $AUTH_ACL; global $ID; global $auth; + global $config_cascade; // fresh 1:1 copy without replacements $AUTH_ACL = file(DOKU_CONF.'acl.auth.php'); @@ -161,11 +162,11 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { } } // save it - io_saveFile(DOKU_CONF.'acl.auth.php', join('',$lines)); + io_saveFile($config_cascade['acl']['default'], join('',$lines)); } // reload ACL config - $AUTH_ACL = file(DOKU_CONF.'acl.auth.php'); + $AUTH_ACL = file($config_cascade['acl']['default']); } // initialize ACL array @@ -696,7 +697,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * @author Frank Schubert <frank@schokilade.de> */ function _acl_add($acl_scope, $acl_user, $acl_level){ - $acl_config = file_get_contents(DOKU_CONF.'acl.auth.php'); + global $config_cascade; + $acl_config = file_get_contents($config_cascade['acl']['default']); $acl_user = auth_nameencode($acl_user,true); // max level for pagenames is edit @@ -718,7 +720,8 @@ class admin_plugin_acl extends DokuWiki_Admin_Plugin { * @author Frank Schubert <frank@schokilade.de> */ function _acl_del($acl_scope, $acl_user){ - $acl_config = file(DOKU_CONF.'acl.auth.php'); + global $config_cascade; + $acl_config = file($config_cascade['acl']['default']); $acl_user = auth_nameencode($acl_user,true); $acl_pattern = '^'.preg_quote($acl_scope,'/').'\s+'.$acl_user.'\s+[0-8].*$'; -- GitLab