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

  1. #include "headers.h" /* has all important stuff */
  2.  
  3. /* this file does the authentication stuff */
  4.  
  5. /* authenticate client */
  6. void authClient(char *str, const int len)
  7. {
  8.    int count = 0;  /* used to prevent overflows         */
  9.  
  10.    long res;       /* result of new challenge           */
  11.    long chal;      /* will contain the random challenge */
  12.  
  13.    char *keyptr;   /* pointer into key                  */
  14.    char *dataptr;  /* pointer into readbuf              */
  15.  
  16.    char key[32];   /* will hold their final value       */
  17.    char readbuf[MAXREADSIZE];
  18.  
  19.    keyptr = key, dataptr = readbuf;
  20.  
  21.    memset(key, 0, sizeof(key));
  22.    memset(readbuf, 0, sizeof(readbuf));
  23.  
  24.    strncpy(readbuf, str, len);
  25.  
  26.    getID(readbuf);  /* do some stuff with the client ID */
  27.                     /* will set the client.ID           */
  28.  
  29.    if (debugging == 1)
  30.    {
  31.       (void)putchar('\n');
  32.       (void)write(dblogfd, "\n", 1);
  33.    }
  34.  
  35.    /* generate a random challenge */
  36.    chal = random();
  37.  
  38.    debug("sending random challenge to client..\n");
  39.  
  40.    /* send client a challenge (with ID1) */
  41.    send_data((clients[curClient]).sockfd, "VERIFY %ld\n", chal);
  42.  
  43.    timeout = 0, errors = 0;
  44.  
  45.    memset(readbuf, 0, sizeof(readbuf)); /* [re]clear buffer */
  46.    recv_data((clients[curClient]).sockfd, readbuf, sizeof(readbuf)-1, 0);
  47.  
  48.    (void)alarm(0);
  49.  
  50.    if ((timeout == 1) || (errors == 1) || (strncmp(readbuf, "VERIFY", 6) != 0))
  51.    {
  52.       errors = 1;
  53.       return;
  54.    }
  55.  
  56.    dataptr = strstr(readbuf, "VERIFY");
  57.    dataptr += 7; /* skip "VERIFY " */
  58.    
  59.    count = 0;
  60.    while ((*dataptr) && (isprint(*dataptr) != 0) && 
  61.           (count < (int)sizeof(key)))
  62.    {
  63.       *keyptr++ = *dataptr++;
  64.       count++;
  65.    }
  66.  
  67.    res = atol(key);
  68.    if (res != chal)
  69.    {
  70.       if (debugging == 1)
  71.       {
  72.          putchar('\n');
  73.          (void)write(dblogfd, "\n", 1);
  74.       }
  75.  
  76.       debug("client returned invalid verification #..\n");
  77.  
  78.       signal(SIGPIPE, SIG_IGN);
  79.  
  80.       send_data((clients[curClient]).sockfd, "ERROR: %s\n", VERERROR);
  81.       (void)sleep(MAXPAUSE); /* give them time to handle this */
  82.  
  83.       errors = 1;
  84.       return;
  85.    }
  86.  
  87.    else
  88.    {
  89.       /* -- now authenticated -- */
  90.       if (debugging == 1)
  91.       {
  92.          putchar('\n');
  93.          (void)write(dblogfd, "\n", 1);
  94.       }
  95.  
  96.       debug("client successfully verified...\n"); 
  97.       send_data((clients[curClient]).sockfd, "SUCCESSFUL verification\n");
  98.    }
  99. }
  100.  
  101.  
  102. /* ----------------------- */
  103.