A Way to Catch Peepers
by Alien X
Here is a nice little C program for those who use UNIXes with Internet capabilities. The function of the program is to let you know when someone tries to Finger you via the finger command. When a user Fingers you, the program will display the Finger information as normal, but will also send mail to you indicating who the busybody was so that you can keep tabs on who's so interested in you. It accomplishes this by converting your .plan into a named pipe (see manual page on mknod on your UNIX system).
As the program stands, the output is an exact duplicate of what a normal, finger command would produce, however modification is possible if you wish to output some other information to the user.
Example:
printf("It is currently: "); system("date"); /* output the system date */ fflush(stdout); /* flush the output */You can insert this in the area of the: system("cat .plan");
Just remember to flush the stdout after each command.
Also, while the source indicates that you should only have to run peep once, sometime confused operators will kill jobs they don't understand so it's a safe bet to check once in a while by finger yourself. Also, running multiple copies of peep in the background can raise hell when someone Fingers you (i.e., multiple mail messages and such).
This source was originally obtained from volpecr@crd.ge.com (Christopher R. Volpe), and was hacked (and rehacked!) to run on Ultrix by shedevil@leland.stanford.edu.
You must already have a .plan file before proceeding. You must edit the following file, and where you see the term username@machine substitute your own email address.
Do the following commands at your system prompt:
$ cd ~ # Backup your old .plan $ mv .plan .plan.bak # Make a FIFO named .plan $ mknod .plan p # Check it $ ls -l .plan prw-rw-r-- 1 user user 0 Feb 9 02:09 .plan # Compile it $ cc peep.c -o peep # To run peep: $ peep &Note: Do not run peep and unless you have already checked and you are sure it is not already running. The easiest way is to finger yourself and see if it's working... Because peep & tells the system to keep it running in the background, it will stay running even when you log out and back in. So it's rare that you will need to start it up again.
#include <sys/types.h> #include <sys/file.h> #include <setjmp.h> #include <signal.h> #include <sys/uio.h> #include <stdio.h> sigjmp_buf start; void handler(sig, code, scp, addr) int sig, code; struct sigcontext *scp; char *addr; { close(1); longjmp(start, 0); } main() { int fd; fd_set writefds; setjmp(start); signal(SIGHUP.handler); signal(SIGINT, handler); signal(SIGQUIT, handler); signal(SIGPIPE, handler); while (1) { fd = open(".plan", O_WRONLY); if (fd != 1) if (dup2(fd, 1) == (-1)) fprintf(stderr, "Error on dup\n"); system("cat .plan.bak"); fflush(stdout); /* Send me mail indicating the request */ system ("(echo \"You have been fingered on `hostname` at `date`; echo Relevant process information follows:; `netstat -an | grep -i finger`\" | mail -s Finger-Alert username@machine"); fflush(stdout); close(fd); close(1); sleep(3); } }Code: peep.c