identd.c revision 1.7 1 1.1 cgd /*
2 1.7 mycroft ** $NetBSD: identd.c,v 1.7 1997/08/04 18:00:14 mycroft Exp $
3 1.2 cgd **
4 1.1 cgd ** identd.c A TCP/IP link identification protocol server
5 1.1 cgd **
6 1.1 cgd ** This program is in the public domain and may be used freely by anyone
7 1.1 cgd ** who wants to.
8 1.1 cgd **
9 1.1 cgd ** Last update: 22 April 1993
10 1.1 cgd **
11 1.1 cgd ** Please send bug fixes/bug reports to: Peter Eriksson <pen (at) lysator.liu.se>
12 1.1 cgd */
13 1.1 cgd
14 1.2 cgd #if defined(IRIX) || defined(SVR4) || defined(NeXT) || defined(__NetBSD__)
15 1.1 cgd # define SIGRETURN_TYPE void
16 1.1 cgd # define SIGRETURN_TYPE_IS_VOID
17 1.1 cgd #else
18 1.1 cgd # define SIGRETURN_TYPE int
19 1.1 cgd #endif
20 1.1 cgd
21 1.1 cgd #ifdef SVR4
22 1.1 cgd # define STRNET
23 1.1 cgd #endif
24 1.1 cgd
25 1.1 cgd #include <stdio.h>
26 1.5 cgd #include <string.h>
27 1.1 cgd #include <ctype.h>
28 1.1 cgd #include <errno.h>
29 1.1 cgd #include <netdb.h>
30 1.1 cgd #include <signal.h>
31 1.1 cgd #include <fcntl.h>
32 1.1 cgd
33 1.1 cgd #include <sys/types.h>
34 1.1 cgd #include <sys/param.h>
35 1.1 cgd #include <sys/ioctl.h>
36 1.1 cgd #include <sys/socket.h>
37 1.1 cgd #ifndef _AUX_SOURCE
38 1.1 cgd # include <sys/file.h>
39 1.1 cgd #endif
40 1.1 cgd #include <sys/time.h>
41 1.1 cgd #include <sys/wait.h>
42 1.1 cgd
43 1.1 cgd #include <pwd.h>
44 1.1 cgd #include <grp.h>
45 1.1 cgd
46 1.1 cgd #include <netinet/in.h>
47 1.1 cgd
48 1.1 cgd #ifndef HPUX7
49 1.1 cgd # include <arpa/inet.h>
50 1.1 cgd #endif
51 1.1 cgd
52 1.1 cgd #if defined(MIPS) || defined(BSD43)
53 1.1 cgd extern int errno;
54 1.1 cgd #endif
55 1.1 cgd
56 1.1 cgd #include "identd.h"
57 1.1 cgd #include "error.h"
58 1.1 cgd
59 1.1 cgd /* Antique unixes do not have these things defined... */
60 1.1 cgd #ifndef FD_SETSIZE
61 1.1 cgd # define FD_SETSIZE 256
62 1.1 cgd #endif
63 1.1 cgd
64 1.1 cgd #ifndef FD_SET
65 1.1 cgd # ifndef NFDBITS
66 1.1 cgd # define NFDBITS (sizeof(int) * NBBY) /* bits per mask */
67 1.1 cgd # endif
68 1.1 cgd # define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
69 1.1 cgd #endif
70 1.1 cgd
71 1.1 cgd #ifndef FD_ZERO
72 1.1 cgd # define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
73 1.1 cgd #endif
74 1.1 cgd
75 1.1 cgd extern char *version;
76 1.1 cgd
77 1.1 cgd extern void *calloc();
78 1.1 cgd extern void *malloc();
79 1.1 cgd
80 1.1 cgd
81 1.1 cgd char *path_unix = NULL;
82 1.1 cgd char *path_kmem = NULL;
83 1.1 cgd
84 1.1 cgd int verbose_flag = 0;
85 1.1 cgd int debug_flag = 0;
86 1.1 cgd int syslog_flag = 0;
87 1.1 cgd int multi_flag = 0;
88 1.1 cgd int other_flag = 0;
89 1.1 cgd int unknown_flag = 0;
90 1.1 cgd int number_flag = 0;
91 1.1 cgd int noident_flag = 0;
92 1.1 cgd
93 1.1 cgd int lport = 0;
94 1.1 cgd int fport = 0;
95 1.1 cgd
96 1.1 cgd char *charset_name = NULL;
97 1.1 cgd char *indirect_host = NULL;
98 1.1 cgd char *indirect_password = NULL;
99 1.1 cgd
100 1.1 cgd static int child_pid;
101 1.1 cgd
102 1.1 cgd #ifdef LOG_DAEMON
103 1.1 cgd static int syslog_facility = LOG_DAEMON;
104 1.1 cgd #endif
105 1.1 cgd
106 1.1 cgd /*
107 1.1 cgd ** The structure passing convention for GCC is incompatible with
108 1.1 cgd ** Suns own C compiler, so we define our own inet_ntoa() function.
109 1.1 cgd ** (This should only affect GCC version 1 I think, a well, this works
110 1.1 cgd ** for version 2 also so why bother.. :-)
111 1.1 cgd */
112 1.1 cgd #if defined(__GNUC__) && defined(__sparc__)
113 1.1 cgd
114 1.1 cgd #ifdef inet_ntoa
115 1.1 cgd #undef inet_ntoa
116 1.1 cgd #endif
117 1.1 cgd
118 1.1 cgd char *inet_ntoa(ad)
119 1.1 cgd struct in_addr ad;
120 1.1 cgd {
121 1.1 cgd unsigned long int s_ad;
122 1.1 cgd int a, b, c, d;
123 1.1 cgd static char addr[20];
124 1.1 cgd
125 1.1 cgd s_ad = ad.s_addr;
126 1.1 cgd d = s_ad % 256;
127 1.1 cgd s_ad /= 256;
128 1.1 cgd c = s_ad % 256;
129 1.1 cgd s_ad /= 256;
130 1.1 cgd b = s_ad % 256;
131 1.1 cgd a = s_ad / 256;
132 1.1 cgd sprintf(addr, "%d.%d.%d.%d", a, b, c, d);
133 1.1 cgd
134 1.1 cgd return addr;
135 1.1 cgd }
136 1.1 cgd #endif
137 1.1 cgd
138 1.1 cgd
139 1.1 cgd /*
140 1.1 cgd ** Return the name of the connecting host, or the IP number as a string.
141 1.1 cgd */
142 1.1 cgd char *gethost(addr)
143 1.1 cgd struct in_addr *addr;
144 1.1 cgd {
145 1.1 cgd struct hostent *hp;
146 1.1 cgd
147 1.1 cgd
148 1.1 cgd hp = gethostbyaddr((char *) addr, sizeof(struct in_addr), AF_INET);
149 1.1 cgd if (hp)
150 1.1 cgd return hp->h_name;
151 1.1 cgd else
152 1.1 cgd return inet_ntoa(*addr);
153 1.1 cgd }
154 1.1 cgd
155 1.1 cgd /*
156 1.1 cgd ** Exit cleanly after our time's up.
157 1.1 cgd */
158 1.1 cgd static SIGRETURN_TYPE
159 1.1 cgd alarm_handler()
160 1.1 cgd {
161 1.1 cgd if (syslog_flag)
162 1.1 cgd syslog(LOG_DEBUG, "SIGALRM triggered, exiting");
163 1.1 cgd
164 1.1 cgd exit(0);
165 1.1 cgd }
166 1.1 cgd
167 1.7 mycroft #if !defined(hpux) && !defined(__hpux) && !defined(SVR4) && !defined(__NetBSD__) || defined(_CRAY)
168 1.1 cgd /*
169 1.1 cgd ** This is used to clean up zombie child processes
170 1.1 cgd ** if the -w or -b options are used.
171 1.1 cgd */
172 1.1 cgd static SIGRETURN_TYPE
173 1.1 cgd child_handler()
174 1.1 cgd {
175 1.1 cgd #if defined(IRIX) || defined(NeXT)
176 1.1 cgd union wait status;
177 1.1 cgd #else
178 1.1 cgd int status;
179 1.1 cgd #endif
180 1.1 cgd
181 1.1 cgd while (wait3(&status, WNOHANG, NULL) > 0)
182 1.1 cgd ;
183 1.1 cgd
184 1.1 cgd #ifndef SIGRETURN_TYPE_IS_VOID
185 1.1 cgd return 0;
186 1.1 cgd #endif
187 1.1 cgd }
188 1.1 cgd #endif
189 1.1 cgd
190 1.1 cgd
191 1.1 cgd char *clearmem(bp, len)
192 1.1 cgd char *bp;
193 1.1 cgd int len;
194 1.1 cgd {
195 1.1 cgd char *cp;
196 1.1 cgd
197 1.1 cgd cp = bp;
198 1.1 cgd while (len-- > 0)
199 1.1 cgd *cp++ = 0;
200 1.1 cgd
201 1.1 cgd return bp;
202 1.1 cgd }
203 1.1 cgd
204 1.1 cgd
205 1.1 cgd /*
206 1.1 cgd ** Main entry point into this daemon
207 1.1 cgd */
208 1.1 cgd int main(argc,argv)
209 1.1 cgd int argc;
210 1.1 cgd char *argv[];
211 1.1 cgd {
212 1.1 cgd int i, len;
213 1.1 cgd struct sockaddr_in sin;
214 1.1 cgd struct in_addr laddr, faddr;
215 1.1 cgd struct timeval tv;
216 1.1 cgd
217 1.1 cgd int background_flag = 0;
218 1.1 cgd int timeout = 0;
219 1.1 cgd char *portno = "113";
220 1.1 cgd char *bind_address = NULL;
221 1.1 cgd int set_uid = 0;
222 1.1 cgd int set_gid = 0;
223 1.1 cgd int inhibit_default_config = 0;
224 1.1 cgd int opt_count = 0; /* Count of option flags */
225 1.1 cgd
226 1.1 cgd #ifdef __convex__
227 1.1 cgd argc--; /* get rid of extra argument passed by inetd */
228 1.1 cgd #endif
229 1.1 cgd
230 1.1 cgd /*
231 1.1 cgd ** Prescan the arguments for "-f<config-file>" switches
232 1.1 cgd */
233 1.1 cgd inhibit_default_config = 0;
234 1.1 cgd for (i = 1; i < argc && argv[i][0] == '-'; i++)
235 1.1 cgd if (argv[i][1] == 'f')
236 1.1 cgd inhibit_default_config = 1;
237 1.1 cgd
238 1.1 cgd /*
239 1.1 cgd ** Parse the default config file - if it exists
240 1.1 cgd */
241 1.1 cgd if (!inhibit_default_config)
242 1.1 cgd parse_config(NULL, 1);
243 1.1 cgd
244 1.1 cgd /*
245 1.1 cgd ** Parse the command line arguments
246 1.1 cgd */
247 1.1 cgd for (i = 1; i < argc && argv[i][0] == '-'; i++) {
248 1.1 cgd opt_count++;
249 1.1 cgd switch (argv[i][1])
250 1.1 cgd {
251 1.1 cgd case 'b': /* Start as standalone daemon */
252 1.1 cgd background_flag = 1;
253 1.1 cgd break;
254 1.1 cgd
255 1.1 cgd case 'w': /* Start from Inetd, wait mode */
256 1.1 cgd background_flag = 2;
257 1.1 cgd break;
258 1.1 cgd
259 1.1 cgd case 'i': /* Start from Inetd, nowait mode */
260 1.1 cgd background_flag = 0;
261 1.1 cgd break;
262 1.1 cgd
263 1.1 cgd case 't':
264 1.1 cgd timeout = atoi(argv[i]+2);
265 1.1 cgd break;
266 1.1 cgd
267 1.1 cgd case 'p':
268 1.1 cgd portno = argv[i]+2;
269 1.1 cgd break;
270 1.1 cgd
271 1.1 cgd case 'a':
272 1.1 cgd bind_address = argv[i]+2;
273 1.1 cgd break;
274 1.1 cgd
275 1.1 cgd case 'u':
276 1.1 cgd if (isdigit(argv[i][2]))
277 1.1 cgd set_uid = atoi(argv[i]+2);
278 1.1 cgd else
279 1.1 cgd {
280 1.1 cgd struct passwd *pwd;
281 1.1 cgd
282 1.1 cgd pwd = getpwnam(argv[i]+2);
283 1.1 cgd if (!pwd)
284 1.1 cgd ERROR1("no such user (%s) for -u option", argv[i]+2);
285 1.1 cgd else
286 1.1 cgd {
287 1.1 cgd set_uid = pwd->pw_uid;
288 1.1 cgd set_gid = pwd->pw_gid;
289 1.1 cgd }
290 1.1 cgd }
291 1.1 cgd break;
292 1.1 cgd
293 1.1 cgd case 'g':
294 1.1 cgd if (isdigit(argv[i][2]))
295 1.1 cgd set_gid = atoi(argv[i]+2);
296 1.1 cgd else
297 1.1 cgd {
298 1.1 cgd struct group *grp;
299 1.1 cgd
300 1.1 cgd grp = getgrnam(argv[i]+2);
301 1.1 cgd if (!grp)
302 1.1 cgd ERROR1("no such group (%s) for -g option", argv[i]+2);
303 1.1 cgd else
304 1.1 cgd set_gid = grp->gr_gid;
305 1.1 cgd }
306 1.1 cgd break;
307 1.1 cgd
308 1.1 cgd case 'c':
309 1.1 cgd charset_name = argv[i]+2;
310 1.1 cgd break;
311 1.1 cgd
312 1.1 cgd case 'r':
313 1.1 cgd indirect_host = argv[i]+2;
314 1.1 cgd break;
315 1.1 cgd
316 1.1 cgd case 'l': /* Use the Syslog daemon for logging */
317 1.1 cgd syslog_flag++;
318 1.1 cgd break;
319 1.1 cgd
320 1.1 cgd case 'o':
321 1.1 cgd other_flag = 1;
322 1.1 cgd break;
323 1.1 cgd
324 1.1 cgd case 'e':
325 1.1 cgd unknown_flag = 1;
326 1.1 cgd break;
327 1.1 cgd
328 1.1 cgd case 'n':
329 1.1 cgd number_flag = 1;
330 1.1 cgd break;
331 1.1 cgd
332 1.1 cgd case 'V': /* Give version of this daemon */
333 1.1 cgd printf("[in.identd, version %s]\r\n", version);
334 1.1 cgd exit(0);
335 1.1 cgd break;
336 1.1 cgd
337 1.1 cgd case 'v': /* Be verbose */
338 1.1 cgd verbose_flag++;
339 1.1 cgd break;
340 1.1 cgd
341 1.1 cgd case 'd': /* Enable debugging */
342 1.1 cgd debug_flag++;
343 1.1 cgd break;
344 1.1 cgd
345 1.1 cgd case 'm': /* Enable multiline queries */
346 1.1 cgd multi_flag++;
347 1.1 cgd break;
348 1.1 cgd
349 1.1 cgd case 'N': /* Enable users ".noident" files */
350 1.1 cgd noident_flag++;
351 1.1 cgd break;
352 1.1 cgd }
353 1.1 cgd }
354 1.1 cgd
355 1.1 cgd #if defined(_AUX_SOURCE) || defined (SUNOS35)
356 1.1 cgd /* A/UX 2.0* & SunOS 3.5 calls us with an argument XXXXXXXX.YYYY
357 1.1 cgd ** where XXXXXXXXX is the hexadecimal version of the callers
358 1.1 cgd ** IP number, and YYYY is the port/socket or something.
359 1.1 cgd ** It seems to be impossible to pass arguments to a daemon started
360 1.1 cgd ** by inetd.
361 1.1 cgd **
362 1.1 cgd ** Just in case it is started from something else, then we only
363 1.1 cgd ** skip the argument if no option flags have been seen.
364 1.1 cgd */
365 1.1 cgd if (opt_count == 0)
366 1.1 cgd argc--;
367 1.1 cgd #endif
368 1.1 cgd
369 1.1 cgd /*
370 1.1 cgd ** Path to kernel namelist file specified on command line
371 1.1 cgd */
372 1.1 cgd if (i < argc)
373 1.1 cgd path_unix = argv[i++];
374 1.1 cgd
375 1.1 cgd /*
376 1.1 cgd ** Path to kernel memory device specified on command line
377 1.1 cgd */
378 1.1 cgd if (i < argc)
379 1.1 cgd path_kmem = argv[i++];
380 1.1 cgd
381 1.1 cgd
382 1.1 cgd /*
383 1.1 cgd ** Open the kernel memory device and read the nlist table
384 1.1 cgd */
385 1.1 cgd if (k_open() < 0)
386 1.1 cgd ERROR("main: k_open");
387 1.1 cgd
388 1.1 cgd /*
389 1.1 cgd ** Do the special handling needed for the "-b" flag
390 1.1 cgd */
391 1.1 cgd if (background_flag == 1)
392 1.1 cgd {
393 1.1 cgd struct sockaddr_in addr;
394 1.1 cgd struct servent *sp;
395 1.1 cgd int fd;
396 1.1 cgd
397 1.1 cgd
398 1.1 cgd if (fork())
399 1.1 cgd exit(0);
400 1.1 cgd
401 1.1 cgd close(0);
402 1.1 cgd close(1);
403 1.1 cgd close(2);
404 1.1 cgd
405 1.1 cgd if (fork())
406 1.1 cgd exit(0);
407 1.1 cgd
408 1.1 cgd fd = socket(AF_INET, SOCK_STREAM, 0);
409 1.1 cgd if (fd == -1)
410 1.1 cgd ERROR("main: socket");
411 1.1 cgd
412 1.1 cgd if (fd != 0)
413 1.1 cgd dup2(fd, 0);
414 1.1 cgd
415 1.1 cgd clearmem(&addr, sizeof(addr));
416 1.1 cgd
417 1.4 mycroft addr.sin_len = sizeof(struct sockaddr_in);
418 1.1 cgd addr.sin_family = AF_INET;
419 1.1 cgd if (bind_address == NULL)
420 1.1 cgd addr.sin_addr.s_addr = htonl(INADDR_ANY);
421 1.1 cgd else
422 1.1 cgd {
423 1.3 mycroft if (inet_aton(bind_address, &addr.sin_addr) == 0)
424 1.1 cgd {
425 1.1 cgd struct hostent *hp;
426 1.1 cgd
427 1.1 cgd hp = gethostbyname(bind_address);
428 1.1 cgd if (!hp)
429 1.1 cgd ERROR1("no such address (%s) for -a switch", bind_address);
430 1.1 cgd
431 1.3 mycroft memcpy(&addr.sin_addr, hp->h_addr, sizeof(addr.sin_addr));
432 1.1 cgd }
433 1.1 cgd }
434 1.1 cgd
435 1.1 cgd if (isdigit(portno[0]))
436 1.1 cgd addr.sin_port = htons(atoi(portno));
437 1.1 cgd else
438 1.1 cgd {
439 1.1 cgd sp = getservbyname(portno, "tcp");
440 1.1 cgd if (sp == NULL)
441 1.1 cgd ERROR1("main: getservbyname: %s", portno);
442 1.1 cgd addr.sin_port = sp->s_port;
443 1.1 cgd }
444 1.1 cgd
445 1.1 cgd if (bind(0, (struct sockaddr *) &addr, sizeof(addr)) < 0)
446 1.1 cgd ERROR("main: bind");
447 1.1 cgd
448 1.1 cgd if (listen(0, 3) < 0)
449 1.1 cgd ERROR("main: listen");
450 1.1 cgd }
451 1.1 cgd
452 1.1 cgd if (set_gid)
453 1.1 cgd if (setgid(set_gid) == -1)
454 1.1 cgd ERROR("main: setgid");
455 1.1 cgd
456 1.1 cgd if (set_uid)
457 1.1 cgd if (setuid(set_uid) == -1)
458 1.1 cgd ERROR("main: setuid");
459 1.1 cgd
460 1.1 cgd /*
461 1.1 cgd ** Do some special handling if the "-b" or "-w" flags are used
462 1.1 cgd */
463 1.1 cgd if (background_flag)
464 1.1 cgd {
465 1.1 cgd int nfds, fd;
466 1.1 cgd fd_set read_set;
467 1.1 cgd
468 1.1 cgd
469 1.1 cgd /*
470 1.1 cgd ** Set up the SIGCHLD signal child termination handler so
471 1.1 cgd ** that we can avoid zombie processes hanging around and
472 1.1 cgd ** handle childs terminating before being able to complete the
473 1.1 cgd ** handshake.
474 1.1 cgd */
475 1.1 cgd #if (defined(SVR4) || defined(hpux) || defined(__hpux) || \
476 1.7 mycroft defined(__NetBSD__) || defined(_CRAY) || defined(_AUX_SOURCE))
477 1.1 cgd signal(SIGCHLD, SIG_IGN);
478 1.1 cgd #else
479 1.1 cgd signal(SIGCHLD, (SIGRETURN_TYPE (*)()) child_handler);
480 1.1 cgd #endif
481 1.1 cgd
482 1.1 cgd /*
483 1.1 cgd ** Loop and dispatch client handling processes
484 1.1 cgd */
485 1.1 cgd do
486 1.1 cgd {
487 1.1 cgd /*
488 1.1 cgd ** Terminate if we've been idle for 'timeout' seconds
489 1.1 cgd */
490 1.1 cgd if (background_flag == 2 && timeout)
491 1.1 cgd {
492 1.1 cgd signal(SIGALRM, alarm_handler);
493 1.1 cgd alarm(timeout);
494 1.1 cgd }
495 1.1 cgd
496 1.1 cgd /*
497 1.1 cgd ** Wait for a connection request to occur.
498 1.1 cgd ** Ignore EINTR (Interrupted System Call).
499 1.1 cgd */
500 1.1 cgd do
501 1.1 cgd {
502 1.1 cgd FD_ZERO(&read_set);
503 1.1 cgd FD_SET(0, &read_set);
504 1.1 cgd
505 1.1 cgd if (timeout)
506 1.1 cgd {
507 1.1 cgd tv.tv_sec = timeout;
508 1.1 cgd tv.tv_usec = 0;
509 1.1 cgd nfds = select(FD_SETSIZE, &read_set, NULL, NULL, &tv);
510 1.1 cgd }
511 1.1 cgd else
512 1.1 cgd
513 1.1 cgd nfds = select(FD_SETSIZE, &read_set, NULL, NULL, NULL);
514 1.1 cgd } while (nfds < 0 && errno == EINTR);
515 1.1 cgd
516 1.1 cgd /*
517 1.1 cgd ** An error occured in select? Just die
518 1.1 cgd */
519 1.1 cgd if (nfds < 0)
520 1.1 cgd ERROR("main: select");
521 1.1 cgd
522 1.1 cgd /*
523 1.1 cgd ** Timeout limit reached. Exit nicely
524 1.1 cgd */
525 1.1 cgd if (nfds == 0)
526 1.1 cgd exit(0);
527 1.1 cgd
528 1.1 cgd /*
529 1.1 cgd ** Disable the alarm timeout
530 1.1 cgd */
531 1.1 cgd alarm(0);
532 1.1 cgd
533 1.1 cgd /*
534 1.1 cgd ** Accept the new client
535 1.1 cgd */
536 1.1 cgd fd = accept(0, NULL, NULL);
537 1.1 cgd if (fd == -1)
538 1.1 cgd ERROR1("main: accept. errno = %d", errno);
539 1.1 cgd
540 1.1 cgd /*
541 1.1 cgd ** And fork, then close the fd if we are the parent.
542 1.1 cgd */
543 1.1 cgd child_pid = fork();
544 1.1 cgd } while (child_pid && (close(fd), 1));
545 1.1 cgd
546 1.1 cgd /*
547 1.1 cgd ** We are now in child, the parent has returned to "do" above.
548 1.1 cgd */
549 1.1 cgd if (dup2(fd, 0) == -1)
550 1.1 cgd ERROR("main: dup2: failed fd 0");
551 1.1 cgd
552 1.1 cgd if (dup2(fd, 1) == -1)
553 1.1 cgd ERROR("main: dup2: failed fd 1");
554 1.1 cgd
555 1.1 cgd if (dup2(fd, 2) == -1)
556 1.1 cgd ERROR("main: dup2: failed fd 2");
557 1.1 cgd }
558 1.1 cgd
559 1.1 cgd /*
560 1.1 cgd ** Get foreign internet address
561 1.1 cgd */
562 1.1 cgd len = sizeof(sin);
563 1.1 cgd if (getpeername(0, (struct sockaddr *) &sin, &len) == -1)
564 1.1 cgd {
565 1.1 cgd /*
566 1.1 cgd ** A user has tried to start us from the command line or
567 1.1 cgd ** the network link died, in which case this message won't
568 1.1 cgd ** reach to other end anyway, so lets give the poor user some
569 1.1 cgd ** errors.
570 1.1 cgd */
571 1.1 cgd perror("in.identd: getpeername()");
572 1.1 cgd exit(1);
573 1.1 cgd }
574 1.1 cgd
575 1.1 cgd faddr = sin.sin_addr;
576 1.1 cgd
577 1.1 cgd
578 1.1 cgd /*
579 1.1 cgd ** Open the connection to the Syslog daemon if requested
580 1.1 cgd */
581 1.1 cgd if (syslog_flag)
582 1.1 cgd {
583 1.1 cgd #ifdef LOG_DAEMON
584 1.1 cgd openlog("identd", LOG_PID, syslog_facility);
585 1.1 cgd #else
586 1.1 cgd openlog("identd", LOG_PID);
587 1.1 cgd #endif
588 1.1 cgd
589 1.1 cgd syslog(LOG_INFO, "Connection from %s", gethost(&faddr));
590 1.1 cgd }
591 1.1 cgd
592 1.1 cgd
593 1.1 cgd /*
594 1.1 cgd ** Get local internet address
595 1.1 cgd */
596 1.1 cgd len = sizeof(sin);
597 1.1 cgd #ifdef ATTSVR4
598 1.1 cgd if (t_getsockname(0, (struct sockaddr *) &sin, &len) == -1)
599 1.1 cgd #else
600 1.1 cgd if (getsockname(0, (struct sockaddr *) &sin, &len) == -1)
601 1.1 cgd #endif
602 1.1 cgd {
603 1.1 cgd /*
604 1.1 cgd ** We can just die here, because if this fails then the
605 1.1 cgd ** network has died and we haven't got anyone to return
606 1.1 cgd ** errors to.
607 1.1 cgd */
608 1.1 cgd exit(1);
609 1.1 cgd }
610 1.1 cgd laddr = sin.sin_addr;
611 1.1 cgd
612 1.1 cgd
613 1.1 cgd /*
614 1.1 cgd ** Get the local/foreign port pair from the luser
615 1.1 cgd */
616 1.1 cgd parse(stdin, &laddr, &faddr);
617 1.1 cgd
618 1.1 cgd exit(0);
619 1.1 cgd }
620