blob: 3e9e5f82ce026bc57ffb457e10752e92c87d9188 [file] [log] [blame]
San Mehata430b2b2014-09-23 08:30:51 -07001/*
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/* -- remote.c -- */
34
35#include "x11vnc.h"
36#include "inet.h"
37#include "xwrappers.h"
38#include "xevents.h"
39#include "xinerama.h"
40#include "xrandr.h"
41#include "xdamage.h"
42#include "xrecord.h"
43#include "xkb_bell.h"
44#include "win_utils.h"
45#include "screen.h"
46#include "cleanup.h"
47#include "gui.h"
48#include "solid.h"
49#include "user.h"
50#include "rates.h"
51#include "scan.h"
52#include "connections.h"
53#include "pointer.h"
54#include "cursor.h"
55#include "userinput.h"
56#include "keyboard.h"
57#include "selection.h"
58#include "unixpw.h"
59#include "uinput.h"
60#include "userinput.h"
61#include "avahi.h"
62#include "sslhelper.h"
63
64int send_remote_cmd(char *cmd, int query, int wait);
65int do_remote_query(char *remote_cmd, char *query_cmd, int remote_sync,
66 int qdefault);
67void check_black_fb(void);
68int check_httpdir(void);
69void http_connections(int on);
70int remote_control_access_ok(void);
71char *process_remote_cmd(char *cmd, int stringonly);
72
73
74static char *add_item(char *instr, char *item);
75static char *delete_item(char *instr, char *item);
76static void if_8bpp_do_new_fb(void);
77static void reset_httpport(int old, int newp);
78static void reset_rfbport(int old, int newp) ;
79
80char *query_result = NULL;
81
82/*
83 * for the wild-n-crazy -remote/-R interface.
84 */
85int send_remote_cmd(char *cmd, int query, int wait) {
86 FILE *in = NULL;
87
88 if (query_result != NULL) {
89 free(query_result);
90 query_result = NULL;
91 }
92
93 if (client_connect_file) {
94 umask(077);
95 in = fopen(client_connect_file, "w");
96 if (in == NULL) {
97 fprintf(stderr, "send_remote_cmd: could not open "
98 "connect file \"%s\" for writing\n",
99 client_connect_file);
100 perror("fopen");
101 return 1;
102 }
103 } else if (x11vnc_remote_prop == None) {
104 initialize_x11vnc_remote_prop();
105 if (x11vnc_remote_prop == None) {
106 fprintf(stderr, "send_remote_cmd: could not obtain "
107 "X11VNC_REMOTE X property\n");
108 return 1;
109 }
110 }
111
112 if (in != NULL) {
113 fprintf(stderr, ">>> sending remote command: \"%s\"\n via"
114 " connect file: %s\n", cmd, client_connect_file);
115 fprintf(in, "%s\n", cmd);
116 fclose(in);
117 } else {
118 fprintf(stderr, ">>> sending remote command: \"%s\" via"
119 " X11VNC_REMOTE X property.\n", cmd);
120 set_x11vnc_remote_prop(cmd);
121 if (dpy) {
122 XFlush_wr(dpy);
123 }
124 }
125
126 if (query || wait) {
127 char line[X11VNC_REMOTE_MAX];
128 int rc=1, i=0, max=140, ms_sl=25;
129
130 if (!strcmp(cmd, "cmd=stop")) {
131 max = 40;
132 }
133 if (strstr(cmd, "script:")) {
134 max = 400;
135 }
136 if (strstr(cmd, "bcx_xattach:")) {
137 max = 400;
138 }
139 if (getenv("X11VNC_SYNC_TIMEOUT")) {
140 max = (int) ((1000. * atof(getenv("X11VNC_SYNC_TIMEOUT")))/ms_sl);
141 }
142 for (i=0; i<max; i++) {
143 if (i==0) {
144 usleep(10 * 1000);
145 } else {
146 usleep(ms_sl * 1000);
147 }
148 if (client_connect_file) {
149 char *q;
150 in = fopen(client_connect_file, "r");
151 if (in == NULL) {
152 fprintf(stderr, "send_remote_cmd: could"
153 " not open connect file \"%s\" for"
154 " writing\n", client_connect_file);
155 perror("fopen");
156 return 1;
157 }
158 fgets(line, X11VNC_REMOTE_MAX, in);
159 fclose(in);
160 q = line;
161 while (*q != '\0') {
162 if (*q == '\n') *q = '\0';
163 q++;
164 }
165 } else {
166 read_x11vnc_remote_prop(1);
167 strncpy(line, x11vnc_remote_str,
168 X11VNC_REMOTE_MAX);
169 }
170 if (strcmp(cmd, line)) {
171 if (query || wait) {
172 query_result = strdup(line);
173 fprintf(stdout, "%s\n", line);
174 fflush(stdout);
175 }
176 rc = 0;
177 break;
178 }
179 }
180 if (rc) {
181 fprintf(stderr, "error: could not connect to "
182 "an x11vnc server at %s (rc=%d)\n",
183 client_connect_file ? client_connect_file
184 : DisplayString(dpy), rc);
185 }
186 return rc;
187 }
188 return 0;
189}
190
191int do_remote_query(char *remote_cmd, char *query_cmd, int remote_sync,
192 int qdefault) {
193 char *rcmd = NULL, *qcmd = NULL;
194 int rc = 1, direct = 0;
195
196 if (qdefault && !query_cmd) {
197 query_cmd = remote_cmd;
198 remote_cmd = NULL;
199 }
200 if (remote_cmd && strstr(remote_cmd, "DIRECT:") == remote_cmd) {
201 direct = 1;
202 remote_cmd += strlen("DIRECT:");
203 }
204 if (query_cmd && strstr(query_cmd, "DIRECT:") == query_cmd) {
205 direct = 1;
206 query_cmd += strlen("DIRECT:");
207 }
208
209 if (remote_cmd) {
210 rcmd = (char *) malloc(strlen(remote_cmd) + 5);
211 strcpy(rcmd, "cmd=");
212 strcat(rcmd, remote_cmd);
213 }
214 if (query_cmd) {
215 qcmd = (char *) malloc(strlen(query_cmd) + 5);
216 strcpy(qcmd, "qry=");
217 strcat(qcmd, query_cmd);
218 }
219 if (direct) {
220 char *res;
221 if (rcmd) {
222 res = process_remote_cmd(rcmd, 1);
223 fprintf(stdout, "%s\n", res);
224 }
225 if (qcmd) {
226 res = process_remote_cmd(qcmd, 1);
227 fprintf(stdout, "%s\n", res);
228 }
229 fflush(stdout);
230 return 0;
231 }
232 if (qdefault) {
233 char *res;
234 if (!qcmd) {
235 return 1;
236 }
237 res = process_remote_cmd(qcmd, 1);
238 fprintf(stdout, "%s\n", res);
239 fflush(stdout);
240 return 0;
241 }
242
243 if (rcmd && qcmd) {
244 rc = send_remote_cmd(rcmd, 0, 1);
245 if (rc) {
246 free(rcmd);
247 free(qcmd);
248 return(rc);
249 }
250 rc = send_remote_cmd(qcmd, 1, 1);
251 } else if (rcmd) {
252 rc = send_remote_cmd(rcmd, 0, remote_sync);
253 free(rcmd);
254 } else if (qcmd) {
255 rc = send_remote_cmd(qcmd, 1, 1);
256 free(qcmd);
257 }
258 return rc;
259}
260
261static char *add_item(char *instr, char *item) {
262 char *p, *str;
263 int len, saw_item = 0;
264
265 if (! instr || *instr == '\0') {
266 str = strdup(item);
267 return str;
268 }
269 len = strlen(instr) + 1 + strlen(item) + 1;
270 str = (char *) malloc(len);
271 str[0] = '\0';
272
273 /* n.b. instr will be modified; caller replaces with returned string */
274 p = strtok(instr, ",");
275 while (p) {
276 if (!strcmp(p, item)) {
277 if (saw_item) {
278 p = strtok(NULL, ",");
279 continue;
280 }
281 saw_item = 1;
282 } else if (*p == '\0') {
283 p = strtok(NULL, ",");
284 continue;
285 }
286 if (str[0]) {
287 strcat(str, ",");
288 }
289 strcat(str, p);
290 p = strtok(NULL, ",");
291 }
292 if (! saw_item) {
293 if (str[0]) {
294 strcat(str, ",");
295 }
296 strcat(str, item);
297 }
298 return str;
299}
300
301static char *delete_item(char *instr, char *item) {
302 char *p, *str;
303 int len;
304
305 if (! instr || *instr == '\0') {
306 str = strdup("");
307 return str;
308 }
309 len = strlen(instr) + 1;
310 str = (char *) malloc(len);
311 str[0] = '\0';
312
313 /* n.b. instr will be modified; caller replaces with returned string */
314 p = strtok(instr, ",");
315 while (p) {
316 if (!strcmp(p, item) || *p == '\0') {
317 p = strtok(NULL, ",");
318 continue;
319 }
320 if (str[0]) {
321 strcat(str, ",");
322 }
323 strcat(str, p);
324 p = strtok(NULL, ",");
325 }
326 return str;
327}
328
329static void if_8bpp_do_new_fb(void) {
330 if (bpp == 8) {
331 do_new_fb(0);
332 } else {
333 rfbLog(" bpp(%d) is not 8bpp, not resetting fb\n", bpp);
334 }
335}
336
337void check_black_fb(void) {
338 if (!screen) {
339 return;
340 }
341 if (new_fb_size_clients(screen) != client_count) {
342 rfbLog("trying to send a black fb for non-newfbsize"
343 " clients %d != %d\n", client_count,
344 new_fb_size_clients(screen));
345 push_black_screen(4);
346 }
347}
348
349int check_httpdir(void) {
350 if (http_dir && http_dir[0] != '\0') {
351 return 1;
352 } else {
353 char *prog = NULL, *httpdir, *q;
354 struct stat sbuf;
355 int len;
356
357 rfbLog("check_httpdir: trying to guess httpdir... %s\n", program_name);
358 if (program_name[0] == '/') {
359 prog = strdup(program_name);
360 } else {
361 char cwd[1024];
362 getcwd(cwd, 1024);
363 len = strlen(cwd) + 1 + strlen(program_name) + 1;
364 prog = (char *) malloc(len);
365 snprintf(prog, len, "%s/%s", cwd, program_name);
366 if (stat(prog, &sbuf) != 0) {
367 char *path = strdup(getenv("PATH"));
368 char *p, *base;
369 base = strrchr(program_name, '/');
370 if (base) {
371 base++;
372 } else {
373 base = program_name;
374 }
375
376 p = strtok(path, ":");
377 while(p) {
378 if (prog) {
379 free(prog);
380 prog = NULL;
381 }
382 len = strlen(p) + 1 + strlen(base) + 1;
383 prog = (char *) malloc(len);
384 snprintf(prog, len, "%s/%s", p, base);
385 if (stat(prog, &sbuf) == 0) {
386 break;
387 }
388 p = strtok(NULL, ":");
389 }
390 free(path);
391 }
392 }
393 /*
394 * /path/to/bin/x11vnc
395 * /path/to/bin/../share/x11vnc/classes
396 * 12345678901234567
397 * /path/to/bin/../share/x11vnc/classes/ssl
398 * 123456789012345678901
399 * 21
400 */
401 if ((q = strrchr(prog, '/')) == NULL) {
402 rfbLog("check_httpdir: bad program path: %s\n", prog);
403 free(prog);
404 rfbLog("check_httpdir: *HTTP disabled* Use -httpdir path\n");
405 return 0;
406 }
407
408 len = strlen(prog) + 21 + 1;
409 *q = '\0';
410 httpdir = (char *) malloc(len);
411 if (use_stunnel && http_ssl) {
412 snprintf(httpdir, len, "%s/../share/x11vnc/classes/ssl", prog);
413 } else if (!enc_str && (use_openssl || use_stunnel || http_ssl)) {
414 snprintf(httpdir, len, "%s/../share/x11vnc/classes/ssl", prog);
415 } else {
416 snprintf(httpdir, len, "%s/../share/x11vnc/classes", prog);
417 }
418 if (stat(httpdir, &sbuf) != 0) {
419 if (use_stunnel && http_ssl) {
420 snprintf(httpdir, len, "%s/../classes/ssl", prog);
421 } else if (!enc_str && (use_openssl || use_stunnel || http_ssl)) {
422 snprintf(httpdir, len, "%s/../classes/ssl", prog);
423 } else {
424 snprintf(httpdir, len, "%s/../classes", prog);
425 }
426 }
427 free(prog);
428
429 if (stat(httpdir, &sbuf) == 0) {
430 /* good enough for me */
431 rfbLog("check_httpdir: guessed directory:\n");
432 rfbLog(" %s\n", httpdir);
433 http_dir = httpdir;
434 return 1;
435 } else {
436 /* try some hardwires: */
437 int i;
438 char **use;
439 char *list[] = {
440 "/usr/local/share/x11vnc/classes",
441 "/usr/share/x11vnc/classes",
442 NULL
443 };
444 char *ssllist[] = {
445 "/usr/local/share/x11vnc/classes/ssl",
446 "/usr/share/x11vnc/classes/ssl",
447 NULL
448 };
449 if (use_stunnel && http_ssl) {
450 use = ssllist;
451 } else if (!enc_str && (use_openssl || use_stunnel || http_ssl)) {
452 use = ssllist;
453 } else {
454 use = list;
455 }
456 i = 0;
457 while (use[i] != NULL) {
458 if (stat(use[i], &sbuf) == 0) {
459 http_dir = strdup(use[i]);
460 return 1;
461 }
462 i++;
463 }
464
465 rfbLog("check_httpdir: bad guess:\n");
466 rfbLog(" %s\n", httpdir);
467 rfbLog("check_httpdir: *HTTP disabled* Use -httpdir path\n");
468 return 0;
469 }
470 }
471}
472
473static void rfb_http_init_sockets(void) {
474 in_addr_t iface;
475 if (!screen) {
476 return;
477 }
478 iface = screen->listenInterface;
479 if (getenv("X11VNC_HTTP_LISTEN_LOCALHOST")) {
480 rfbLog("http_connections: HTTP listen on localhost only. (not HTTPS)\n");
481 screen->listenInterface = htonl(INADDR_LOOPBACK);
482 }
483 rfbHttpInitSockets(screen);
484 if (noipv4 || getenv("IPV4_FAILS")) {
485 if (getenv("IPV4_FAILS")) {
486 rfbLog("TESTING: IPV4_FAILS for rfb_http_init_sockets()\n");
487 }
488 if (screen->httpListenSock > -1) {
489 close(screen->httpListenSock);
490 screen->httpListenSock = -1;
491 }
492 }
493 screen->listenInterface = iface;
494}
495
496void http_connections(int on) {
497 if (!screen) {
498 return;
499 }
500 if (on) {
501 rfbLog("http_connections: turning on http service.\n");
502
503 if (inetd && use_openssl) {
504 /*
505 * try to work around rapid fire https requests
506 * in inetd mode... ugh.
507 */
508 if (screen->httpPort == 0) {
509 int port = find_free_port(5800, 5850);
510 if (port) {
511 /* mutex */
512 screen->httpPort = port;
513 }
514 }
515 }
516 screen->httpInitDone = FALSE;
517 if (check_httpdir()) {
518 int fd6 = -1;
519 char *save = listen_str6;
520
521 screen->httpDir = http_dir;
522
523 rfb_http_init_sockets();
524
525 if (getenv("X11VNC_HTTP_LISTEN_LOCALHOST")) {
526 listen_str6 = "localhost";
527 }
528
529 if (screen->httpPort != 0 && screen->httpListenSock < 0) {
530 rfbLog("http_connections: failed to listen on http port: %d\n", screen->httpPort);
531 if (ipv6_listen) {
532 fd6 = listen6(screen->httpPort);
533 }
534 if (fd6 < 0) {
535 clean_up_exit(1);
536 }
537 rfbLog("http_connections: trying IPv6 only mode.\n");
538 }
539 if (ipv6_listen && screen->httpPort > 0) {
540 if (fd6 < 0) {
541 fd6 = listen6(screen->httpPort);
542 }
543 ipv6_http_fd = fd6;
544 if (ipv6_http_fd >= 0) {
545 rfbLog("http_connections: Listening %s on IPv6 port %d (socket %d)\n",
546 screen->httpListenSock < 0 ? "only" : "also",
547 screen->httpPort, ipv6_http_fd);
548 }
549 }
550 listen_str6 = save;
551 }
552 } else {
553 rfbLog("http_connections: turning off http service.\n");
554 if (screen->httpListenSock > -1) {
555 close(screen->httpListenSock);
556 screen->httpListenSock = -1;
557 }
558 screen->httpDir = NULL;
559 if (ipv6_http_fd >= 0) {
560 close(ipv6_http_fd);
561 ipv6_http_fd = -1;
562 }
563 }
564}
565
566static void reset_httpport(int old, int newp) {
567 int hp = newp;
568
569 if (! screen->httpDir) {
570 return;
571 } else if (inetd) {
572 rfbLog("reset_httpport: cannot set httpport: %d in inetd.\n", hp);
573 return;
574 } else if (!screen) {
575 rfbLog("reset_httpport: no screen.\n");
576 return;
577 } else if (hp < 0) {
578 rfbLog("reset_httpport: invalid httpport: %d\n", hp);
579 return;
580 } else if (hp == old) {
581 rfbLog("reset_httpport: unchanged httpport: %d\n", hp);
582 return;
583 }
584
585 if (screen->httpListenSock > -1) {
586 close(screen->httpListenSock);
587 screen->httpListenSock = -1;
588 }
589
590 screen->httpPort = hp;
591 screen->httpInitDone = FALSE;
592
593 rfbLog("reset_httpport: setting httpport %d -> %d.\n",
594 old == -1 ? hp : old, hp);
595
596 if (noipv4 || getenv("IPV4_FAILS")) {
597 if (getenv("IPV4_FAILS")) {
598 rfbLog("TESTING: IPV4_FAILS for reset_httpport()\n");
599 }
600 } else if (screen->httpPort == 0) {
601 ;
602 } else {
603 rfb_http_init_sockets();
604 }
605
606 if (screen->httpPort != 0 && screen->httpListenSock < 0) {
607 rfbLog("reset_httpport: failed to listen on http port: %d\n",
608 screen->httpPort);
609 }
610
611 if (ipv6_http_fd >= 0) {
612 close(ipv6_http_fd);
613 ipv6_http_fd = -1;
614 }
615 if (ipv6_listen && screen->httpPort > 0) {
616 ipv6_http_fd = listen6(screen->httpPort);
617 rfbLog("reset_httpport: ipv6_http_fd: %d port: %d\n",
618 ipv6_http_fd, screen->httpPort);
619 }
620}
621
622static void reset_rfbport(int old, int newp) {
623 int rp = newp;
624
625 if (inetd) {
626 rfbLog("reset_rfbport: cannot set rfbport: %d in inetd.\n", rp);
627 return;
628 } else if (!screen) {
629 rfbLog("reset_rfbport: no screen.\n");
630 return;
631 } else if (rp < 0) {
632 rfbLog("reset_rfbport: invalid rfbport: %d\n", rp);
633 return;
634 } else if (rp == old) {
635 rfbLog("reset_rfbport: unchanged rfbport: %d\n", rp);
636 return;
637 }
638
639 rfbLog("reset_rfbport: setting rfbport %d -> %d.\n", old == -1 ? rp : old, rp);
640
641 screen->port = rp;
642
643 if (use_openssl) {
644 openssl_port(1);
645 if (openssl_sock < 0 && openssl_sock6 < 0) {
646 rfbLog("reset_rfbport: warning could not listen on port: %d\n",
647 screen->port);
648 } else {
649 set_vnc_desktop_name();
650 }
651 if (https_port_num >= 0) {
652 https_port(1);
653 }
654 return;
655 }
656
657 if (screen->listenSock >= 0) {
658 FD_CLR(screen->listenSock, &(screen->allFds));
659 close(screen->listenSock);
660 screen->listenSock = -1;
661 }
662
663 if (noipv4 || getenv("IPV4_FAILS")) {
664 if (getenv("IPV4_FAILS")) {
665 rfbLog("TESTING: IPV4_FAILS for reset_rfbport()\n");
666 }
667 } else {
668 screen->listenSock = listen_tcp(screen->port, screen->listenInterface, 0);
669 if (screen->listenSock >= 0) {
670 if (screen->listenSock > screen->maxFd) {
671 screen->maxFd = screen->listenSock;
672 }
673 FD_SET(screen->listenSock, &(screen->allFds));
674 }
675 }
676
677 if (ipv6_listen_fd >= 0) {
678 close(ipv6_listen_fd);
679 ipv6_listen_fd = -1;
680 }
681 if (ipv6_listen && screen->port > 0) {
682 ipv6_listen_fd = listen6(screen->port);
683 rfbLog("reset_rfbport: ipv6_listen_fd: %d port: %d\n",
684 ipv6_listen_fd, screen->port);
685 }
686
687 if (screen->listenSock < 0 && ipv6_listen_fd < 0) {
688 rfbLog("reset_rfbport: warning could not listen on port: %d\n", screen->port);
689 } else {
690 set_vnc_desktop_name();
691 }
692}
693
694/*
695 * Do some sanity checking of the permissions on the XAUTHORITY and the
696 * -connect file. This is -privremote. What should be done is check
697 * for an empty host access list, currently we lazily do not bring in
698 * libXau yet.
699 */
700int remote_control_access_ok(void) {
701#if NO_X11
702 return 0;
703#else
704 struct stat sbuf;
705
706 if (client_connect_file) {
707 if (stat(client_connect_file, &sbuf) == 0) {
708 if (sbuf.st_mode & S_IWOTH) {
709 rfbLog("connect file is writable by others.\n");
710 rfbLog(" %s\n", client_connect_file);
711 return 0;
712 }
713 if (sbuf.st_mode & S_IWGRP) {
714 rfbLog("connect file is writable by group.\n");
715 rfbLog(" %s\n", client_connect_file);
716 return 0;
717 }
718 }
719 }
720
721 if (dpy) {
722 char tmp[1000];
723 char *home, *xauth;
724 char *dpy_str = DisplayString(dpy);
725 Display *dpy2;
726 XHostAddress *xha;
727 Bool enabled;
728 int n;
729
730 home = get_home_dir();
731 if (getenv("XAUTHORITY") != NULL) {
732 xauth = getenv("XAUTHORITY");
733 } else if (home) {
734 int len = 1000 - strlen("/.Xauthority") - 1;
735 strncpy(tmp, home, len);
736 strcat(tmp, "/.Xauthority");
737 xauth = tmp;
738 } else {
739 rfbLog("cannot determine default XAUTHORITY.\n");
740 return 0;
741 }
742 if (home) {
743 free(home);
744 }
745 if (stat(xauth, &sbuf) == 0) {
746 if (sbuf.st_mode & S_IWOTH) {
747 rfbLog("XAUTHORITY is writable by others!!\n");
748 rfbLog(" %s\n", xauth);
749 return 0;
750 }
751 if (sbuf.st_mode & S_IWGRP) {
752 rfbLog("XAUTHORITY is writable by group!!\n");
753 rfbLog(" %s\n", xauth);
754 return 0;
755 }
756 if (sbuf.st_mode & S_IROTH) {
757 rfbLog("XAUTHORITY is readable by others.\n");
758 rfbLog(" %s\n", xauth);
759 return 0;
760 }
761 if (sbuf.st_mode & S_IRGRP) {
762 rfbLog("XAUTHORITY is readable by group.\n");
763 rfbLog(" %s\n", xauth);
764 return 0;
765 }
766 }
767
768 X_LOCK;
769 xha = XListHosts(dpy, &n, &enabled);
770 X_UNLOCK;
771 if (! enabled) {
772 rfbLog("X access control is disabled, X clients can\n");
773 rfbLog(" connect from any host. Run 'xhost -'\n");
774 return 0;
775 }
776 if (xha) {
777 int i;
778 rfbLog("The following hosts can connect w/o X11 "
779 "auth:\n");
780 for (i=0; i<n; i++) {
781 if (xha[i].family == FamilyInternet) {
782 char *str = raw2host(xha[i].address,
783 xha[i].length);
784 char *ip = raw2ip(xha[i].address);
785 rfbLog(" %s/%s\n", str, ip);
786 free(str);
787 free(ip);
788 } else {
789 rfbLog(" unknown-%d\n", i+1);
790 }
791 }
792 XFree_wr(xha);
793 return 0;
794 }
795
796 if (getenv("XAUTHORITY")) {
797 xauth = strdup(getenv("XAUTHORITY"));
798 } else {
799 xauth = NULL;
800 }
801 set_env("XAUTHORITY", "/impossible/xauthfile");
802
803 fprintf(stderr, "\nChecking if display %s requires "
804 "XAUTHORITY\n", dpy_str);
805 fprintf(stderr, " -- (ignore any Xlib: errors that"
806 " follow) --\n");
807 dpy2 = XOpenDisplay_wr(dpy_str);
808 fflush(stderr);
809 fprintf(stderr, " -- (done checking) --\n\n");
810
811 if (xauth) {
812 set_env("XAUTHORITY", xauth);
813 free(xauth);
814 } else {
815 xauth = getenv("XAUTHORITY");
816 if (xauth) {
817 *(xauth-2) = '_'; /* yow */
818 }
819 }
820 if (dpy2) {
821 rfbLog("XAUTHORITY is not required on display.\n");
822 rfbLog(" %s\n", DisplayString(dpy));
823 XCloseDisplay_wr(dpy2);
824 dpy2 = NULL;
825 return 0;
826 }
827
828 }
829 return 1;
830#endif /* NO_X11 */
831}
832
833#ifdef MACOSX
834void macosxCG_keycode_inject(int down, int keycode);
835#endif
836
837int rc_npieces = 0;
838
839/*
840 * Huge, ugly switch to handle all remote commands and queries
841 * -remote/-R and -query/-Q.
842 */
843char *process_remote_cmd(char *cmd, int stringonly) {
844#if REMOTE_CONTROL
845 char *p = cmd;
846 char *co = "";
847 char buf[X11VNC_REMOTE_MAX];
848 int bufn = X11VNC_REMOTE_MAX;
849 int query = 0;
850 static char *prev_cursors_mode = NULL;
851
852 if (!query_default && !accept_remote_cmds) {
853 rfbLog("remote commands disabled: %s\n", cmd);
854 return NULL;
855 }
856 if (unixpw_in_progress) {
857 rfbLog("skip remote command: %s unixpw_in_progress.\n", cmd);
858 return NULL;
859 }
860
861 if (!query_default && priv_remote) {
862 if (! remote_control_access_ok()) {
863 rfbLog("** Disabling remote commands in -privremote "
864 "mode.\n");
865 accept_remote_cmds = 0;
866 return NULL;
867 }
868 }
869
870
871 strcpy(buf, "");
872 if (strstr(cmd, "cmd=") == cmd) {
873 p += strlen("cmd=");
874 if (strstr(p, "script:") == p) {
875 char *s, *q, **pieces, tmp[1024];
876 int k = 0, n = 0, dp = 1;
877
878 p += strlen("script:");
879
880 if (strstr(p, "file=") == p) {
881 FILE *f;
882 struct stat sbuf;
883
884 p += strlen("file=");
885
886 rfbLog("reading script from file '%s'\n", p);
887
888 if (stat(p, &sbuf) != 0) {
889 rfbLogPerror("stat");
890 return NULL;
891 }
892
893 f = fopen(p, "r");
894 if (f == NULL) {
895 rfbLogPerror("fopen");
896 return NULL;
897 }
898
899 p = (char *) calloc(sbuf.st_size + 1, 1);
900 dp = 0;
901 while (fgets(tmp, 1024, f) != NULL) {
902 char *c = strchr(tmp, '#');
903 if (c) *c = '\0';
904 if (strlen(p) + strlen(tmp) > (size_t) sbuf.st_size) {
905 break;
906 }
907 strcat(p, tmp);
908 }
909 fclose(f);
910 }
911
912 pieces = (char **) malloc(strlen(p) * sizeof(char *));
913 if (dp) {
914 s = strdup(p);
915 } else {
916 s = p;
917 }
918 q = strtok(s, ";");
919
920 while (q) {
921 char *t = lblanks(q);
922 if (strstr(t, "cmd=") != t && strstr(t, "qry=") != t) {
923 strcpy(tmp, "cmd=");
924 } else {
925 strcpy(tmp, "");
926 }
927 strncat(tmp, t, 1000);
928 pieces[n] = strdup(tmp);
929 n++;
930 q = strtok(NULL, ";");
931 }
932 free(s);
933
934 for (k=0; k < n; k++) {
935 char *c = pieces[k];
936 char *t = c + strlen(c) - 1; /* shortest is "cmd=" */
937 while (isspace((unsigned char) (*t))) {
938 *t = '\0';
939 if (t <= c) break;
940 t--;
941 }
942 if (k < n - 1) {
943 process_remote_cmd(c, 1);
944 } else {
945 process_remote_cmd(c, 0);
946 }
947 }
948 for (k=0; k<n; k++) {
949 free(pieces[k]);
950 }
951 free(pieces);
952 return NULL;
953 }
954 } else if (strstr(cmd, "qry=") == cmd) {
955 query = 1;
956 if (strchr(cmd, ',')) {
957 /* comma separated batch mode */
958 char *s, *q, *res, **pieces, tmp[1024];
959 int k = 0, n = 0;
960
961 pieces = (char **) malloc(strlen(cmd) * sizeof(char *));
962 s = strdup(cmd + strlen("qry="));
963 q = strtok(s, ",");
964
965 while (q) {
966 strcpy(tmp, "qry=");
967 strncat(tmp, q, 1000);
968 pieces[n] = strdup(tmp);
969 n++;
970 q = strtok(NULL, ",");
971 }
972 free(s);
973
974 rc_npieces = n;
975 strcpy(buf, "");
976 for (k=0; k < n; k++) {
977 res = process_remote_cmd(pieces[k], 1);
978 if (res && strlen(buf)+strlen(res)
979 >= X11VNC_REMOTE_MAX - 1) {
980 rfbLog("overflow in process_remote_cmd:"
981 " %s -- %s\n", buf, res);
982 free(res);
983 break;
984 }
985 if (res) {
986 strcat(buf, res);
987 free(res);
988 }
989 if (k < n - 1) {
990 strcat(buf, ",");
991 }
992 }
993 for (k=0; k<n; k++) {
994 free(pieces[k]);
995 }
996 free(pieces);
997 rc_npieces = 0;
998 goto qry;
999 }
1000 p += strlen("qry=");
1001 } else {
1002 rfbLog("ignoring malformed command: %s\n", cmd);
1003 goto done;
1004 }
1005
1006 /* allow var=val usage */
1007 if (!strchr(p, ':')) {
1008 char *q = strchr(p, '=');
1009 if (q) *q = ':';
1010 }
1011
1012 /* always call like: COLON_CHECK("foobar:") */
1013#define COLON_CHECK(str) \
1014 if (strstr(p, str) != p) { \
1015 co = ":"; \
1016 if (! query) { \
1017 goto done; \
1018 } \
1019 } else { \
1020 char *q = strchr(p, ':'); \
1021 if (query && q != NULL) { \
1022 *(q+1) = '\0'; \
1023 } \
1024 }
1025
1026#define NOTAPP \
1027 if (query) { \
1028 if (strchr(p, ':')) { \
1029 snprintf(buf, bufn, "ans=%sN/A", p); \
1030 } else { \
1031 snprintf(buf, bufn, "ans=%s:N/A", p); \
1032 } \
1033 goto qry; \
1034 }
1035
1036#define NOTAPPRO \
1037 if (query) { \
1038 if (strchr(p, ':')) { \
1039 snprintf(buf, bufn, "aro=%sN/A", p); \
1040 } else { \
1041 snprintf(buf, bufn, "aro=%s:N/A", p); \
1042 } \
1043 goto qry; \
1044 }
1045
1046/*
1047 * Maybe add: passwdfile logfile bg rfbauth passwd...
1048 */
1049 if (!strcmp(p, "")) { /* skip-cmd-list */
1050 NOTAPP
1051 rfbLog("remote_cmd: empty command.\n");
1052 goto done;
1053 }
1054 if (strstr(p, "CR:") == p) { /* skip-cmd-list */
1055 /* CR:WxH+X+Y,dx,dy */
1056 int w, h, x, y, dx, dy;
1057 NOTAPP
1058 if (sscanf(p+3, "%dx%d+%d+%d,%d,%d", &w, &h, &x, &y, &dx, &dy) == 6) {
1059 sraRegionPtr r;
1060 rfbLog("rfbDoCopyRect(screen, %d, %d, %d, %d, %d, %d)\n", x, y, x+w, y+h, dx, dy);
1061 r = sraRgnCreateRect(x, y, x+w, y+h);
1062 do_copyregion(r, dx, dy, 0);
1063 fb_push();
1064 sraRgnDestroy(r);
1065 rfbLog("did\n");
1066 } else {
1067 rfbLog("remote_cmd: bad CR string: %s\n", p);
1068 }
1069 goto done;
1070 }
1071 if (!strcmp(p, "stop") || !strcmp(p, "quit") ||
1072 !strcmp(p, "exit") || !strcmp(p, "shutdown")) {
1073 NOTAPP
1074 if (client_connect_file) {
1075 FILE *in = fopen(client_connect_file, "w");
1076 if (in) {
1077 fprintf(in, "cmd=noop\n");
1078 fclose(in);
1079 }
1080 }
1081 rfbLog("remote_cmd: setting shut_down flag\n");
1082 shut_down = 1;
1083 close_all_clients();
1084 goto done;
1085 }
1086 if (!strcmp(p, "ping")
1087 || strstr(p, "ping:") == p) { /* skip-cmd-list */
1088 query = 1;
1089 if (rfb_desktop_name) {
1090 snprintf(buf, bufn, "ans=%s:%s", p, rfb_desktop_name);
1091 } else {
1092 snprintf(buf, bufn, "ans=%s:%s", p, "unknown");
1093 }
1094 goto qry;
1095 goto done;
1096 }
1097 if (!strcmp(p, "resend_cutbuffer")) {
1098 NOTAPP
1099 resend_selection("cutbuffer");
1100 goto done;
1101 }
1102 if (!strcmp(p, "resend_clipboard")) {
1103 NOTAPP
1104 resend_selection("clipboard");
1105 goto done;
1106 }
1107 if (!strcmp(p, "resend_primary")) {
1108 NOTAPP
1109 resend_selection("primary");
1110 goto done;
1111 }
1112 if (!strcmp(p, "blacken") || !strcmp(p, "zero")) {
1113 NOTAPP
1114 push_black_screen(4);
1115 goto done;
1116 }
1117 if (!strcmp(p, "refresh")) {
1118 NOTAPP
1119 refresh_screen(1);
1120 goto done;
1121 }
1122 if (!strcmp(p, "reset")) {
1123 NOTAPP
1124 do_new_fb(1);
1125 goto done;
1126 }
1127 if (strstr(p, "zero:") == p) { /* skip-cmd-list */
1128 int x1, y1, x2, y2;
1129 NOTAPP
1130 p += strlen("zero:");
1131 if (sscanf(p, "%d,%d,%d,%d", &x1, &y1, &x2, &y2) == 4) {
1132 int mark = 1;
1133 rfbLog("zeroing rect: %s\n", p);
1134 if (x1 < 0 || x2 < 0) {
1135 x1 = nabs(x1);
1136 x2 = nabs(x2);
1137 mark = 0; /* hack for testing */
1138 }
1139
1140 zero_fb(x1, y1, x2, y2);
1141 if (mark) {
1142 mark_rect_as_modified(x1, y1, x2, y2, 0);
1143 }
1144 push_sleep(4);
1145 }
1146 goto done;
1147 }
1148 if (strstr(p, "damagefb:") == p) { /* skip-cmd-list */
1149 int delay;
1150 NOTAPP
1151 p += strlen("damagefb:");
1152 if (sscanf(p, "%d", &delay) == 1) {
1153 rfbLog("damaging client fb's for %d secs "
1154 "(by not marking rects.)\n", delay);
1155 damage_time = time(NULL);
1156 damage_delay = delay;
1157 }
1158 goto done;
1159 }
1160 if (strstr(p, "close") == p) {
1161 NOTAPP
1162 COLON_CHECK("close:")
1163 p += strlen("close:");
1164 close_clients(p);
1165 goto done;
1166 }
1167 if (strstr(p, "disconnect") == p) {
1168 NOTAPP
1169 COLON_CHECK("disconnect:")
1170 p += strlen("disconnect:");
1171 close_clients(p);
1172 goto done;
1173 }
1174 if (strstr(p, "id_cmd") == p) {
1175 NOTAPP
1176 COLON_CHECK("id_cmd:")
1177 p += strlen("id_cmd:");
1178 id_cmd(p);
1179 goto done;
1180 }
1181 if (strstr(p, "id") == p) {
1182 int ok = 0;
1183 Window twin;
1184 COLON_CHECK("id:")
1185 if (query) {
1186 snprintf(buf, bufn, "ans=%s%s0x%lx", p, co,
1187 rootshift ? 0 : subwin);
1188 goto qry;
1189 }
1190 p += strlen("id:");
1191 if (*p == '\0' || !strcmp("root", p)) { /* skip-cmd-list */
1192 /* back to root win */
1193 twin = 0x0;
1194 ok = 1;
1195 } else if (!strcmp("pick", p)) {
1196 twin = 0x0;
1197 if (safe_remote_only) {
1198 rfbLog("unsafe: '-id pick'\n");
1199 } else if (pick_windowid(&twin)) {
1200 ok = 1;
1201 }
1202 } else if (! scan_hexdec(p, &twin)) {
1203 rfbLog("-id: skipping incorrect hex/dec number:"
1204 " %s\n", p);
1205 } else {
1206 ok = 1;
1207 }
1208 if (ok) {
1209 X_LOCK;
1210 if (twin && ! valid_window(twin, NULL, 0)) {
1211 rfbLog("skipping invalid sub-window: 0x%lx\n", twin);
1212 X_UNLOCK;
1213 } else {
1214 subwin = twin;
1215 rootshift = 0;
1216 X_UNLOCK;
1217 check_black_fb();
1218 do_new_fb(1);
1219 }
1220 }
1221 goto done;
1222 }
1223 if (strstr(p, "sid") == p) {
1224 int ok = 0;
1225 Window twin;
1226 COLON_CHECK("sid:")
1227 if (query) {
1228 snprintf(buf, bufn, "ans=%s%s0x%lx", p, co,
1229 !rootshift ? 0 : subwin);
1230 goto qry;
1231 }
1232 p += strlen("sid:");
1233 if (*p == '\0' || !strcmp("root", p)) { /* skip-cmd-list */
1234 /* back to root win */
1235 twin = 0x0;
1236 ok = 1;
1237 } else if (!strcmp("pick", p)) {
1238 twin = 0x0;
1239 if (safe_remote_only) {
1240 rfbLog("unsafe: '-sid pick'\n");
1241 } else if (pick_windowid(&twin)) {
1242 ok = 1;
1243 }
1244 } else if (! scan_hexdec(p, &twin)) {
1245 rfbLog("-sid: skipping incorrect hex/dec number: %s\n", p);
1246 } else {
1247 ok = 1;
1248 }
1249 if (ok) {
1250 X_LOCK;
1251 if (twin && ! valid_window(twin, NULL, 0)) {
1252 rfbLog("skipping invalid sub-window: 0x%lx\n", twin);
1253 X_UNLOCK;
1254 } else {
1255 subwin = twin;
1256 rootshift = 1;
1257 X_UNLOCK;
1258 check_black_fb();
1259 do_new_fb(1);
1260 }
1261 }
1262 goto done;
1263 }
1264 if (strstr(p, "waitmapped") == p) {
1265 if (query) {
1266 snprintf(buf, bufn, "ans=%s:%d", p,
1267 subwin_wait_mapped);
1268 goto qry;
1269 }
1270 subwin_wait_mapped = 1;
1271 goto done;
1272 }
1273 if (strstr(p, "nowaitmapped") == p) {
1274 if (query) {
1275 snprintf(buf, bufn, "ans=%s:%d", p,
1276 !subwin_wait_mapped);
1277 goto qry;
1278 }
1279 subwin_wait_mapped = 0;
1280 goto done;
1281 }
1282 if (!strcmp(p, "clip") ||
1283 strstr(p, "clip:") == p) { /* skip-cmd-list */
1284 COLON_CHECK("clip:")
1285 if (query) {
1286 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1287 NONUL(clip_str));
1288 goto qry;
1289 }
1290 p += strlen("clip:");
1291 if (clip_str) {
1292 int w, h, x, y;
1293 free(clip_str);
1294 /* try to handle easy case where WxH is unchanged: */
1295 if (parse_geom(p, &w, &h, &x, &y, wdpy_x, wdpy_y)) {
1296 if (cdpy_x == w && cdpy_y == h) {
1297 if (x >= 0 && y >= 0) {
1298 if (x + w <= wdpy_x && y + h <= wdpy_y) {
1299 coff_x = x;
1300 coff_y = y;
1301 clip_str = strdup(p);
1302 goto done;
1303 }
1304 }
1305 }
1306 }
1307 }
1308 clip_str = strdup(p);
1309
1310 /* OK, this requires a new fb... */
1311 do_new_fb(1);
1312 goto done;
1313 }
1314 if (!strcmp(p, "flashcmap")) {
1315 if (query) {
1316 snprintf(buf, bufn, "ans=%s:%d", p, flash_cmap);
1317 goto qry;
1318 }
1319 rfbLog("remote_cmd: turning on flashcmap mode.\n");
1320 flash_cmap = 1;
1321 goto done;
1322 }
1323 if (!strcmp(p, "noflashcmap")) {
1324 if (query) {
1325 snprintf(buf, bufn, "ans=%s:%d", p, !flash_cmap);
1326 goto qry;
1327 }
1328 rfbLog("remote_cmd: turning off flashcmap mode.\n");
1329 flash_cmap = 0;
1330 goto done;
1331 }
1332 if (strstr(p, "shiftcmap") == p) {
1333 COLON_CHECK("shiftcmap:")
1334 if (query) {
1335 snprintf(buf, bufn, "ans=%s%s%d", p, co, shift_cmap);
1336 goto qry;
1337 }
1338 p += strlen("shiftcmap:");
1339 shift_cmap = atoi(p);
1340 rfbLog("remote_cmd: set -shiftcmap %d\n", shift_cmap);
1341 do_new_fb(1);
1342 goto done;
1343 }
1344 if (!strcmp(p, "truecolor")) {
1345 int orig = force_indexed_color;
1346 if (query) {
1347 snprintf(buf, bufn, "ans=%s:%d", p,
1348 !force_indexed_color);
1349 goto qry;
1350 }
1351 rfbLog("remote_cmd: turning off notruecolor mode.\n");
1352 force_indexed_color = 0;
1353 if (orig != force_indexed_color) {
1354 if_8bpp_do_new_fb();
1355 }
1356 goto done;
1357 }
1358 if (!strcmp(p, "notruecolor")) {
1359 int orig = force_indexed_color;
1360 if (query) {
1361 snprintf(buf, bufn, "ans=%s:%d", p,
1362 force_indexed_color);
1363 goto qry;
1364 }
1365 rfbLog("remote_cmd: turning on notruecolor mode.\n");
1366 force_indexed_color = 1;
1367 if (orig != force_indexed_color) {
1368 if_8bpp_do_new_fb();
1369 }
1370 goto done;
1371 }
1372 if (!strcmp(p, "overlay")) {
1373 if (query) {
1374 snprintf(buf, bufn, "ans=%s:%d", p, overlay);
1375 goto qry;
1376 }
1377 rfbLog("remote_cmd: turning on -overlay mode.\n");
1378 if (!overlay_present) {
1379 rfbLog("skipping: overlay extension not present.\n");
1380 } else if (overlay) {
1381 rfbLog("skipping: already in -overlay mode.\n");
1382 } else {
1383 int reset_mem = 0;
1384 /* here we go... */
1385 if (using_shm) {
1386 rfbLog("setting -noshm mode.\n");
1387 using_shm = 0;
1388 reset_mem = 1;
1389 }
1390 overlay = 1;
1391 do_new_fb(reset_mem);
1392 }
1393 goto done;
1394 }
1395 if (!strcmp(p, "nooverlay")) {
1396 int orig = overlay;
1397 if (query) {
1398 snprintf(buf, bufn, "ans=%s:%d", p, !overlay);
1399 goto qry;
1400 }
1401 rfbLog("remote_cmd: turning off overlay mode\n");
1402 overlay = 0;
1403 if (!overlay_present) {
1404 rfbLog("warning: overlay extension not present.\n");
1405 } else if (!orig) {
1406 rfbLog("skipping: already not in -overlay mode.\n");
1407 } else {
1408 /* here we go... */
1409 do_new_fb(0);
1410 }
1411 goto done;
1412 }
1413 if (!strcmp(p, "overlay_cursor") ||
1414 !strcmp(p, "overlay_yescursor") ||
1415 !strcmp(p, "nooverlay_nocursor")) {
1416 if (query) {
1417 snprintf(buf, bufn, "ans=%s:%d", p, overlay_cursor);
1418 goto qry;
1419 }
1420 rfbLog("remote_cmd: turning on overlay_cursor mode.\n");
1421 overlay_cursor = 1;
1422 if (!overlay_present) {
1423 rfbLog("warning: overlay extension not present.\n");
1424 } else if (!overlay) {
1425 rfbLog("warning: not in -overlay mode.\n");
1426 } else {
1427 rfbLog("You may want to run -R noshow_cursor or\n");
1428 rfbLog(" -R cursor:none to disable any extra "
1429 "cursors.\n");
1430 }
1431 goto done;
1432 }
1433 if (!strcmp(p, "nooverlay_cursor") ||
1434 !strcmp(p, "nooverlay_yescursor") ||
1435 !strcmp(p, "overlay_nocursor")) {
1436 if (query) {
1437 snprintf(buf, bufn, "ans=%s:%d", p, !overlay_cursor);
1438 goto qry;
1439 }
1440 rfbLog("remote_cmd: turning off overlay_cursor mode\n");
1441 overlay_cursor = 0;
1442 if (!overlay_present) {
1443 rfbLog("warning: overlay extension not present.\n");
1444 } else if (!overlay) {
1445 rfbLog("warning: not in -overlay mode.\n");
1446 } else {
1447 rfbLog("You may want to run -R show_cursor or\n");
1448 rfbLog(" -R cursor:... to re-enable any cursors.\n");
1449 }
1450 goto done;
1451 }
1452 if (!strcmp(p, "8to24")) {
1453 if (query) {
1454 snprintf(buf, bufn, "ans=%s:%d", p, cmap8to24);
1455 goto qry;
1456 }
1457 if (overlay) {
1458 rfbLog("disabling -overlay in -8to24 mode.\n");
1459 overlay = 0;
1460 }
1461 rfbLog("remote_cmd: turning on -8to24 mode.\n");
1462 cmap8to24 = 1;
1463 if (overlay) {
1464 rfbLog("disabling -overlay in -8to24 mode.\n");
1465 overlay = 0;
1466 }
1467 do_new_fb(0);
1468 goto done;
1469 }
1470 if (!strcmp(p, "no8to24")) {
1471 if (query) {
1472 snprintf(buf, bufn, "ans=%s:%d", p, !cmap8to24);
1473 goto qry;
1474 }
1475 rfbLog("remote_cmd: turning off -8to24 mode.\n");
1476 cmap8to24 = 0;
1477 do_new_fb(0);
1478 goto done;
1479 }
1480 if (strstr(p, "8to24_opts") == p) {
1481 COLON_CHECK("8to24_opts:")
1482 if (query) {
1483 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1484 NONUL(cmap8to24_str));
1485 goto qry;
1486 }
1487 p += strlen("8to24_opts:");
1488 if (cmap8to24_str) {
1489 free(cmap8to24_str);
1490 }
1491 cmap8to24_str = strdup(p);
1492 if (*p == '\0') {
1493 cmap8to24 = 0;
1494 } else {
1495 cmap8to24 = 1;
1496 }
1497 rfbLog("remote_cmd: set cmap8to24_str to: %s\n", cmap8to24_str);
1498 do_new_fb(0);
1499 goto done;
1500 }
1501 if (!strcmp(p, "24to32")) {
1502 if (query) {
1503 snprintf(buf, bufn, "ans=%s:%d", p, xform24to32);
1504 goto qry;
1505 }
1506 rfbLog("remote_cmd: turning on -24to32 mode.\n");
1507 xform24to32 = 1;
1508 do_new_fb(1);
1509 goto done;
1510 }
1511 if (!strcmp(p, "no24to32")) {
1512 if (query) {
1513 snprintf(buf, bufn, "ans=%s:%d", p, !xform24to32);
1514 goto qry;
1515 }
1516 rfbLog("remote_cmd: turning off -24to32 mode.\n");
1517 if (set_visual_str_to_something) {
1518 if (visual_str) {
1519 rfbLog("unsetting: %d %d/%d\n", visual_str,
1520 (int) visual_id, visual_depth);
1521 free(visual_str);
1522 }
1523 visual_str = NULL;
1524 visual_id = (VisualID) 0;
1525 visual_depth = 0;
1526 }
1527 xform24to32 = 0;
1528 do_new_fb(1);
1529 goto done;
1530 }
1531 if (strstr(p, "visual") == p) {
1532 COLON_CHECK("visual:")
1533 if (query) {
1534 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1535 NONUL(visual_str));
1536 goto qry;
1537 }
1538 p += strlen("visual:");
1539 if (visual_str) free(visual_str);
1540 visual_str = strdup(p);
1541
1542 /* OK, this requires a new fb... */
1543 do_new_fb(0);
1544 goto done;
1545 }
1546 if (!strcmp(p, "scale") ||
1547 strstr(p, "scale:") == p) { /* skip-cmd-list */
1548 COLON_CHECK("scale:")
1549 if (query) {
1550 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1551 NONUL(scale_str));
1552 goto qry;
1553 }
1554 p += strlen("scale:");
1555 if (scale_str) free(scale_str);
1556 scale_str = strdup(p);
1557
1558 /* OK, this requires a new fb... */
1559 check_black_fb();
1560 do_new_fb(0);
1561 goto done;
1562 }
1563 if (!strcmp(p, "scale_cursor") ||
1564 strstr(p, "scale_cursor:") == p) { /* skip-cmd-list */
1565 COLON_CHECK("scale_cursor:")
1566 if (query) {
1567 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1568 NONUL(scale_cursor_str));
1569 goto qry;
1570 }
1571 p += strlen("scale_cursor:");
1572 if (scale_cursor_str) free(scale_cursor_str);
1573 if (*p == '\0') {
1574 scale_cursor_str = NULL;
1575 } else {
1576 scale_cursor_str = strdup(p);
1577 }
1578 setup_cursors_and_push();
1579 goto done;
1580 }
1581 if (!strcmp(p, "viewonly")) {
1582 if (query) {
1583 snprintf(buf, bufn, "ans=%s:%d", p, view_only);
1584 goto qry;
1585 }
1586 rfbLog("remote_cmd: enable viewonly mode.\n");
1587 view_only = 1;
1588 goto done;
1589 }
1590 if (!strcmp(p, "noviewonly")) {
1591 if (query) {
1592 snprintf(buf, bufn, "ans=%s:%d", p, !view_only);
1593 goto qry;
1594 }
1595 rfbLog("remote_cmd: disable viewonly mode.\n");
1596 view_only = 0;
1597 if (raw_fb) set_raw_fb_params(0);
1598 goto done;
1599 }
1600 if (!strcmp(p, "shared")) {
1601 if (query) {
1602 snprintf(buf, bufn, "ans=%s:%d", p, shared); goto qry;
1603 }
1604 rfbLog("remote_cmd: enable sharing.\n");
1605 shared = 1;
1606 if (screen) {
1607 /* mutex */
1608 screen->alwaysShared = TRUE;
1609 screen->neverShared = FALSE;
1610 }
1611 goto done;
1612 }
1613 if (!strcmp(p, "noshared")) {
1614 if (query) {
1615 snprintf(buf, bufn, "ans=%s:%d", p, !shared); goto qry;
1616 }
1617 rfbLog("remote_cmd: disable sharing.\n");
1618 shared = 0;
1619 if (screen) {
1620 /* mutex */
1621 screen->alwaysShared = FALSE;
1622 screen->neverShared = TRUE;
1623 }
1624 goto done;
1625 }
1626 if (!strcmp(p, "forever")) {
1627 if (query) {
1628 snprintf(buf, bufn, "ans=%s:%d", p, 1-connect_once);
1629 goto qry;
1630 }
1631 rfbLog("remote_cmd: enable -forever mode.\n");
1632 connect_once = 0;
1633 goto done;
1634 }
1635 if (!strcmp(p, "noforever") || !strcmp(p, "once")) {
1636 if (query) {
1637 snprintf(buf, bufn, "ans=%s:%d", p, connect_once);
1638 goto qry;
1639 }
1640 rfbLog("remote_cmd: disable -forever mode.\n");
1641 connect_once = 1;
1642 goto done;
1643 }
1644 if (strstr(p, "timeout") == p) {
1645 int to;
1646 COLON_CHECK("timeout:")
1647 if (query) {
1648 snprintf(buf, bufn, "ans=%s%s%d", p, co,
1649 first_conn_timeout);
1650 goto qry;
1651 }
1652 p += strlen("timeout:");
1653 to = atoi(p);
1654 if (to > 0 ) {
1655 to = -to;
1656 }
1657 first_conn_timeout = to;
1658 rfbLog("remote_cmd: set -timeout to %d\n", -to);
1659 goto done;
1660 }
1661 if (!strcmp(p, "tightfilexfer")) {
1662 if (query) {
1663 snprintf(buf, bufn, "ans=%s:%d", p, tightfilexfer);
1664 goto qry;
1665 }
1666#ifdef LIBVNCSERVER_WITH_TIGHTVNC_FILETRANSFER
1667 if (! tightfilexfer) {
1668 rfbLog("remote_cmd: enabling -tightfilexfer for *NEW* clients.\n");
1669 tightfilexfer = 1;
1670 rfbLog("rfbRegisterTightVNCFileTransferExtension: 4\n");
1671 rfbRegisterTightVNCFileTransferExtension();
1672 }
1673#else
1674 rfbLog("remote_cmd: -tightfilexfer not supported in this binary.\n");
1675#endif
1676 goto done;
1677 }
1678 if (!strcmp(p, "notightfilexfer")) {
1679 if (query) {
1680 snprintf(buf, bufn, "ans=%s:%d", p, !tightfilexfer);
1681 goto qry;
1682 }
1683#ifdef LIBVNCSERVER_WITH_TIGHTVNC_FILETRANSFER
1684 if (tightfilexfer) {
1685 rfbLog("remote_cmd: disabling -tightfilexfer for *NEW* clients.\n");
1686 tightfilexfer = 0;
1687 rfbLog("rfbUnregisterTightVNCFileTransferExtension: 2\n");
1688 rfbUnregisterTightVNCFileTransferExtension();
1689 }
1690#else
1691 rfbLog("remote_cmd: -tightfilexfer not supported in this binary.\n");
1692#endif
1693 goto done;
1694 }
1695 if (!strcmp(p, "ultrafilexfer")) {
1696 if (query) {
1697 if (screen) {
1698 snprintf(buf, bufn, "ans=%s:%d", p, screen->permitFileTransfer == TRUE);
1699 } else {
1700 snprintf(buf, bufn, "ans=%s:%d", p, 0);
1701 }
1702 goto qry;
1703 }
1704 if (! screen->permitFileTransfer) {
1705 rfbLog("remote_cmd: enabling -ultrafilexfer for clients.\n");
1706 /* mutex */
1707 screen->permitFileTransfer = TRUE;
1708 }
1709 goto done;
1710 }
1711 if (!strcmp(p, "noultrafilexfer")) {
1712 if (query) {
1713 if (screen) {
1714 snprintf(buf, bufn, "ans=%s:%d", p, screen->permitFileTransfer == FALSE);
1715 } else {
1716 snprintf(buf, bufn, "ans=%s:%d", p, 1);
1717 }
1718 goto qry;
1719 }
1720 if (screen->permitFileTransfer) {
1721 rfbLog("remote_cmd: disabling -ultrafilexfer for clients.\n");
1722 /* mutex */
1723 screen->permitFileTransfer = FALSE;
1724 }
1725 goto done;
1726 }
1727 if (strstr(p, "rfbversion") == p) {
1728 int maj, min;
1729 COLON_CHECK("rfbversion:")
1730 if (query) {
1731 if (screen) {
1732 snprintf(buf, bufn, "ans=%s:%d.%d", p, screen->protocolMajorVersion, screen->protocolMinorVersion);
1733 } else {
1734 snprintf(buf, bufn, "ans=%s:%d.%d", p, 3, 8);
1735 }
1736 goto qry;
1737 }
1738 p += strlen("rfbversion:");
1739
1740 if (sscanf(p, "%d.%d", &maj, &min) == 2) {
1741 /* mutex */
1742 screen->protocolMajorVersion = maj;
1743 screen->protocolMinorVersion = min;
1744 rfbLog("remote_cmd: set rfbversion to: %d.%d\n", maj, min);
1745 } else {
1746 rfbLog("remote_cmd: invalid rfbversion: %s\n", p);
1747 }
1748 goto done;
1749 }
1750 if (!strcmp(p, "deny") || !strcmp(p, "lock")) {
1751 if (query) {
1752 snprintf(buf, bufn, "ans=%s:%d", p, deny_all);
1753 goto qry;
1754 }
1755 rfbLog("remote_cmd: denying new connections.\n");
1756 deny_all = 1;
1757 goto done;
1758 }
1759 if (!strcmp(p, "nodeny") || !strcmp(p, "unlock")) {
1760 if (query) {
1761 snprintf(buf, bufn, "ans=%s:%d", p, !deny_all);
1762 goto qry;
1763 }
1764 rfbLog("remote_cmd: allowing new connections.\n");
1765 deny_all = 0;
1766 goto done;
1767 }
1768 if (!strcmp(p, "avahi") || !strcmp(p, "mdns") || !strcmp(p, "zeroconf")) {
1769 if (query) {
1770 snprintf(buf, bufn, "ans=%s:%d", p, avahi);
1771 goto qry;
1772 }
1773 rfbLog("remote_cmd: enable -avahi mDNS mode.\n");
1774 if (!avahi) {
1775 avahi = 1;
1776 avahi_initialise();
1777 avahi_advertise(vnc_desktop_name, this_host(),
1778 screen->port);
1779 }
1780 goto done;
1781 }
1782 if (!strcmp(p, "noavahi") || !strcmp(p, "nomdns") || !strcmp(p, "nozeroconf")) {
1783 if (query) {
1784 snprintf(buf, bufn, "ans=%s:%d", p, !avahi);
1785 goto qry;
1786 }
1787 rfbLog("remote_cmd: disable -avahi mDNS mode.\n");
1788 if (avahi) {
1789 avahi = 0;
1790 avahi_reset();
1791 }
1792 goto done;
1793 }
1794 if (strstr(p, "connect") == p) {
1795 NOTAPP
1796 COLON_CHECK("connect:")
1797 p += strlen("connect:");
1798 /* this is a reverse connection */
1799 reverse_connect(p);
1800 goto done;
1801 }
1802 if (strstr(p, "proxy") == p) {
1803 COLON_CHECK("proxy:")
1804 if (query) {
1805 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1806 NONUL(connect_proxy));
1807 goto qry;
1808 }
1809 p += strlen("proxy:");
1810 if (connect_proxy) {
1811 free(connect_proxy);
1812 connect_proxy = NULL;
1813 }
1814 if (!strcmp(p, "") || !strcasecmp(p, "none")) { /* skip-cmd-list */
1815 rfbLog("remote_cmd: disabled -proxy\n");
1816 } else {
1817 connect_proxy = strdup(p);
1818 rfbLog("remote_cmd: set -proxy %s\n", connect_proxy);
1819 }
1820 goto done;
1821 }
1822 if (strstr(p, "allowonce") == p) {
1823 COLON_CHECK("allowonce:")
1824 if (query) {
1825 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1826 NONUL(allow_once));
1827 goto qry;
1828 }
1829 p += strlen("allowonce:");
1830 allow_once = strdup(p);
1831 rfbLog("remote_cmd: set allow_once %s\n", allow_once);
1832 goto done;
1833 }
1834 if (strstr(p, "allow") == p) {
1835 char *before, *old;
1836 COLON_CHECK("allow:")
1837 if (query) {
1838 snprintf(buf, bufn, "ans=%s%s%s", p, co,
1839 NONUL(allow_list));
1840 goto qry;
1841 }
1842
1843 if (unixpw) {
1844 rfbLog("remote_cmd: cannot change allow in -unixpw\n");
1845 goto done;
1846 }
1847 p += strlen("allow:");
1848 if (allow_list && strchr(allow_list, '/')) {
1849 rfbLog("remote_cmd: cannot use allow:host\n");
1850 rfbLog("in '-allow %s' mode.\n", allow_list);
1851 goto done;
1852 }
1853 if (allow_list) {
1854 before = strdup(allow_list);
1855 } else {
1856 before = strdup("");
1857 }
1858
1859 old = allow_list;
1860 if (*p == '+') {
1861 p++;
1862 allow_list = add_item(allow_list, p);
1863 } else if (*p == '-') {
1864 p++;
1865 allow_list = delete_item(allow_list, p);
1866 } else {
1867 allow_list = strdup(p);
1868 }
1869
1870 if (strcmp(before, allow_list)) {
1871 rfbLog("remote_cmd: modified allow_list:\n");
1872 rfbLog(" from: \"%s\"\n", before);
1873 rfbLog(" to: \"%s\"\n", allow_list);
1874 }
1875 if (old) free(old);
1876 free(before);
1877 goto done;
1878 }
1879 if (!strcmp(p, "noipv6")) {
1880 if (query) {
1881 snprintf(buf, bufn, "ans=%s:%d", p, noipv6);
1882 goto qry;
1883 }
1884 rfbLog("remote_cmd: enabling -noipv6 mode for future sockets.\n");
1885 noipv6 = 1;
1886 goto done;
1887 }
1888 if (!strcmp(p, "ipv6")) {
1889 if (query) {
1890 snprintf(buf, bufn, "ans=%s:%d", p, !noipv6);
1891 goto qry;
1892 }
1893 rfbLog("remote_cmd: disabling -noipv6 mode for future sockets.\n");
1894 noipv6 = 0;
1895 goto done;
1896 }
1897 if (!strcmp(p, "noipv4")) {
1898 if (query) {
1899 snprintf(buf, bufn, "ans=%s:%d", p, noipv4);
1900 goto qry;
1901 }
1902 rfbLog("remote_cmd: enabling -noipv4 mode for future sockets.\n");
1903 noipv4 = 1;
1904 goto done;
1905 }
1906 if (!strcmp(p, "ipv4")) {
1907 if (query) {
1908 snprintf(buf, bufn, "ans=%s:%d", p, !noipv4);
1909 goto qry;
1910 }
1911 rfbLog("remote_cmd: disabling -noipv4 mode for future sockets.\n");
1912 noipv4 = 0;
1913 goto done;
1914 }
1915 if (!strcmp(p, "no6")) {
1916 if (query) {
1917 snprintf(buf, bufn, "ans=%s:%d", p, !ipv6_listen);
1918 goto qry;
1919 }
1920 if (ipv6_listen) {
1921 ipv6_listen = 0;
1922 rfbLog("disabling -6 IPv6 listening mode.\n");
1923 reset_rfbport(-1, screen->port);
1924 reset_httpport(-1, screen->httpPort);
1925 if (https_port_num > 0) {
1926 https_port(1);
1927 }
1928 }
1929 goto done;
1930 }
1931 if (!strcmp(p, "6")) {
1932 if (query) {
1933 snprintf(buf, bufn, "ans=%s:%d", p, ipv6_listen);
1934 goto qry;
1935 }
1936 if (!ipv6_listen) {
1937 ipv6_listen = 1;
1938 rfbLog("enabling -6 IPv6 listening mode.\n");
1939 reset_rfbport(-1, screen->port);
1940 reset_httpport(-1, screen->httpPort);
1941 if (https_port_num > 0) {
1942 https_port(1);
1943 }
1944 }
1945 goto done;
1946 }
1947 if (!strcmp(p, "localhost")) {
1948 char *before, *old;
1949 if (query) {
1950 int state = 0;
1951 char *s = allow_list;
1952 if (s && (!strcmp(s, "127.0.0.1") ||
1953 !strcmp(s, "localhost"))) {
1954 state = 1;
1955 }
1956 snprintf(buf, bufn, "ans=%s:%d", p, state);
1957 goto qry;
1958 }
1959 if (allow_list) {
1960 before = strdup(allow_list);
1961 } else {
1962 before = strdup("");
1963 }
1964 old = allow_list;
1965
1966 allow_list = strdup("127.0.0.1");
1967
1968 if (strcmp(before, allow_list)) {
1969 rfbLog("remote_cmd: modified allow_list:\n");
1970 rfbLog(" from: \"%s\"\n", before);
1971 rfbLog(" to: \"%s\"\n", allow_list);
1972 }
1973 if (old) free(old);
1974 free(before);
1975
1976 if (listen_str) {
1977 free(listen_str);
1978 }
1979 listen_str = strdup("localhost");
1980
1981 /* mutex */
1982 screen->listenInterface = htonl(INADDR_LOOPBACK);
1983 rfbLog("listening on loopback network only.\n");
1984 rfbLog("allow list is: '%s'\n", NONUL(allow_list));
1985 reset_rfbport(-1, screen->port);
1986 reset_httpport(-1, screen->httpPort);
1987 goto done;
1988 }
1989 if (!strcmp(p, "nolocalhost")) {
1990 char *before, *old;
1991 if (query) {
1992 int state = 0;
1993 char *s = allow_list;
1994 if (s && (!strcmp(s, "127.0.0.1") ||
1995 !strcmp(s, "localhost"))) {
1996 state = 1;
1997 }
1998 snprintf(buf, bufn, "ans=%s:%d", p, !state);
1999 goto qry;
2000 }
2001 if (unixpw) {
2002 rfbLog("remote_cmd: cannot change localhost in -unixpw\n");
2003 goto done;
2004 }
2005 if (allow_list) {
2006 before = strdup(allow_list);
2007 } else {
2008 before = strdup("");
2009 }
2010 old = allow_list;
2011
2012 allow_list = strdup("");
2013
2014 if (strcmp(before, allow_list)) {
2015 rfbLog("remote_cmd: modified allow_list:\n");
2016 rfbLog(" from: \"%s\"\n", before);
2017 rfbLog(" to: \"%s\"\n", allow_list);
2018 }
2019 if (old) free(old);
2020 free(before);
2021
2022 if (listen_str) {
2023 free(listen_str);
2024 }
2025 listen_str = NULL;
2026
2027 /* mutex */
2028 screen->listenInterface = htonl(INADDR_ANY);
2029 rfbLog("listening on ALL network interfaces.\n");
2030 rfbLog("allow list is: '%s'\n", NONUL(allow_list));
2031 reset_rfbport(-1, screen->port);
2032 reset_httpport(-1, screen->httpPort);
2033 goto done;
2034 }
2035 if (strstr(p, "listen") == p) {
2036 char *before;
2037 int ok, mod = 0;
2038
2039 COLON_CHECK("listen:")
2040 if (query) {
2041 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2042 NONUL(listen_str));
2043 goto qry;
2044 }
2045 if (unixpw) {
2046 rfbLog("remote_cmd: cannot change listen in -unixpw\n");
2047 goto done;
2048 }
2049 if (listen_str) {
2050 before = strdup(listen_str);
2051 } else {
2052 before = strdup("");
2053 }
2054 p += strlen("listen:");
2055
2056 listen_str = strdup(p);
2057
2058 if (strcmp(before, listen_str)) {
2059 rfbLog("remote_cmd: modified listen_str:\n");
2060 rfbLog(" from: \"%s\"\n", before);
2061 rfbLog(" to: \"%s\"\n", listen_str);
2062 mod = 1;
2063 }
2064
2065 ok = 1;
2066 /* mutex */
2067 if (listen_str == NULL || *listen_str == '\0' ||
2068 !strcmp(listen_str, "any")) {
2069 screen->listenInterface = htonl(INADDR_ANY);
2070 } else if (!strcmp(listen_str, "localhost")) {
2071 screen->listenInterface = htonl(INADDR_LOOPBACK);
2072 } else {
2073 struct hostent *hp;
2074 in_addr_t iface = inet_addr(listen_str);
2075 if (iface == htonl(INADDR_NONE)) {
2076 if (!host_lookup) {
2077 ok = 0;
2078 } else if (!(hp = gethostbyname(listen_str))) {
2079 ok = 0;
2080 } else {
2081 iface = *(unsigned long *)hp->h_addr;
2082 }
2083 }
2084 if (ok) {
2085 screen->listenInterface = iface;
2086 }
2087 }
2088
2089 if (ok && mod) {
2090 int is_loopback = 0;
2091 in_addr_t iface = screen->listenInterface;
2092
2093 if (allow_list) {
2094 if (!strcmp(allow_list, "127.0.0.1") ||
2095 !strcmp(allow_list, "localhost")) {
2096 is_loopback = 1;
2097 }
2098 }
2099 if (iface != htonl(INADDR_LOOPBACK)) {
2100 if (is_loopback) {
2101 rfbLog("re-setting -allow list to all "
2102 "hosts for non-loopback listening.\n");
2103 if (allow_list) {
2104 free(allow_list);
2105 }
2106 allow_list = NULL;
2107 }
2108 } else {
2109 if (!is_loopback) {
2110 if (allow_list) {
2111 free(allow_list);
2112 }
2113 rfbLog("setting -allow list to 127.0.0.1\n");
2114 allow_list = strdup("127.0.0.1");
2115 }
2116 }
2117 }
2118 if (ok) {
2119 rfbLog("allow list is: '%s'\n", NONUL(allow_list));
2120 reset_rfbport(-1, screen->port);
2121 reset_httpport(-1, screen->httpPort);
2122 free(before);
2123 } else {
2124 rfbLog("invalid listen string: %s\n", listen_str);
2125 free(listen_str);
2126 listen_str = before;
2127 }
2128 goto done;
2129 }
2130 if (!strcmp(p, "lookup")) {
2131 if (query) {
2132 snprintf(buf, bufn, "ans=%s:%d", p, host_lookup);
2133 goto qry;
2134 }
2135 rfbLog("remote_cmd: enabling hostname lookup.\n");
2136 host_lookup = 1;
2137 goto done;
2138 }
2139 if (!strcmp(p, "nolookup")) {
2140 if (query) {
2141 snprintf(buf, bufn, "ans=%s:%d", p, !host_lookup);
2142 goto qry;
2143 }
2144 rfbLog("remote_cmd: disabling hostname lookup.\n");
2145 host_lookup = 0;
2146 goto done;
2147 }
2148 if (strstr(p, "accept") == p) {
2149 int doit = 1, safe = 0;
2150 COLON_CHECK("accept:")
2151 if (query) {
2152 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2153 NONUL(accept_cmd));
2154 goto qry;
2155 }
2156 p += strlen("accept:");
2157 if (!strcmp(p, "") || strstr(p, "popup") == p) { /* skip-cmd-list */
2158 safe = 1;
2159 }
2160 if (safe_remote_only && ! safe) {
2161 rfbLog("unsafe: %s\n", p);
2162 doit = 0;
2163 }
2164
2165 if (doit) {
2166 if (accept_cmd) free(accept_cmd);
2167 accept_cmd = strdup(p);
2168 }
2169 goto done;
2170 }
2171 if (strstr(p, "afteraccept") == p) {
2172 int safe = 0;
2173 COLON_CHECK("afteraccept:")
2174 if (query) {
2175 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2176 NONUL(afteraccept_cmd));
2177 goto qry;
2178 }
2179 p += strlen("afteraccept:");
2180 if (!strcmp(p, "")) { /* skip-cmd-list */
2181 safe = 1;
2182 }
2183 if (safe_remote_only && ! safe) {
2184 rfbLog("unsafe: %s\n", p);
2185 } else {
2186 if (afteraccept_cmd) free(afteraccept_cmd);
2187 afteraccept_cmd = strdup(p);
2188 }
2189 goto done;
2190 }
2191 if (strstr(p, "gone") == p) {
2192 int safe = 0;
2193 COLON_CHECK("gone:")
2194 if (query) {
2195 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2196 NONUL(gone_cmd));
2197 goto qry;
2198 }
2199 p += strlen("gone:");
2200 if (!strcmp(p, "") || strstr(p, "popup") == p) { /* skip-cmd-list */
2201 safe = 1;
2202 }
2203 if (safe_remote_only && ! safe) {
2204 rfbLog("unsafe: %s\n", p);
2205 } else {
2206 if (gone_cmd) free(gone_cmd);
2207 gone_cmd = strdup(p);
2208 }
2209 goto done;
2210 }
2211 if (!strcmp(p, "shm")) {
2212 int orig = using_shm;
2213 if (query) {
2214 snprintf(buf, bufn, "ans=%s:%d", p, using_shm);
2215 goto qry;
2216 }
2217 rfbLog("remote_cmd: turning off noshm mode.\n");
2218 using_shm = 1;
2219 if (raw_fb) set_raw_fb_params(0);
2220
2221 if (orig != using_shm) {
2222 do_new_fb(1);
2223 } else {
2224 rfbLog(" already in shm mode.\n");
2225 }
2226 goto done;
2227 }
2228 if (!strcmp(p, "noshm")) {
2229 int orig = using_shm;
2230 if (query) {
2231 snprintf(buf, bufn, "ans=%s:%d", p, !using_shm);
2232 goto qry;
2233 }
2234 rfbLog("remote_cmd: turning on noshm mode.\n");
2235 using_shm = 0;
2236 if (orig != using_shm) {
2237 do_new_fb(1);
2238 } else {
2239 rfbLog(" already in noshm mode.\n");
2240 }
2241 goto done;
2242 }
2243 if (!strcmp(p, "flipbyteorder")) {
2244 int orig = flip_byte_order;
2245 if (query) {
2246 snprintf(buf, bufn, "ans=%s:%d", p, flip_byte_order);
2247 goto qry;
2248 }
2249 rfbLog("remote_cmd: turning on flipbyteorder mode.\n");
2250 flip_byte_order = 1;
2251 if (orig != flip_byte_order) {
2252 if (! using_shm || xform24to32) {
2253 do_new_fb(1);
2254 } else {
2255 rfbLog(" using shm, not resetting fb\n");
2256 }
2257 }
2258 goto done;
2259 }
2260 if (!strcmp(p, "noflipbyteorder")) {
2261 int orig = flip_byte_order;
2262 if (query) {
2263 snprintf(buf, bufn, "ans=%s:%d", p, !flip_byte_order);
2264 goto qry;
2265 }
2266 rfbLog("remote_cmd: turning off flipbyteorder mode.\n");
2267 flip_byte_order = 0;
2268 if (orig != flip_byte_order) {
2269 if (! using_shm || xform24to32) {
2270 do_new_fb(1);
2271 } else {
2272 rfbLog(" using shm, not resetting fb\n");
2273 }
2274 }
2275 goto done;
2276 }
2277 if (!strcmp(p, "onetile")) {
2278 if (query) {
2279 snprintf(buf, bufn, "ans=%s:%d", p, single_copytile);
2280 goto qry;
2281 }
2282 rfbLog("remote_cmd: enable -onetile mode.\n");
2283 single_copytile = 1;
2284 goto done;
2285 }
2286 if (!strcmp(p, "noonetile")) {
2287 if (query) {
2288 snprintf(buf, bufn, "ans=%s:%d", p, !single_copytile);
2289 goto qry;
2290 }
2291 rfbLog("remote_cmd: disable -onetile mode.\n");
2292 if (tile_shm_count < ntiles_x) {
2293 rfbLog(" this has no effect: tile_shm_count=%d"
2294 " ntiles_x=%d\n", tile_shm_count, ntiles_x);
2295
2296 }
2297 single_copytile = 0;
2298 goto done;
2299 }
2300 if (strstr(p, "solid_color") == p) {
2301 /*
2302 * n.b. this solid stuff perhaps should reflect
2303 * safe_remote_only but at least the command names
2304 * are fixed.
2305 */
2306 char *newc;
2307 int doit = 1;
2308 COLON_CHECK("solid_color:")
2309 if (query) {
2310 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2311 NONUL(solid_str));
2312 goto qry;
2313 }
2314 p += strlen("solid_color:");
2315 if (*p != '\0') {
2316 newc = strdup(p);
2317 } else {
2318 newc = strdup(solid_default);
2319 }
2320 rfbLog("remote_cmd: solid %s -> %s\n", NONUL(solid_str), newc);
2321
2322 if (solid_str) {
2323 if (!strcmp(solid_str, newc)) {
2324 doit = 0;
2325 }
2326 free(solid_str);
2327 }
2328 solid_str = newc;
2329 use_solid_bg = 1;
2330 if (raw_fb && !macosx_console) set_raw_fb_params(0);
2331
2332 if (doit && client_count) {
2333 solid_bg(0);
2334 }
2335 goto done;
2336 }
2337 if (!strcmp(p, "solid")) {
2338 int orig = use_solid_bg;
2339 if (query) {
2340 snprintf(buf, bufn, "ans=%s:%d", p, use_solid_bg);
2341 goto qry;
2342 }
2343 rfbLog("remote_cmd: enable -solid mode\n");
2344 if (! solid_str) {
2345 solid_str = strdup(solid_default);
2346 }
2347 use_solid_bg = 1;
2348 if (raw_fb && !macosx_console) set_raw_fb_params(0);
2349 if (client_count && !orig) {
2350 solid_bg(0);
2351 }
2352 goto done;
2353 }
2354 if (!strcmp(p, "nosolid")) {
2355 int orig = use_solid_bg;
2356 if (query) {
2357 snprintf(buf, bufn, "ans=%s:%d", p, !use_solid_bg);
2358 goto qry;
2359 }
2360 rfbLog("remote_cmd: disable -solid mode\n");
2361 use_solid_bg = 0;
2362 if (client_count && orig) {
2363 solid_bg(1);
2364 }
2365 goto done;
2366 }
2367 if (strstr(p, "blackout") == p) {
2368 char *before, *old;
2369 COLON_CHECK("blackout:")
2370 if (query) {
2371 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2372 NONUL(blackout_str));
2373 goto qry;
2374 }
2375 p += strlen("blackout:");
2376 if (blackout_str) {
2377 before = strdup(blackout_str);
2378 } else {
2379 before = strdup("");
2380 }
2381 old = blackout_str;
2382 if (*p == '+') {
2383 p++;
2384 blackout_str = add_item(blackout_str, p);
2385 } else if (*p == '-') {
2386 p++;
2387 blackout_str = delete_item(blackout_str, p);
2388 } else {
2389 blackout_str = strdup(p);
2390 }
2391 if (strcmp(before, blackout_str)) {
2392 rfbLog("remote_cmd: changing -blackout\n");
2393 rfbLog(" from: %s\n", before);
2394 rfbLog(" to: %s\n", blackout_str);
2395 if (0 && !strcmp(blackout_str, "") &&
2396 single_copytile_orig != single_copytile) {
2397 rfbLog("resetting single_copytile to: %d\n",
2398 single_copytile_orig);
2399 single_copytile = single_copytile_orig;
2400 }
2401 initialize_blackouts_and_xinerama();
2402 }
2403 if (old) free(old);
2404 free(before);
2405 goto done;
2406 }
2407 if (!strcmp(p, "xinerama")) {
2408 if (query) {
2409 snprintf(buf, bufn, "ans=%s:%d", p, xinerama);
2410 goto qry;
2411 }
2412 rfbLog("remote_cmd: enable xinerama mode. (if applicable).\n");
2413 xinerama = 1;
2414 initialize_blackouts_and_xinerama();
2415 goto done;
2416 }
2417 if (!strcmp(p, "noxinerama")) {
2418 if (query) {
2419 snprintf(buf, bufn, "ans=%s:%d", p, !xinerama);
2420 goto qry;
2421 }
2422 rfbLog("remote_cmd: disable xinerama mode. (if applicable).\n");
2423 xinerama = 0;
2424 initialize_blackouts_and_xinerama();
2425 goto done;
2426 }
2427 if (!strcmp(p, "xtrap")) {
2428 if (query) {
2429 snprintf(buf, bufn, "ans=%s:%d", p, xtrap_input);
2430 goto qry;
2431 }
2432 rfbLog("remote_cmd: enable xtrap input mode."
2433 "(if applicable).\n");
2434 if (! xtrap_input) {
2435 xtrap_input = 1;
2436 disable_grabserver(dpy, 1);
2437 }
2438 goto done;
2439 }
2440 if (!strcmp(p, "noxtrap")) {
2441 if (query) {
2442 snprintf(buf, bufn, "ans=%s:%d", p, !xtrap_input);
2443 goto qry;
2444 }
2445 rfbLog("remote_cmd: disable xtrap input mode."
2446 "(if applicable).\n");
2447 if (xtrap_input) {
2448 xtrap_input = 0;
2449 disable_grabserver(dpy, 1);
2450 }
2451 goto done;
2452 }
2453 if (!strcmp(p, "xrandr")) {
2454 int orig = xrandr;
2455 if (query) {
2456 snprintf(buf, bufn, "ans=%s:%d", p, xrandr); goto qry;
2457 }
2458 if (xrandr_present) {
2459 rfbLog("remote_cmd: enable xrandr mode.\n");
2460 xrandr = 1;
2461 if (raw_fb) set_raw_fb_params(0);
2462 if (! xrandr_mode) {
2463 xrandr_mode = strdup("default");
2464 }
2465 if (orig != xrandr) {
2466 initialize_xrandr();
2467 }
2468 } else {
2469 rfbLog("remote_cmd: XRANDR ext. not present.\n");
2470 }
2471 goto done;
2472 }
2473 if (!strcmp(p, "noxrandr")) {
2474 int orig = xrandr;
2475 if (query) {
2476 snprintf(buf, bufn, "ans=%s:%d", p, !xrandr); goto qry;
2477 }
2478 xrandr = 0;
2479 xrandr_maybe = 0;
2480 if (xrandr_present) {
2481 rfbLog("remote_cmd: disable xrandr mode.\n");
2482 if (orig != xrandr) {
2483 initialize_xrandr();
2484 }
2485 } else {
2486 rfbLog("remote_cmd: XRANDR ext. not present.\n");
2487 }
2488 goto done;
2489 }
2490 if (strstr(p, "xrandr_mode") == p) {
2491 int orig = xrandr;
2492 COLON_CHECK("xrandr_mode:")
2493 if (query) {
2494 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2495 NONUL(xrandr_mode));
2496 goto qry;
2497 }
2498 p += strlen("xrandr_mode:");
2499 if (!strcmp("none", p)) {
2500 xrandr = 0;
2501 xrandr_maybe = 0;
2502 } else {
2503 if (known_xrandr_mode(p)) {
2504 if (xrandr_mode) free(xrandr_mode);
2505 xrandr_mode = strdup(p);
2506 } else {
2507 rfbLog("skipping unknown xrandr mode: %s\n", p);
2508 goto done;
2509 }
2510 xrandr = 1;
2511 }
2512 if (xrandr_present) {
2513 if (xrandr) {
2514 rfbLog("remote_cmd: enable xrandr mode.\n");
2515 } else {
2516 rfbLog("remote_cmd: disable xrandr mode.\n");
2517 }
2518 if (! xrandr_mode) {
2519 xrandr_mode = strdup("default");
2520 }
2521 if (orig != xrandr) {
2522 initialize_xrandr();
2523 }
2524 } else {
2525 rfbLog("remote_cmd: XRANDR ext. not present.\n");
2526 }
2527 goto done;
2528 }
2529 if (strstr(p, "rotate") == p) {
2530 COLON_CHECK("rotate:")
2531 if (query) {
2532 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2533 NONUL(rotating_str));
2534 goto qry;
2535 }
2536 p += strlen("rotate:");
2537 if (rotating_str) free(rotating_str);
2538 rotating_str = strdup(p);
2539 rfbLog("remote_cmd: set rotate to \"%s\"\n", rotating_str);
2540
2541 do_new_fb(0);
2542 goto done;
2543 }
2544 if (strstr(p, "padgeom") == p) {
2545 COLON_CHECK("padgeom:")
2546 if (query) {
2547 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2548 NONUL(pad_geometry));
2549 goto qry;
2550 }
2551 p += strlen("padgeom:");
2552 if (!strcmp("force", p) || !strcmp("do",p) || !strcmp("go",p)) {
2553 rfbLog("remote_cmd: invoking install_padded_fb()\n");
2554 install_padded_fb(pad_geometry);
2555 } else {
2556 if (pad_geometry) free(pad_geometry);
2557 pad_geometry = strdup(p);
2558 rfbLog("remote_cmd: set padgeom to: %s\n",
2559 pad_geometry);
2560 }
2561 goto done;
2562 }
2563 if (!strcmp(p, "quiet") || !strcmp(p, "q")) {
2564 if (query) {
2565 snprintf(buf, bufn, "ans=%s:%d", p, quiet); goto qry;
2566 }
2567 rfbLog("remote_cmd: turning on quiet mode.\n");
2568 quiet = 1;
2569 goto done;
2570 }
2571 if (!strcmp(p, "noquiet")) {
2572 if (query) {
2573 snprintf(buf, bufn, "ans=%s:%d", p, !quiet); goto qry;
2574 }
2575 rfbLog("remote_cmd: turning off quiet mode.\n");
2576 quiet = 0;
2577 goto done;
2578 }
2579 if (!strcmp(p, "modtweak")) {
2580 if (query) {
2581 snprintf(buf, bufn, "ans=%s:%d", p, use_modifier_tweak);
2582 goto qry;
2583 }
2584 rfbLog("remote_cmd: enabling -modtweak mode.\n");
2585 if (! use_modifier_tweak) {
2586 use_modifier_tweak = 1;
2587 initialize_modtweak();
2588 }
2589 use_modifier_tweak = 1;
2590 goto done;
2591 }
2592 if (!strcmp(p, "nomodtweak")) {
2593 if (query) {
2594 snprintf(buf, bufn, "ans=%s:%d", p,
2595 !use_modifier_tweak);
2596 goto qry;
2597 }
2598 rfbLog("remote_cmd: enabling -nomodtweak mode.\n");
2599 got_nomodtweak = 1;
2600 use_modifier_tweak = 0;
2601 goto done;
2602 }
2603 if (!strcmp(p, "xkb")) {
2604 if (query) {
2605 snprintf(buf, bufn, "ans=%s:%d", p, use_xkb_modtweak);
2606 goto qry;
2607 }
2608 if (! xkb_present) {
2609 rfbLog("remote_cmd: cannot enable -xkb "
2610 "modtweak mode (not supported on X display)\n");
2611 goto done;
2612 }
2613 rfbLog("remote_cmd: enabling -xkb modtweak mode"
2614 " (if supported).\n");
2615 if (! use_modifier_tweak || ! use_xkb_modtweak) {
2616 use_modifier_tweak = 1;
2617 use_xkb_modtweak = 1;
2618 initialize_modtweak();
2619 }
2620 use_modifier_tweak = 1;
2621 use_xkb_modtweak = 1;
2622 goto done;
2623 }
2624 if (!strcmp(p, "noxkb")) {
2625 if (query) {
2626 snprintf(buf, bufn, "ans=%s:%d", p, !use_xkb_modtweak);
2627 goto qry;
2628 }
2629 if (! xkb_present) {
2630 rfbLog("remote_cmd: cannot disable -xkb "
2631 "modtweak mode (not supported on X display)\n");
2632 goto done;
2633 }
2634 rfbLog("remote_cmd: disabling -xkb modtweak mode.\n");
2635 use_xkb_modtweak = 0;
2636 got_noxkb = 1;
2637 initialize_modtweak();
2638 goto done;
2639 }
2640 if (!strcmp(p, "capslock")) {
2641 if (query) {
2642 snprintf(buf, bufn, "ans=%s:%d", p, watch_capslock);
2643 goto qry;
2644 }
2645 rfbLog("remote_cmd: enabling -capslock mode\n");
2646 watch_capslock = 1;
2647 goto done;
2648 }
2649 if (!strcmp(p, "nocapslock")) {
2650 if (query) {
2651 snprintf(buf, bufn, "ans=%s:%d", p, !watch_capslock);
2652 goto qry;
2653 }
2654 rfbLog("remote_cmd: disabling -capslock mode\n");
2655 watch_capslock = 0;
2656 goto done;
2657 }
2658 if (!strcmp(p, "skip_lockkeys")) {
2659 if (query) {
2660 snprintf(buf, bufn, "ans=%s:%d", p, skip_lockkeys);
2661 goto qry;
2662 }
2663 rfbLog("remote_cmd: enabling -skip_lockkeys mode\n");
2664 skip_lockkeys = 1;
2665 goto done;
2666 }
2667 if (!strcmp(p, "noskip_lockkeys")) {
2668 if (query) {
2669 snprintf(buf, bufn, "ans=%s:%d", p, !skip_lockkeys);
2670 goto qry;
2671 }
2672 rfbLog("remote_cmd: disabling -skip_lockkeys mode\n");
2673 skip_lockkeys = 0;
2674 goto done;
2675 }
2676 if (strstr(p, "skip_keycodes") == p) {
2677 COLON_CHECK("skip_keycodes:")
2678 if (query) {
2679 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2680 NONUL(skip_keycodes));
2681 goto qry;
2682 }
2683 p += strlen("skip_keycodes:");
2684 rfbLog("remote_cmd: setting xkb -skip_keycodes"
2685 " to:\n\t'%s'\n", p);
2686 if (! xkb_present) {
2687 rfbLog("remote_cmd: warning xkb not present\n");
2688 } else if (! use_xkb_modtweak) {
2689 rfbLog("remote_cmd: turning on xkb.\n");
2690 use_xkb_modtweak = 1;
2691 if (! use_modifier_tweak) {
2692 rfbLog("remote_cmd: turning on modtweak.\n");
2693 use_modifier_tweak = 1;
2694 }
2695 }
2696 if (skip_keycodes) free(skip_keycodes);
2697 skip_keycodes = strdup(p);
2698 initialize_modtweak();
2699 goto done;
2700 }
2701 if (!strcmp(p, "sloppy_keys")) {
2702 if (query) {
2703 snprintf(buf, bufn, "ans=%s:%d", p, sloppy_keys);
2704 goto qry;
2705 }
2706 sloppy_keys += 1;
2707 rfbLog("remote_cmd: set sloppy_keys to: %d\n", sloppy_keys);
2708 goto done;
2709 }
2710 if (!strcmp(p, "nosloppy_keys")) {
2711 if (query) {
2712 snprintf(buf, bufn, "ans=%s:%d", p, !sloppy_keys);
2713 goto qry;
2714 }
2715 sloppy_keys = 0;
2716 rfbLog("remote_cmd: set sloppy_keys to: %d\n", sloppy_keys);
2717 goto done;
2718 }
2719 if (!strcmp(p, "skip_dups")) {
2720 if (query) {
2721 snprintf(buf, bufn, "ans=%s:%d", p,
2722 skip_duplicate_key_events);
2723 goto qry;
2724 }
2725 rfbLog("remote_cmd: enabling -skip_dups mode\n");
2726 skip_duplicate_key_events = 1;
2727 goto done;
2728 }
2729 if (!strcmp(p, "noskip_dups")) {
2730 if (query) {
2731 snprintf(buf, bufn, "ans=%s:%d", p,
2732 !skip_duplicate_key_events);
2733 goto qry;
2734 }
2735 rfbLog("remote_cmd: disabling -skip_dups mode\n");
2736 skip_duplicate_key_events = 0;
2737 goto done;
2738 }
2739 if (!strcmp(p, "add_keysyms")) {
2740 if (query) {
2741 snprintf(buf, bufn, "ans=%s:%d", p, add_keysyms);
2742 goto qry;
2743 }
2744 rfbLog("remote_cmd: enabling -add_keysyms mode.\n");
2745 add_keysyms = 1;
2746 goto done;
2747 }
2748 if (!strcmp(p, "noadd_keysyms")) {
2749 if (query) {
2750 snprintf(buf, bufn, "ans=%s:%d", p, !add_keysyms);
2751 goto qry;
2752 }
2753 rfbLog("remote_cmd: disabling -add_keysyms mode.\n");
2754 add_keysyms = 0;
2755 goto done;
2756 }
2757 if (!strcmp(p, "clear_mods")) {
2758 if (query) {
2759 snprintf(buf, bufn, "ans=%s:%d", p, clear_mods == 1);
2760 goto qry;
2761 }
2762 rfbLog("remote_cmd: enabling -clear_mods mode.\n");
2763 clear_mods = 1;
2764 if (use_threads) {X_LOCK;}
2765 clear_modifiers(0);
2766 if (use_threads) {X_UNLOCK;}
2767 goto done;
2768 }
2769 if (!strcmp(p, "noclear_mods")) {
2770 if (query) {
2771 snprintf(buf, bufn, "ans=%s:%d", p,
2772 !(clear_mods == 1));
2773 goto qry;
2774 }
2775 rfbLog("remote_cmd: disabling -clear_mods mode.\n");
2776 clear_mods = 0;
2777 goto done;
2778 }
2779 if (!strcmp(p, "clear_keys")) {
2780 if (query) {
2781 snprintf(buf, bufn, "ans=%s:%d", p,
2782 clear_mods == 2);
2783 goto qry;
2784 }
2785 rfbLog("remote_cmd: enabling -clear_keys mode.\n");
2786 clear_mods = 2;
2787 if (use_threads) {X_LOCK;}
2788 clear_keys();
2789 if (use_threads) {X_UNLOCK;}
2790 goto done;
2791 }
2792 if (!strcmp(p, "noclear_keys")) {
2793 if (query) {
2794 snprintf(buf, bufn, "ans=%s:%d", p,
2795 !(clear_mods == 2));
2796 goto qry;
2797 }
2798 rfbLog("remote_cmd: disabling -clear_keys mode.\n");
2799 clear_mods = 0;
2800 goto done;
2801 }
2802 if (!strcmp(p, "clear_all")) {
2803 if (query) {
2804 snprintf(buf, bufn, "ans=%s:%d", p,
2805 clear_mods == 3);
2806 goto qry;
2807 }
2808 rfbLog("remote_cmd: doing clear_all action.\n");
2809 clear_mods = 3;
2810 if (use_threads) {X_LOCK;}
2811 clear_keys();
2812 clear_locks();
2813 if (use_threads) {X_UNLOCK;}
2814 goto done;
2815 }
2816 if (!strcmp(p, "clear_locks")) {
2817 NOTAPP
2818 rfbLog("remote_cmd: doing clear_locks action.\n");
2819 if (use_threads) {X_LOCK;}
2820 clear_locks();
2821 if (use_threads) {X_UNLOCK;}
2822 goto done;
2823 }
2824 if (!strcmp(p, "keystate")) {
2825 int i, state[256];
2826 NOTAPP
2827 for (i=0; i<256; i++) {
2828 state[i] = 0;
2829 }
2830 if (use_threads) {X_LOCK;}
2831 get_keystate(state);
2832 if (use_threads) {X_UNLOCK;}
2833 for (i=0; i<256; i++) {
2834 fprintf(stderr, "keystate[%03d] %d\n", i, state[i]);
2835 }
2836 goto done;
2837 }
2838 if (strstr(p, "remap") == p) {
2839 char *before, *old;
2840 COLON_CHECK("remap:")
2841 if (query) {
2842 snprintf(buf, bufn, "ans=%s%s%s", p, co,
2843 NONUL(remap_file));
2844 goto qry;
2845 }
2846 p += strlen("remap:");
2847 if ((*p == '+' || *p == '-') && remap_file &&
2848 strchr(remap_file, '/')) {
2849 rfbLog("remote_cmd: cannot use remap:+/-\n");
2850 rfbLog("in '-remap %s' mode.\n", remap_file);
2851 goto done;
2852 }
2853 if (remap_file) {
2854 before = strdup(remap_file);
2855 } else {
2856 before = strdup("");
2857 }
2858 old = remap_file;
2859 if (*p == '+') {
2860 p++;
2861 remap_file = add_item(remap_file, p);
2862 } else if (*p == '-') {
2863 p++;
2864 remap_file = delete_item(remap_file, p);
2865 if (! strchr(remap_file, '-')) {
2866 *remap_file = '\0';
2867 }
2868 } else {
2869 remap_file = strdup(p);
2870 }
2871 if (strcmp(before, remap_file)) {
2872 rfbLog("remote_cmd: changed -remap\n");
2873 rfbLog(" from: %s\n", before);
2874 rfbLog(" to: %s\n", remap_file);
2875 initialize_remap(remap_file);
2876 }
2877 if (old) free(old);
2878 free(before);
2879 goto done;
2880 }
2881 if (!strcmp(p, "repeat")) {
2882 if (query) {
2883 snprintf(buf, bufn, "ans=%s:%d", p, !no_autorepeat);
2884 goto qry;
2885 }
2886 rfbLog("remote_cmd: enabling -repeat mode.\n");
2887 autorepeat(1, 0); /* restore initial setting */
2888 no_autorepeat = 0;
2889 goto done;
2890 }
2891 if (!strcmp(p, "norepeat")) {
2892 if (query) {
2893 snprintf(buf, bufn, "ans=%s:%d", p, no_autorepeat);
2894 goto qry;
2895 }
2896 rfbLog("remote_cmd: enabling -norepeat mode.\n");
2897 no_autorepeat = 1;
2898 if (no_repeat_countdown >= 0) {
2899 no_repeat_countdown = 2;
2900 }
2901 if (client_count && ! view_only) {
2902 autorepeat(0, 0); /* disable if any clients */
2903 }
2904 goto done;
2905 }
2906 if (!strcmp(p, "fb")) {
2907 if (query) {
2908 snprintf(buf, bufn, "ans=%s:%d", p, !nofb);
2909 goto qry;
2910 }
2911 if (nofb) {
2912 rfbLog("remote_cmd: disabling nofb mode.\n");
2913 rfbLog(" you may need to these turn back on:\n");
2914 rfbLog(" xfixes, xdamage, solid, flashcmap\n");
2915 rfbLog(" overlay, shm, noonetile, nap, cursor\n");
2916 rfbLog(" cursorpos, cursorshape, bell.\n");
2917 nofb = 0;
2918 set_nofb_params(1);
2919 do_new_fb(1);
2920 }
2921 goto done;
2922 }
2923 if (!strcmp(p, "nofb")) {
2924 if (query) {
2925 snprintf(buf, bufn, "ans=%s:%d", p, nofb);
2926 goto qry;
2927 }
2928 if (!nofb) {
2929 rfbLog("remote_cmd: enabling nofb mode.\n");
2930 if (main_fb) {
2931 push_black_screen(4);
2932 }
2933 nofb = 1;
2934 sound_bell = 0;
2935 initialize_watch_bell();
2936 set_nofb_params(0);
2937 do_new_fb(1);
2938 }
2939 goto done;
2940 }
2941 if (!strcmp(p, "bell")) {
2942 if (query) {
2943 snprintf(buf, bufn, "ans=%s:%d", p, sound_bell);
2944 goto qry;
2945 }
2946 rfbLog("remote_cmd: enabling bell (if supported).\n");
2947 initialize_watch_bell();
2948 sound_bell = 1;
2949 goto done;
2950 }
2951 if (!strcmp(p, "nobell")) {
2952 if (query) {
2953 snprintf(buf, bufn, "ans=%s:%d", p, !sound_bell);
2954 goto qry;
2955 }
2956 rfbLog("remote_cmd: disabling bell.\n");
2957 initialize_watch_bell();
2958 sound_bell = 0;
2959 goto done;
2960 }
2961 if (!strcmp(p, "sendbell")) {
2962 NOTAPP
2963 rfbLog("remote_cmd: sendbell.\n");
2964 if (screen && client_count) {
2965 rfbSendBell(screen);
2966 }
2967 goto done;
2968 }
2969 if (!strcmp(p, "sel")) {
2970 if (query) {
2971 snprintf(buf, bufn, "ans=%s:%d", p, watch_selection);
2972 goto qry;
2973 }
2974 rfbLog("remote_cmd: enabling watch selection+primary.\n");
2975 watch_selection = 1;
2976 watch_primary = 1;
2977 watch_clipboard = 1;
2978 goto done;
2979 }
2980 if (!strcmp(p, "nosel")) {
2981 if (query) {
2982 snprintf(buf, bufn, "ans=%s:%d", p, !watch_selection);
2983 goto qry;
2984 }
2985 rfbLog("remote_cmd: disabling watch selection+primary.\n");
2986 watch_selection = 0;
2987 watch_primary = 0;
2988 watch_clipboard = 0;
2989 goto done;
2990 }
2991 if (!strcmp(p, "primary")) {
2992 if (query) {
2993 snprintf(buf, bufn, "ans=%s:%d", p, watch_primary);
2994 goto qry;
2995 }
2996 rfbLog("remote_cmd: enabling watch_primary.\n");
2997 watch_primary = 1;
2998 goto done;
2999 }
3000 if (!strcmp(p, "noprimary")) {
3001 if (query) {
3002 snprintf(buf, bufn, "ans=%s:%d", p, !watch_primary);
3003 goto qry;
3004 }
3005 rfbLog("remote_cmd: disabling watch_primary.\n");
3006 watch_primary = 0;
3007 goto done;
3008 }
3009 if (!strcmp(p, "setprimary")) {
3010 if (query) {
3011 snprintf(buf, bufn, "ans=%s:%d", p, set_primary);
3012 goto qry;
3013 }
3014 rfbLog("remote_cmd: enabling set_primary.\n");
3015 set_primary = 1;
3016 goto done;
3017 }
3018 if (!strcmp(p, "nosetprimary")) {
3019 if (query) {
3020 snprintf(buf, bufn, "ans=%s:%d", p, !set_primary);
3021 goto qry;
3022 }
3023 rfbLog("remote_cmd: disabling set_primary.\n");
3024 set_primary = 0;
3025 goto done;
3026 }
3027 if (!strcmp(p, "clipboard")) {
3028 if (query) {
3029 snprintf(buf, bufn, "ans=%s:%d", p, watch_clipboard);
3030 goto qry;
3031 }
3032 rfbLog("remote_cmd: enabling watch_clipboard.\n");
3033 watch_clipboard = 1;
3034 goto done;
3035 }
3036 if (!strcmp(p, "noclipboard")) {
3037 if (query) {
3038 snprintf(buf, bufn, "ans=%s:%d", p, !watch_clipboard);
3039 goto qry;
3040 }
3041 rfbLog("remote_cmd: disabling watch_clipboard.\n");
3042 watch_clipboard = 0;
3043 goto done;
3044 }
3045 if (!strcmp(p, "setclipboard")) {
3046 if (query) {
3047 snprintf(buf, bufn, "ans=%s:%d", p, set_clipboard);
3048 goto qry;
3049 }
3050 rfbLog("remote_cmd: enabling set_clipboard.\n");
3051 set_clipboard = 1;
3052 goto done;
3053 }
3054 if (!strcmp(p, "nosetclipboard")) {
3055 if (query) {
3056 snprintf(buf, bufn, "ans=%s:%d", p, !set_clipboard);
3057 goto qry;
3058 }
3059 rfbLog("remote_cmd: disabling set_clipboard.\n");
3060 set_clipboard = 0;
3061 goto done;
3062 }
3063 if (strstr(p, "seldir") == p) {
3064 COLON_CHECK("seldir:")
3065 if (query) {
3066 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3067 NONUL(sel_direction));
3068 goto qry;
3069 }
3070 p += strlen("seldir:");
3071 rfbLog("remote_cmd: setting -seldir to %s\n", p);
3072 if (sel_direction) free(sel_direction);
3073 sel_direction = strdup(p);
3074 goto done;
3075 }
3076 if (!strcmp(p, "set_no_cursor")) { /* skip-cmd-list */
3077 rfbLog("remote_cmd: calling set_no_cursor()\n");
3078 set_no_cursor();
3079 goto done;
3080 }
3081 if (!strcmp(p, "cursorshape")) {
3082 if (query) {
3083 snprintf(buf, bufn, "ans=%s:%d", p,
3084 cursor_shape_updates);
3085 goto qry;
3086 }
3087 rfbLog("remote_cmd: turning on cursorshape mode.\n");
3088
3089 set_no_cursor();
3090 cursor_shape_updates = 1;
3091 restore_cursor_shape_updates(screen);
3092 first_cursor();
3093 goto done;
3094 }
3095 if (!strcmp(p, "nocursorshape")) {
3096 int i, max = 5;
3097 if (query) {
3098 snprintf(buf, bufn, "ans=%s:%d", p,
3099 !cursor_shape_updates);
3100 goto qry;
3101 }
3102 rfbLog("remote_cmd: turning off cursorshape mode.\n");
3103
3104 set_no_cursor();
3105 for (i=0; i<max; i++) {
3106 /* XXX: try to force empty cursor back to client */
3107 rfbPE(-1);
3108 }
3109 cursor_shape_updates = 0;
3110 disable_cursor_shape_updates(screen);
3111 first_cursor();
3112 goto done;
3113 }
3114 if (!strcmp(p, "cursorpos")) {
3115 if (query) {
3116 snprintf(buf, bufn, "ans=%s:%d", p,
3117 cursor_pos_updates);
3118 goto qry;
3119 }
3120 rfbLog("remote_cmd: turning on cursorpos mode.\n");
3121 cursor_pos_updates = 1;
3122 goto done;
3123 }
3124 if (!strcmp(p, "nocursorpos")) {
3125 if (query) {
3126 snprintf(buf, bufn, "ans=%s:%d", p,
3127 !cursor_pos_updates);
3128 goto qry;
3129 }
3130 rfbLog("remote_cmd: turning off cursorpos mode.\n");
3131 cursor_pos_updates = 0;
3132 goto done;
3133 }
3134 if (!strcmp(p, "cursor_drag")) {
3135 if (query) {
3136 snprintf(buf, bufn, "ans=%s:%d", p, cursor_drag_changes);
3137 goto qry;
3138 }
3139 cursor_drag_changes = 1;
3140 rfbLog("remote_cmd: setting cursor_drag_changes: %d.\n", cursor_drag_changes);
3141 goto done;
3142 }
3143 if (!strcmp(p, "nocursor_drag")) {
3144 if (query) {
3145 snprintf(buf, bufn, "ans=%s:%d", p, !cursor_drag_changes);
3146 goto qry;
3147 }
3148 cursor_drag_changes = 0;
3149 rfbLog("remote_cmd: setting cursor_drag_changes: %d.\n", cursor_drag_changes);
3150 goto done;
3151 }
3152 if (strstr(p, "cursor") == p) {
3153 COLON_CHECK("cursor:")
3154 if (query) {
3155 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3156 NONUL(multiple_cursors_mode));
3157 goto qry;
3158 }
3159 p += strlen("cursor:");
3160 if (multiple_cursors_mode) {
3161 if (prev_cursors_mode) free(prev_cursors_mode);
3162 prev_cursors_mode = strdup(multiple_cursors_mode);
3163 free(multiple_cursors_mode);
3164 }
3165 multiple_cursors_mode = strdup(p);
3166
3167 rfbLog("remote_cmd: changed -cursor mode "
3168 "to: %s\n", multiple_cursors_mode);
3169
3170 if (strcmp(multiple_cursors_mode, "none") && !show_cursor) {
3171 show_cursor = 1;
3172 rfbLog("remote_cmd: changed show_cursor "
3173 "to: %d\n", show_cursor);
3174 }
3175 initialize_cursors_mode();
3176 first_cursor();
3177 goto done;
3178 }
3179 if (!strcmp(p, "show_cursor")) {
3180 if (query) {
3181 snprintf(buf, bufn, "ans=%s:%d", p, show_cursor);
3182 goto qry;
3183 }
3184 rfbLog("remote_cmd: enabling show_cursor.\n");
3185 show_cursor = 1;
3186 if (multiple_cursors_mode && !strcmp(multiple_cursors_mode,
3187 "none")) {
3188 free(multiple_cursors_mode);
3189 if (prev_cursors_mode) {
3190 multiple_cursors_mode =
3191 strdup(prev_cursors_mode);
3192 } else {
3193 multiple_cursors_mode = strdup("default");
3194 }
3195 rfbLog("remote_cmd: changed -cursor mode "
3196 "to: %s\n", multiple_cursors_mode);
3197 }
3198 initialize_cursors_mode();
3199 first_cursor();
3200 goto done;
3201 }
3202 if (!strcmp(p, "noshow_cursor") || !strcmp(p, "nocursor")) {
3203 if (query) {
3204 snprintf(buf, bufn, "ans=%s:%d", p, !show_cursor);
3205 goto qry;
3206 }
3207 if (prev_cursors_mode) free(prev_cursors_mode);
3208 prev_cursors_mode = strdup(multiple_cursors_mode);
3209
3210 rfbLog("remote_cmd: disabling show_cursor.\n");
3211 show_cursor = 0;
3212 initialize_cursors_mode();
3213 first_cursor();
3214 goto done;
3215 }
3216 if (strstr(p, "arrow") == p) {
3217 COLON_CHECK("arrow:")
3218 if (query) {
3219 snprintf(buf, bufn, "ans=%s%s%d", p, co, alt_arrow);
3220 goto qry;
3221 }
3222 p += strlen("arrow:");
3223 alt_arrow = atoi(p);
3224 rfbLog("remote_cmd: setting alt_arrow: %d.\n", alt_arrow);
3225 setup_cursors_and_push();
3226 goto done;
3227 }
3228 if (!strcmp(p, "xfixes")) {
3229 if (query) {
3230 snprintf(buf, bufn, "ans=%s:%d", p, use_xfixes);
3231 goto qry;
3232 }
3233 if (! xfixes_present) {
3234 rfbLog("remote_cmd: cannot enable xfixes "
3235 "(not supported on X display)\n");
3236 goto done;
3237 }
3238 rfbLog("remote_cmd: enabling -xfixes"
3239 " (if supported).\n");
3240 use_xfixes = 1;
3241 initialize_xfixes();
3242 first_cursor();
3243 goto done;
3244 }
3245 if (!strcmp(p, "noxfixes")) {
3246 if (query) {
3247 snprintf(buf, bufn, "ans=%s:%d", p, !use_xfixes);
3248 goto qry;
3249 }
3250 if (! xfixes_present) {
3251 rfbLog("remote_cmd: disabling xfixes "
3252 "(but not supported on X display)\n");
3253 goto done;
3254 }
3255 rfbLog("remote_cmd: disabling -xfixes.\n");
3256 use_xfixes = 0;
3257 initialize_xfixes();
3258 first_cursor();
3259 goto done;
3260 }
3261 if (!strcmp(p, "xdamage")) {
3262 int orig = use_xdamage;
3263 if (query) {
3264 snprintf(buf, bufn, "ans=%s:%d", p, use_xdamage);
3265 goto qry;
3266 }
3267 if (! xdamage_present) {
3268 rfbLog("remote_cmd: cannot enable xdamage hints "
3269 "(not supported on X display)\n");
3270 goto done;
3271 }
3272 rfbLog("remote_cmd: enabling xdamage hints"
3273 " (if supported).\n");
3274 use_xdamage = 1;
3275 if (use_xdamage != orig) {
3276 initialize_xdamage();
3277 create_xdamage_if_needed(0);
3278 }
3279 goto done;
3280 }
3281 if (!strcmp(p, "noxdamage")) {
3282 int orig = use_xdamage;
3283 if (query) {
3284 snprintf(buf, bufn, "ans=%s:%d", p, !use_xdamage);
3285 goto qry;
3286 }
3287 if (! xdamage_present) {
3288 rfbLog("remote_cmd: disabling xdamage hints "
3289 "(but not supported on X display)\n");
3290 goto done;
3291 }
3292 rfbLog("remote_cmd: disabling xdamage hints.\n");
3293 use_xdamage = 0;
3294 if (use_xdamage != orig) {
3295 initialize_xdamage();
3296 destroy_xdamage_if_needed();
3297 }
3298 goto done;
3299 }
3300 if (strstr(p, "xd_area") == p) {
3301 int a;
3302 COLON_CHECK("xd_area:")
3303 if (query) {
3304 snprintf(buf, bufn, "ans=%s%s%d", p, co,
3305 xdamage_max_area);
3306 goto qry;
3307 }
3308 p += strlen("xd_area:");
3309 a = atoi(p);
3310 if (a >= 0) {
3311 rfbLog("remote_cmd: setting xdamage_max_area "
3312 "%d -> %d.\n", xdamage_max_area, a);
3313 xdamage_max_area = a;
3314 }
3315 goto done;
3316 }
3317 if (strstr(p, "xd_mem") == p) {
3318 double a;
3319 COLON_CHECK("xd_mem:")
3320 if (query) {
3321 snprintf(buf, bufn, "ans=%s%s%.3f", p, co,
3322 xdamage_memory);
3323 goto qry;
3324 }
3325 p += strlen("xd_mem:");
3326 a = atof(p);
3327 if (a >= 0.0) {
3328 rfbLog("remote_cmd: setting xdamage_memory "
3329 "%.3f -> %.3f.\n", xdamage_memory, a);
3330 xdamage_memory = a;
3331 }
3332 goto done;
3333 }
3334 if (strstr(p, "alphacut") == p) {
3335 int a;
3336 COLON_CHECK("alphacut:")
3337 if (query) {
3338 snprintf(buf, bufn, "ans=%s%s%d", p, co,
3339 alpha_threshold);
3340 goto qry;
3341 }
3342 p += strlen("alphacut:");
3343 a = atoi(p);
3344 if (a < 0) a = 0;
3345 if (a > 256) a = 256; /* allow 256 for testing. */
3346 if (alpha_threshold != a) {
3347 rfbLog("remote_cmd: setting alphacut "
3348 "%d -> %d.\n", alpha_threshold, a);
3349 if (a == 256) {
3350 rfbLog("note: alphacut=256 leads to completely"
3351 " transparent cursors.\n");
3352 }
3353 alpha_threshold = a;
3354 setup_cursors_and_push();
3355 }
3356 goto done;
3357 }
3358 if (strstr(p, "alphafrac") == p) {
3359 double a;
3360 COLON_CHECK("alphafrac:")
3361 if (query) {
3362 snprintf(buf, bufn, "ans=%s%s%f", p, co,
3363 alpha_frac);
3364 goto qry;
3365 }
3366 p += strlen("alphafrac:");
3367 a = atof(p);
3368 if (a < 0.0) a = 0.0;
3369 if (a > 1.0) a = 1.0;
3370 if (alpha_frac != a) {
3371 rfbLog("remote_cmd: setting alphafrac "
3372 "%f -> %f.\n", alpha_frac, a);
3373 alpha_frac = a;
3374 setup_cursors_and_push();
3375 }
3376 goto done;
3377 }
3378 if (strstr(p, "alpharemove") == p) {
3379 if (query) {
3380 snprintf(buf, bufn, "ans=%s:%d", p, alpha_remove);
3381 goto qry;
3382 }
3383 if (!alpha_remove) {
3384 rfbLog("remote_cmd: enable alpharemove\n");
3385 alpha_remove = 1;
3386 setup_cursors_and_push();
3387 }
3388 goto done;
3389 }
3390 if (strstr(p, "noalpharemove") == p) {
3391 if (query) {
3392 snprintf(buf, bufn, "ans=%s:%d", p, !alpha_remove);
3393 goto qry;
3394 }
3395 if (alpha_remove) {
3396 rfbLog("remote_cmd: disable alpharemove\n");
3397 alpha_remove = 0;
3398 setup_cursors_and_push();
3399 }
3400 goto done;
3401 }
3402 if (strstr(p, "alphablend") == p) {
3403 if (query) {
3404 snprintf(buf, bufn, "ans=%s:%d", p, alpha_blend);
3405 goto qry;
3406 }
3407 if (!alpha_blend) {
3408 rfbLog("remote_cmd: enable alphablend\n");
3409 alpha_remove = 0;
3410 alpha_blend = 1;
3411 setup_cursors_and_push();
3412 }
3413 goto done;
3414 }
3415 if (strstr(p, "noalphablend") == p) {
3416 if (query) {
3417 snprintf(buf, bufn, "ans=%s:%d", p, !alpha_blend);
3418 goto qry;
3419 }
3420 if (alpha_blend) {
3421 rfbLog("remote_cmd: disable alphablend\n");
3422 alpha_blend = 0;
3423 setup_cursors_and_push();
3424 }
3425 goto done;
3426 }
3427 if (strstr(p, "xwarppointer") == p || strstr(p, "xwarp") == p) {
3428 if (query) {
3429 snprintf(buf, bufn, "ans=%s:%d", p, use_xwarppointer);
3430 goto qry;
3431 }
3432 rfbLog("remote_cmd: turning on xwarppointer mode.\n");
3433 use_xwarppointer = 1;
3434 goto done;
3435 }
3436 if (strstr(p, "noxwarppointer") == p ||
3437 strstr(p, "noxwarp") == p) {
3438 if (query) {
3439 snprintf(buf, bufn, "ans=%s:%d", p, !use_xwarppointer);
3440 goto qry;
3441 }
3442 rfbLog("remote_cmd: turning off xwarppointer mode.\n");
3443 use_xwarppointer = 0;
3444 goto done;
3445 }
3446 if (strstr(p, "always_inject") == p) {
3447 if (query) {
3448 snprintf(buf, bufn, "ans=%s:%d", p, always_inject);
3449 goto qry;
3450 }
3451 rfbLog("remote_cmd: turning on always_inject mode.\n");
3452 always_inject = 1;
3453 goto done;
3454 }
3455 if (strstr(p, "noalways_inject") == p) {
3456 if (query) {
3457 snprintf(buf, bufn, "ans=%s:%d", p, !always_inject);
3458 goto qry;
3459 }
3460 rfbLog("remote_cmd: turning off always_inject mode.\n");
3461 always_inject = 0;
3462 goto done;
3463 }
3464 if (strstr(p, "buttonmap") == p) {
3465 COLON_CHECK("buttonmap:")
3466 if (query) {
3467 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3468 NONUL(pointer_remap));
3469 goto qry;
3470 }
3471 p += strlen("buttonmap:");
3472 if (pointer_remap) free(pointer_remap);
3473 pointer_remap = strdup(p);
3474
3475 rfbLog("remote_cmd: setting -buttonmap to:\n\t'%s'\n", p);
3476 initialize_pointer_map(p);
3477 goto done;
3478 }
3479 if (!strcmp(p, "dragging")) {
3480 if (query) {
3481 snprintf(buf, bufn, "ans=%s:%d", p, show_dragging);
3482 goto qry;
3483 }
3484 rfbLog("remote_cmd: enabling mouse dragging mode.\n");
3485 show_dragging = 1;
3486 goto done;
3487 }
3488 if (!strcmp(p, "nodragging")) {
3489 if (query) {
3490 snprintf(buf, bufn, "ans=%s:%d", p, !show_dragging);
3491 goto qry;
3492 }
3493 rfbLog("remote_cmd: enabling mouse nodragging mode.\n");
3494 show_dragging = 0;
3495 goto done;
3496 }
3497#ifndef NO_NCACHE
3498 if (!strcmp(p, "ncache_cr")) {
3499 if (query) {
3500 snprintf(buf, bufn, "ans=%s:%d", p, ncache_copyrect);
3501 goto qry;
3502 }
3503 ncache_copyrect = 1;
3504 rfbLog("remote_cmd: set -ncache_cr %d\n", ncache_copyrect);
3505 goto done;
3506 }
3507 if (!strcmp(p, "noncache_cr")) {
3508 if (query) {
3509 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_copyrect);
3510 goto qry;
3511 }
3512 ncache_copyrect = 0;
3513 rfbLog("remote_cmd: disabled -ncache_cr %d\n", ncache_copyrect);
3514
3515 goto done;
3516 }
3517 if (!strcmp(p, "ncache_no_moveraise")) {
3518 if (query) {
3519 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_wf_raises);
3520 goto qry;
3521 }
3522 ncache_wf_raises = 0;
3523 rfbLog("remote_cmd: set -ncache_no_moveraise\n");
3524 goto done;
3525 }
3526 if (!strcmp(p, "noncache_no_moveraise")) {
3527 if (query) {
3528 snprintf(buf, bufn, "ans=%s:%d", p, ncache_wf_raises);
3529 goto qry;
3530 }
3531 ncache_wf_raises = 1;
3532 rfbLog("remote_cmd: disabled -ncache_no_moveraise\n");
3533 goto done;
3534 }
3535 if (!strcmp(p, "ncache_no_dtchange")) {
3536 if (query) {
3537 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_dt_change);
3538 goto qry;
3539 }
3540 ncache_dt_change = 0;
3541 rfbLog("remote_cmd: set -ncache_no_dt_change\n");
3542 goto done;
3543 }
3544 if (!strcmp(p, "noncache_no_dtchange")) {
3545 if (query) {
3546 snprintf(buf, bufn, "ans=%s:%d", p, ncache_dt_change);
3547 goto qry;
3548 }
3549 ncache_dt_change = 1;
3550 rfbLog("remote_cmd: disabled -ncache_no_dt_change\n");
3551 goto done;
3552 }
3553 if (!strcmp(p, "ncache_no_rootpixmap")) {
3554 int orig = ncache_xrootpmap;
3555 if (query) {
3556 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_xrootpmap);
3557 goto qry;
3558 }
3559 ncache_xrootpmap = 0;
3560 rfbLog("remote_cmd: set -ncache_no_rootpixmap\n");
3561 if (orig != ncache_xrootpmap) {
3562 do_new_fb(1);
3563 }
3564 goto done;
3565 }
3566 if (!strcmp(p, "noncache_no_rootpixmap")) {
3567 int orig = ncache_xrootpmap;
3568 if (query) {
3569 snprintf(buf, bufn, "ans=%s:%d", p, ncache_xrootpmap);
3570 goto qry;
3571 }
3572 ncache_xrootpmap = 1;
3573 rfbLog("remote_cmd: disabled -ncache_no_rootpixmap\n");
3574 if (orig != ncache_xrootpmap) {
3575 do_new_fb(1);
3576 }
3577 goto done;
3578 }
3579 if (!strcmp(p, "ncache_reset_rootpixmap") || !strcmp(p, "ncrp")) {
3580 if (query) {
3581 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_xrootpmap);
3582 goto qry;
3583 }
3584 if (ncache_xrootpmap) {
3585 rfbLog("remote_cmd: resetting root pixmap.\n");
3586 set_ncache_xrootpmap();
3587 }
3588 goto done;
3589 }
3590 if (!strcmp(p, "ncache_keep_anims")) {
3591 if (query) {
3592 snprintf(buf, bufn, "ans=%s:%d", p, ncache_keep_anims);
3593 goto qry;
3594 }
3595 kde_no_animate(0);
3596 ncache_keep_anims = 1;
3597 rfbLog("remote_cmd: set -ncache_keep_anims\n");
3598 goto done;
3599 }
3600 if (!strcmp(p, "noncache_keep_anims")) {
3601 if (query) {
3602 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_keep_anims);
3603 goto qry;
3604 }
3605 ncache_keep_anims = 0;
3606 kde_no_animate(1);
3607 rfbLog("remote_cmd: disabled -ncache_keep_anims\n");
3608 goto done;
3609 }
3610 if (!strcmp(p, "ncache_old_wm")) {
3611 if (query) {
3612 snprintf(buf, bufn, "ans=%s:%d", p, ncache_old_wm);
3613 goto qry;
3614 }
3615 ncache_old_wm = 1;
3616 rfbLog("remote_cmd: set -ncache_old_wm\n");
3617 goto done;
3618 }
3619 if (!strcmp(p, "noncache_old_wm")) {
3620 if (query) {
3621 snprintf(buf, bufn, "ans=%s:%d", p, !ncache_old_wm);
3622 goto qry;
3623 }
3624 ncache_old_wm = 0;
3625 rfbLog("remote_cmd: disabled -ncache_old_wm\n");
3626 goto done;
3627 }
3628 if (strstr(p, "ncache_pad") == p) {
3629 int orig = ncache_pad, n;
3630 COLON_CHECK("ncache_pad:")
3631 if (query) {
3632 snprintf(buf, bufn, "ans=%s%s%d", p, co, ncache_pad);
3633 goto qry;
3634 }
3635 p += strlen("ncache_pad:");
3636 n = atoi(p);
3637
3638 rfbLog("remote_cmd: setting ncache_pad %d to: %d\n", orig, n);
3639 goto done;
3640 }
3641 if (!strcmp(p, "ncache")) {
3642 if (query) {
3643 snprintf(buf, bufn, "ans=%s:%d", p, !!ncache);
3644 goto qry;
3645 }
3646 ncache = ncache0;
3647 rfbLog("remote_cmd: set ncache %d\n", ncache);
3648 goto done;
3649 }
3650 if (!strcmp(p, "noncache")) {
3651 if (query) {
3652 snprintf(buf, bufn, "ans=%s:%d", p, !ncache);
3653 goto qry;
3654 }
3655 ncache = 0;
3656 rfbLog("remote_cmd: disabled ncache %d\n", ncache);
3657 goto done;
3658 }
3659 if (strstr(p, "ncache_size") == p) {
3660 int orig = ncache, n;
3661 COLON_CHECK("ncache_size:")
3662 if (query) {
3663 snprintf(buf, bufn, "ans=%s%s%d", p, co, ncache);
3664 goto qry;
3665 }
3666 p += strlen("ncache_size:");
3667 n = atoi(p);
3668
3669 if (n >= 0 && n != ncache) {
3670 rfbLog("remote_cmd: setting ncache %d to: %d\n", orig, ncache);
3671 ncache = n;
3672 do_new_fb(1);
3673 if (client_count) {
3674 check_ncache(1,0);
3675 }
3676 }
3677 goto done;
3678 }
3679 if (!strcmp(p, "debug_ncache")) {
3680 if (query) {
3681 snprintf(buf, bufn, "ans=%s:%d", p, ncdb);
3682 goto qry;
3683 }
3684 ncdb = 1;
3685 rfbLog("remote_cmd: enabled debug_ncache\n");
3686 goto done;
3687 }
3688 if (!strcmp(p, "nodebug_ncache")) {
3689 if (query) {
3690 snprintf(buf, bufn, "ans=%s:%d", p, !ncdb);
3691 goto qry;
3692 }
3693 ncdb = 0;
3694 rfbLog("remote_cmd: disabled debug_ncache\n");
3695 goto done;
3696 }
3697#endif
3698 if (strstr(p, "wireframe_mode") == p) {
3699 COLON_CHECK("wireframe_mode:")
3700 if (query) {
3701 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3702 wireframe_str ? wireframe_str : WIREFRAME_PARMS);
3703 goto qry;
3704 }
3705 p += strlen("wireframe_mode:");
3706 if (*p) {
3707 if (wireframe_str) {
3708 free(wireframe_str);
3709 }
3710 wireframe_str = strdup(p);
3711 parse_wireframe();
3712 }
3713 rfbLog("remote_cmd: enabling -wireframe mode.\n");
3714 wireframe = 1;
3715 goto done;
3716 }
3717 if (strstr(p, "wireframe:") == p) { /* skip-cmd-list */
3718 COLON_CHECK("wireframe:")
3719 if (query) {
3720 snprintf(buf, bufn, "ans=%s%s%d", p, co, wireframe);
3721 goto qry;
3722 }
3723 p += strlen("wireframe:");
3724 if (*p) {
3725 if (wireframe_str) {
3726 free(wireframe_str);
3727 }
3728 wireframe_str = strdup(p);
3729 parse_wireframe();
3730 }
3731 rfbLog("remote_cmd: enabling -wireframe mode.\n");
3732 wireframe = 1;
3733 goto done;
3734 }
3735 if (strstr(p, "wf:") == p) { /* skip-cmd-list */
3736 COLON_CHECK("wf:")
3737 if (query) {
3738 snprintf(buf, bufn, "ans=%s%s%d", p, co, wireframe);
3739 goto qry;
3740 }
3741 p += strlen("wf:");
3742 if (*p) {
3743 if (wireframe_str) {
3744 free(wireframe_str);
3745 }
3746 wireframe_str = strdup(p);
3747 parse_wireframe();
3748 }
3749 rfbLog("remote_cmd: enabling -wireframe mode.\n");
3750 wireframe = 1;
3751 goto done;
3752 }
3753 if (!strcmp(p, "wireframe") || !strcmp(p, "wf")) {
3754 if (query) {
3755 snprintf(buf, bufn, "ans=%s:%d", p, wireframe);
3756 goto qry;
3757 }
3758 rfbLog("remote_cmd: enabling -wireframe mode.\n");
3759 wireframe = 1;
3760 goto done;
3761 }
3762 if (!strcmp(p, "nowireframe") || !strcmp(p, "nowf")) {
3763 if (query) {
3764 snprintf(buf, bufn, "ans=%s:%d", p, !wireframe);
3765 goto qry;
3766 }
3767 rfbLog("remote_cmd: enabling -nowireframe mode.\n");
3768 wireframe = 0;
3769 goto done;
3770 }
3771 if (!strcmp(p, "wireframelocal") || !strcmp(p, "wfl")) {
3772 if (query) {
3773 snprintf(buf, bufn, "ans=%s:%d", p, wireframe_local);
3774 goto qry;
3775 }
3776 rfbLog("remote_cmd: enabling -wireframelocal mode.\n");
3777 wireframe_local = 1;
3778 goto done;
3779 }
3780 if (!strcmp(p, "nowireframelocal") || !strcmp(p, "nowfl")) {
3781 if (query) {
3782 snprintf(buf, bufn, "ans=%s:%d", p, !wireframe_local);
3783 goto qry;
3784 }
3785 rfbLog("remote_cmd: enabling -nowireframelocal mode.\n");
3786 wireframe_local = 0;
3787 goto done;
3788 }
3789 if (strstr(p, "wirecopyrect") == p) {
3790 COLON_CHECK("wirecopyrect:")
3791 if (query) {
3792 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3793 NONUL(wireframe_copyrect));
3794 goto qry;
3795 }
3796 p += strlen("wirecopyrect:");
3797
3798 set_wirecopyrect_mode(p);
3799 rfbLog("remote_cmd: changed -wirecopyrect mode "
3800 "to: %s\n", NONUL(wireframe_copyrect));
3801 got_wirecopyrect = 1;
3802 goto done;
3803 }
3804 if (strstr(p, "wcr") == p) {
3805 COLON_CHECK("wcr:")
3806 if (query) {
3807 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3808 NONUL(wireframe_copyrect));
3809 goto qry;
3810 }
3811 p += strlen("wcr:");
3812
3813 set_wirecopyrect_mode(p);
3814 rfbLog("remote_cmd: changed -wirecopyrect mode "
3815 "to: %s\n", NONUL(wireframe_copyrect));
3816 got_wirecopyrect = 1;
3817 goto done;
3818 }
3819 if (!strcmp(p, "nowirecopyrect") || !strcmp(p, "nowcr")) {
3820 if (query) {
3821 snprintf(buf, bufn, "ans=%s:%s", p,
3822 NONUL(wireframe_copyrect));
3823 goto qry;
3824 }
3825
3826 set_wirecopyrect_mode("never");
3827 rfbLog("remote_cmd: changed -wirecopyrect mode "
3828 "to: %s\n", NONUL(wireframe_copyrect));
3829 goto done;
3830 }
3831 if (strstr(p, "scr_area") == p) {
3832 COLON_CHECK("scr_area:")
3833 if (query) {
3834 snprintf(buf, bufn, "ans=%s%s%d", p, co,
3835 scrollcopyrect_min_area);
3836 goto qry;
3837 }
3838 p += strlen("scr_area:");
3839
3840 scrollcopyrect_min_area = atoi(p);
3841 rfbLog("remote_cmd: changed -scr_area to: %d\n",
3842 scrollcopyrect_min_area);
3843 goto done;
3844 }
3845 if (strstr(p, "scr_skip") == p) {
3846 char *s = scroll_skip_str;
3847 COLON_CHECK("scr_skip:")
3848 if (!s || *s == '\0') s = scroll_skip_str0;
3849 if (query) {
3850 snprintf(buf, bufn, "ans=%s%s%s", p, co, NONUL(s));
3851 goto qry;
3852 }
3853 p += strlen("scr_skip:");
3854 if (scroll_skip_str) {
3855 free(scroll_skip_str);
3856 }
3857
3858 scroll_skip_str = strdup(p);
3859 rfbLog("remote_cmd: changed -scr_skip to: %s\n",
3860 scroll_skip_str);
3861 initialize_scroll_matches();
3862 goto done;
3863 }
3864 if (strstr(p, "scr_inc") == p) {
3865 char *s = scroll_good_str;
3866 if (!s || *s == '\0') s = scroll_good_str0;
3867 COLON_CHECK("scr_inc:")
3868 if (query) {
3869 snprintf(buf, bufn, "ans=%s%s%s", p, co, NONUL(s));
3870 goto qry;
3871 }
3872 p += strlen("scr_inc:");
3873 if (scroll_good_str) {
3874 free(scroll_good_str);
3875 }
3876
3877 scroll_good_str = strdup(p);
3878 rfbLog("remote_cmd: changed -scr_inc to: %s\n",
3879 scroll_good_str);
3880 initialize_scroll_matches();
3881 goto done;
3882 }
3883 if (strstr(p, "scr_keys") == p) {
3884 COLON_CHECK("scr_keys:")
3885 if (query) {
3886 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3887 NONUL(scroll_key_list_str));
3888 goto qry;
3889 }
3890 p += strlen("scr_keys:");
3891 if (scroll_key_list_str) {
3892 free(scroll_key_list_str);
3893 }
3894
3895 scroll_key_list_str = strdup(p);
3896 rfbLog("remote_cmd: changed -scr_keys to: %s\n",
3897 scroll_key_list_str);
3898 initialize_scroll_keys();
3899 goto done;
3900 }
3901 if (strstr(p, "scr_term") == p) {
3902 char *s = scroll_term_str;
3903 if (!s || *s == '\0') s = scroll_term_str0;
3904 COLON_CHECK("scr_term:")
3905 if (query) {
3906 snprintf(buf, bufn, "ans=%s%s%s", p, co, NONUL(s));
3907 goto qry;
3908 }
3909 p += strlen("scr_term:");
3910 if (scroll_term_str) {
3911 free(scroll_term_str);
3912 }
3913
3914 scroll_term_str = strdup(p);
3915 rfbLog("remote_cmd: changed -scr_term to: %s\n",
3916 scroll_term_str);
3917 initialize_scroll_term();
3918 goto done;
3919 }
3920 if (strstr(p, "scr_keyrepeat") == p) {
3921 char *s = max_keyrepeat_str;
3922 if (!s || *s == '\0') s = max_keyrepeat_str0;
3923 COLON_CHECK("scr_keyrepeat:")
3924 if (query) {
3925 snprintf(buf, bufn, "ans=%s%s%s", p, co, NONUL(s));
3926 goto qry;
3927 }
3928 p += strlen("scr_keyrepeat:");
3929 if (max_keyrepeat_str) {
3930 free(max_keyrepeat_str);
3931 }
3932
3933 max_keyrepeat_str = strdup(p);
3934 rfbLog("remote_cmd: changed -scr_keyrepeat to: %s\n",
3935 max_keyrepeat_str);
3936 initialize_max_keyrepeat();
3937 goto done;
3938 }
3939 if (strstr(p, "scr_parms") == p) {
3940 COLON_CHECK("scr_parms:")
3941 if (query) {
3942 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3943 scroll_copyrect_str ? scroll_copyrect_str
3944 : SCROLL_COPYRECT_PARMS);
3945 goto qry;
3946 }
3947 p += strlen("scr_parms:");
3948 if (*p) {
3949 if (scroll_copyrect_str) {
3950 free(scroll_copyrect_str);
3951 }
3952 set_scrollcopyrect_mode("always");
3953 scroll_copyrect_str = strdup(p);
3954 parse_scroll_copyrect();
3955 }
3956 rfbLog("remote_cmd: set -scr_parms %s.\n",
3957 NONUL(scroll_copyrect_str));
3958 got_scrollcopyrect = 1;
3959 goto done;
3960 }
3961 if (strstr(p, "scrollcopyrect") == p) {
3962 COLON_CHECK("scrollcopyrect:")
3963 if (query) {
3964 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3965 NONUL(scroll_copyrect));
3966 goto qry;
3967 }
3968 p += strlen("scrollcopyrect:");
3969
3970 set_scrollcopyrect_mode(p);
3971 rfbLog("remote_cmd: changed -scrollcopyrect mode "
3972 "to: %s\n", NONUL(scroll_copyrect));
3973 got_scrollcopyrect = 1;
3974 goto done;
3975 }
3976 if (!strcmp(p, "scr") ||
3977 strstr(p, "scr:") == p) { /* skip-cmd-list */
3978 COLON_CHECK("scr:")
3979 if (query) {
3980 snprintf(buf, bufn, "ans=%s%s%s", p, co,
3981 NONUL(scroll_copyrect));
3982 goto qry;
3983 }
3984 p += strlen("scr:");
3985
3986 set_scrollcopyrect_mode(p);
3987 rfbLog("remote_cmd: changed -scrollcopyrect mode "
3988 "to: %s\n", NONUL(scroll_copyrect));
3989 got_scrollcopyrect = 1;
3990 goto done;
3991 }
3992 if (!strcmp(p, "noscrollcopyrect") || !strcmp(p, "noscr")) {
3993 if (query) {
3994 snprintf(buf, bufn, "ans=%s:%s", p,
3995 NONUL(scroll_copyrect));
3996 goto qry;
3997 }
3998
3999 set_scrollcopyrect_mode("never");
4000 rfbLog("remote_cmd: changed -scrollcopyrect mode "
4001 "to: %s\n", NONUL(scroll_copyrect));
4002 goto done;
4003 }
4004 if (strstr(p, "fixscreen") == p) {
4005 COLON_CHECK("fixscreen:")
4006 if (query) {
4007 snprintf(buf, bufn, "ans=%s%s%s", p, co,
4008 NONUL(screen_fixup_str));
4009 goto qry;
4010 }
4011 p += strlen("fixscreen:");
4012 if (screen_fixup_str) {
4013 free(screen_fixup_str);
4014 }
4015 screen_fixup_str = strdup(p);
4016 parse_fixscreen();
4017 rfbLog("remote_cmd: set -fixscreen %s.\n",
4018 NONUL(screen_fixup_str));
4019 goto done;
4020 }
4021 if (!strcmp(p, "noxrecord")) {
4022 int orig = noxrecord;
4023 if (query) {
4024 snprintf(buf, bufn, "ans=%s:%d", p, noxrecord);
4025 goto qry;
4026 }
4027 noxrecord = 1;
4028 rfbLog("set noxrecord to: %d\n", noxrecord);
4029 if (orig != noxrecord) {
4030 shutdown_xrecord();
4031 }
4032 goto done;
4033 }
4034 if (!strcmp(p, "xrecord")) {
4035 int orig = noxrecord;
4036 if (query) {
4037 snprintf(buf, bufn, "ans=%s:%d", p, !noxrecord);
4038 goto qry;
4039 }
4040 noxrecord = 0;
4041 rfbLog("set noxrecord to: %d\n", noxrecord);
4042 if (orig != noxrecord) {
4043 initialize_xrecord();
4044 }
4045 goto done;
4046 }
4047 if (!strcmp(p, "reset_record")) {
4048 NOTAPP
4049 if (use_xrecord) {
4050 rfbLog("resetting RECORD\n");
4051 check_xrecord_reset(1);
4052 } else {
4053 rfbLog("RECORD is disabled, not resetting.\n");
4054 }
4055 goto done;
4056 }
4057 if (strstr(p, "pointer_mode") == p) {
4058 int pm;
4059 COLON_CHECK("pointer_mode:")
4060 if (query) {
4061 snprintf(buf, bufn, "ans=%s%s%d", p, co, pointer_mode);
4062 goto qry;
4063 }
4064 p += strlen("pointer_mode:");
4065 pm = atoi(p);
4066 if (pm < 0 || pm > pointer_mode_max) {
4067 rfbLog("remote_cmd: pointer_mode out of range:"
4068 " 1-%d: %d\n", pointer_mode_max, pm);
4069 } else {
4070 rfbLog("remote_cmd: setting pointer_mode %d\n", pm);
4071 pointer_mode = pm;
4072 }
4073 goto done;
4074 }
4075 if (strstr(p, "pm") == p) {
4076 int pm;
4077 COLON_CHECK("pm:")
4078 if (query) {
4079 snprintf(buf, bufn, "ans=%s%s%d", p, co, pointer_mode);
4080 goto qry;
4081 }
4082 p += strlen("pm:");
4083 pm = atoi(p);
4084 if (pm < 0 || pm > pointer_mode_max) {
4085 rfbLog("remote_cmd: pointer_mode out of range:"
4086 " 1-%d: %d\n", pointer_mode_max, pm);
4087 } else {
4088 rfbLog("remote_cmd: setting pointer_mode %d\n", pm);
4089 pointer_mode = pm;
4090 }
4091 goto done;
4092 }
4093 if (strstr(p, "input_skip") == p) {
4094 int is;
4095 COLON_CHECK("input_skip:")
4096 if (query) {
4097 snprintf(buf, bufn, "ans=%s%s%d", p, co, ui_skip);
4098 goto qry;
4099 }
4100 p += strlen("input_skip:");
4101 is = atoi(p);
4102 rfbLog("remote_cmd: setting input_skip %d\n", is);
4103 ui_skip = is;
4104 goto done;
4105 }
4106 if (!strcmp(p, "allinput")) {
4107 if (query) {
4108 snprintf(buf, bufn, "ans=%s:%d", p, all_input);
4109 goto qry;
4110 }
4111 all_input = 1;
4112 rfbLog("enabled allinput\n");
4113 if (handle_events_eagerly) {
4114 rfbLog("disabled input_eagerly\n");
4115 handle_events_eagerly = 0;
4116 }
4117 goto done;
4118 }
4119 if (!strcmp(p, "noallinput")) {
4120 if (query) {
4121 snprintf(buf, bufn, "ans=%s:%d", p, !all_input);
4122 goto qry;
4123 }
4124 all_input = 0;
4125 rfbLog("disabled allinput\n");
4126 goto done;
4127 }
4128 if (!strcmp(p, "input_eagerly")) {
4129 if (query) {
4130 snprintf(buf, bufn, "ans=%s:%d", p, handle_events_eagerly);
4131 goto qry;
4132 }
4133 handle_events_eagerly = 1;
4134 rfbLog("enabled input_eagerly\n");
4135 if (all_input) {
4136 rfbLog("disabled allinput\n");
4137 all_input = 0;
4138 }
4139 goto done;
4140 }
4141 if (!strcmp(p, "noinput_eagerly")) {
4142 if (query) {
4143 snprintf(buf, bufn, "ans=%s:%d", p, !handle_events_eagerly);
4144 goto qry;
4145 }
4146 handle_events_eagerly = 0;
4147 rfbLog("disabled input_eagerly\n");
4148 goto done;
4149 }
4150 if (strstr(p, "input") == p) {
4151 int doit = 1;
4152 COLON_CHECK("input:")
4153 if (query) {
4154 snprintf(buf, bufn, "ans=%s%s%s", p, co,
4155 NONUL(allowed_input_str));
4156 goto qry;
4157 }
4158 p += strlen("input:");
4159 if (allowed_input_str && !strcmp(p, allowed_input_str)) { /* skip-cmd-list */
4160 doit = 0;
4161 }
4162 rfbLog("remote_cmd: setting input %s\n", p);
4163 if (allowed_input_str) free(allowed_input_str);
4164 if (*p == '\0') {
4165 allowed_input_str = NULL;
4166 } else {
4167 allowed_input_str = strdup(p);
4168 }
4169 if (doit) {
4170 initialize_allowed_input();
4171 }
4172 goto done;
4173 }
4174 if (!strcmp(p, "grabkbd")) {
4175 if (query) {
4176 snprintf(buf, bufn, "ans=%s:%d", p, grab_kbd);
4177 goto qry;
4178 }
4179 grab_kbd = 1;
4180 if (grab_always) {
4181 adjust_grabs(1, 0);
4182 }
4183 rfbLog("enabled grab_kbd\n");
4184 goto done;
4185 }
4186 if (!strcmp(p, "nograbkbd")) {
4187 int orig = grab_kbd;
4188 if (query) {
4189 snprintf(buf, bufn, "ans=%s:%d", p, !grab_kbd);
4190 goto qry;
4191 }
4192 grab_kbd = 0;
4193 if (orig && dpy) {
4194#if !NO_X11
4195 X_LOCK;
4196 XUngrabKeyboard(dpy, CurrentTime);
4197 X_UNLOCK;
4198#endif
4199 }
4200 rfbLog("disabled grab_kbd\n");
4201
4202 goto done;
4203 }
4204 if (!strcmp(p, "grabptr")) {
4205 if (query) {
4206 snprintf(buf, bufn, "ans=%s:%d", p, grab_ptr);
4207 goto qry;
4208 }
4209 grab_ptr = 1;
4210 if (grab_always) {
4211 adjust_grabs(1, 0);
4212 }
4213 rfbLog("enabled grab_ptr\n");
4214 goto done;
4215 }
4216 if (!strcmp(p, "ungrabboth")) {
4217 if (query) {
4218 snprintf(buf, bufn, "ans=%s:%d", p, ungrab_both);
4219 goto qry;
4220 }
4221 ungrab_both = 1;
4222 rfbLog("enabled ungrab_both\n");
4223 goto done;
4224 }
4225 if (!strcmp(p, "noungrabboth")) {
4226 if (query) {
4227 snprintf(buf, bufn, "ans=%s:%d", p, !ungrab_both);
4228 goto qry;
4229 }
4230 ungrab_both = 0;
4231 rfbLog("disabled ungrab_both\n");
4232 goto done;
4233 }
4234 if (!strcmp(p, "nograbptr")) {
4235 int orig = grab_ptr;
4236 if (query) {
4237 snprintf(buf, bufn, "ans=%s:%d", p, !grab_ptr);
4238 goto qry;
4239 }
4240 grab_ptr = 0;
4241 if (orig && dpy) {
4242#if !NO_X11
4243 X_LOCK;
4244 XUngrabPointer(dpy, CurrentTime);
4245 X_UNLOCK;
4246#endif
4247 }
4248 rfbLog("disabled grab_ptr\n");
4249 goto done;
4250 }
4251 if (!strcmp(p, "grabalways")) {
4252 if (query) {
4253 snprintf(buf, bufn, "ans=%s:%d", p, grab_always);
4254 goto qry;
4255 }
4256 grab_ptr = 1;
4257 grab_kbd = 1;
4258 grab_always = 1;
4259 adjust_grabs(1, 0);
4260 rfbLog("enabled grab_always\n");
4261 goto done;
4262 }
4263 if (!strcmp(p, "nograbalways")) {
4264 int orig = grab_always;
4265 if (query) {
4266 snprintf(buf, bufn, "ans=%s:%d", p, !grab_always);
4267 goto qry;
4268 }
4269 grab_ptr = 0;
4270 grab_kbd = 0;
4271 grab_always = 0;
4272 if (orig && dpy) {
4273#if !NO_X11
4274 X_LOCK;
4275 XUngrabKeyboard(dpy, CurrentTime);
4276 XUngrabPointer(dpy, CurrentTime);
4277 X_UNLOCK;
4278#endif
4279 }
4280 adjust_grabs(0, 0);
4281 rfbLog("disabled grab_always\n");
4282 goto done;
4283 }
4284 if (strstr(p, "grablocal") == p) {
4285 COLON_CHECK("grablocal:")
4286 if (query) {
4287 snprintf(buf, bufn, "ans=%s%s%d", p, co,
4288 grab_local);
4289 goto qry;
4290 }
4291 p += strlen("grablocal:");
4292
4293 grab_local = atoi(p);
4294 rfbLog("remote_cmd: changed -grablocal to: %d\n",
4295 grab_local);
4296 goto done;
4297 }
4298 if (strstr(p, "client_input") == p) {
4299 NOTAPP
4300 COLON_CHECK("client_input:")
4301 p += strlen("client_input:");
4302 set_client_input(p);
4303 goto done;
4304 }
4305 if (strstr(p, "ssltimeout") == p) {
4306 int is;
4307 COLON_CHECK("ssltimeout:")
4308 if (query) {
4309 snprintf(buf, bufn, "ans=%s%s%d", p, co,
4310 ssl_timeout_secs);
4311 goto qry;
4312 }
4313 p += strlen("ssltimeout:");
4314 is = atoi(p);
4315 rfbLog("remote_cmd: setting ssltimeout: %d\n", is);
4316 ssl_timeout_secs = is;
4317 goto done;
4318 }
4319 if (strstr(p, "speeds") == p) {
4320 COLON_CHECK("speeds:")
4321 if (query) {
4322 snprintf(buf, bufn, "ans=%s%s%s", p, co,
4323 NONUL(speeds_str));
4324 goto qry;
4325 }
4326 p += strlen("speeds:");
4327 if (speeds_str) free(speeds_str);
4328 speeds_str = strdup(p);
4329
4330 rfbLog("remote_cmd: setting -speeds to:\n\t'%s'\n", p);
4331 initialize_speeds();
4332 goto done;
4333 }
4334 if (strstr(p, "wmdt") == p) {
4335 COLON_CHECK("wmdt:")
4336 if (query) {
4337 snprintf(buf, bufn, "ans=%s%s%s", p, co,
4338 NONUL(wmdt_str));
4339 goto qry;
4340 }
4341 p += strlen("wmdt:");
4342 if (wmdt_str) free(wmdt_str);
4343 wmdt_str = strdup(p);
4344
4345 rfbLog("remote_cmd: setting -wmdt to: %s\n", p);
4346 goto done;
4347 }
4348 if (!strcmp(p, "debug_pointer") || !strcmp(p, "dp")) {
4349 if (query) {
4350 snprintf(buf, bufn, "ans=%s:%d", p, debug_pointer);
4351 goto qry;
4352 }
4353 rfbLog("remote_cmd: turning on debug_pointer.\n");
4354 debug_pointer = 1;
4355 goto done;
4356 }
4357 if (!strcmp(p, "nodebug_pointer") || !strcmp(p, "nodp")) {
4358 if (query) {
4359 snprintf(buf, bufn, "ans=%s:%d", p, !debug_pointer);
4360 goto qry;
4361 }
4362 rfbLog("remote_cmd: turning off debug_pointer.\n");
4363 debug_pointer = 0;
4364 goto done;
4365 }
4366 if (!strcmp(p, "debug_keyboard") || !strcmp(p, "dk")) {
4367 if (query) {
4368 snprintf(buf, bufn, "ans=%s:%d", p, debug_keyboard);
4369 goto qry;
4370 }
4371 rfbLog("remote_cmd: turning on debug_keyboard.\n");
4372 debug_keyboard = 1;
4373 goto done;
4374 }
4375 if (!strcmp(p, "nodebug_keyboard") || !strcmp(p, "nodk")) {
4376 if (query) {
4377 snprintf(buf, bufn, "ans=%s:%d", p, !debug_keyboard);
4378 goto qry;
4379 }
4380 rfbLog("remote_cmd: turning off debug_keyboard.\n");
4381 debug_keyboard = 0;
4382 goto done;
4383 }
4384 if (strstr(p, "keycode") == p) {
4385 int kc, down = -1;
4386 char *c;
4387 NOTAPP
4388 COLON_CHECK("keycode:")
4389 p += strlen("keycode:");
4390 kc = atoi(p);
4391 if (kc < 0) kc = 0;
4392 kc = kc % 256;
4393 c = strchr(p, ',');
4394 if (c) down = atoi(c+1);
4395 rfbLog("remote_cmd: insert keycode %d down=%d\n", kc, down);
4396
4397 if (macosx_console) {
4398#ifdef MACOSX
4399 if (down == -1) {
4400 macosxCG_keycode_inject(1, kc);
4401 usleep(50*1000);
4402 macosxCG_keycode_inject(0, kc);
4403 } else {
4404 macosxCG_keycode_inject(down, kc);
4405 }
4406#endif
4407 } else {
4408 X_LOCK;
4409 if (down == -1) {
4410 XTestFakeKeyEvent_wr(dpy, kc, 1, CurrentTime);
4411 usleep(50*1000);
4412 XTestFakeKeyEvent_wr(dpy, kc, 0, CurrentTime);
4413 } else {
4414 XTestFakeKeyEvent_wr(dpy, kc, down, CurrentTime);
4415 }
4416 XFlush_wr(dpy);
4417 X_UNLOCK;
4418 }
4419 goto done;
4420 }
4421 if (strstr(p, "keysym") == p) {
4422 int down = -1;
4423 unsigned int in;
4424 KeySym ks;
4425 char *c, *str;
4426 NOTAPP
4427 COLON_CHECK("keysym:")
4428 p += strlen("keysym:");
4429
4430 c = strchr(p, ',');
4431 if (c) {
4432 down = atoi(c+1);
4433 *c = '\0';
4434 }
4435
4436 if (sscanf(p, "0x%x", &in) == 1) {
4437 ks = (KeySym) in;
4438 } else if (sscanf(p, "%u", &in) == 1) {
4439 ks = (KeySym) in;
4440 } else if ((ks = XStringToKeysym(p)) != NoSymbol) {
4441 ;
4442 } else {
4443 rfbLog("remote_cmd: bad keysym: %s\n", p);
4444 goto done;
4445 }
4446 str = XKeysymToString(ks);
4447 str = str ? str : "NoSymbol";
4448 rfbLog("remote_cmd: insert keysym %s 0x%x '%s' down=%d\n", p, ks, str, down);
4449 if (down == -1) {
4450 keyboard(1, ks, NULL);
4451 usleep(50*1000);
4452 keyboard(0, ks, NULL);
4453 } else {
4454 keyboard(down, ks, NULL);
4455 }
4456 goto done;
4457 }
4458 if (strstr(p, "ptr") == p) {
4459 int x, y, m = 0;
4460 NOTAPP
4461 COLON_CHECK("ptr:")
4462 p += strlen("ptr:");
4463 rfbLog("remote_cmd: insert pointer event: %s\n", p);
4464 if (sscanf(p, "%d,%d,%d", &x, &y, &m) == 3) {
4465 pointer_event(m, x, y, NULL);
4466 } else if (sscanf(p, "%d,%d", &x, &y) == 2) {
4467 pointer_event(m, x, y, NULL);
4468 } else {
4469 rfbLog("remote_cmd: bad ptr:x,y,mask\n");
4470 }
4471
4472 goto done;
4473 }
4474 if (strstr(p, "fakebuttonevent") == p) {
4475 int mb, down = 0;
4476 NOTAPP
4477 COLON_CHECK("fakebuttonevent:")
4478 p += strlen("fakebuttonevent:");
4479 rfbLog("remote_cmd: insert fakebuttonevent: %s\n", p);
4480 if (sscanf(p, "%d,%d", &mb, &down) == 2) {
4481 X_LOCK;
4482 rfbLog("remote_cmd: XTestFakeButtonEvent(mb=%d, down=%d)\n", mb, down);
4483 XTestFakeButtonEvent_wr(dpy, mb, down ? True : False, CurrentTime);
4484 XFlush_wr(dpy);
4485 X_UNLOCK;
4486 }
4487
4488 goto done;
4489 }
4490 if (strstr(p, "sleep") == p) {
4491 NOTAPP
4492 COLON_CHECK("sleep:")
4493 p += strlen("sleep:");
4494 rfbLog("remote_cmd: sleeping: %s\n", p);
4495 usleep((int) (1.0e+6 * atof(p)));
4496 rfbLog("remote_cmd: done sleeping.\n");
4497 goto done;
4498 }
4499 if (strstr(p, "get_xprop") == p) {
4500 char *res;
4501 unsigned long id;
4502 Window win = None; /* None implies root in get_xprop() */
4503
4504 /* note we force query and assume the colon is there. */
4505 query = 1;
4506 if (strstr(p, "get_xprop:") != p) { /* skip-cmd-list */
4507 snprintf(buf, bufn, "ans=%s:N/A", p);
4508 goto qry;
4509 }
4510 p += strlen("get_xprop:");
4511
4512 if (strstr(p, "id=") == p) { /* skip-cmd-list */
4513 p += strlen("id=");
4514 if (scan_hexdec(p, &id)) {
4515 win = (Window) id;
4516 }
4517 if (strchr(p, ':')) {
4518 p = strchr(p, ':') + 1;
4519 }
4520 }
4521
4522 res = get_xprop(p, win);
4523 if (res == NULL) {
4524 res = strdup("NULL");
4525 }
4526 snprintf(buf, bufn, "ans=get_xprop:%s:%s", p, res);
4527 free(res);
4528
4529 goto qry;
4530 }
4531 if (strstr(p, "set_xprop") == p) {
4532 char *q;
4533 int rc = -2;
4534 unsigned long id;
4535 Window win = None; /* None implies root in set_xprop() */
4536
4537 /* note we force query and assume the colon is there. */
4538 query = 1;
4539 if (strstr(p, "set_xprop:") != p) { /* skip-cmd-list */
4540 snprintf(buf, bufn, "ans=%s:N/A", p);
4541 goto qry;
4542 }
4543 p += strlen("set_xprop:");
4544
4545 if (strstr(p, "id=") == p) { /* skip-cmd-list */
4546 p += strlen("id=");
4547 if (scan_hexdec(p, &id)) {
4548 win = (Window) id;
4549 }
4550 if (strchr(p, ':')) {
4551 p = strchr(p, ':') + 1;
4552 }
4553 }
4554
4555 q = strchr(p, ':');
4556 if (q) {
4557 *q = '\0';
4558 rc = set_xprop(p, win, q+1);
4559 *q = ':';
4560 }
4561 snprintf(buf, bufn, "ans=set_xprop:%s:%d", p, rc);
4562
4563 goto qry;
4564 }
4565 if (strstr(p, "wininfo") == p) {
4566 char *res, *t = "";
4567 unsigned long id;
4568 Window win = None;
4569 int show_children = 0;
4570
4571 /* note we force query and assume the colon is there. */
4572 query = 1;
4573 if (strstr(p, "wininfo:") != p) { /* skip-cmd-list */
4574 snprintf(buf, bufn, "ans=%s:N/A", p);
4575 goto qry;
4576 }
4577 p += strlen("wininfo:");
4578
4579 if (p[0] == '+') {
4580 show_children = 1;
4581 t = "+";
4582 p++;
4583 }
4584 if (!strcmp(p, "root")) { /* skip-cmd-list */
4585 win = rootwin;
4586 } else if (scan_hexdec(p, &id)) {
4587 win = (Window) id;
4588 }
4589
4590 res = wininfo(win, show_children);
4591 if (res == NULL) {
4592 res = strdup("NULL");
4593 }
4594 snprintf(buf, bufn, "ans=wininfo:%s%s:%s", t, p, res);
4595 free(res);
4596
4597 goto qry;
4598 }
4599 if (strstr(p, "bcx_xattach") == p) {
4600 char *res;
4601 int pg_init = -1, kg_init = -1;
4602 int try = 0, max_tries = 4;
4603
4604 /* note we force query and assume the colon is there. */
4605 query = 1;
4606 if (strstr(p, "bcx_xattach:") != p) { /* skip-cmd-list */
4607 snprintf(buf, bufn, "ans=%s:N/A", p);
4608 goto qry;
4609 }
4610 p += strlen("bcx_xattach:");
4611
4612 if (strstr(p, "retry=")) { /* skip-cmd-list */
4613 int n;
4614 char *q = strstr(p, "retry="); /* skip-cmd-list */
4615 if (sscanf(q, "retry=%d", &n) == 1) {
4616 if (n < 0) n = 0;
4617 max_tries = 1 + n;
4618 }
4619 }
4620
4621 try_again:
4622
4623 res = bcx_xattach(p, &pg_init, &kg_init);
4624 try++;
4625 if (res == NULL) {
4626 res = strdup("NULL");
4627 } else if (strstr(res, "GRAB_FAIL_INIT")) {
4628 rfbLog("bcx_xattach: failed grab check for '%s': %s. Final state OK, not Retrying.\n", p, res);
4629 } else if (strstr(res, "GRAB_FAIL") && try < max_tries) {
4630 rfbLog("bcx_xattach: failed grab check for '%s': %s. Retrying[%d]...\n", p, res, try);
4631 free(res);
4632 pointer_event(0, dpy_x/2 + try, dpy_y/2 + try, NULL);
4633#if !NO_X11
4634 X_LOCK;
4635 XFlush_wr(dpy);
4636 if (dpy) {
4637 if (try == 2) {
4638 XSync(dpy, False);
4639 } else if (try == 3) {
4640 XSync(dpy, True);
4641 }
4642 }
4643 X_UNLOCK;
4644#endif
4645 if (try == 1) {
4646 usleep(250*1000);
4647 } else if (try <= 4) {
4648 usleep(try*400*1000);
4649 } else {
4650 usleep(4*500*1000);
4651 }
4652 goto try_again;
4653 }
4654
4655 snprintf(buf, bufn, "ans=bcx_xattach:%s:%s", p, res);
4656 free(res);
4657
4658 goto qry;
4659 }
4660 if (strstr(p, "deferupdate") == p) {
4661 int d;
4662 COLON_CHECK("deferupdate:")
4663 if (query) {
4664 if (!screen) {
4665 d = defer_update;
4666 } else {
4667 d = screen->deferUpdateTime;
4668 }
4669 snprintf(buf, bufn, "ans=%s%s%d", p, co, d);
4670 goto qry;
4671 }
4672 p += strlen("deferupdate:");
4673 d = atoi(p);
4674 if (d < 0) d = 0;
4675 rfbLog("remote_cmd: setting defer to %d ms.\n", d);
4676 defer_update = d;
4677 /* mutex */
4678 screen->deferUpdateTime = d;
4679 got_defer = 1;
4680 goto done;
4681 }
4682 if (strstr(p, "defer") == p) {
4683 int d;
4684 COLON_CHECK("defer:")
4685 if (query) {
4686 if (!screen) {
4687 d = defer_update;
4688 } else {
4689 d = screen->deferUpdateTime;
4690 }
4691 snprintf(buf, bufn, "ans=%s%s%d", p, co, d);
4692 goto qry;
4693 }
4694 p += strlen("defer:");
4695 d = atoi(p);
4696 if (d < 0) d = 0;
4697 rfbLog("remote_cmd: setting defer to %d ms.\n", d);
4698 defer_update = d;
4699 /* mutex */
4700 screen->deferUpdateTime = d;
4701 got_defer = 1;
4702 goto done;
4703 }
4704 if (strstr(p, "setdefer") == p) {
4705 COLON_CHECK("setdefer:")
4706 if (query) {
4707 snprintf(buf, bufn, "ans=%s%s%d", p, co, set_defer);
4708 goto qry;
4709 }
4710 p += strlen("setdefer:");
4711 set_defer = atoi(p);
4712 rfbLog("remote_cmd: setting set_defer to %d\n", set_defer);
4713 goto done;
4714 }
4715 if (strstr(p, "extra_fbur") == p) {
4716 COLON_CHECK("extra_fbur:")
4717 if (query) {
4718 snprintf(buf, bufn, "ans=%s%s%d", p, co, extra_fbur);
4719 goto qry;
4720 }
4721 p += strlen("extra_fbur:");
4722 extra_fbur = atoi(p);
4723 rfbLog("remote_cmd: setting extra_fbur to %d\n", extra_fbur);
4724 goto done;
4725 }
4726 if (strstr(p, "wait_ui") == p) {
4727 double w;
4728 COLON_CHECK("wait_ui:")
4729 if (query) {
4730 snprintf(buf, bufn, "ans=%s%s%.2f", p, co, wait_ui);
4731 goto qry;
4732 }
4733 p += strlen("wait_ui:");
4734 w = atof(p);
4735 if (w <= 0) w = 1.0;
4736 rfbLog("remote_cmd: setting wait_ui factor %.2f -> %.2f\n",
4737 wait_ui, w);
4738 wait_ui = w;
4739 goto done;
4740 }
4741 if (!strcmp(p, "wait_bog")) {
4742 if (query) {
4743 snprintf(buf, bufn, "ans=%s:%d", p, wait_bog);
4744 goto qry;
4745 }
4746 wait_bog = 1;
4747 rfbLog("remote_cmd: setting wait_bog to %d\n", wait_bog);
4748 goto done;
4749 }
4750 if (!strcmp(p, "nowait_bog")) {
4751 if (query) {
4752 snprintf(buf, bufn, "ans=%s:%d", p, !wait_bog);
4753 goto qry;
4754 }
4755 wait_bog = 0;
4756 rfbLog("remote_cmd: setting wait_bog to %d\n", wait_bog);
4757 goto done;
4758 }
4759 if (strstr(p, "slow_fb") == p) {
4760 double w;
4761 COLON_CHECK("slow_fb:")
4762 if (query) {
4763 snprintf(buf, bufn, "ans=%s%s%.2f", p, co, slow_fb);
4764 goto qry;
4765 }
4766 p += strlen("slow_fb:");
4767 w = atof(p);
4768 if (w <= 0) w = 0.0;
4769 rfbLog("remote_cmd: setting slow_fb factor %.2f -> %.2f\n",
4770 slow_fb, w);
4771 slow_fb = w;
4772 goto done;
4773 }
4774 if (strstr(p, "xrefresh") == p) {
4775 double w;
4776 COLON_CHECK("xrefresh:")
4777 if (query) {
4778 snprintf(buf, bufn, "ans=%s%s%.2f", p, co, xrefresh);
4779 goto qry;
4780 }
4781 p += strlen("xrefresh:");
4782 w = atof(p);
4783 if (w <= 0) w = 0.0;
4784 rfbLog("remote_cmd: setting xrefresh delay %.2f -> %.2f\n",
4785 xrefresh, w);
4786 xrefresh = w;
4787 goto done;
4788 }
4789 if (strstr(p, "wait") == p) {
4790 int w;
4791 COLON_CHECK("wait:")
4792 if (query) {
4793 snprintf(buf, bufn, "ans=%s%s%d", p, co, waitms);
4794 goto qry;
4795 }
4796 p += strlen("wait:");
4797 w = atoi(p);
4798 if (w < 0) w = 0;
4799 rfbLog("remote_cmd: setting wait %d -> %d ms.\n", waitms, w);
4800 waitms = w;
4801 goto done;
4802 }
4803 if (strstr(p, "readtimeout") == p) {
4804 int w, orig = rfbMaxClientWait;
4805 COLON_CHECK("readtimeout:")
4806 if (query) {
4807 snprintf(buf, bufn, "ans=%s%s%d", p, co,
4808 rfbMaxClientWait/1000);
4809 goto qry;
4810 }
4811 p += strlen("readtimeout:");
4812 w = atoi(p) * 1000;
4813 if (w <= 0) w = 0;
4814 rfbLog("remote_cmd: setting rfbMaxClientWait %d -> "
4815 "%d msec.\n", orig, w);
4816 rfbMaxClientWait = w;
4817 goto done;
4818 }
4819 if (!strcmp(p, "nap")) {
4820 if (query) {
4821 snprintf(buf, bufn, "ans=%s:%d", p, take_naps);
4822 goto qry;
4823 }
4824 rfbLog("remote_cmd: turning on nap mode.\n");
4825 take_naps = 1;
4826 goto done;
4827 }
4828 if (!strcmp(p, "nonap")) {
4829 if (query) {
4830 snprintf(buf, bufn, "ans=%s:%d", p, !take_naps);
4831 goto qry;
4832 }
4833 rfbLog("remote_cmd: turning off nap mode.\n");
4834 take_naps = 0;
4835 goto done;
4836 }
4837 if (strstr(p, "sb") == p) {
4838 int w;
4839 COLON_CHECK("sb:")
4840 if (query) {
4841 snprintf(buf, bufn, "ans=%s%s%d", p, co, screen_blank);
4842 goto qry;
4843 }
4844 p += strlen("sb:");
4845 w = atoi(p);
4846 if (w < 0) w = 0;
4847 rfbLog("remote_cmd: setting screen_blank %d -> %d sec.\n",
4848 screen_blank, w);
4849 screen_blank = w;
4850 goto done;
4851 }
4852 if (strstr(p, "screen_blank") == p) {
4853 int w;
4854 COLON_CHECK("screen_blank:")
4855 if (query) {
4856 snprintf(buf, bufn, "ans=%s%s%d", p, co, screen_blank);
4857 goto qry;
4858 }
4859 p += strlen("screen_blank:");
4860 w = atoi(p);
4861 if (w < 0) w = 0;
4862 rfbLog("remote_cmd: setting screen_blank %d -> %d sec.\n",
4863 screen_blank, w);
4864 screen_blank = w;
4865 goto done;
4866 }
4867 if (!strcmp(p, "fbpm")) {
4868 if (query) {
4869 snprintf(buf, bufn, "ans=%s:%d", p, !watch_fbpm);
4870 goto qry;
4871 }
4872 rfbLog("remote_cmd: turning off -nofbpm mode.\n");
4873 watch_fbpm = 0;
4874 goto done;
4875 }
4876 if (!strcmp(p, "nofbpm")) {
4877 if (query) {
4878 snprintf(buf, bufn, "ans=%s:%d", p, watch_fbpm);
4879 goto qry;
4880 }
4881 rfbLog("remote_cmd: turning on -nofbpm mode.\n");
4882 watch_fbpm = 1;
4883 goto done;
4884 }
4885 if (!strcmp(p, "dpms")) {
4886 if (query) {
4887 snprintf(buf, bufn, "ans=%s:%d", p, !watch_dpms);
4888 goto qry;
4889 }
4890 rfbLog("remote_cmd: turning off -nodpms mode.\n");
4891 watch_dpms = 0;
4892 goto done;
4893 }
4894 if (!strcmp(p, "nodpms")) {
4895 if (query) {
4896 snprintf(buf, bufn, "ans=%s:%d", p, watch_dpms);
4897 goto qry;
4898 }
4899 rfbLog("remote_cmd: turning on -nodpms mode.\n");
4900 watch_dpms = 1;
4901 goto done;
4902 }
4903 if (!strcmp(p, "clientdpms")) {
4904 if (query) {
4905 snprintf(buf, bufn, "ans=%s:%d", p, client_dpms);
4906 goto qry;
4907 }
4908 rfbLog("remote_cmd: turning on -clientdpms mode.\n");
4909 client_dpms = 1;
4910 goto done;
4911 }
4912 if (!strcmp(p, "noclientdpms")) {
4913 if (query) {
4914 snprintf(buf, bufn, "ans=%s:%d", p, !client_dpms);
4915 goto qry;
4916 }
4917 rfbLog("remote_cmd: turning off -clientdpms mode.\n");
4918 client_dpms = 0;
4919 goto done;
4920 }
4921 if (!strcmp(p, "forcedpms")) {
4922 if (query) {
4923 snprintf(buf, bufn, "ans=%s:%d", p, force_dpms);
4924 goto qry;
4925 }
4926 rfbLog("remote_cmd: turning on -forcedpms mode.\n");
4927 force_dpms = 1;
4928 goto done;
4929 }
4930 if (!strcmp(p, "noforcedpms")) {
4931 if (query) {
4932 snprintf(buf, bufn, "ans=%s:%d", p, !force_dpms);
4933 goto qry;
4934 }
4935 rfbLog("remote_cmd: turning off -forcedpms mode.\n");
4936 force_dpms = 0;
4937 goto done;
4938 }
4939 if (!strcmp(p, "noserverdpms")) {
4940 if (query) {
4941 snprintf(buf, bufn, "ans=%s:%d", p, no_ultra_dpms);
4942 goto qry;
4943 }
4944 rfbLog("remote_cmd: turning on -noserverdpms mode.\n");
4945 no_ultra_dpms = 1;
4946 goto done;
4947 }
4948 if (!strcmp(p, "serverdpms")) {
4949 if (query) {
4950 snprintf(buf, bufn, "ans=%s:%d", p, !no_ultra_dpms);
4951 goto qry;
4952 }
4953 rfbLog("remote_cmd: turning off -noserverdpms mode.\n");
4954 no_ultra_dpms = 0;
4955 goto done;
4956 }
4957 if (!strcmp(p, "noultraext")) {
4958 if (query) {
4959 snprintf(buf, bufn, "ans=%s:%d", p, no_ultra_ext);
4960 goto qry;
4961 }
4962 rfbLog("remote_cmd: turning on -noultraext mode.\n");
4963 no_ultra_ext = 1;
4964 goto done;
4965 }
4966 if (!strcmp(p, "ultraext")) {
4967 if (query) {
4968 snprintf(buf, bufn, "ans=%s:%d", p, !no_ultra_ext);
4969 goto qry;
4970 }
4971 rfbLog("remote_cmd: turning off -noultraext mode.\n");
4972 no_ultra_ext = 0;
4973 goto done;
4974 }
4975 if (!strcmp(p, "chatwindow")) {
4976 if (query) {
4977 snprintf(buf, bufn, "ans=%s:%d", p, chat_window);
4978 goto qry;
4979 }
4980 rfbLog("remote_cmd: enabling the local chat window.\n");
4981 chat_window = 1;
4982 goto done;
4983 }
4984 if (!strcmp(p, "nochatwindow")) {
4985 if (query) {
4986 snprintf(buf, bufn, "ans=%s:%d", p, !chat_window);
4987 goto qry;
4988 }
4989 rfbLog("remote_cmd: disabling the local chat window.\n");
4990 chat_window = 0;
4991 goto done;
4992 }
4993 if (!strcmp(p, "chaton")) {
4994 if (query) {
4995 snprintf(buf, bufn, "ans=%s:%d", p, (chat_window_client != NULL));
4996 goto qry;
4997 }
4998 rfbLog("remote_cmd: turning local chat window on.\n");
4999 chat_window = 1;
5000 set_text_chat(NULL, rfbTextChatOpen, "");
5001 goto done;
5002 }
5003 if (!strcmp(p, "chatoff")) {
5004 if (query) {
5005 snprintf(buf, bufn, "ans=%s:%d", p, (chat_window_client == NULL));
5006 goto qry;
5007 }
5008 rfbLog("remote_cmd: turning local chat window off.\n");
5009 set_text_chat(NULL, rfbTextChatClose, "");
5010 set_text_chat(NULL, rfbTextChatFinished, "");
5011 goto done;
5012 }
5013 if (strstr(p, "fs") == p) {
5014 COLON_CHECK("fs:")
5015 if (query) {
5016 snprintf(buf, bufn, "ans=%s%s%f", p, co, fs_frac);
5017 goto qry;
5018 }
5019 p += strlen("fs:");
5020 fs_frac = atof(p);
5021 rfbLog("remote_cmd: setting -fs frac to %f\n", fs_frac);
5022 goto done;
5023 }
5024 if (strstr(p, "gaps") == p) {
5025 int g;
5026 COLON_CHECK("gaps:")
5027 if (query) {
5028 snprintf(buf, bufn, "ans=%s%s%d", p, co, gaps_fill);
5029 goto qry;
5030 }
5031 p += strlen("gaps:");
5032 g = atoi(p);
5033 if (g < 0) g = 0;
5034 rfbLog("remote_cmd: setting gaps_fill %d -> %d.\n",
5035 gaps_fill, g);
5036 gaps_fill = g;
5037 goto done;
5038 }
5039 if (strstr(p, "grow") == p) {
5040 int g;
5041 COLON_CHECK("grow:")
5042 if (query) {
5043 snprintf(buf, bufn, "ans=%s%s%d", p, co, grow_fill);
5044 goto qry;
5045 }
5046 p += strlen("grow:");
5047 g = atoi(p);
5048 if (g < 0) g = 0;
5049 rfbLog("remote_cmd: setting grow_fill %d -> %d.\n",
5050 grow_fill, g);
5051 grow_fill = g;
5052 goto done;
5053 }
5054 if (strstr(p, "fuzz") == p) {
5055 int f;
5056 COLON_CHECK("fuzz:")
5057 if (query) {
5058 snprintf(buf, bufn, "ans=%s%s%d", p, co, tile_fuzz);
5059 goto qry;
5060 }
5061 p += strlen("fuzz:");
5062 f = atoi(p);
5063 if (f < 0) f = 0;
5064 rfbLog("remote_cmd: setting tile_fuzz %d -> %d.\n",
5065 tile_fuzz, f);
5066 grow_fill = f;
5067 goto done;
5068 }
5069 if (!strcmp(p, "snapfb")) {
5070 int orig = use_snapfb;
5071 if (query) {
5072 snprintf(buf, bufn, "ans=%s:%d", p, use_snapfb);
5073 goto qry;
5074 }
5075 rfbLog("remote_cmd: turning on snapfb mode.\n");
5076 use_snapfb = 1;
5077 if (orig != use_snapfb) {
5078 do_new_fb(1);
5079 }
5080 goto done;
5081 }
5082 if (!strcmp(p, "nosnapfb")) {
5083 int orig = use_snapfb;
5084 if (query) {
5085 snprintf(buf, bufn, "ans=%s:%d", p, !use_snapfb);
5086 goto qry;
5087 }
5088 rfbLog("remote_cmd: turning off snapfb mode.\n");
5089 use_snapfb = 0;
5090 if (orig != use_snapfb) {
5091 do_new_fb(1);
5092 }
5093
5094 goto done;
5095 }
5096 if (strstr(p, "rawfb") == p) {
5097 COLON_CHECK("rawfb:")
5098 if (query) {
5099 snprintf(buf, bufn, "ans=%s%s%s", p, co,
5100 NONUL(raw_fb_str));
5101 goto qry;
5102 }
5103 p += strlen("rawfb:");
5104 if (raw_fb_str) free(raw_fb_str);
5105 raw_fb_str = strdup(p);
5106 if (safe_remote_only && strstr(p, "setup:") == p) { /* skip-cmd-list */
5107 /* n.b. we still allow filename, shm, of rawfb */
5108 fprintf(stderr, "unsafe rawfb setup: %s\n", p);
5109 exit(1);
5110 }
5111
5112 rfbLog("remote_cmd: setting -rawfb to:\n\t'%s'\n", p);
5113
5114 if (*raw_fb_str == '\0') {
5115 free(raw_fb_str);
5116 raw_fb_str = NULL;
5117 if (raw_fb_mmap) {
5118 munmap(raw_fb_addr, raw_fb_mmap);
5119 }
5120 if (raw_fb_fd >= 0) {
5121 close(raw_fb_fd);
5122 }
5123 raw_fb_fd = -1;
5124 raw_fb = NULL;
5125 raw_fb_addr = NULL;
5126 raw_fb_offset = 0;
5127 raw_fb_shm = 0;
5128 raw_fb_mmap = 0;
5129 raw_fb_seek = 0;
5130 rfbLog("restoring per-rawfb settings...\n");
5131 set_raw_fb_params(1);
5132 }
5133 rfbLog("hang on tight, here we go...\n");
5134 raw_fb_back_to_X = 1;
5135 do_new_fb(1);
5136 raw_fb_back_to_X = 0;
5137 goto done;
5138 }
5139 if (strstr(p, "uinput_accel") == p) {
5140 COLON_CHECK("uinput_accel:")
5141 if (query) {
5142 snprintf(buf, bufn, "ans=%s%s%s", p, co,
5143 NONUL(get_uinput_accel()));
5144 goto qry;
5145 }
5146 p += strlen("uinput_accel:");
5147 rfbLog("set_uinput_accel: %s\n", p);
5148 set_uinput_accel(p);
5149 goto done;
5150 }
5151 if (strstr(p, "uinput_thresh") == p) {
5152 COLON_CHECK("uinput_thresh:")
5153 if (query) {
5154 snprintf(buf, bufn, "ans=%s%s%s", p, co,
5155 NONUL(get_uinput_thresh()));
5156 goto qry;
5157 }
5158 p += strlen("uinput_thresh:");
5159 rfbLog("set_uinput_thresh: %s\n", p);
5160 set_uinput_thresh(p);
5161 goto done;
5162 }
5163 if (strstr(p, "uinput_reset") == p) {
5164 COLON_CHECK("uinput_reset:")
5165 if (query) {
5166 snprintf(buf, bufn, "ans=%s%s%d", p, co,
5167 get_uinput_reset());
5168 goto qry;
5169 }
5170 p += strlen("uinput_reset:");
5171 rfbLog("set_uinput_reset: %s\n", p);
5172 set_uinput_reset(atoi(p));
5173 goto done;
5174 }
5175 if (strstr(p, "uinput_always") == p) {
5176 COLON_CHECK("uinput_always:")
5177 if (query) {
5178 snprintf(buf, bufn, "ans=%s%s%d", p, co,
5179 get_uinput_always());
5180 goto qry;
5181 }
5182 p += strlen("uinput_always:");
5183 rfbLog("set_uinput_always: %s\n", p);
5184 set_uinput_always(atoi(p));
5185 goto done;
5186 }
5187 if (strstr(p, "progressive") == p) {
5188 int f;
5189 COLON_CHECK("progressive:")
5190 if (query) {
5191 if (!screen) {
5192 f = 0;
5193 } else {
5194 f = screen->progressiveSliceHeight;
5195 }
5196 snprintf(buf, bufn, "ans=%s%s%d", p, co, f);
5197 goto qry;
5198 }
5199 p += strlen("progressive:");
5200 f = atoi(p);
5201 if (f < 0) f = 0;
5202 rfbLog("remote_cmd: setting progressive %d -> %d.\n",
5203 screen->progressiveSliceHeight, f);
5204 /* mutex */
5205 screen->progressiveSliceHeight = f;
5206 goto done;
5207 }
5208 if (strstr(p, "rfbport") == p) {
5209 int rp, orig = screen ? screen->port : 5900;
5210 COLON_CHECK("rfbport:")
5211 if (query) {
5212 snprintf(buf, bufn, "ans=%s%s%d", p, co, orig);
5213 goto qry;
5214 }
5215 p += strlen("rfbport:");
5216 rp = atoi(p);
5217 reset_rfbport(orig, rp);
5218 goto done;
5219 }
5220 if (!strcmp(p, "http")) {
5221 if (query) {
5222 int ls = screen ? screen->httpListenSock : -1;
5223 snprintf(buf, bufn, "ans=%s:%d", p, (ls > -1));
5224 goto qry;
5225 }
5226 if (screen->httpListenSock > -1 || ipv6_http_fd > -1) {
5227 rfbLog("already listening for http connections.\n");
5228 } else {
5229 rfbLog("turning on listening for http connections.\n");
5230 if (check_httpdir()) {
5231 http_connections(1);
5232 }
5233 }
5234 goto done;
5235 }
5236 if (!strcmp(p, "nohttp")) {
5237 if (query) {
5238 int ls = screen ? screen->httpListenSock : -1;
5239 snprintf(buf, bufn, "ans=%s:%d", p, !(ls > -1));
5240 goto qry;
5241 }
5242 if (screen->httpListenSock < 0 && ipv6_http_fd < 0) {
5243 rfbLog("already not listening for http connections.\n");
5244 } else {
5245 rfbLog("turning off listening for http connections.\n");
5246 if (check_httpdir()) {
5247 http_connections(0);
5248 }
5249 }
5250 goto done;
5251 }
5252 if (strstr(p, "httpport") == p) {
5253 int hp, orig = screen ? screen->httpPort : 0;
5254 COLON_CHECK("httpport:")
5255 if (query) {
5256 snprintf(buf, bufn, "ans=%s%s%d", p, co, orig);
5257 goto qry;
5258 }
5259 p += strlen("httpport:");
5260 hp = atoi(p);
5261 reset_httpport(orig, hp);
5262 goto done;
5263 }
5264 if (strstr(p, "httpdir") == p) {
5265 COLON_CHECK("httpdir:")
5266 if (query) {
5267 snprintf(buf, bufn, "ans=%s%s%s", p, co,
5268 NONUL(http_dir));
5269 goto qry;
5270 }
5271 p += strlen("httpdir:");
5272 if (http_dir && !strcmp(http_dir, p)) {
5273 rfbLog("no change in httpdir: %s\n", http_dir);
5274 } else {
5275 if (http_dir) {
5276 free(http_dir);
5277 }
5278 http_dir = strdup(p);
5279 http_connections(0);
5280 if (*p != '\0') {
5281 http_connections(1);
5282 }
5283 }
5284 goto done;
5285 }
5286 if (!strcmp(p, "enablehttpproxy")) {
5287 if (query) {
5288 int ht = screen ? screen->httpEnableProxyConnect : 0;
5289 snprintf(buf, bufn, "ans=%s:%d", p, ht != 0);
5290 goto qry;
5291 }
5292 rfbLog("turning on enablehttpproxy.\n");
5293 /* mutex */
5294 screen->httpEnableProxyConnect = 1;
5295 goto done;
5296 }
5297 if (!strcmp(p, "noenablehttpproxy")) {
5298 if (query) {
5299 int ht = screen ? screen->httpEnableProxyConnect : 0;
5300 snprintf(buf, bufn, "ans=%s:%d", p, ht == 0);
5301 goto qry;
5302 }
5303 rfbLog("turning off enablehttpproxy.\n");
5304 screen->httpEnableProxyConnect = 0;
5305 goto done;
5306 }
5307 if (!strcmp(p, "alwaysshared")) {
5308 if (query) {
5309 int t = screen ? screen->alwaysShared : 0;
5310 snprintf(buf, bufn, "ans=%s:%d", p, t != 0);
5311 goto qry;
5312 }
5313 rfbLog("turning on alwaysshared.\n");
5314 screen->alwaysShared = 1;
5315 goto done;
5316 }
5317 if (!strcmp(p, "noalwaysshared")) {
5318 if (query) {
5319 int t = screen ? screen->alwaysShared : 0;
5320 snprintf(buf, bufn, "ans=%s:%d", p, t == 0);
5321 goto qry;
5322 }
5323 rfbLog("turning off alwaysshared.\n");
5324 screen->alwaysShared = 0;
5325 goto done;
5326 }
5327 if (!strcmp(p, "nevershared")) {
5328 if (query) {
5329 int t = screen ? screen->neverShared : 1;
5330 snprintf(buf, bufn, "ans=%s:%d", p, t != 0);
5331 goto qry;
5332 }
5333 rfbLog("turning on nevershared.\n");
5334 screen->neverShared = 1;
5335 goto done;
5336 }
5337 if (!strcmp(p, "noalwaysshared")) {
5338 if (query) {
5339 int t = screen ? screen->neverShared : 1;
5340 snprintf(buf, bufn, "ans=%s:%d", p, t == 0);
5341 goto qry;
5342 }
5343 rfbLog("turning off nevershared.\n");
5344 screen->neverShared = 0;
5345 goto done;
5346 }
5347 if (!strcmp(p, "dontdisconnect")) {
5348 if (query) {
5349 int t = screen ? screen->dontDisconnect : 1;
5350 snprintf(buf, bufn, "ans=%s:%d", p, t != 0);
5351 goto qry;
5352 }
5353 rfbLog("turning on dontdisconnect.\n");
5354 screen->dontDisconnect = 1;
5355 goto done;
5356 }
5357 if (!strcmp(p, "nodontdisconnect")) {
5358 if (query) {
5359 int t = screen ? screen->dontDisconnect : 1;
5360 snprintf(buf, bufn, "ans=%s:%d", p, t == 0);
5361 goto qry;
5362 }
5363 rfbLog("turning off dontdisconnect.\n");
5364 screen->dontDisconnect = 0;
5365 goto done;
5366 }
5367 if (!strcmp(p, "desktop") ||
5368 strstr(p, "desktop:") == p) { /* skip-cmd-list */
5369 COLON_CHECK("desktop:")
5370 if (query) {
5371 snprintf(buf, bufn, "ans=%s%s%s", p, co,
5372 NONUL(rfb_desktop_name));
5373 goto qry;
5374 }
5375 p += strlen("desktop:");
5376 if (rfb_desktop_name) {
5377 free(rfb_desktop_name);
5378 }
5379 rfb_desktop_name = strdup(p);
5380 /* mutex */
5381 screen->desktopName = rfb_desktop_name;
5382 rfbLog("remote_cmd: setting desktop name to %s\n",
5383 rfb_desktop_name);
5384 goto done;
5385 }
5386 if (!strcmp(p, "debug_xevents")) {
5387 if (query) {
5388 snprintf(buf, bufn, "ans=%s:%d", p, debug_xevents);
5389 goto qry;
5390 }
5391 debug_xevents = 1;
5392 rfbLog("set debug_xevents to: %d\n", debug_xevents);
5393 goto done;
5394 }
5395 if (!strcmp(p, "nodebug_xevents")) {
5396 if (query) {
5397 snprintf(buf, bufn, "ans=%s:%d", p, !debug_xevents);
5398 goto qry;
5399 }
5400 debug_xevents = 0;
5401 rfbLog("set debug_xevents to: %d\n", debug_xevents);
5402 goto done;
5403 }
5404 if (strstr(p, "debug_xevents") == p) {
5405 COLON_CHECK("debug_xevents:")
5406 if (query) {
5407 snprintf(buf, bufn, "ans=%s%s%d", p, co, debug_xevents);
5408 goto qry;
5409 }
5410 p += strlen("debug_xevents:");
5411 debug_xevents = atoi(p);
5412 rfbLog("set debug_xevents to: %d\n", debug_xevents);
5413 goto done;
5414 }
5415 if (!strcmp(p, "debug_xdamage")) {
5416 if (query) {
5417 snprintf(buf, bufn, "ans=%s:%d", p, debug_xdamage);
5418 goto qry;
5419 }
5420 debug_xdamage = 1;
5421 rfbLog("set debug_xdamage to: %d\n", debug_xdamage);
5422 goto done;
5423 }
5424 if (!strcmp(p, "nodebug_xdamage")) {
5425 if (query) {
5426 snprintf(buf, bufn, "ans=%s:%d", p, !debug_xdamage);
5427 goto qry;
5428 }
5429 debug_xdamage = 0;
5430 rfbLog("set debug_xdamage to: %d\n", debug_xdamage);
5431 goto done;
5432 }
5433 if (strstr(p, "debug_xdamage") == p) {
5434 COLON_CHECK("debug_xdamage:")
5435 if (query) {
5436 snprintf(buf, bufn, "ans=%s%s%d", p, co, debug_xdamage);
5437 goto qry;
5438 }
5439 p += strlen("debug_xdamage:");
5440 debug_xdamage = atoi(p);
5441 rfbLog("set debug_xdamage to: %d\n", debug_xdamage);
5442 goto done;
5443 }
5444 if (!strcmp(p, "debug_wireframe")) {
5445 if (query) {
5446 snprintf(buf, bufn, "ans=%s:%d", p, debug_wireframe);
5447 goto qry;
5448 }
5449 debug_wireframe = 1;
5450 rfbLog("set debug_wireframe to: %d\n", debug_wireframe);
5451 goto done;
5452 }
5453 if (!strcmp(p, "nodebug_wireframe")) {
5454 if (query) {
5455 snprintf(buf, bufn, "ans=%s:%d", p, !debug_wireframe);
5456 goto qry;
5457 }
5458 debug_wireframe = 0;
5459 rfbLog("set debug_wireframe to: %d\n", debug_wireframe);
5460 goto done;
5461 }
5462 if (strstr(p, "debug_wireframe") == p) {
5463 COLON_CHECK("debug_wireframe:")
5464 if (query) {
5465 snprintf(buf, bufn, "ans=%s%s%d", p, co,
5466 debug_wireframe);
5467 goto qry;
5468 }
5469 p += strlen("debug_wireframe:");
5470 debug_wireframe = atoi(p);
5471 rfbLog("set debug_wireframe to: %d\n", debug_wireframe);
5472 goto done;
5473 }
5474 if (!strcmp(p, "debug_scroll")) {
5475 if (query) {
5476 snprintf(buf, bufn, "ans=%s:%d", p, debug_scroll);
5477 goto qry;
5478 }
5479 debug_scroll = 1;
5480 rfbLog("set debug_scroll to: %d\n", debug_scroll);
5481 goto done;
5482 }
5483 if (!strcmp(p, "nodebug_scroll")) {
5484 if (query) {
5485 snprintf(buf, bufn, "ans=%s:%d", p, !debug_scroll);
5486 goto qry;
5487 }
5488 debug_scroll = 0;
5489 rfbLog("set debug_scroll to: %d\n", debug_scroll);
5490 goto done;
5491 }
5492 if (strstr(p, "debug_scroll") == p) {
5493 COLON_CHECK("debug_scroll:")
5494 if (query) {
5495 snprintf(buf, bufn, "ans=%s%s%d", p, co,
5496 debug_scroll);
5497 goto qry;
5498 }
5499 p += strlen("debug_scroll:");
5500 debug_scroll = atoi(p);
5501 rfbLog("set debug_scroll to: %d\n", debug_scroll);
5502 goto done;
5503 }
5504 if (!strcmp(p, "debug_tiles") || !strcmp(p, "dbt")) {
5505 if (query) {
5506 snprintf(buf, bufn, "ans=%s:%d", p, debug_tiles);
5507 goto qry;
5508 }
5509 debug_tiles = 1;
5510 rfbLog("set debug_tiles to: %d\n", debug_tiles);
5511 goto done;
5512 }
5513 if (!strcmp(p, "nodebug_tiles") || !strcmp(p, "nodbt")) {
5514 if (query) {
5515 snprintf(buf, bufn, "ans=%s:%d", p, !debug_tiles);
5516 goto qry;
5517 }
5518 debug_tiles = 0;
5519 rfbLog("set debug_tiles to: %d\n", debug_tiles);
5520 goto done;
5521 }
5522 if (strstr(p, "debug_tiles") == p) {
5523 COLON_CHECK("debug_tiles:")
5524 if (query) {
5525 snprintf(buf, bufn, "ans=%s%s%d", p, co,
5526 debug_tiles);
5527 goto qry;
5528 }
5529 p += strlen("debug_tiles:");
5530 debug_tiles = atoi(p);
5531 rfbLog("set debug_tiles to: %d\n", debug_tiles);
5532 goto done;
5533 }
5534 if (!strcmp(p, "debug_grabs")) {
5535 if (query) {
5536 snprintf(buf, bufn, "ans=%s:%d", p, debug_grabs);
5537 goto qry;
5538 }
5539 debug_grabs = 1;
5540 rfbLog("set debug_grabs to: %d\n", debug_grabs);
5541 goto done;
5542 }
5543 if (!strcmp(p, "nodebug_grabs")) {
5544 if (query) {
5545 snprintf(buf, bufn, "ans=%s:%d", p, !debug_grabs);
5546 goto qry;
5547 }
5548 debug_grabs = 0;
5549 rfbLog("set debug_grabs to: %d\n", debug_grabs);
5550 goto done;
5551 }
5552 if (!strcmp(p, "debug_sel")) {
5553 if (query) {
5554 snprintf(buf, bufn, "ans=%s:%d", p, debug_sel);
5555 goto qry;
5556 }
5557 debug_sel = 1;
5558 rfbLog("set debug_sel to: %d\n", debug_sel);
5559 goto done;
5560 }
5561 if (!strcmp(p, "nodebug_sel")) {
5562 if (query) {
5563 snprintf(buf, bufn, "ans=%s:%d", p, !debug_sel);
5564 goto qry;
5565 }
5566 debug_sel = 0;
5567 rfbLog("set debug_sel to: %d\n", debug_sel);
5568 goto done;
5569 }
5570 if (!strcmp(p, "dbg")) {
5571 if (query) {
5572 snprintf(buf, bufn, "ans=%s:%d", p, crash_debug);
5573 goto qry;
5574 }
5575 crash_debug = 1;
5576 rfbLog("set crash_debug to: %d\n", crash_debug);
5577 goto done;
5578 }
5579 if (!strcmp(p, "nodbg")) {
5580 if (query) {
5581 snprintf(buf, bufn, "ans=%s:%d", p, !crash_debug);
5582 goto qry;
5583 }
5584 crash_debug = 0;
5585 rfbLog("set crash_debug to: %d\n", crash_debug);
5586 goto done;
5587 }
5588 if (!strcmp(p, "macnosaver")) {
5589 if (query) {
5590 snprintf(buf, bufn, "ans=%s:%d", p, macosx_noscreensaver); goto qry;
5591 }
5592 rfbLog("remote_cmd: turn on macnosaver.\n");
5593 macosx_noscreensaver = 1;
5594 goto done;
5595 }
5596 if (!strcmp(p, "macsaver") || !strcmp(p, "nomacnosaver")) {
5597 if (query) {
5598 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_noscreensaver); goto qry;
5599 }
5600 rfbLog("remote_cmd: turn off macnosaver.\n");
5601 macosx_noscreensaver = 0;
5602 goto done;
5603 }
5604 if (!strcmp(p, "macnowait")) {
5605 if (query) {
5606 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_wait_for_switch); goto qry;
5607 }
5608 rfbLog("remote_cmd: disable macosx_wait_for_switch.\n");
5609 macosx_wait_for_switch = 0;
5610 goto done;
5611 }
5612 if (!strcmp(p, "macwait") || !strcmp(p, "nomacnowait")) {
5613 if (query) {
5614 snprintf(buf, bufn, "ans=%s:%d", p, macosx_wait_for_switch); goto qry;
5615 }
5616 rfbLog("remote_cmd: enable macosx_wait_for_switch.\n");
5617 macosx_wait_for_switch = 1;
5618 goto done;
5619 }
5620 if (strstr(p, "macwheel") == p) {
5621 COLON_CHECK("macwheel:")
5622 if (query) {
5623 snprintf(buf, bufn, "ans=%s%s%d", p, co, macosx_mouse_wheel_speed);
5624 goto qry;
5625 }
5626 p += strlen("macwheel:");
5627 macosx_mouse_wheel_speed = atoi(p);
5628 rfbLog("set macosx_mouse_wheel_speed to: %d\n", macosx_mouse_wheel_speed);
5629 goto done;
5630 }
5631 if (!strcmp(p, "macnoswap")) {
5632 if (query) {
5633 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_swap23); goto qry;
5634 }
5635 rfbLog("remote_cmd: disable macosx_swap23.\n");
5636 macosx_swap23 = 0;
5637 goto done;
5638 }
5639 if (!strcmp(p, "macswap") || !strcmp(p, "nomacnoswap")) {
5640 if (query) {
5641 snprintf(buf, bufn, "ans=%s:%d", p, macosx_swap23); goto qry;
5642 }
5643 rfbLog("remote_cmd: enable macosx_swap23.\n");
5644 macosx_swap23 = 1;
5645 goto done;
5646 }
5647 if (!strcmp(p, "macnoresize")) {
5648 if (query) {
5649 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_resize); goto qry;
5650 }
5651 rfbLog("remote_cmd: disable macosx_resize.\n");
5652 macosx_resize = 0;
5653 goto done;
5654 }
5655 if (!strcmp(p, "macresize") || !strcmp(p, "nomacnoresize")) {
5656 if (query) {
5657 snprintf(buf, bufn, "ans=%s:%d", p, macosx_resize); goto qry;
5658 }
5659 rfbLog("remote_cmd: enable macosx_resize.\n");
5660 macosx_resize = 1;
5661 goto done;
5662 }
5663 if (strstr(p, "maciconanim") == p) {
5664 COLON_CHECK("maciconanim:")
5665 if (query) {
5666 snprintf(buf, bufn, "ans=%s%s%d", p, co, macosx_icon_anim_time);
5667 goto qry;
5668 }
5669 p += strlen("maciconanim:");
5670 macosx_icon_anim_time = atoi(p);
5671 rfbLog("set macosx_icon_anim_time to: %d\n", macosx_icon_anim_time);
5672 goto done;
5673 }
5674 if (!strcmp(p, "macmenu")) {
5675 if (query) {
5676 snprintf(buf, bufn, "ans=%s:%d", p, macosx_ncache_macmenu); goto qry;
5677 }
5678 rfbLog("remote_cmd: enable macosx_ncache_macmenu.\n");
5679 macosx_ncache_macmenu = 1;
5680 goto done;
5681 }
5682 if (!strcmp(p, "macnomenu") || !strcmp(p, "nomacmenu")) {
5683 if (query) {
5684 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_ncache_macmenu); goto qry;
5685 }
5686 rfbLog("remote_cmd: disable macosx_ncache_macmenu.\n");
5687 macosx_ncache_macmenu = 0;
5688 goto done;
5689 }
5690 if (!strcmp(p, "macuskbd")) {
5691 if (query) {
5692 snprintf(buf, bufn, "ans=%s:%d", p, macosx_us_kbd); goto qry;
5693 }
5694 rfbLog("remote_cmd: enable macosx_us_kbd.\n");
5695 macosx_us_kbd = 1;
5696 goto done;
5697 }
5698 if (!strcmp(p, "nomacuskbd")) {
5699 if (query) {
5700 snprintf(buf, bufn, "ans=%s:%d", p, !macosx_us_kbd); goto qry;
5701 }
5702 rfbLog("remote_cmd: disable macosx_us_kbd.\n");
5703 macosx_us_kbd = 0;
5704 goto done;
5705 }
5706 if (strstr(p, "hack") == p) { /* skip-cmd-list */
5707 COLON_CHECK("hack:")
5708 if (query) {
5709 snprintf(buf, bufn, "ans=%s%s%d", p, co, hack_val);
5710 goto qry;
5711 }
5712 p += strlen("hack:");
5713 hack_val = atoi(p);
5714 rfbLog("set hack_val to: %d\n", hack_val);
5715 goto done;
5716 }
5717 if (!strcmp(p, "noremote")) {
5718 if (query) {
5719 snprintf(buf, bufn, "ans=%s:%d", p,
5720 !accept_remote_cmds);
5721 goto qry;
5722 }
5723 rfbLog("remote_cmd: disabling remote commands.\n");
5724 accept_remote_cmds = 0; /* cannot be turned back on. */
5725 goto done;
5726 }
5727 if (strstr(p, "client_info_sock") == p) { /* skip-cmd-list */
5728 NOTAPP
5729 p += strlen("client_info_sock:");
5730 if (*p != '\0') {
5731 start_client_info_sock(p);
5732 }
5733 goto done;
5734 }
5735 if (strstr(p, "noop") == p) {
5736 NOTAPP
5737 rfbLog("remote_cmd: noop\n");
5738 goto done;
5739 }
5740 if (icon_mode && !query && strstr(p, "passwd") == p) { /* skip-cmd-list */
5741 char **passwds_new = (char **) malloc(3*sizeof(char *));
5742 char **passwds_old = (char **) screen->authPasswdData;
5743
5744 COLON_CHECK("passwd:")
5745 p += strlen("passwd:");
5746
5747 passwds_new[0] = strdup(p);
5748
5749 /* mutex */
5750 if (screen->authPasswdData &&
5751 screen->passwordCheck == rfbCheckPasswordByList) {
5752 passwds_new[1] = passwds_old[1];
5753 } else {
5754 passwds_new[1] = NULL;
5755 screen->passwordCheck = rfbCheckPasswordByList;
5756 }
5757 passwds_new[2] = NULL;
5758
5759 screen->authPasswdData = (void*) passwds_new;
5760 if (*p == '\0') {
5761 screen->authPasswdData = (void*) NULL;
5762 }
5763 rfbLog("remote_cmd: changed full access passwd.\n");
5764 goto done;
5765 }
5766 if (icon_mode && !query && strstr(p, "viewpasswd") == p) { /* skip-cmd-list */
5767 char **passwds_new = (char **) malloc(3*sizeof(char *));
5768 char **passwds_old = (char **) screen->authPasswdData;
5769
5770 COLON_CHECK("viewpasswd:")
5771 p += strlen("viewpasswd:");
5772
5773 passwds_new[1] = strdup(p);
5774
5775 if (screen->authPasswdData &&
5776 screen->passwordCheck == rfbCheckPasswordByList) {
5777 passwds_new[0] = passwds_old[0];
5778 } else {
5779 char *tmp = (char *) malloc(4 + CHALLENGESIZE);
5780 rfbRandomBytes((unsigned char*)tmp);
5781 passwds_new[0] = tmp;
5782 screen->passwordCheck = rfbCheckPasswordByList;
5783 }
5784 passwds_new[2] = NULL;
5785
5786 if (*p == '\0') {
5787 passwds_new[1] = NULL;
5788 }
5789
5790 screen->authPasswdData = (void*) passwds_new;
5791 rfbLog("remote_cmd: changed view only passwd.\n");
5792 goto done;
5793 }
5794 if (strstr(p, "trayembed") == p) { /* skip-cmd-list */
5795 unsigned long id;
5796 NOTAPP
5797
5798 COLON_CHECK("trayembed:")
5799 p += strlen("trayembed:");
5800 if (scan_hexdec(p, &id)) {
5801 tray_request = (Window) id;
5802 tray_unembed = 0;
5803 rfbLog("remote_cmd: will try to embed 0x%x in"
5804 " the system tray.\n", id);
5805 }
5806 goto done;
5807 }
5808 if (strstr(p, "trayunembed") == p) { /* skip-cmd-list */
5809 unsigned long id;
5810 NOTAPP
5811
5812 COLON_CHECK("trayunembed:")
5813 p += strlen("trayunembed:");
5814 if (scan_hexdec(p, &id)) {
5815 tray_request = (Window) id;
5816 tray_unembed = 1;
5817 rfbLog("remote_cmd: will try to unembed 0x%x out"
5818 " of the system tray.\n", id);
5819 }
5820 goto done;
5821 }
5822 if (query) {
5823 /* read-only variables that can only be queried: */
5824
5825 if (!strcmp(p, "display")) {
5826 if (raw_fb) {
5827 snprintf(buf, bufn, "aro=%s:rawfb:%p",
5828 p, raw_fb_addr);
5829 } else if (! dpy) {
5830 snprintf(buf, bufn, "aro=%s:", p);
5831 } else {
5832 char *d;
5833 d = DisplayString(dpy);
5834 if (! d) d = "unknown";
5835 if (*d == ':') {
5836 snprintf(buf, bufn, "aro=%s:%s%s", p,
5837 this_host(), d);
5838 } else {
5839 snprintf(buf, bufn, "aro=%s:%s", p, d);
5840 }
5841 }
5842 goto qry;
5843 }
5844 if (!strcmp(p, "vncdisplay")) {
5845 snprintf(buf, bufn, "aro=%s:%s", p,
5846 NONUL(vnc_desktop_name));
5847 goto qry;
5848 }
5849 if (!strcmp(p, "icon_mode")) {
5850 snprintf(buf, bufn, "aro=%s:%d", p, icon_mode);
5851 goto qry;
5852 }
5853 if (!strcmp(p, "autoport")) {
5854 snprintf(buf, bufn, "aro=%s:%d", p, auto_port);
5855 goto qry;
5856 }
5857 if (!strcmp(p, "loop") || !strcmp(p, "loopbg")) {
5858 snprintf(buf, bufn, "aro=%s:%d", p, 0);
5859 goto qry;
5860 }
5861 if (!strcmp(p, "desktopname")) {
5862 snprintf(buf, bufn, "aro=%s:%s", p,
5863 NONUL(rfb_desktop_name));
5864 goto qry;
5865 }
5866 if (!strcmp(p, "guess_desktop")) {
5867 snprintf(buf, bufn, "aro=%s:%s", p,
5868 NONUL(guess_desktop()));
5869 goto qry;
5870 }
5871 if (!strcmp(p, "guess_dbus")) {
5872 snprintf(buf, bufn, "aro=%s:%s", p,
5873 NONUL(dbus_session()));
5874 goto qry;
5875 }
5876 if (!strcmp(p, "http_url")) {
5877 if (!screen) {
5878 snprintf(buf, bufn, "aro=%s:", p);
5879 } else if (screen->httpListenSock > -1) {
5880 snprintf(buf, bufn, "aro=%s:http://%s:%d", p,
5881 NONUL(screen->thisHost), screen->httpPort);
5882 } else {
5883 snprintf(buf, bufn, "aro=%s:%s", p,
5884 "http_not_active");
5885 }
5886 goto qry;
5887 }
5888 if (!strcmp(p, "auth") || !strcmp(p, "xauth")) {
5889 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(auth_file));
5890 goto qry;
5891 }
5892 if (!strcmp(p, "users")) {
5893 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(users_list));
5894 goto qry;
5895 }
5896 if (!strcmp(p, "rootshift")) {
5897 snprintf(buf, bufn, "aro=%s:%d", p, rootshift);
5898 goto qry;
5899 }
5900 if (!strcmp(p, "clipshift")) {
5901 snprintf(buf, bufn, "aro=%s:%d", p, clipshift);
5902 goto qry;
5903 }
5904 if (!strcmp(p, "scale_str")) {
5905 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(scale_str));
5906 goto qry;
5907 }
5908 if (!strcmp(p, "scaled_x")) {
5909 snprintf(buf, bufn, "aro=%s:%d", p, scaled_x);
5910 goto qry;
5911 }
5912 if (!strcmp(p, "scaled_y")) {
5913 snprintf(buf, bufn, "aro=%s:%d", p, scaled_y);
5914 goto qry;
5915 }
5916 if (!strcmp(p, "scale_numer")) {
5917 snprintf(buf, bufn, "aro=%s:%d", p, scale_numer);
5918 goto qry;
5919 }
5920 if (!strcmp(p, "scale_denom")) {
5921 snprintf(buf, bufn, "aro=%s:%d", p, scale_denom);
5922 goto qry;
5923 }
5924 if (!strcmp(p, "scale_fac_x")) {
5925 snprintf(buf, bufn, "aro=%s:%f", p, scale_fac_x);
5926 goto qry;
5927 }
5928 if (!strcmp(p, "scale_fac_y")) {
5929 snprintf(buf, bufn, "aro=%s:%f", p, scale_fac_y);
5930 goto qry;
5931 }
5932 if (!strcmp(p, "scaling_blend")) {
5933 snprintf(buf, bufn, "aro=%s:%d", p, scaling_blend);
5934 goto qry;
5935 }
5936 if (!strcmp(p, "scaling_nomult4")) {
5937 snprintf(buf, bufn, "aro=%s:%d", p, scaling_nomult4);
5938 goto qry;
5939 }
5940 if (!strcmp(p, "scaling_pad")) {
5941 snprintf(buf, bufn, "aro=%s:%d", p, scaling_pad);
5942 goto qry;
5943 }
5944 if (!strcmp(p, "scaling_interpolate")) {
5945 snprintf(buf, bufn, "aro=%s:%d", p,
5946 scaling_interpolate);
5947 goto qry;
5948 }
5949 if (!strcmp(p, "inetd")) {
5950 snprintf(buf, bufn, "aro=%s:%d", p, inetd);
5951 goto qry;
5952 }
5953 if (!strcmp(p, "privremote")) {
5954 snprintf(buf, bufn, "aro=%s:%d", p, priv_remote);
5955 goto qry;
5956 }
5957 if (!strcmp(p, "unsafe")) {
5958 snprintf(buf, bufn, "aro=%s:%d", p, !safe_remote_only);
5959 goto qry;
5960 }
5961 if (!strcmp(p, "safer")) {
5962 snprintf(buf, bufn, "aro=%s:%d", p, more_safe);
5963 goto qry;
5964 }
5965 if (!strcmp(p, "nocmds")) {
5966 snprintf(buf, bufn, "aro=%s:%d", p, no_external_cmds);
5967 goto qry;
5968 }
5969 if (!strcmp(p, "passwdfile")) {
5970 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(passwdfile));
5971 goto qry;
5972 }
5973 if (!strcmp(p, "unixpw")) {
5974 snprintf(buf, bufn, "aro=%s:%d", p, unixpw);
5975 goto qry;
5976 }
5977 if (!strcmp(p, "unixpw_nis")) {
5978 snprintf(buf, bufn, "aro=%s:%d", p, unixpw_nis);
5979 goto qry;
5980 }
5981 if (!strcmp(p, "unixpw_list")) {
5982 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(unixpw_list));
5983 goto qry;
5984 }
5985 if (!strcmp(p, "ssl")) {
5986 snprintf(buf, bufn, "aro=%s:%d", p, use_openssl);
5987 goto qry;
5988 }
5989 if (!strcmp(p, "ssl_pem")) {
5990 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(openssl_pem));
5991 goto qry;
5992 }
5993 if (!strcmp(p, "sslverify")) {
5994 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(ssl_verify));
5995 goto qry;
5996 }
5997 if (!strcmp(p, "stunnel")) {
5998 snprintf(buf, bufn, "aro=%s:%d", p, use_stunnel);
5999 goto qry;
6000 }
6001 if (!strcmp(p, "stunnel_pem")) {
6002 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(stunnel_pem));
6003 goto qry;
6004 }
6005 if (!strcmp(p, "https")) {
6006 snprintf(buf, bufn, "aro=%s:%d", p, https_port_num);
6007 goto qry;
6008 }
6009 if (!strcmp(p, "httpsredir")) {
6010 snprintf(buf, bufn, "aro=%s:%d", p, https_port_redir);
6011 goto qry;
6012 }
6013 if (!strcmp(p, "usepw")) {
6014 snprintf(buf, bufn, "aro=%s:%d", p, usepw);
6015 goto qry;
6016 }
6017 if (!strcmp(p, "using_shm")) {
6018 snprintf(buf, bufn, "aro=%s:%d", p, !using_shm);
6019 goto qry;
6020 }
6021 if (!strcmp(p, "logfile") || !strcmp(p, "o")) {
6022 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(logfile));
6023 goto qry;
6024 }
6025 if (!strcmp(p, "flag")) {
6026 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(flagfile));
6027 goto qry;
6028 }
6029 if (!strcmp(p, "rmflag")) {
6030 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(rm_flagfile));
6031 goto qry;
6032 }
6033 if (!strcmp(p, "rc")) {
6034 char *s = rc_rcfile;
6035 if (rc_rcfile_default) {
6036 s = NULL;
6037 }
6038 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(s));
6039 goto qry;
6040 }
6041 if (!strcmp(p, "norc")) {
6042 snprintf(buf, bufn, "aro=%s:%d", p, got_norc);
6043 goto qry;
6044 }
6045 if (!strcmp(p, "h") || !strcmp(p, "help") ||
6046 !strcmp(p, "V") || !strcmp(p, "version") ||
6047 !strcmp(p, "lastmod")) {
6048 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(lastmod));
6049 goto qry;
6050 }
6051 if (!strcmp(p, "bg")) {
6052 snprintf(buf, bufn, "aro=%s:%d", p, opts_bg);
6053 goto qry;
6054 }
6055 if (!strcmp(p, "sigpipe")) {
6056 snprintf(buf, bufn, "aro=%s:%s", p, NONUL(sigpipe));
6057 goto qry;
6058 }
6059 if (!strcmp(p, "threads")) {
6060 snprintf(buf, bufn, "aro=%s:%d", p, use_threads);
6061 goto qry;
6062 }
6063 if (!strcmp(p, "readrate")) {
6064 snprintf(buf, bufn, "aro=%s:%d", p, get_read_rate());
6065 goto qry;
6066 }
6067 if (!strcmp(p, "netrate")) {
6068 snprintf(buf, bufn, "aro=%s:%d", p, get_net_rate());
6069 goto qry;
6070 }
6071 if (!strcmp(p, "netlatency")) {
6072 snprintf(buf, bufn, "aro=%s:%d", p, get_net_latency());
6073 goto qry;
6074 }
6075 if (!strcmp(p, "pipeinput")) {
6076 snprintf(buf, bufn, "aro=%s:%s", p,
6077 NONUL(pipeinput_str));
6078 goto qry;
6079 }
6080 if (!strcmp(p, "clients")) {
6081 char *str = list_clients();
6082 snprintf(buf, bufn, "aro=%s:%s", p, str);
6083 free(str);
6084 goto qry;
6085 }
6086 if (!strcmp(p, "client_count")) {
6087 snprintf(buf, bufn, "aro=%s:%d", p, client_count);
6088 goto qry;
6089 }
6090 if (!strcmp(p, "pid")) {
6091 snprintf(buf, bufn, "aro=%s:%d", p, (int) getpid());
6092 goto qry;
6093 }
6094 if (!strcmp(p, "ext_xtest")) {
6095 snprintf(buf, bufn, "aro=%s:%d", p, xtest_present);
6096 goto qry;
6097 }
6098 if (!strcmp(p, "ext_xtrap")) {
6099 snprintf(buf, bufn, "aro=%s:%d", p, xtrap_present);
6100 goto qry;
6101 }
6102 if (!strcmp(p, "ext_xrecord")) {
6103 snprintf(buf, bufn, "aro=%s:%d", p, xrecord_present);
6104 goto qry;
6105 }
6106 if (!strcmp(p, "ext_xkb")) {
6107 snprintf(buf, bufn, "aro=%s:%d", p, xkb_present);
6108 goto qry;
6109 }
6110 if (!strcmp(p, "ext_xshm")) {
6111 snprintf(buf, bufn, "aro=%s:%d", p, xshm_present);
6112 goto qry;
6113 }
6114 if (!strcmp(p, "ext_xinerama")) {
6115 snprintf(buf, bufn, "aro=%s:%d", p, xinerama_present);
6116 goto qry;
6117 }
6118 if (!strcmp(p, "ext_overlay")) {
6119 snprintf(buf, bufn, "aro=%s:%d", p, overlay_present);
6120 goto qry;
6121 }
6122 if (!strcmp(p, "ext_xfixes")) {
6123 snprintf(buf, bufn, "aro=%s:%d", p, xfixes_present);
6124 goto qry;
6125 }
6126 if (!strcmp(p, "ext_xdamage")) {
6127 snprintf(buf, bufn, "aro=%s:%d", p, xdamage_present);
6128 goto qry;
6129 }
6130 if (!strcmp(p, "ext_xrandr")) {
6131 snprintf(buf, bufn, "aro=%s:%d", p, xrandr_present);
6132 goto qry;
6133 }
6134 if (!strcmp(p, "rootwin")) {
6135 snprintf(buf, bufn, "aro=%s:0x%x", p,
6136 (unsigned int) rootwin);
6137 goto qry;
6138 }
6139 if (!strcmp(p, "num_buttons")) {
6140 snprintf(buf, bufn, "aro=%s:%d", p, num_buttons);
6141 goto qry;
6142 }
6143 if (!strcmp(p, "button_mask")) {
6144 snprintf(buf, bufn, "aro=%s:%d", p, button_mask);
6145 goto qry;
6146 }
6147 if (!strcmp(p, "mouse_x")) {
6148 snprintf(buf, bufn, "aro=%s:%d", p, cursor_x);
6149 goto qry;
6150 }
6151 if (!strcmp(p, "mouse_y")) {
6152 snprintf(buf, bufn, "aro=%s:%d", p, cursor_y);
6153 goto qry;
6154 }
6155 if (!strcmp(p, "grab_state")) {
6156 int ptr_grabbed, kbd_grabbed;
6157
6158 grab_state(&ptr_grabbed, &kbd_grabbed);
6159 snprintf(buf, bufn, "aro=%s:%d,%d", p, ptr_grabbed, kbd_grabbed);
6160 if (dpy && rc_npieces < 10) {
6161 rfbLog("remote_cmd: ptr,kbd: %s\n", buf);
6162 }
6163 goto qry;
6164 }
6165 if (!strcmp(p, "pointer_pos") || !strcmp(p, "pointer_x") || !strcmp(p, "pointer_y") || !strcmp(p, "pointer_same") || !strcmp(p, "pointer_root") || !strcmp(p, "pointer_mask")) {
6166 int px = -1, py = -1;
6167 int wx, wy;
6168 unsigned int m = 0;
6169 Window r, c;
6170 Bool same_screen = True;
6171
6172
6173 if (!strcmp(p, "pointer_pos")) { /* skip-cmd-list */
6174 snprintf(buf, bufn, "aro=%s:%d,%d", p, px, py);
6175 } else if (!strcmp(p, "pointer_x")) { /* skip-cmd-list */
6176 snprintf(buf, bufn, "aro=%s:%d", p, px);
6177 } else if (!strcmp(p, "pointer_y")) { /* skip-cmd-list */
6178 snprintf(buf, bufn, "aro=%s:%d", p, py);
6179 } else if (!strcmp(p, "pointer_same")) { /* skip-cmd-list */
6180 snprintf(buf, bufn, "aro=%s:%d", p, same_screen);
6181 } else if (!strcmp(p, "pointer_root")) { /* skip-cmd-list */
6182 snprintf(buf, bufn, "aro=%s:0x%x", p, (unsigned int) rootwin);
6183 } else if (!strcmp(p, "pointer_mask")) { /* skip-cmd-list */
6184 snprintf(buf, bufn, "aro=%s:0x%x", p, m);
6185 }
6186 if (!dpy) {
6187 goto qry;
6188 }
6189#if NO_X11
6190 goto qry;
6191#else
6192 X_LOCK;
6193 same_screen = XQueryPointer_wr(dpy, rootwin, &r, &c, &px, &py, &wx, &wy, &m);
6194 X_UNLOCK;
6195#endif
6196
6197 if (!strcmp(p, "pointer_pos")) { /* skip-cmd-list */
6198 snprintf(buf, bufn, "aro=%s:%d,%d", p, px, py);
6199 } else if (!strcmp(p, "pointer_x")) { /* skip-cmd-list */
6200 snprintf(buf, bufn, "aro=%s:%d", p, px);
6201 } else if (!strcmp(p, "pointer_y")) { /* skip-cmd-list */
6202 snprintf(buf, bufn, "aro=%s:%d", p, py);
6203 } else if (!strcmp(p, "pointer_same")) { /* skip-cmd-list */
6204 snprintf(buf, bufn, "aro=%s:%d", p, same_screen);
6205 } else if (!strcmp(p, "pointer_root")) { /* skip-cmd-list */
6206 snprintf(buf, bufn, "aro=%s:0x%x", p, (unsigned int) r);
6207 } else if (!strcmp(p, "pointer_mask")) { /* skip-cmd-list */
6208 snprintf(buf, bufn, "aro=%s:0x%x", p, m);
6209 }
6210 if (rc_npieces < 10) {
6211 rfbLog("remote_cmd: %s: %s\n", p, buf);
6212 }
6213 goto qry;
6214 }
6215 if (!strcmp(p, "bpp")) {
6216 snprintf(buf, bufn, "aro=%s:%d", p, bpp);
6217 goto qry;
6218 }
6219 if (!strcmp(p, "depth")) {
6220 snprintf(buf, bufn, "aro=%s:%d", p, depth);
6221 goto qry;
6222 }
6223 if (!strcmp(p, "indexed_color")) {
6224 snprintf(buf, bufn, "aro=%s:%d", p, indexed_color);
6225 goto qry;
6226 }
6227 if (!strcmp(p, "dpy_x")) {
6228 snprintf(buf, bufn, "aro=%s:%d", p, dpy_x);
6229 goto qry;
6230 }
6231 if (!strcmp(p, "dpy_y")) {
6232 snprintf(buf, bufn, "aro=%s:%d", p, dpy_y);
6233 goto qry;
6234 }
6235 if (!strcmp(p, "wdpy_x")) {
6236 snprintf(buf, bufn, "aro=%s:%d", p, wdpy_x);
6237 goto qry;
6238 }
6239 if (!strcmp(p, "wdpy_y")) {
6240 snprintf(buf, bufn, "aro=%s:%d", p, wdpy_y);
6241 goto qry;
6242 }
6243 if (!strcmp(p, "off_x")) {
6244 snprintf(buf, bufn, "aro=%s:%d", p, off_x);
6245 goto qry;
6246 }
6247 if (!strcmp(p, "off_y")) {
6248 snprintf(buf, bufn, "aro=%s:%d", p, off_y);
6249 goto qry;
6250 }
6251 if (!strcmp(p, "cdpy_x")) {
6252 snprintf(buf, bufn, "aro=%s:%d", p, cdpy_x);
6253 goto qry;
6254 }
6255 if (!strcmp(p, "cdpy_y")) {
6256 snprintf(buf, bufn, "aro=%s:%d", p, cdpy_y);
6257 goto qry;
6258 }
6259 if (!strcmp(p, "coff_x")) {
6260 snprintf(buf, bufn, "aro=%s:%d", p, coff_x);
6261 goto qry;
6262 }
6263 if (!strcmp(p, "coff_y")) {
6264 snprintf(buf, bufn, "aro=%s:%d", p, coff_y);
6265 goto qry;
6266 }
6267 if (!strcmp(p, "rfbauth")) {
6268 NOTAPPRO
6269 goto qry;
6270 }
6271 if (!strcmp(p, "passwd")) {
6272 NOTAPPRO
6273 goto qry;
6274 }
6275 if (!strcmp(p, "viewpasswd")) {
6276 NOTAPPRO
6277 goto qry;
6278 }
6279 if (1) {
6280 NOTAPP
6281 goto qry;
6282 }
6283 goto done;
6284 }
6285 if (1) {
6286 char tmp[100];
6287 NOTAPP
6288 rfbLog("remote_cmd: warning unknown\n");
6289 strncpy(tmp, p, 90);
6290 rfbLog("command \"%s\"\n", tmp);
6291 goto done;
6292 }
6293
6294 done:
6295
6296 if (*buf == '\0') {
6297 sprintf(buf, "%s", "ack=1");
6298 }
6299
6300 qry:
6301
6302 if (stringonly) {
6303 return strdup(buf);
6304 } else if (client_connect_file) {
6305 FILE *out = fopen(client_connect_file, "w");
6306 if (out != NULL) {
6307 fprintf(out, "%s\n", buf);
6308 fclose(out);
6309 usleep(20*1000);
6310 }
6311 } else {
6312 if (dpy) { /* raw_fb hack */
6313 X_LOCK;
6314 set_x11vnc_remote_prop(buf);
6315 XFlush_wr(dpy);
6316 X_UNLOCK;
6317 }
6318 }
6319#endif /* REMOTE_CONTROL */
6320 return NULL;
6321}
6322
6323