]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
libmisc: call `active_sessions_count()`
authorIker Pedrosa <ipedrosa@redhat.com>
Wed, 19 Jul 2023 10:02:31 +0000 (12:02 +0200)
committerSerge Hallyn <serge@hallyn.com>
Wed, 2 Aug 2023 15:13:28 +0000 (10:13 -0500)
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 <ipedrosa@redhat.com>
libmisc/limits.c

index 2d4f51a549833b54f64a1afba6b3d54410e33293..ef8cb92096e8e344578677bfc421047826fc873c 100644 (file)
@@ -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",