annotate lib-src/gnuserv.c @ 5927:b58b74274fa2 cygwin

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