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 \
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
$(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)
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));
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);
/*
(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
(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="
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. */
--- /dev/null
+/*
+ * 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);
+}