summaryrefslogtreecommitdiffstats
path: root/lib/logind.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:18:37 +0000
commitb6b00dd55e035bfbe311a527b567962ffa77ee43 (patch)
treecafc4d13785448e5a78bd40a51697ee07f07ac12 /lib/logind.c
parentAdding debian version 1:4.13+dfsg1-5. (diff)
downloadshadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.tar.xz
shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.zip
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/logind.c')
-rw-r--r--lib/logind.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/logind.c b/lib/logind.c
new file mode 100644
index 0000000..ba7278f
--- /dev/null
+++ b/lib/logind.c
@@ -0,0 +1,52 @@
+/*
+ * SPDX-FileCopyrightText: 2023, Iker Pedrosa <ipedrosa@redhat.com>
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <config.h>
+
+#ident "$Id$"
+
+#include "attr.h"
+#include "defines.h"
+#include "prototypes.h"
+
+#include <systemd/sd-login.h>
+
+int get_session_host (char **out)
+{
+ char *host = NULL;
+ char *session = NULL;
+ int ret;
+
+ ret = sd_pid_get_session (getpid(), &session);
+ if (ret < 0) {
+ return ret;
+ }
+ ret = sd_session_get_remote_host (session, &host);
+ if (ret < 0) {
+ goto done;
+ }
+
+ *out = host;
+
+done:
+ free (session);
+ return ret;
+}
+
+unsigned long active_sessions_count(const char *name, MAYBE_UNUSED unsigned long limit)
+{
+ struct passwd *pw;
+ unsigned long count = 0;
+
+ pw = prefix_getpwnam(name);
+ if (pw == NULL) {
+ return 0;
+ }
+
+ count = sd_uid_get_sessions(pw->pw_uid, 0, NULL);
+
+ return count;
+}