diff options
-rw-r--r-- | src/firstboot/firstboot.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 9aaa0af848..432cab4786 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -344,7 +344,11 @@ static int process_locale(int rfd) { if (r <= 0) return r; - if (arg_copy_locale && !dir_fd_is_root(rfd)) { + r = dir_fd_is_root(rfd); + if (r < 0) + return log_error_errno(r, "Failed to check if directory file descriptor is root: %m"); + + if (arg_copy_locale && r == 0) { r = copy_file_atomic_at(AT_FDCWD, "/etc/locale.conf", pfd, f, 0644, COPY_REFLINK); if (r != -ENOENT) { if (r < 0) @@ -429,7 +433,11 @@ static int process_keymap(int rfd) { if (r <= 0) return r; - if (arg_copy_keymap && !dir_fd_is_root(rfd)) { + r = dir_fd_is_root(rfd); + if (r < 0) + return log_error_errno(r, "Failed to check if directory file descriptor is root: %m"); + + if (arg_copy_keymap && r == 0) { r = copy_file_atomic_at(AT_FDCWD, "/etc/vconsole.conf", pfd, f, 0644, COPY_REFLINK); if (r != -ENOENT) { if (r < 0) @@ -517,7 +525,11 @@ static int process_timezone(int rfd) { if (r <= 0) return r; - if (arg_copy_timezone && !dir_fd_is_root(rfd)) { + r = dir_fd_is_root(rfd); + if (r < 0) + return log_error_errno(r, "Failed to check if directory file descriptor is root: %m"); + + if (arg_copy_timezone && r == 0) { _cleanup_free_ char *s = NULL; r = readlink_malloc("/etc/localtime", &s); @@ -973,7 +985,11 @@ static int process_root_account(int rfd) { if (r < 0) return log_error_errno(r, "Failed to take a lock on /etc/passwd: %m"); - if (arg_copy_root_shell && !dir_fd_is_root(rfd)) { + k = dir_fd_is_root(rfd); + if (k < 0) + return log_error_errno(k, "Failed to check if directory file descriptor is root: %m"); + + if (arg_copy_root_shell && k == 0) { struct passwd *p; errno = 0; @@ -990,7 +1006,7 @@ static int process_root_account(int rfd) { if (r < 0) return r; - if (arg_copy_root_password && !dir_fd_is_root(rfd)) { + if (arg_copy_root_password && k == 0) { struct spwd *p; errno = 0; |