From ba2da34854a2dc8a099d2266c3b94158e3906807 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Fri, 29 Apr 2022 10:04:38 +0200 Subject: [PATCH] system: only restore missign or zero size ACL files #5746 --- src/etc/rc.subr.d/recover | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/etc/rc.subr.d/recover b/src/etc/rc.subr.d/recover index 18162f462..15ae1dc35 100755 --- a/src/etc/rc.subr.d/recover +++ b/src/etc/rc.subr.d/recover @@ -2,7 +2,7 @@ + * Copyright (c) 2015-2022 Franco Fichtner * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -263,11 +263,17 @@ function recover_rebuild() function recover_base($etc_group, $etc_master_passwd, $etc_shells, $etc_ttys, $php_ini) { - echo "===> Restoring /etc/group\n"; - file_put_contents('/etc/group', $etc_group); + $partial_restore = [ + '/etc/group' => $etc_group, + '/etc/master.passwd' => $etc_master_passwd, + ]; - echo "===> Restoring /etc/master.passwd\n"; - file_put_contents('/etc/master.passwd', $etc_master_passwd); + foreach ($partial_restore as $file => $content) { + if (!file_exists($file) || filesize($file) === 0) { + echo "===> Restoring $file\n"; + file_put_contents($file, $content); + } + } echo "===> Restoring /etc/shells\n"; file_put_contents('/etc/shells', $etc_shells);