Skip to content

Commit

Permalink
Use io_replaceInFile for updating auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ptbrown committed May 7, 2015
1 parent 1bd6bbd commit 699e3c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
11 changes: 2 additions & 9 deletions lib/plugins/acl/admin.php
Expand Up @@ -682,7 +682,6 @@ function _get_exact_perm(){
*/
function _acl_add($acl_scope, $acl_user, $acl_level){
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 @@ -692,9 +691,7 @@ function _acl_add($acl_scope, $acl_user, $acl_level){

$new_acl = "$acl_scope\t$acl_user\t$acl_level\n";

$new_config = $acl_config.$new_acl;

return io_saveFile($config_cascade['acl']['default'], $new_config);
return io_saveFile($config_cascade['acl']['default'], $new_config, true);
}

/**
Expand All @@ -704,15 +701,11 @@ function _acl_add($acl_scope, $acl_user, $acl_level){
*/
function _acl_del($acl_scope, $acl_user){
global $config_cascade;
$acl_config = file($config_cascade['acl']['default']);
$acl_user = auth_nameencode($acl_user,true);

$acl_pattern = '^'.preg_quote($acl_scope,'/').'[ \t]+'.$acl_user.'[ \t]+[0-8].*$';

// save all non!-matching
$new_config = preg_grep("/$acl_pattern/", $acl_config, PREG_GREP_INVERT);

return io_saveFile($config_cascade['acl']['default'], join('',$new_config));
return io_deleteFromFile($config_cascade['acl']['default'], "/$acl_pattern/", true);
}

/**
Expand Down
11 changes: 3 additions & 8 deletions lib/plugins/authplain/auth.php
Expand Up @@ -185,14 +185,9 @@ public function modifyUser($user, $changes) {

$userline = $this->_createUserLine($newuser, $userinfo['pass'], $userinfo['name'], $userinfo['mail'], $userinfo['grps']);

if(!$this->deleteUsers(array($user))) {
msg('Unable to modify user data. Please inform the Wiki-Admin', -1);
return false;
}

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
if(!io_replaceInFile($config_cascade['plainauth.users']['default'], '/^'.$user.':/', $userline, true)) {
msg('There was an error modifying your user data. You may need to register again.', -1);
// FIXME, io functions should be fail-safe so existing data isn't lost
$ACT = 'register';
return false;
}
Expand Down

0 comments on commit 699e3c4

Please sign in to comment.