--- a/slim-1.3.2/app.cpp +++ b/slim-1.3.2/app.cpp @@ -536,6 +536,60 @@ string xauthority = pw->pw_dir; xauthority.append("/.Xauthority"); +#ifdef USE_CONSOLEKIT + cerr << APPNAME << ": consolekit support enabled" << endl; + int ret; + DBusError error; + char *remote_host_name = ""; + dbus_bool_t is_local; + char *display_device = ""; + //char devtmp[16]; + + // if (!use_consolekit) return 1; + cerr << APPNAME << ": initializing a consolekit session" << endl; + + is_local = TRUE; //is_local = Dpy->displayType.location == Local; + //if (Dpy->peerlen > 0 && Dpy->peer) + //remote_host_name = Dpy->peer; + /* how can we get the corresponding tty at best...? */ +// if (Dpy->windowPath) { +// display_device = strchr(Dpy->windowPath, ':'); +// if (display_device && display_device[1]) +// display_device++; +// else +// display_device = Dpy->windowPath; +// snprintf(devtmp, sizeof(devtmp), "/dev/tty%s", display_device); +// display_device = devtmp; +display_device = dpy_tty; // } + + ckconnector = ck_connector_new(); + if (!ckconnector) { + cerr << APPNAME << ": ck_connector not initialized" << endl; + //return 0; + } + + dbus_error_init(&error); + ret = ck_connector_open_session_with_parameters( + ckconnector, &error, + "unix-user", &pw->pw_uid, + "x11-display", &DisplayName, + "x11-display-device", &display_device, + "remote-host-name", &remote_host_name, + "is-local", &is_local, + NULL); + if (!ret) { + if (dbus_error_is_set(&error)) { + cerr << APPNAME << ": Dbus error: " << error.message << endl; + dbus_error_free(&error); + } else { + cerr << APPNAME << ": ConsoleKit error" << endl; + } + cerr << APPNAME << ": console-kit-daemon not running?" << endl; + ck_connector_unref(ckconnector); + ckconnector = NULL; + } +#endif + #ifdef USE_PAM // Setup the PAM environment try{ @@ -548,6 +602,10 @@ pam.setenv("DISPLAY", DisplayName); pam.setenv("MAIL", maildir.c_str()); pam.setenv("XAUTHORITY", xauthority.c_str()); +#ifdef USE_CONSOLEKIT + pam.setenv("XDG_SESSION_COOKIE", ck_connector_get_cookie(ckconnector)); + cerr << APPNAME << ": ck_connector has XDG_SESSION_COOKIE of " << ck_connector_get_cookie(ckconnector) << endl; +#endif } catch(PAM::Exception& e){ cerr << APPNAME << ": " << e << endl; @@ -564,7 +622,11 @@ char** child_env = pam.getenvlist(); pam.end(); #else +#if USE_CONSOLEKIT + const int Num_Of_Variables = 11; // Number of env. variables + 1 +#else const int Num_Of_Variables = 10; // Number of env. variables + 1 +#endif char** child_env = static_cast(malloc(sizeof(char*)*Num_Of_Variables)); int n = 0; if(term) child_env[n++]=StrConcat("TERM=", term); @@ -576,6 +638,10 @@ child_env[n++]=StrConcat("DISPLAY=", DisplayName); child_env[n++]=StrConcat("MAIL=", maildir.c_str()); child_env[n++]=StrConcat("XAUTHORITY=", xauthority.c_str()); +#if USE_CONSOLEKIT + child_env[n++]=StrConcat("XDG_SESSION_COOKIE=", ck_connector_get_cookie(ckconnector)); + cerr << APPNAME << ": ck_connector has XDG_SESSION_COOKIE of " << ck_connector_get_cookie(ckconnector) << endl; +#endif child_env[n++]=0; #endif @@ -617,6 +683,28 @@ } } +#ifdef USE_CONSOLEKIT + + //DBusError error; + + // if (!ckconnector) + //return; + + //dbus_error_init(&error); + if (!ck_connector_close_session(ckconnector, &error)) { + if (dbus_error_is_set(&error)) { + cerr << APPNAME << ": Dbus error: " << error.message << endl; + dbus_error_free(&error); + } else { + cerr << APPNAME << ": ConsoleKit close error" << endl; + } + cerr << APPNAME << ": console-kit-daemon not running?" << endl; + } + ck_connector_unref(ckconnector); + ckconnector = NULL; + //} +#endif + #ifdef USE_PAM try{ pam.close_session(); @@ -881,12 +969,18 @@ bool ok = false; Cfg::string2int(server[i]+2, &ok); if (ok) { +#ifdef USE_CONSOLEKIT + sprintf(dpy_tty,"/dev/tty%d",atoi(server[i]+2)); +#endif hasVtSet = true; } } } if (!hasVtSet && daemonmode) { +#ifdef USE_CONSOLEKIT + sprintf(dpy_tty,"/dev/tty7"); +#endif server[argc++] = (char*)"vt07"; } server[argc] = NULL; --- a/slim-1.3.2/app.h +++ b/slim-1.3.2/app.h @@ -27,6 +27,10 @@ #ifdef USE_PAM #include "PAM.h" #endif +#ifdef USE_CONSOLEKIT +#include +#include +#endif class App { public: @@ -81,6 +85,12 @@ #ifdef USE_PAM PAM::Authenticator pam; #endif +#ifdef USE_CONSOLEKIT + CkConnector *ckconnector; + int use_consolekit; + char dpy_tty[16]; +#endif + // Options char* DispName; --- a/slim-1.3.2/Makefile +++ b/slim-1.3.2/Makefile @@ -13,6 +13,11 @@ LDFLAGS+= -lpam CUSTOM+= -DUSE_PAM endif +ifdef USE_CONSOLEKIT +LDFLAGS+= `pkg-config --libs ck-connector` +CFLAGS+= `pkg-config --cflags ck-connector` +CUSTOM+= -DUSE_CONSOLEKIT +endif PREFIX=/usr CFGDIR=/etc MANDIR=/usr/share/man