]> granicus.if.org Git - sudo/commitdiff
Make get_timestr() take a time_t so we can use it properly in
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Sep 2009 09:55:08 +0000 (09:55 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 17 Sep 2009 09:55:08 +0000 (09:55 +0000)
sudoreplay.

logging.c
sudo.h
timestr.c

index 2f1421fe3848dde1e1238b02cd2d97c9560bc928..927914be0f32d1435322272f3a365546da8b6427 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -197,21 +197,24 @@ do_logfile(msg)
        send_mail(full_line);
        efree(full_line);
     } else {
+       time_t now;
+
+       now = time(NULL);
        if (def_loglinelen == 0) {
            /* Don't pretty-print long log file lines (hard to grep) */
            if (def_log_host)
                (void) fprintf(fp, "%s : %s : HOST=%s : %s\n",
-                   get_timestr(def_log_year), user_name, user_shost, msg);
+                   get_timestr(now, def_log_year), user_name, user_shost, msg);
            else
-               (void) fprintf(fp, "%s : %s : %s\n", get_timestr(def_log_year),
-                   user_name, msg);
+               (void) fprintf(fp, "%s : %s : %s\n",
+                   get_timestr(now, def_log_year), user_name, msg);
        } else {
            if (def_log_host)
                easprintf(&full_line, "%s : %s : HOST=%s : %s",
-                   get_timestr(def_log_year), user_name, user_shost, msg);
+                   get_timestr(now, def_log_year), user_name, user_shost, msg);
            else
-               easprintf(&full_line, "%s : %s : %s", get_timestr(def_log_year),
-                   user_name, msg);
+               easprintf(&full_line, "%s : %s : %s",
+                   get_timestr(now, def_log_year), user_name, msg);
 
            /*
             * Print out full_line with word wrap
@@ -590,7 +593,7 @@ send_mail(line)
            (void) fputc(*p, mail);
     }
     (void) fprintf(mail, "\n\n%s : %s : %s : %s\n\n", user_host,
-       get_timestr(def_log_year), user_name, line);
+       get_timestr(time(NULL), def_log_year), user_name, line);
     fclose(mail);
     do {
 #ifdef HAVE_WAITPID
diff --git a/sudo.h b/sudo.h
index eaba6f04944cd604f91f9dd604eefcb485ac70b6..ebb08cb626973d4620435ff56ad905f403fcca20 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -334,7 +334,7 @@ int term_copy __P((int, int));
 int term_noecho __P((int));
 int term_raw __P((int));
 int term_restore __P((int));
-char *get_timestr __P((int));
+char *get_timestr __P((time_t, int));
 YY_DECL;
 
 /* Only provide extern declarations outside of sudo.c. */
index 7bc3a338c6d41124f3d8e92741f6258e3a0719a4..aaa004e1c4172fd5a01406c45713d2566e68e154 100644 (file)
--- a/timestr.c
+++ b/timestr.c
 __unused static const char rcsid[] = "$Sudo$";
 #endif /* lint */
 
-char *get_timestr      __P((int));
+char *get_timestr      __P((time_t, int));
 
 /*
  * Return an ascii string with the current date + time
  * Uses strftime() if available, else falls back to ctime().
  */
 char *
-get_timestr(log_year)
+get_timestr(tstamp, log_year)
+    time_t tstamp;
     int log_year;
 {
     char *s;
-    time_t now = time((time_t) 0);
 #ifdef HAVE_STRFTIME
     static char buf[128];
     struct tm *timeptr;
 
-    timeptr = localtime(&now);
+    timeptr = localtime(&tstamp);
     if (log_year)
        s = "%h %e %T %Y";
     else
@@ -63,7 +63,7 @@ get_timestr(log_year)
 
 #endif /* HAVE_STRFTIME */
 
-    s = ctime(&now) + 4;               /* skip day of the week */
+    s = ctime(&tstamp) + 4;            /* skip day of the week */
     if (log_year)
        s[20] = '\0';                   /* avoid the newline */
     else