--- embedaddon/sudo/plugins/sudoers/logging.c 2013/10/14 07:56:34 1.1.1.5 +++ embedaddon/sudo/plugins/sudoers/logging.c 2014/06/15 16:12:54 1.1.1.6 @@ -59,10 +59,6 @@ #include "sudoers.h" -#ifndef va_copy -# define va_copy(d, s) memcpy(&(d), &(s), sizeof(d)); -#endif - /* Special message for log_warning() so we know to use ngettext() */ #define INCORRECT_PASSWORD_ATTEMPT ((char *)0x01) @@ -180,7 +176,6 @@ do_logfile(char *msg) char *full_line; size_t len; mode_t oldmask; - time_t now; int oldlocale; FILE *fp; debug_decl(do_logfile, SUDO_DEBUG_LOGGING) @@ -197,25 +192,24 @@ do_logfile(char *msg) send_mail(_("unable to lock log file: %s: %s"), def_logfile, strerror(errno)); } else { - time(&now); - if (def_loglinelen < sizeof(LOG_INDENT)) { + const char *timestr = get_timestr(time(NULL), def_log_year); + if (timestr == NULL) + timestr = "invalid date"; + if ((size_t)def_loglinelen < sizeof(LOG_INDENT)) { /* 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(now, def_log_year), user_name, user_srunhost, - msg); + timestr, user_name, user_srunhost, msg); } else { - (void) fprintf(fp, "%s : %s : %s\n", - get_timestr(now, def_log_year), user_name, msg); + (void) fprintf(fp, "%s : %s : %s\n", timestr, user_name, msg); } } else { if (def_log_host) { len = easprintf(&full_line, "%s : %s : HOST=%s : %s", - get_timestr(now, def_log_year), user_name, user_srunhost, - msg); + timestr, user_name, user_srunhost, msg); } else { len = easprintf(&full_line, "%s : %s : %s", - get_timestr(now, def_log_year), user_name, msg); + timestr, user_name, msg); } /* @@ -336,9 +330,9 @@ log_failure(int status, int flags) * their path to just contain a single dir. */ if (flags == NOT_FOUND) - warningx(_("%s: command not found"), user_cmnd); + warningx(U_("%s: command not found"), user_cmnd); else if (flags == NOT_FOUND_DOT) - warningx(_("ignoring `%s' found in '.'\nUse `sudo ./%s' if this is the `%s' you wish to run."), user_cmnd, user_cmnd, user_cmnd); + warningx(U_("ignoring `%s' found in '.'\nUse `sudo ./%s' if this is the `%s' you wish to run."), user_cmnd, user_cmnd, user_cmnd); } debug_return; @@ -348,7 +342,7 @@ log_failure(int status, int flags) * Log and audit that user was not able to authenticate themselves. */ void -log_auth_failure(int status, int tries) +log_auth_failure(int status, unsigned int tries) { int flags = NO_MAIL; debug_decl(log_auth_failure, SUDO_DEBUG_LOGGING) @@ -443,13 +437,22 @@ vlog_warning(int flags, const char *fmt, va_list ap) /* Expand printf-style format + args (with a special case). */ if (fmt == INCORRECT_PASSWORD_ATTEMPT) { - int tries = va_arg(ap, int); - easprintf(&message, ngettext("%d incorrect password attempt", - "%d incorrect password attempts", tries), tries); + unsigned int tries = va_arg(ap, unsigned int); + easprintf(&message, ngettext("%u incorrect password attempt", + "%u incorrect password attempts", tries), tries); } else { evasprintf(&message, _(fmt), ap); } + /* Log to debug file. */ + if (USE_ERRNO) { + sudo_debug_printf2(NULL, NULL, 0, + SUDO_DEBUG_WARN|SUDO_DEBUG_ERRNO|sudo_debug_subsys, "%s", message); + } else { + sudo_debug_printf2(NULL, NULL, 0, + SUDO_DEBUG_WARN|sudo_debug_subsys, "%s", message); + } + if (ISSET(flags, MSG_ONLY)) { logline = message; } else { @@ -486,16 +489,18 @@ vlog_warning(int flags, const char *fmt, va_list ap) * Tell the user (in their locale). */ if (!ISSET(flags, NO_STDERR)) { + sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale); if (fmt == INCORRECT_PASSWORD_ATTEMPT) { - int tries = va_arg(ap2, int); - warningx(ngettext("%d incorrect password attempt", - "%d incorrect password attempts", tries), tries); + unsigned int tries = va_arg(ap2, unsigned int); + warningx_nodebug(ngettext("%u incorrect password attempt", + "%u incorrect password attempts", tries), tries); } else { if (ISSET(flags, USE_ERRNO)) - vwarning(fmt, ap2); + vwarning_nodebug(_(fmt), ap2); else - vwarningx(fmt, ap2); + vwarningx_nodebug(_(fmt), ap2); } + sudoers_setlocale(oldlocale, NULL); va_end(ap2); } @@ -543,6 +548,7 @@ send_mail(const char *fmt, ...) { FILE *mail; char *p; + const char *timestr; int fd, pfd[2], status; pid_t pid, rv; sigaction_t sa; @@ -572,7 +578,7 @@ send_mail(const char *fmt, ...) switch (pid = sudo_debug_fork()) { case -1: /* Error. */ - fatal(_("unable to fork")); + fatal(U_("unable to fork")); break; case 0: /* Child. */ @@ -722,8 +728,9 @@ send_mail(const char *fmt, ...) (void) fprintf(mail, "\nContent-Type: text/plain; charset=\"%s\"\nContent-Transfer-Encoding: 8bit", nl_langinfo(CODESET)); #endif /* HAVE_NL_LANGINFO */ - (void) fprintf(mail, "\n\n%s : %s : %s : ", user_host, - get_timestr(time(NULL), def_log_year), user_name); + if ((timestr = get_timestr(time(NULL), def_log_year)) == NULL) + timestr = "invalid date"; + (void) fprintf(mail, "\n\n%s : %s : %s : ", user_host, timestr, user_name); va_start(ap, fmt); (void) vfprintf(mail, fmt, ap); va_end(ap); @@ -904,5 +911,5 @@ new_logline(const char *message, int serrno) debug_return_str(line); toobig: - fatalx(_("internal error: insufficient space for log line")); + fatalx(U_("internal error: insufficient space for log line")); }