From: Tobias Stoeckmann Date: Sun, 8 Oct 2023 18:22:47 +0000 (+0200) Subject: login: access login.noauth file directly X-Git-Tag: v2.40-rc1~208^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=601686e833bae3a15d6a6ca79b952df923fd552e;p=thirdparty%2Futil-linux.git 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 --- 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)