summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/find_uid.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/find_uid.c b/src/util/find_uid.c
index d34a4abd..63b34645 100644
--- a/src/util/find_uid.c
+++ b/src/util/find_uid.c
@@ -40,6 +40,10 @@
#include "util/util.h"
#include "util/strtonum.h"
+#ifdef HAVE_SYSTEMD_LOGIN
+#include <systemd/sd-login.h>
+#endif
+
#define INITIAL_TABLE_SIZE 64
#define PATHLEN (NAME_MAX + 14)
#define BUFSIZE 4096
@@ -301,6 +305,22 @@ errno_t check_if_uid_is_active(uid_t uid, bool *result)
{
int ret;
+#ifdef HAVE_SYSTEMD_LOGIN
+ ret = sd_uid_get_sessions(uid, 0, NULL);
+ if (ret > 0) {
+ *result = true;
+ }
+ if (ret == 0) {
+ *result = false;
+ }
+ if (ret >= 0) {
+ return EOK;
+ }
+ DEBUG(SSSDBG_CRIT_FAILURE, ("systemd-login gave error %d: %s\n",
+ -ret, strerror(-ret)));
+ /* fall back to the old method */
+#endif
+
ret = get_active_uid_linux(NULL, uid);
if (ret != EOK && ret != ENOENT) {
DEBUG(1, ("get_uid_table failed.\n"));