Skip to content

Commit

Permalink
Use config_cascade for ACLs and plain auth users FS#1677
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed Jun 27, 2010
1 parent c5ef5f5 commit c8f80b4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
5 changes: 3 additions & 2 deletions inc/auth.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 16 additions & 10 deletions inc/auth/plain.class.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -89,6 +89,7 @@ function getUserData($user){
*/
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;
Expand All @@ -102,12 +103,13 @@ function createUser($user,$pwd,$name,$mail,$grps=null){
$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;
}

Expand All @@ -123,6 +125,7 @@ function modifyUser($user, $changes) {
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;
Expand All @@ -147,7 +150,7 @@ function modifyUser($user, $changes) {
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';
Expand All @@ -166,6 +169,7 @@ function modifyUser($user, $changes) {
* @return int the number of users deleted
*/
function deleteUsers($users) {
global $config_cascade;

if (!is_array($users) || empty($users)) return 0;

Expand All @@ -180,7 +184,7 @@ function deleteUsers($users) {

$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);
}
Expand Down Expand Up @@ -271,11 +275,13 @@ function cleanGroup($group){
* @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);
Expand Down
38 changes: 22 additions & 16 deletions inc/init.php
Expand Up @@ -77,26 +77,32 @@ function delta_time($start=0) {
'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()
Expand Down
11 changes: 7 additions & 4 deletions lib/plugins/acl/admin.php
Expand Up @@ -69,6 +69,7 @@ function handle() {
global $AUTH_ACL;
global $ID;
global $auth;
global $config_cascade;

// fresh 1:1 copy without replacements
$AUTH_ACL = file(DOKU_CONF.'acl.auth.php');
Expand Down Expand Up @@ -161,11 +162,11 @@ function handle() {
}
}
// 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
Expand Down Expand Up @@ -696,7 +697,8 @@ function _get_exact_perm(){
* @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
Expand All @@ -718,7 +720,8 @@ function _acl_add($acl_scope, $acl_user, $acl_level){
* @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].*$';
Expand Down

0 comments on commit c8f80b4

Please sign in to comment.