|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983, 1988 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted provided ! 6: * that: (1) source distributions retain this entire copyright notice and ! 7: * comment, and (2) distributions including binaries display the following ! 8: * acknowledgement: ``This product includes software developed by the ! 9: * University of California, Berkeley and its contributors'' in the ! 10: * documentation or other materials provided with the distribution and in ! 11: * all advertising materials mentioning features or use of this software. ! 12: * Neither the name of the University nor the names of its contributors may ! 13: * be used to endorse or promote products derived from this software without ! 14: * specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 16: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 17: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)implogd.c 5.9 (Berkeley) 6/1/90"; ! 28: #endif /* not lint */ ! 29: ! 30: #include <sys/param.h> ! 31: #include <sys/time.h> ! 32: #include <sys/socket.h> ! 33: #include <sys/syslog.h> ! 34: #include <sys/file.h> ! 35: ! 36: #include <net/if.h> ! 37: ! 38: #include <netinet/in.h> ! 39: #include <netimp/if_imp.h> ! 40: ! 41: #include <sgtty.h> ! 42: #include "pathnames.h" ! 43: ! 44: /* ! 45: * Socket address, internet style, with ! 46: * unused space taken by timestamp and packet ! 47: * size. ! 48: */ ! 49: struct sockstamp { ! 50: short sin_family; ! 51: u_short sin_port; ! 52: struct in_addr sin_addr; ! 53: time_t sin_time; ! 54: int sin_len; ! 55: }; ! 56: ! 57: main() ! 58: { ! 59: register int len, log, s; ! 60: struct sockstamp from; ! 61: int fromlen; ! 62: u_char request[1024]; ! 63: time_t time(); ! 64: ! 65: openlog("implogd", LOG_PID|LOG_ODELAY|LOG_PERROR, LOG_DAEMON); ! 66: log = open(_PATH_IMPLOG, O_CREAT|O_WRONLY|O_APPEND, 0644); ! 67: if (log < 0) { ! 68: syslog(LOG_ERR, "%s: %m\n", _PATH_IMPLOG); ! 69: exit(1); ! 70: } ! 71: from.sin_time = time((time_t *)NULL); ! 72: from.sin_len = sizeof(time_t); ! 73: (void)write(log, (char *)&from, sizeof(from)); ! 74: if ((s = socket(AF_IMPLINK, SOCK_RAW, 0)) < 0) { ! 75: syslog(LOG_ERR, "socket: %m\n"); ! 76: exit(1); ! 77: } ! 78: #ifndef DEBUG ! 79: { ! 80: register int i, tt; ! 81: ! 82: if (fork()) ! 83: exit(0); ! 84: for (i = 0; i < 10; i++) ! 85: if (i != log && i != s) ! 86: (void) close(i); ! 87: (void) open("/", O_RDONLY, 0); ! 88: (void) dup2(0, 1); ! 89: (void) dup2(0, 2); ! 90: tt = open(_PATH_TTY, O_RDWR, 0); ! 91: if (tt > 0) { ! 92: ioctl(tt, TIOCNOTTY, 0); ! 93: (void)close(tt); ! 94: } ! 95: } ! 96: #endif ! 97: for (fromlen = sizeof(from);;) { ! 98: len = recvfrom(s, request, sizeof(request), 0, ! 99: &from, &fromlen); ! 100: if (len < 0) { ! 101: syslog(LOG_ERR, "recvfrom: %m\n"); ! 102: continue; ! 103: } ! 104: if (len == 0 || len > IMPMTU) /* sanity */ ! 105: continue; ! 106: from.sin_len = len; ! 107: from.sin_time = time((time_t *)NULL); ! 108: (void)write(log, (char *)&from, sizeof(from)); ! 109: (void)write(log, request, len); ! 110: } ! 111: /*NOTREACHED*/ ! 112: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.