]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: use chase_symlinks_and_access() where appropriate
authorLennart Poettering <lennart@poettering.net>
Thu, 22 Dec 2022 09:30:02 +0000 (10:30 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 Dec 2022 17:09:02 +0000 (18:09 +0100)
src/core/dbus-manager.c

index ed91e9a1cfcb907dc75e79205d5988c54c3d5852..6109ab6ce09e4e0832aac597d737dd2016a7a720 100644 (file)
@@ -1702,8 +1702,6 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er
                                                  "Specified switch root path '%s' does not seem to be an OS tree. os-release file is missing.",
                                                  root);
         } else {
-                _cleanup_free_ char *chased = NULL;
-
                 if (!path_is_valid(init))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
                                                  "Path to init binary '%s' is not a valid path.", init);
@@ -1712,19 +1710,13 @@ static int method_switch_root(sd_bus_message *message, void *userdata, sd_bus_er
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
                                                  "Path to init binary '%s' not absolute.", init);
 
-                r = chase_symlinks(init, root, CHASE_PREFIX_ROOT|CHASE_TRAIL_SLASH, &chased, NULL);
+                r = chase_symlinks_and_access(init, root, CHASE_PREFIX_ROOT, X_OK, NULL, NULL);
+                if (r == -EACCES)
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
+                                                 "Init binary %s is not executable.", init);
                 if (r < 0)
                         return sd_bus_error_set_errnof(error, r,
                                                        "Could not resolve init executable %s: %m", init);
-
-                if (laccess(chased, X_OK) < 0) {
-                        if (errno == EACCES)
-                                return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS,
-                                                         "Init binary %s is not executable.", init);
-
-                        return sd_bus_error_set_errnof(error, r,
-                                                       "Could not check whether init binary %s is executable: %m", init);
-                }
         }
 
         rt = strdup(root);