Release bumped to "gts4".
[tac_plus.git] / report.c
index a458617..d46abfd 100644 (file)
--- a/report.c
+++ b/report.c
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (c) 1995-1998 by Cisco systems, Inc.
 
    Permission to use, copy, modify, and distribute this software for
    FITNESS FOR A PARTICULAR PURPOSE.
 */
 
+
 #include "tac_plus.h"
-#include <stdio.h>
 
-#ifdef AIX
+#include <stdio.h>
 #include <sys/types.h>
-#else
 #include <time.h>
+#include <sys/stat.h>
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
 #endif
-
-#ifdef __STDC__
-#include <stdarg.h>            /* ANSI C, variable length args */
-#else
-#include <varargs.h>           /* has 'vararg' definitions */
+#include <string.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
 #endif
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
+#ifdef HAVE_SYS_SYSLOG_H
+#include <sys/syslog.h>
+#endif
+
+#include "report.h"
+#include "utils.h"
+#include "main.h"
+
+
+/* Configurable:
+ */
+
+#define LOGFILE_DEFAULT "/var/log/tac_plus.log"
+
 
 FILE *ostream = NULL;
 
@@ -45,21 +62,30 @@ char *logfile = LOGFILE_DEFAULT;
  * All other priorities are always logged to syslog.
  */
 
+void report TAC_ARGS((int priority, const char *fmt, ...)) G_GNUC_PRINTF(2, 3);
+
 #ifdef __STDC__
+
+#include <stdarg.h>            /* ANSI C, variable length args */
 void
-report(int priority, char *fmt,...)
-#else
+report(int priority, const char *fmt,...)
+
+#else /* __STDC__ */
+
+#include <varargs.h>           /* has 'vararg' definitions */
 /* VARARGS2 */
 void
 report(priority, fmt, va_alist)
 int priority;
-char *fmt;
+const char *fmt;
 va_dcl                         /* no terminating semi-colon */
-#endif
+
+#endif /* __STDC__ */
 {
     char msg[255];             /* temporary string */
-    char *fp, *bufp, *charp;
-    int len, m, i, n;
+    const char *fp;
+    char *bufp, *charp = NULL /* GCC paranoia */;
+    int len, m = 0 /* GCC paranoia */, i, n;
     char digits[16];
     va_list ap;
 
@@ -119,8 +145,11 @@ va_dcl                             /* no terminating semi-colon */
            m = strlen(digits);
            charp = digits;
            break;
+       default:
+           syslog(LOG_ERR, "Unknown format character '%c', ignoring it", *fp);
+           continue;
        }
-           
+
        if ((len + m + 1) >= n) {
            break;
        }
@@ -143,7 +172,7 @@ va_dcl                              /* no terminating semi-colon */
 
     if (console) {
        extern int errno;
-       
+
        if (!ostream)
            ostream = fopen("/dev/console", "w");
 
@@ -152,7 +181,7 @@ va_dcl                              /* no terminating semi-colon */
                fprintf(ostream, "Error ");
            fprintf(ostream, "%s\n", msg);
        }
-       else 
+       else
            syslog(LOG_ERR, "Cannot open /dev/console errno=%d", errno);
     }
 
@@ -167,7 +196,7 @@ va_dcl                              /* no terminating semi-colon */
 
            ct[24] = '\0';
            tac_lockfd(logfile, logfd);
-           sprintf(buf, "%s [%d]: ", ct, getpid());
+           sprintf(buf, "%s [%d]: ", ct, (int) getpid());
            write(logfd, buf, strlen(buf));
            if (priority == LOG_ERR)
                write(logfd, "Error ", 6);
@@ -190,6 +219,8 @@ va_dcl                              /* no terminating semi-colon */
        syslog(priority, "%s", msg);
 }
 
+void report_hex TAC_ARGS((int priority, u_char *p, int len));
+
 /* format a hex dump for syslog */
 void
 report_hex(priority, p, len)
@@ -200,7 +231,7 @@ int len;
     char digit[10];
     int buflen;
     int i;
-    
+
     if (len <= 0)
        return;
 
@@ -225,6 +256,8 @@ int len;
 }
 
 
+void report_string TAC_ARGS((int priority, u_char *p, int len));
+
 /* format a non-null terminated string for syslog */
 void
 report_string(priority, p, len)
@@ -251,10 +284,11 @@ int len;
     report(priority, "%s", buf);
 }
 
+void tac_regerror TAC_ARGS((const char *s));
+
 void
-regerror(s)
-char *s;
+tac_regerror(s)
+const char *s;
 {
     report(LOG_ERR, "in regular expression %s", s);
 }
-