/*
	Original source : ponk
	Modified source : cl0se

	This little prog doesn't do much except mimic the finger
	command with a couple extra features.  It doesn't do
	everything the finger command does, but does show how
	finger works (more or less) so if you're interested in
	this sort of systems programming, here's something to 
	look at.
*/ 

#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <stdio.h>
#include <pwd.h>
#include <lastlog.h>

main (int argc, char **argv)
{
  
  struct passwd *ptr;
  struct stat *buf;
  char *path="/usr/spool/mail/";
  char *mail,*lastread;
  buf = (struct stat *)malloc(sizeof(struct stat));
  
  if(argc < 2)
    {
      printf("Usage: %s login_name \n",argv[0]);
      exit(0);
    }
  
  if((ptr = getpwnam(argv[1])) == NULL)
    {
      printf("Login name %s not found.\n",argv[1]);
      exit(0);
     }  
  
  strcat(path,argv[1]); 
  
  if((stat(path,buf)) == -1)
    {
      printf("Path is %s\n",path);
    }
  lastread=(asctime(localtime(&buf->st_atime)));  
  
  printf("\nUsername: %s",ptr->pw_name);
  printf("\nPassword: %s",ptr->pw_passwd);
  printf("\n   Shell: %s\t",ptr->pw_shell);
  printf("\nHome dir: %s",ptr->pw_dir);
  printf("\nMail last read: %s\n",lastread); 

  exit(0); 
}
