home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / sectools / SRS / client / src / auth.c next >
Encoding:
C/C++ Source or Header  |  2000-01-12  |  1.7 KB  |  69 lines

  1. /* Do authentication with server */
  2. /* ----------------------------- */
  3.  
  4. #include "headers.h" /* all important stuff */
  5.  
  6. /* get challenge, and respond */
  7. void doAuth()
  8. {
  9.    long res;        /* final result for our authentication algorithm */
  10.    int count = 0;  /* prevent overflows */
  11.  
  12.    char *dataptr;  /* pointer to challenge from server */
  13.    char *chalptr;  /* points to actual challenge       */
  14.  
  15.    char chalval[32]; 
  16.    char readbuf[MAXREADSIZE];
  17.  
  18.    chalptr = chalval;
  19.    memset(chalval, 0, sizeof(chalval));
  20.  
  21.    if (debugging == 1)
  22.    {
  23.       (void)putchar('\n');
  24.       (void)write(dblogfd, "\n", 1);
  25.    }
  26.  
  27.    recv_data(readbuf, sizeof(readbuf));
  28.    if (strncmp(readbuf, "VERIFY", 6) != 0)
  29.    {
  30.       error("error: was expecting VERIFY.. restarting\n\n");
  31.  
  32.       if (gotInfoServ == 1) longjmp(reconnect, 1);
  33.       else longjmp(infoconn, 1);
  34.    }
  35.  
  36.    dataptr = strstr(readbuf, "VERIFY");
  37.    dataptr += 7; /* skip "VERIFY " */
  38.  
  39.    count = 0;
  40.    while ((*dataptr) && (*dataptr != ' ') &&
  41.           (isprint((int)*dataptr) != 0) && (count < (int)sizeof(chalval))) 
  42.    {
  43.       *chalptr++ = *dataptr++;
  44.       count++;
  45.    }
  46.  
  47.    res = atol(chalval);
  48.    send_data("VERIFY %ld\n", res);
  49.  
  50.    /* loop until server tells us success or failure */
  51.    recv_data(readbuf, sizeof(readbuf));
  52.  
  53.    if (strncmp(readbuf, "SUCCESSFUL verification", 23) == 0)
  54.       (void)printf("%cerified ourselves successfully\n\n",
  55.                   (debugging != 1 ? 'V' : 'v'));
  56.  
  57.    else
  58.    {
  59.       error("error: expecting \"SUCCESSFUL verification\".."
  60.             "received message was: %s\n%c", readbuf,
  61.             (strchr(readbuf, '\n') == NULL ? '\n' : '\0'));
  62.  
  63.       debug("now restarting\n");
  64.  
  65.       if (gotInfoServ == 1) longjmp(reconnect, 1);
  66.       else longjmp(infoconn, 1);
  67.    }
  68. }
  69.