/* change to an existing vt */ static void change_vt (int vt) { char *cmd; char *ret; cmd = g_strdup_printf (MDM_SUP_SET_VT " %d", vt); ret = mdmcomm_call_mdm (cmd, auth_cookie, "1.0.0.0", 5); g_free (cmd); if (ve_string_empty (ret) || strcmp (ret, "OK") != 0) { GtkWidget *dialog; const char *message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot change display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); } g_free (ret); }
static int get_cur_vt (void) { char *result; static int cur_vt; static gboolean checked = FALSE; char *ret = NULL; result = NULL; if (checked) { return cur_vt; } ret = mdmcomm_call_mdm ("QUERY_VT", auth_cookie, "1.0.0.0", 5); if (ve_string_empty (ret) || strncmp (ret, "OK ", 3) != 0) { goto out; } if (sscanf (ret, "OK %d", &cur_vt) != 1) { cur_vt = -1; } checked = TRUE; out: g_free (ret); return cur_vt; }
/** * mdm_config_get_xserver_details * * Calls daemon to get details for an xserver config. */ static gchar * mdm_config_get_xserver_details (const gchar *xserver, const gchar *key) { gchar *command = NULL; gchar *result = NULL; gchar *temp; command = g_strdup_printf ("GET_SERVER_DETAILS %s %s", xserver, key); result = mdmcomm_call_mdm (command, NULL /* auth cookie */, "1.0.0.0", comm_tries); g_free (command); if (! result || ve_string_empty (result) || strncmp (result, "OK ", 3) != 0) { mdm_common_error ("Could not access xserver configuration"); if (result) g_free (result); return NULL; } /* skip the "OK " */ temp = g_strdup (result + 3); g_free (result); return temp; }
/** * mdm_config_get_result * * Calls daemon to get config result, stripping the key so it * doesn't contain a default value. */ static gchar * mdm_config_get_result (const gchar *key) { gchar *p; gchar *newkey = g_strdup (key); gchar *command = NULL; gchar *result = NULL; static char *display = NULL; g_strstrip (newkey); p = strchr (newkey, '='); if (p != NULL) *p = '\0'; display = g_strdup (g_getenv ("DISPLAY")); if (display == NULL) command = g_strdup_printf ("GET_CONFIG %s", newkey); else command = g_strdup_printf ("GET_CONFIG %s %s", newkey, display); result = mdmcomm_call_mdm (command, NULL /* auth cookie */, "1.0.0.0", comm_tries); g_free (display); g_free (command); g_free (newkey); return result; }
static void check_for_users (void) { char *ret; char **vec; int i; int extra; /* only for console logins on vt supporting systems */ if (auth_cookie == NULL || get_cur_vt () < 0) return; ret = mdmcomm_call_mdm ("CONSOLE_SERVERS", auth_cookie, "1.0.0.0", 5); if (ve_string_empty (ret) || strncmp (ret, "OK ", 3) != 0) { g_free (ret); return; } vec = g_strsplit (&ret[3], ";", -1); g_free (ret); if (vec == NULL) return; extra = 0; for (i = 0; vec[i] != NULL; i++) { char **rvec; int vt; rvec = g_strsplit (vec[i], ",", -1); if (mdm_vector_len (rvec) != 3) { g_strfreev (rvec); continue; } vt = get_vt_num (vec, rvec[2], 5); if (strcmp (rvec[0], mdmcomm_get_display ()) != 0 && vt >= 0) { /* this is not the current display */ extra++; } g_strfreev (rvec); } if (extra == 0) { g_strfreev (vec); return; } run_logged_in_dialogue (vec); g_strfreev (vec); }
static void check_for_displays (void) { char *ret; char **vec; char *auth_cookie = NULL; int i; /* * Might be nice to move this call into read_config() so that it happens * on the same socket call as reading the configuration. */ ret = mdmcomm_call_mdm (MDM_SUP_ATTACHED_SERVERS, auth_cookie, "1.0.0.0", 5); if (ve_string_empty (ret) || strncmp (ret, "OK ", 3) != 0) { g_free (ret); return; } vec = g_strsplit (&ret[3], ";", -1); g_free (ret); if (vec == NULL) return; if (displays_hash == NULL) displays_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); for (i = 0; vec[i] != NULL; i++) { char **rvec; rvec = g_strsplit (vec[i], ",", -1); if (mdm_vector_len (rvec) != 3) { g_strfreev (rvec); continue; } g_hash_table_insert (displays_hash, g_strdup (rvec[1]), g_strdup (rvec[0])); g_strfreev (rvec); } g_strfreev (vec); }
int main (int argc, char *argv[]) { GtkWidget *dialog; char *command; char *version; char *ret; const char *message; GOptionContext *ctx; bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Option parsing */ ctx = g_option_context_new ("- New mdm login"); g_option_context_add_main_entries (ctx, options, _("main options")); g_option_context_parse (ctx, &argc, &argv, NULL); g_option_context_free (ctx); if (monte_carlo_pi) { calc_pi (); return 0; } mdm_log_init (); mdm_log_set_debug (debug_in); if (args_remaining != NULL && args_remaining[0] != NULL) server = args_remaining[0]; if (send_command != NULL) { if ( ! mdmcomm_check (FALSE)) { mdm_common_error (_("Error: MDM (MDM Display Manager) is not running.")); mdm_common_error (_("You might be using a different display manager.")); return 1; } } else { /* * The --command argument does not display anything, so avoid * running gtk_init until it finishes. Sometimes the * --command argument is used when there is no display so it * will fail and cause the program to exit, complaining about * "no display". */ gtk_init (&argc, &argv); if ( ! mdmcomm_check (TRUE)) { return 1; } } /* Start reading config data in bulk */ mdmcomm_comm_bulk_start (); /* Process --command option */ g_type_init (); if (send_command != NULL) { /* gdk_init is needed for cookie code to get display */ gdk_init (&argc, &argv); if (authenticate) auth_cookie = mdmcomm_get_auth_cookie (); /* * If asking for a translatable config value, then try to get * the translated value first. If this fails, then go ahead * and call the normal sockets command. */ if (strncmp (send_command, MDM_SUP_GET_CONFIG " ", strlen (MDM_SUP_GET_CONFIG " ")) == 0) { gchar *value = NULL; const char *key = &send_command[strlen (MDM_SUP_GET_CONFIG " ")]; if (is_key (MDM_KEY_WELCOME, key) || is_key (MDM_KEY_REMOTE_WELCOME, key)) { value = mdm_config_get_translated_string ((gchar *)key); if (value != NULL) { ret = g_strdup_printf ("OK %s", value); } } /* * If the above didn't return a value, then must be a * different key, so call mdmcomm_call_mdm. */ if (value == NULL) ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } else { ret = mdmcomm_call_mdm (send_command, auth_cookie, "1.0.0.0", 5); } /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL) { g_print ("%s\n", ret); return 0; } else { dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot communicate with MDM " "(The MDM Display Manager)"), _("Perhaps you have an old version " "of MDM running.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } } /* * Now process what mdmflexiserver is more frequently used to * do, start VT (Virtual Terminal) sesions - at least on * systems where it is supported. On systems where it is not * supporteed VT stands for "Very Tight" and will mess up your * display if you use it. Tight! So do not use it. * * I would accept a patch to disable it on such systems, but it * is easy to avoid not using it as long as your distro does not * put the menu choice in the application launch button on the * panel (don't ship the desktop file). */ /* * Always attempt to get cookie and authenticate. On remote * servers */ auth_cookie = mdmcomm_get_auth_cookie (); if (use_xnest) { char *cookie = mdmcomm_get_a_cookie (FALSE /* binary */); if (cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to have the " "authentication needed for this " "operation"), _("Perhaps your .Xauthority " "file is not set up correctly.")); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } command = g_strdup_printf (MDM_SUP_FLEXI_XNEST " %s %d %s %s", mdmcomm_get_display (), (int)getuid (), cookie, XauFileName ()); g_free (cookie); version = "1.0.0.0"; auth_cookie = NULL; } else { /* check for other displays/logged in users */ check_for_users (); if (auth_cookie == NULL) { /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("You do not seem to be logged in on the " "console"), _("Starting a new login only " "works correctly on the console.")); gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return 1; } read_servers (); server = choose_server (); if (server == NULL) command = g_strdup (MDM_SUP_FLEXI_XSERVER); else command = g_strdup_printf (MDM_SUP_FLEXI_XSERVER " %s", server); version = "1.0.0.0"; } ret = mdmcomm_call_mdm (command, auth_cookie, version, 5); g_free (command); g_free (auth_cookie); g_strfreev (args_remaining); /* At this point we are done using the socket, so close it */ mdmcomm_comm_bulk_stop (); if (ret != NULL && strncmp (ret, "OK ", 3) == 0) { /* if we switched to a different screen as a result of this, * lock the current screen */ if ( ! no_lock && ! use_xnest) { maybe_lock_screen (); } /* all fine and dandy */ g_free (ret); return 0; } message = mdmcomm_get_error_message (ret, use_xnest); dialog = hig_dialog_new (NULL /* parent */, GTK_DIALOG_MODAL /* flags */, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _("Cannot start new display"), message); gtk_widget_show_all (dialog); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_free (ret); return 1; }
/** * mdm_config_get_xservers * * Calls daemon to get xserver config. */ GSList * mdm_config_get_xservers (gboolean flexible) { GSList *xservers = NULL; gchar **splitstr, **sec; gchar *command = NULL; gchar *result = NULL; gchar *temp; command = g_strdup_printf ("GET_SERVER_LIST"); result = mdmcomm_call_mdm (command, NULL /* auth cookie */, "1.0.0.0", comm_tries); g_free (command); if (! result || ve_string_empty (result) || strncmp (result, "OK ", 3) != 0) { mdm_common_error ("Could not access xserver configuration"); if (result) g_free (result); return NULL; } /* skip the "OK " */ splitstr = g_strsplit (result + 3, ";", 0); sec = splitstr; g_free (result); while (sec != NULL && *sec != NULL) { MdmXserver *svr = g_new0 (MdmXserver, 1); temp = mdm_config_get_xserver_details (*sec, "ID"); if (temp == NULL) { g_free (svr); continue; } svr->id = temp; temp = mdm_config_get_xserver_details (*sec, "NAME"); if (temp == NULL) { g_free (svr); continue; } svr->name = temp; temp = mdm_config_get_xserver_details (*sec, "COMMAND"); if (temp == NULL) { g_free (svr); continue; } svr->command = temp; temp = mdm_config_get_xserver_details (*sec, "FLEXIBLE"); if (temp == NULL) { g_free (svr); continue; } else if (g_strncasecmp (ve_sure_string (temp), "true", 4) == 0) svr->flexible = TRUE; else svr->flexible = FALSE; g_free (temp); temp = mdm_config_get_xserver_details (*sec, "CHOOSABLE"); if (temp == NULL) { g_free (svr); continue; } else if (g_strncasecmp (temp, "true", 4) == 0) svr->choosable = TRUE; else svr->choosable = FALSE; g_free (temp); temp = mdm_config_get_xserver_details (*sec, "HANDLED"); if (temp == NULL) { g_free (svr); continue; } else if (g_strncasecmp (temp, "true", 4) == 0) svr->handled = TRUE; else svr->handled = FALSE; g_free (temp); temp = mdm_config_get_xserver_details (*sec, "CHOOSER"); if (temp == NULL) { g_free (svr); continue; } else if (g_strncasecmp (temp, "true", 4) == 0) svr->chooser = TRUE; else svr->chooser = FALSE; g_free (temp); temp = mdm_config_get_xserver_details (*sec, "PRIORITY"); if (temp == NULL) { g_free (svr); continue; } else { svr->priority = atoi (temp); } g_free (temp); sec++; /* If only flexible was requested, then skip if not flexible */ if (flexible && !svr->flexible) { g_free (svr); continue; } xservers = g_slist_append (xservers, svr); } g_strfreev (splitstr); return xservers; }