summaryrefslogtreecommitdiff
path: root/daemon/gdm-product-slave.c
diff options
context:
space:
mode:
authorWilliam Jon McCann <mccann@jhu.edu>2007-10-29 17:09:04 +0000
committerWilliam Jon McCann <mccann@src.gnome.org>2007-10-29 17:09:04 +0000
commitf86a775c01b27bad3b1167bb5a6571a1ecf971cc (patch)
tree0ffdc769cd07c0940f995d270cec835607cbaec6 /daemon/gdm-product-slave.c
parentee4e3a5f4f46fa22aaa7fb0e4de82f2fece9c563 (diff)
downloadgdm-f86a775c01b27bad3b1167bb5a6571a1ecf971cc.tar.gz
Move the exec_script stuff to the base class.
2007-10-29 William Jon McCann <mccann@jhu.edu> * daemon/gdm-factory-slave.c: (run_greeter): * daemon/gdm-product-slave.c: (setup_server): * daemon/gdm-simple-slave.c: (run_greeter): * daemon/gdm-slave.c: (gdm_slave_whack_temp_auth_file), (create_temp_auth_file), (listify_hash), (get_script_environment), (gdm_slave_run_script): * daemon/gdm-slave.h: Move the exec_script stuff to the base class. svn path=/trunk/; revision=5449
Diffstat (limited to 'daemon/gdm-product-slave.c')
-rw-r--r--daemon/gdm-product-slave.c252
1 files changed, 1 insertions, 251 deletions
diff --git a/daemon/gdm-product-slave.c b/daemon/gdm-product-slave.c
index 20879449..53ac41c6 100644
--- a/daemon/gdm-product-slave.c
+++ b/daemon/gdm-product-slave.c
@@ -103,254 +103,6 @@ static void gdm_product_slave_finalize (GObject *object);
G_DEFINE_TYPE (GdmProductSlave, gdm_product_slave, GDM_TYPE_SLAVE)
static void
-gdm_product_slave_whack_temp_auth_file (GdmProductSlave *product_slave)
-{
-#if 0
- uid_t old;
-
- old = geteuid ();
- if (old != 0)
- seteuid (0);
- if (d->parent_temp_auth_file != NULL) {
- VE_IGNORE_EINTR (g_unlink (d->parent_temp_auth_file));
- }
- g_free (d->parent_temp_auth_file);
- d->parent_temp_auth_file = NULL;
- if (old != 0)
- seteuid (old);
-#endif
-}
-
-
-static void
-create_temp_auth_file (GdmProductSlave *product_slave)
-{
-#if 0
- if (d->type == TYPE_FLEXI_XNEST &&
- d->parent_auth_file != NULL) {
- if (d->parent_temp_auth_file != NULL) {
- VE_IGNORE_EINTR (g_unlink (d->parent_temp_auth_file));
- }
- g_free (d->parent_temp_auth_file);
- d->parent_temp_auth_file =
- copy_auth_file (d->server_uid,
- gdm_daemon_config_get_gdmuid (),
- d->parent_auth_file);
- }
-#endif
-}
-
-static void
-listify_hash (const char *key,
- const char *value,
- GPtrArray *env)
-{
- char *str;
- str = g_strdup_printf ("%s=%s", key, value);
- g_debug ("environment: %s", str);
- g_ptr_array_add (env, str);
-}
-
-static GPtrArray *
-get_script_environment (GdmProductSlave *slave,
- const char *username)
-{
- GPtrArray *env;
- GHashTable *hash;
- struct passwd *pwent;
- char *x_servers_file;
- char *display_name;
- char *display_hostname;
- char *display_x11_authority_file;
- gboolean display_is_local;
- char *temp;
-
- g_object_get (slave,
- "display-name", &display_name,
- "display-hostname", &display_hostname,
- "display-is-local", &display_is_local,
- "display-x11-authority-file", &display_x11_authority_file,
- NULL);
-
- env = g_ptr_array_new ();
-
- /* create a hash table of current environment, then update keys has necessary */
- hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
-
- /* modify environment here */
- g_hash_table_insert (hash, g_strdup ("HOME"), g_strdup ("/"));
- g_hash_table_insert (hash, g_strdup ("PWD"), g_strdup ("/"));
- g_hash_table_insert (hash, g_strdup ("SHELL"), g_strdup ("/bin/sh"));
-
- g_hash_table_insert (hash, g_strdup ("LOGNAME"), g_strdup (username));
- g_hash_table_insert (hash, g_strdup ("USER"), g_strdup (username));
- g_hash_table_insert (hash, g_strdup ("USERNAME"), g_strdup (username));
-
- pwent = getpwnam (username);
- if (pwent != NULL) {
- if (pwent->pw_dir != NULL && pwent->pw_dir[0] != '\0') {
- g_hash_table_insert (hash, g_strdup ("HOME"), g_strdup (pwent->pw_dir));
- g_hash_table_insert (hash, g_strdup ("PWD"), g_strdup (pwent->pw_dir));
- }
-
- g_hash_table_insert (hash, g_strdup ("SHELL"), g_strdup (pwent->pw_shell));
- }
-
-#if 0
- if (display_is_parented) {
- g_hash_table_insert (hash, g_strdup ("GDM_PARENT_DISPLAY"), g_strdup (parent_display_name));
-
- /*g_hash_table_insert (hash, "GDM_PARENT_XAUTHORITY"), slave->priv->parent_temp_auth_file));*/
- }
-#endif
-
- /* some env for use with the Pre and Post scripts */
- temp = g_strconcat (display_name, ".Xservers", NULL);
- x_servers_file = g_build_filename (AUTHDIR, temp, NULL);
- g_free (temp);
-
- g_hash_table_insert (hash, g_strdup ("X_SERVERS"), x_servers_file);
-
- if (! display_is_local) {
- g_hash_table_insert (hash, g_strdup ("REMOTE_HOST"), g_strdup (display_hostname));
- }
-
- /* Runs as root */
- g_hash_table_insert (hash, g_strdup ("XAUTHORITY"), g_strdup (display_x11_authority_file));
- g_hash_table_insert (hash, g_strdup ("DISPLAY"), g_strdup (display_name));
-
- /*g_setenv ("PATH", gdm_daemon_config_get_value_string (GDM_KEY_ROOT_PATH), TRUE);*/
-
- g_hash_table_insert (hash, g_strdup ("RUNNING_UNDER_GDM"), g_strdup ("true"));
-
- g_hash_table_remove (hash, "MAIL");
-
-
- g_hash_table_foreach (hash, (GHFunc)listify_hash, env);
- g_hash_table_destroy (hash);
-
- g_ptr_array_add (env, NULL);
-
- g_free (display_name);
- g_free (display_hostname);
- g_free (display_x11_authority_file);
-
- return env;
-}
-
-static gboolean
-gdm_product_slave_exec_script (GdmProductSlave *slave,
- const char *dir,
- const char *login)
-{
- char *script;
- char **argv;
- gint status;
- GError *error;
- GPtrArray *env;
- gboolean res;
- gboolean ret;
- char *display_name;
- char *display_hostname;
-
- g_assert (dir != NULL);
- g_assert (login != NULL);
-
- g_object_get (slave,
- "display-name", &display_name,
- "display-hostname", &display_hostname,
- NULL);
-
- script = g_build_filename (dir, display_name, NULL);
- if (g_access (script, R_OK|X_OK) != 0) {
- g_free (script);
- script = NULL;
- }
-
- if (script == NULL &&
- display_hostname != NULL) {
- script = g_build_filename (dir, display_hostname, NULL);
- if (g_access (script, R_OK|X_OK) != 0) {
- g_free (script);
- script = NULL;
- }
- }
-
-#if 0
- if (script == NULL &&
- SERVER_IS_XDMCP (d)) {
- script = g_build_filename (dir, "XDMCP", NULL);
- if (g_access (script, R_OK|X_OK) != 0) {
- g_free (script);
- script = NULL;
- }
- }
- if (script == NULL &&
- SERVER_IS_FLEXI (d)) {
- script = g_build_filename (dir, "Flexi", NULL);
- if (g_access (script, R_OK|X_OK) != 0) {
- g_free (script);
- script = NULL;
- }
- }
-#endif
-
- if (script == NULL) {
- script = g_build_filename (dir, "Default", NULL);
- if (g_access (script, R_OK|X_OK) != 0) {
- g_free (script);
- script = NULL;
- }
- }
-
- if (script == NULL) {
- return TRUE;
- }
-
- create_temp_auth_file (slave);
-
- g_debug ("Running process: %s", script);
- error = NULL;
- if (! g_shell_parse_argv (script, NULL, &argv, &error)) {
- g_warning ("Could not parse command: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- env = get_script_environment (slave, login);
-
- res = g_spawn_sync (NULL,
- argv,
- (char **)env->pdata,
- G_SPAWN_SEARCH_PATH,
- NULL,
- NULL,
- NULL,
- NULL,
- &status,
- &error);
-
- g_ptr_array_foreach (env, (GFunc)g_free, NULL);
- g_ptr_array_free (env, TRUE);
-
- gdm_product_slave_whack_temp_auth_file (slave);
-
- if (WIFEXITED (status)) {
- g_debug ("Process exit status: %d", WEXITSTATUS (status));
- ret = WEXITSTATUS (status) != 0;
- } else {
- ret = TRUE;
- }
-
- out:
- g_free (script);
- g_free (display_name);
- g_free (display_hostname);
-
- return ret;
-}
-
-static void
relay_session_started (GdmProductSlave *slave)
{
GError *error;
@@ -711,9 +463,7 @@ setup_server (GdmProductSlave *slave)
#endif
/* Run the init script. gdmslave suspends until script has terminated */
- gdm_product_slave_exec_script (slave,
- GDMCONFDIR"/Init",
- "gdm");
+ gdm_slave_run_script (GDM_SLAVE (slave), GDMCONFDIR"/Init", "gdm");
g_free (display_name);
g_free (auth_file);