summaryrefslogtreecommitdiff
path: root/src/firstboot
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-29 17:59:50 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-03-29 17:59:50 +0200
commitfe75d5bcfac81505cd89e96baa6e8ee959ec9fb6 (patch)
treea1a917f00ea2b7022c09fdcfa4d3469e8a4097c2 /src/firstboot
parentfe585662829457aa95d88396916d6a4d642a3677 (diff)
downloadsystemd-fe75d5bcfac81505cd89e96baa6e8ee959ec9fb6.tar.gz
firstboot: Check for errors returned by dir_fd_is_root()
Diffstat (limited to 'src/firstboot')
-rw-r--r--src/firstboot/firstboot.c26
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;