]> granicus.if.org Git - sudo/commitdiff
Move get_timestr() into its own source file so sudoreplay can use it.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Sep 2009 11:48:34 +0000 (11:48 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Wed, 16 Sep 2009 11:48:34 +0000 (11:48 +0000)
Makefile.in
logging.c
sudo.h
timestr.c [new file with mode: 0644]

index 14a73b1a4f2c39884a66b303b51006b9b972e564..fcee8a509f77a9f8ac3286fd5819be8588409e6b 100644 (file)
@@ -110,7 +110,8 @@ SRCS = aix.c alias.c alloc.c audit.c bsm_audit.c check.c closefrom.c \
        snprintf.c strcasecmp.c strerror.c strlcat.c strlcpy.c sudo.c \
        sudo_noexec.c sudo_edit.c sudo_nss.c term.c testsudoers.c tgetpass.c \
        toke.c toke.l tsgetgrpw.c utimes.c vasgroups.c visudo.c zero_bytes.c \
-       redblack.c selinux.c sesh.c sudoreplay.c getdate.c getdate.y $(AUTH_SRCS)
+       redblack.c selinux.c sesh.c sudoreplay.c getdate.c getdate.y timestr.c \
+       $(AUTH_SRCS)
 
 AUTH_SRCS = auth/afs.c auth/aix_auth.c auth/bsdauth.c auth/dce.c auth/fwtk.c \
            auth/kerb4.c auth/kerb5.c auth/pam.c auth/passwd.c auth/rfc1938.c \
@@ -132,12 +133,13 @@ COMMON_OBJS = gram.o alias.o alloc.o defaults.o error.o list.o match.o \
 SUDO_OBJS = $(COMMON_OBJS) $(AUTH_OBJS) @SUDO_OBJS@ audit.o check.o env.o \
            getspwuid.o gettime.o goodpath.o fileops.o find_path.o \
            interfaces.o lbuf.o logging.o parse.o pwutil.o script.o \
-           set_perms.o sudo.o sudo_edit.o sudo_nss.o term.o tgetpass.o
+           set_perms.o sudo.o sudo_edit.o sudo_nss.o term.o tgetpass.o \
+           timestr.o
 
 VISUDO_OBJS = $(COMMON_OBJS) visudo.o fileops.o gettime.o goodpath.o \
              find_path.o pwutil.o
 
-REPLAY_OBJS = sudoreplay.o error.o alloc.o getdate.o
+REPLAY_OBJS = sudoreplay.o error.o alloc.o getdate.o timestr.o
 
 TEST_OBJS = $(COMMON_OBJS) interfaces.o testsudoers.o tsgetgrpw.o tspwutil.o
 
@@ -334,6 +336,8 @@ testsudoers.o: $(srcdir)/testsudoers.c $(SUDODEP) $(srcdir)/parse.h $(srcdir)/li
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/testsudoers.c
 tgetpass.o: $(srcdir)/tgetpass.c $(SUDODEP)
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/tgetpass.c
+timestr.o: $(srcdir)/timestr.c $(srcdir)/compat.h config.h
+       $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(srcdir)/timestr.c
 toke.o: $(devdir)/toke.c $(SUDODEP) $(srcdir)/parse.h $(srcdir)/list.h $(devdir)/gram.h
        $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(OPTIONS) $(devdir)/toke.c
 tsgetgrpw.o: $(srcdir)/tsgetgrpw.c $(SUDODEP)
index af01f3c8b8fcaec47215f25aadb0d98acf6bdadd..2f1421fe3848dde1e1238b02cd2d97c9560bc928 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -65,7 +65,6 @@ static void do_syslog         __P((int, char *));
 static void do_logfile         __P((char *));
 static void send_mail          __P((char *));
 static int should_mail         __P((int));
-static char *get_timestr       __P((void));
 static void mysyslog           __P((int, const char *, ...));
 static char *new_logline       __P((const char *, int));
 
@@ -201,17 +200,17 @@ do_logfile(msg)
        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(),
-                   user_name, user_shost, msg);
+               (void) fprintf(fp, "%s : %s : HOST=%s : %s\n",
+                   get_timestr(def_log_year), user_name, user_shost, msg);
            else
-               (void) fprintf(fp, "%s : %s : %s\n", get_timestr(),
+               (void) fprintf(fp, "%s : %s : %s\n", get_timestr(def_log_year),
                    user_name, msg);
        } else {
            if (def_log_host)
-               easprintf(&full_line, "%s : %s : HOST=%s : %s", get_timestr(),
-                   user_name, user_shost, msg);
+               easprintf(&full_line, "%s : %s : HOST=%s : %s",
+                   get_timestr(def_log_year), user_name, user_shost, msg);
            else
-               easprintf(&full_line, "%s : %s : %s", get_timestr(),
+               easprintf(&full_line, "%s : %s : %s", get_timestr(def_log_year),
                    user_name, msg);
 
            /*
@@ -591,7 +590,7 @@ send_mail(line)
            (void) fputc(*p, mail);
     }
     (void) fprintf(mail, "\n\n%s : %s : %s : %s\n\n", user_host,
-       get_timestr(), user_name, line);
+       get_timestr(def_log_year), user_name, line);
     fclose(mail);
     do {
 #ifdef HAVE_WAITPID
@@ -617,41 +616,6 @@ should_mail(status)
        (def_mail_no_perms && !ISSET(status, VALIDATE_OK)));
 }
 
-/*
- * Return an ascii string with the current date + time
- * Uses strftime() if available, else falls back to ctime().
- */
-static char *
-get_timestr()
-{
-    char *s;
-    time_t now = time((time_t) 0);
-#ifdef HAVE_STRFTIME
-    static char buf[128];
-    struct tm *timeptr;
-
-    timeptr = localtime(&now);
-    if (def_log_year)
-       s = "%h %e %T %Y";
-    else
-       s = "%h %e %T";
-
-    /* strftime() does not guarantee to NUL-terminate so we must check. */
-    buf[sizeof(buf) - 1] = '\0';
-    if (strftime(buf, sizeof(buf), s, timeptr) && buf[sizeof(buf) - 1] == '\0')
-       return(buf);
-
-#endif /* HAVE_STRFTIME */
-
-    s = ctime(&now) + 4;               /* skip day of the week */
-    if (def_log_year)
-       s[20] = '\0';                   /* avoid the newline */
-    else
-       s[15] = '\0';                   /* don't care about year */
-
-    return(s);
-}
-
 #define        LL_TTY_STR      "TTY="
 #define        LL_CWD_STR      "PWD="          /* XXX - should be CWD= */
 #define        LL_USER_STR     "USER="
diff --git a/sudo.h b/sudo.h
index 86e04a89ba09c1664e8d05b7e056d4f9be40ce63..eaba6f04944cd604f91f9dd604eefcb485ac70b6 100644 (file)
--- a/sudo.h
+++ b/sudo.h
@@ -334,6 +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));
 YY_DECL;
 
 /* Only provide extern declarations outside of sudo.c. */
diff --git a/timestr.c b/timestr.c
new file mode 100644 (file)
index 0000000..7bc3a33
--- /dev/null
+++ b/timestr.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 1999, 2009 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#include <time.h>
+
+#include "compat.h"
+
+#ifndef lint
+__unused static const char rcsid[] = "$Sudo$";
+#endif /* lint */
+
+char *get_timestr      __P((int));
+
+/*
+ * Return an ascii string with the current date + time
+ * Uses strftime() if available, else falls back to ctime().
+ */
+char *
+get_timestr(log_year)
+    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);
+    if (log_year)
+       s = "%h %e %T %Y";
+    else
+       s = "%h %e %T";
+
+    /* strftime() does not guarantee to NUL-terminate so we must check. */
+    buf[sizeof(buf) - 1] = '\0';
+    if (strftime(buf, sizeof(buf), s, timeptr) && buf[sizeof(buf) - 1] == '\0')
+       return(buf);
+
+#endif /* HAVE_STRFTIME */
+
+    s = ctime(&now) + 4;               /* skip day of the week */
+    if (log_year)
+       s[20] = '\0';                   /* avoid the newline */
+    else
+       s[15] = '\0';                   /* don't care about year */
+
+    return(s);
+}