From 2e299c5473badec2ea3037151a0f4d765d60af02 Mon Sep 17 00:00:00 2001 From: Jesse Norell Date: Thu, 10 Dec 2020 10:54:15 -0700 Subject: [PATCH] restoreFileOwnership() excludes system paths --- server/lib/classes/backup.inc.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/server/lib/classes/backup.inc.php b/server/lib/classes/backup.inc.php index cafff35f18..3cdf17d1fc 100644 --- a/server/lib/classes/backup.inc.php +++ b/server/lib/classes/backup.inc.php @@ -100,12 +100,21 @@ class backup * @param string $web_user * @author Ramil Valitov */ - protected static function restoreFileOwnership($web_document_root, $web_user) + protected static function restoreFileOwnership($web_document_root, $web_user, $web_group) { global $app; + $blacklist = array('bin', 'dev', 'etc', 'home', 'lib', 'lib32', 'lib64', 'log', 'opt', 'proc', 'net', 'run', 'sbin', 'ssl', 'srv', 'sys', 'usr', 'var'); + + $find_excludes = '-not -path "." -and -not -path "./web/stats/*"'; + + foreach ( $blacklist as $dir ) { + $find_excludes .= ' -and -not -path "./'.$dir.'" -and -not -path "./'.$dir.'/*"'; + } + $app->log('Restoring permissions for ' . $web_document_root, LOGLEVEL_DEBUG); - $app->system->exec_safe('cd ? && find . -not -path "./web/stats/*" -and -not -path "./log" -and -not -path "./log/*" -and -not -path "./ssl" -and -not -path "./ssl/*" -and -not -path "." -exec chown ?:? {} \;', $web_document_root, $web_user, $web_user); + $app->system->exec_safe('cd ? && find . '.$find_excludes.' -exec chown ?:? {} \;', $web_document_root, $web_user, $web_group); + } /** @@ -290,7 +299,7 @@ class backup */ $success = ($retval == 0 || $retval == 50); if ($success) { - self::restoreFileOwnership($web_root, $web_user); + self::restoreFileOwnership($web_root, $web_user, $web_group); } break; case 'rar': -- GitLab