Logo Search packages:      
Sourcecode: nbsmtp version File versions  Download package

void log_msg ( int  priority,
char *  format,
  ... 
)

Logs a message to syslog, checks for debug if the priority is LOG_DEBUG.

Parameters:
[in] priority An int with the message priority (LOG_INFO,LOG_DEBUG,LOG_ERR...)
[in] format A pointer to the message format
[in] ... Variable list.

Definition at line 107 of file util.c.

References debug.

Referenced by fileconfig_parse(), get_socket(), main(), nbsmtp_auth(), nbsmtp_data(), nbsmtp_ehlo(), nbsmtp_header(), nbsmtp_helo(), nbsmtp_rcpts(), parse_mail(), parse_options(), send_mail(), smtp_read(), and smtp_write().

{
      static int mask_next = 0;
      char buffer[BUFSIZ];
      char *p;
      va_list list;

      /*
       * If we are receiving a LOG_DEBUG message, we check for debug
       * to write it.
       */
      if ((priority==LOG_DEBUG) && (debug==0))
      {
            return;
      }

      /*
       * Copy in buffer the result of parsing format with list
       * up to BUFSIZ bytes
       */
      va_start(list,format);
      vsnprintf(buffer,BUFSIZ,format,list);
      va_end(list);

      /*
       * Strip \r and \n so we don't mess syslog
       */
      if ((p = strchr(buffer,'\r')) != NULL)
      {
            *p = '\0';
      }

      if ((p = strchr(buffer,'\n')) != NULL)
      {
            *p = '\0';
      }

      /*
       * Remove passwords (they are only sent with debug>0)
       */
      if (debug>0 && debug<3)
      {
            if (mask_next==1)
            {
                  p = NULL;

                  if (buffer[2]=='>')
                  {
                        /* Skip the ' ' */
                        p = strchr(buffer,' ')+1;
                        mask_next = 0;
                  }
            }
            else if ((p = strstr(buffer,"AUTH PLAIN ")) != NULL)
            {
                  p += strlen("AUTH PLAIN ");
            }
            else if ((p = strstr(buffer,"AUTH LOGIN ")) != NULL)
            {
                  p += strlen("AUTH LOGIN ");
                  mask_next = 1;
            }
            else
            {
                  p = NULL;
            }

            if (p!=NULL)
            {
                  int k;

                  for ( k = 0 ; k < 10 && *p ; k++ , p++ )
                  {
                        *p='X';
                  }

                  *p = (char)NULL;
            }
      }

      if (debug==0 || debug==1)
      {
            openlog("nbSMTP", LOG_PID, LOG_MAIL);
            syslog(priority,"%s",buffer);
            closelog();
      }
      else /* if (debug==2) */
      {
            fprintf(stderr,"%s\n",buffer);
      }
}


Generated by  Doxygen 1.6.0   Back to index