home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / crackunx.txt / Sources / crack-supp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-25  |  3.3 KB  |  177 lines

  1. /*
  2.  * This program is copyright Alec Muffett 1991 except for some portions of
  3.  * code in "crack-fcrypt.c" which are copyright Robert Baldwin, Icarus Sparry
  4.  * and Alec Muffett.  The author(s) disclaims all responsibility or liability
  5.  * with respect to it's usage or its effect upon hardware or computer
  6.  * systems, and maintain copyright as set out in the "LICENCE" document which
  7.  * accompanies distributions of Crack v4.0 and upwards.
  8.  */
  9.  
  10. #include "crack.h"
  11.  
  12. #ifdef CRACK_UNAME
  13. #ifndef AMIGA
  14. #include <sys/utsname.h>
  15. int
  16. gethostname (name, namelen)
  17.     char *name;
  18.     int namelen;
  19. {
  20.     struct utsname uts;
  21.     if (uname (&uts))
  22.     {
  23.     return (-1);
  24.     }
  25.     strncpy (name, uts.nodename, namelen - 1);
  26.     return (0);
  27. }
  28. #else
  29. int
  30. gethostname (name, namelen)
  31.     char *name;
  32.     int namelen;
  33. {
  34.     strncpy (name, "dougal", namelen);
  35.     return (0);
  36. }
  37. #endif                /* AMIGA */
  38. #endif                /* CRACK_UNAME */
  39.  
  40. /* log anything to datafile. */
  41.  
  42. void
  43. Log (fmt, a, b, c, d, e, f, g, h, i, j)
  44.     char *fmt;
  45.     long int a, b, c, d, e, f, g, h, i, j;
  46. {
  47.     long t;
  48.  
  49.     time (&t);
  50.     printf ("pwc: %-15.15s ", ctime (&t) + 4);
  51.     printf (fmt, a, b, c, d, e, f, g, h, i, j);
  52.     fflush (stdout);
  53. }
  54. /* print a guess, giving a single place to mod where necessary */
  55.  
  56. void
  57. PrintGuess (eptr, guess)
  58.     register struct USER *eptr;
  59.     char *guess;
  60. {
  61.     eptr -> done = 1;
  62.     eptr -> passwd_txt = Clone (guess);    /* ESSENTIAL to FeedBack() */
  63.  
  64.     if (!eptr -> passwd_txt)
  65.     {
  66.     eptr -> passwd_txt = "<Ran out of memory logging this password>";
  67.     }
  68.     Log ("Guessed %s%s (%s in %s) [%s] %s\n",
  69.      (eptr -> passwd.pw_uid ? "" : "ROOT PASSWORD "),
  70.      eptr -> passwd.pw_name,
  71.      eptr -> passwd.pw_shell,
  72.      eptr -> filename,
  73.      guess,
  74.      eptr -> passwd.pw_passwd);
  75.  
  76.     if (mail_bool)
  77.     {
  78.     char dobuff[STRINGSIZE];
  79.  
  80.     sprintf (dobuff, "%s %s", nastygram, eptr -> passwd.pw_name);
  81.     system (dobuff);
  82.     }
  83. }
  84.  
  85.  
  86. /* write a pointfile out */
  87.  
  88. int
  89. SetPoint (dict, rule, usernum, username)
  90.     char *dict;
  91.     char *rule;
  92.     int usernum;
  93.     char *username;
  94. {
  95.     FILE *fp;
  96.     long t;
  97.  
  98.     if (!(fp = fopen (pointfile, "w")))
  99.     {
  100.     perror (pointfile);
  101.     return (-1);
  102.     }
  103.     time (&t);
  104.  
  105.     fprintf (fp, "host=%s pid=%d pointtime=%s", this_hostname, pid, ctime (&t));
  106.     fprintf (fp, "%s\n", this_hostname);
  107.     fprintf (fp, "%s\n", dict);
  108.     fprintf (fp, "%s\n", rule);
  109.     fprintf (fp, "%d\n", usernum);
  110.     fprintf (fp, "%s\n", username);
  111.  
  112.     fclose (fp);
  113.  
  114.     return (0);
  115. }
  116. /* read a pointfile in... */
  117.  
  118. int
  119. GetPoint (pf)
  120.     char *pf;
  121. {
  122.     FILE *fp;
  123.     char buffer[STRINGSIZE];
  124.  
  125.     if (!(fp = fopen (pf, "r")))
  126.     {
  127.     perror (pf);
  128.     return (-1);
  129.     }
  130.     /* junk */
  131.     if (!fgets (buffer, STRINGSIZE, fp))
  132.     {
  133.     return (-2);
  134.     }
  135.     /* hostname */
  136.     if (!fgets (old_hostname, STRINGSIZE, fp))
  137.     {
  138.     return (-3);
  139.     }
  140.     /* dictname */
  141.     if (!fgets (old_dictname, STRINGSIZE, fp))
  142.     {
  143.     return (-4);
  144.     }
  145.     /* rule */
  146.     if (!fgets (old_rule, STRINGSIZE, fp))
  147.     {
  148.     return (-5);
  149.     }
  150.     /* usernum */
  151.     if (!fgets (buffer, STRINGSIZE, fp))
  152.     {
  153.     return (-6);
  154.     }
  155.     /* username */
  156.     if (!fgets (old_username, STRINGSIZE, fp))
  157.     {
  158.     return (-7);
  159.     }
  160.     Trim (old_hostname);
  161.  
  162.     if (strcmp (old_hostname, this_hostname))
  163.     {
  164.     return (-8);
  165.     }
  166.     Trim (old_dictname);
  167.     Trim (old_rule);
  168.  
  169.     old_usernum = atoi (buffer);
  170.  
  171.     Trim (old_username);
  172.  
  173.     fclose (fp);
  174.  
  175.     return (0);
  176. }
  177.