aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorThorsten Kukuk <kukuk@suse.com>2024-09-04 16:07:56 +0200
committerDmitry V. Levin <ldv@strace.io>2024-09-05 08:00:00 +0000
commit8401cef10cd5f62849c5fcfef4c82db92712296c (patch)
treebc2b54f4c37721157ee2525fac2e5aa349d158ea /modules
parent1c6a4a54fa238b148428a9ce601a52fce63e9afe (diff)
downloadpam-8401cef10cd5f62849c5fcfef4c82db92712296c.tar.gz
pam-8401cef10cd5f62849c5fcfef4c82db92712296c.tar.bz2
pam-8401cef10cd5f62849c5fcfef4c82db92712296c.zip
pam_issue: only count class user
Since systemd added new types of classes (e.g. manager*), we cannot use the count of all sessions anymore, but have to check which class this is. This is backward compatible, systemd v209 or newer is required.
Diffstat (limited to 'modules')
-rw-r--r--modules/pam_issue/pam_issue.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/modules/pam_issue/pam_issue.c b/modules/pam_issue/pam_issue.c
index aade642e..e2c555c4 100644
--- a/modules/pam_issue/pam_issue.c
+++ b/modules/pam_issue/pam_issue.c
@@ -165,13 +165,31 @@ read_issue_quoted(pam_handle_t *pamh, FILE *fp, char **prompt)
{
unsigned int users = 0;
#ifdef USE_LOGIND
- int sessions = sd_get_sessions(NULL);
+ char **sessions_list;
+ int sessions = sd_get_sessions(&sessions_list);
if (sessions < 0) {
pam_syslog(pamh, LOG_ERR, "logind error: %s",
strerror(-sessions));
_pam_drop(issue);
return PAM_SERVICE_ERR;
+ } else if (sessions > 0 && sessions_list != NULL) {
+ int i;
+
+ for (i = 0; i < sessions; i++) {
+ char *class;
+
+ if (sd_session_get_class(sessions_list[i], &class) < 0 || class == NULL)
+ continue;
+
+ if (strncmp(class, "user", 4) == 0) // user, user-early, user-incomplete
+ users++;
+ free(class);
+ }
+
+ for (i = 0; i < sessions; i++)
+ free(sessions_list[i]);
+ free(sessions_list);
} else {
users = sessions;
}