/* Copyright (C) 2002-2010 Karl J. Runge All rights reserved. This file is part of x11vnc. x11vnc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. x11vnc is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with x11vnc; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA or see . In addition, as a special exception, Karl J. Runge gives permission to link the code of its release of x11vnc with the OpenSSL project's "OpenSSL" library (or with modified versions of it that use the same license as the "OpenSSL" library), and distribute the linked executables. You must obey the GNU General Public License in all respects for all of the code used other than "OpenSSL". If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ /* -- connections.c -- */ #include "x11vnc.h" #include "inet.h" #include "remote.h" #include "keyboard.h" #include "cleanup.h" #include "gui.h" #include "solid.h" #include "rates.h" #include "screen.h" #include "unixpw.h" #include "user.h" #include "scan.h" #include "sslcmds.h" #include "sslhelper.h" #include "xwrappers.h" #include "xevents.h" #include "win_utils.h" #include "macosx.h" #include "macosxCG.h" #include "userinput.h" #include "pointer.h" #include "xrandr.h" /* * routines for handling incoming, outgoing, etc connections */ /* string for the VNC_CONNECT property */ char vnc_connect_str[VNC_CONNECT_MAX+1]; Atom vnc_connect_prop = None; char x11vnc_remote_str[X11VNC_REMOTE_MAX+1]; Atom x11vnc_remote_prop = None; rfbClientPtr inetd_client = NULL; int all_clients_initialized(void); char *list_clients(void); int new_fb_size_clients(rfbScreenInfoPtr s); void close_all_clients(void); void close_clients(char *str); void set_client_input(char *str); void set_child_info(void); int cmd_ok(char *cmd); void client_gone(rfbClientPtr client); void client_gone_chat_helper(rfbClientPtr client); void reverse_connect(char *str); void set_vnc_connect_prop(char *str); void read_vnc_connect_prop(int); void set_x11vnc_remote_prop(char *str); void read_x11vnc_remote_prop(int); void check_connect_inputs(void); void check_gui_inputs(void); rfbClientPtr create_new_client(int sock, int start_thread); enum rfbNewClientAction new_client(rfbClientPtr client); enum rfbNewClientAction new_client_chat_helper(rfbClientPtr client); rfbBool password_check_chat_helper(rfbClientPtr cl, const char* response, int len); void start_client_info_sock(char *host_port_cookie); void send_client_info(char *str); void adjust_grabs(int grab, int quiet); void check_new_clients(void); int accept_client(rfbClientPtr client); void check_ipv6_listen(long usec); void check_unix_sock(long usec); int run_user_command(char *cmd, rfbClientPtr client, char *mode, char *input, int len, FILE *output); int check_access(char *addr); void client_set_net(rfbClientPtr client); char *get_xprop(char *prop, Window win); int set_xprop(char *prop, Window win, char *value); char *bcx_xattach(char *str, int *pg_init, int *kg_init); void grab_state(int *ptr_grabbed, int *kbd_grabbed); char *wininfo(Window win, int show_children); static rfbClientPtr *client_match(char *str); static void free_client_data(rfbClientPtr client); static void ugly_geom(char *p, int *x, int *y); static int ugly_window(char *addr, char *userhost, int X, int Y, int timeout, char *mode, int accept); static int action_match(char *action, int rc); static void check_connect_file(char *file); static void send_client_connect(void); /* * check that all clients are in RFB_NORMAL state */ int all_clients_initialized(void) { rfbClientIteratorPtr iter; rfbClientPtr cl; int ok = 1; if (! screen) { return ok; } iter = rfbGetClientIterator(screen); while( (cl = rfbClientIteratorNext(iter)) ) { if (cl->state != RFB_NORMAL) { ok = 0; } else { client_normal_count++; } } rfbReleaseClientIterator(iter); return ok; } char *list_clients(void) { rfbClientIteratorPtr iter; rfbClientPtr cl; char *list, tmp[256]; int count = 0; if (!screen) { return strdup(""); } iter = rfbGetClientIterator(screen); while( (cl = rfbClientIteratorNext(iter)) ) { client_set_net(cl); count++; } rfbReleaseClientIterator(iter); /* * each client: * ::::::::