]> granicus.if.org Git - sudo/commitdiff
add WRAP_LOG and HOST_IN_LOG
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 10 Sep 1998 22:51:09 +0000 (22:51 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 10 Sep 1998 22:51:09 +0000 (22:51 +0000)
logging.c

index 2725556a7acafd9af3236357152481bbdfb0b217..9d32acca5dbee03ddea58ed7a070fb5038aaba36 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -87,12 +87,6 @@ static void syslog_wrapper   __P((int, char *, char *, char *));
 static char *logline;
 extern int errorlineno;
 
-/*
- * length of syslog-like header info used for mail and file logs
- * is len("Mon MM HH:MM:SS : username : ")
- */
-#define LOG_HEADER_LEN         29
-
 #ifdef BROKEN_SYSLOG
 #define MAXSYSLOGTRIES         16      /* num of retries for broken syslogs */
 #define SYSLOG(a,b,c,d)                syslog_wrapper(a,b,c,d)
@@ -136,7 +130,7 @@ void log_error(code)
     int code;
 {
     char *p;
-    int count;
+    int count, header_length;
     time_t now;
 #if (LOGGING & SLOG_FILE)
     mode_t oldmask;
@@ -147,10 +141,20 @@ void log_error(code)
     char *tmp, save;
 #endif /* LOGGING & SLOG_SYSLOG */
 
+    /*
+     * length of syslog-like header info used for mail and file logs
+     * is len("DDD MM HH:MM:SS : username : ") with an additional
+     * len("HOST=hostname : ") if HOST_IN_LOG is defined.
+     */
+    header_length = 21 + strlen(user_name);
+#ifdef HOST_IN_LOG
+    header_length += 8 + strlen(shost);
+#endif
+
     /*
      * Allocate enough memory for logline so we won't overflow it
      */
-    count = LOG_HEADER_LEN + 136 + 2 * MAXPATHLEN + strlen(tty) + strlen(cwd) +
+    count = header_length + 136 + 2 * MAXPATHLEN + strlen(tty) + strlen(cwd) +
            strlen(runas_user);
     if (cmnd_args)
        count += strlen(cmnd_args);
@@ -168,12 +172,16 @@ void log_error(code)
      */
     now = time((time_t) 0);
     p = ctime(&now) + 4;
-    (void) sprintf(logline, "%15.15s : %8.8s : ", p, user_name);
+#ifdef HOST_IN_LOG
+    (void) sprintf(logline, "%15.15s : %s : HOST=%s : ", p, user_name, shost);
+#else
+    (void) sprintf(logline, "%15.15s : %s : ", p, user_name);
+#endif
 
     /*
      * we need a pointer to the end of logline for cheap appends.
      */
-    p = logline + LOG_HEADER_LEN;
+    p = logline + header_length;
 
     switch (code) {
 
@@ -316,7 +324,7 @@ void log_error(code)
     /*
      * Log the full line, breaking into multiple syslog(3) calls if necesary
      */
-    p = &logline[LOG_HEADER_LEN];      /* skip past the date and user */
+    p = &logline[header_length];       /* skip past the date, host, and user */
     for (count = 0; count < strlen(logline) / MAXSYSLOGLEN + 1; count++) {
        if (strlen(p) > MAXSYSLOGLEN) {
            /*
@@ -366,6 +374,9 @@ void log_error(code)
        char *beg, *oldend, *end;
        int maxlen = MAXLOGFILELEN;
 
+#ifndef WRAP_LOG
+       (void) fprintf(fp, "%s\n", logline);
+#else
        /*
         * Print out logline with word wrap
         */
@@ -413,6 +424,7 @@ void log_error(code)
                beg = NULL;                     /* exit condition */
            }
        }
+#endif
 
        (void) fclose(fp);
     }