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