1 /*
2  * Copyright 1994, Brown University, Providence, RI
3  *
4  * Permission to use and modify this software and its documentation for
5  * any purpose other than its incorporation into a commercial product is
6  * hereby granted without fee.  Permission to copy and distribute this
7  * software and its documentation only for non-commercial use is also
8  * granted without fee, provided, however, that the above copyright notice
9  * appear in all copies, that both that copyright notice and this permission
10  * notice appear in supporting documentation, that the name of Brown
11  * University not be used in advertising or publicity pertaining to
12  * distribution of the software without specific, written prior permission,
13  * and that the person doing the distribution notify Brown University of
14  * such distributions outside of his or her organization. Brown University
15  * makes no representations about the suitability of this software for
16  * any purpose.  It is provided "as is" without express or implied warranty.
17  * Brown University requests notification of any modifications to this
18  * software or its documentation.
19  *
20  * Send the following redistribution information:
21  *
22  *	Name:
23  *	Organization:
24  *	Address (postal and/or electronic):
25  *
26  * To:
27  *	Software Librarian
28  *	Computer Science Department, Box 1910
29  *	Brown University
30  *	Providence, RI 02912
31  *
32  *		or
33  *
34  *	brusd@cs.brown.edu
35  *
36  * We will acknowledge all electronic notifications.
37  */
38 
39 /*
40 **	xnull.c
41 **
42 **	Null X client.  Sustains an X server for use by another
43 **	(remote) client.  Control-q on default root quits.
44 **
45 **	WARNING:  disables access control by default
46 **
47 */
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <netdb.h>
51 
52 #include <stdio.h>
53 #include <X11/X.h>
54 #include <X11/Xlib.h>
55 #include <X11/keysym.h>
56 
57 char *usage = "usage: xnull [-q] [hostname...]\n";
58 
main(argc,argv)59 main(argc, argv)
60    int argc;
61    char **argv;
62 {
63    int verbose = 1;
64    Display *dpy;
65    XSetWindowAttributes swa;
66    XEvent event;
67    XHostAddress ha;
68    struct hostent *hp;
69 
70    for (argc--, argv++; argc && **argv == '-'; argc--, argv++)
71       switch (*(*argv+1)) {
72          case 'q':
73             verbose = 0;
74             break;
75          default:
76             fprintf(stderr, usage);
77             exit(-1);
78       }
79 
80    dpy = XOpenDisplay(0);
81    if (dpy) {
82       swa.event_mask = KeyPressMask;
83       XChangeWindowAttributes(dpy, DefaultRootWindow(dpy), CWEventMask, &swa);
84       if (argc)
85          for (; argc--; argv++)
86             if (hp = gethostbyname(*argv)) {
87                ha.family = FamilyInternet;	/* so sue me */
88                ha.length = hp->h_length;
89                ha.address = *hp->h_addr_list;
90                XAddHost(dpy, &ha);
91                if (verbose)
92                   printf("xnull: added %s to access list\n", hp->h_name);
93             }
94             else
95                fprintf(stderr, "xnull: unknown host '%s'\n", *argv);
96       else {
97          XDisableAccessControl(dpy);
98          if (verbose)
99             printf("xnull: access control disabled\n");
100       }
101       while (1) {
102          XNextEvent(dpy, &event);
103          switch (event.type) {
104             case KeyPress:
105                if (	XKeycodeToKeysym(dpy, event.xkey.keycode, 0) == XK_q &&
106 			event.xkey.state & ControlMask)
107                   exit(0);
108                break;
109          }
110       }
111 
112    }
113 }
114