From: Lennart Poettering Date: Thu, 22 Dec 2022 09:30:02 +0000 (+0100) Subject: core: use chase_symlinks_and_access() where appropriate X-Git-Tag: v253-rc1~213^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e10086ac01627a19d3cb32fcd6fc42c12fb2584f;p=thirdparty%2Fsystemd.git core: use chase_symlinks_and_access() where appropriate --- diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index ed91e9a1cfc..6109ab6ce09 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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);