From 601686e833bae3a15d6a6ca79b952df923fd552e Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Sun, 8 Oct 2023 20:22:47 +0200 Subject: [PATCH] login: access login.noauth file directly There is no need to scan a directory if we already know the filename we are looking for. While at it, close resources afterwards. Signed-off-by: Tobias Stoeckmann --- login-utils/login.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/login-utils/login.c b/login-utils/login.c index 1f3f5d36c1..82f0cd9f7f 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -1292,9 +1292,8 @@ static void __attribute__((__noreturn__)) usage(void) } static void load_credentials(struct login_context *cxt) { + char str[32] = { 0 }; char *env; - DIR *dir; - struct dirent *d; struct path_cxt *pc; env = safe_getenv("CREDENTIALS_DIRECTORY"); @@ -1307,20 +1306,11 @@ static void load_credentials(struct login_context *cxt) { return; } - dir = ul_path_opendir(pc, NULL); - if (!dir) { - syslog(LOG_WARNING, _("failed to open credentials directory")); - return; - } - - while ((d = xreaddir(dir))) { - char str[32] = { 0 }; + if (ul_path_read_buffer(pc, str, sizeof(str), "login.noauth") > 0 + && *str && strcmp(str, "yes") == 0) + cxt->noauth = 1; - if (strcmp(d->d_name, "login.noauth") == 0 - && ul_path_read_buffer(pc, str, sizeof(str), d->d_name) > 0 - && *str && strcmp(str, "yes") == 0) - cxt->noauth = 1; - } + ul_unref_path(pc); } static void initialize(int argc, char **argv, struct login_context *cxt) -- 2.47.2