]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: access login.noauth file directly
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 8 Oct 2023 18:22:47 +0000 (20:22 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 10 Oct 2023 16:55:32 +0000 (18:55 +0200)
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 <tobias@stoeckmann.org>
login-utils/login.c

index 1f3f5d36c141e0e1535248c8b2d2ff78433846db..82f0cd9f7f1a7b9fa4224ad7a25868ae92cdd67b 100644 (file)
@@ -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)