diff options
author | Dan Williams <dcbw@redhat.com> | 2010-10-26 15:57:03 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2010-10-26 15:57:03 -0500 |
commit | edbf4a3ca243dd7ae110da80e870e4d4ba18deba (patch) | |
tree | 34892a3529c59a67fae894acbe19dff5f08f8c78 | |
parent | e5adfcbabe3416c25f5d6da945437be9b3e60735 (diff) | |
download | NetworkManager-edbf4a3ca243dd7ae110da80e870e4d4ba18deba.tar.gz |
core: allow ConsoleKit usage to be disabled
-rw-r--r-- | configure.ac | 19 | ||||
-rw-r--r-- | src/nm-session-monitor.c | 72 |
2 files changed, 91 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index e66a1f4903..4dfda03575 100644 --- a/configure.ac +++ b/configure.ac @@ -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} diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 61d647901a..b3d06543be 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -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; |