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

  1. /* This has functions to read the configuration file */
  2. /* ------------------------------------------------- */
  3.  
  4. #include "headers.h" /* has all important stuff */
  5.  
  6. /* reads client's syslog.conf */
  7. void readSysConf()
  8. {
  9.    int res;
  10.    register int i;
  11.    char readbuf[MAXREADSIZE/4];
  12.  
  13.    if (curlogfd > 0)
  14.    {
  15.       if (debugging == 1) 
  16.       {
  17.          (void)putchar('\n');
  18.          (void)write(dblogfd, "\n", 1);
  19.       }
  20.  
  21.       debug("re-HUPing client's config file..\n\n");
  22.  
  23.       for (i = 0; i <= curlogfd; i++)
  24.       {
  25.          if ((clients[curClient].logs[i].fd <= 0) &&
  26.              (clients[curClient].logs[i].filename == NULL)) continue;
  27.  
  28.          else
  29.          {
  30.             if (clients[curClient].logs[i].fd > 0) 
  31.                close(clients[curClient].logs[i].fd); 
  32.  
  33.             if (clients[curClient].logs[i].filename != NULL)
  34.                free(clients[curClient].logs[i].filename);
  35.  
  36.             memset(&clients[curClient].logs[i], 0, sizeof(struct log));
  37.  
  38.             clients[curClient].logs[i].fd = ERROR;
  39.             clients[curClient].logs[i].filename = NULL;
  40.          }
  41.       }
  42.    }
  43.  
  44.    /* inform client we're ready */
  45.    send_data(clients[curClient].sockfd, "START SYSLOG.CONF OKAY\n");
  46.  
  47.    debug("----- BEGIN PARSE SYSLOG.CONF -----\n\n");
  48.  
  49.    curlogfd = ERROR;
  50.  
  51.    res = seteuid(0);
  52.    if (res == ERROR) 
  53.    {
  54.       error("error with seteuid: %s\n\n", strerror(errno));
  55.       quit(ERROR);
  56.    }
  57.  
  58.    while(1) 
  59.    {      
  60.       memset(readbuf, 0, sizeof(readbuf));
  61.       recv_data(clients[curClient].sockfd, readbuf, sizeof(readbuf)-1, 0);
  62.  
  63.       if (isprint(readbuf[0]) == 0) continue;
  64.       else if (strncmp(readbuf, "END SYSLOG.CONF", 15) == 0) break;
  65.       else
  66.       {
  67.          debug("parsing line:\n%s\n", readbuf);
  68.  
  69.          if (strchr(readbuf, '\n') == NULL) 
  70.          {
  71.             debug("no newline in message.. adding one\n");
  72.             readbuf[sizeof(readbuf)-2] = '\n';
  73.             readbuf[sizeof(readbuf)-1] = '\0';
  74.          }
  75.  
  76.          else
  77.          {
  78.             char *dataptr = readbuf;
  79.             char *dataptr1 = dataptr;
  80.  
  81.             while(1)
  82.             {
  83.                dataptr = dataptr1;
  84.  
  85.                if (isprint((*(strchr(dataptr, '\n') + 1))) != 0)
  86.                {
  87.                   debug("possibly several commands in one line\n");
  88.                   dataptr1 = strchr(dataptr, '\n');
  89.  
  90.                   dataptr1 += 1, parseSysConf(dataptr1);               
  91.                }
  92.  
  93.                else break;
  94.             }
  95.          }
  96.  
  97.          parseSysConf(readbuf);          
  98.       }
  99.    }
  100.  
  101.    res = seteuid(pwd->pw_uid);
  102.    if (res == ERROR) 
  103.    {
  104.       error("error with seteuid: %s\n\n", strerror(errno));
  105.       quit(ERROR);
  106.    }
  107.  
  108.    debug("----- END PARSE SYSLOG.CONF -----\n\n");
  109.  
  110.    send_data(clients[curClient].sockfd, "SUCCESSFUL logging\n");
  111.    printConfig();
  112. }
  113.  
  114.  
  115. /* ------------------------------- */
  116.  
  117.  
  118. /* output what's being logged to where */
  119. void printConfig()
  120. {
  121.    register int i;
  122.  
  123.    for (i = 0; i <= curlogfd; i++)
  124.    {
  125.        if ((clients[curClient].logs[i].filename == NULL) || 
  126.            (clients[curClient].logs[i].fd <= 0)) continue;
  127.  
  128.        if ((clients[curClient].logs[i].facility != ALL)  && 
  129.            (clients[curClient].logs[i].priority.priority != ALL) &&
  130.            (clients[curClient].logs[i].priority.priority != NONE))
  131.        {
  132.           debug("%s, for %s.%s\n", clients[curClient].logs[i].filename, 
  133.                 facValToName(clients[curClient].logs[i].facility),
  134.                 priValToName(clients[curClient].logs[i].priority.priority));
  135.        }
  136.  
  137.        else
  138.        {
  139.           if (clients[curClient].logs[i].facility == ALL)
  140.           {
  141.              if (clients[curClient].logs[i].priority.priority == ALL)
  142.                 debug("%s, for *.*\n", clients[curClient].logs[i].filename);
  143.  
  144.              else if (clients[curClient].logs[i].priority.priority == NONE)
  145.                 debug("%s, for *.none\n", clients[curClient].logs[i].filename);
  146.  
  147.              else
  148.                 debug("%s, for *.%s\n", clients[curClient].logs[i].filename, 
  149.                    priValToName(clients[curClient].logs[i].priority.priority));
  150.           }
  151.  
  152.           else if (clients[curClient].logs[i].priority.priority == ALL)
  153.              debug("%s for %s.*\n", clients[curClient].logs[i].filename, 
  154.                    facValToName(clients[curClient].logs[i].facility));
  155.  
  156.           else if (clients[curClient].logs[i].priority.priority == NONE)
  157.              debug("%s, for %s.none\n", clients[curClient].logs[i].filename, 
  158.                    facValToName(clients[curClient].logs[i].facility));
  159.  
  160.        }
  161.    }
  162.  
  163.    if (debugging == 1)
  164.    {
  165.       (void)putchar('\n');
  166.       (void)write(dblogfd, "\n", 1);
  167.    }
  168. }
  169.