From: Todd C. Miller Date: Fri, 28 Jan 2011 21:11:32 +0000 (-0500) Subject: Do logging and email sending in the locale specified by the X-Git-Tag: SUDO_1_7_5~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c17628c841b0a6444d49098fced2d517df528e96;p=sudo Do logging and email sending in the locale specified by the "sudoers_locale" setting ("C" by default). Email send by sudo includes MIME headers when the sudoers locale is not "C". --HG-- branch : 1.7 --- diff --git a/NEWS b/NEWS index 2356f35d4..3e9cca89e 100644 --- a/NEWS +++ b/NEWS @@ -63,6 +63,10 @@ What's new in Sudo 1.7.5? after validating the command so the sudoers entries do not need to include the backslashes. + * Logging and email sending are now done in the locale specified + by the "sudoers_locale" setting ("C" by default). Email send by + sudo now includes MIME headers when "sudoers_locale" is not "C". + What's new in Sudo 1.7.4p6? * A bug has been fixed in the I/O logging support that could cause diff --git a/config.h.in b/config.h.in index 90c3a66e8..1c12befd0 100644 --- a/config.h.in +++ b/config.h.in @@ -358,6 +358,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETGROUP_H +/* Define to 1 if you have the `nl_langinfo' function. */ +#undef HAVE_NL_LANGINFO + /* Define to 1 if you have the `openpty' function. */ #undef HAVE_OPENPTY diff --git a/configure b/configure index 0ec5e6e91..e4a1833e3 100755 --- a/configure +++ b/configure @@ -15099,7 +15099,7 @@ LIBS=$ac_save_LIBS for ac_func in strchr strrchr memchr memcpy memset sysconf tzset \ strftime setrlimit initgroups getgroups fstat gettimeofday \ - regcomp setlocale getaddrinfo setenv vhangup \ + regcomp setlocale nl_langinfo getaddrinfo setenv vhangup \ mbr_check_membership setrlimit64 do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/configure.in b/configure.in index 6b9714d73..f8d8ed688 100644 --- a/configure.in +++ b/configure.in @@ -1954,7 +1954,7 @@ dnl AC_FUNC_GETGROUPS AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf tzset \ strftime setrlimit initgroups getgroups fstat gettimeofday \ - regcomp setlocale getaddrinfo setenv vhangup \ + regcomp setlocale nl_langinfo getaddrinfo setenv vhangup \ mbr_check_membership setrlimit64) AC_CHECK_FUNCS(getline, [], [ AC_LIBOBJ(getline) diff --git a/logging.c b/logging.c index 9d8d5a89e..d0aeab990 100644 --- a/logging.c +++ b/logging.c @@ -47,6 +47,12 @@ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ +#ifdef HAVE_SETLOCALE +# include +#endif /* HAVE_SETLOCALE */ +#ifdef HAVE_NL_LANGINFO +# include +#endif /* HAVE_NL_LANGINFO */ #include #include #include @@ -132,6 +138,12 @@ do_syslog(pri, msg) char *p, *tmp, save; const char *fmt; +#ifdef HAVE_SETLOCALE + const char *old_locale = estrdup(setlocale(LC_ALL, NULL)); + if (!setlocale(LC_ALL, def_sudoers_locale)) + setlocale(LC_ALL, "C"); +#endif /* HAVE_SETLOCALE */ + /* * Log the full line, breaking into multiple syslog(3) calls if necessary */ @@ -166,6 +178,11 @@ do_syslog(pri, msg) fmt = FMT_CONTD; maxlen = MAXSYSLOGLEN - (sizeof(FMT_CONTD) - 6 + strlen(user_name)); } + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, old_locale); + efree((void *)old_locale); +#endif /* HAVE_SETLOCALE */ } static void @@ -189,6 +206,12 @@ do_logfile(msg) } else { time_t now; +#ifdef HAVE_SETLOCALE + const char *old_locale = estrdup(setlocale(LC_ALL, NULL)); + if (!setlocale(LC_ALL, def_sudoers_locale)) + setlocale(LC_ALL, "C"); +#endif /* HAVE_SETLOCALE */ + now = time(NULL); if (def_loglinelen == 0) { /* Don't pretty-print long log file lines (hard to grep) */ @@ -258,6 +281,11 @@ do_logfile(msg) (void) fflush(fp); (void) lock_file(fileno(fp), SUDO_UNLOCK); (void) fclose(fp); + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, old_locale); + efree((void *)old_locale); +#endif /* HAVE_SETLOCALE */ } } @@ -437,7 +465,7 @@ send_mail(fmt, va_alist) "USER=root", NULL }; -#endif +#endif /* NO_ROOT_MAILER */ /* Just return if mailer is disabled. */ if (!def_mailerpath || !def_mailto) @@ -487,6 +515,14 @@ send_mail(fmt, va_alist) (void) dup2(fd, STDERR_FILENO); } +#ifdef HAVE_SETLOCALE + if (!setlocale(LC_ALL, def_sudoers_locale)) { + setlocale(LC_ALL, "C"); + efree(def_sudoers_locale); + def_sudoers_locale = estrdup("C"); + } +#endif /* HAVE_SETLOCALE */ + /* Close password, group and other fds so we don't leak. */ sudo_endpwent(); sudo_endgrent(); @@ -583,6 +619,11 @@ send_mail(fmt, va_alist) (void) fputc(*p, mail); } +#ifdef HAVE_NL_LANGINFO + if (strcmp(def_sudoers_locale, "C") != 0) + (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); #ifdef __STDC__