From fb8f44d73fc64cf26ed10cebf9dce9d0b865501d Mon Sep 17 00:00:00 2001 From: Iker Pedrosa Date: Wed, 19 Jul 2023 12:02:31 +0200 Subject: [PATCH] libmisc: call `active_sessions_count()` Replace the utmp dependent code with the call to `active_sessions_count()`. Resolves: https://github.com/shadow-maint/shadow/issues/674 Signed-off-by: Iker Pedrosa --- libmisc/limits.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/libmisc/limits.c b/libmisc/limits.c index 2d4f51a54..ef8cb9209 100644 --- a/libmisc/limits.c +++ b/libmisc/limits.c @@ -119,7 +119,6 @@ static int set_umask (const char *value) /* Counts the number of user logins and check against the limit */ static int check_logins (const char *name, const char *maxlogins) { - struct utmp *ut; unsigned long limit, count; if (getulong (maxlogins, &limit) == 0) { @@ -131,29 +130,8 @@ static int check_logins (const char *name, const char *maxlogins) return LOGIN_ERROR_LOGIN; } - count = 0; - setutent (); - while ((ut = getutent ())) - { - if (USER_PROCESS != ut->ut_type) { - continue; - } - if ('\0' == ut->ut_user[0]) { - continue; - } - if (strncmp (name, ut->ut_user, sizeof (ut->ut_user)) != 0) { - continue; - } - count++; - if (count > limit) { - break; - } - } - endutent (); - /* - * This is called after setutmp(), so the number of logins counted - * includes the user who is currently trying to log in. - */ + count = active_sessions_count(name, limit); + if (count > limit) { SYSLOG ((LOG_WARN, "Too many logins (max %lu) for %s\n", -- 2.47.2