Diff for /embedaddon/sudo/plugins/sudoers/logging.c between versions 1.1.1.5 and 1.1.1.6

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

Removed from v.1.1.1.5  
changed lines
  Added in v.1.1.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>