PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/ica/x11/x11vnc/x11vnc.c

https://github.com/EmebedQtsoft/italc2
C | 5955 lines | 5355 code | 328 blank | 272 comment | 1733 complexity | 3972ec586c7c1d83fbd30cbee6dd99a3 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * x11vnc: a VNC server for X displays.
  3. *
  4. * Copyright (C) 2002-2010 Karl J. Runge <runge@karlrunge.com>
  5. * All rights reserved.
  6. *
  7. * This file is part of x11vnc.
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License, or (at
  12. * your option) any later version.
  13. *
  14. * This software is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this software; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  22. * USA or see <http://www.gnu.org/licenses/>.
  23. *
  24. * In addition, as a special exception, Karl J. Runge
  25. * gives permission to link the code of its release of x11vnc with the
  26. * OpenSSL project's "OpenSSL" library (or with modified versions of it
  27. * that use the same license as the "OpenSSL" library), and distribute
  28. * the linked executables. You must obey the GNU General Public License
  29. * in all respects for all of the code used other than "OpenSSL". If you
  30. * modify this file, you may extend this exception to your version of the
  31. * file, but you are not obligated to do so. If you do not wish to do
  32. * so, delete this exception statement from your version.
  33. */
  34. /*
  35. * This program is based on some ideas from the following programs:
  36. *
  37. * the initial x11vnc.c in libvncserver (Johannes E. Schindelin)
  38. * x0rfbserver, the original native X vnc server (Jens Wagner)
  39. * krfb, the KDE desktopsharing project (Tim Jansen)
  40. *
  41. * Please see http://www.karlrunge.com/x11vnc for the most up-to-date
  42. * information about x11vnc. Some of the following text may be out
  43. * of date.
  44. *
  45. * The primary goal of this program is to create a portable and simple
  46. * command-line server utility that allows a VNC viewer to connect
  47. * to an actual X display (as the above do). The only non-standard
  48. * dependency of this program is the static library libvncserver.a.
  49. * Although in some environments libjpeg.so or libz.so may not be
  50. * readily available and needs to be installed, they may be found
  51. * at ftp://ftp.uu.net/graphics/jpeg/ and http://www.gzip.org/zlib/,
  52. * respectively. To increase portability it is written in plain C.
  53. *
  54. * Another goal is to improve performance and interactive response.
  55. * The algorithm of x0rfbserver was used as a base. Many additional
  56. * heuristics are also applied.
  57. *
  58. * Another goal is to add many features that enable and incourage creative
  59. * usage and application of the tool. Apologies for the large number
  60. * of options!
  61. *
  62. * To build:
  63. *
  64. * Obtain the libvncserver package (http://libvncserver.sourceforge.net).
  65. * As of 12/2002 this version of x11vnc.c is contained in the libvncserver
  66. * CVS tree and released in version 0.5.
  67. *
  68. * gcc should be used on all platforms. To build a threaded version put
  69. * "-D_REENTRANT -DX11VNC_THREADED" in the environment variable CFLAGS
  70. * or CPPFLAGS (e.g. before running the libvncserver configure). The
  71. * threaded mode is a bit more responsive, but can be unstable (e.g.
  72. * if more than one client the same tight or zrle encoding).
  73. *
  74. * Known shortcomings:
  75. *
  76. * The screen updates are good, but of course not perfect since the X
  77. * display must be continuously polled and read for changes and this is
  78. * slow for most hardware. This can be contrasted with receiving a change
  79. * callback from the X server, if that were generally possible... (UPDATE:
  80. * this is handled now with the X DAMAGE extension, but unfortunately
  81. * that doesn't seem to address the slow read from the video h/w). So,
  82. * e.g., opaque moves and similar window activity can be very painful;
  83. * one has to modify one's behavior a bit.
  84. *
  85. * General audio at the remote display is lost unless one separately
  86. * sets up some audio side-channel such as esd.
  87. *
  88. * It does not appear possible to query the X server for the current
  89. * cursor shape. We can use XTest to compare cursor to current window's
  90. * cursor, but we cannot extract what the cursor is... (UPDATE: we now
  91. * use XFIXES extension for this. Also on Solaris and IRIX Overlay
  92. * extensions exists that allow drawing the mouse into the framebuffer)
  93. *
  94. * The current *position* of the remote X mouse pointer is shown with
  95. * the -cursor option. Further, if -cursor X is used, a trick
  96. * is done to at least show the root window cursor vs non-root cursor.
  97. * (perhaps some heuristic can be done to further distinguish cases...,
  98. * currently "-cursor some" is a first hack at this)
  99. *
  100. * Under XFIXES mode for showing the cursor shape, the cursor may be
  101. * poorly approximated if it has transparency (alpha channel).
  102. *
  103. * Windows using visuals other than the default X visual may have
  104. * their colors messed up. When using 8bpp indexed color, the colormap
  105. * is attempted to be followed, but may become out of date. Use the
  106. * -flashcmap option to have colormap flashing as the pointer moves
  107. * windows with private colormaps (slow). Displays with mixed depth 8 and
  108. * 24 visuals will incorrectly display windows using the non-default one.
  109. * On Sun and Sgi hardware we can to work around this with -overlay.
  110. *
  111. * Feature -id <windowid> can be picky: it can crash for things like
  112. * the window not sufficiently mapped into server memory, etc (UPDATE:
  113. * we now use the -xrandr mechanisms to trap errors more robustly for
  114. * this mode). SaveUnders menus, popups, etc will not be seen.
  115. *
  116. * Under some situations the keysym unmapping is not correct, especially
  117. * if the two keyboards correspond to different languages. The -modtweak
  118. * option is the default and corrects most problems. One can use the
  119. * -xkb option to try to use the XKEYBOARD extension to clear up any
  120. * remaining problems.
  121. *
  122. * Occasionally, a few tile updates can be missed leaving a patch of
  123. * color that needs to be refreshed. This may only be when threaded,
  124. * which is no longer the default.
  125. *
  126. * There seems to be a serious bug with simultaneous clients when
  127. * threaded, currently the only workaround in this case is -nothreads
  128. * (which is now the default).
  129. */
  130. /* -- x11vnc.c -- */
  131. #include "x11vnc.h"
  132. #include "xwrappers.h"
  133. #include "xdamage.h"
  134. #include "xrecord.h"
  135. #include "xevents.h"
  136. #include "xinerama.h"
  137. #include "xrandr.h"
  138. #include "xkb_bell.h"
  139. #include "win_utils.h"
  140. #include "remote.h"
  141. #include "scan.h"
  142. #include "gui.h"
  143. #include "help.h"
  144. #include "user.h"
  145. #include "cleanup.h"
  146. #include "keyboard.h"
  147. #include "pointer.h"
  148. #include "cursor.h"
  149. #include "userinput.h"
  150. #include "screen.h"
  151. #include "connections.h"
  152. #include "rates.h"
  153. #include "unixpw.h"
  154. #include "inet.h"
  155. #include "sslcmds.h"
  156. #include "sslhelper.h"
  157. #include "selection.h"
  158. #include "pm.h"
  159. #include "solid.h"
  160. /*
  161. * main routine for the x11vnc program
  162. */
  163. void watch_loop(void);
  164. static int limit_shm(void);
  165. static void check_rcfile(int argc, char **argv);
  166. static void immediate_switch_user(int argc, char* argv[]);
  167. static void print_settings(int try_http, int bg, char *gui_str);
  168. static void check_loop_mode(int argc, char* argv[], int force);
  169. static void check_appshare_mode(int argc, char* argv[]);
  170. static int tsdo_timeout_flag;
  171. static void tsdo_timeout (int sig) {
  172. tsdo_timeout_flag = 1;
  173. if (sig) {};
  174. }
  175. #define TASKMAX 32
  176. static pid_t ts_tasks[TASKMAX];
  177. static int ts_taskn = -1;
  178. int tsdo(int port, int lsock, int *conn) {
  179. int csock, rsock, i, db = 1;
  180. pid_t pid;
  181. struct sockaddr_in addr;
  182. #ifdef __hpux
  183. int addrlen = sizeof(addr);
  184. #else
  185. socklen_t addrlen = sizeof(addr);
  186. #endif
  187. if (*conn < 0) {
  188. signal(SIGALRM, tsdo_timeout);
  189. tsdo_timeout_flag = 0;
  190. alarm(10);
  191. csock = accept(lsock, (struct sockaddr *)&addr, &addrlen);
  192. alarm(0);
  193. if (db) rfbLog("tsdo: accept: lsock: %d, csock: %d, port: %d\n", lsock, csock, port);
  194. if (tsdo_timeout_flag > 0 || csock < 0) {
  195. close(csock);
  196. *conn = -1;
  197. return 1;
  198. }
  199. *conn = csock;
  200. } else {
  201. csock = *conn;
  202. if (db) rfbLog("tsdo: using existing csock: %d, port: %d\n", csock, port);
  203. }
  204. rsock = connect_tcp("127.0.0.1", port);
  205. if (rsock < 0) {
  206. if (db) rfbLog("tsdo: connect_tcp(port=%d) failed.\n", port);
  207. close(csock);
  208. return 2;
  209. }
  210. pid = fork();
  211. if (pid < 0) {
  212. close(csock);
  213. close(rsock);
  214. return 3;
  215. }
  216. if (pid > 0) {
  217. ts_taskn = (ts_taskn+1) % TASKMAX;
  218. ts_tasks[ts_taskn] = pid;
  219. close(csock);
  220. close(rsock);
  221. *conn = -1;
  222. return 0;
  223. }
  224. if (pid == 0) {
  225. for (i=0; i<255; i++) {
  226. if (i != csock && i != rsock && i != 2) {
  227. close(i);
  228. }
  229. }
  230. #if LIBVNCSERVER_HAVE_SETSID
  231. if (setsid() == -1) {
  232. perror("setsid");
  233. close(csock);
  234. close(rsock);
  235. exit(1);
  236. }
  237. #else
  238. if (setpgrp() == -1) {
  239. perror("setpgrp");
  240. close(csock);
  241. close(rsock);
  242. exit(1);
  243. }
  244. #endif /* SETSID */
  245. raw_xfer(rsock, csock, csock);
  246. close(csock);
  247. close(rsock);
  248. exit(0);
  249. }
  250. return 0;
  251. }
  252. void set_redir_properties(void);
  253. #define TSMAX 32
  254. #define TSSTK 16
  255. void terminal_services(char *list) {
  256. int i, j, n, db = 1;
  257. char *p, *q, *r, *str;
  258. #if !NO_X11
  259. char *tag[TSMAX];
  260. int listen[TSMAX], redir[TSMAX][TSSTK], socks[TSMAX], tstk[TSSTK];
  261. double rate_start;
  262. int rate_count;
  263. Atom at, atom[TSMAX];
  264. fd_set rd;
  265. Window rwin;
  266. XErrorHandler old_handler1;
  267. XIOErrorHandler old_handler2;
  268. char num[32];
  269. time_t last_clean = time(NULL);
  270. if (getenv("TS_REDIR_DEBUG")) {
  271. db = 2;
  272. }
  273. if (! dpy) {
  274. return;
  275. }
  276. rwin = RootWindow(dpy, DefaultScreen(dpy));
  277. at = XInternAtom(dpy, "TS_REDIR_LIST", False);
  278. if (at != None) {
  279. XChangeProperty(dpy, rwin, at, XA_STRING, 8,
  280. PropModeReplace, (unsigned char *)list, strlen(list));
  281. XSync(dpy, False);
  282. }
  283. if (db) fprintf(stderr, "TS_REDIR_LIST Atom: %d.\n", (int) at);
  284. oh_restart_it_all:
  285. for (i=0; i<TASKMAX; i++) {
  286. ts_tasks[i] = 0;
  287. }
  288. for (i=0; i<TSMAX; i++) {
  289. socks[i] = -1;
  290. listen[i] = -1;
  291. for (j=0; j<TSSTK; j++) {
  292. redir[i][j] = 0;
  293. }
  294. }
  295. rate_start = 0.0;
  296. rate_count = 0;
  297. n = 0;
  298. str = strdup(list);
  299. p = strtok(str, ",");
  300. while (p) {
  301. int m1, m2;
  302. if (db) fprintf(stderr, "item: %s\n", p);
  303. q = strrchr(p, ':');
  304. if (!q) {
  305. p = strtok(NULL, ",");
  306. continue;
  307. }
  308. r = strchr(p, ':');
  309. if (!r || r == q) {
  310. p = strtok(NULL, ",");
  311. continue;
  312. }
  313. m1 = atoi(q+1);
  314. *q = '\0';
  315. m2 = atoi(r+1);
  316. *r = '\0';
  317. if (m1 <= 0 || m2 <= 0 || m1 >= 0xffff || m2 >= 0xffff) {
  318. p = strtok(NULL, ",");
  319. continue;
  320. }
  321. redir[n][0] = m1;
  322. listen[n] = m2;
  323. tag[n] = strdup(p);
  324. if (db) fprintf(stderr, " %d %d %s\n", redir[n][0], listen[n], tag[n]);
  325. *r = ':';
  326. *q = ':';
  327. n++;
  328. if (n >= TSMAX) {
  329. break;
  330. }
  331. p = strtok(NULL, ",");
  332. }
  333. free(str);
  334. if (n==0) {
  335. return;
  336. }
  337. at = XInternAtom(dpy, "TS_REDIR_PID", False);
  338. if (at != None) {
  339. sprintf(num, "%d", getpid());
  340. XChangeProperty(dpy, rwin, at, XA_STRING, 8,
  341. PropModeReplace, (unsigned char *)num, strlen(num));
  342. XSync(dpy, False);
  343. }
  344. for (i=0; i<n; i++) {
  345. int k;
  346. atom[i] = XInternAtom(dpy, tag[i], False);
  347. if (db) fprintf(stderr, "tag: %s atom: %d\n", tag[i], (int) atom[i]);
  348. if (atom[i] == None) {
  349. continue;
  350. }
  351. sprintf(num, "%d", redir[i][0]);
  352. if (db) fprintf(stderr, " listen: %d redir: %s\n", listen[i], num);
  353. XChangeProperty(dpy, rwin, atom[i], XA_STRING, 8,
  354. PropModeReplace, (unsigned char *)num, strlen(num));
  355. XSync(dpy, False);
  356. for (k=1; k <= 5; k++) {
  357. /* XXX ::1 fallback? */
  358. socks[i] = listen_tcp(listen[i], htonl(INADDR_LOOPBACK), 1);
  359. if (socks[i] >= 0) {
  360. if (db) fprintf(stderr, " listen succeeded: %d\n", listen[i]);
  361. break;
  362. }
  363. if (db) fprintf(stderr, " listen failed***: %d\n", listen[i]);
  364. usleep(k * 2000*1000);
  365. }
  366. }
  367. if (getenv("TSD_RESTART")) {
  368. if (!strcmp(getenv("TSD_RESTART"), "1")) {
  369. set_redir_properties();
  370. }
  371. }
  372. while (1) {
  373. struct timeval tv;
  374. int nfd;
  375. int fmax = -1;
  376. tv.tv_sec = 3;
  377. tv.tv_usec = 0;
  378. FD_ZERO(&rd);
  379. for (i=0; i<n; i++) {
  380. if (socks[i] >= 0) {
  381. FD_SET(socks[i], &rd);
  382. if (socks[i] > fmax) {
  383. fmax = socks[i];
  384. }
  385. }
  386. }
  387. nfd = select(fmax+1, &rd, NULL, NULL, &tv);
  388. if (db && 0) fprintf(stderr, "nfd=%d\n", nfd);
  389. if (nfd < 0 && errno == EINTR) {
  390. XSync(dpy, True);
  391. continue;
  392. }
  393. if (nfd > 0) {
  394. int did_ts = 0;
  395. for(i=0; i<n; i++) {
  396. int k = 0;
  397. for (j = 0; j < TSSTK; j++) {
  398. tstk[j] = 0;
  399. }
  400. for (j = 0; j < TSSTK; j++) {
  401. if (redir[i][j] != 0) {
  402. tstk[k++] = redir[i][j];
  403. }
  404. }
  405. for (j = 0; j < TSSTK; j++) {
  406. redir[i][j] = tstk[j];
  407. if (tstk[j] != 0) fprintf(stderr, "B redir[%d][%d] = %d %s\n", i, j, tstk[j], tag[i]);
  408. }
  409. }
  410. for(i=0; i<n; i++) {
  411. int s = socks[i];
  412. if (s < 0) {
  413. continue;
  414. }
  415. if (FD_ISSET(s, &rd)) {
  416. int p0, p, found = -1, jzero = -1;
  417. int conn = -1;
  418. get_prop(num, 32, atom[i], None);
  419. p0 = atoi(num);
  420. for (j = TSSTK-1; j >= 0; j--) {
  421. if (redir[i][j] == 0) {
  422. jzero = j;
  423. continue;
  424. }
  425. if (p0 > 0 && p0 < 0xffff) {
  426. if (redir[i][j] == p0) {
  427. found = j;
  428. break;
  429. }
  430. }
  431. }
  432. if (jzero < 0) {
  433. jzero = TSSTK-1;
  434. }
  435. if (found < 0) {
  436. if (p0 > 0 && p0 < 0xffff) {
  437. redir[i][jzero] = p0;
  438. }
  439. }
  440. for (j = TSSTK-1; j >= 0; j--) {
  441. int rc;
  442. p = redir[i][j];
  443. if (p <= 0 || p >= 0xffff) {
  444. redir[i][j] = 0;
  445. continue;
  446. }
  447. if (dnow() > rate_start + 10.0) {
  448. rate_start = dnow();
  449. rate_count = 0;
  450. }
  451. rate_count++;
  452. rc = tsdo(p, s, &conn);
  453. did_ts++;
  454. if (rc == 0) {
  455. /* AOK */
  456. if (db) fprintf(stderr, "tsdo[%d] OK: %d\n", i, p);
  457. if (p != p0) {
  458. sprintf(num, "%d", p);
  459. XChangeProperty(dpy, rwin, atom[i], XA_STRING, 8,
  460. PropModeReplace, (unsigned char *)num, strlen(num));
  461. XSync(dpy, False);
  462. }
  463. break;
  464. } else if (rc == 1) {
  465. /* accept failed */
  466. if (db) fprintf(stderr, "tsdo[%d] accept failed: %d, sleep 50ms\n", i, p);
  467. usleep(50*1000);
  468. break;
  469. } else if (rc == 2) {
  470. /* connect failed */
  471. if (db) fprintf(stderr, "tsdo[%d] connect failed: %d, sleep 50ms rate: %d/10s\n", i, p, rate_count);
  472. redir[i][j] = 0;
  473. usleep(50*1000);
  474. continue;
  475. } else if (rc == 3) {
  476. /* fork failed */
  477. usleep(500*1000);
  478. break;
  479. }
  480. }
  481. for (j = 0; j < TSSTK; j++) {
  482. if (redir[i][j] != 0) fprintf(stderr, "A redir[%d][%d] = %d %s\n", i, j, redir[i][j], tag[i]);
  483. }
  484. }
  485. }
  486. if (did_ts && rate_count > 100) {
  487. int db_netstat = 1;
  488. char dcmd[100];
  489. if (no_external_cmds) {
  490. db_netstat = 0;
  491. }
  492. rfbLog("terminal_services: throttling high connect rate %d/10s\n", rate_count);
  493. usleep(2*1000*1000);
  494. rfbLog("terminal_services: stopping ts services.\n");
  495. for(i=0; i<n; i++) {
  496. int s = socks[i];
  497. if (s < 0) {
  498. continue;
  499. }
  500. rfbLog("terminal_services: closing listen=%d sock=%d.\n", listen[i], socks[i]);
  501. if (listen[i] >= 0 && db_netstat) {
  502. sprintf(dcmd, "netstat -an | grep -w '%d'", listen[i]);
  503. fprintf(stderr, "#1 %s\n", dcmd);
  504. system(dcmd);
  505. }
  506. close(s);
  507. socks[i] = -1;
  508. usleep(2*1000*1000);
  509. if (listen[i] >= 0 && db_netstat) {
  510. fprintf(stderr, "#2 %s\n", dcmd);
  511. system(dcmd);
  512. }
  513. }
  514. usleep(10*1000*1000);
  515. rfbLog("terminal_services: restarting ts services\n");
  516. goto oh_restart_it_all;
  517. }
  518. }
  519. for (i=0; i<TASKMAX; i++) {
  520. pid_t p = ts_tasks[i];
  521. if (p > 0) {
  522. int status;
  523. pid_t p2 = waitpid(p, &status, WNOHANG);
  524. if (p2 == p) {
  525. ts_tasks[i] = 0;
  526. }
  527. }
  528. }
  529. /* this is to drop events and exit when X server is gone. */
  530. old_handler1 = XSetErrorHandler(trap_xerror);
  531. old_handler2 = XSetIOErrorHandler(trap_xioerror);
  532. trapped_xerror = 0;
  533. trapped_xioerror = 0;
  534. XSync(dpy, True);
  535. sprintf(num, "%d", (int) time(NULL));
  536. at = XInternAtom(dpy, "TS_REDIR", False);
  537. if (at != None) {
  538. XChangeProperty(dpy, rwin, at, XA_STRING, 8,
  539. PropModeReplace, (unsigned char *)num, strlen(num));
  540. XSync(dpy, False);
  541. }
  542. if (time(NULL) > last_clean + 20 * 60) {
  543. int i, j;
  544. for(i=0; i<n; i++) {
  545. int first = 1;
  546. for (j = TSSTK-1; j >= 0; j--) {
  547. int s, p = redir[i][j];
  548. if (p <= 0 || p >= 0xffff) {
  549. redir[i][j] = 0;
  550. continue;
  551. }
  552. s = connect_tcp("127.0.0.1", p);
  553. if (s < 0) {
  554. redir[i][j] = 0;
  555. if (db) fprintf(stderr, "tsdo[%d][%d] clean: connect failed: %d\n", i, j, p);
  556. } else {
  557. close(s);
  558. if (first) {
  559. sprintf(num, "%d", p);
  560. XChangeProperty(dpy, rwin, atom[i], XA_STRING, 8,
  561. PropModeReplace, (unsigned char *)num, strlen(num));
  562. XSync(dpy, False);
  563. }
  564. first = 0;
  565. }
  566. usleep(500*1000);
  567. }
  568. }
  569. last_clean = time(NULL);
  570. }
  571. if (trapped_xerror || trapped_xioerror) {
  572. if (db) fprintf(stderr, "Xerror: %d/%d\n", trapped_xerror, trapped_xioerror);
  573. exit(0);
  574. }
  575. XSetErrorHandler(old_handler1);
  576. XSetIOErrorHandler(old_handler2);
  577. }
  578. #endif
  579. }
  580. char *ts_services[][2] = {
  581. {"FD_CUPS", "TS_CUPS_REDIR"},
  582. {"FD_SMB", "TS_SMB_REDIR"},
  583. {"FD_ESD", "TS_ESD_REDIR"},
  584. {"FD_NAS", "TS_NAS_REDIR"},
  585. {NULL, NULL}
  586. };
  587. void do_tsd(void) {
  588. #if !NO_X11
  589. Atom a;
  590. char prop[513];
  591. pid_t pid;
  592. char *cmd;
  593. int n, sz = 0;
  594. char *disp = DisplayString(dpy);
  595. char *logfile = getenv("TS_REDIR_LOGFILE");
  596. int db = 0;
  597. if (getenv("TS_REDIR_DEBUG")) {
  598. db = 1;
  599. }
  600. if (db) fprintf(stderr, "do_tsd() in.\n");
  601. prop[0] = '\0';
  602. a = XInternAtom(dpy, "TS_REDIR_LIST", False);
  603. if (a != None) {
  604. get_prop(prop, 512, a, None);
  605. }
  606. if (db) fprintf(stderr, "TS_REDIR_LIST Atom: %d = '%s'\n", (int) a, prop);
  607. if (prop[0] == '\0') {
  608. return;
  609. }
  610. if (! program_name) {
  611. program_name = "x11vnc";
  612. }
  613. sz += strlen(program_name) + 1;
  614. sz += strlen("-display") + 1;
  615. sz += strlen(disp) + 1;
  616. sz += strlen("-tsd") + 1;
  617. sz += 1 + strlen(prop) + 1 + 1;
  618. sz += strlen("-env TSD_RESTART=1") + 1;
  619. sz += strlen("</dev/null 1>/dev/null 2>&1") + 1;
  620. sz += strlen(" &") + 1;
  621. if (logfile) {
  622. sz += strlen(logfile);
  623. }
  624. if (ipv6_listen) {
  625. sz += strlen("-6") + 1;
  626. }
  627. cmd = (char *) malloc(sz);
  628. if (getenv("XAUTHORITY")) {
  629. char *xauth = getenv("XAUTHORITY");
  630. if (!strcmp(xauth, "") || access(xauth, R_OK) != 0) {
  631. *(xauth-2) = '_'; /* yow */
  632. }
  633. }
  634. sprintf(cmd, "%s -display %s -tsd '%s' -env TSD_RESTART=1 %s </dev/null 1>%s 2>&1 &",
  635. program_name, disp, prop, ipv6_listen ? "-6" : "",
  636. logfile ? logfile : "/dev/null" );
  637. rfbLog("running: %s\n", cmd);
  638. #if LIBVNCSERVER_HAVE_FORK && LIBVNCSERVER_HAVE_SETSID
  639. /* fork into the background now */
  640. if ((pid = fork()) > 0) {
  641. pid_t pidw;
  642. int status;
  643. double s = dnow();
  644. while (dnow() < s + 1.5) {
  645. pidw = waitpid(pid, &status, WNOHANG);
  646. if (pidw == pid) {
  647. break;
  648. }
  649. usleep(100*1000);
  650. }
  651. return;
  652. } else if (pid == -1) {
  653. system(cmd);
  654. } else {
  655. setsid();
  656. /* adjust our stdio */
  657. n = open("/dev/null", O_RDONLY);
  658. dup2(n, 0);
  659. dup2(n, 1);
  660. dup2(n, 2);
  661. if (n > 2) {
  662. close(n);
  663. }
  664. system(cmd);
  665. exit(0);
  666. }
  667. #else
  668. system(cmd);
  669. #endif
  670. #endif
  671. }
  672. void set_redir_properties(void) {
  673. #if !NO_X11
  674. char *e, *f, *t;
  675. Atom a;
  676. char num[32];
  677. int i, p;
  678. if (! dpy) {
  679. return;
  680. }
  681. i = 0;
  682. while (ts_services[i][0] != NULL) {
  683. f = ts_services[i][0];
  684. t = ts_services[i][1];
  685. e = getenv(f);
  686. if (!e || strstr(e, "DAEMON-") != e) {
  687. i++;
  688. continue;
  689. }
  690. p = atoi(e + strlen("DAEMON-"));
  691. if (p <= 0) {
  692. i++;
  693. continue;
  694. }
  695. sprintf(num, "%d", p);
  696. a = XInternAtom(dpy, t, False);
  697. if (a != None) {
  698. Window rwin = RootWindow(dpy, DefaultScreen(dpy));
  699. fprintf(stderr, "Set: %s %s %s -> %s\n", f, t, e, num);
  700. XChangeProperty(dpy, rwin, a, XA_STRING, 8,
  701. PropModeReplace, (unsigned char *) num, strlen(num));
  702. XSync(dpy, False);
  703. }
  704. i++;
  705. }
  706. #endif
  707. }
  708. static void check_redir_services(void) {
  709. #if !NO_X11
  710. Atom a;
  711. char prop[513];
  712. time_t tsd_last;
  713. int restart = 0;
  714. pid_t pid = 0;
  715. int db = 0;
  716. db = 0;
  717. if (getenv("TS_REDIR_DEBUG")) {
  718. db = 1;
  719. }
  720. if (db) fprintf(stderr, "check_redir_services in.\n");
  721. if (! dpy) {
  722. return;
  723. }
  724. a = XInternAtom(dpy, "TS_REDIR_PID", False);
  725. if (a != None) {
  726. prop[0] = '\0';
  727. get_prop(prop, 512, a, None);
  728. if (prop[0] != '\0') {
  729. pid = (pid_t) atoi(prop);
  730. }
  731. }
  732. if (db) fprintf(stderr, "TS_REDIR_PID Atom: %d = '%s'\n", (int) a, prop);
  733. if (getenv("FD_TAG") && strcmp(getenv("FD_TAG"), "")) {
  734. a = XInternAtom(dpy, "FD_TAG", False);
  735. if (a != None) {
  736. Window rwin = RootWindow(dpy, DefaultScreen(dpy));
  737. char *tag = getenv("FD_TAG");
  738. XChangeProperty(dpy, rwin, a, XA_STRING, 8,
  739. PropModeReplace, (unsigned char *)tag, strlen(tag));
  740. XSync(dpy, False);
  741. }
  742. if (db) fprintf(stderr, "FD_TAG Atom: %d = '%s'\n", (int) a, prop);
  743. }
  744. prop[0] = '\0';
  745. a = XInternAtom(dpy, "TS_REDIR", False);
  746. if (a != None) {
  747. get_prop(prop, 512, a, None);
  748. }
  749. if (db) fprintf(stderr, "TS_REDIR Atom: %d = '%s'\n", (int) a, prop);
  750. if (prop[0] == '\0') {
  751. rfbLog("TS_REDIR is empty, restarting...\n");
  752. restart = 1;
  753. } else {
  754. tsd_last = (time_t) atoi(prop);
  755. if (time(NULL) > tsd_last + 30) {
  756. rfbLog("TS_REDIR seems dead for: %d sec, restarting...\n",
  757. time(NULL) - tsd_last);
  758. restart = 1;
  759. } else if (pid > 0 && time(NULL) > tsd_last + 6) {
  760. if (kill(pid, 0) != 0) {
  761. rfbLog("TS_REDIR seems dead via kill(%d, 0), restarting...\n",
  762. pid);
  763. restart = 1;
  764. }
  765. }
  766. }
  767. if (restart) {
  768. if (pid > 1) {
  769. rfbLog("killing TS_REDIR_PID: %d\n", pid);
  770. kill(pid, SIGTERM);
  771. usleep(500*1000);
  772. kill(pid, SIGKILL);
  773. }
  774. do_tsd();
  775. if (db) fprintf(stderr, "check_redir_services restarted.\n");
  776. return;
  777. }
  778. if (db) fprintf(stderr, "check_redir_services, no restart, calling set_redir_properties.\n");
  779. set_redir_properties();
  780. #endif
  781. }
  782. void ssh_remote_tunnel(char *instr, int lport) {
  783. #ifndef WIN32
  784. char *q, *cmd, *ssh;
  785. char *s = strdup(instr);
  786. int sleep = 300, disp = 0, sport = 0;
  787. int rc, len, rport;
  788. /* user@host:port:disp+secs */
  789. /* +sleep */
  790. q = strrchr(s, '+');
  791. if (q) {
  792. sleep = atoi(q+1);
  793. if (sleep <= 0) {
  794. sleep = 1;
  795. }
  796. *q = '\0';
  797. }
  798. /* :disp */
  799. q = strrchr(s, ':');
  800. if (q) {
  801. disp = atoi(q+1);
  802. *q = '\0';
  803. }
  804. /* :sshport */
  805. q = strrchr(s, ':');
  806. if (q) {
  807. sport = atoi(q+1);
  808. *q = '\0';
  809. }
  810. if (getenv("SSH")) {
  811. ssh = getenv("SSH");
  812. } else {
  813. ssh = "ssh";
  814. }
  815. len = 0;
  816. len += strlen(ssh) + strlen(s) + 500;
  817. cmd = (char *) malloc(len);
  818. if (disp >= 0 && disp <= 200) {
  819. rport = disp + 5900;
  820. } else if (disp < 0) {
  821. rport = -disp;
  822. } else {
  823. rport = disp;
  824. }
  825. if (sport > 0) {
  826. sprintf(cmd, "%s -f -p %d -R '%d:localhost:%d' '%s' 'sleep %d'", ssh, sport, rport, lport, s, sleep);
  827. } else {
  828. sprintf(cmd, "%s -f -R '%d:localhost:%d' '%s' 'sleep %d'", ssh, rport, lport, s, sleep);
  829. }
  830. if (no_external_cmds || !cmd_ok("ssh")) {
  831. rfbLogEnable(1);
  832. rfbLog("cannot run external commands in -nocmds mode:\n");
  833. rfbLog(" \"%s\"\n", cmd);
  834. rfbLog(" exiting.\n");
  835. clean_up_exit(1);
  836. }
  837. close_exec_fds();
  838. fprintf(stderr, "\n");
  839. rfbLog("running: %s\n", cmd);
  840. rc = system(cmd);
  841. if (rc != 0) {
  842. free(cmd);
  843. free(s);
  844. rfbLog("ssh remote listen failed.\n");
  845. clean_up_exit(1);
  846. }
  847. if (1) {
  848. FILE *pipe;
  849. int mypid = (int) getpid();
  850. int bestpid = -1;
  851. int best = -1;
  852. char line[1024];
  853. char *psef = "ps -ef";
  854. char *psww = "ps wwwwwwaux";
  855. char *ps = psef;
  856. /* not portable... but it is really good to terminate the ssh when done. */
  857. /* ps -ef | egrep 'ssh2.*-R.*5907:localhost:5900.*runge@celias.lbl.gov.*sleep 300' | grep -v grep | awk '{print $2}' */
  858. if (strstr(UT.sysname, "Linux")) {
  859. ps = psww;
  860. } else if (strstr(UT.sysname, "BSD")) {
  861. ps = psww;
  862. } else if (strstr(UT.sysname, "Darwin")) {
  863. ps = psww;
  864. }
  865. sprintf(cmd, "env COLUMNS=256 %s | egrep '%s.*-R *%d:localhost:%d.*%s.*sleep *%d' | grep -v grep | awk '{print $2}'", ps, ssh, rport, lport, s, sleep);
  866. pipe = popen(cmd, "r");
  867. if (pipe) {
  868. while (fgets(line, 1024, pipe) != NULL) {
  869. int p = atoi(line);
  870. if (p > 0) {
  871. int score;
  872. if (p > mypid) {
  873. score = p - mypid;
  874. } else {
  875. score = p - mypid + 32768;
  876. if (score < 0) {
  877. score = 32768;
  878. }
  879. }
  880. if (best < 0 || score < best) {
  881. best = score;
  882. bestpid = p;
  883. }
  884. }
  885. }
  886. pclose(pipe);
  887. }
  888. if (bestpid != -1) {
  889. ssh_pid = (pid_t) bestpid;
  890. rfbLog("guessed ssh pid=%d, will terminate it on exit.\n", bestpid);
  891. }
  892. }
  893. free(cmd);
  894. free(s);
  895. #endif
  896. }
  897. /*
  898. * check blacklist for OSs with tight shm limits.
  899. */
  900. static int limit_shm(void) {
  901. int limit = 0;
  902. #ifndef WIN32
  903. if (UT.sysname == NULL) {
  904. return 0;
  905. }
  906. if (getenv("X11VNC_NO_LIMIT_SHM")) {
  907. return 0;
  908. }
  909. if (!strcmp(UT.sysname, "SunOS")) {
  910. char *r = UT.release;
  911. if (*r == '5' && *(r+1) == '.') {
  912. if (strchr("2345678", *(r+2)) != NULL) {
  913. limit = 1;
  914. }
  915. }
  916. } else if (!strcmp(UT.sysname, "Darwin")) {
  917. limit = 1;
  918. }
  919. if (limit && ! quiet) {
  920. fprintf(stderr, "reducing shm usage on %s %s (adding "
  921. "-onetile)\n", UT.sysname, UT.release);
  922. }
  923. #endif
  924. return limit;
  925. }
  926. /*
  927. * quick-n-dirty ~/.x11vncrc: each line (except # comments) is a cmdline option.
  928. */
  929. static int argc2 = 0;
  930. static char **argv2;
  931. static void check_rcfile(int argc, char **argv) {
  932. int i, j, pwlast, enclast, norc = 0, argmax = 1024;
  933. char *infile = NULL;
  934. char rcfile[1024];
  935. FILE *rc = NULL;
  936. for (i=1; i < argc; i++) {
  937. if (!strcmp(argv[i], "-printgui")) {
  938. fprintf(stdout, "%s", get_gui_code());
  939. fflush(stdout);
  940. exit(0);
  941. }
  942. if (!strcmp(argv[i], "-norc")) {
  943. norc = 1;
  944. got_norc = 1;
  945. }
  946. if (!strcmp(argv[i], "-QD")) {
  947. norc = 1;
  948. }
  949. if (!strcmp(argv[i], "-rc")) {
  950. if (i+1 >= argc) {
  951. fprintf(stderr, "-rc option requires a "
  952. "filename\n");
  953. exit(1);
  954. } else {
  955. infile = argv[i+1];
  956. }
  957. }
  958. }
  959. rc_norc = norc;
  960. rc_rcfile = strdup("");
  961. if (norc) {
  962. ;
  963. } else if (infile != NULL) {
  964. rc = fopen(infile, "r");
  965. rc_rcfile = strdup(infile);
  966. if (rc == NULL) {
  967. fprintf(stderr, "could not open rcfile: %s\n", infile);
  968. perror("fopen");
  969. exit(1);
  970. }
  971. } else {
  972. char *home = get_home_dir();
  973. if (! home) {
  974. norc = 1;
  975. } else {
  976. memset(rcfile, 0, sizeof(rcfile));
  977. strncpy(rcfile, home, 500);
  978. free(home);
  979. strcat(rcfile, "/.x11vncrc");
  980. infile = rcfile;
  981. rc = fopen(rcfile, "r");
  982. if (rc == NULL) {
  983. norc = 1;
  984. } else {
  985. rc_rcfile = strdup(rcfile);
  986. rc_rcfile_default = 1;
  987. }
  988. }
  989. }
  990. argv2 = (char **) malloc(argmax * sizeof(char *));
  991. argv2[argc2++] = strdup(argv[0]);
  992. if (! norc) {
  993. char line[4096], parm[400], tmp[401];
  994. char *buf, *tbuf;
  995. struct stat sbuf;
  996. int sz;
  997. if (fstat(fileno(rc), &sbuf) != 0) {
  998. fprintf(stderr, "problem with %s\n", infile);
  999. perror("fstat");
  1000. exit(1);
  1001. }
  1002. sz = sbuf.st_size+1; /* allocate whole file size */
  1003. if (sz < 1024) {
  1004. sz = 1024;
  1005. }
  1006. buf = (char *) malloc(sz);
  1007. buf[0] = '\0';
  1008. while (fgets(line, 4096, rc) != NULL) {
  1009. char *q, *p = line;
  1010. char c;
  1011. int cont = 0;
  1012. q = p;
  1013. c = '\0';
  1014. while (*q) {
  1015. if (*q == '#') {
  1016. if (c != '\\') {
  1017. *q = '\0';
  1018. break;
  1019. }
  1020. }
  1021. c = *q;
  1022. q++;
  1023. }
  1024. q = p;
  1025. c = '\0';
  1026. while (*q) {
  1027. if (*q == '\n') {
  1028. if (c == '\\') {
  1029. cont = 1;
  1030. *q = '\0';
  1031. *(q-1) = ' ';
  1032. break;
  1033. }
  1034. while (isspace((unsigned char) (*q))) {
  1035. *q = '\0';
  1036. if (q == p) {
  1037. break;
  1038. }
  1039. q--;
  1040. }
  1041. break;
  1042. }
  1043. c = *q;
  1044. q++;
  1045. }
  1046. if (q != p && !cont) {
  1047. if (*q == '\0') {
  1048. q--;
  1049. }
  1050. while (isspace((unsigned char) (*q))) {
  1051. *q = '\0';
  1052. if (q == p) {
  1053. break;
  1054. }
  1055. q--;
  1056. }
  1057. }
  1058. p = lblanks(p);
  1059. strncat(buf, p, sz - strlen(buf) - 1);
  1060. if (cont) {
  1061. continue;
  1062. }
  1063. if (buf[0] == '\0') {
  1064. continue;
  1065. }
  1066. i = 0;
  1067. q = buf;
  1068. while (*q) {
  1069. i++;
  1070. if (*q == '\n' || isspace((unsigned char) (*q))) {
  1071. break;
  1072. }
  1073. q++;
  1074. }
  1075. if (i >= 400) {
  1076. fprintf(stderr, "invalid rcfile line: %s/%s\n",
  1077. p, buf);
  1078. exit(1);
  1079. }
  1080. if (sscanf(buf, "%s", parm) != 1) {
  1081. fprintf(stderr, "invalid rcfile line: %s\n", p);
  1082. exit(1);
  1083. }
  1084. if (parm[0] == '-') {
  1085. strncpy(tmp, parm, 400);
  1086. } else {
  1087. tmp[0] = '-';
  1088. strncpy(tmp+1, parm, 400);
  1089. }
  1090. if (strstr(tmp, "-loop") == tmp) {
  1091. if (! getenv("X11VNC_LOOP_MODE")) {
  1092. check_loop_mode(argc, argv, 1);
  1093. exit(0);
  1094. }
  1095. }
  1096. argv2[argc2++] = strdup(tmp);
  1097. if (argc2 >= argmax) {
  1098. fprintf(stderr, "too many rcfile options\n");
  1099. exit(1);
  1100. }
  1101. p = buf;
  1102. p += strlen(parm);
  1103. p = lblanks(p);
  1104. if (*p == '\0') {
  1105. buf[0] = '\0';
  1106. continue;
  1107. }
  1108. tbuf = (char *) calloc(strlen(p) + 1, 1);
  1109. j = 0;
  1110. while (*p) {
  1111. if (*p == '\\' && *(p+1) == '#') {
  1112. ;
  1113. } else {
  1114. tbuf[j++] = *p;
  1115. }
  1116. p++;
  1117. }
  1118. argv2[argc2++] = strdup(tbuf);
  1119. free(tbuf);
  1120. if (argc2 >= argmax) {
  1121. fprintf(stderr, "too many rcfile options\n");
  1122. exit(1);
  1123. }
  1124. buf[0] = '\0';
  1125. }
  1126. fclose(rc);
  1127. free(buf);
  1128. }
  1129. pwlast = 0;
  1130. enclast = 0;
  1131. for (i=1; i < argc; i++) {
  1132. argv2[argc2++] = strdup(argv[i]);
  1133. if (pwlast || !strcmp("-passwd", argv[i])
  1134. || !strcmp("-viewpasswd", argv[i])) {
  1135. char *p = argv[i];
  1136. if (pwlast) {
  1137. pwlast = 0;
  1138. } else {
  1139. pwlast = 1;
  1140. }
  1141. strzero(p);
  1142. }
  1143. if (enclast || !strcmp("-enc", argv[i])) {
  1144. char *q, *p = argv[i];
  1145. if (enclast) {
  1146. enclast = 0;
  1147. } else {
  1148. enclast = 1;
  1149. }
  1150. q = strstr(p, "pw=");
  1151. if (q) {
  1152. strzero(q);
  1153. }
  1154. }
  1155. if (argc2 >= argmax) {
  1156. fprintf(stderr, "too many rcfile options\n");
  1157. exit(1);
  1158. }
  1159. }
  1160. }
  1161. static void immediate_switch_user(int argc, char* argv[]) {
  1162. int i, bequiet = 0;
  1163. for (i=1; i < argc; i++) {
  1164. if (strcmp(argv[i], "-inetd")) {
  1165. bequiet = 1;
  1166. }
  1167. if (strcmp(argv[i], "-quiet")) {
  1168. bequiet = 1;
  1169. }
  1170. if (strcmp(argv[i], "-q")) {
  1171. bequiet = 1;
  1172. }
  1173. }
  1174. for (i=1; i < argc; i++) {
  1175. char *u, *q;
  1176. if (strcmp(argv[i], "-users")) {
  1177. continue;
  1178. }
  1179. if (i == argc - 1) {
  1180. fprintf(stderr, "not enough arguments for: -users\n");
  1181. exit(1);
  1182. }
  1183. if (*(argv[i+1]) != '=') {
  1184. break;
  1185. }
  1186. /* wants an immediate switch: =bob */
  1187. u = strdup(argv[i+1]);
  1188. *u = '+';
  1189. q = strchr(u, '.');
  1190. if (q) {
  1191. user2group = (char **) malloc(2*sizeof(char *));
  1192. user2group[0] = strdup(u+1);
  1193. user2group[1] = NULL;
  1194. *q = '\0';
  1195. }
  1196. if (strstr(u, "+guess") == u) {
  1197. fprintf(stderr, "invalid user: %s\n", u+1);
  1198. exit(1);
  1199. }
  1200. if (!switch_user(u, 0)) {
  1201. fprintf(stderr, "Could not switch to user: %s\n", u+1);
  1202. exit(1);
  1203. } else {
  1204. if (!bequiet) {
  1205. fprintf(stderr, "Switched to user: %s\n", u+1);
  1206. }
  1207. started_as_root = 2;
  1208. }
  1209. free(u);
  1210. break;
  1211. }
  1212. }
  1213. static void quick_pw(char *str) {
  1214. char *p, *q;
  1215. char tmp[1024];
  1216. int db = 0;
  1217. if (db) fprintf(stderr, "quick_pw: %s\n", str);
  1218. if (! str || str[0] == '\0') {
  1219. exit(2);
  1220. }
  1221. if (str[0] != '%') {
  1222. exit(2);
  1223. }
  1224. /*
  1225. * "%-" or "%stdin" means read one line from stdin.
  1226. *
  1227. * "%env" means it is in $UNIXPW env var.
  1228. *
  1229. * starting "%/" or "%." means read the first line from that file.
  1230. *
  1231. * "%%" or "%" means prompt user.
  1232. *
  1233. * otherwise: %user:pass
  1234. */
  1235. if (!strcmp(str, "%-") || !strcmp(str, "%stdin")) {
  1236. if(fgets(tmp, 1024, stdin) == NULL) {
  1237. exit(2);
  1238. }
  1239. q = strdup(tmp);
  1240. } else if (!strcmp(str, "%env")) {
  1241. if (getenv("UNIXPW") == NULL) {
  1242. exit(2);
  1243. }
  1244. q = strdup(getenv("UNIXPW"));
  1245. } else if (!strcmp(str, "%%") || !strcmp(str, "%")) {
  1246. char *t, inp[1024];
  1247. fprintf(stdout, "username: ");
  1248. if(fgets(tmp, 128, stdin) == NULL) {
  1249. exit(2);
  1250. }
  1251. strcpy(inp, tmp);
  1252. t = strchr(inp, '\n');
  1253. if (t) {
  1254. *t = ':';
  1255. } else {
  1256. strcat(inp, ":");
  1257. }
  1258. fprintf(stdout, "password: ");
  1259. /* test mode: no_external_cmds does not apply */
  1260. system("stty -echo");
  1261. if(fgets(tmp, 128, stdin) == NULL) {
  1262. fprintf(stdout, "\n");
  1263. system("stty echo");
  1264. exit(2);
  1265. }
  1266. system("stty echo");
  1267. fprintf(stdout, "\n");
  1268. strcat(inp, tmp);
  1269. q = strdup(inp);
  1270. } else if (str[1] == '/' || str[1] == '.') {
  1271. FILE *in = fopen(str+1, "r");
  1272. if (in == NULL) {
  1273. exit(2);
  1274. }
  1275. if(fgets(tmp, 1024, in) == NULL) {
  1276. exit(2);
  1277. }
  1278. fclose(in);
  1279. q = strdup(tmp);
  1280. } else {
  1281. q = strdup(str+1);
  1282. }
  1283. p = (char *) malloc(strlen(q) + 10);
  1284. strcpy(p, q);
  1285. if (strchr(p, '\n') == NULL) {
  1286. strcat(p, "\n");
  1287. }
  1288. if ((q = strchr(p, ':')) == NULL) {
  1289. exit(2);
  1290. }
  1291. *q = '\0';
  1292. if (db) fprintf(stderr, "'%s' '%s'\n", p, q+1);
  1293. if (unixpw_cmd) {
  1294. if (cmd_verify(p, q+1)) {
  1295. fprintf(stdout, "Y %s\n", p);
  1296. exit(0);
  1297. } else {
  1298. fprintf(stdout, "N %s\n", p);
  1299. exit(1);
  1300. }
  1301. } else if (unixpw_nis) {
  1302. if (crypt_verify(p, q+1)) {
  1303. fprintf(stdout, "Y %s\n", p);
  1304. exit(0);
  1305. } else {
  1306. fprintf(stdout, "N %s\n", p);
  1307. exit(1);
  1308. }
  1309. } else {
  1310. char *ucmd = getenv("UNIXPW_CMD");
  1311. if (su_verify(p, q+1, ucmd, NULL, NULL, 1)) {
  1312. fprintf(stdout, "Y %s\n", p);
  1313. exit(0);
  1314. } else {
  1315. fprintf(stdout, "N %s\n", p);
  1316. exit(1);
  1317. }
  1318. }
  1319. /* NOTREACHED */
  1320. exit(2);
  1321. }
  1322. static void print_settings(int try_http, int bg, char *gui_str) {
  1323. fprintf(stderr, "\n");
  1324. fprintf(stderr, "Settings:\n");
  1325. fprintf(stderr, " display: %s\n", use_dpy ? use_dpy
  1326. : "null");
  1327. #if SMALL_FOOTPRINT < 2
  1328. fprintf(stderr, " authfile: %s\n", auth_file ? auth_file
  1329. : "null");
  1330. fprintf(stderr, " subwin: 0x%lx\n", subwin);
  1331. fprintf(stderr, " -sid mode: %d\n", rootshift);
  1332. fprintf(stderr, " clip: %s\n", clip_str ? clip_str
  1333. : "null");
  1334. fprintf(stderr, " flashcmap: %d\n", flash_cmap);
  1335. fprintf(stderr, " shiftcmap: %d\n", shift_cmap);
  1336. fprintf(stderr, " force_idx: %d\n", force_indexed_color);
  1337. fprintf(stderr, " cmap8to24: %d\n", cmap8to24);
  1338. fprintf(stderr, " 8to24_opts: %s\n", cmap8to24_str ? cmap8to24_str
  1339. : "null");
  1340. fprintf(stderr, " 24to32: %d\n", xform24to32);
  1341. fprintf(stderr, " visual: %s\n", visual_str ? visual_str
  1342. : "null");
  1343. fprintf(stderr, " overlay: %d\n", overlay);
  1344. fprintf(stderr, " ovl_cursor: %d\n", overlay_cursor);
  1345. fprintf(stderr, " scaling: %d %.4f %.4f\n", scaling, scale_fac_x, scale_fac_y);
  1346. fprintf(stderr, " viewonly: %d\n", view_only);
  1347. fprintf(stderr, " shared: %d\n", shared);
  1348. fprintf(stderr, " conn_once: %d\n", connect_once);
  1349. fprintf(stderr, " timeout: %d\n", first_conn_timeout);
  1350. fprintf(stderr, " ping: %d\n", ping_interval);
  1351. fprintf(stderr, " inetd: %d\n", inetd);
  1352. fprintf(stderr, " tightfilexfer: %d\n", tightfilexfer);
  1353. fprintf(stderr, " http: %d\n", try_http);
  1354. fprintf(stderr, " connect: %s\n", client_connect
  1355. ? client_connect : "null");
  1356. fprintf(stderr, " connectfile %s\n", client_connect_file
  1357. ? client_connect_file : "null");
  1358. fprintf(stderr, " vnc_conn: %d\n", vnc_connect);
  1359. fprintf(stderr, " allow: %s\n", allow_list ? allow_list
  1360. : "null");
  1361. fprintf(stderr, " input: %s\n", allowed_input_str
  1362. ? allowed_input_str : "null");
  1363. fprintf(stderr, " passfile: %s\n", passwdfile ? passwdfile
  1364. : "null");
  1365. fprintf(stderr, " unixpw: %d\n", unixpw);
  1366. fprintf(stderr, " unixpw_lst: %s\n", unixpw_list ? unixpw_list:"null");
  1367. fprintf(stderr, " ssl: %s\n", openssl_pem ? openssl_pem:"null");
  1368. fprintf(stderr, " ssldir: %s\n", ssl_certs_dir ? ssl_certs_dir:"null");
  1369. fprintf(stderr, " ssltimeout %d\n", ssl_timeout_secs);
  1370. fprintf(stderr, " sslverify: %s\n", ssl_verify ? ssl_verify:"null");
  1371. fprintf(stderr, " stunnel: %d\n", use_stunnel);
  1372. fprintf(stderr, " accept: %s\n", accept_cmd ? accept_cmd
  1373. : "null");
  1374. fprintf(stderr, " accept: %s\n", afteraccept_cmd ? afteraccept_cmd
  1375. : "null");
  1376. fprintf(stderr, " gone: %s\n", gone_cmd ? gone_cmd
  1377. : "null");
  1378. fprintf(stderr, " users: %s\n", users_list ? users_list
  1379. : "null");
  1380. fprintf(stderr, " using_shm: %d\n", using_shm);
  1381. fprintf(stderr, " flipbytes: %d\n", flip_byte_order);
  1382. fprintf(stderr, " onetile: %d\n", single_copytile);
  1383. fprintf(stderr, " solid: %s\n", solid_str
  1384. ? solid_str : "null");
  1385. fprintf(stderr, " blackout: %s\n", blackout_str
  1386. ? blackout_str : "null");
  1387. fprintf(stderr, " xinerama: %d\n", xinerama);
  1388. fprintf(stderr, " xtrap: %d\n", xtrap_input);
  1389. fprintf(stderr, " xrandr: %d\n", xrandr);
  1390. fprintf(stderr, " xrandrmode: %s\n", xrandr_mode ? xrandr_mode
  1391. : "null");
  1392. fprintf(stderr, " padgeom: %s\n", pad_geometry
  1393. ? pad_geometry : "null");
  1394. fprintf(stderr, " logfile: %s\n", logfile ? logfile
  1395. : "null");
  1396. fprintf(stderr, " logappend: %d\n", logfile_append);
  1397. fprintf(stderr, " flag: %s\n", flagfile ? flagfile
  1398. : "null");
  1399. fprintf(stderr, " rm_flag: %s\n", rm_flagfile ? rm_flagfile
  1400. : "null");
  1401. fprintf(stderr, " rc_file: \"%s\"\n", rc_rcfile ? rc_rcfile
  1402. : "null");
  1403. fprintf(stderr, " norc: %d\n", rc_norc);
  1404. fprintf(stderr, " dbg: %d\n", crash_debug);
  1405. fprintf(stderr, " bg: %d\n", bg);
  1406. fprintf(stderr, " mod_tweak: %d\n", use_modifier_tweak);
  1407. fprintf(stderr, " isolevel3: %d\n", use_iso_level3);
  1408. fprintf(stderr, " xkb: %d\n", use_xkb_modtweak);
  1409. fprintf(stderr, " skipkeys: %s\n",
  1410. skip_keycodes ? skip_keycodes : "null");
  1411. fprintf(stderr, " sloppykeys: %d\n", sloppy_keys);
  1412. fprintf(stderr, " skip_dups: %d\n", skip_duplicate_key_events);
  1413. fprintf(stderr, " addkeysyms: %d\n", add_keysyms);
  1414. fprintf(stderr, " xkbcompat: %d\n", xkbcompat);
  1415. fprintf(stderr, " clearmods: %d\n", clear_mods);
  1416. fprintf(stderr, " remap: %s\n", remap_file ? remap_file
  1417. : "null");
  1418. fprintf(stderr, " norepeat: %d\n", no_autorepeat);
  1419. fprintf(stderr, " norepeatcnt:%d\n", no_repeat_countdown);
  1420. fprintf(stderr, " nofb: %d\n", nofb);
  1421. fprintf(stderr, " watchbell: %d\n", watch_bell);
  1422. fprintf(stderr, " watchsel: %d\n", watch_selection);
  1423. fprintf(stderr, " watchprim: %d\n", watch_primary);
  1424. fprintf(stderr, " seldir: %s\n", sel_direction ?
  1425. sel_direction : "null");
  1426. fprintf(stderr, " cursor: %d\n", show_cursor);
  1427. fprintf(stderr, " multicurs: %d\n", show_multiple_cursors);
  1428. fprintf(stderr, " curs_mode: %s\n", multiple_cursors_mode
  1429. ? multiple_cursors_mode : "null");
  1430. fprintf(stderr, " arrow: %d\n", alt_arrow);
  1431. fprintf(stderr, " xfixes: %d\n", use_xfixes);
  1432. fprintf(stderr, " alphacut: %d\n", alpha_threshold);
  1433. fprintf(stderr, " alphafrac: %.2f\n", alpha_frac);
  1434. fprintf(stderr, " alpharemove:%d\n", alpha_remove);
  1435. fprintf(stderr, " alphablend: %d\n", alpha_blend);
  1436. fprintf(stderr, " cursorshape:%d\n", cursor_shape_updates);
  1437. fprintf(stderr, " cursorpos: %d\n", cursor_pos_updates);
  1438. fprintf(stderr, " xwarpptr: %d\n", use_xwarppointer);
  1439. fprintf(stderr, " alwaysinj: %d\n", always_inject);
  1440. fprintf(stderr, " buttonmap: %s\n", pointer_remap
  1441. ? pointer_remap : "null");
  1442. fprintf(stderr, " dragging: %d\n", show_dragging);
  1443. fprintf(stderr, " ncache: %d\n", ncache);
  1444. fprintf(stderr, " wireframe: %s\n", wireframe_str ?
  1445. wireframe_str : WIREFRAME_PARMS);
  1446. fprintf(stderr, " wirecopy: %s\n", wireframe_copyrect ?
  1447. wireframe_copyrect : wireframe_copyrect_default);
  1448. fprintf(stderr, " scrollcopy: %s\n", scroll_copyrect ?
  1449. scroll_copyrect : scroll_copyrect_default);
  1450. fprintf(stderr, " scr_area: %d\n", scrollcopyrect_min_area);
  1451. fprintf(stderr, " scr_skip: %s\n", scroll_skip_str ?
  1452. scroll_skip_str : scroll_skip_str0);
  1453. fprintf(stderr, " scr_inc: %s\n", scroll_good_str ?
  1454. scroll_good_str : scroll_good_str0);
  1455. fprintf(stderr, " scr_keys: %s\n", scroll_key_list_str ?
  1456. scroll_key_list_str : "null");
  1457. fprintf(stderr, " scr_term: %s\n", scroll_term_str ?
  1458. scroll_term_str : "null");
  1459. fprintf(stderr, " scr_keyrep: %s\n", max_keyrepeat_str ?
  1460. max_keyrepeat_str : "null");
  1461. fprintf(stderr, " scr_parms: %s\n", scroll_copyrect_str ?
  1462. scroll_copyrect_str : SCROLL_COPYRECT_PARMS);
  1463. fprintf(stderr, " fixscreen: %s\n", screen_fixup_str ?
  1464. screen_fixup_str : "null");
  1465. fprintf(stderr, " noxrecord: %d\n", noxrecord);
  1466. fprintf(stderr, " grabbuster: %d\n", grab_buster);
  1467. fprintf(stderr, " ptr_mode: %d\n", pointer_mode);
  1468. fprintf(stderr, " inputskip: %d\n", ui_skip);
  1469. fprintf(stderr, " speeds: %s\n", speeds_str
  1470. ? speeds_str : "null");
  1471. fprintf(stderr, " wmdt: %s\n", wmdt_str
  1472. ? wmdt_str : "null");
  1473. fprintf(stderr, " debug_ptr: %d\n", debug_pointer);
  1474. fprintf(stderr, " debug_key: %d\n", debug_keyboard);
  1475. fprintf(stderr, " defer: %d\n", defer_update);
  1476. fprintf(stderr, " waitms: %d\n", waitms);
  1477. fprintf(stderr, " wait_ui: %.2f\n", wait_ui);
  1478. fprintf(stderr, " nowait_bog: %d\n", !wait_bog);
  1479. fprintf(stderr, " slow_fb: %.2f\n", slow_fb);
  1480. fprintf(stderr, " xrefresh: %.2f\n", xrefresh);
  1481. fprintf(stderr, " readtimeout: %d\n", rfbMaxClientWait/1000);
  1482. fprintf(stderr, " take_naps: %d\n", take_naps);
  1483. fprintf(stderr, " sb: %d\n", screen_blank);
  1484. fprintf(stderr, " fbpm: %d\n", !watch_fbpm);
  1485. fprintf(stderr, " dpms: %d\n", !watch_dpms);
  1486. fprintf(stderr, " xdamage: %d\n", use_xdamage);
  1487. fprintf(stderr, " xd_area: %d\n", xdamage_max_area);
  1488. fprintf(stderr, " xd_mem: %.3f\n", xdamage_memory);
  1489. fprintf(stderr, " sigpipe: %s\n", sigpipe
  1490. ? sigpipe : "null");
  1491. fprintf(stderr, " threads: %d\n", use_threads);
  1492. fprintf(stderr, " fs_frac: %.2f\n", fs_frac);
  1493. fprintf(stderr, " gaps_fill: %d\n", gaps_fill);
  1494. fprintf(stderr, " grow_fill: %d\n", grow_fill);
  1495. fprintf(stderr, " tile_fuzz: %d\n", tile_fuzz);
  1496. fprintf(stderr, " snapfb: %d\n", use_snapfb);
  1497. fprintf(stderr, " rawfb: %s\n", raw_fb_str
  1498. ? raw_fb_str : "null");
  1499. fprintf(stderr, " pipeinput: %s\n", pipeinput_str
  1500. ? pipeinput_str : "null");
  1501. fprintf(stderr, " gui: %d\n", launch_gui);
  1502. fprintf(stderr, " gui_mode: %s\n", gui_str
  1503. ? gui_str : "null");
  1504. fprintf(stderr, " noremote: %d\n", !accept_remote_cmds);
  1505. fprintf(stderr, " unsafe: %d\n", !safe_remote_only);
  1506. fprintf(stderr, " privremote: %d\n", priv_remote);
  1507. fprintf(stderr, " safer: %d\n", more_safe);
  1508. fprintf(stderr, " nocmds: %d\n", no_external_cmds);
  1509. fprintf(stderr, " deny_all: %d\n", deny_all);
  1510. fprintf(stderr, " pid: %d\n", getpid());
  1511. fprintf(stderr, "\n");
  1512. #endif
  1513. }
  1514. static void check_loop_mode(int argc, char* argv[], int force) {
  1515. int i;
  1516. int loop_mode = 0, loop_sleep = 2000, loop_max = 0;
  1517. if (force) {
  1518. loop_mode = 1;
  1519. }
  1520. for (i=1; i < argc; i++) {
  1521. char *p = argv[i];
  1522. if (strstr(p, "--") == p) {
  1523. p++;
  1524. }
  1525. if (strstr(p, "-loop") == p) {
  1526. char *q;
  1527. loop_mode = 1;
  1528. if ((q = strchr(p, ',')) != NULL) {
  1529. loop_max = atoi(q+1);
  1530. *q = '\0';
  1531. }
  1532. if (strstr(p, "-loopbg") == p) {
  1533. set_env("X11VNC_LOOP_MODE_BG", "1");
  1534. loop_sleep = 500;
  1535. }
  1536. q = strpbrk(p, "0123456789");
  1537. if (q) {
  1538. loop_sleep = atoi(q);
  1539. if (loop_sleep <= 0) {
  1540. loop_sleep = 20;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. if (loop_mode && getenv("X11VNC_LOOP_MODE") == NULL) {
  1546. #if LIBVNCSERVER_HAVE_FORK
  1547. char **argv2;
  1548. int k, i = 1;
  1549. set_env("X11VNC_LOOP_MODE", "1");
  1550. argv2 = (char **) malloc((argc+1)*sizeof(char *));
  1551. for (k=0; k < argc+1; k++) {
  1552. argv2[k] = NULL;
  1553. if (k < argc) {
  1554. argv2[k] = argv[k];
  1555. }
  1556. }
  1557. while (1) {
  1558. int status;
  1559. pid_t p;
  1560. fprintf(stderr, "\n --- x11vnc loop: %d ---\n\n", i++);
  1561. fflush(stderr);
  1562. usleep(500 * 1000);
  1563. if ((p = fork()) > 0) {
  1564. fprintf(stderr, " --- x11vnc loop: waiting "
  1565. "for: %d\n\n", p);
  1566. wait(&status);
  1567. } else if (p == -1) {
  1568. fprintf(stderr, "could not fork\n");
  1569. perror("fork");
  1570. exit(1);
  1571. } else {
  1572. /* loop mode: no_external_cmds does not apply */
  1573. execvp(argv[0], argv2);
  1574. exit(1);
  1575. }
  1576. if (loop_max > 0 && i > loop_max) {
  1577. fprintf(stderr, "\n --- x11vnc loop: did %d"
  1578. " done. ---\n\n", loop_max);
  1579. break;
  1580. }
  1581. fprintf(stderr, "\n --- x11vnc loop: sleeping %d ms "
  1582. "---\n\n", loop_sleep);
  1583. usleep(loop_sleep * 1000);
  1584. }
  1585. exit(0);
  1586. #else
  1587. fprintf(stderr, "fork unavailable, cannot do -loop mode\n");
  1588. exit(1);
  1589. #endif
  1590. }
  1591. }
  1592. extern int appshare_main(int argc, char* argv[]);
  1593. static void check_appshare_mode(int argc, char* argv[]) {
  1594. #ifndef WIN32
  1595. int i;
  1596. for (i=1; i < argc; i++) {
  1597. char *p = argv[i];
  1598. if (strstr(p, "--") == p) {
  1599. p++;
  1600. }
  1601. if (strstr(p, "-appshare") == p) {
  1602. appshare_main(argc, argv);
  1603. exit(0);
  1604. }
  1605. }
  1606. #endif
  1607. }
  1608. static void store_homedir_passwd(char *file) {
  1609. #ifndef WIN32
  1610. char str1[32], str2[32], *p, *h, *f;
  1611. struct stat sbuf;
  1612. str1[0] = '\0';
  1613. str2[0] = '\0';
  1614. /* storepasswd */
  1615. if (no_external_cmds || !cmd_ok("storepasswd")) {
  1616. fprintf(stderr, "-nocmds cannot be used with -storepasswd\n");
  1617. exit(1);
  1618. }
  1619. fprintf(stderr, "Enter VNC password: ");
  1620. system("stty -echo");
  1621. if (fgets(str1, 32, stdin) == NULL) {
  1622. perror("fgets");
  1623. system("stty echo");
  1624. exit(1);
  1625. }
  1626. fprintf(stderr, "\n");
  1627. fprintf(stderr, "Verify password: ");
  1628. if (fgets(str2, 32, stdin) == NULL) {
  1629. perror("fgets");
  1630. system("stty echo");
  1631. exit(1);
  1632. }
  1633. fprintf(stderr, "\n");
  1634. system("stty echo");
  1635. if ((p = strchr(str1, '\n')) != NULL) {
  1636. *p = '\0';
  1637. }
  1638. if ((p = strchr(str2, '\n')) != NULL) {
  1639. *p = '\0';
  1640. }
  1641. if (strcmp(str1, str2)) {
  1642. fprintf(stderr, "** passwords differ.\n");
  1643. exit(1);
  1644. }
  1645. if (str1[0] == '\0') {
  1646. fprintf(stderr, "** no password supplied.\n");
  1647. exit(1);
  1648. }
  1649. if (file != NULL) {
  1650. f = file;
  1651. } else {
  1652. h = getenv("HOME");
  1653. if (! h) {
  1654. fprintf(stderr, "** $HOME not set.\n");
  1655. exit(1);
  1656. }
  1657. f = (char *) malloc(strlen(h) + strlen("/.vnc/passwd") + 1);
  1658. sprintf(f, "%s/.vnc", h);
  1659. if (stat(f, &sbuf) != 0) {
  1660. if (mkdir(f, 0755) != 0) {
  1661. fprintf(stderr, "** could not create directory %s\n", f);
  1662. perror("mkdir");
  1663. exit(1);
  1664. }
  1665. } else if (! S_ISDIR(sbuf.st_mode)) {
  1666. fprintf(stderr, "** not a directory %s\n", f);
  1667. exit(1);
  1668. }
  1669. sprintf(f, "%s/.vnc/passwd", h);
  1670. }
  1671. fprintf(stderr, "Write password to %s? [y]/n ", f);
  1672. if (fgets(str2, 32, stdin) == NULL) {
  1673. perror("fgets");
  1674. exit(1);
  1675. }
  1676. if (str2[0] == 'n' || str2[0] == 'N') {
  1677. fprintf(stderr, "not creating password.\n");
  1678. exit(1);
  1679. }
  1680. if (rfbEncryptAndStorePasswd(str1, f) != 0) {
  1681. fprintf(stderr, "** error creating password: %s\n", f);
  1682. perror("storepasswd");
  1683. exit(1);
  1684. }
  1685. if (stat(f, &sbuf) != 0) {
  1686. fprintf(stderr, "** error creating password: %s\n", f);
  1687. perror("stat");
  1688. exit(1);
  1689. }
  1690. fprintf(stdout, "Password written to: %s\n", f);
  1691. exit(0);
  1692. #endif
  1693. }
  1694. void ncache_beta_tester_message(void) {
  1695. char msg[] =
  1696. "\n"
  1697. "******************************************************************************\n"
  1698. "\n"
  1699. "Hello! Exciting News!!\n"
  1700. "\n"
  1701. "You have been selected at random to beta-test the x11vnc '-ncache' VNC\n"
  1702. "client-side pixel caching feature!\n"
  1703. "\n"
  1704. "This scheme stores pixel data offscreen on the VNC viewer side for faster\n"
  1705. "retrieval. It should work with any VNC viewer.\n"
  1706. "\n"
  1707. "This method requires much testing and so we hope you will try it out and\n"
  1708. "perhaps even report back your observations. However, if you do not want\n"
  1709. "to test or use the feature, run x11vnc like this:\n"
  1710. "\n"
  1711. " x11vnc -noncache ...\n"
  1712. "\n"
  1713. "Your current setting is: -ncache %d\n"
  1714. "\n"
  1715. "The feature needs additional testing because we want to have x11vnc\n"
  1716. "performance enhancements on by default. Otherwise, only a relative few\n"
  1717. "would notice and use the -ncache option (e.g. the wireframe and scroll\n"
  1718. "detection features are on by default). A couple things to note:\n"
  1719. "\n"
  1720. " 1) It uses a large amount of RAM (on both viewer and server sides)\n"
  1721. "\n"
  1722. " 2) You can actually see the cached pixel data if you scroll down\n"
  1723. " to it in your viewer; adjust your viewer's size to hide it.\n"
  1724. "\n"
  1725. "More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching\n"
  1726. "\n"
  1727. "waiting for connections:\n"
  1728. ;
  1729. char msg2[] =
  1730. "\n"
  1731. "******************************************************************************\n"
  1732. "Have you tried the x11vnc '-ncache' VNC client-side pixel caching feature yet?\n"
  1733. "\n"
  1734. "The scheme stores pixel data offscreen on the VNC viewer side for faster\n"
  1735. "retrieval. It should work with any VNC viewer. Try it by running:\n"
  1736. "\n"
  1737. " x11vnc -ncache 10 ...\n"
  1738. "\n"
  1739. "One can also add -ncache_cr for smooth 'copyrect' window motion.\n"
  1740. "More info: http://www.karlrunge.com/x11vnc/faq.html#faq-client-caching\n"
  1741. "\n"
  1742. ;
  1743. if (raw_fb_str && !macosx_console) {
  1744. return;
  1745. }
  1746. if (quiet) {
  1747. return;
  1748. }
  1749. if (remote_direct) {
  1750. return;
  1751. }
  1752. if (nofb) {
  1753. return;
  1754. }
  1755. #ifdef NO_NCACHE
  1756. return;
  1757. #endif
  1758. if (ncache == 0) {
  1759. fprintf(stderr, "%s", msg2);
  1760. ncache0 = ncache = 0;
  1761. } else {
  1762. fprintf(stderr, msg, ncache);
  1763. }
  1764. }
  1765. #define SHOW_NO_PASSWORD_WARNING \
  1766. (!got_passwd && !got_rfbauth && (!got_passwdfile || !passwd_list) \
  1767. && !query_cmd && !remote_cmd && !unixpw && !got_gui_pw \
  1768. && ! ssl_verify && !inetd && !terminal_services_daemon)
  1769. static void do_sleepin(char *sleep) {
  1770. int n1, n2, nt;
  1771. double f1, f2, ft;
  1772. if (strchr(sleep, '-')) {
  1773. double s = atof(strchr(sleep, '-')+1);
  1774. if (sscanf(sleep, "%d-%d", &n1, &n2) == 2) {
  1775. if (n1 > n2) {
  1776. nt = n1;
  1777. n1 = n2;
  1778. n2 = nt;
  1779. }
  1780. s = n1 + rfac() * (n2 - n1);
  1781. } else if (sscanf(sleep, "%lf-%lf", &f1, &f2) == 2) {
  1782. if (f1 > f2) {
  1783. ft = f1;
  1784. f1 = f2;
  1785. f2 = ft;
  1786. }
  1787. s = f1 + rfac() * (f2 - f1);
  1788. }
  1789. if (getenv("DEBUG_SLEEPIN")) fprintf(stderr, "sleepin: %f secs\n", s);
  1790. usleep( (int) (1000*1000*s) );
  1791. } else {
  1792. n1 = atoi(sleep);
  1793. if (getenv("DEBUG_SLEEPIN")) fprintf(stderr, "sleepin: %d secs\n", n1);
  1794. if (n1 > 0) {
  1795. usleep(1000*1000*n1);
  1796. }
  1797. }
  1798. }
  1799. static void check_guess_auth_file(void) {
  1800. if (!strcasecmp(auth_file, "guess")) {
  1801. char line[4096], *cmd, *q, *disp = use_dpy ? use_dpy: "";
  1802. FILE *p;
  1803. int n;
  1804. if (!program_name) {
  1805. rfbLog("-auth guess: no program_name found.\n");
  1806. clean_up_exit(1);

Large files files are truncated, but you can click here to view the full file