#include "console-kit.h"
#include "login1.h"
#include "guest-account.h"
+#include "shared-data-manager.h"
enum {
GOT_MESSAGES,
struct SessionPrivate
{
+ /* Session type */
+ gchar *session_type;
+
/* Display server running on */
DisplayServer *display_server;
/* File to log to */
gchar *log_filename;
- /* Seat class */
- gchar *class;
-
/* tty this session is running on */
gchar *tty;
/* X display connected to */
gchar *xdisplay;
- XAuthority *xauthority;
- gboolean xauth_use_system_location;
+ XAuthority *x_authority;
+ gboolean x_authority_use_system_location;
/* Remote host this session is being controlled from */
gchar *remote_host_name;
/* Maximum length of a string to pass between daemon and session */
#define MAX_STRING_LENGTH 65535
-G_DEFINE_TYPE (Session, session, G_TYPE_OBJECT);
+static void session_logger_iface_init (LoggerInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (Session, session, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (
+ LOGGER_TYPE, session_logger_iface_init));
+
+Session *
+session_new (void)
+{
+ return g_object_new (SESSION_TYPE, NULL);
+}
+
+void
+session_set_session_type (Session *session, const gchar *session_type)
+{
+ g_return_if_fail (session != NULL);
+ g_free (session->priv->session_type);
+ session->priv->session_type = g_strdup (session_type);
+}
+
+const gchar *
+session_get_session_type (Session *session)
+{
+ g_return_val_if_fail (session != NULL, NULL);
+ return session->priv->session_type;
+}
void
session_set_pam_service (Session *session, const gchar *pam_service)
session->priv->log_filename = g_strdup (filename);
}
-void
-session_set_class (Session *session, const gchar *class)
-{
- g_return_if_fail (session != NULL);
- g_free (session->priv->class);
- session->priv->class = g_strdup (class);
-}
-
void
session_set_display_server (Session *session, DisplayServer *display_server)
{
g_return_if_fail (session != NULL);
g_return_if_fail (display_server != NULL);
if (session->priv->display_server)
+ {
+ display_server_disconnect_session (session->priv->display_server, session);
g_object_unref (session->priv->display_server);
+ }
session->priv->display_server = g_object_ref (display_server);
}
}
void
-session_set_xauthority (Session *session, XAuthority *authority, gboolean use_system_location)
+session_set_x_authority (Session *session, XAuthority *authority, gboolean use_system_location)
{
g_return_if_fail (session != NULL);
- if (session->priv->xauthority)
+ if (session->priv->x_authority)
{
- g_object_unref (session->priv->xauthority);
- session->priv->xauthority = NULL;
+ g_object_unref (session->priv->x_authority);
+ session->priv->x_authority = NULL;
}
if (authority)
- session->priv->xauthority = g_object_ref (authority);
- session->priv->xauth_use_system_location = use_system_location;
+ session->priv->x_authority = g_object_ref (authority);
+ session->priv->x_authority_use_system_location = use_system_location;
}
void
session->priv->remote_host_name = g_strdup (remote_host_name);
}
+static GList *
+find_env_entry (Session *session, const gchar *name)
+{
+ GList *link;
+
+ for (link = session->priv->env; link; link = link->next)
+ {
+ const gchar *entry = link->data;
+
+ if (g_str_has_prefix (entry, name) && entry[strlen (name)] == '=')
+ return link;
+ }
+
+ return NULL;
+}
+
void
session_set_env (Session *session, const gchar *name, const gchar *value)
{
+ GList *link;
+ gchar *entry;
+
+ g_return_if_fail (session != NULL);
+ g_return_if_fail (value != NULL);
+
+ entry = g_strdup_printf ("%s=%s", name, value);
+
+ link = find_env_entry (session, name);
+ if (link)
+ {
+ g_free (link->data);
+ link->data = entry;
+ }
+ else
+ session->priv->env = g_list_append (session->priv->env, entry);
+}
+
+const gchar *
+session_get_env (Session *session, const gchar *name)
+{
+ GList *link;
+ gchar *entry;
+
+ link = find_env_entry (session, name);
+ if (!link)
+ return NULL;
+
+ entry = link->data;
+
+ return entry + strlen (name) + 1;
+}
+
+void
+session_unset_env (Session *session, const gchar *name)
+{
+ GList *link;
+
g_return_if_fail (session != NULL);
- session->priv->env = g_list_append (session->priv->env, g_strdup_printf ("%s=%s", name, value));
+
+ link = find_env_entry (session, name);
+ if (!link)
+ return;
+
+ g_free (link->data);
+ session->priv->env = g_list_remove_link (session->priv->env, link);
}
void
write_data (Session *session, const void *buf, size_t count)
{
if (write (session->priv->to_child_input, buf, count) != count)
- g_warning ("Error writing to session: %s", strerror (errno));
+ l_warning (session, "Error writing to session: %s", strerror (errno));
}
static void
}
static void
-write_xauth (Session *session, XAuthority *xauthority)
+write_xauth (Session *session, XAuthority *x_authority)
{
guint16 family;
gsize length;
- if (!xauthority)
+ if (!x_authority)
{
write_string (session, NULL);
return;
}
- write_string (session, xauth_get_authorization_name (session->priv->xauthority));
- family = xauth_get_family (session->priv->xauthority);
+ write_string (session, x_authority_get_authorization_name (session->priv->x_authority));
+ family = x_authority_get_family (session->priv->x_authority);
write_data (session, &family, sizeof (family));
- length = xauth_get_address_length (session->priv->xauthority);
+ length = x_authority_get_address_length (session->priv->x_authority);
write_data (session, &length, sizeof (length));
- write_data (session, xauth_get_address (session->priv->xauthority), length);
- write_string (session, xauth_get_number (session->priv->xauthority));
- length = xauth_get_authorization_data_length (session->priv->xauthority);
+ write_data (session, x_authority_get_address (session->priv->x_authority), length);
+ write_string (session, x_authority_get_number (session->priv->x_authority));
+ length = x_authority_get_authorization_data_length (session->priv->x_authority);
write_data (session, &length, sizeof (length));
- write_data (session, xauth_get_authorization_data (session->priv->xauthority), length);
+ write_data (session, x_authority_get_authorization_data (session->priv->x_authority), length);
}
static ssize_t
ssize_t n_read;
n_read = read (session->priv->from_child_output, buf, count);
if (n_read < 0)
- g_warning ("Error reading from session: %s", strerror (errno));
+ l_warning (session, "Error reading from session: %s", strerror (errno));
return n_read;
}
return NULL;
if (length > MAX_STRING_LENGTH)
{
- g_warning ("Invalid string length %d from child", length);
+ l_warning (session, "Invalid string length %d from child", length);
return NULL;
}
{
Session *session = data;
- session->priv->pid = 0;
+ session->priv->child_watch = 0;
if (WIFEXITED (status))
- g_debug ("Session %d exited with return value %d", pid, WEXITSTATUS (status));
+ l_debug (session, "Exited with return value %d", WEXITSTATUS (status));
else if (WIFSIGNALED (status))
- g_debug ("Session %d terminated with signal %d", pid, WTERMSIG (status));
+ l_debug (session, "Terminated with signal %d", WTERMSIG (status));
+
+ /* do this as late as possible for log messages prefix */
+ session->priv->pid = 0;
/* If failed during authentication then report this as an authentication failure */
if (session->priv->authentication_started && !session->priv->authentication_complete)
{
- g_debug ("Session %d failed during authentication", pid);
+ l_debug (session, "Failed during authentication");
session->priv->authentication_complete = TRUE;
session->priv->authentication_result = PAM_CONV_ERR;
g_free (session->priv->authentication_result_string);
/* Check if authentication completed */
n_read = read_from_child (session, &auth_complete, sizeof (auth_complete));
if (n_read < 0)
- g_debug ("Error reading from child: %s", strerror (errno));
+ l_debug (session, "Error reading from child: %s", strerror (errno));
if (n_read <= 0)
{
session->priv->from_child_watch = 0;
g_free (session->priv->authentication_result_string);
session->priv->authentication_result_string = read_string_from_child (session);
- g_debug ("Session %d authentication complete with return value %d: %s", session->priv->pid, session->priv->authentication_result, session->priv->authentication_result_string);
+ l_debug (session, "Authentication complete with return value %d: %s", session->priv->authentication_result, session->priv->authentication_result_string);
/* No longer expect any more messages */
session->priv->from_child_watch = 0;
m->msg = read_string_from_child (session);
}
- g_debug ("Session %d got %d message(s) from PAM", session->priv->pid, session->priv->messages_length);
+ l_debug (session, "Got %d message(s) from PAM", session->priv->messages_length);
g_signal_emit (G_OBJECT (session), signals[GOT_MESSAGES], 0);
}
session_start (Session *session)
{
g_return_val_if_fail (session != NULL, FALSE);
- g_return_val_if_fail (session->priv->display_server != NULL, FALSE);
return SESSION_GET_CLASS (session)->start (session);
}
g_return_val_if_fail (session->priv->pid == 0, FALSE);
+ if (session->priv->display_server)
+ display_server_connect_session (session->priv->display_server, session);
+
/* Create pipes to talk to the child */
if (pipe (to_child_pipe) < 0 || pipe (from_child_pipe) < 0)
{
write_string (session, session->priv->username);
write_data (session, &session->priv->do_authenticate, sizeof (session->priv->do_authenticate));
write_data (session, &session->priv->is_interactive, sizeof (session->priv->is_interactive));
- write_string (session, session->priv->class);
+ write_string (session, NULL); /* Used to be class, now we just use the environment variable */
write_string (session, session->priv->tty);
write_string (session, session->priv->remote_host_name);
write_string (session, session->priv->xdisplay);
- write_xauth (session, session->priv->xauthority);
+ write_xauth (session, session->priv->x_authority);
- g_debug ("Started session %d with service '%s', username '%s'", session->priv->pid, session->priv->pam_service, session->priv->username);
+ l_debug (session, "Started with service '%s', username '%s'", session->priv->pam_service, session->priv->username);
return TRUE;
}
session_real_run (Session *session)
{
gsize i, argc;
- gchar *command, *xauth_filename;
+ gchar *command, *x_authority_filename;
GList *link;
g_return_if_fail (session != NULL);
g_return_if_fail (session->priv->argv != NULL);
g_return_if_fail (session->priv->pid != 0);
+ display_server_connect_session (session->priv->display_server, session);
+
session->priv->command_run = TRUE;
command = g_strjoinv (" ", session->priv->argv);
- g_debug ("Session %d running command %s", session->priv->pid, command);
+ l_debug (session, "Running command %s", command);
g_free (command);
/* Create authority location */
- if (session->priv->xauth_use_system_location)
+ if (session->priv->x_authority_use_system_location)
{
gchar *run_dir, *dir;
g_free (run_dir);
if (g_mkdir_with_parents (dir, S_IRWXU) < 0)
- g_warning ("Failed to set create system authority dir %s: %s", dir, strerror (errno));
+ l_warning (session, "Failed to set create system authority dir %s: %s", dir, strerror (errno));
if (getuid () == 0)
{
if (chown (dir, user_get_uid (session_get_user (session)), user_get_gid (session_get_user (session))) < 0)
- g_warning ("Failed to set ownership of user authority dir: %s", strerror (errno));
+ l_warning (session, "Failed to set ownership of user authority dir: %s", strerror (errno));
}
- xauth_filename = g_build_filename (dir, "xauthority", NULL);
+ x_authority_filename = g_build_filename (dir, "xauthority", NULL);
g_free (dir);
}
else
- xauth_filename = g_build_filename (user_get_home_directory (session_get_user (session)), ".Xauthority", NULL);
+ x_authority_filename = g_build_filename (user_get_home_directory (session_get_user (session)), ".Xauthority", NULL);
+ /* Make sure shared user directory for this user exists */
+ if (!session->priv->remote_host_name)
+ {
+ gchar *data_dir = shared_data_manager_ensure_user_dir (shared_data_manager_get_instance (), session->priv->username);
+ l_debug(session, "MIKE set XDG_GREETER_DATA_DIR=%s from user %s", data_dir, session->priv->username);
+ if (data_dir)
+ {
+ session_set_env (session, "XDG_GREETER_DATA_DIR", data_dir);
+ g_free (data_dir);
+ }
+ }
+
+ if (session->priv->log_filename)
+ l_debug (session, "Logging to %s", session->priv->log_filename);
write_string (session, session->priv->log_filename);
write_string (session, session->priv->tty);
- write_string (session, xauth_filename);
- g_free (xauth_filename);
+ write_string (session, x_authority_filename);
+ g_free (x_authority_filename);
write_string (session, session->priv->xdisplay);
- write_xauth (session, session->priv->xauthority);
+ write_xauth (session, session->priv->x_authority);
argc = g_list_length (session->priv->env);
write_data (session, &argc, sizeof (argc));
for (link = session->priv->env; link; link = link->next)
g_return_if_fail (session != NULL);
if (getuid () == 0)
{
- if (login1_is_running ())
+ if (session->priv->login1_session)
login1_lock_session (session->priv->login1_session);
- if (!session->priv->login1_session)
+ else if (session->priv->console_kit_cookie)
ck_lock_session (session->priv->console_kit_cookie);
}
}
g_return_if_fail (session != NULL);
if (getuid () == 0)
{
- if (login1_is_running ())
+ if (session->priv->login1_session)
login1_unlock_session (session->priv->login1_session);
- if (!session->priv->login1_session)
+ else if (session->priv->console_kit_cookie)
ck_unlock_session (session->priv->console_kit_cookie);
}
}
if (session->priv->pid > 0)
{
- g_debug ("Session %d: Sending SIGTERM", session->priv->pid);
+ l_debug (session, "Sending SIGTERM");
kill (session->priv->pid, SIGTERM);
// FIXME: Handle timeout
}
session_init (Session *session)
{
session->priv = G_TYPE_INSTANCE_GET_PRIVATE (session, SESSION_TYPE, SessionPrivate);
+ session->priv->log_filename = g_strdup (".xsession-errors");
}
static void
Session *self = SESSION (object);
int i;
+ g_free (self->priv->session_type);
if (self->priv->display_server)
g_object_unref (self->priv->display_server);
if (self->priv->pid)
g_free (self->priv->messages);
g_free (self->priv->authentication_result_string);
g_free (self->priv->log_filename);
- g_free (self->priv->class);
g_free (self->priv->tty);
g_free (self->priv->xdisplay);
- if (self->priv->xauthority)
- g_object_unref (self->priv->xauthority);
+ if (self->priv->x_authority)
+ g_object_unref (self->priv->x_authority);
g_free (self->priv->remote_host_name);
g_free (self->priv->login1_session);
g_free (self->priv->console_kit_cookie);
NULL,
G_TYPE_NONE, 0);
}
+
+static gint
+session_real_logprefix (Logger *self, gchar *buf, gulong buflen)
+{
+ Session *session = SESSION (self);
+ if (session->priv->pid != 0)
+ return g_snprintf (buf, buflen, "Session pid=%d: ", session->priv->pid);
+ else
+ return g_snprintf (buf, buflen, "Session: ");
+}
+
+static void
+session_logger_iface_init (LoggerInterface *iface)
+{
+ iface->logprefix = &session_real_logprefix;
+}