diff options
author | Simo Sorce <simo@redhat.com> | 2013-09-10 18:24:41 -0400 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-09-16 15:48:34 +0200 |
commit | b49a7d90708e816120ff88ce5a88fa62b35ff795 (patch) | |
tree | 798ae2d5998a37a7efd7420cad9a483b76ef973c /src | |
parent | 6d2942eb10f5fc4f791498d7f6c2ef021c3b8777 (diff) | |
download | sssd-b49a7d90708e816120ff88ce5a88fa62b35ff795.tar.gz sssd-b49a7d90708e816120ff88ce5a88fa62b35ff795.tar.bz2 sssd-b49a7d90708e816120ff88ce5a88fa62b35ff795.zip |
util: Use systemd-login to check user sessions
Use systemd-lgin in preference to check if the user is logged in or not.
Fall back to the old method if no systemd-login support is available at compile
time or if it returns a fatal error, and can't determine the status of the user
on its own.
This will allow to consider a user really active (in order to reuse or refresh
crdentials) only if it really is logged into the system, and not just if one
of the user's processes is stuck around.
Resolves:
https://fedorahosted.org/sssd/ticket/2084
Diffstat (limited to 'src')
-rw-r--r-- | src/external/systemd.m4 | 4 | ||||
-rw-r--r-- | src/util/find_uid.c | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/external/systemd.m4 b/src/external/systemd.m4 index 2c26dc19..202915a5 100644 --- a/src/external/systemd.m4 +++ b/src/external/systemd.m4 @@ -6,3 +6,7 @@ AC_DEFUN([AM_CHECK_SYSTEMD], [AC_MSG_ERROR([Could not detect systemd presence])] ) ]) +AM_COND_IF([HAVE_SYSTEMD], + [PKG_CHECK_MODULES([SYSTEMD_LOGIN], [libsystemd-login], + [AC_DEFINE_UNQUOTED(HAVE_SYSTEMD_LOGIN, 1, [Build with libsystemdlogin support])], + [AC_DEFINE_UNQUOTED(HAVE_SYSTEMD_LOGIN, 0, [Build without libsystemd-login support])])]) 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")); |