FONT *font_gtk_new() { FONT *f = g_new(FONT, 1); f->sel_font = font_gtk_sel_font; f->get_glyph = font_gtk_get_glyph; f->draw_glyph = font_gtk_draw_glyph; f->self_drawable = drawable; f->antialiase_on = FALSE; mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); gdk_depth = gdk_visual_get_best_depth(); img_glyph.width = GLYPH_PIXMAP_WIDTH; img_glyph.height = GLYPH_PIXMAP_HEIGHT; img_glyph.bytes_per_line = GLYPH_PIXMAP_WIDTH; img_glyph.depth = 8; img_glyph.bytes_per_pixel = 1; img_glyph.pixel = g_malloc(GLYPH_PIXMAP_WIDTH * GLYPH_PIXMAP_HEIGHT); this = f; NOTICE("FontDevice gtk\n"); return f; }
char *iupdrvGetGlobal(const char *name) { if (iupStrEqual(name, "VIRTUALSCREEN")) { GdkScreen *screen = gdk_screen_get_default(); GdkWindow *root = gdk_screen_get_root_window(gdk_screen_get_default()); int x = 0; int y = 0; int w = gdk_screen_get_width(screen); int h = gdk_screen_get_height(screen); gdk_window_get_root_origin(root, &x, &y); return iupStrReturnStrf("%d %d %d %d", x, y, w, h); } if (iupStrEqual(name, "MONITORSINFO")) { int i; GdkScreen *screen = gdk_screen_get_default(); int monitors_count = gdk_screen_get_n_monitors(screen); char *str = iupStrGetMemory(monitors_count*50); char* pstr = str; GdkRectangle rect; for (i=0; i < monitors_count; i++) { gdk_screen_get_monitor_geometry(screen, i, &rect); pstr += sprintf(pstr, "%d %d %d %d\n", rect.x, rect.y, rect.width, rect.height); } return str; } if (iupStrEqual(name, "TRUECOLORCANVAS")) { return iupStrReturnBoolean(gdk_visual_get_best_depth() > 8); } if (iupStrEqual(name, "UTF8MODE")) { return iupStrReturnBoolean(iupgtkStrGetUTF8Mode()); } if (iupStrEqual(name, "UTF8AUTOCONVERT")) { return iupStrReturnBoolean(!iupgtkStrGetUTF8Mode()); } if (iupStrEqual(name, "SHOWMENUIMAGES")) { gboolean menu_images; g_object_get (gtk_settings_get_default (), "gtk-menu-images", &menu_images, NULL); return iupStrReturnBoolean(menu_images); } return NULL; }
void remmina_rdp_event_init(RemminaProtocolWidget* gp) { gchar* s; gint flags; rfContext* rfi; GtkClipboard* clipboard; rfi = GET_DATA(gp); rfi->drawing_area = gtk_drawing_area_new(); gtk_widget_show(rfi->drawing_area); gtk_container_add(GTK_CONTAINER(gp), rfi->drawing_area); gtk_widget_add_events(rfi->drawing_area, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_SCROLL_MASK | GDK_FOCUS_CHANGE_MASK); gtk_widget_set_can_focus(rfi->drawing_area, TRUE); remmina_plugin_service->protocol_plugin_register_hostkey(gp, rfi->drawing_area); s = remmina_plugin_service->pref_get_value("rdp_use_client_keymap"); rfi->use_client_keymap = (s && s[0] == '1' ? TRUE : FALSE); g_free(s); #if GTK_VERSION == 3 g_signal_connect(G_OBJECT(rfi->drawing_area), "draw", G_CALLBACK(remmina_rdp_event_on_draw), gp); #elif GTK_VERSION == 2 g_signal_connect(G_OBJECT(rfi->drawing_area), "expose-event", G_CALLBACK(remmina_rdp_event_on_expose), gp); #endif g_signal_connect(G_OBJECT(rfi->drawing_area), "configure-event", G_CALLBACK(remmina_rdp_event_on_configure), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "motion-notify-event", G_CALLBACK(remmina_rdp_event_on_motion), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "button-press-event", G_CALLBACK(remmina_rdp_event_on_button), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "button-release-event", G_CALLBACK(remmina_rdp_event_on_button), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "scroll-event", G_CALLBACK(remmina_rdp_event_on_scroll), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "key-press-event", G_CALLBACK(remmina_rdp_event_on_key), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "key-release-event", G_CALLBACK(remmina_rdp_event_on_key), gp); g_signal_connect(G_OBJECT(rfi->drawing_area), "focus-in-event", G_CALLBACK(remmina_rdp_event_on_focus_in), gp); RemminaFile* remminafile = remmina_plugin_service->protocol_plugin_get_file(gp); if (!remmina_plugin_service->file_get_int(remminafile, "disableclipboard", FALSE)) { clipboard = gtk_widget_get_clipboard(rfi->drawing_area, GDK_SELECTION_CLIPBOARD); rfi->clipboard_handler = g_signal_connect(clipboard, "owner-change", G_CALLBACK(remmina_rdp_event_on_clipboard), gp); } rfi->pressed_keys = g_array_new(FALSE, TRUE, sizeof (gint)); rfi->event_queue = g_async_queue_new_full(g_free); rfi->ui_queue = g_async_queue_new(); if (pipe(rfi->event_pipe)) { g_print("Error creating pipes.\n"); rfi->event_pipe[0] = -1; rfi->event_pipe[1] = -1; } else { flags = fcntl(rfi->event_pipe[0], F_GETFL, 0); fcntl(rfi->event_pipe[0], F_SETFL, flags | O_NONBLOCK); } rfi->object_table = g_hash_table_new_full(NULL, NULL, NULL, g_free); rfi->display = gdk_display_get_default(); rfi->bpp = gdk_visual_get_best_depth(); }
int main (int argc, char **argv) { gchar *confdir; gchar *host = g_strdup ("localhost"); gchar *port = g_strdup ("22"); gchar *sshkey = NULL; gchar *user = NULL; gchar *password = NULL; gchar *session = g_strdup ("thinnx"); gchar *type = g_strdup ("unix-gnome"); gchar *cookie = NULL; gboolean use_ssl = 0; gchar *link = g_strdup ("adsl"); gchar *kbdtype = g_strdup ("pc104/us"); gchar *geometry = g_strdup ("fullscreen"); gchar *screeninfo = NULL; gchar *session_id = NULL; gchar *session_display = NULL; gchar *pcookie = NULL; gchar **nxssh_argv = (gchar**) g_malloc (sizeof(gchar*) * 9); gchar *restore_id = NULL; pid_t pid; int parent_pipe[2]; /* For talking to the parent */ int child_pipe[2]; /* For talking to the child */ gint in = 0, out = 0; gtk_init (&argc, &argv); homedir = g_get_home_dir (); confdir = g_strdup_printf ("%s/.nx/", homedir); sshkey = g_strdup_printf ("%s/.ssh/id_dsa", homedir); { struct stat info; if (stat (confdir, &info) == -1) { if (mkdir (confdir, 0777) == -1) g_critical ("Could not create directory %s: %s\n", confdir, strerror (errno)); } } { #if GTK_MAJOR_VERSION == 2 GdkScreen *screen; screen = gdk_screen_get_default (); screeninfo = g_strdup_printf ("%dx%dx%d+render", gdk_screen_get_width (screen), gdk_screen_get_height (screen), gdk_visual_get_best_depth ()); #else screeninfo = g_strdup_printf ("%dx%dx%d+render", gdk_screen_width (), gdk_screen_height (), gdk_visual_get_best_depth ()); #endif } { /* get X authentication cookie information */ FILE *xauth_output; gchar xauth[256] = {0}; gchar *tmp = NULL; gchar **tmpv = NULL; gchar *display = NULL; /* avoid problems with "network" DISPLAY's */ display = g_strdup (getenv ("DISPLAY")); tmpv = g_strsplit (display, ":", 3); g_free (display); display = g_strdup_printf (":%s", tmpv[1]); g_strfreev (tmpv); /* get the authorization token */ tmp = g_strdup_printf (XAUTHBINDIR"/xauth list %s | " "grep 'MIT-MAGIC-COOKIE-1' | " "cut -d ' ' -f 5", display); if ((xauth_output = popen (tmp, "r")) == NULL) { g_critical ("Failed to obtain xauth key: %s", strerror(errno)); exit (1); } fread (xauth, sizeof(char), 256, xauth_output); xauth[strlen(xauth) - 1] = '\0'; pclose (xauth_output); g_free (tmp); if (!strcmp (xauth, "")) { message_dialog ("Não foi possível obter um cookie de autenticação\n" "do servidor X. Impossível continuar."); exit (1); } cookie = g_strdup (xauth); } { /* read configuration file */ FILE *fconf; gint fconf_fd; gchar **tmp, *key, *value; struct stat info; if (stat (CONFFILE, &info) == -1) { g_warning ("WARNING: Could not stat %s: %s.\n", CONFFILE, strerror (errno)); } fconf = fopen (CONFFILE, "r"); if (fconf == NULL) { g_critical ("Could not open %s: %s.\n", CONFFILE, strerror (errno)); } else { fconf_fd = fileno (fconf); while (!feof (fconf)) { buffer = read_line (fconf_fd); if (!buffer) break; /* remove comments */ tmp = g_strsplit (buffer, "#", 2); g_free (buffer); buffer = g_strdup (tmp[0]); g_strfreev (tmp); /* check if we still have a key/value pair */ tmp = g_strsplit (buffer, "=", 2); g_free (buffer); if (tmp[1] == NULL || tmp[0] == NULL) { g_strfreev (tmp); continue; } key = tmp[0]; value = tmp[1]; g_strstrip (key); g_strstrip (value); if (!strcmp ("host", key)) { g_free (host); host = g_strdup (value); } else if (!strcmp ("port", key)) { g_free (port); port = g_strdup (value); } else if (!strcmp ("sshkey", key)) { g_free (sshkey); sshkey = g_strdup (value); } else if (!strcmp ("session", key)) { g_free (session); session = g_strdup (value); } else if (!strcmp ("ssl", key)) { if (!strcmp (value, "yes")) use_ssl = 1; } else if (!strcmp ("type", key)) { g_free (type); type = g_strdup (value); } else if (!strcmp ("link", key)) { g_free (link); link = g_strdup (value); } else if (!strcmp ("kbdtype", key)) { g_free (kbdtype); kbdtype = g_strdup (value); } else if (!strcmp ("geometry", key)) { g_free (geometry); geometry = g_strdup (value); } else g_warning ("Unknown option in %s: %s=%s\n", CONFFILE, key, value); g_strfreev (tmp); } fclose (fconf); } } /* grab auth information from the user before anything else */ input_dialog (&user, &password); if (!strcmp (user, "root")) { message_dialog ("O usuário root não pode entrar por aqui!"); exit (1); } pipe (parent_pipe); pipe (child_pipe); pid = fork (); if (pid == -1) { g_critical ("Could not fork!\n"); exit (1); } else if (pid == 0) { close (child_pipe[1]); dup2 (child_pipe[0], STDIN_FILENO); dup2 (parent_pipe[1], STDOUT_FILENO); nxssh_argv[0] = g_strdup (BINDIR"/nxssh"); nxssh_argv[1] = g_strdup ("-nx"); nxssh_argv[2] = g_strdup_printf ("-p%s", port); nxssh_argv[3] = g_strdup ("-i"); nxssh_argv[4] = g_strdup (sshkey); nxssh_argv[5] = g_strdup_printf ("nx@%s", host); nxssh_argv[6] = g_strdup ("-2"); nxssh_argv[7] = g_strdup ("-S"); nxssh_argv[8] = NULL; execv (nxssh_argv[0], nxssh_argv); } else { close(parent_pipe[1]); out = parent_pipe[0]; in = child_pipe[1]; /* Handle initial hand-shaking */ { gboolean ssh_authed = FALSE; while (!ssh_authed) { buffer = read_code (out); if (!strcmp (buffer, "NX> 205")) { flush_buffer (buffer); drop_line (out); drop_line (out); drop_chars (out, 56); write_line (in, "yes"); drop_line (out); drop_line (out); /* buffer != NULL? but why?! */ buffer = NULL; } else if (!strcmp (buffer, "NX> 208")) { /* OK, authenticating... */ } else if (!strcmp (buffer, "NX> 203") || (!strcmp (buffer, "NX> 285")) || (!strcmp (buffer, "NX> 200")) || (!strcmp (buffer, "NX> 202"))) { /* ignored stderr */ } else if (!strncmp (buffer, "nxssh", 5)) { gchar *msg; flush_buffer (buffer); buffer = read_line (out); msg = get_info_after_colon (buffer); g_free (buffer); if (!strcmp (msg, "Name or service not known")) message_dialog ("Não foi possível resolver o nome do servidor."); else if (!strcmp (msg, "Connection refused")) message_dialog ("A conexão foi recusada!\n" "Verifique a porta."); else if (!strcmp (msg, "Connection timed out")) message_dialog ("Tempo limite da conexão expirou!\n" "Verifique servidor e porta."); flush_buffer (msg); fprintf (stderr, "\n"); exit (1); } else if (!strcmp (buffer, "NX> 204")) { message_dialog ("Falha na autenticação inicial!\n" "Confira a chave privada."); g_critical ("Failed to authenticate to SSH using the public key!\n"); exit (1); } else if (!strcmp (buffer, "HELLO N")) { /* OK, time to say HELLO! */ ssh_authed = TRUE; } else protocol_error ("problems waiting for HELLO"); flush_buffer (buffer); buffer = read_line (out); flush_buffer (buffer); } } /* Handle HELLO */ buffer = read_code (out); if (!strcmp (buffer, "NX> 105")) { flush_buffer (buffer); drop_chars (out, 1); write_line (in, "HELLO NXCLIENT - Version 1.4.0"); drop_line (out); } else protocol_error ("problems during HELLO"); /* Handle Login */ buffer = read_code (out); if (!strcmp (buffer, "NX> 134")) { flush_buffer (buffer); buffer = read_line (out); flush_buffer (buffer); } else protocol_error ("HELLO failed?"); buffer = read_code (out); if (!strcmp (buffer, "NX> 105")) { flush_buffer (buffer); drop_chars (out, 1); write_line (in, "login"); drop_line (out); } else protocol_error ("No login? How come!"); buffer = read_code (out); if (!strcmp (buffer, "NX> 101")) { flush_buffer (buffer); drop_chars (out, 7); write_line (in, user); drop_line (out); } else protocol_error ("who took my login prompt away?"); buffer = read_code (out); if (!strcmp (buffer, "NX> 102")) { flush_buffer (buffer); drop_chars (out, 11); write_line (in, password); drop_line (out); } else protocol_error ("where is my password prompt?"); buffer = read_code (out); if (!strcmp (buffer, "NX> 103")) { flush_buffer (buffer); drop_line (out); } else { flush_buffer (buffer); message_dialog ("Login ou senha incorretos!"); exit (1); } buffer = read_code (out); if (!strcmp (buffer, "NX> 105")) { gchar *m; flush_buffer (buffer); drop_chars (out, 1); m = g_strdup_printf ("list %s", user); write_line (in, m); g_free (m); drop_lines (out, 5); while (1) { buffer = read_code (out); if (!strcmp (buffer, "NX> 105")) { flush_buffer (buffer); drop_chars (out, 1); break; } flush_buffer (buffer); buffer = read_line (out); restore_id = get_restore_id (buffer); } } else protocol_error ("session startup, buddy, I don't want problems!"); { gchar *cmdline; if (!restore_id) cmdline = g_strdup_printf ("startsession --session=\"%s\" --type=\"%s\" --cache=\"8M\" --images=\"32M\" --cookie=\"%s\" --link=\"%s\" --kbtype=\"%s\" --nodelay=\"1\" --backingstore=\"never\" --geometry=\"%s\" --media=\"0\" --agent_server=\"\" --agent_user=\"\" --agent_password=\"\" --screeninfo=\"%s\" --encryption=\"%d\"", session, type, cookie, link, kbdtype, geometry, screeninfo, use_ssl); else cmdline = g_strdup_printf ("restoresession --session=\"%s\" --type=\"%s\" --cache=\"8M\" --images=\"32M\" --cookie=\"%s\" --link=\"%s\" --kbtype=\"%s\" --nodelay=\"1\" --backingstore=\"never\" --geometry=\"%s\" --media=\"0\" --agent_server=\"\" --agent_user=\"\" --agent_password=\"\" --screeninfo=\"%s\" --encryption=\"%d\" --id=\"%s\"", session, type, cookie, link, kbdtype, geometry, screeninfo, use_ssl, restore_id); write_line (in, cmdline); g_free (cmdline); cmdline = NULL; drop_lines (out, 4); } session_id = get_session_info (out, "NX> 700"); session_display = get_session_info (out, "NX> 705"); drop_line (out); /* 703 (session type) */ pcookie = get_session_info (out, "NX> 701"); drop_line (out); /* 702 proxy ip */ drop_line (out); /* 706 agent cookie */ drop_line (out); /* 704 session cache */ { gchar *tmp = get_session_info (out, "NX> 707"); /* 707 ssl tunneling */ use_ssl = atoi (tmp); g_free (tmp); } drop_line (out); /* 710 session status: running */ drop_line (out); /* 1002 commit */ drop_line (out); /* 1006 session status: running */ read_code (out); drop_chars (out, 1); /* now prepare to run nxproxy */ { FILE *options; gchar *dirname; gchar *fname; gchar *cmdline; dirname = g_strdup_printf ("%s/.nx/S-%s", homedir, session_id); fname = g_strdup_printf ("%s/options", dirname); g_print ("Dir: %s\nFname: %s\n", dirname, fname); if (mkdir (dirname, 0777) == -1) { /* BOMB or handle 'directory already exists' */ } g_free (dirname); if (use_ssl) buffer = g_strdup_printf ("cookie=%s,root=%s/.nx,session=%s,id=%s,listen=%d:%s", pcookie, homedir, session, session_id, 8008, session_display); else buffer = g_strdup_printf ("cookie=%s,root=%s/.nx,session=%s,id=%s,connect=%s:%s", pcookie, homedir, session, session_id, host, session_display); options = fopen (fname, "w"); fwrite (buffer, sizeof(char), strlen (buffer), options); fclose (options); g_free (buffer); cmdline = g_strdup_printf (BINDIR"/nxproxy -S options=%s:%s", fname, session_display); system (cmdline); g_free (cmdline); g_free (fname); } } write_line (in, "bye"); drop_line (out); if (use_ssl) write_line (in, "switch"); drop_line (out); drop_line (out); drop_line (out); return 0; }
static VALUE rg_s_best_depth(G_GNUC_UNUSED VALUE self) { return INT2NUM(gdk_visual_get_best_depth()); }
char *iupdrvGetGlobal(const char *name) { if (iupStrEqual(name, "VIRTUALSCREEN")) { GdkScreen *screen = gdk_screen_get_default(); GdkWindow *root = gdk_screen_get_root_window(gdk_screen_get_default()); int x = 0; int y = 0; int w = gdk_screen_get_width(screen); int h = gdk_screen_get_height(screen); gdk_window_get_root_origin(root, &x, &y); return iupStrReturnStrf("%d %d %d %d", x, y, w, h); } if (iupStrEqual(name, "MONITORSINFO")) { int i; #if GTK_CHECK_VERSION(3, 22, 0) GdkDisplay *display = gdk_display_get_default(); int monitors_count = gdk_display_get_n_monitors(display); #else GdkScreen *screen = gdk_screen_get_default(); int monitors_count = gdk_screen_get_n_monitors(screen); #endif char *str = iupStrGetMemory(monitors_count * 50); char* pstr = str; GdkRectangle rect; for (i = 0; i < monitors_count; i++) { #if GTK_CHECK_VERSION(3, 22, 0) GdkMonitor* monitor = gdk_display_get_monitor(display, i); gdk_monitor_get_geometry(monitor, &rect); #else gdk_screen_get_monitor_geometry(screen, i, &rect); #endif pstr += sprintf(pstr, "%d %d %d %d\n", rect.x, rect.y, rect.width, rect.height); } return str; } if (iupStrEqual(name, "MONITORSCOUNT")) { #if GTK_CHECK_VERSION(3, 22, 0) GdkDisplay *display = gdk_display_get_default(); int monitors_count = gdk_display_get_n_monitors(display); #else GdkScreen *screen = gdk_screen_get_default(); int monitors_count = gdk_screen_get_n_monitors(screen); #endif return iupStrReturnInt(monitors_count); } if (iupStrEqual(name, "TRUECOLORCANVAS")) { return iupStrReturnBoolean(gdk_visual_get_best_depth() > 8); } if (iupStrEqual(name, "UTF8MODE")) { return iupStrReturnBoolean(iupgtkStrGetUTF8Mode()); } if (iupStrEqual(name, "UTF8AUTOCONVERT")) { return iupStrReturnBoolean(!iupgtkStrGetUTF8Mode()); } #ifndef WIN32 if (iupStrEqual(name, "EXEFILENAME")) { char* argv0 = IupGetGlobal("ARGV0"); if (argv0) { char* exefilename = realpath(argv0, NULL); if (exefilename) { char* str = iupStrReturnStr(exefilename); free(exefilename); return str; } } } #endif if (iupStrEqual(name, "SHOWMENUIMAGES")) { gboolean menu_images; g_object_get (gtk_settings_get_default (), "gtk-menu-images", &menu_images, NULL); return iupStrReturnBoolean(menu_images); } return NULL; }