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_modifier_tweak = 1;	/* use the shift/altgr modifier tweak */
196 int watch_capslock = 0;		/* -capslock */
197 int skip_lockkeys = 0;		/* -skip_lockkeys */
198 int use_iso_level3 = 0;		/* ISO_Level3_Shift instead of Mode_switch */
199 int clear_mods = 0;		/* -clear_mods (1) and -clear_keys (2) -clear_locks (3) */
200 int nofb = 0;			/* do not send any fb updates */
201 char *raw_fb_str = NULL;	/* used under -rawfb */
202 char *raw_fb_pixfmt = NULL;
203 char *raw_fb_full_str = NULL;
204 char *freqtab = NULL;
205 char *pipeinput_str = NULL;	/* -pipeinput [tee,reopen,keycodes:]cmd */
206 char *pipeinput_opts = NULL;
207 FILE *pipeinput_fh = NULL;
208 int pipeinput_tee = 0;
209 int pipeinput_int = 0;
210 int pipeinput_cons_fd = -1;
211 char *pipeinput_cons_dev = NULL;
212 
213 int macosx_nodimming = 0;	/* Some native MacOSX server settings. */
214 int macosx_nosleep = 0;
215 int macosx_noscreensaver = 0;
216 int macosx_wait_for_switch = 1;
217 int macosx_mouse_wheel_speed = 5;
218 int macosx_console = 0;
219 int macosx_swap23 = 1;
220 int macosx_resize = 1;
221 int macosx_icon_anim_time = 450;
222 int macosx_no_opengl = 0;
223 int macosx_no_rawfb = 0;
224 int macosx_read_opengl = 0;
225 int macosx_read_rawfb = 0;
226 
227 unsigned long subwin = 0x0;	/* -id, -sid */
228 int subwin_wait_mapped = 0;
229 int freeze_when_obscured = 0;
230 int subwin_obscured = 0;
231 
232 int debug_xevents = 0;		/* -R debug_xevents:1 */
233 int debug_xdamage = 0;		/* -R debug_xdamage:1 or 2 ... */
234 int debug_wireframe = 0;
235 int debug_tiles = 0;
236 int debug_grabs = 0;
237 int debug_sel = 0;
238 
239 int xtrap_input = 0;		/* -xtrap for user input insertion */
240 int xinerama = XINERAMA;	/* -xinerama */
241 int xrandr = 0;			/* -xrandr */
242 int xrandr_maybe = 1;		/* check for events, but don't trap all calls */
243 char *xrandr_mode = NULL;
244 char *pad_geometry = NULL;
245 time_t pad_geometry_time = 0;
246 int use_snapfb = 0;
247 
248 int use_xrecord = 0;
249 int noxrecord = 0;
250 
251 char *client_connect = NULL;	/* strings for -connect option */
252 char *client_connect_file = NULL;
253 int connect_or_exit = 0;
254 int vnc_connect = 1;		/* -vncconnect option */
255 char *connect_proxy = NULL;
256 
257 int show_cursor = 1;		/* show cursor shapes */
258 int show_multiple_cursors = 0;	/* show X when on root background, etc */
259 char *multiple_cursors_mode = NULL;
260 #ifndef CURSOR_DRAG
261 #define CURSOR_DRAG 0
262 #endif
263 int cursor_drag_changes = CURSOR_DRAG;
264 int cursor_pos_updates = 1;	/* cursor position updates -cursorpos */
265 int cursor_shape_updates = 1;	/* cursor shape updates -nocursorshape */
266 int use_xwarppointer = 0;	/* use XWarpPointer instead of XTestFake... */
267 int always_inject = 0;		/* inject new mouse coordinates even if dx=dy=0 */
268 int show_dragging = 1;		/* process mouse movement events */
269 #ifndef WIREFRAME
270 #define WIREFRAME 1
271 #endif
272 int wireframe = WIREFRAME;	/* try to emulate wireframe wm moves */
273 /* shade,linewidth,percent,T+B+L+R,t1+t2+t3+t4 */
274 char *wireframe_str = NULL;
275 char *wireframe_copyrect = NULL;
276 #ifndef WIREFRAME_COPYRECT
277 #define WIREFRAME_COPYRECT 1
278 #endif
279 #if WIREFRAME_COPYRECT
280 char *wireframe_copyrect_default = "always";
281 #else
282 char *wireframe_copyrect_default = "never";
283 #endif
284 int wireframe_in_progress = 0;
285 int 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
297 int ncache = 0;
298 int ncache_pad = 24;
299 #else
300 int ncache = NCACHE;
301 int ncache_pad = 0;
302 #endif
303 
304 #ifndef NCACHE_XROOTPMAP
305 #define NCACHE_XROOTPMAP 1
306 #endif
307 int ncache_xrootpmap = NCACHE_XROOTPMAP;
308 int ncache0 = 0;
309 int ncache_default = 10;
310 int ncache_copyrect = 0;
311 int ncache_wf_raises = 1;
312 int ncache_dt_change = 1;
313 int ncache_keep_anims = 0;
314 int ncache_old_wm = 0;
315 int macosx_ncache_macmenu = 0;
316 int macosx_us_kbd = 0;
317 int ncache_beta_tester = 0;
318 int ncdb = 0;
319 
320 Atom atom_NET_ACTIVE_WINDOW = None;
321 Atom atom_NET_CURRENT_DESKTOP = None;
322 Atom atom_NET_CLIENT_LIST_STACKING = None;
323 Atom atom_XROOTPMAP_ID = None;
324 double got_NET_ACTIVE_WINDOW = 0.0;
325 double got_NET_CURRENT_DESKTOP = 0.0;
326 double got_NET_CLIENT_LIST_STACKING = 0.0;
327 double got_XROOTPMAP_ID = 0.0;
328 
329 /* T+B+L+R,tkey+presist_key,tmouse+persist_mouse */
330 char *scroll_copyrect_str = NULL;
331 #ifndef SCROLL_COPYRECT
332 #define SCROLL_COPYRECT 1
333 #endif
334 char *scroll_copyrect = NULL;
335 #if SCROLL_COPYRECT
336 #if 1
337 char *scroll_copyrect_default = "always";	/* -scrollcopyrect */
338 #else
339 char *scroll_copyrect_default = "keys";
340 #endif
341 #else
342 char *scroll_copyrect_default = "never";
343 #endif
344 char *scroll_key_list_str = NULL;
345 KeySym *scroll_key_list = NULL;
346 
347 #ifndef SCALING_COPYRECT
348 #define SCALING_COPYRECT 1
349 #endif
350 int scaling_copyrect0 = SCALING_COPYRECT;
351 int scaling_copyrect  = SCALING_COPYRECT;
352 
353 int scrollcopyrect_min_area = 60000;	/* minimum rectangle area */
354 int debug_scroll = 0;
355 double pointer_flush_delay = 0.0;
356 double last_scroll_event = 0.0;
357 int max_scroll_keyrate = 0;
358 double max_keyrepeat_time = 0.0;
359 char *max_keyrepeat_str = NULL;
360 char *max_keyrepeat_str0 = "4-20";
361 int max_keyrepeat_lo = 1, max_keyrepeat_hi = 40;
362 
363 char **scroll_good_all = NULL;
364 char **scroll_good_key = NULL;
365 char **scroll_good_mouse = NULL;
366 char *scroll_good_str = NULL;
367 char *scroll_good_str0 = "##Nomatch";
368 /*	"##Firefox-bin," */
369 /*	"##Gnome-terminal," */
370 /*	"##XTerm", */
371 
372 char **scroll_skip_all = NULL;
373 char **scroll_skip_key = NULL;
374 char **scroll_skip_mouse = NULL;
375 char *scroll_skip_str = NULL;
376 char *scroll_skip_str0 = "##Soffice.bin,##StarOffice,##OpenOffice";
377 /*	"##Konsole,"	 * no problems, known heuristics do not work */
378 
379 char **scroll_term = NULL;
380 char *scroll_term_str = NULL;
381 char *scroll_term_str0 = "term";
382 
383 char* screen_fixup_str = NULL;
384 double screen_fixup_V = 0.0;
385 double screen_fixup_C = 0.0;
386 double screen_fixup_X = 0.0;
387 double screen_fixup_8 = 0.0;
388 
389 #ifndef NOREPEAT
390 #define NOREPEAT 1
391 #endif
392 int no_autorepeat = NOREPEAT;	/* turn off autorepeat with clients */
393 int no_repeat_countdown = 2;
394 int watch_bell = 1;		/* watch for the bell using XKEYBOARD */
395 int sound_bell = 1;		/* actually send it */
396 int xkbcompat = 0;		/* ignore XKEYBOARD extension */
397 int use_xkb_modtweak = 0;	/* -xkb */
398 #ifndef SKIPDUPS
399 #define SKIPDUPS 0
400 #endif
401 int skip_duplicate_key_events = SKIPDUPS;
402 char *skip_keycodes = NULL;
403 int sloppy_keys = 0;
404 #ifndef ADDKEYSYMS
405 #define ADDKEYSYMS 1
406 #endif
407 int add_keysyms = ADDKEYSYMS;	/* automatically add keysyms to X server */
408 
409 char *remap_file = NULL;	/* -remap */
410 char *pointer_remap = NULL;
411 /* use the various ways of updating pointer */
412 #ifndef POINTER_MODE_DEFAULT
413 #define POINTER_MODE_DEFAULT 2
414 #endif
415 int pointer_mode = POINTER_MODE_DEFAULT;
416 int pointer_mode_max = 4;
417 int single_copytile = 0;	/* use the old way copy_tiles() */
418 int single_copytile_orig = 0;
419 int single_copytile_count = 0;
420 int tile_shm_count = 0;
421 
422 int using_shm = 1;		/* whether mit-shm is used */
423 int 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  */
428 int waitms = 20;
429 int got_waitms = 0;
430 double wait_ui = 2.0;
431 double slow_fb = 0.0;
432 double xrefresh = 0.0;
433 int wait_bog = 1;
434 int extra_fbur = 1;
435 int defer_update = 20;	/* deferUpdateTime ms to wait before sends. */
436 int set_defer = 1;
437 int got_defer = 0;
438 int got_deferupdate = 0;
439 
440 int screen_blank = 60;	/* number of seconds of no activity to throttle */
441 			/* down the screen polls.  zero to disable. */
442 int no_fbu_blank = 30;	/* nap if no client updates in this many secs. */
443 int take_naps = 1;	/* -nap/-nonap */
444 int naptile = 4;	/* tile change threshold per poll to take a nap */
445 int napfac = 4;		/* time = napfac*waitms, cut load with extra waits */
446 int napmax = 1500;	/* longest nap in ms. */
447 int ui_skip = 10;	/* see watchloop.  negative means ignore input */
448 int all_input = 0;
449 int handle_events_eagerly = 0;
450 
451 
452 #if LIBVNCSERVER_HAVE_FBPM
453 int watch_fbpm = 1;	/* -nofbpm */
454 #else
455 int watch_fbpm = 0;
456 #endif
457 
458 int watch_dpms = 0;	/* -dpms */
459 int force_dpms = 0;
460 int client_dpms = 0;
461 int no_ultra_dpms = 0;
462 int no_ultra_ext = 0;
463 int saw_ultra_chat = 0;
464 int saw_ultra_file = 0;
465 int chat_window = 0;
466 rfbClientPtr chat_window_client = NULL;
467 
468 int watch_selection = 1;	/* normal selection/cutbuffer maintenance */
469 int watch_primary = 1;		/* more dicey, poll for changes in PRIMARY */
470 int watch_clipboard = 1;
471 char *sel_direction = NULL;	/* "send" or "recv" for one-way */
472 
473 char *sigpipe = NULL;		/* skip, ignore, exit */
474 
475 /* visual stuff for -visual override or -overlay */
476 VisualID visual_id = (VisualID) 0;
477 int visual_depth = 0;
478 
479 /* for -overlay mode on Solaris/IRIX.  X server draws cursor correctly.  */
480 int overlay = 0;
481 int overlay_cursor = 1;
482 
483 /* tile heuristics: */
484 double fs_frac = 0.75;	/* threshold tile fraction to do fullscreen updates. */
485 int tile_fuzz = 2;	/* tolerance for suspecting changed tiles touching */
486 			/* a known changed tile. */
487 int grow_fill = 3;	/* do the grow islands heuristic with this width. */
488 int gaps_fill = 4;	/* do a final pass to try to fill gaps between tiles. */
489 
490 int debug_pointer = 0;
491 int debug_keyboard = 0;
492 
493 int quiet = 0;
494 int verbose = 0;
495 
496 /* threaded vs. non-threaded (default) */
497 int use_threads = 0;
498 int started_rfbRunEventLoop = 0;
499 int threads_drop_input = 0;
500 
501 /* info about command line opts */
502 int got_noxwarppointer = 0;
503 int got_rfbport = 0;
504 int got_rfbport_val = -1;
505 int got_alwaysshared = 0;
506 int got_nevershared = 0;
507 int got_cursorpos = 0;
508 int got_pointer_mode = -1;
509 int got_noviewonly = 0;
510 int got_wirecopyrect = 0;
511 int got_scrollcopyrect = 0;
512 int got_noxkb = 0;
513 int got_nomodtweak = 0;
514 
515