Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 148400 Details for
Bug 229172
login(1) needs to poke ConsoleKit
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
source code patch
util-linux-login-use-ck.patch (text/plain), 12.88 KB, created by
David Zeuthen
on 2007-02-20 04:33:45 UTC
(
hide
)
Description:
source code patch
Filename:
MIME Type:
Creator:
David Zeuthen
Created:
2007-02-20 04:33:45 UTC
Size:
12.88 KB
patch
obsolete
>--- login-utils/login.c.before-ck-patch 2007-02-19 16:50:07.000000000 -0500 >+++ login-utils/login.c 2007-02-19 22:56:47.000000000 -0500 >@@ -118,6 +118,12 @@ > > #include <utmp.h> > >+#define HAVE_CK_CONNECTOR >+ >+#ifdef HAVE_CK_CONNECTOR >+#include "ck-connector.h" >+#endif >+ > #ifdef HAVE_SECURITY_PAM_MISC_H > # include <security/pam_appl.h> > # include <security/pam_misc.h> >@@ -232,7 +238,7 @@ check_ttyname(char *ttyn) { > } > } > >-#ifdef LOGIN_CHOWN_VCS >+#if defined(LOGIN_CHOWN_VCS) || defined(HAVE_CK_CONNECTOR) > /* true if the filedescriptor fd is a console tty, very Linux specific */ > static int > consoletty(int fd) { >@@ -334,6 +340,9 @@ main(int argc, char **argv) > char vcsn[20], vcsan[20]; > #endif > int audit_fd; >+#ifdef HAVE_CK_CONNECTOR >+ CKConnector *ckc = NULL; >+#endif > > pid = getpid(); > >@@ -1108,6 +1117,22 @@ Michael Riepe <michael@stud.uni-hannover > signal(SIGTSTP, SIG_IGN); > > #ifdef HAVE_SECURITY_PAM_MISC_H >+ >+#ifdef HAVE_CK_CONNECTOR >+ if (consoletty (0)) { >+ ckc = ckc_new (); >+ if (ckc == NULL) { >+ /* TODO: how to handle OOM */ >+ } else { >+ if (!ckc_create_local_session (ckc, pwd->pw_uid, ttyn)) { >+ syslog (LOG_NOTICE, _("Couldn't connect to ConsoleKit: session will not be tracked")); >+ ckc_free (ckc); >+ ckc = NULL; >+ } >+ } >+ } >+#endif >+ > /* > * We must fork before setuid() because we need to call > * pam_close_session() as root. >@@ -1130,6 +1155,14 @@ Michael Riepe <michael@stud.uni-hannover > /* error in fork() */ > fprintf(stderr, _("login: failure forking: %s"), strerror(errsv)); > PAM_END; >+#ifdef HAVE_CK_CONNECTOR >+ if (ckc != NULL) { >+ /* technically we don't need this as CK will notice our >+ * connection go away via D-Bus's connection tracking. */ >+ ckc_close_session (ckc); >+ ckc_free (ckc); >+ } >+#endif > exit(0); > } > >@@ -1141,6 +1174,14 @@ Michael Riepe <michael@stud.uni-hannover > while(wait(NULL) == -1 && errno == EINTR) /**/ ; > openlog("login", LOG_ODELAY, LOG_AUTHPRIV); > PAM_END; >+#ifdef HAVE_CK_CONNECTOR >+ if (ckc != NULL) { >+ /* technically we don't need this as CK will notice our >+ * connection go away via D-Bus's connection tracking. */ >+ ckc_close_session (ckc); >+ ckc_free (ckc); >+ } >+#endif > exit(0); > } > >@@ -1213,6 +1254,19 @@ Michael Riepe <michael@stud.uni-hannover > > childArgv[childArgc++] = NULL; > >+#ifdef HAVE_CK_CONNECTOR >+ if (ckc != NULL) { >+ char *cookie; >+ cookie = ckc_get_cookie (ckc); >+ if (cookie != NULL) { >+ if (setenv ("XDG_SESSION_COOKIE", cookie, 1) != 0) { >+ fprintf(stderr, _("login: no memory XDG_SESSION_COOKIE environment variable.\n")); >+ exit(0); >+ } >+ } >+ } >+#endif >+ > execvp(childArgv[0], childArgv + 1); > > errsv = errno; >--- /dev/null 2007-02-19 10:25:38.553280570 -0500 >+++ login-utils/ck-connector.h 2007-02-19 22:43:42.000000000 -0500 >@@ -0,0 +1,100 @@ >+/* >+ * ck-connector.h : Code for login managers to register with ConsoleKit. >+ * >+ * Code for login managers to register with ConsoleKit. >+ * >+ * Copyright (C) 2007 David Zeuthen <davidz@redhat.com> >+ * >+ * This code is placed in the public domain. >+ */ >+ >+#ifndef CK_CONNECTOR_H >+#define CK_CONNECTOR_H >+ >+#include <sys/types.h> >+#include <dbus/dbus.h> >+ >+struct CKConnecter_s; >+typedef struct CKConnector_s CKConnector; >+ >+/* Allocates a new CKConnector instance. >+ * >+ * Returns NULL on OOM */ >+CKConnector *ckc_new (void); >+ >+/* Connects to the D-Bus system bus daemon and issues the method call >+ * OpenSessionWithParameters on the ConsoleKit manager interface. The >+ * connection to the bus is private. >+ * >+ * Returns FALSE on OOM, if the system bus daemon is not running, if >+ * the ConsoleKit daemon is not running or if the caller doesn't have >+ * sufficient privileges. >+ */ >+dbus_bool_t ckc_create_local_session (CKConnector *ckc, uid_t user, const char *tty); >+ >+/* Gets the cookie that should be set as XDG_SESSION_COOKIE in the >+ * users environment. >+ * >+ * Returns NULL unless ckc_create_local_session() succeeded >+ */ >+char *ckc_get_cookie (CKConnector *ckc); >+ >+/* Issues the CloseSession method call on the ConsoleKit manager >+ * interface. >+ * >+ * Returns FALSE on OOM, if the system bus daemon is not running, if >+ * the ConsoleKit daemon is not running, if the caller doesn't have >+ * sufficient privilege or if ckc_create_local_session() wasn't >+ * successfully invoked. >+ */ >+dbus_bool_t ckc_close_session (CKConnector *ckc); >+ >+/* Frees all resources allocated and disconnects from the system >+ * message bus. >+ */ >+void ckc_free (CKConnector *ckc); >+ >+/* example code: >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include "ck-connector.h" >+ >+int >+main (int argc, char *argv[]) >+{ >+ CKConnector *ckc; >+ >+ ckc = ckc_new (); >+ if (ckc == NULL) { >+ printf ("OOM creating CKConnector\n"); >+ goto out; >+ } >+ >+ if (!ckc_create_local_session (ckc, 500, "/dev/tty2")) { >+ printf ("cannot create CK session: OOM, D-Bus system bus not available,\n" >+ "ConsoleKit not available or insufficient privileges.\n"); >+ goto out; >+ } >+ >+ printf ("Session cookie is '%s'\n", ckc_get_cookie (ckc)); >+ sleep (20); >+ >+ if (!ckc_close_session (ckc)) { >+ printf ("Cannot close CK session: OOM, D-Bus system bus not available,\n" >+ "ConsoleKit not available or insufficient privileges.\n"); >+ goto out; >+ } >+ >+out: >+ if (ckc != NULL) { >+ ckc_free (ckc); >+ } >+} >+ >+*/ >+ >+#endif /* CK_CONNECTOR_H */ >+ >+ >+ >--- /dev/null 2007-02-19 10:25:38.553280570 -0500 >+++ login-utils/ck-connector.c 2007-02-19 22:43:34.000000000 -0500 >@@ -0,0 +1,297 @@ >+/* >+ * ck-connector.c : Code for login managers to register with ConsoleKit. >+ * >+ * Copyright (C) 2007 David Zeuthen <davidz@redhat.com> >+ * >+ * This code is placed in the public domain. >+ */ >+ >+#include <stdio.h> >+#include <stdlib.h> >+#include <string.h> >+#include <unistd.h> >+#include <sys/types.h> >+#include <dbus/dbus.h> >+ >+#include "ck-connector.h" >+ >+static dbus_bool_t >+add_param_int32 (DBusMessageIter *iter_array, const char *key, dbus_int32_t value) >+{ >+ DBusMessageIter iter_struct; >+ DBusMessageIter iter_variant; >+ >+ if (!dbus_message_iter_open_container (iter_array, >+ DBUS_TYPE_STRUCT, >+ NULL, >+ &iter_struct)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &key)) >+ goto oom; >+ if (!dbus_message_iter_open_container (&iter_struct, >+ DBUS_TYPE_VARIANT, >+ DBUS_TYPE_INT32_AS_STRING, >+ &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &value)) >+ goto oom; >+ if (!dbus_message_iter_close_container (&iter_struct, &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_close_container (iter_array, &iter_struct)) >+ goto oom; >+ >+ return TRUE; >+oom: >+ return FALSE; >+} >+ >+static dbus_bool_t >+add_param_string (DBusMessageIter *iter_array, const char *key, const char *value) >+{ >+ DBusMessageIter iter_struct; >+ DBusMessageIter iter_variant; >+ >+ if (!dbus_message_iter_open_container (iter_array, >+ DBUS_TYPE_STRUCT, >+ NULL, >+ &iter_struct)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &key)) >+ goto oom; >+ if (!dbus_message_iter_open_container (&iter_struct, >+ DBUS_TYPE_VARIANT, >+ DBUS_TYPE_STRING_AS_STRING, >+ &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_STRING, &value)) >+ goto oom; >+ if (!dbus_message_iter_close_container (&iter_struct, &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_close_container (iter_array, &iter_struct)) >+ goto oom; >+ >+ return TRUE; >+oom: >+ return FALSE; >+} >+ >+static dbus_bool_t >+add_param_bool (DBusMessageIter *iter_array, const char *key, dbus_bool_t value) >+{ >+ DBusMessageIter iter_struct; >+ DBusMessageIter iter_variant; >+ >+ if (!dbus_message_iter_open_container (iter_array, >+ DBUS_TYPE_STRUCT, >+ NULL, >+ &iter_struct)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &key)) >+ goto oom; >+ if (!dbus_message_iter_open_container (&iter_struct, >+ DBUS_TYPE_VARIANT, >+ DBUS_TYPE_BOOLEAN_AS_STRING, >+ &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_BOOLEAN, &value)) >+ goto oom; >+ if (!dbus_message_iter_close_container (&iter_struct, &iter_variant)) >+ goto oom; >+ if (!dbus_message_iter_close_container (iter_array, &iter_struct)) >+ goto oom; >+ >+ return TRUE; >+oom: >+ return FALSE; >+} >+ >+ >+struct CKConnector_s >+{ >+ char *cookie; >+ dbus_bool_t session_created; >+ DBusConnection *con; >+}; >+ >+CKConnector* >+ckc_new (void) >+{ >+ CKConnector *ckc; >+ >+ ckc = calloc (1, sizeof (CKConnector)); >+ if (ckc == NULL) >+ goto oom; >+ ckc->con = NULL; >+ ckc->cookie = NULL; >+ ckc->session_created = FALSE; >+oom: >+ return ckc; >+}; >+ >+dbus_bool_t >+ckc_create_local_session (CKConnector *ckc, uid_t user, const char *tty) >+{ >+ DBusError error; >+ DBusMessage *message; >+ DBusMessage *reply; >+ DBusMessageIter iter; >+ DBusMessageIter iter_array; >+ dbus_bool_t ret; >+ char *cookie; >+ >+ reply = NULL; >+ message = NULL; >+ ret = FALSE; >+ >+ dbus_error_init (&error); >+ ckc->con = dbus_bus_get_private (DBUS_BUS_SYSTEM, &error); >+ if (ckc->con == NULL) { >+ goto out; >+ } >+ dbus_connection_set_exit_on_disconnect (ckc->con, FALSE); >+ >+ message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", >+ "/org/freedesktop/ConsoleKit/Manager", >+ "org.freedesktop.ConsoleKit.Manager", >+ "OpenSessionWithParameters"); >+ if (message == NULL) >+ goto out; >+ >+ dbus_message_iter_init_append (message, &iter); >+ if (!dbus_message_iter_open_container (&iter, >+ DBUS_TYPE_ARRAY, >+ "(sv)", >+ &iter_array)) >+ goto out; >+ >+ if (!add_param_string (&iter_array, "host-name", "localhost")) >+ goto out; >+ if (!add_param_string (&iter_array, "display-device", tty)) >+ goto out; >+ if (!add_param_int32 (&iter_array, "user", user)) >+ goto out; >+ if (!add_param_bool (&iter_array, "is-local", TRUE)) >+ goto out; >+ >+ if (!dbus_message_iter_close_container (&iter, &iter_array)) >+ goto out; >+ >+ reply = dbus_connection_send_with_reply_and_block (ckc->con, message, -1, &error); >+ if (reply == NULL) { >+ if (dbus_error_is_set (&error)) { >+ dbus_error_free (&error); >+ goto out; >+ } >+ } >+ >+ if (!dbus_message_get_args (reply, >+ &error, >+ DBUS_TYPE_STRING, &cookie, >+ DBUS_TYPE_INVALID)) { >+ if (dbus_error_is_set (&error)) { >+ dbus_error_free (&error); >+ goto out; >+ } >+ } >+ >+ ckc->cookie = strdup (cookie); >+ if (ckc->cookie == NULL) >+ goto out; >+ >+ ckc->session_created = TRUE; >+ ret = TRUE; >+ >+out: >+ if (reply != NULL) >+ dbus_message_unref (reply); >+ >+ if (message != NULL) >+ dbus_message_unref (message); >+ >+ return ret; >+} >+ >+char * >+ckc_get_cookie (CKConnector *ckc) >+{ >+ if (!ckc->session_created) >+ return NULL; >+ else >+ return ckc->cookie; >+} >+ >+dbus_bool_t >+ckc_close_session (CKConnector *ckc) >+{ >+ DBusError error; >+ DBusMessage *message; >+ DBusMessage *reply; >+ dbus_bool_t ret; >+ dbus_bool_t session_closed; >+ >+ reply = NULL; >+ message = NULL; >+ ret = FALSE; >+ if (!ckc->session_created || ckc->cookie == NULL) >+ goto out; >+ >+ dbus_error_init (&error); >+ message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", >+ "/org/freedesktop/ConsoleKit/Manager", >+ "org.freedesktop.ConsoleKit.Manager", >+ "CloseSession"); >+ if (message == NULL) >+ goto out; >+ >+ if (!dbus_message_append_args (message, >+ DBUS_TYPE_STRING, &(ckc->cookie), >+ DBUS_TYPE_INVALID)) >+ goto out; >+ >+ reply = dbus_connection_send_with_reply_and_block (ckc->con, message, -1, &error); >+ if (reply == NULL) { >+ if (dbus_error_is_set (&error)) { >+ dbus_error_free (&error); >+ goto out; >+ } >+ } >+ >+ if (!dbus_message_get_args (reply, >+ &error, >+ DBUS_TYPE_BOOLEAN, &session_closed, >+ DBUS_TYPE_INVALID)) { >+ if (dbus_error_is_set (&error)) { >+ dbus_error_free (&error); >+ goto out; >+ } >+ } >+ >+ if (!session_closed) >+ goto out; >+ >+ ckc->session_created = FALSE; >+ ret = TRUE; >+ >+out: >+ if (reply != NULL) >+ dbus_message_unref (reply); >+ >+ if (message != NULL) >+ dbus_message_unref (message); >+ >+ return ret; >+ >+} >+ >+void >+ckc_free (CKConnector *ckc) >+{ >+ if (ckc->con != NULL) { >+ /* it's a private connection so it's all good */ >+ dbus_connection_close (ckc->con); >+ } >+ if (ckc->cookie != NULL) { >+ free (ckc->cookie); >+ } >+ free (ckc); >+} >--- login-utils/Makefile.am.before-ck-patch 2007-02-19 23:02:07.000000000 -0500 >+++ login-utils/Makefile.am 2007-02-19 23:02:59.000000000 -0500 >@@ -57,6 +57,9 @@ > chsh_LDADD += -lpam -lpam_misc > login_LDADD += -lpam -lpam_misc -laudit > login_SOURCES = login.c >+login_SOURCES += ck-connector.c ck-connector.h >+login_LDADD += -ldbus-1 >+DEFAULT_INCLUDES += -I/usr/include/dbus-1.0 -I/usr/lib/dbus-1.0/include > else > login_SOURCES = login.c checktty.c > endif
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 229172
: 148400 |
148401