x2vnc-1.0/README100664 1750 1750 2711 6560206077 11762 0ustar hubbehubbe x2vnc - A dual-screen hack Written by Fredrik Hübinette Based on ideas from x2x and code from vncviewer. This program merges the capabilities of x2x and vncviewer. It will allow a machine with an X display and a machine with a VNC server running on it's main screen to act as if they were two displays connected to one machine. When you move your mouse pointer off the screen in a direction of your choosing, the pointer will appear on the other screen instead. To compile x2vmc, execute the commands 'xmkmf' and then 'make'. The latest version of this program should be available from http://www.hubbe.net/~hubbe/x2vnc.html For more info about VNC: http://www.orl.co.uk/vnc/ For more info about x2x: http://ftp.digital.com/pub/Digital/SRC/x2x/ This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this software; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. x2vnc-1.0/COPYING100664 1750 1750 43076 6560202753 12163 0ustar hubbehubbe GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. x2vnc-1.0/Imakefile100664 1750 1750 1107 6560202753 12706 0ustar hubbehubbeVERSION=1.0 SRCS = args.c listen.c rfbproto.c sockets.c x2vnc.c x.c vncauth.c d3des.c HFILES=d3des.h rfbproto.h vncauth.h x2vnc.h OBJS = args.o listen.o rfbproto.o sockets.o x2vnc.o x.o vncauth.o d3des.o INCLUDES = -I. XFILES=README COPYING Imakefile $(SRCS) $(HFILES) NormalProgramTarget(x2vnc,$(OBJS),$(DEPXLIB) $(VNCAUTH_LIB),$(XLIB) $(VNCAUTH_LIB) $(LIBS),) DependTarget() export: ( cd .. ; \ ln -s x2vnc x2vnc-$(VERSION) ; \ tar cvf - `for a in $(XFILES) ; do echo x2vnc-$(VERSION)/$$a ; done` | gzip -c9 >x2vnc-$(VERSION).tar.gz ;\ rm x2vnc-$(VERSION) ; \ echo Done ) x2vnc-1.0/args.c100664 1750 1750 10364 6560202753 12222 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * args.c - argument processing. */ #include #include #define FLASHPORT (5400) /* Offset to listen for `flash' commands */ #define CLIENTPORT (5500) /* Offset to listen for reverse connections */ #define SERVERPORT (5900) /* Offset to server for regular connections */ char *programName; char hostname[256]; int port; Bool listenSpecified = False; int listenPort = 0, flashPort = 0; char *displayname = NULL; Bool shareDesktop = False; CARD32 explicitEncodings[MAX_ENCODINGS]; int nExplicitEncodings = 0; Bool addCopyRect = True; Bool addRRE = True; Bool addCoRRE = True; Bool addHextile = True; Bool useBGR233 = False; Bool forceOwnCmap = False; Bool forceTruecolour = False; Bool resurface = True; int requestedDepth = 0; char *geometry = NULL; int wmDecorationWidth = 4; int wmDecorationHeight = 24; char *passwdFile = NULL; int updateRequestPeriodms = 0; int updateRequestX = 0; int updateRequestY = 0; int updateRequestW = 0; int updateRequestH = 0; int rawDelay = 0; int copyRectDelay = 0; Bool debug = False; void usage() { fprintf(stderr,"\n" "usage: %s [] :\n" " %s [] -listen []\n" "\n" " are:\n" " [-display ] [-shared]\n" " [-north] [-south] [-east] [-west]\n" " [-passwd ]\n" " [-resurface]\n" ,programName,programName); exit(1); } void processArgs(int argc, char **argv) { int i; Bool argumentSpecified = False; programName = argv[0]; for (i = 1; i < argc; i++) { if (strcmp(argv[i],"-display") == 0) { if (++i >= argc) usage(); displayname = argv[i]; } else if (strcmp(argv[i],"-east") == 0) { edge=EDGE_EAST; } else if (strcmp(argv[i],"-west") == 0) { edge=EDGE_WEST; } else if (strcmp(argv[i],"-north") == 0) { edge=EDGE_NORTH; } else if (strcmp(argv[i],"-south") == 0) { edge=EDGE_SOUTH; } else if (strcmp(argv[i],"-resurface") == 0) { resurface=True; } else if (strcmp(argv[i],"-shared") == 0) { shareDesktop = True; } else if (strcmp(argv[i],"-passwd") == 0) { if (++i >= argc) usage(); passwdFile = argv[i]; } else if (strcmp(argv[i],"-debug") == 0) { debug = True; } else if (strcmp(argv[i],"-listen") == 0) { if (argumentSpecified) usage(); listenSpecified = True; if (++i < argc) { listenPort = CLIENTPORT+atoi(argv[i]); flashPort = FLASHPORT+atoi(argv[i]); } } else if (argv[i][0] != '-') { if (argumentSpecified || listenSpecified) usage(); argumentSpecified = True; if (sscanf(argv[i], "%[^:]:%d", hostname, &port) != 2) usage(); if (port < 100) port += SERVERPORT; } else { usage(); } } if (listenSpecified) { if (listenPort == 0) { char *display; char *colonPos; struct utsname hostinfo; display = XDisplayName(displayname); colonPos = strchr(display, ':'); uname(&hostinfo); if (colonPos && ((colonPos == display) || (strncmp(hostinfo.nodename, display, strlen(hostinfo.nodename)) == 0))) { listenPort = CLIENTPORT+atoi(colonPos+1); flashPort = FLASHPORT+atoi(colonPos+1); } else { fprintf(stderr,"%s: cannot work out which display number to " "listen on.\n", programName); fprintf(stderr, "Please specify explicitly with -listen \n"); exit(1); } } } else if (!argumentSpecified) { usage(); } } x2vnc-1.0/listen.c100664 1750 1750 12646 6560202753 12571 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * listen.c - listen for incoming connections */ #include #include #include #include #include #define FLASHWIDTH 50 /* pixels */ #define FLASHDELAY 1 /* seconds */ static Font flashFont; static void getFlashFont(Display *d); static void flashDisplay(Display *d, char *user); void listenForIncomingConnections() { Display *d; XEvent ev; int listenSocket, flashSocket, sock; fd_set fds; char flashUser[256]; int n; if (!(d = XOpenDisplay(displayname))) { fprintf(stderr,"%s: unable to open display %s\n", programName, XDisplayName(displayname)); exit(1); } getFlashFont(d); listenSocket = ListenAtTcpPort(listenPort); flashSocket = ListenAtTcpPort(flashPort); if ((listenSocket < 0) || (flashSocket < 0)) exit(1); fprintf(stderr,"%s: Listening on port %d (flash port %d)\n", programName,listenPort,flashPort); while (True) { /* reap any zombies */ int status, pid; while ((pid= wait3(&status, WNOHANG, (struct rusage *)0))>0); /* discard any X events */ while (XCheckIfEvent(d, &ev, AllXEventsPredicate, NULL)) ; FD_ZERO(&fds); FD_SET(flashSocket, &fds); FD_SET(listenSocket, &fds); FD_SET(ConnectionNumber(d), &fds); select(FD_SETSIZE, &fds, NULL, NULL, NULL); if (FD_ISSET(flashSocket, &fds)) { sock = AcceptTcpConnection(flashSocket); if (sock < 0) exit(1); n = read(sock, flashUser, 255); if (n > 0) { flashUser[n] = 0; flashDisplay(d, flashUser); } else { flashDisplay(d, NULL); } close(sock); } if (FD_ISSET(listenSocket, &fds)) { rfbsock = AcceptTcpConnection(listenSocket); if (rfbsock < 0) exit(1); XCloseDisplay(d); /* Now fork off a new process to deal with it... */ switch (fork()) { case -1: perror("fork"); exit(1); case 0: /* child - return to caller */ close(listenSocket); close(flashSocket); return; default: /* parent - go round and listen again */ close(rfbsock); if (!(d = XOpenDisplay(displayname))) { fprintf(stderr,"%s: unable to open display \"%s\"\r\n", programName, XDisplayName (displayname)); exit(1); } getFlashFont(d); break; } } } } /* * getFlashFont */ static void getFlashFont(Display *d) { char fontName[256]; char **fontNames; int nFontNames; sprintf(fontName,"-*-courier-bold-r-*-*-%d-*-*-*-*-*-iso8859-1", FLASHWIDTH); fontNames = XListFonts(d, fontName, 1, &nFontNames); if (nFontNames == 1) { XFreeFontNames(fontNames); } else { sprintf(fontName,"fixed"); } flashFont = XLoadFont(d, fontName); } /* * flashDisplay */ static void flashDisplay(Display *d, char *user) { Window w1, w2, w3, w4; XSetWindowAttributes attr; XBell(d, 100); XForceScreenSaver(d, ScreenSaverReset); attr.background_pixel = BlackPixel(d, DefaultScreen(d)); attr.override_redirect = 1; attr.save_under = True; w1 = XCreateWindow(d, DefaultRootWindow(d), 0, 0, WidthOfScreen(DefaultScreenOfDisplay(d)), FLASHWIDTH, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel|CWOverrideRedirect|CWSaveUnder, &attr); w2 = XCreateWindow(d, DefaultRootWindow(d), 0, 0, FLASHWIDTH, HeightOfScreen(DefaultScreenOfDisplay(d)), 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel|CWOverrideRedirect|CWSaveUnder, &attr); w3 = XCreateWindow(d, DefaultRootWindow(d), WidthOfScreen(DefaultScreenOfDisplay(d))-FLASHWIDTH, 0, FLASHWIDTH, HeightOfScreen(DefaultScreenOfDisplay(d)), 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel|CWOverrideRedirect|CWSaveUnder, &attr); w4 = XCreateWindow(d, DefaultRootWindow(d), 0, HeightOfScreen(DefaultScreenOfDisplay(d))-FLASHWIDTH, WidthOfScreen(DefaultScreenOfDisplay(d)), FLASHWIDTH, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixel|CWOverrideRedirect|CWSaveUnder, &attr); XMapWindow(d, w1); XMapWindow(d, w2); XMapWindow(d, w3); XMapWindow(d, w4); if (user) { GC gc; XGCValues gcv; gcv.foreground = WhitePixel(d, DefaultScreen(d)); gcv.font = flashFont; gc = XCreateGC(d, w1, GCForeground|GCFont, &gcv); XDrawString(d, w1, gc, WidthOfScreen(DefaultScreenOfDisplay(d)) / 2 - FLASHWIDTH, (FLASHWIDTH * 3 / 4), user, strlen(user)); } XFlush(d); sleep(FLASHDELAY); XDestroyWindow(d, w1); XDestroyWindow(d, w2); XDestroyWindow(d, w3); XDestroyWindow(d, w4); XFlush(d); } x2vnc-1.0/rfbproto.c100664 1750 1750 50052 6560214244 13117 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * Seriously modified by Fredrik Hübinette */ /* * rfbproto.c - functions to deal with client side of RFB protocol. */ #include #include #include #include #include #include static Bool HandleHextileEncoding8(int x, int y, int w, int h); static Bool HandleHextileEncoding16(int x, int y, int w, int h); static Bool HandleHextileEncoding32(int x, int y, int w, int h); int rfbsock; char *desktopName; rfbPixelFormat myFormat; rfbServerInitMsg si; struct timeval updateRequestTime; Bool sendUpdateRequest; int endianTest = 1; /* note that the CoRRE encoding uses this buffer and assumes it is big enough to hold 255 * 255 * 32 bits -> 260100 bytes. 640*480 = 307200 bytes */ /* also hextile assumes it is big enough to hold 16 * 16 * 32 bits */ #define BUFFER_SIZE (640*480) static char buffer[BUFFER_SIZE]; /* * ConnectToRFBServer. */ Bool ConnectToRFBServer(const char *hostname, int port) { unsigned int host; if (!StringToIPAddr(hostname, &host)) { fprintf(stderr,"%s: couldn't convert '%s' to host address\n", programName,hostname); return False; } rfbsock = ConnectToTcpAddr(host, port); if (rfbsock < 0) { fprintf(stderr,"%s: unable to connect to VNC server\n", programName); return False; } return True; } /* * InitialiseRFBConnection. */ Bool InitialiseRFBConnection(int sock) { rfbProtocolVersionMsg pv; int major,minor; Bool authWillWork = True; CARD32 authScheme, reasonLen, authResult; char *reason; CARD8 challenge[CHALLENGESIZE]; char *passwd; int i; rfbClientInitMsg ci; /* if the connection is immediately closed, don't report anything, so that pmw's monitor can make test connections */ if (listenSpecified) errorMessageFromReadExact = False; if (!ReadExact(sock, pv, sz_rfbProtocolVersionMsg)) return False; errorMessageFromReadExact = True; pv[sz_rfbProtocolVersionMsg] = 0; if (sscanf(pv,rfbProtocolVersionFormat,&major,&minor) != 2) { fprintf(stderr,"%s: Not a valid VNC server\n",programName); return False; } fprintf(stderr,"%s: VNC server supports protocol version %d.%d " "(viewer %d.%d)\n", programName,major,minor,rfbProtocolMajorVersion, rfbProtocolMinorVersion); if ((major == 3) && (minor < 3)) { /* if server is before 3.3 authentication won't work */ authWillWork = False; } else { /* any other server version, just tell it what we want */ major = rfbProtocolMajorVersion; minor = rfbProtocolMinorVersion; } sprintf(pv,rfbProtocolVersionFormat,major,minor); if (!WriteExact(sock, pv, sz_rfbProtocolVersionMsg)) return False; if (!ReadExact(sock, (char *)&authScheme, 4)) return False; authScheme = Swap32IfLE(authScheme); switch (authScheme) { case rfbConnFailed: if (!ReadExact(sock, (char *)&reasonLen, 4)) return False; reasonLen = Swap32IfLE(reasonLen); reason = malloc(reasonLen); if (!ReadExact(sock, reason, reasonLen)) return False; fprintf(stderr,"%s: VNC connection failed: %.*s\n", programName, (int)reasonLen, reason); return False; case rfbNoAuth: fprintf(stderr,"%s: No authentication needed\n",programName); break; case rfbVncAuth: if (!authWillWork) { fprintf(stderr, "\n%s: VNC server uses the old authentication scheme.\n" "You should kill your old desktop(s) and restart.\n" "If you really need to connect to this desktop use " "vncviewer3.2\n\n", programName); return False; } if (!ReadExact(sock, (char *)challenge, CHALLENGESIZE)) return False; if (passwdFile) { passwd = vncDecryptPasswdFromFile(passwdFile); } else { passwd = getpass("Password: "); if (strlen(passwd) == 0) { fprintf(stderr,"%s: Reading password failed\n",programName); return False; } if (strlen(passwd) > 8) { passwd[8] = '\0'; } } vncEncryptBytes(challenge, passwd); /* Lose the password from memory */ for (i=0; i si.framebufferWidth) || ((updateRequestY + updateRequestH) > si.framebufferHeight)) { fprintf(stderr, "%s: region requested is outside server's framebuffer\n", programName); return False; } if (updateRequestW == 0) updateRequestW = si.framebufferWidth - updateRequestX; if (updateRequestH == 0) updateRequestH = si.framebufferHeight - updateRequestY; desktopName = malloc(si.nameLength + 1); if (!ReadExact(sock, desktopName, si.nameLength)) return False; desktopName[si.nameLength] = 0; fprintf(stderr,"%s: Desktop name \"%s\"\n",programName,desktopName); fprintf(stderr, "%s: Connected to VNC server, using protocol version %d.%d\n", programName, rfbProtocolMajorVersion, rfbProtocolMinorVersion); fprintf(stderr,"%s: VNC server default format:\n",programName); return True; } /* * SetFormatAndEncodings. */ Bool SetFormatAndEncodings() { rfbSetPixelFormatMsg spf; char buf[sz_rfbSetEncodingsMsg + MAX_ENCODINGS * 4]; rfbSetEncodingsMsg *se = (rfbSetEncodingsMsg *)buf; CARD32 *encs = (CARD32 *)(&buf[sz_rfbSetEncodingsMsg]); int len = 0; int i; spf.type = rfbSetPixelFormat; spf.format = myFormat; spf.format.redMax = Swap16IfLE(spf.format.redMax); spf.format.greenMax = Swap16IfLE(spf.format.greenMax); spf.format.blueMax = Swap16IfLE(spf.format.blueMax); if (!WriteExact(rfbsock, (char *)&spf, sz_rfbSetPixelFormatMsg)) return False; se->type = rfbSetEncodings; se->nEncodings = 0; for (i = 0; i < nExplicitEncodings; i++) { encs[se->nEncodings++] = Swap32IfLE(explicitEncodings[i]); } if (SameMachine(rfbsock)) { encs[se->nEncodings++] = Swap32IfLE(rfbEncodingRaw); } if (addCopyRect) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCopyRect); if (addHextile) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingHextile); if (addCoRRE) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingCoRRE); if (addRRE) encs[se->nEncodings++] = Swap32IfLE(rfbEncodingRRE); len = sz_rfbSetEncodingsMsg + se->nEncodings * 4; se->nEncodings = Swap16IfLE(se->nEncodings); if (!WriteExact(rfbsock, buf, len)) return False; return True; } /* * SendPointerEvent. */ Bool SendPointerEvent(int x, int y, int buttonMask) { rfbPointerEventMsg pe; pe.type = rfbPointerEvent; pe.buttonMask = buttonMask; if (x < 0) x = 0; if (y < 0) y = 0; pe.x = Swap16IfLE(x); pe.y = Swap16IfLE(y); return WriteExact(rfbsock, (char *)&pe, sz_rfbPointerEventMsg); } /* * SendKeyEvent. */ Bool SendKeyEvent(CARD32 key, Bool down) { rfbKeyEventMsg ke; ke.type = rfbKeyEvent; ke.down = down ? 1 : 0; ke.key = Swap32IfLE(key); return WriteExact(rfbsock, (char *)&ke, sz_rfbKeyEventMsg); } /* * SendClientCutText. */ Bool SendClientCutText(char *str, int len) { rfbClientCutTextMsg cct; cct.type = rfbClientCutText; cct.length = Swap32IfLE(len); return (WriteExact(rfbsock, (char *)&cct, sz_rfbClientCutTextMsg) && WriteExact(rfbsock, str, len)); } /* * HandleRFBServerMessage. */ Bool HandleRFBServerMessage() { rfbServerToClientMsg msg; if (!ReadExact(rfbsock, (char *)&msg, 1)) return False; switch (msg.type) { case rfbSetColourMapEntries: { int i; CARD16 rgb[3]; XColor xc; if (!ReadExact(rfbsock, ((char *)&msg) + 1, sz_rfbSetColourMapEntriesMsg - 1)) return False; msg.scme.firstColour = Swap16IfLE(msg.scme.firstColour); msg.scme.nColours = Swap16IfLE(msg.scme.nColours); for (i = 0; i < msg.scme.nColours; i++) { if (!ReadExact(rfbsock, (char *)rgb, 6)) return False; } break; } case rfbFramebufferUpdate: { rfbFramebufferUpdateRectHeader rect; int linesToRead; int bytesPerLine; int i; if (!ReadExact(rfbsock, ((char *)&msg.fu) + 1, sz_rfbFramebufferUpdateMsg - 1)) return False; msg.fu.nRects = Swap16IfLE(msg.fu.nRects); for (i = 0; i < msg.fu.nRects; i++) { if (!ReadExact(rfbsock, (char *)&rect, sz_rfbFramebufferUpdateRectHeader)) return False; rect.r.x = Swap16IfLE(rect.r.x); rect.r.y = Swap16IfLE(rect.r.y); rect.r.w = Swap16IfLE(rect.r.w); rect.r.h = Swap16IfLE(rect.r.h); rect.encoding = Swap32IfLE(rect.encoding); if ((rect.r.x + rect.r.w > si.framebufferWidth) || (rect.r.y + rect.r.h > si.framebufferHeight)) { fprintf(stderr,"%s: rect too large: %dx%d at (%d, %d)\n", programName, rect.r.w, rect.r.h, rect.r.x, rect.r.y); return False; } if ((rect.r.h * rect.r.w) == 0) { fprintf(stderr,"%s: zero size rect - ignoring\n",programName); continue; } switch (rect.encoding) { case rfbEncodingRaw: bytesPerLine = rect.r.w * myFormat.bitsPerPixel / 8; linesToRead = BUFFER_SIZE / bytesPerLine; while (rect.r.h > 0) { if (linesToRead > rect.r.h) linesToRead = rect.r.h; if (!ReadExact(rfbsock, buffer,bytesPerLine * linesToRead)) return False; // CopyDataToScreen((CARD8 *)buffer, rect.r.x, rect.r.y, // rect.r.w, linesToRead); rect.r.h -= linesToRead; rect.r.y += linesToRead; } break; case rfbEncodingCopyRect: { rfbCopyRect cr; if (!ReadExact(rfbsock, (char *)&cr, sz_rfbCopyRect)) return False; break; } case rfbEncodingRRE: { rfbRREHeader hdr; CARD8 pix8; CARD16 pix16; CARD32 pix32; XGCValues gcv; rfbRectangle subrect; int j; if (!ReadExact(rfbsock, (char *)&hdr, sz_rfbRREHeader)) return False; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); switch (myFormat.bitsPerPixel) { case 8: if (!ReadExact(rfbsock, (char *)&pix8, 1)) return False; for (j = 0; j < hdr.nSubrects; j++) { if (!ReadExact(rfbsock, (char *)&pix8, 1)) return False; if (!ReadExact(rfbsock, (char *)&subrect, sz_rfbRectangle)) return False; } break; case 16: if (!ReadExact(rfbsock, (char *)&pix16, 2)) return False; for (j = 0; j < hdr.nSubrects; j++) { if (!ReadExact(rfbsock, (char *)&pix16, 2)) return False; if (!ReadExact(rfbsock, (char *)&subrect, sz_rfbRectangle)) return False; } break; case 32: if (!ReadExact(rfbsock, (char *)&pix32, 4)) return False; for (j = 0; j < hdr.nSubrects; j++) { if (!ReadExact(rfbsock, (char *)&pix32, 4)) return False; if (!ReadExact(rfbsock, (char *)&subrect, sz_rfbRectangle)) return False; } break; } break; } case rfbEncodingCoRRE: { rfbRREHeader hdr; CARD8 pix8; CARD16 pix16; CARD32 pix32; XGCValues gcv; int j; CARD8 *ptr; register int x, y, w, h; if (!ReadExact(rfbsock, (char *)&hdr, sz_rfbRREHeader)) return False; hdr.nSubrects = Swap32IfLE(hdr.nSubrects); switch (myFormat.bitsPerPixel) { case 8: if (!ReadExact(rfbsock, (char *)&pix8, 1)) return False; if (!ReadExact(rfbsock, buffer, hdr.nSubrects * 5)) return False; break; case 16: if (!ReadExact(rfbsock, (char *)&pix16, 2)) return False; if (!ReadExact(rfbsock, buffer, hdr.nSubrects * 6)) return False; ptr = (CARD8 *)buffer; break; case 32: if (!ReadExact(rfbsock, (char *)&pix32, 4)) return False; if (!ReadExact(rfbsock, buffer, hdr.nSubrects * 8)) return False; break; } break; } case rfbEncodingHextile: { switch (myFormat.bitsPerPixel) { case 8: if (!HandleHextileEncoding8(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; case 16: if (!HandleHextileEncoding16(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; case 32: if (!HandleHextileEncoding32(rect.r.x, rect.r.y, rect.r.w, rect.r.h)) return False; break; } break; } default: fprintf(stderr,"%s: unknown rect encoding %d\n",programName, (int)rect.encoding); return False; } } sendUpdateRequest = True; break; } case rfbBell: #if 0 XBell(dpy,100); #endif break; case rfbServerCutText: { char *str; if (!ReadExact(rfbsock, ((char *)&msg) + 1, sz_rfbServerCutTextMsg - 1)) return False; msg.sct.length = Swap32IfLE(msg.sct.length); str = malloc(msg.sct.length); if (!ReadExact(rfbsock, str, msg.sct.length)) return False; XSelectInput(dpy, DefaultRootWindow(dpy), 0); XStoreBytes(dpy, str, msg.sct.length); XSetSelectionOwner(dpy, XA_PRIMARY, None, CurrentTime); XSelectInput(dpy, DefaultRootWindow(dpy), PropertyChangeMask); free(str); break; } default: fprintf(stderr,"%s: unknown message type %d from VNC server\n", programName,msg.type); return False; } return True; } #define GET_PIXEL8(pix, ptr) ((pix) = *(ptr)++) #define GET_PIXEL16(pix, ptr) (((CARD8*)&(pix))[0] = *(ptr)++, \ ((CARD8*)&(pix))[1] = *(ptr)++) #define GET_PIXEL32(pix, ptr) (((CARD8*)&(pix))[0] = *(ptr)++, \ ((CARD8*)&(pix))[1] = *(ptr)++, \ ((CARD8*)&(pix))[2] = *(ptr)++, \ ((CARD8*)&(pix))[3] = *(ptr)++) #define DEFINE_HEXTILE(bpp) \ static Bool \ HandleHextileEncoding##bpp(int rx, int ry, int rw, int rh) \ { \ CARD##bpp bg, fg; \ XGCValues gcv; \ int i; \ CARD8 *ptr; \ int x, y, w, h; \ int sx, sy, sw, sh; \ CARD8 subencoding; \ CARD8 nSubrects; \ \ for (y = ry; y < ry+rh; y += 16) { \ for (x = rx; x < rx+rw; x += 16) { \ w = h = 16; \ if (rx+rw - x < 16) \ w = rx+rw - x; \ if (ry+rh - y < 16) \ h = ry+rh - y; \ \ if (!ReadExact(rfbsock, (char *)&subencoding, 1)) \ return False; \ \ if (subencoding & rfbHextileRaw) { \ if (!ReadExact(rfbsock, buffer, w * h * (bpp / 8))) \ return False; \ \ continue; \ } \ \ if (subencoding & rfbHextileBackgroundSpecified) \ if (!ReadExact(rfbsock, (char *)&bg, (bpp/8))) \ return False; \ \ if (subencoding & rfbHextileForegroundSpecified) \ if (!ReadExact(rfbsock, (char *)&fg, (bpp/8))) \ return False; \ \ if (!(subencoding & rfbHextileAnySubrects)) { \ continue; \ } \ \ if (!ReadExact(rfbsock, (char *)&nSubrects, 1)) \ return False; \ \ ptr = (CARD8 *)buffer; \ \ if (subencoding & rfbHextileSubrectsColoured) { \ if (!ReadExact(rfbsock, buffer, nSubrects * (2 + (bpp / 8)))) \ return False; \ \ \ } else { \ if (!ReadExact(rfbsock, buffer, nSubrects * 2)) \ return False; \ \ } \ } \ } \ \ return True; \ } DEFINE_HEXTILE(8) DEFINE_HEXTILE(16) DEFINE_HEXTILE(32) x2vnc-1.0/sockets.c100664 1750 1750 13245 6560202753 12742 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * sockets.c - functions to deal with sockets. */ #include #include #include #include #include #include #include #include void PrintInHex(char *buf, int len); Bool errorMessageFromReadExact = True; /* * Read an exact number of bytes, and don't return until you've got them. */ Bool ReadExact(int sock, char *buf, int n) { int i = 0; int j; while (i < n) { j = read(sock, buf + i, (n - i)); if (j <= 0) { if (j < 0) { fprintf(stderr,programName); perror(": read"); } else { if (errorMessageFromReadExact) { fprintf(stderr,"%s: read failed\n",programName); } } return False; } i += j; } if (debug) PrintInHex(buf,n); return True; } /* * Write an exact number of bytes, and don't return until you've sent them. */ Bool WriteExact(int sock, char *buf, int n) { int i = 0; int j; while (i < n) { j = write(sock, buf + i, (n - i)); if (j <= 0) { if (j < 0) { fprintf(stderr,programName); perror(": write"); } else { fprintf(stderr,"%s: write failed\n",programName); } return False; } i += j; } return True; } /* * ConnectToTcpAddr connects to the given TCP port. */ int ConnectToTcpAddr(unsigned int host, int port) { int sock; struct sockaddr_in addr; int one = 1; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = host; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { fprintf(stderr,programName); perror(": ConnectToTcpAddr: socket"); return -1; } if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { fprintf(stderr,programName); perror(": ConnectToTcpAddr: connect"); close(sock); return -1; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { fprintf(stderr,programName); perror(": ConnectToTcpAddr: setsockopt"); close(sock); return -1; } return sock; } /* * ListenAtTcpPort starts listening at the given TCP port. */ int ListenAtTcpPort(int port) { int sock; struct sockaddr_in addr; int one = 1; addr.sin_family = AF_INET; addr.sin_port = htons(port); addr.sin_addr.s_addr = INADDR_ANY; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { fprintf(stderr,programName); perror(": ListenAtTcpPort: socket"); return -1; } if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one)) < 0) { fprintf(stderr,programName); perror(": ListenAtTcpPort: setsockopt"); close(sock); return -1; } if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { fprintf(stderr,programName); perror(": ListenAtTcpPort: bind"); close(sock); return -1; } if (listen(sock, 5) < 0) { fprintf(stderr,programName); perror(": ListenAtTcpPort: listen"); close(sock); return -1; } return sock; } /* * AcceptTcpConnection accepts a TCP connection. */ int AcceptTcpConnection(int listenSock) { int sock; struct sockaddr_in addr; int addrlen = sizeof(addr); int one = 1; sock = accept(listenSock, (struct sockaddr *) &addr, &addrlen); if (sock < 0) { fprintf(stderr,programName); perror(": AcceptTcpConnection: accept"); return -1; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { fprintf(stderr,programName); perror(": AcceptTcpConnection: setsockopt"); close(sock); return -1; } return sock; } /* * StringToIPAddr - convert a host string to an IP address. */ int StringToIPAddr(const char *str, unsigned int *addr) { struct hostent *hp; if ((*addr = inet_addr(str)) == -1) { if (!(hp = gethostbyname(str))) return 0; *addr = *(unsigned int *)hp->h_addr; } return 1; } /* * Test if the other end of a socket is on the same machine. */ Bool SameMachine(int sock) { struct sockaddr_in peeraddr, myaddr; int addrlen = sizeof(struct sockaddr_in); getpeername(sock, (struct sockaddr *)&peeraddr, &addrlen); getsockname(sock, (struct sockaddr *)&myaddr, &addrlen); return (peeraddr.sin_addr.s_addr == myaddr.sin_addr.s_addr); } /* * Print out the contents of a packet for debugging. */ void PrintInHex(char *buf, int len) { int i, j; char c, str[17]; str[16] = 0; fprintf(stderr,"ReadExact: "); for (i = 0; i < len; i++) { if ((i % 16 == 0) && (i != 0)) { fprintf(stderr," "); } c = buf[i]; str[i % 16] = (((c > 31) && (c < 127)) ? c : '.'); fprintf(stderr,"%02x ",(unsigned char)c); if ((i % 4) == 3) fprintf(stderr," "); if ((i % 16) == 15) { fprintf(stderr,"%s\n",str); } } if ((i % 16) != 0) { for (j = i % 16; j < 16; j++) { fprintf(stderr," "); if ((j % 4) == 3) fprintf(stderr," "); } str[i % 16] = 0; fprintf(stderr,"%s\n",str); } fflush(stderr); } x2vnc-1.0/x2vnc.c100664 1750 1750 3751 6560202753 12310 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * Seriously modified by Fredrik Hübinette */ /* * x2vnc - control VNC displays without showing them */ #include int main(int argc, char **argv) { fd_set fds; struct timeval tv, *tvp; int msWait; processArgs(argc, argv); if (listenSpecified) { listenForIncomingConnections(); /* returns only with a succesful connection */ } else { if (!ConnectToRFBServer(hostname, port)) exit(1); } if (!InitialiseRFBConnection(rfbsock)) exit(1); if (!CreateXWindow()) exit(1); if (!SetFormatAndEncodings()) { ShutdownX(); exit(1); } while (1) { /* * Always handle all X events before doing select. This is the * simplest way of ensuring that we don't block in select while * Xlib has some events on its queue. */ if (!HandleXEvents()) { ShutdownX(); exit(1); } tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&fds); FD_SET(ConnectionNumber(dpy),&fds); FD_SET(rfbsock,&fds); if (select(FD_SETSIZE, &fds, NULL, NULL, &tv) < 0) { perror("select"); ShutdownX(); exit(1); } if (FD_ISSET(rfbsock, &fds)) { if (!HandleRFBServerMessage()) { ShutdownX(); exit(1); } } } return 0; } x2vnc-1.0/x.c100664 1750 1750 22000 6560210461 11516 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * * Seriously modified by Fredrik Hübinette */ /* * x.c - functions to deal with X display. */ #include #include #include #include #include #include #define SCROLLBAR_SIZE 10 #define SCROLLBAR_BG_SIZE (SCROLLBAR_SIZE + 2) #define INVALID_PIXEL 0xffffffff #define COLORMAP_SIZE 256 Display *dpy; static Window topLevel; static int topLevelWidth, topLevelHeight; static Atom wmProtocols, wmDeleteWindow, wmState; static Bool modifierPressed[256]; static Bool HandleTopLevelEvent(XEvent *ev); static Bool HandleRootEvent(XEvent *ev); static int displayWidth, displayHeight; static int grabbed; Cursor grabCursor; enum edge_enum edge = EDGE_EAST; /* * CreateXWindow. */ Bool CreateXWindow(void) { XSetWindowAttributes attr; XEvent ev; char defaultGeometry[256]; XSizeHints wmHints; XGCValues gcv; int i; Pixmap nullPixmap; XColor dummyColor; if (!(dpy = XOpenDisplay(displayname))) { fprintf(stderr,"%s: unable to open display %s\n", programName, XDisplayName(displayname)); return False; } for (i = 0; i < 256; i++) modifierPressed[i] = False; /* Try to work out the geometry of the top-level window */ displayWidth = WidthOfScreen(DefaultScreenOfDisplay(dpy)); displayHeight = HeightOfScreen(DefaultScreenOfDisplay(dpy)); topLevelWidth = si.framebufferWidth; topLevelHeight = si.framebufferHeight; topLevelWidth=1; topLevelHeight=1; wmHints.x=0; wmHints.y=0; switch(edge) { case EDGE_EAST: wmHints.x=displayWidth-1; case EDGE_WEST: topLevelHeight=displayHeight; break; case EDGE_SOUTH: wmHints.y=displayHeight-1; case EDGE_NORTH: topLevelWidth=displayWidth; break; } wmHints.flags = PMaxSize | PMinSize |PPosition |PBaseSize; wmHints.max_width = topLevelWidth; wmHints.max_height = topLevelHeight; sprintf(defaultGeometry, "%dx%d+%d+%d", topLevelWidth, topLevelHeight, wmHints.x, wmHints.y); XWMGeometry(dpy, DefaultScreen(dpy), geometry, defaultGeometry, 0, &wmHints, &wmHints.x, &wmHints.y, &topLevelWidth, &topLevelHeight, &wmHints.win_gravity); /* Create the top-level window */ attr.border_pixel = 0; /* needed to allow 8-bit cmap on 24-bit display - otherwise we get a Match error! */ attr.background_pixel = BlackPixelOfScreen(DefaultScreenOfDisplay(dpy)); attr.event_mask = ( LeaveWindowMask| StructureNotifyMask| ButtonPressMask| ButtonReleaseMask| PointerMotionMask| KeyPressMask| KeyReleaseMask| EnterWindowMask| (resurface?VisibilityChangeMask:0) ); attr.override_redirect=True; topLevel = XCreateWindow(dpy, DefaultRootWindow(dpy), wmHints.x, wmHints.y, topLevelWidth, topLevelHeight, 0, CopyFromParent, InputOutput, CopyFromParent, (CWBorderPixel| CWEventMask| CWOverrideRedirect| CWBackPixel), &attr); wmHints.flags |= USPosition; /* try to force WM to place window */ XSetWMNormalHints(dpy, topLevel, &wmHints); wmProtocols = XInternAtom(dpy, "WM_PROTOCOLS", False); wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", False); XSetWMProtocols(dpy, topLevel, &wmDeleteWindow, 1); XStoreName(dpy, topLevel, desktopName); XMapRaised(dpy, topLevel); XSelectInput(dpy, DefaultRootWindow(dpy), PropertyChangeMask); myFormat.bitsPerPixel = 8; myFormat.depth = 8; myFormat.trueColour = 1; myFormat.bigEndian = 0; myFormat.redMax = 7; myFormat.greenMax = 7; myFormat.blueMax = 3; myFormat.redShift = 0; myFormat.greenShift = 3; myFormat.blueShift = 6; nullPixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), 1, 1, 1); grabCursor = XCreatePixmapCursor(dpy, nullPixmap, nullPixmap, &dummyColor, &dummyColor, 0, 0); return True; } /* * ShutdownX. */ void ShutdownX() { XCloseDisplay(dpy); } /* * HandleXEvents. */ Bool HandleXEvents() { XEvent ev; while (XCheckIfEvent(dpy, &ev, AllXEventsPredicate, NULL)) { if (ev.xany.window == topLevel) { if (!HandleTopLevelEvent(&ev)) return False; } else if (ev.xany.window == DefaultRootWindow(dpy)) { if (!HandleRootEvent(&ev)) return False; } else if (ev.type == MappingNotify) { XRefreshKeyboardMapping(&ev.xmapping); } } return True; } #define EW (edge == EDGE_EAST || edge==EDGE_WEST) #define NS (edge == EDGE_NORTH || edge==EDGE_SOUTH) #define CINVERSE(X,Y,Z) ((X)?((Z)==(Y)?1:!(Z)?(Y)-2:(Y)-(Z)):(Z)) #define SCALEX(X) ((X)-(edge==EDGE_WEST))*si.framebufferWidth/(displayWidth - EW) #define SCALEY(Y) ((Y)-(edge==EDGE_NORTH))*si.framebufferHeight/(displayHeight - EW) /* * HandleTopLevelEvent. */ static Bool HandleTopLevelEvent(XEvent *ev) { int i; int buttonMask; KeySym ks; char keyname[256]; switch (ev->type) { case VisibilityNotify: if (ev->xvisibility.state != VisibilityUnobscured) XRaiseWindow(dpy, topLevel); return 1; case EnterNotify: if(!grabbed && ev->xcrossing.mode==NotifyNormal) { XGrabPointer(dpy, topLevel, True, PointerMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, None, grabCursor, CurrentTime); XGrabKeyboard(dpy, topLevel, True, GrabModeAsync, GrabModeAsync, CurrentTime); XFlush(dpy); XWarpPointer(dpy,None, DefaultRootWindow(dpy),0,0,0,0, CINVERSE(EW,displayWidth,ev->xcrossing.x_root), CINVERSE(NS,displayHeight,ev->xcrossing.y_root)); SendPointerEvent(SCALEX(ev->xcrossing.x_root), SCALEY(ev->xcrossing.y_root), (ev->xmotion.state & 0x1f00) >> 8); grabbed=1; } return 1; case MotionNotify: if(grabbed) { int i, d; while (XCheckTypedWindowEvent(dpy, topLevel, MotionNotify, ev)) ; /* discard all queued motion notify events */ i=SendPointerEvent(SCALEX(ev->xmotion.x_root), SCALEY(ev->xmotion.y_root), (ev->xmotion.state & 0x1f00) >> 8); switch(edge) { case EDGE_NORTH: d=ev->xmotion.y_root == displayHeight-1; break; case EDGE_SOUTH: d=ev->xmotion.y_root == 0; break; case EDGE_EAST: d=ev->xmotion.x_root == 0; break; case EDGE_WEST: d=ev->xmotion.x_root == displayWidth-1; break; } if(d) { XUngrabKeyboard(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime); XWarpPointer(dpy,None, DefaultRootWindow(dpy),0,0,0,0, CINVERSE(EW,displayWidth,ev->xmotion.x_root), CINVERSE(NS,displayHeight,ev->xmotion.y_root)); XFlush(dpy); for (i = 0; i < 256; i++) { if (modifierPressed[i]) { if (!SendKeyEvent(XKeycodeToKeysym(dpy, i, 0), False)) return False; modifierPressed[i]=False; } } grabbed=0; } return i; } return 1; case ButtonPress: case ButtonRelease: if (ev->type == ButtonPress) { buttonMask = (((ev->xbutton.state & 0x1f00) >> 8) | (1 << (ev->xbutton.button - 1))); } else { buttonMask = (((ev->xbutton.state & 0x1f00) >> 8) & ~(1 << (ev->xbutton.button - 1))); } return SendPointerEvent(SCALEX(ev->xbutton.x_root), SCALEY(ev->xbutton.y_root), buttonMask); case KeyPress: case KeyRelease: XLookupString(&ev->xkey, keyname, 256, &ks, NULL); if (IsModifierKey(ks)) { ks = XKeycodeToKeysym(dpy, ev->xkey.keycode, 0); modifierPressed[ev->xkey.keycode] = (ev->type == KeyPress); } return SendKeyEvent(ks, (ev->type == KeyPress)); case ClientMessage: if ((ev->xclient.message_type == wmProtocols) && (ev->xclient.data.l[0] == wmDeleteWindow)) { ShutdownX(); exit(0); } break; } return True; } /* * HandleRootEvent. */ static Bool HandleRootEvent(XEvent *ev) { char *str; int len; switch (ev->type) { case PropertyNotify: if (ev->xproperty.atom == XA_CUT_BUFFER0) { str = XFetchBytes(dpy, &len); if (str) { if (!SendClientCutText(str, len)) return False; XFree(str); } } break; } return True; } /* * AllXEventsPredicate is needed to make XCheckIfEvent return all events. */ Bool AllXEventsPredicate(Display *dpy, XEvent *ev, char *arg) { return True; } x2vnc-1.0/vncauth.c100664 1750 1750 6533 6560202753 12721 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * vncauth.c - Functions for VNC password management and authentication. */ #include #include #include #include #include #include #include /* * We use a fixed key to store passwords, since we assume that our local * file system is secure but nonetheless don't want to store passwords * as plaintext. */ unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7}; /* * Encrypt a password and store it in a file. Returns 0 if successful, * 1 if the file could not be written. */ int vncEncryptAndStorePasswd(char *passwd, char *fname) { FILE *fp; int i; unsigned char encryptedPasswd[8]; if ((fp = fopen(fname,"w")) == NULL) return 1; chmod(fname, S_IRUSR|S_IWUSR); /* pad password with nulls */ for (i = 0; i < 8; i++) { if (i < strlen(passwd)) { encryptedPasswd[i] = passwd[i]; } else { encryptedPasswd[i] = 0; } } /* Do encryption in-place - this way we overwrite our copy of the plaintext password */ deskey(fixedkey, EN0); des(encryptedPasswd, encryptedPasswd); for (i = 0; i < 8; i++) { putc(encryptedPasswd[i], fp); } fclose(fp); return 0; } /* * Decrypt a password from a file. Returns a pointer to a newly allocated * string containing the password or a null pointer if the password could * not be retrieved for some reason. */ char * vncDecryptPasswdFromFile(char *fname) { FILE *fp; int i, ch; unsigned char *passwd = (unsigned char *)malloc(9); if ((fp = fopen(fname,"r")) == NULL) return NULL; for (i = 0; i < 8; i++) { ch = getc(fp); if (ch == EOF) { fclose(fp); return NULL; } passwd[i] = ch; } fclose(fp); deskey(fixedkey, DE1); des(passwd, passwd); passwd[8] = 0; return (char *)passwd; } /* * Generate CHALLENGESIZE random bytes for use in challenge-response * authentication. */ void vncRandomBytes(unsigned char *bytes) { int i; unsigned int seed = (unsigned int) time(0); srandom(seed); for (i = 0; i < CHALLENGESIZE; i++) { bytes[i] = (unsigned char)(random() & 255); } } /* * Encrypt CHALLENGESIZE bytes in memory using a password. */ void vncEncryptBytes(unsigned char *bytes, char *passwd) { unsigned char key[8]; int i; /* key is simply password padded with nulls */ for (i = 0; i < 8; i++) { if (i < strlen(passwd)) { key[i] = passwd[i]; } else { key[i] = 0; } } deskey(key, EN0); for (i = 0; i < CHALLENGESIZE; i += 8) { des(bytes+i, bytes+i); } } x2vnc-1.0/d3des.c100664 1750 1750 36157 6560202753 12300 0ustar hubbehubbe/* * This is D3DES (V5.09) by Richard Outerbridge with the double and * triple-length support removed for use in VNC. Also the bytebit[] array * has been reversed so that the most significant bit in each byte of the * key is ignored, not the least significant. * * These changes are Copyright (C) 1998 Olivetti & Oracle Research Laboratory * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* D3DES (V5.09) - * * A portable, public domain, version of the Data Encryption Standard. * * Written with Symantec's THINK (Lightspeed) C by Richard Outerbridge. * Thanks to: Dan Hoey for his excellent Initial and Inverse permutation * code; Jim Gillogly & Phil Karn for the DES key schedule code; Dennis * Ferguson, Eric Young and Dana How for comparing notes; and Ray Lau, * for humouring me on. * * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge. * (GEnie : OUTER; CIS : [71755,204]) Graven Imagery, 1992. */ #include "d3des.h" static void scrunch(unsigned char *, unsigned long *); static void unscrun(unsigned long *, unsigned char *); static void desfunc(unsigned long *, unsigned long *); static void cookey(unsigned long *); static unsigned long KnL[32] = { 0L }; static unsigned long KnR[32] = { 0L }; static unsigned long Kn3[32] = { 0L }; static unsigned char Df_Key[24] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, 0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 }; static unsigned short bytebit[8] = { 01, 02, 04, 010, 020, 040, 0100, 0200 }; static unsigned long bigbyte[24] = { 0x800000L, 0x400000L, 0x200000L, 0x100000L, 0x80000L, 0x40000L, 0x20000L, 0x10000L, 0x8000L, 0x4000L, 0x2000L, 0x1000L, 0x800L, 0x400L, 0x200L, 0x100L, 0x80L, 0x40L, 0x20L, 0x10L, 0x8L, 0x4L, 0x2L, 0x1L }; /* Use the key schedule specified in the Standard (ANSI X3.92-1981). */ static unsigned char pc1[56] = { 56, 48, 40, 32, 24, 16, 8, 0, 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18, 10, 2, 59, 51, 43, 35, 62, 54, 46, 38, 30, 22, 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 60, 52, 44, 36, 28, 20, 12, 4, 27, 19, 11, 3 }; static unsigned char totrot[16] = { 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 }; static unsigned char pc2[48] = { 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1, 40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47, 43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 }; void deskey(key, edf) /* Thanks to James Gillogly & Phil Karn! */ unsigned char *key; short edf; { register int i, j, l, m, n; unsigned char pc1m[56], pcr[56]; unsigned long kn[32]; for ( j = 0; j < 56; j++ ) { l = pc1[j]; m = l & 07; pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0; } for( i = 0; i < 16; i++ ) { if( edf == DE1 ) m = (15 - i) << 1; else m = i << 1; n = m + 1; kn[m] = kn[n] = 0L; for( j = 0; j < 28; j++ ) { l = j + totrot[i]; if( l < 28 ) pcr[j] = pc1m[l]; else pcr[j] = pc1m[l - 28]; } for( j = 28; j < 56; j++ ) { l = j + totrot[i]; if( l < 56 ) pcr[j] = pc1m[l]; else pcr[j] = pc1m[l - 28]; } for( j = 0; j < 24; j++ ) { if( pcr[pc2[j]] ) kn[m] |= bigbyte[j]; if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j]; } } cookey(kn); return; } static void cookey(raw1) register unsigned long *raw1; { register unsigned long *cook, *raw0; unsigned long dough[32]; register int i; cook = dough; for( i = 0; i < 16; i++, raw1++ ) { raw0 = raw1++; *cook = (*raw0 & 0x00fc0000L) << 6; *cook |= (*raw0 & 0x00000fc0L) << 10; *cook |= (*raw1 & 0x00fc0000L) >> 10; *cook++ |= (*raw1 & 0x00000fc0L) >> 6; *cook = (*raw0 & 0x0003f000L) << 12; *cook |= (*raw0 & 0x0000003fL) << 16; *cook |= (*raw1 & 0x0003f000L) >> 4; *cook++ |= (*raw1 & 0x0000003fL); } usekey(dough); return; } void cpkey(into) register unsigned long *into; { register unsigned long *from, *endp; from = KnL, endp = &KnL[32]; while( from < endp ) *into++ = *from++; return; } void usekey(from) register unsigned long *from; { register unsigned long *to, *endp; to = KnL, endp = &KnL[32]; while( to < endp ) *to++ = *from++; return; } void des(inblock, outblock) unsigned char *inblock, *outblock; { unsigned long work[2]; scrunch(inblock, work); desfunc(work, KnL); unscrun(work, outblock); return; } static void scrunch(outof, into) register unsigned char *outof; register unsigned long *into; { *into = (*outof++ & 0xffL) << 24; *into |= (*outof++ & 0xffL) << 16; *into |= (*outof++ & 0xffL) << 8; *into++ |= (*outof++ & 0xffL); *into = (*outof++ & 0xffL) << 24; *into |= (*outof++ & 0xffL) << 16; *into |= (*outof++ & 0xffL) << 8; *into |= (*outof & 0xffL); return; } static void unscrun(outof, into) register unsigned long *outof; register unsigned char *into; { *into++ = (*outof >> 24) & 0xffL; *into++ = (*outof >> 16) & 0xffL; *into++ = (*outof >> 8) & 0xffL; *into++ = *outof++ & 0xffL; *into++ = (*outof >> 24) & 0xffL; *into++ = (*outof >> 16) & 0xffL; *into++ = (*outof >> 8) & 0xffL; *into = *outof & 0xffL; return; } static unsigned long SP1[64] = { 0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L, 0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L, 0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L, 0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L, 0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L, 0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L, 0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L, 0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L, 0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L, 0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L, 0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L, 0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L, 0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L, 0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L, 0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L, 0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L }; static unsigned long SP2[64] = { 0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L, 0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L, 0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L, 0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L, 0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L, 0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L, 0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L, 0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L, 0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L, 0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L, 0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L, 0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L, 0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L, 0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L, 0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L, 0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L }; static unsigned long SP3[64] = { 0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L, 0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L, 0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L, 0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L, 0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L, 0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L, 0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L, 0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L, 0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L, 0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L, 0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L, 0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L, 0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L, 0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L, 0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L, 0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L }; static unsigned long SP4[64] = { 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L, 0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L, 0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L, 0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L, 0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L, 0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L, 0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L, 0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L, 0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L, 0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L, 0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L, 0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L, 0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L, 0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L, 0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L, 0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L }; static unsigned long SP5[64] = { 0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L, 0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L, 0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L, 0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L, 0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L, 0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L, 0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L, 0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L, 0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L, 0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L, 0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L, 0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L, 0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L, 0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L, 0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L, 0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L }; static unsigned long SP6[64] = { 0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L, 0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L, 0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L, 0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L, 0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L, 0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L, 0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L, 0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L, 0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L, 0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L, 0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L, 0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L, 0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L, 0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L, 0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L, 0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L }; static unsigned long SP7[64] = { 0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L, 0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L, 0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L, 0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L, 0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L, 0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L, 0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L, 0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L, 0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L, 0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L, 0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L, 0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L, 0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L, 0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L, 0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L, 0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L }; static unsigned long SP8[64] = { 0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L, 0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L, 0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L, 0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L, 0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L, 0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L, 0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L, 0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L, 0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L, 0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L, 0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L, 0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L, 0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L, 0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L, 0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L, 0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L }; static void desfunc(block, keys) register unsigned long *block, *keys; { register unsigned long fval, work, right, leftt; register int round; leftt = block[0]; right = block[1]; work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL; right ^= work; leftt ^= (work << 4); work = ((leftt >> 16) ^ right) & 0x0000ffffL; right ^= work; leftt ^= (work << 16); work = ((right >> 2) ^ leftt) & 0x33333333L; leftt ^= work; right ^= (work << 2); work = ((right >> 8) ^ leftt) & 0x00ff00ffL; leftt ^= work; right ^= (work << 8); right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL; work = (leftt ^ right) & 0xaaaaaaaaL; leftt ^= work; right ^= work; leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL; for( round = 0; round < 8; round++ ) { work = (right << 28) | (right >> 4); work ^= *keys++; fval = SP7[ work & 0x3fL]; fval |= SP5[(work >> 8) & 0x3fL]; fval |= SP3[(work >> 16) & 0x3fL]; fval |= SP1[(work >> 24) & 0x3fL]; work = right ^ *keys++; fval |= SP8[ work & 0x3fL]; fval |= SP6[(work >> 8) & 0x3fL]; fval |= SP4[(work >> 16) & 0x3fL]; fval |= SP2[(work >> 24) & 0x3fL]; leftt ^= fval; work = (leftt << 28) | (leftt >> 4); work ^= *keys++; fval = SP7[ work & 0x3fL]; fval |= SP5[(work >> 8) & 0x3fL]; fval |= SP3[(work >> 16) & 0x3fL]; fval |= SP1[(work >> 24) & 0x3fL]; work = leftt ^ *keys++; fval |= SP8[ work & 0x3fL]; fval |= SP6[(work >> 8) & 0x3fL]; fval |= SP4[(work >> 16) & 0x3fL]; fval |= SP2[(work >> 24) & 0x3fL]; right ^= fval; } right = (right << 31) | (right >> 1); work = (leftt ^ right) & 0xaaaaaaaaL; leftt ^= work; right ^= work; leftt = (leftt << 31) | (leftt >> 1); work = ((leftt >> 8) ^ right) & 0x00ff00ffL; right ^= work; leftt ^= (work << 8); work = ((leftt >> 2) ^ right) & 0x33333333L; right ^= work; leftt ^= (work << 2); work = ((right >> 16) ^ leftt) & 0x0000ffffL; leftt ^= work; right ^= (work << 16); work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL; leftt ^= work; right ^= (work << 4); *block++ = right; *block = leftt; return; } /* Validation sets: * * Single-length key, single-length plaintext - * Key : 0123 4567 89ab cdef * Plain : 0123 4567 89ab cde7 * Cipher : c957 4425 6a5e d31d * * Double-length key, single-length plaintext - * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 * Plain : 0123 4567 89ab cde7 * Cipher : 7f1d 0a77 826b 8aff * * Double-length key, double-length plaintext - * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff * Cipher : 27a0 8440 406a df60 278f 47cf 42d6 15d7 * * Triple-length key, single-length plaintext - * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567 * Plain : 0123 4567 89ab cde7 * Cipher : de0b 7c06 ae5e 0ed5 * * Triple-length key, double-length plaintext - * Key : 0123 4567 89ab cdef fedc ba98 7654 3210 89ab cdef 0123 4567 * Plain : 0123 4567 89ab cdef 0123 4567 89ab cdff * Cipher : ad0d 1b30 ac17 cf07 0ed1 1c63 81e4 4de5 * * d3des V5.0a rwo 9208.07 18:44 Graven Imagery **********************************************************************/ x2vnc-1.0/d3des.h100664 1750 1750 3102 6560202753 12245 0ustar hubbehubbe/* * This is D3DES (V5.09) by Richard Outerbridge with the double and * triple-length support removed for use in VNC. * * These changes are Copyright (C) 1998 Olivetti & Oracle Research Laboratory * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ /* d3des.h - * * Headers and defines for d3des.c * Graven Imagery, 1992. * * Copyright (c) 1988,1989,1990,1991,1992 by Richard Outerbridge * (GEnie : OUTER; CIS : [71755,204]) */ #define EN0 0 /* MODE == encrypt */ #define DE1 1 /* MODE == decrypt */ extern void deskey(unsigned char *, short); /* hexkey[8] MODE * Sets the internal key register according to the hexadecimal * key contained in the 8 bytes of hexkey, according to the DES, * for encryption or decryption according to MODE. */ extern void usekey(unsigned long *); /* cookedkey[32] * Loads the internal key register with the data in cookedkey. */ extern void cpkey(unsigned long *); /* cookedkey[32] * Copies the contents of the internal key register into the storage * located at &cookedkey[0]. */ extern void des(unsigned char *, unsigned char *); /* from[8] to[8] * Encrypts/Decrypts (according to the key currently loaded in the * internal key register) one block of eight bytes at address 'from' * into the block at address 'to'. They can be the same. */ /* d3des.h V5.09 rwo 9208.04 15:06 Graven Imagery ********************************************************************/ x2vnc-1.0/rfbproto.h100664 1750 1750 52174 6560202753 13135 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * rfbproto.h - header file for the RFB protocol version 3.3 * * Uses types CARD for an n-bit unsigned integer, INT for an n-bit signed * integer (for n = 8, 16 and 32). * * All multiple byte integers are in big endian (network) order (most * significant byte first). Unless noted otherwise there is no special * alignment of protocol structures. * * * Once the initial handshaking is done, all messages start with a type byte, * (usually) followed by message-specific data. The order of definitions in * this file is as follows: * * (1) Structures used in several types of message. * (2) Structures used in the initial handshaking. * (3) Message types. * (4) Encoding types. * (5) For each message type, the form of the data following the type byte. * Sometimes this is defined by a single structure but the more complex * messages have to be explained by comments. */ /***************************************************************************** * * Structures used in several messages * *****************************************************************************/ /*----------------------------------------------------------------------------- * Structure used to specify a rectangle. This structure is a multiple of 4 * bytes so that it can be interspersed with 32-bit pixel data without * affecting alignment. */ typedef struct { CARD16 x; CARD16 y; CARD16 w; CARD16 h; } rfbRectangle; #define sz_rfbRectangle 8 /*----------------------------------------------------------------------------- * Structure used to specify pixel format. */ typedef struct { CARD8 bitsPerPixel; /* 8,16,32 only */ CARD8 depth; /* 8 to 32 */ CARD8 bigEndian; /* True if multi-byte pixels are interpreted as big endian, or if single-bit-per-pixel has most significant bit of the byte corresponding to first (leftmost) pixel. Of course this is meaningless for 8 bits/pix */ CARD8 trueColour; /* If false then we need a "colour map" to convert pixels to RGB. If true, xxxMax and xxxShift specify bits used for red, green and blue */ /* the following fields are only meaningful if trueColour is true */ CARD16 redMax; /* maximum red value (= 2^n - 1 where n is the number of bits used for red). Note this value is always in big endian order. */ CARD16 greenMax; /* similar for green */ CARD16 blueMax; /* and blue */ CARD8 redShift; /* number of shifts needed to get the red value in a pixel to the least significant bit. To find the red value from a given pixel, do the following: 1) Swap pixel value according to bigEndian (e.g. if bigEndian is false and host byte order is big endian, then swap). 2) Shift right by redShift. 3) AND with redMax (in host byte order). 4) You now have the red value between 0 and redMax. */ CARD8 greenShift; /* similar for green */ CARD8 blueShift; /* and blue */ CARD8 pad1; CARD16 pad2; } rfbPixelFormat; #define sz_rfbPixelFormat 16 /***************************************************************************** * * Initial handshaking messages * *****************************************************************************/ /*----------------------------------------------------------------------------- * Protocol Version * * The server always sends 12 bytes to start which identifies the latest RFB * protocol version number which it supports. These bytes are interpreted * as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where * xxx and yyy are the major and minor version numbers (for version 3.3 * this is "RFB 003.003\n"). * * The client then replies with a similar 12-byte message giving the version * number of the protocol which should actually be used (which may be different * to that quoted by the server). * * It is intended that both clients and servers may provide some level of * backwards compatibility by this mechanism. Servers in particular should * attempt to provide backwards compatibility, and even forwards compatibility * to some extent. For example if a client demands version 3.1 of the * protocol, a 3.0 server can probably assume that by ignoring requests for * encoding types it doesn't understand, everything will still work OK. This * will probably not be the case for changes in the major version number. * * The format string below can be used in sprintf or sscanf to generate or * decode the version string respectively. */ #define rfbProtocolVersionFormat "RFB %03d.%03d\n" #define rfbProtocolMajorVersion 3 #define rfbProtocolMinorVersion 3 typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */ #define sz_rfbProtocolVersionMsg 12 /*----------------------------------------------------------------------------- * Authentication * * Once the protocol version has been decided, the server then sends a 32-bit * word indicating whether any authentication is needed on the connection. * The value of this word determines the authentication scheme in use. For * version 3.0 of the protocol this may have one of the following values: */ #define rfbConnFailed 0 #define rfbNoAuth 1 #define rfbVncAuth 2 /* * rfbConnFailed: For some reason the connection failed (e.g. the server * cannot support the desired protocol version). This is * followed by a string describing the reason (where a * string is specified as a 32-bit length followed by that * many ASCII characters). * * rfbNoAuth: No authentication is needed. * * rfbVncAuth: The VNC authentication scheme is to be used. A 16-byte * challenge follows, which the client encrypts as * appropriate using the password and sends the resulting * 16-byte response. If the response is correct, the * server sends the 32-bit word rfbVncAuthOK. If a simple * failure happens, the server sends rfbVncAuthFailed and * closes the connection. If the server decides that too * many failures have occurred, it sends rfbVncAuthTooMany * and closes the connection. In the latter case, the * server should not allow an immediate reconnection by * the client. */ #define rfbVncAuthOK 0 #define rfbVncAuthFailed 1 #define rfbVncAuthTooMany 2 /*----------------------------------------------------------------------------- * Client Initialisation Message * * Once the client and server are sure that they're happy to talk to one * another, the client sends an initialisation message. At present this * message only consists of a boolean indicating whether the server should try * to share the desktop by leaving other clients connected, or give exclusive * access to this client by disconnecting all other clients. */ typedef struct { CARD8 shared; } rfbClientInitMsg; #define sz_rfbClientInitMsg 1 /*----------------------------------------------------------------------------- * Server Initialisation Message * * After the client initialisation message, the server sends one of its own. * This tells the client the width and height of the server's framebuffer, * its pixel format and the name associated with the desktop. */ typedef struct { CARD16 framebufferWidth; CARD16 framebufferHeight; rfbPixelFormat format; /* the server's preferred pixel format */ CARD32 nameLength; /* followed by char name[nameLength] */ } rfbServerInitMsg; #define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat) /* * Following the server initialisation message it's up to the client to send * whichever protocol messages it wants. Typically it will send a * SetPixelFormat message and a SetEncodings message, followed by a * FramebufferUpdateRequest. From then on the server will send * FramebufferUpdate messages in response to the client's * FramebufferUpdateRequest messages. The client should send * FramebufferUpdateRequest messages with incremental set to true when it has * finished processing one FramebufferUpdate and is ready to process another. * With a fast client, the rate at which FramebufferUpdateRequests are sent * should be regulated to avoid hogging the network. */ /***************************************************************************** * * Message types * *****************************************************************************/ /* server -> client */ #define rfbFramebufferUpdate 0 #define rfbSetColourMapEntries 1 #define rfbBell 2 #define rfbServerCutText 3 /* client -> server */ #define rfbSetPixelFormat 0 #define rfbFixColourMapEntries 1 /* not currently supported */ #define rfbSetEncodings 2 #define rfbFramebufferUpdateRequest 3 #define rfbKeyEvent 4 #define rfbPointerEvent 5 #define rfbClientCutText 6 /***************************************************************************** * * Encoding types * *****************************************************************************/ #define rfbEncodingRaw 0 #define rfbEncodingCopyRect 1 #define rfbEncodingRRE 2 #define rfbEncodingCoRRE 4 #define rfbEncodingHextile 5 /***************************************************************************** * * Server -> client message definitions * *****************************************************************************/ /*----------------------------------------------------------------------------- * FramebufferUpdate - a block of rectangles to be copied to the framebuffer. * * This message consists of a header giving the number of rectangles of pixel * data followed by the rectangles themselves. The header is padded so that * together with the type byte it is an exact multiple of 4 bytes (to help * with alignment of 32-bit pixels): */ typedef struct { CARD8 type; /* always rfbFramebufferUpdate */ CARD8 pad; CARD16 nRects; /* followed by nRects rectangles */ } rfbFramebufferUpdateMsg; #define sz_rfbFramebufferUpdateMsg 4 /* * Each rectangle of pixel data consists of a header describing the position * and size of the rectangle and a type word describing the encoding of the * pixel data, followed finally by the pixel data. Note that if the client has * not sent a SetEncodings message then it will only receive raw pixel data. * Also note again that this structure is a multiple of 4 bytes. */ typedef struct { rfbRectangle r; CARD32 encoding; /* one of the encoding types rfbEncoding... */ } rfbFramebufferUpdateRectHeader; #define sz_rfbFramebufferUpdateRectHeader (sz_rfbRectangle + 4) /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Raw Encoding. Pixels are sent in top-to-bottom scanline order, * left-to-right within a scanline with no padding in between. */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * CopyRect Encoding. The pixels are specified simply by the x and y position * of the source rectangle. */ typedef struct { CARD16 srcX; CARD16 srcY; } rfbCopyRect; #define sz_rfbCopyRect 4 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * RRE - Rise-and-Run-length Encoding. We have an rfbRREHeader structure * giving the number of subrectangles following. Finally the data follows in * the form [...] where each is * []. */ typedef struct { CARD32 nSubrects; } rfbRREHeader; #define sz_rfbRREHeader 4 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * CoRRE - Compact RRE Encoding. We have an rfbRREHeader structure giving * the number of subrectangles following. Finally the data follows in the form * [...] where each is * []. This means that * the whole rectangle must be at most 255x255 pixels. */ typedef struct { CARD8 x; CARD8 y; CARD8 w; CARD8 h; } rfbCoRRERectangle; #define sz_rfbCoRRERectangle 4 /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Hextile Encoding. The rectangle is divided up into "tiles" of 16x16 pixels, * starting at the top left going in left-to-right, top-to-bottom order. If * the width of the rectangle is not an exact multiple of 16 then the width of * the last tile in each row will be correspondingly smaller. Similarly if the * height is not an exact multiple of 16 then the height of each tile in the * final row will also be smaller. Each tile begins with a "subencoding" type * byte, which is a mask made up of a number of bits. If the Raw bit is set * then the other bits are irrelevant; w*h pixel values follow (where w and h * are the width and height of the tile). Otherwise the tile is encoded in a * similar way to RRE, except that the position and size of each subrectangle * can be specified in just two bytes. The other bits in the mask are as * follows: * * BackgroundSpecified - if set, a pixel value follows which specifies * the background colour for this tile. The first non-raw tile in a * rectangle must have this bit set. If this bit isn't set then the * background is the same as the last tile. * * ForegroundSpecified - if set, a pixel value follows which specifies * the foreground colour to be used for all subrectangles in this tile. * If this bit is set then the SubrectsColoured bit must be zero. * * AnySubrects - if set, a single byte follows giving the number of * subrectangles following. If not set, there are no subrectangles (i.e. * the whole tile is just solid background colour). * * SubrectsColoured - if set then each subrectangle is preceded by a pixel * value giving the colour of that subrectangle. If not set, all * subrectangles are the same colour, the foreground colour; if the * ForegroundSpecified bit wasn't set then the foreground is the same as * the last tile. * * The position and size of each subrectangle is specified in two bytes. The * Pack macros below can be used to generate the two bytes from x, y, w, h, * and the Extract macros can be used to extract the x, y, w, h values from * the two bytes. */ #define rfbHextileRaw (1 << 0) #define rfbHextileBackgroundSpecified (1 << 1) #define rfbHextileForegroundSpecified (1 << 2) #define rfbHextileAnySubrects (1 << 3) #define rfbHextileSubrectsColoured (1 << 4) #define rfbHextilePackXY(x,y) (((x) << 4) | (y)) #define rfbHextilePackWH(w,h) ((((w)-1) << 4) | ((h)-1)) #define rfbHextileExtractX(byte) ((byte) >> 4) #define rfbHextileExtractY(byte) ((byte) & 0xf) #define rfbHextileExtractW(byte) (((byte) >> 4) + 1) #define rfbHextileExtractH(byte) (((byte) & 0xf) + 1) /*----------------------------------------------------------------------------- * SetColourMapEntries - these messages are only sent if the pixel * format uses a "colour map" (i.e. trueColour false) and the client has not * fixed the entire colour map using FixColourMapEntries. In addition they * will only start being sent after the client has sent its first * FramebufferUpdateRequest. So if the client always tells the server to use * trueColour then it never needs to process this type of message. */ typedef struct { CARD8 type; /* always rfbSetColourMapEntries */ CARD8 pad; CARD16 firstColour; CARD16 nColours; /* Followed by nColours * 3 * CARD16 r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */ } rfbSetColourMapEntriesMsg; #define sz_rfbSetColourMapEntriesMsg 6 /*----------------------------------------------------------------------------- * Bell - ring a bell on the client if it has one. */ typedef struct { CARD8 type; /* always rfbBell */ } rfbBellMsg; #define sz_rfbBellMsg 1 /*----------------------------------------------------------------------------- * ServerCutText - the server has new text in its cut buffer. */ typedef struct { CARD8 type; /* always rfbServerCutText */ CARD8 pad1; CARD16 pad2; CARD32 length; /* followed by char text[length] */ } rfbServerCutTextMsg; #define sz_rfbServerCutTextMsg 8 /*----------------------------------------------------------------------------- * Union of all server->client messages. */ typedef union { CARD8 type; rfbFramebufferUpdateMsg fu; rfbSetColourMapEntriesMsg scme; rfbBellMsg b; rfbServerCutTextMsg sct; } rfbServerToClientMsg; /***************************************************************************** * * Message definitions (client -> server) * *****************************************************************************/ /*----------------------------------------------------------------------------- * SetPixelFormat - tell the RFB server the format in which the client wants * pixels sent. */ typedef struct { CARD8 type; /* always rfbSetPixelFormat */ CARD8 pad1; CARD16 pad2; rfbPixelFormat format; } rfbSetPixelFormatMsg; #define sz_rfbSetPixelFormatMsg (sz_rfbPixelFormat + 4) /*----------------------------------------------------------------------------- * FixColourMapEntries - when the pixel format uses a "colour map", fix * read-only colour map entries. * * ***************** NOT CURRENTLY SUPPORTED ***************** */ typedef struct { CARD8 type; /* always rfbFixColourMapEntries */ CARD8 pad; CARD16 firstColour; CARD16 nColours; /* Followed by nColours * 3 * CARD16 r1, g1, b1, r2, g2, b2, r3, g3, b3, ..., rn, bn, gn */ } rfbFixColourMapEntriesMsg; #define sz_rfbFixColourMapEntriesMsg 6 /*----------------------------------------------------------------------------- * SetEncodings - tell the RFB server which encoding types we accept. Put them * in order of preference, if we have any. We may always receive raw * encoding, even if we don't specify it here. */ typedef struct { CARD8 type; /* always rfbSetEncodings */ CARD8 pad; CARD16 nEncodings; /* followed by nEncodings * CARD32 encoding types */ } rfbSetEncodingsMsg; #define sz_rfbSetEncodingsMsg 4 /*----------------------------------------------------------------------------- * FramebufferUpdateRequest - request for a framebuffer update. If incremental * is true then the client just wants the changes since the last update. If * false then it wants the whole of the specified rectangle. */ typedef struct { CARD8 type; /* always rfbFramebufferUpdateRequest */ CARD8 incremental; CARD16 x; CARD16 y; CARD16 w; CARD16 h; } rfbFramebufferUpdateRequestMsg; #define sz_rfbFramebufferUpdateRequestMsg 10 /*----------------------------------------------------------------------------- * KeyEvent - key press or release * * Keys are specified using the "keysym" values defined by the X Window System. * For most ordinary keys, the keysym is the same as the corresponding ASCII * value. Other common keys are: * * BackSpace 0xff08 * Tab 0xff09 * Return or Enter 0xff0d * Escape 0xff1b * Insert 0xff63 * Delete 0xffff * Home 0xff50 * End 0xff57 * Page Up 0xff55 * Page Down 0xff56 * Left 0xff51 * Up 0xff52 * Right 0xff53 * Down 0xff54 * F1 0xffbe * F2 0xffbf * ... ... * F12 0xffc9 * Shift 0xffe1 * Control 0xffe3 * Meta 0xffe7 * Alt 0xffe9 */ typedef struct { CARD8 type; /* always rfbKeyEvent */ CARD8 down; /* true if down (press), false if up */ CARD16 pad; CARD32 key; /* key is specified as an X keysym */ } rfbKeyEventMsg; #define sz_rfbKeyEventMsg 8 /*----------------------------------------------------------------------------- * PointerEvent - mouse/pen move and/or button press. */ typedef struct { CARD8 type; /* always rfbPointerEvent */ CARD8 buttonMask; /* bits 0-7 are buttons 1-8, 0=up, 1=down */ CARD16 x; CARD16 y; } rfbPointerEventMsg; #define rfbButton1Mask 1 #define rfbButton2Mask 2 #define rfbButton3Mask 4 #define sz_rfbPointerEventMsg 6 /*----------------------------------------------------------------------------- * ClientCutText - the client has new text in its cut buffer. */ typedef struct { CARD8 type; /* always rfbClientCutText */ CARD8 pad1; CARD16 pad2; CARD32 length; /* followed by char text[length] */ } rfbClientCutTextMsg; #define sz_rfbClientCutTextMsg 8 /*----------------------------------------------------------------------------- * Union of all client->server messages. */ typedef union { CARD8 type; rfbSetPixelFormatMsg spf; rfbFixColourMapEntriesMsg fcme; rfbSetEncodingsMsg se; rfbFramebufferUpdateRequestMsg fur; rfbKeyEventMsg ke; rfbPointerEventMsg pe; rfbClientCutTextMsg cct; } rfbClientToServerMsg; x2vnc-1.0/vncauth.h100664 1750 1750 2207 6560202753 12720 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * vncauth.h - describes the functions provided by the vncauth library. */ #define MAXPWLEN 8 #define CHALLENGESIZE 16 extern int vncEncryptAndStorePasswd(char *passwd, char *fname); extern char *vncDecryptPasswdFromFile(char *fname); extern void vncRandomBytes(unsigned char *bytes); extern void vncEncryptBytes(unsigned char *bytes, char *passwd); x2vnc-1.0/x2vnc.h100664 1750 1750 7256 6560202753 12321 0ustar hubbehubbe/* * Copyright (C) 1997, 1998 Olivetti & Oracle Research Laboratory * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ /* * vncviewer.h */ #include #include #include #include #include #include #include extern int endianTest; #define Swap16IfLE(s) \ (*(char *)&endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s)) #define Swap32IfLE(l) \ (*(char *)&endianTest ? ((((l) & 0xff000000) >> 24) | \ (((l) & 0x00ff0000) >> 8) | \ (((l) & 0x0000ff00) << 8) | \ (((l) & 0x000000ff) << 24)) : (l)) #define MAX_ENCODINGS 10 /* args.c */ extern char *programName; extern char hostname[]; extern int port; extern Bool listenSpecified; extern int listenPort, flashPort; extern char *displayname; extern Bool shareDesktop; extern Bool viewOnly; extern CARD32 explicitEncodings[]; extern int nExplicitEncodings; extern Bool addCopyRect; extern Bool addRRE; extern Bool addCoRRE; extern Bool addHextile; extern Bool useBGR233; extern Bool forceOwnCmap; extern Bool forceTruecolour; extern int requestedDepth; extern char *geometry; extern int wmDecorationWidth; extern int wmDecorationHeight; extern char *passwdFile; extern int updateRequestPeriodms; extern int updateRequestX; extern int updateRequestY; extern int updateRequestW; extern int updateRequestH; extern int rawDelay; extern int copyRectDelay; extern Bool debug; extern Bool resurface; extern void processArgs(int argc, char **argv); extern void usage(); /* rfbproto.c */ extern int rfbsock; extern Bool canUseCoRRE; extern Bool canUseHextile; extern char *desktopName; extern rfbPixelFormat myFormat; extern rfbServerInitMsg si; extern struct timeval updateRequestTime; extern Bool sendUpdateRequest; extern Bool ConnectToRFBServer(const char *hostname, int port); extern Bool InitialiseRFBConnection(); extern Bool SetFormatAndEncodings(); extern Bool SendIncrementalFramebufferUpdateRequest(); extern Bool SendFramebufferUpdateRequest(int x, int y, int w, int h, Bool incremental); extern Bool SendPointerEvent(int x, int y, int buttonMask); extern Bool SendKeyEvent(CARD32 key, Bool down); extern Bool SendClientCutText(char *str, int len); extern Bool HandleRFBServerMessage(); /* x.c */ enum edge_enum { EDGE_EAST, EDGE_WEST, EDGE_NORTH, EDGE_SOUTH }; extern enum edge_enum edge; extern Display *dpy; extern unsigned long BGR233ToPixel[]; extern Bool CreateXWindow(); extern void ShutdownX(); extern Bool HandleXEvents(); extern Bool AllXEventsPredicate(Display *dpy, XEvent *ev, char *arg); /* sockets.c */ extern Bool errorMessageFromReadExact; extern Bool ReadExact(int sock, char *buf, int n); extern Bool WriteExact(int sock, char *buf, int n); extern int ListenAtTcpPort(int port); extern int ConnectToTcpAddr(unsigned int host, int port); extern int AcceptTcpConnection(int listenSock); extern int StringToIPAddr(const char *str, unsigned int *addr); extern Bool SameMachine(int sock); /* listen.c */ extern void listenForIncomingConnections();