From: Daan De Meyer Date: Wed, 29 Mar 2023 15:59:50 +0000 (+0200) Subject: firstboot: Check for errors returned by dir_fd_is_root() X-Git-Tag: v254-rc1~872^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe75d5bcfac81505cd89e96baa6e8ee959ec9fb6;p=thirdparty%2Fsystemd.git firstboot: Check for errors returned by dir_fd_is_root() --- diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 9aaa0af8486..432cab47866 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;