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

  1. #include "headers.h" /* has all the important stuff */
  2.  
  3. /* function to report an error to the error file */
  4. void error(char *fmt, ...)
  5. {
  6.    int res = 0;
  7.    va_list args;
  8.  
  9.    time_t tm;
  10.  
  11.    char errmsg[MAXREADSIZE];
  12.    char errbuf[MAXREADSIZE];
  13.  
  14.    int headlen = strlen("[ERROR (client XXXX [X]) - "
  15.                         "XXX XXX XX XX:XX:XX XXXX]: ");
  16.  
  17.    tm = time(NULL);
  18.  
  19.    memset(errmsg, 0, sizeof(errmsg));
  20.    memset(errbuf, 0, sizeof(errbuf));
  21.  
  22.    va_start(args, fmt);
  23.    (void)vsnprintf(errmsg, sizeof(errmsg) - headlen - 1, fmt, args);
  24.    va_end(args);
  25.  
  26.    errmsg[sizeof(errmsg)-1] = '\0';
  27.  
  28.    if ((curClient < 0) || (clients[curClient].ID <= 0) ||
  29.        (clients[curClient].ID > 9999))
  30.       (void)sprintf(errbuf, "[ERROR (pid %d) - %s", getpid(), ctime(&tm));
  31.  
  32.    else
  33.    {
  34.       if (clients[curClient].numSubIDs > 0)
  35.          (void)sprintf(errbuf, "[ERROR (client %04d [%d]) - %s", 
  36.                        clients[curClient].ID, clients[curClient].numSubIDs,
  37.                        ctime(&tm));
  38.  
  39.       else
  40.          (void)sprintf(errbuf, "[ERROR (client %04d) - %s", 
  41.                        clients[curClient].ID, ctime(&tm));
  42.    }
  43.  
  44.    errbuf[strlen(errbuf)-1] = '\0';
  45.    (void)strcat(errbuf, "]:\n");
  46.  
  47.    errbuf[sizeof(errbuf)-2] = '\n';
  48.    errbuf[sizeof(errbuf)-1] = '\0';
  49.    (void)strcat(errbuf, errmsg);
  50.  
  51.    res = write(errlogfd, errbuf, strlen(errbuf));
  52.    if ((res == 0) || ((res == ERROR) && (errno > 0)))
  53.    {
  54.       (void)fprintf(stderr, "unable to write to the error log: %s\n\n",
  55.                     strerror(errno));
  56.  
  57.       exit(ERROR);
  58.    }
  59.  
  60.    if (debugging == 1)
  61.    {
  62.       if ((curClient < 0) || (clients[curClient].ID <= 0) ||
  63.           (clients[curClient].ID > 9999))
  64.          debug("[ERROR (pid %d)]: %s", getpid(), errmsg);
  65.  
  66.       else
  67.       {
  68.          if (clients[curClient].numSubIDs > 0)
  69.             (void)sprintf(errbuf, "[ERROR (client %04d [%d])]: %s\n", 
  70.                           clients[curClient].ID, clients[curClient].numSubIDs, 
  71.                           errmsg);
  72.  
  73.          else
  74.             (void)sprintf(errbuf, "[ERROR (client %04d)]: %s\n", 
  75.                           clients[curClient].ID, errmsg);
  76.       }
  77.    }
  78. }
  79.