1/*
2   Copyright (C) 2002-2010 Karl J. Runge <runge@karlrunge.com>
3   All rights reserved.
4
5This file is part of x11vnc.
6
7x11vnc is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or (at
10your option) any later version.
11
12x11vnc is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with x11vnc; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
20or see <http://www.gnu.org/licenses/>.
21
22In addition, as a special exception, Karl J. Runge
23gives permission to link the code of its release of x11vnc with the
24OpenSSL project's "OpenSSL" library (or with modified versions of it
25that use the same license as the "OpenSSL" library), and distribute
26the linked executables.  You must obey the GNU General Public License
27in all respects for all of the code used other than "OpenSSL".  If you
28modify this file, you may extend this exception to your version of the
29file, but you are not obligated to do so.  If you do not wish to do
30so, delete this exception statement from your version.
31*/
32
33/* -- options.c -- */
34
35#define _X11VNC_OPTIONS_H
36#include "x11vnc.h"
37
38/*
39 * variables for the command line options
40 */
41int debug = 0;
42
43char *use_dpy = NULL;		/* -display */
44int display_N = 0;
45int auto_port = 0;
46char *auth_file = NULL;		/* -auth/-xauth */
47char *visual_str = NULL;	/* -visual */
48int set_visual_str_to_something = 0;
49char *logfile = NULL;		/* -o, -logfile */
50int logfile_append = 0;
51char *flagfile = NULL;		/* -flag */
52char *rm_flagfile = NULL;	/* -rmflag */
53char *passwdfile = NULL;	/* -passwdfile */
54int unixpw = 0;			/* -unixpw */
55int unixpw_nis = 0;		/* -unixpw_nis */
56char *unixpw_list = NULL;
57char *unixpw_cmd = NULL;
58int unixpw_system_greeter = 0;
59int unixpw_system_greeter_active = 0;
60int use_stunnel = 0;		/* -stunnel */
61int stunnel_port = 0;
62char *stunnel_pem = NULL;
63int use_openssl = 0;
64int http_ssl = 0;
65int ssl_no_fail = 0;
66char *openssl_pem = NULL;
67char *ssl_certs_dir = NULL;
68char *enc_str = NULL;
69int vencrypt_mode = VENCRYPT_SUPPORT;
70int vencrypt_kx = VENCRYPT_BOTH;
71int vencrypt_enable_plain_login = 0;
72int anontls_mode = ANONTLS_SUPPORT;
73int create_fresh_dhparams = 0;
74char *dhparams_file = NULL;
75int http_try_it = 0;
76int stunnel_http_port = 0;
77int https_port_num = -1;
78int https_port_redir = 0;
79char *ssl_verify = NULL;
80char *ssl_crl = NULL;
81int ssl_initialized = 0;
82int ssl_timeout_secs = -1;
83char *ssh_str = NULL;
84pid_t ssh_pid = 0;
85int usepw = USEPW;
86char *blackout_str = NULL;	/* -blackout */
87int blackout_ptr = 0;
88char *clip_str = NULL;		/* -clip */
89int use_solid_bg = 0;		/* -solid */
90char *solid_str = NULL;
91char *solid_default = "cyan4";
92
93char *wmdt_str = NULL;		/* -wmdt */
94
95char *speeds_str = NULL;	/* -speeds */
96
97char *rc_rcfile = NULL;		/* -rc */
98int rc_rcfile_default = 0;
99int rc_norc = 0;
100int got_norc = 0;
101int opts_bg = 0;
102
103#ifndef VNCSHARED
104int shared = 0;			/* share vnc display. */
105#else
106int shared = 1;
107#endif
108#ifndef FOREVER
109int connect_once = 1;		/* disconnect after first connection session. */
110#else
111int connect_once = 0;
112#endif
113int got_connect_once = 0;
114int got_findauth = 0;
115int deny_all = 0;		/* global locking of new clients */
116#ifndef REMOTE_DEFAULT
117#define REMOTE_DEFAULT 1
118#endif
119int accept_remote_cmds = REMOTE_DEFAULT;	/* -noremote */
120char *remote_prefix = NULL;
121int remote_direct = 0;
122int query_default = 0;
123int safe_remote_only = 1;	/* -unsafe */
124int priv_remote = 0;		/* -privremote */
125int more_safe = 0;		/* -safer */
126#ifndef EXTERNAL_COMMANDS
127#define EXTERNAL_COMMANDS 1
128#endif
129#if EXTERNAL_COMMANDS
130int no_external_cmds = 0;	/* -nocmds */
131#else
132int no_external_cmds = 1;	/* cannot be turned back on. */
133#endif
134char *allowed_external_cmds = NULL;
135int started_as_root = 0;
136int host_lookup = 1;
137char *unix_sock = NULL;
138int unix_sock_fd = -1;
139#if X11VNC_LISTEN6
140int ipv6_listen = 1;		/* -6 / -no6 */
141int got_ipv6_listen = 1;
142#else
143int ipv6_listen = 0;		/* -6 / -no6 */
144int got_ipv6_listen = 0;
145#endif
146int ipv6_listen_fd = -1;
147int ipv6_http_fd = -1;
148int noipv6 = 0;
149int noipv4 = 0;
150char *ipv6_client_ip_str = NULL;
151char *users_list = NULL;	/* -users */
152char **user2group = NULL;
153char *allow_list = NULL;	/* for -allow and -localhost */
154char *listen_str = NULL;
155char *listen_str6 = NULL;
156char *allow_once = NULL;	/* one time -allow */
157char *accept_cmd = NULL;	/* for -accept */
158char *afteraccept_cmd = NULL;	/* for -afteraccept */
159char *gone_cmd = NULL;		/* for -gone */
160#ifndef VIEWONLY
161#define VIEWONLY 0
162#endif
163int view_only = VIEWONLY;		/* clients can only watch. */
164char *allowed_input_view_only = NULL;
165char *allowed_input_normal = NULL;
166char *allowed_input_str = NULL;
167char *viewonly_passwd = NULL;	/* view only passwd. */
168char **passwd_list = NULL;	/* for -passwdfile */
169int begin_viewonly = -1;
170int inetd = 0;			/* spawned from inetd(8) */
171#ifndef TIGHTFILEXFER
172#define TIGHTFILEXFER 0
173#endif
174int tightfilexfer = TIGHTFILEXFER;
175int got_ultrafilexfer = 0;
176int first_conn_timeout = 0;	/* -timeout */
177int ping_interval = 0;		/* -ping */
178int flash_cmap = 0;		/* follow installed colormaps */
179int shift_cmap = 0;		/* ncells < 256 and needs shift of pixel values */
180int force_indexed_color = 0;	/* whether to force indexed color for 8bpp */
181int advertise_truecolor = 0;
182int advertise_truecolor_reset = 0;
183int cmap8to24 = 0;		/* -8to24 */
184int xform24to32 = 0;		/* -24to32 */
185char *cmap8to24_str = NULL;
186int launch_gui = 0;		/* -gui */
187
188#ifndef AVAHI
189#define AVAHI 0
190#endif
191int avahi = AVAHI;		/* -avahi, -mdns */
192int vnc_redirect = 0;
193int vnc_redirect_sock = -1;
194
195int use_modifier_tweak = 1;	/* use the shift/altgr modifier tweak */
196int watch_capslock = 0;		/* -capslock */
197int skip_lockkeys = 0;		/* -skip_lockkeys */
198int use_iso_level3 = 0;		/* ISO_Level3_Shift instead of Mode_switch */
199int clear_mods = 0;		/* -clear_mods (1) and -clear_keys (2) -clear_locks (3) */
200int nofb = 0;			/* do not send any fb updates */
201char *raw_fb_str = NULL;	/* used under -rawfb */
202char *raw_fb_pixfmt = NULL;
203char *raw_fb_full_str = NULL;
204char *freqtab = NULL;
205char *pipeinput_str = NULL;	/* -pipeinput [tee,reopen,keycodes:]cmd */
206char *pipeinput_opts = NULL;
207FILE *pipeinput_fh = NULL;
208int pipeinput_tee = 0;
209int pipeinput_int = 0;
210int pipeinput_cons_fd = -1;
211char *pipeinput_cons_dev = NULL;
212
213int macosx_nodimming = 0;	/* Some native MacOSX server settings. */
214int macosx_nosleep = 0;
215int macosx_noscreensaver = 0;
216int macosx_wait_for_switch = 1;
217int macosx_mouse_wheel_speed = 5;
218int macosx_console = 0;
219int macosx_swap23 = 1;
220int macosx_resize = 1;
221int macosx_icon_anim_time = 450;
222int macosx_no_opengl = 0;
223int macosx_no_rawfb = 0;
224int macosx_read_opengl = 0;
225int macosx_read_rawfb = 0;
226
227unsigned long subwin = 0x0;	/* -id, -sid */
228int subwin_wait_mapped = 0;
229int freeze_when_obscured = 0;
230int subwin_obscured = 0;
231
232int debug_xevents = 0;		/* -R debug_xevents:1 */
233int debug_xdamage = 0;		/* -R debug_xdamage:1 or 2 ... */
234int debug_wireframe = 0;
235int debug_tiles = 0;
236int debug_grabs = 0;
237int debug_sel = 0;
238
239int xtrap_input = 0;		/* -xtrap for user input insertion */
240int xinerama = XINERAMA;	/* -xinerama */
241int xrandr = 0;			/* -xrandr */
242int xrandr_maybe = 1;		/* check for events, but don't trap all calls */
243char *xrandr_mode = NULL;
244char *pad_geometry = NULL;
245time_t pad_geometry_time = 0;
246int use_snapfb = 0;
247
248int use_xrecord = 0;
249int noxrecord = 0;
250
251char *client_connect = NULL;	/* strings for -connect option */
252char *client_connect_file = NULL;
253int connect_or_exit = 0;
254int vnc_connect = 1;		/* -vncconnect option */
255char *connect_proxy = NULL;
256
257int show_cursor = 1;		/* show cursor shapes */
258int show_multiple_cursors = 0;	/* show X when on root background, etc */
259char *multiple_cursors_mode = NULL;
260#ifndef CURSOR_DRAG
261#define CURSOR_DRAG 0
262#endif
263int cursor_drag_changes = CURSOR_DRAG;
264int cursor_pos_updates = 1;	/* cursor position updates -cursorpos */
265int cursor_shape_updates = 1;	/* cursor shape updates -nocursorshape */
266int use_xwarppointer = 0;	/* use XWarpPointer instead of XTestFake... */
267int always_inject = 0;		/* inject new mouse coordinates even if dx=dy=0 */
268int show_dragging = 1;		/* process mouse movement events */
269#ifndef WIREFRAME
270#define WIREFRAME 1
271#endif
272int wireframe = WIREFRAME;	/* try to emulate wireframe wm moves */
273/* shade,linewidth,percent,T+B+L+R,t1+t2+t3+t4 */
274char *wireframe_str = NULL;
275char *wireframe_copyrect = NULL;
276#ifndef WIREFRAME_COPYRECT
277#define WIREFRAME_COPYRECT 1
278#endif
279#if WIREFRAME_COPYRECT
280char *wireframe_copyrect_default = "always";
281#else
282char *wireframe_copyrect_default = "never";
283#endif
284int wireframe_in_progress = 0;
285int wireframe_local = 1;
286
287#ifndef NCACHE
288#ifdef NO_NCACHE
289#define NCACHE 0
290#else
291#define xxNCACHE -12
292#define NCACHE -1
293#endif
294#endif
295
296#ifdef MACOSX
297int ncache = 0;
298int ncache_pad = 24;
299#else
300int ncache = NCACHE;
301int ncache_pad = 0;
302#endif
303
304#ifndef NCACHE_XROOTPMAP
305#define NCACHE_XROOTPMAP 1
306#endif
307int ncache_xrootpmap = NCACHE_XROOTPMAP;
308int ncache0 = 0;
309int ncache_default = 10;
310int ncache_copyrect = 0;
311int ncache_wf_raises = 1;
312int ncache_dt_change = 1;
313int ncache_keep_anims = 0;
314int ncache_old_wm = 0;
315int macosx_ncache_macmenu = 0;
316int macosx_us_kbd = 0;
317int ncache_beta_tester = 0;
318int ncdb = 0;
319
320Atom atom_NET_ACTIVE_WINDOW = None;
321Atom atom_NET_CURRENT_DESKTOP = None;
322Atom atom_NET_CLIENT_LIST_STACKING = None;
323Atom atom_XROOTPMAP_ID = None;
324double got_NET_ACTIVE_WINDOW = 0.0;
325double got_NET_CURRENT_DESKTOP = 0.0;
326double got_NET_CLIENT_LIST_STACKING = 0.0;
327double got_XROOTPMAP_ID = 0.0;
328
329/* T+B+L+R,tkey+presist_key,tmouse+persist_mouse */
330char *scroll_copyrect_str = NULL;
331#ifndef SCROLL_COPYRECT
332#define SCROLL_COPYRECT 1
333#endif
334char *scroll_copyrect = NULL;
335#if SCROLL_COPYRECT
336#if 1
337char *scroll_copyrect_default = "always";	/* -scrollcopyrect */
338#else
339char *scroll_copyrect_default = "keys";
340#endif
341#else
342char *scroll_copyrect_default = "never";
343#endif
344char *scroll_key_list_str = NULL;
345KeySym *scroll_key_list = NULL;
346
347#ifndef SCALING_COPYRECT
348#define SCALING_COPYRECT 1
349#endif
350int scaling_copyrect0 = SCALING_COPYRECT;
351int scaling_copyrect  = SCALING_COPYRECT;
352
353int scrollcopyrect_min_area = 60000;	/* minimum rectangle area */
354int debug_scroll = 0;
355double pointer_flush_delay = 0.0;
356double last_scroll_event = 0.0;
357int max_scroll_keyrate = 0;
358double max_keyrepeat_time = 0.0;
359char *max_keyrepeat_str = NULL;
360char *max_keyrepeat_str0 = "4-20";
361int max_keyrepeat_lo = 1, max_keyrepeat_hi = 40;
362
363char **scroll_good_all = NULL;
364char **scroll_good_key = NULL;
365char **scroll_good_mouse = NULL;
366char *scroll_good_str = NULL;
367char *scroll_good_str0 = "##Nomatch";
368/*	"##Firefox-bin," */
369/*	"##Gnome-terminal," */
370/*	"##XTerm", */
371
372char **scroll_skip_all = NULL;
373char **scroll_skip_key = NULL;
374char **scroll_skip_mouse = NULL;
375char *scroll_skip_str = NULL;
376char *scroll_skip_str0 = "##Soffice.bin,##StarOffice,##OpenOffice";
377/*	"##Konsole,"	 * no problems, known heuristics do not work */
378
379char **scroll_term = NULL;
380char *scroll_term_str = NULL;
381char *scroll_term_str0 = "term";
382
383char* screen_fixup_str = NULL;
384double screen_fixup_V = 0.0;
385double screen_fixup_C = 0.0;
386double screen_fixup_X = 0.0;
387double screen_fixup_8 = 0.0;
388
389#ifndef NOREPEAT
390#define NOREPEAT 1
391#endif
392int no_autorepeat = NOREPEAT;	/* turn off autorepeat with clients */
393int no_repeat_countdown = 2;
394int watch_bell = 1;		/* watch for the bell using XKEYBOARD */
395int sound_bell = 1;		/* actually send it */
396int xkbcompat = 0;		/* ignore XKEYBOARD extension */
397int use_xkb_modtweak = 0;	/* -xkb */
398#ifndef SKIPDUPS
399#define SKIPDUPS 0
400#endif
401int skip_duplicate_key_events = SKIPDUPS;
402char *skip_keycodes = NULL;
403int sloppy_keys = 0;
404#ifndef ADDKEYSYMS
405#define ADDKEYSYMS 1
406#endif
407int add_keysyms = ADDKEYSYMS;	/* automatically add keysyms to X server */
408
409char *remap_file = NULL;	/* -remap */
410char *pointer_remap = NULL;
411/* use the various ways of updating pointer */
412#ifndef POINTER_MODE_DEFAULT
413#define POINTER_MODE_DEFAULT 2
414#endif
415int pointer_mode = POINTER_MODE_DEFAULT;
416int pointer_mode_max = 4;
417int single_copytile = 0;	/* use the old way copy_tiles() */
418int single_copytile_orig = 0;
419int single_copytile_count = 0;
420int tile_shm_count = 0;
421
422int using_shm = 1;		/* whether mit-shm is used */
423int flip_byte_order = 0;	/* sometimes needed when using_shm = 0 */
424/*
425 * waitms is the msec to wait between screen polls.  Not too old h/w shows
426 * poll times of 10-35ms, so maybe this value cuts the idle load by 2 or so.
427 */
428int waitms = 20;
429int got_waitms = 0;
430double wait_ui = 2.0;
431double slow_fb = 0.0;
432double xrefresh = 0.0;
433int wait_bog = 1;
434int extra_fbur = 1;
435int defer_update = 20;	/* deferUpdateTime ms to wait before sends. */
436int set_defer = 1;
437int got_defer = 0;
438int got_deferupdate = 0;
439
440int screen_blank = 60;	/* number of seconds of no activity to throttle */
441			/* down the screen polls.  zero to disable. */
442int no_fbu_blank = 30;	/* nap if no client updates in this many secs. */
443int take_naps = 1;	/* -nap/-nonap */
444int naptile = 4;	/* tile change threshold per poll to take a nap */
445int napfac = 4;		/* time = napfac*waitms, cut load with extra waits */
446int napmax = 1500;	/* longest nap in ms. */
447int ui_skip = 10;	/* see watchloop.  negative means ignore input */
448int all_input = 0;
449int handle_events_eagerly = 0;
450
451
452#if LIBVNCSERVER_HAVE_FBPM
453int watch_fbpm = 1;	/* -nofbpm */
454#else
455int watch_fbpm = 0;
456#endif
457
458int watch_dpms = 0;	/* -dpms */
459int force_dpms = 0;
460int client_dpms = 0;
461int no_ultra_dpms = 0;
462int no_ultra_ext = 0;
463int saw_ultra_chat = 0;
464int saw_ultra_file = 0;
465int chat_window = 0;
466rfbClientPtr chat_window_client = NULL;
467
468int watch_selection = 1;	/* normal selection/cutbuffer maintenance */
469int watch_primary = 1;		/* more dicey, poll for changes in PRIMARY */
470int watch_clipboard = 1;
471char *sel_direction = NULL;	/* "send" or "recv" for one-way */
472
473char *sigpipe = NULL;		/* skip, ignore, exit */
474
475/* visual stuff for -visual override or -overlay */
476VisualID visual_id = (VisualID) 0;
477int visual_depth = 0;
478
479/* for -overlay mode on Solaris/IRIX.  X server draws cursor correctly.  */
480int overlay = 0;
481int overlay_cursor = 1;
482
483/* tile heuristics: */
484double fs_frac = 0.75;	/* threshold tile fraction to do fullscreen updates. */
485int tile_fuzz = 2;	/* tolerance for suspecting changed tiles touching */
486			/* a known changed tile. */
487int grow_fill = 3;	/* do the grow islands heuristic with this width. */
488int gaps_fill = 4;	/* do a final pass to try to fill gaps between tiles. */
489
490int debug_pointer = 0;
491int debug_keyboard = 0;
492
493int quiet = 0;
494int verbose = 0;
495
496/* threaded vs. non-threaded (default) */
497int use_threads = 0;
498int started_rfbRunEventLoop = 0;
499int threads_drop_input = 0;
500
501/* info about command line opts */
502int got_noxwarppointer = 0;
503int got_rfbport = 0;
504int got_rfbport_val = -1;
505int got_alwaysshared = 0;
506int got_nevershared = 0;
507int got_cursorpos = 0;
508int got_pointer_mode = -1;
509int got_noviewonly = 0;
510int got_wirecopyrect = 0;
511int got_scrollcopyrect = 0;
512int got_noxkb = 0;
513int got_nomodtweak = 0;
514
515