]> granicus.if.org Git - sudo/commitdiff
add log_year option
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Sep 1999 16:56:32 +0000 (16:56 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Sep 1999 16:56:32 +0000 (16:56 +0000)
defaults.c
defaults.h
logging.c

index f174de9457fff7c6e58e2879b6c37c3bfcf6a434..6c3f8980dacbc4fa51b1499c13f135cc917afcd5 100644 (file)
@@ -147,6 +147,9 @@ struct sudo_defs_types {
     }, { 
        "log_host", T_FLAG, FL_LOG_HOST, NULL,
        "Log the hostname in the (non-syslog) log file"
+    }, { 
+       "log_year", T_FLAG, FL_LOG_YEAR, NULL,
+       "Log the year in the (non-syslog) log file"
     }, { 
        "shell_noargs", T_FLAG, FL_SHELL_NOARGS, NULL,
        "If sudo is invoked with no arguments, start a shell"
index bf4c36bedb018e1817d5b9a4a04a1e5fa472b662..c07ca67b2b18e20f5a0e9425d7230e63324dd821 100644 (file)
@@ -68,6 +68,7 @@
 #define FL_PATH_INFO           0x02000
 #define FL_FQDN                        0x04000
 #define FL_INSULTS             0x08000
+#define FL_LOG_YEAR            0x10000
 #define FL_MAX                 0xFFFFF
 
 /*
index 5058a89de0667880ab88159ae5c07964585edca1..3e6fb3b25364e4c7d8375bd36db27da852a6c381 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -149,7 +149,7 @@ static void
 do_logfile(msg)
     char *msg;
 {
-    char *full_line;
+    char *full_line, *timestr;
     char *beg, *oldend, *end;
     FILE *fp;
     mode_t oldmask;
@@ -172,21 +172,25 @@ do_logfile(msg)
        send_mail(full_line);
        free(full_line);
     } else {
+       timestr = ctime(&now) + 4;              /* skip day of the week */
+       if (sudo_flag_set(FL_LOG_YEAR))
+           timestr[20] = '\0';                 /* avoid the newline */
+       else
+           timestr[15] = '\0';                 /* don't care about year */
+
        if (sudo_inttable[I_LOGLEN] == 0) {
            /* Don't pretty-print long log file lines (hard to grep) */
            if (sudo_flag_set(FL_LOG_HOST))
-               (void) fprintf(fp, "%15.15s : %s : HOST=%s : %s\n",
-                   ctime(&now) + 4, user_name, user_shost, msg);
+               (void) fprintf(fp, "%s : %s : HOST=%s : %s\n", timestr,
+                   user_name, user_shost, msg);
            else
-               (void) fprintf(fp, "%15.15s : %s : %s\n", ctime(&now) + 4,
-                   user_name, msg);
+               (void) fprintf(fp, "%s : %s : %s\n", timestr, user_name, msg);
        } else {
            if (sudo_flag_set(FL_LOG_HOST))
-               easprintf(&full_line, "%15.15s : %s : HOST=%s : %s",
-                   ctime(&now) + 4, user_name, user_shost, msg);
+               easprintf(&full_line, "%s : %s : HOST=%s : %s", timestr,
+                   user_name, user_shost, msg);
            else
-               easprintf(&full_line, "%15.15s : %s : %s", ctime(&now) + 4,
-                   user_name, msg);
+               easprintf(&full_line, "%s : %s : %s", timestr, user_name, msg);
 
            /*
             * Print out full_line with word wrap
@@ -465,7 +469,11 @@ send_mail(line)
        }
        now = time((time_t) 0);
        p = ctime(&now) + 4;
-       (void) fprintf(mail, "\n\n%s : %15.15s : %s : %s\n\n", user_host, p,
+       if (sudo_flag_set(FL_LOG_YEAR))
+           p[20] = '\0';                       /* avoid the newline */
+       else
+           p[15] = '\0';                       /* don't care about year */
+       (void) fprintf(mail, "\n\n%s : %s : %s : %s\n\n", user_host, p,
            user_name, line);
        fclose(mail);
        reapchild(0);