]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
firstboot: Check for errors returned by dir_fd_is_root()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 29 Mar 2023 15:59:50 +0000 (17:59 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 29 Mar 2023 15:59:50 +0000 (17:59 +0200)
src/firstboot/firstboot.c

index 9aaa0af8486ba65347844d50cdcdf0f68ed50c7d..432cab47866b404c8a95365d036bad9021a0f600 100644 (file)
@@ -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;