annotate lib-src/gnuserv.c @ 48:56c54cf7c5b6 r19-16b90

Import from CVS: tag r19-16b90
author cvs
date Mon, 13 Aug 2007 08:56:04 +0200
parents ec9a17fef872
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* -*-C-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Server code for handling requests from clients and forwarding them
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 on to the GNU Emacs process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 Copying is permitted under those conditions described by the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 General Public License.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 Author: Andy Norman (ange@hplb.hpl.hp.com), based on 'etc/server.c'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 from the 18.52 GNU Emacs distribution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 Please mail bugs and suggestions to the author at the above address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 /* HISTORY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 * 11-Nov-1990 bristor@simba
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 * Added EOT stuff.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 * This file incorporates new features added by Bob Weiner <weiner@mot.com>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 * Darrell Kindred <dkindred@cmu.edu> and Arup Mukherjee <arup@cmu.edu>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 * Please see the note at the end of the README file for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 * (If gnuserv came bundled with your emacs, the README file is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 * ../etc/gnuserv.README relative to the directory containing this file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 static char rcsid [] = "!Header: gnuserv.c,v 2.1 95/02/16 11:58:27 arup alpha !";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "gnuserv.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #ifdef USE_LITOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #ifdef linux
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include <bsd/sgtty.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include <sgtty.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include <sys/select.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include <unistd.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #if !defined(SYSV_IPC) && !defined(UNIX_DOMAIN_SOCKETS) && \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 !defined(INTERNET_DOMAIN_SOCKETS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 main ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 fprintf (stderr,"Sorry, the Emacs server is only supported on systems that have\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 fprintf (stderr,"Unix Domain sockets, Internet Domain sockets or System V IPC\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #else /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 int ipc_qid = 0; /* ipc message queue id */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 int ipc_wpid = 0; /* watchdog task pid */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ipc_exit -- clean up the queue id and queue, then kill the watchdog task
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 if it exists. exit with the given status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 void ipc_exit(stat)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 int stat;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 msgctl(ipc_qid,IPC_RMID,0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if (ipc_wpid != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 kill(ipc_wpid,SIGKILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 exit(stat);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 } /* ipc_exit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ipc_handle_signal -- catch the signal given and clean up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 void ipc_handle_signal(sig)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 int sig;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ipc_exit(0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 } /* ipc_handle_signal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ipc_spawn_watchdog -- spawn a watchdog task to clean up the message queue should the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 server process die.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 void ipc_spawn_watchdog()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 if ((ipc_wpid = fork()) == 0) { /* child process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 int ppid = getppid(); /* parent's process id */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 setpgrp(); /* gnu kills process group on exit */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 while (1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 if (kill(ppid,0) < 0) { /* ppid is no longer valid, parent may have died */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ipc_exit(0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 sleep(10); /* have another go later */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 } /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 } /* ipc_spawn_watchdog */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ipc_init -- initialize server, setting the global msqid that can be listened on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 void ipc_init(msgpp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 struct msgbuf **msgpp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 key_t key; /* messge key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 char buf[GSERV_BUFSZ]; /* pathname for key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 sprintf(buf,"/tmp/gsrv%d",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 creat(buf,0600);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 key = ftok(buf,1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 if ((ipc_qid = msgget(key,0600|IPC_CREAT)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 fprintf(stderr,"%s: unable to create msg queue\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ipc_exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ipc_spawn_watchdog();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 signal(SIGTERM,ipc_handle_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 signal(SIGINT,ipc_handle_signal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 if ((*msgpp = (struct msgbuf *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 malloc(sizeof **msgpp + GSERV_BUFSZ)) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 fprintf(stderr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "%s: unable to allocate space for message buffer\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ipc_exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 } /* ipc_init */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 handle_ipc_request -- accept a request from a client, pass the request on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 to the GNU Emacs process, then wait for its reply and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 pass that on to the client.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 void handle_ipc_request(msgp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 struct msgbuf *msgp; /* message buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 struct msqid_ds msg_st; /* message status */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 char buf[GSERV_BUFSZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 int len; /* length of message / read */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 int s, result_len; /* tag fields on the response from emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 int offset = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 int total = 1; /* # bytes that will actually be sent off */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if ((len = msgrcv(ipc_qid,msgp,GSERV_BUFSZ-1,1,0)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 fprintf(stderr,"%s: unable to receive\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ipc_exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 msgctl(ipc_qid,IPC_STAT,&msg_st);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 strncpy(buf,msgp->mtext,len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 buf[len] = '\0'; /* terminate */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 printf("%d %s",ipc_qid,buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 fflush(stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 /* now for the response from gnu */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 msgp->mtext[0] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 if ((len = read(0,buf,GSERV_BUFSZ-1)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ipc_exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 sscanf(buf,"%d:%[^\n]\n",&junk,msgp->mtext);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 /* read in "n/m:" (n=client fd, m=message length) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 while (offset < (GSERV_BUFSZ-1) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ((len = read(0,buf+offset,1)) > 0) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 buf[offset] != ':') {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 offset += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (len < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 /* parse the response from emacs, getting client fd & result length */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 buf[offset] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 sscanf(buf,"%d/%d", &s, &result_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 while (result_len > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 if ((len = read(0,buf,min2(result_len, GSERV_BUFSZ - 1))) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 /* Send this string off, but only if we have enough space */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 if (GSERV_BUFSZ > total) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 if (total + len <= GSERV_BUFSZ)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 buf[len] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 buf[GSERV_BUFSZ - total] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 send_string(s,buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 total += strlen(buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 result_len -= len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 /* eat the newline */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 while ((len = read(0,buf,1)) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if (len < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 if (buf[0] != '\n') {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 fprintf(stderr,"%s: garbage after result [%c]\n",progname, buf[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 /* Send a response back to the client. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 msgp->mtype = msg_st.msg_lspid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 if (msgsnd(ipc_qid,msgp,strlen(msgp->mtext)+1,0) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 perror("msgsend(gnuserv)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 } /* handle_ipc_request */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 #if defined(INTERNET_DOMAIN_SOCKETS) || defined(UNIX_DOMAIN_SOCKETS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 echo_request -- read request from a given socket descriptor, and send the information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 to stdout (the gnu process).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 echo_request (int s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 char buf[GSERV_BUFSZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 printf("%d ",s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 /* read until we get a newline or no characters */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 while ((len = recv(s,buf,GSERV_BUFSZ-1,0)) > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 buf[len] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 printf("%s",buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 if (buf[len-1] == EOT_CHR) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 fflush(stdout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 break; /* end of message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 } /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (len < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 fprintf(stderr,"%s: unable to recv\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 } /* echo_request */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 handle_response -- accept a response from stdin (the gnu process) and pass the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 information on to the relevant client.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 handle_response (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 char buf[GSERV_BUFSZ+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 int offset=0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 int result_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 /* read in "n/m:" (n=client fd, m=message length) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 while (offset < GSERV_BUFSZ &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ((len = read(0,buf+offset,1)) > 0) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 buf[offset] != ':') {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 offset += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 if (len < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 /* parse the response from emacs, getting client fd & result length */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 buf[offset] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 sscanf(buf,"%d/%d", &s, &result_len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 while (result_len > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 if ((len = read(0,buf,min2(result_len,GSERV_BUFSZ))) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 buf[len] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 send_string(s,buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 result_len -= len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 /* eat the newline */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 while ((len = read(0,buf,1)) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 if (len < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 fprintf(stderr,"%s: unable to read\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 if (buf[0] != '\n') {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 fprintf(stderr,"%s: garbage after result\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 0
diff changeset
348 /* send the newline */
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 0
diff changeset
349 buf[1] = '\0';
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 0
diff changeset
350 send_string(s,buf);
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 0
diff changeset
351 close(s);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 } /* handle_response */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 struct entry {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 u_long host_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 struct entry *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 struct entry *permitted_hosts[TABLE_SIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 #ifdef AUTH_MAGIC_COOKIE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 # include <X11/X.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 # include <X11/Xauth.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 static Xauth *server_xauth = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 timed_read (int fd, char *buf, int max, int timeout, int one_line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 fd_set rmask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 struct timeval tv; /* = {timeout, 0}; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 char c = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 int nbytes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 int r;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 tv.tv_sec = timeout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 tv.tv_usec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 FD_ZERO(&rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 FD_SET(fd, &rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 do {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 r = select(fd + 1, &rmask, NULL, NULL, &tv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 if (r > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (read (fd, &c, 1) == 1 ){
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 *buf++ = c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ++nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 printf ("read error on socket\004\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 } else if (r == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 printf ("read timed out\004\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 } else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 printf ("error in select\004\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 } while ((nbytes < max) && !(one_line && (c == '\n')));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 --buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 if (one_line && *buf == '\n') {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 *buf = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 return nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 permitted -- return whether a given host is allowed to connect to the server.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 permitted (u_long host_addr, int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 int key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 struct entry *entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 char auth_protocol[128];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 char buf[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 int auth_data_len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 if (fd > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 /* we are checking permission on a real connection */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 /* Read auth protocol name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 if (timed_read(fd, auth_protocol, AUTH_NAMESZ, AUTH_TIMEOUT, 1) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 return FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 if (strcmp (auth_protocol, DEFAUTH_NAME) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 strcmp (auth_protocol, MCOOKIE_NAME)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 printf ("authentication protocol (%s) from client is invalid...\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 auth_protocol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 printf ("... Was the client an old version of gnuclient/gnudoit?\004\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 return FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 if (!strcmp(auth_protocol, MCOOKIE_NAME)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 * doing magic cookie auth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 if (timed_read(fd, buf, 10, AUTH_TIMEOUT, 1) <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 return FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 auth_data_len = atoi(buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 if (timed_read(fd, buf, auth_data_len, AUTH_TIMEOUT, 0) != auth_data_len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 return FALSE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 #ifdef AUTH_MAGIC_COOKIE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 if (server_xauth && server_xauth->data &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 !memcmp(buf, server_xauth->data, auth_data_len)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 return TRUE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 printf ("client tried Xauth, but server is not compiled with Xauth\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 * auth failed, but allow this to fall through to the GNU_SECURE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 * protocol....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 printf ("Xauth authentication failed, trying GNU_SECURE auth...\004\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 /* Other auth protocols go here, and should execute only if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 * auth_protocol name matches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 /* Now, try the old GNU_SECURE stuff... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 /* First find the hash key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 key = HASH(host_addr) % TABLE_SIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 /* Now check the chain for that hash key */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 for(entry=permitted_hosts[key]; entry != NULL; entry=entry->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 if (host_addr == entry->host_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 return(TRUE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 return(FALSE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 } /* permitted */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 add_host -- add the given host to the list of permitted hosts, provided it isn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 already there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 add_host (u_long host_addr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 int key;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 struct entry *new_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 if (!permitted(host_addr, -1)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 if ((new_entry = (struct entry *) malloc(sizeof(struct entry))) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 fprintf(stderr,"%s: unable to malloc space for permitted host entry\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 new_entry->host_addr = host_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 key = HASH(host_addr) % TABLE_SIZE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 new_entry->next = permitted_hosts[key];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 permitted_hosts[key] = new_entry;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 } /* add_host */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 setup_table -- initialise the table of hosts allowed to contact the server,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 by reading from the file specified by the GNU_SECURE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 environment variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 Put in the local machine, and, if a security file is specifed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 add each host that is named in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 Return the number of hosts added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 setup_table (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 FILE *host_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 char *file_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 char hostname[HOSTNAMSZ];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 u_int host_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 int i, hosts=0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 /* Make sure every entry is null */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 for (i=0; i<TABLE_SIZE; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 permitted_hosts[i] = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 gethostname(hostname,HOSTNAMSZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 if ((host_addr = internet_addr(hostname)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 progname,hostname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 #ifdef AUTH_MAGIC_COOKIE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 server_xauth = XauGetAuthByAddr (FamilyInternet,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 sizeof(host_addr), (char *)&host_addr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 hosts++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 #endif /* AUTH_MAGIC_COOKIE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 #if 0 /* Don't even want to allow access from the local host by default */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 add_host(host_addr); /* add local host */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 if (((file_name = getenv("GNU_SECURE")) != NULL && /* security file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (host_file = fopen(file_name,"r")) != NULL)) { /* opened ok */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 while ((fscanf(host_file,"%s",hostname) != EOF)) /* find a host */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 if ((host_addr = internet_addr(hostname)) != -1) {/* get its addr */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 add_host(host_addr); /* add the addr */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 hosts++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 fclose(host_file);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 return hosts;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 } /* setup_table */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 internet_init -- initialize server, returning an internet socket that can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 be listened on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 internet_init (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 int ls; /* socket descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 struct servent *sp; /* pointer to service information */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 struct sockaddr_in server; /* for local socket address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 char *ptr; /* ptr to return from getenv */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 if (setup_table() == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 /* clear out address structure */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 memset((char *)&server,0,sizeof(struct sockaddr_in));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 /* Set up address structure for the listen socket. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 server.sin_family = AF_INET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 server.sin_addr.s_addr = INADDR_ANY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 /* Find the information for the gnu server
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 * in order to get the needed port number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 if ((ptr=getenv("GNU_PORT")) != NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 server.sin_port = htons(atoi(ptr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 else if ((sp = getservbyname ("gnuserv", "tcp")) == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 server.sin_port = htons(DEFAULT_PORT+getuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 server.sin_port = sp->s_port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 /* Create the listen socket. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 if ((ls = socket (AF_INET,SOCK_STREAM, 0)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 fprintf(stderr,"%s: unable to create socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 /* Bind the listen address to the socket. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 if (bind(ls,(struct sockaddr *) &server,sizeof(struct sockaddr_in)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 fprintf(stderr,"%s: unable to bind socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 /* Initiate the listen on the socket so remote users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 * can connect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 if (listen(ls,20) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 fprintf(stderr,"%s: unable to listen\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 return(ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 } /* internet_init */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 handle_internet_request -- accept a request from a client and send the information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 to stdout (the gnu process).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 handle_internet_request (int ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 int addrlen = sizeof(struct sockaddr_in);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 struct sockaddr_in peer; /* for peer socket address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 memset((char *)&peer,0,sizeof(struct sockaddr_in));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 if ((s = accept(ls,(struct sockaddr *)&peer,&addrlen)) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 fprintf(stderr,"%s: unable to accept\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 /* Check that access is allowed - if not return crud to the client */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 if (!permitted(peer.sin_addr.s_addr, s)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 send_string(s,"gnudoit: Connection refused\ngnudoit: unable to connect to remote");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 close(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 printf("Refused connection from %s\004\n", inet_ntoa(peer.sin_addr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 echo_request(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 } /* handle_internet_request */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 unix_init -- initialize server, returning an unix-domain socket that can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 be listened on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 unix_init (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 int ls; /* socket descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 struct sockaddr_un server; /* unix socket address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 int bindlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 if ((ls = socket(AF_UNIX,SOCK_STREAM, 0)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 fprintf(stderr,"%s: unable to create socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 /* Set up address structure for the listen socket. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 #ifdef HIDE_UNIX_SOCKET
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 sprintf(server.sun_path,"/tmp/gsrvdir%d",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 if (mkdir(server.sun_path, 0700) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 /* assume it already exists, and try to set perms */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 if (chmod(server.sun_path, 0700) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 fprintf(stderr,"%s: can't set permissions on %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 progname, server.sun_path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 strcat(server.sun_path,"/gsrv");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 unlink(server.sun_path); /* remove old file if it exists */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 #else /* HIDE_UNIX_SOCKET */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 sprintf(server.sun_path,"/tmp/gsrv%d",(int)geteuid());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 unlink(server.sun_path); /* remove old file if it exists */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 #endif /* HIDE_UNIX_SOCKET */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 server.sun_family = AF_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 #ifdef HAVE_SOCKADDR_SUN_LEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 /* See W. R. Stevens "Advanced Programming in the Unix Environment"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 p. 502 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 bindlen = (sizeof (server.sun_len) + sizeof (server.sun_family)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 + strlen (server.sun_path) + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 server.sun_len = bindlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 bindlen = strlen (server.sun_path) + sizeof (server.sun_family);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 if (bind(ls,(struct sockaddr *)&server,bindlen) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 fprintf(stderr,"%s: unable to bind socket\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 chmod(server.sun_path,0700); /* only this user can send commands */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 if (listen(ls,20) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 fprintf(stderr,"%s: unable to listen\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 /* #### there are also better ways of dealing with this when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 sigvec() is present. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 #if defined (HAVE_SIGPROCMASK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 sigset_t _mask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 sigemptyset (&_mask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 sigaddset (&_mask, SIGPIPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 sigprocmask (SIG_BLOCK, &_mask, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 signal(SIGPIPE,SIG_IGN); /* in case user kills client */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 return(ls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 } /* unix_init */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 handle_unix_request -- accept a request from a client and send the information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 to stdout (the gnu process).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 handle_unix_request (int ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 int s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 int len = sizeof(struct sockaddr_un);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 struct sockaddr_un server; /* for unix socket address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 server.sun_family = AF_UNIX;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 if ((s = accept(ls,(struct sockaddr *)&server,&len)) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 fprintf(stderr,"%s: unable to accept\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 echo_request(s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 } /* handle_unix_request */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 #endif /* UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 main(argc,argv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 int argc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 char *argv[];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 int chan; /* temporary channel number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 int ils = -1; /* internet domain listen socket */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 int uls = -1; /* unix domain listen socket */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 struct msgbuf *msgp; /* message buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 progname = argv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 for(chan=3; chan < _NFILE; close(chan++)) /* close unwanted channels */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 #ifdef USE_LITOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 /* this is to allow ^D to pass to emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 int d = LLITOUT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (void) ioctl(fileno(stdout), TIOCLBIS, &d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 ipc_init(&msgp); /* get a msqid to listen on, and a message buffer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 #endif /* SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 ils = internet_init(); /* get a internet domain socket to listen on */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 uls = unix_init(); /* get a unix domain socket to listen on */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 #endif /* UNIX_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 while (1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 #ifdef SYSV_IPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 handle_ipc_request(msgp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 #else /* NOT SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 fd_set rmask;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 FD_ZERO(&rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 FD_SET(fileno(stdin), &rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 if (uls >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 FD_SET(uls, &rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 if (ils >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 FD_SET(ils, &rmask);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 perror(progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 fprintf(stderr,"%s: unable to select\n",progname);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 exit(1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 } /* if */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 #ifdef UNIX_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 if (uls > 0 && FD_ISSET(uls, &rmask))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 handle_unix_request(uls);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 #ifdef INTERNET_DOMAIN_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 if (ils > 0 && FD_ISSET(ils, &rmask))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 handle_internet_request(ils);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 #endif /* INTERNET_DOMAIN_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 if (FD_ISSET(fileno(stdin), &rmask)) /* from stdin (gnu process) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 handle_response();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 #endif /* NOT SYSV_IPC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 } /* while */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 } /* main */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */