From f12b11abc70b03fa75faf211a6311acb1cc1b32d Mon Sep 17 00:00:00 2001 From: Loui Chang Date: Sun, 9 Nov 2008 22:35:00 -0500 Subject: Give group writable permissions to uploaded files. Add a new function chown_group to recursively change permissions. Tweak some of the coding style. Replace some of the redundant string concatenation with a variable. Thanks to Dan McGee for chmod_group. Signed-off-by: Loui Chang --- web/lib/aur.inc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'web/lib') diff --git a/web/lib/aur.inc b/web/lib/aur.inc index a126bb94..d08ff0ca 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -381,6 +381,34 @@ function rm_rf($dirname="") { return; } +# Recursive chmod to set group write permissions +# +function chmod_group($path) { + if (!is_dir($path)) + return chmod($path, 0664); + + $d = dir($path); + while ($f = $d->read()) { + if ($f != '.' && $f != '..') { + $fullpath = $path.'/'.$f; + if (is_link($fullpath)) + continue; + elseif (!is_dir($fullpath)) { + if (!chmod($fullpath, 0664)) + return FALSE; + } + elseif(!chmod_group($fullpath)) + return FALSE; + } + } + $d->close(); + + if(chmod($path, 0775)) + return TRUE; + else + return FALSE; +} + # obtain the uid given a Users.Username # function uid_from_username($username="") -- cgit v1.2.3-24-g4f1b