/* * Copyright (c) 1983 The Regents of the University of California. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by the University of California, Berkeley. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #ifndef lint char copyright[] = "@(#) Copyright (c) 1983 The Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#) fingerd.c 5.3 (Berkeley) 11/3/88"; #endif /* not lint */ /* * Finger ID: This version of fingerd has been adjusted to record finger * requests on the system console or in the syslog at priority "auth.notice". * To actually see these messages you need to add a line to /etc/syslog.conf * containing something like: * auth.notice /dev/console * See syslogd(1) and/or syslog.conf(5) for more info. * * 7 Feb 1999 - updated for Linux: Compile with -DLINUX to find the * correct finger command on Linux. * * Eric Myers 3 December 1994 * Department of Physics, University of Michigan, Ann Arbor, MI USA */ #ifndef lint char rcsid[] = "@(#) Hacked to record finger requests in syslog or to console.\n\ @(#) $Revision: 1.6 $ $Date: 1999/02/07 20:02:54 $\n"; #endif /* not lint */ /* * Finger server. */ #include #include /* sockaddr_in, */ #include #include /* * System logging. */ #include #include /* hostent, gethostbyaddr */ #include /* in_addr */ #define AF_INET 2 /* internetwork: UDP, TCP, etc. */ #ifdef _HPUX_SOURCE #define FINGERCMD "/usr/bin/finger" #else #ifdef LINUX #define FINGERCMD "/usr/bin/finger" #else #define FINGERCMD "/usr/ucb/finger" #endif #endif main(argc, argv) int argc; char *argv[]; { register char *sp; char line[512]; struct sockaddr_in sin; int i, p[2], pid, status; FILE *fp; char *av[4]; struct in_addr HostAddr; struct hostent *host; char *HostName; i = sizeof (sin); if (getpeername(0, &sin, &i) < 0) fatal(argv[0], "getpeername"); if (fgets(line, sizeof(line), stdin) == NULL) exit(1); sp = line; av[0] = "finger"; for (i = 1;i<3;) { while (isspace(*sp)) sp++; /* ignore leading whitespace */ if (!*sp) break; if (*sp == '\r') *sp = '\0'; if (*sp == '/' && (sp[1] == 'W' || sp[1] == 'w')) { sp += 2; av[i++] = "-l"; } if (*sp && !isspace(*sp)) { av[i++] = sp; while (*sp && !isspace(*sp)) { if (*sp == '\r') *sp = '\0'; if (*sp == '@') *sp = '\0'; /* no finger relay */ sp++;} *sp = '\0'; } } av[i] = 0; /* * Log the request to syslog as auth.notice. You may have to * add a line to /etc/syslog.conf for this to actually appear * on the console. */ openlog("fingerd", LOG_CONS, LOG_AUTH); HostAddr = sin.sin_addr; /* get peer's IP address */ host = gethostbyaddr((char *)&HostAddr, sizeof(HostAddr), AF_INET); if (host == NULL ) HostName = inet_ntoa(HostAddr); else HostName = host->h_name; syslog(LOG_NOTICE|LOG_AUTH,"from %s: `finger %s`", HostName, line ); /* * Fork into a pipe and run the finger request */ if (pipe(p) < 0) fatal(argv[0], "pipe"); if ((pid = fork()) == 0) { close(p[0]); if (p[1] != 1) { dup2(p[1], 1); close(p[1]); } execv(FINGERCMD, av); _exit(1); } if (pid == -1) fatal(argv[0], "fork"); close(p[1]); /* Copy from the pipe output to stdout */ if ((fp = fdopen(p[0], "r")) == NULL) fatal(argv[0], "fdopen"); while ((i = getc(fp)) != EOF) { if (i == '\n') putchar('\r'); putchar(i); } fclose(fp); while ((i = wait(&status)) != pid && i != -1) ; return(0); } fatal(prog, s) char *prog, *s; { fprintf(stderr, "%s: ", prog); perror(s); exit(1); }