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

  1. #include "headers.h" /* has all the important stuff */
  2.  
  3. /* function to output debugging information */
  4. void debug(char *fmt, ...)
  5. {
  6.    const int headlen = strlen("[ERROR (client XXXX [X])]: ") + 1;
  7.  
  8.    va_list args;
  9.  
  10.    char debugbuf[MAXREADSIZE];
  11.    char bigbuf[MAXREADSIZE + headlen];
  12.  
  13.    if (debugging != 1) return;
  14.  
  15.    memset(bigbuf, 0, sizeof(bigbuf));
  16.    memset(debugbuf, 0, sizeof(debugbuf));
  17.  
  18.    va_start(args, fmt);
  19.    (void)vsnprintf(debugbuf, sizeof(debugbuf) - headlen, fmt, args);
  20.    va_end(args);
  21.  
  22.    if (debugging == 1)
  23.    {
  24.       if (strstr(debugbuf, "ERROR") == NULL)
  25.       {
  26.          if ((curClient >= 0) && (clients[curClient].ID > 0) &&
  27.              (clients[curClient].ID <= 9999))
  28.          {
  29.             if (clients[curClient].numSubIDs > 0)
  30.             {
  31.                printf("[DEBUG (client %04d [%d])]: %s", clients[curClient].ID, 
  32.                       clients[curClient].numSubIDs, debugbuf);
  33.  
  34.                if (dblogfd <= 0) return;
  35.  
  36.                snprintf(bigbuf, sizeof(bigbuf)-1, 
  37.                         "[DEBUG (client %04d [%d])]: %s", 
  38.                         clients[curClient].ID, clients[curClient].numSubIDs, 
  39.                         debugbuf);
  40.  
  41.                (void)write(dblogfd, bigbuf, strlen(bigbuf));
  42.  
  43.             }
  44.  
  45.             else
  46.             {
  47.                printf("[DEBUG (client %04d)]: %s", clients[curClient].ID, 
  48.                       debugbuf);
  49.  
  50.                if (dblogfd <= 0) return;
  51.  
  52.                snprintf(bigbuf, sizeof(bigbuf) - 1, 
  53.                         "[DEBUG (client %04d)]: %s", clients[curClient].ID, 
  54.                         debugbuf);
  55.  
  56.                (void)write(dblogfd, bigbuf, strlen(bigbuf));
  57.             }
  58.          }
  59.  
  60.          else
  61.          {
  62.             printf("[DEBUG (pid %d)]: %s", getpid(), debugbuf);
  63.  
  64.             if (dblogfd <= 0) return;
  65.  
  66.             snprintf(bigbuf, sizeof(bigbuf)-1, "[DEBUG (pid %d)]: %s", 
  67.                      getpid(), debugbuf);
  68.  
  69.             (void)write(dblogfd, bigbuf, strlen(bigbuf));
  70.          }
  71.       }
  72.  
  73.       else
  74.       {
  75.          printf("%s", debugbuf);
  76.  
  77.          if (dblogfd <= 0) return;
  78.          (void)write(dblogfd, debugbuf, strlen(debugbuf));
  79.       }
  80.    }
  81. }
  82.