[comp.unix.questions] Finger logging program

c60b-1eq@e260-3e.berkeley.edu (Noam Mendelson) (04/10/91)

Ever since I mentioned that it is possible to log finger attempts I have
received quite a bit of mail requesting source code for such a program.
Unfortunately I don't have to time to mail out a copy of such a program
to every user who requests it, and I don't want to post it since the
program is still in the testing stages and it will not work on some
systems.
If anyone knows of a more generic type program which logs finger attempts,
please post it or refer readers of this newsgroup to the appropriate
FTP site or article #.

+==========================================================================+
| Noam Mendelson   ..!agate!ucbvax!web!c60b-1eq | "I haven't lost my mind, |
| c60b-1eq@web.Berkeley.EDU                     |  it's backed up on tape  |
| University of California at Berkeley          |  somewhere."             |

volpe@camelback.crd.ge.com (Christopher R Volpe) (04/12/91)

In article <1991Apr10.001954.27707@agate.berkeley.edu>,
c60b-1eq@e260-3e.berkeley.edu (Noam Mendelson) writes:
|>If anyone knows of a more generic type program which logs finger attempts,
|>please post it or refer readers of this newsgroup to the appropriate
|>FTP site or article #.
|>
|>+==========================================================================+
|>| Noam Mendelson   ..!agate!ucbvax!web!c60b-1eq | "I haven't lost my mind, |
|>| c60b-1eq@web.Berkeley.EDU                     |  it's backed up on tape  |
|>| University of California at Berkeley          |  somewhere."             |

I hacked one up a while back. It runs on SunOS 4.x. It's a pretty ugly
hack, but it seems to do the job. (It requires that you set up your
.plan file to be a FIFO. (Type "man mknod" to see how.)
======================================================================
#include <sys/types.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <stdio.h>

main()
{ int fd;
  fd_set writefds;
  int i=1;


  while (1) {
  fd=open(".plan",O_WRONLY);
  if (fd!=1) if (dup2(fd,1)== (-1)) fprintf(stderr,"Error on dup\n");

    printf("\nHello! You are the %dth person to finger me on ",i);
    fflush(stdout);
    system("hostname");
    printf("The current date is ");
    fflush(stdout);
    system("date");
    printf("\nHere's some nice trivia for you:\n");
    fflush(stdout);
    system("/usr/games/fortune");
    fflush(stdout);

/* Send me mail indicating the request */
    system("(echo \"You have been fingered on\" `hostname` at `date`; \
             echo \"Relevant process information follows:\"; \
             ((ps -agxu; netstat) | grep finger) ) | mail -s \"Finger
notification\" \
             volpe@stp");

    printf("\nPlease finger me again sometime!\n");
    printf("*****************************************************\n");
    fflush(stdout);
    i++;
  close(fd);close(1);sleep(3);
  }
    
}
              
==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com

volpe@camelback.crd.ge.com (Christopher R Volpe) (04/12/91)

I forgot to mention a couple of things. 
1) You have to be in your home directory when you run that program, because
   it just attempts to open ".plan", not "/path/to/my/home/dir/.plan".
   (Like I said, it was a quick hack :) )
2) The program tries to send mail to *me* when it detects a finger, so 
   edit the source and change "volpe@stp" to "<your-userid>".

==================
Chris Volpe
G.E. Corporate R&D
volpecr@crd.ge.com