"Fossies" - the Fresh Open Source Software Archive

Member "chkrootkit-0.57/chkwtmp.c" (16 Jun 2022, 2299 Bytes) of package /linux/misc/chkrootkit-0.57.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "chkwtmp.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2    Copyright (c) DFN-CERT, Univ. of Hamburg 1994
    3 
    4    Univ. Hamburg, Dept. of Computer Science
    5    DFN-CERT
    6    Vogt-Koelln-Strasse 30
    7    22527 Hamburg
    8    Germany
    9 
   10    02/20/97 - Minimal changes for Linux/FreeBSD port.
   11    Nelson Murilo, nelson@pangeia.com.br
   12    09/07/00 - Ports for Solaris
   13    Andre Gustavo <gustavo@anita.visualnet.com.br>
   14    12/15/00 - Add -f option
   15    Nelson Murilo, nelson@pangeia.com.br
   16    07/08/04 - fix del counter value (Thanks to Dietrich Raisin)
   17    Nelson Murilo, nelson@pangeia.com.br
   18    09/12/05 - fix Segfault (Thanks to Jérémie Andréi)
   19    Nelson Murilo, nelson@pangeia.com.br
   20 */
   21 
   22 #if __FreeBSD__ > 9 
   23 int main () { return 0; } 
   24 #else
   25 #include <stdio.h>
   26 #include <stdlib.h>
   27 #include <unistd.h>
   28 #include <string.h>
   29 #include <utmp.h>
   30 #include <time.h>
   31 #include <sys/time.h>
   32 #include <sys/file.h>
   33 #ifdef SOLARIS2
   34 #include <fcntl.h>
   35 #endif
   36 
   37 #ifdef __FreeBSD__
   38 #define WTMP_FILENAME "/var/log/wtmp"
   39 #else
   40 #ifndef WTMP_FILENAME
   41 #define WTMP_FILENAME "/var/adm/wtmp"
   42 #endif
   43 #endif
   44 
   45 void printit(counter, start, end)
   46 int counter;
   47 long start,end;
   48 {
   49     char        buffer[30];
   50 
   51     printf("%d deletion(s) between ", counter);
   52     strncpy(buffer, ctime( (time_t *) &start), 30);
   53     buffer[24]='\0';
   54     printf("%s and %s", buffer, ctime( (time_t *) &end));
   55 }
   56 
   57 
   58 int main(int argc, char*argv[]) {
   59     int     filehandle;
   60     struct utmp utmp_ent;
   61     struct timeval  mytime;
   62     struct timezone dummy;
   63     long        start_time, act_time;
   64     int     del_counter, t_del;
   65         char wtmpfile[128];
   66 
   67     del_counter=t_del=0;
   68     start_time=0;
   69 
   70     gettimeofday(&mytime, &dummy);
   71        act_time=mytime.tv_sec;
   72        wtmpfile[127]='\0';
   73        memcpy(wtmpfile, WTMP_FILENAME, 127);
   74        if ( argc == 3 && !memcmp("-f", argv[1], 2) && *argv[2])
   75           memcpy(wtmpfile, argv[2], 127);
   76 
   77     if ((filehandle=open(wtmpfile,O_RDONLY)) < 0) {
   78         fprintf(stderr, "unable to open wtmp-file %s\n", wtmpfile);
   79         return(2);
   80     }
   81 
   82     while (read (filehandle, (char *) &utmp_ent, sizeof (struct utmp)) > 0) {
   83         if (utmp_ent.ut_time == 0)
   84             del_counter++;
   85         else {
   86             if (del_counter) {
   87                 printit(del_counter, start_time,
   88                     utmp_ent.ut_time);
   89                 t_del++;
   90                 del_counter=0;
   91             }
   92             start_time=utmp_ent.ut_time;
   93         }
   94     }
   95     close(filehandle);
   96     if (del_counter)
   97        printit(del_counter, start_time, act_time);
   98         exit((int) t_del+del_counter);
   99 }
  100 #endif