summaryrefslogtreecommitdiff
path: root/inc/init.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2006-03-04 16:40:38 +0100
committerAndreas Gohr <andi@splitbrain.org>2006-03-04 16:40:38 +0100
commit1ca31cfe69e2d10cce65c4323eb652b355f4c904 (patch)
tree5783a2da2d5ef9ba40aef392b7ad959740125e4c /inc/init.php
parent7c6f82e59d762d68d99d1a88f449d1035ffa5f76 (diff)
downloadrpg-1ca31cfe69e2d10cce65c4323eb652b355f4c904.tar.gz
rpg-1ca31cfe69e2d10cce65c4323eb652b355f4c904.tar.bz2
simplified file permission handling
This patch simpliefies the configuration of the file and directory creation modes. There is no need to set the umask anymore. Only the wanted permissions for files and directories are set. An init function compares the wanted modes with the ones that would be choosen by the system automatically (consulting the system's umask) and sets the modes for chmod when needed. darcs-hash:20060304154038-7ad00-5ef1db3a87e42563a602f9d050c681d2ea74682f.gz
Diffstat (limited to 'inc/init.php')
-rw-r--r--inc/init.php59
1 files changed, 33 insertions, 26 deletions
diff --git a/inc/init.php b/inc/init.php
index 1557070e5..10c7240d8 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -77,31 +77,8 @@
$conf['usegzip'] = 0;
}
- // Legacy support for old umask/dmask scheme
- if(isset($conf['dmask'])) {
- unset($conf['dmask']);
- unset($conf['fmask']);
- unset($conf['umask']);
- }
-
- // Set defaults for fmode, dmode and umask.
- if(!isset($conf['fmode']) || $conf['fmode'] === '') {
- $conf['fmode'] = 0666;
- }
- if(!isset($conf['dmode']) || $conf['dmode'] === '') {
- $conf['dmode'] = 0777;
- }
- if(!isset($conf['umask']) || $conf['umask'] === '') {
- $conf['umask'] = umask();
- }
-
- // Precalculate the fmask and dmask, so we can set later.
- if(($conf['umask'] != umask()) or ($conf['fmode'] != 0666)) {
- $conf['fmask'] = $conf['fmode'] & ~$conf['umask'];
- }
- if(($conf['umask'] != umask()) or ($conf['dmode'] != 0666)) {
- $conf['dmask'] = $conf['dmode'] & ~$conf['umask'];
- }
+ // precalculate file creation modes
+ init_creationmodes();
// make real paths and check them
init_paths();
@@ -149,7 +126,7 @@ function init_files(){
$fh = @fopen($file,'a');
if($fh){
fclose($fh);
- if(isset($conf['fmask'])) { chmod($file, $conf['fmask']); }
+ if($conf['fperm']) chmod($file, $conf['fperm']);
}else{
nice_die("$file is not writable. Check your permissions settings!");
}
@@ -189,6 +166,36 @@ function init_path($path){
}
/**
+ * Sets the internal config values fperm and dperm which, when set,
+ * will be used to change the permission of a newly created dir or
+ * file with chmod. Considers the influence of the system's umask
+ * setting the values only if needed.
+ */
+function init_creationmodes(){
+ global $conf;
+
+ // Legacy support for old umask/dmask scheme
+ unset($conf['dmask']);
+ unset($conf['fmask']);
+ unset($conf['umask']);
+ unset($conf['fperm']);
+ unset($conf['dperm']);
+
+ // get system umask
+ $umask = umask();
+
+ // check what is set automatically by the system on file creation
+ // and set the fperm param if it's not what we want
+ $auto_fmode = 0666 & ~$umask;
+ if($auto_fmode != $conf['fmode']) $conf['fperm'] = $conf['fmode'];
+
+ // check what is set automatically by the system on file creation
+ // and set the dperm param if it's not what we want
+ $auto_dmode = $conf['dmode'] & ~$umask;
+ if($auto_dmode != $conf['dmode']) $conf['dperm'] = $conf['dmode'];
+}
+
+/**
* remove magic quotes recursivly
*
* @author Andreas Gohr <andi@splitbrain.org>