Commit edbf4a3c authored by Dan Williams's avatar Dan Williams

core: allow ConsoleKit usage to be disabled

parent e5adfcba
......@@ -253,6 +253,19 @@ if test "x$with_systemdsystemunitdir" != xno; then
fi
AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
dnl
dnl Disable ConsoleKit support
dnl
AC_ARG_WITH(ck, AS_HELP_STRING([--without-ck], [Build NetworkManager without ConsoleKit session tracking support]))
AM_CONDITIONAL(WITH_CONSOLEKIT, test x"$with_ck" != xno)
no_ck=0
if test x"$with_ck" = x"no"; then
no_ck="1"
else
with_ck="yes"
fi
AC_DEFINE_UNQUOTED(NO_CONSOLEKIT, $no_ck, [Define to disable use of ConsoleKit])
PKG_CHECK_MODULES(LIBNL, libnl-1 >= 1.0-pre8)
AC_SUBST(LIBNL_CFLAGS)
AC_SUBST(LIBNL_LIBS)
......@@ -597,6 +610,12 @@ else
echo systemd support: no
fi
if test -n "${with_ck}"; then
echo ConsoleKit support: ${with_ck}
else
echo ConsoleKit support: no
fi
echo
echo Building documentation: ${with_docs}
echo Building tests: ${with_tests}
......
......@@ -260,6 +260,10 @@ ensure_database (NMSessionMonitor *self, GError **error)
{
gboolean ret = FALSE;
#if NO_CONSOLEKIT
return TRUE;
#endif
if (self->database != NULL) {
struct stat statbuf;
......@@ -305,6 +309,10 @@ nm_session_monitor_init (NMSessionMonitor *self)
GError *error = NULL;
GFile *file;
#if NO_CONSOLEKIT
return;
#endif
/* Sessions-by-user is responsible for destroying the Session objects */
self->sessions_by_user = g_hash_table_new_full (g_str_hash, g_str_equal,
NULL, (GDestroyNotify) session_free);
......@@ -384,6 +392,50 @@ nm_session_monitor_get (void)
/* ---------------------------------------------------------------------------------------------------- */
#if NO_CONSOLEKIT
static gboolean
uid_to_user (uid_t uid, const char **out_user, GError **error)
{
struct passwd *pw;
pw = getpwuid (uid);
if (!pw) {
g_set_error (error,
NM_SESSION_MONITOR_ERROR,
NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
"Could not get username for UID %d",
uid);
return FALSE;
}
/* Ugly, but hey, use ConsoleKit */
if (out_user)
*out_user = pw->pw_name;
return TRUE;
}
static gboolean
user_to_uid (const char *user, uid_t *out_uid, GError **error)
{
struct passwd *pw;
pw = getpwnam (user);
if (!pw) {
g_set_error (error,
NM_SESSION_MONITOR_ERROR,
NM_SESSION_MONITOR_ERROR_UNKNOWN_USER,
"Could not get UID for username '%s'",
user);
return FALSE;
}
/* Ugly, but hey, use ConsoleKit */
if (out_uid)
*out_uid = pw->pw_uid;
return TRUE;
}
#endif
/**
* nm_session_monitor_user_has_session:
* @monitor: A #NMSessionMonitor.
......@@ -403,6 +455,12 @@ nm_session_monitor_user_has_session (NMSessionMonitor *monitor,
{
Session *s;
#if NO_CONSOLEKIT
if (!user_to_uid (username, out_uid, error))
return FALSE;
return TRUE;
#endif
if (!ensure_database (monitor, error))
return FALSE;
......@@ -440,6 +498,12 @@ nm_session_monitor_uid_has_session (NMSessionMonitor *monitor,
{
Session *s;
#if NO_CONSOLEKIT
if (!uid_to_user (uid, out_user, error))
return FALSE;
return TRUE;
#endif
if (!ensure_database (monitor, error))
return FALSE;
......@@ -476,6 +540,10 @@ nm_session_monitor_user_active (NMSessionMonitor *monitor,
{
Session *s;
#if NO_CONSOLEKIT
return TRUE;
#endif
if (!ensure_database (monitor, error))
return FALSE;
......@@ -510,6 +578,10 @@ nm_session_monitor_uid_active (NMSessionMonitor *monitor,
{
Session *s;
#if NO_CONSOLEKIT
return TRUE;
#endif
if (!ensure_database (monitor, error))
return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment