/*

Author	: Premson P. R.
Desc	: Fetch account information using audit ID

*/

#include <stdlib.h>
#include <sys/types.h>
#include <stdio.h>
#include <sys/security.h>
#include <prot.h>
#include <sys/audit.h>
#include <sys/syscall.h>

void main (argc, argv)
int        argc;
char      *argv[];
{

   if (argc < 2) {
   printf("Author : Premson P R\n");
   printf("Usage  : usrinfo [username]\n");
   } else {

   struct es_passwd  *acct;
   time_t expire_time;
   time_t expire_date;
   uid_t myuid;
   int cntlflag;
   char buf[AUDIT_MASK_LEN];
   char prem[100];



   /*--- Standard initialization ---*/

   set_auth_parameters(argc, argv);
   initprivs();

   /*--- fetch account information using audit ID ---*/

   myuid = getluid();

   if (acct = getespwnam(argv[1]))
   {
   	printf("Username	\t   : %s \n", acct->ufld->fd_name);
	printf("Getluid	\t\t   : %d \n", myuid);
	printf("Last Successful Attempt    : %s \n", acct->ufld->fd_suctty);
	printf("Last Unsuccessful Attempt  : %s \n", acct->ufld->fd_unsuctty);

	bzero ( buf, sizeof(buf) );
	A_SITEMASK_SET(buf, LOGIN, 1, 1);

	if ((cntlflag = audcntl(SET_PROC_AMASK, buf, AUDIT_MASK_LEN, 0, 0, 0)) == -1) {
   	perror("audcntl");
	strcpy(prem,buf);
	printf("PREM \t\t      : %s \n", prem);
	printf("AUDCNTL \t\t   : %d \n", cntlflag); } else {
	strcpy(prem,buf);
	printf("PREM ELSE \t\t   : %s \n", prem);
	printf("AUDCNTL ELSE\t\t   : %d \n", cntlflag); }

//	if ((cntlflag = audcntl(GET_PROC_AMASK,NULL, 0, 0, 0, 0)) == -1) {
	//printf("AUDCNTL : %d \n", audcntl); }
	//else {
   }
   else {
   printf("No Such User ! \n");
   exit(1); }
   }
}
