]> granicus.if.org Git - sudo/commitdiff
Do logging and email sending in the locale specified by the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 28 Jan 2011 21:11:32 +0000 (16:11 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 28 Jan 2011 21:11:32 +0000 (16:11 -0500)
"sudoers_locale" setting ("C" by default).  Email send by sudo
includes MIME headers when the sudoers locale is not "C".

--HG--
branch : 1.7

NEWS
config.h.in
configure
configure.in
logging.c

diff --git a/NEWS b/NEWS
index 2356f35d44d63f04067a53fe73f7040552cf6879..3e9cca89e69772e3e599a159b512e86faf2ecb0c 100644 (file)
--- 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
index 90c3a66e89181debcb85a197f095338c277d5216..1c12befd0f53c5d68c9578cabeaad582f74a0057 100644 (file)
 /* Define to 1 if you have the <netgroup.h> 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
 
index 0ec5e6e915c6549d00c132ad6c20050380720976..e4a1833e349d1819c0a06eb03101f8365d5aef85 100755 (executable)
--- 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`
index 6b9714d731e9eb5d110e0acc1a9f6b427350e38c..f8d8ed6885cc8d67cb53659fe81a33d33ae8062c 100644 (file)
@@ -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)
index 9d8d5a89e7b999a05fdab3b4cb0b4067163e1b72..d0aeab9906f3836f972a55b23a1e2608171e0e06 100644 (file)
--- a/logging.c
+++ b/logging.c
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif /* HAVE_UNISTD_H */
+#ifdef HAVE_SETLOCALE
+# include <locale.h>
+#endif /* HAVE_SETLOCALE */
+#ifdef HAVE_NL_LANGINFO
+# include <langinfo.h>
+#endif /* HAVE_NL_LANGINFO */
 #include <pwd.h>
 #include <grp.h>
 #include <signal.h>
@@ -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__