From: Todd C. Miller Date: Tue, 18 Oct 2016 23:00:53 +0000 (-0600) Subject: Use vsyslog() if available. X-Git-Tag: SUDO_1_8_19^2~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c18ff022e0b9ec8e72d7887769425cbc32c3ec18;p=sudo Use vsyslog() if available. --- diff --git a/config.h.in b/config.h.in index 6586fb74e..e34cc6dfd 100644 --- a/config.h.in +++ b/config.h.in @@ -842,6 +842,9 @@ /* Define to 1 if you have the `vsnprintf' function. */ #undef HAVE_VSNPRINTF +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + /* Define to 1 if you have the `wordexp' function. */ #undef HAVE_WORDEXP diff --git a/configure b/configure index 8c9798822..c3748d662 100755 --- a/configure +++ b/configure @@ -2663,6 +2663,7 @@ as_fn_append ac_func_list " pwrite" as_fn_append ac_func_list " openat" as_fn_append ac_func_list " faccessat" as_fn_append ac_func_list " wordexp" +as_fn_append ac_func_list " vsyslog" as_fn_append ac_func_list " seteuid" # Check that the precious variables saved in the cache have kept the same # value. @@ -18095,6 +18096,8 @@ done + + case "$host_os" in diff --git a/configure.ac b/configure.ac index 2d7554e35..55a2573f7 100644 --- a/configure.ac +++ b/configure.ac @@ -2408,7 +2408,7 @@ dnl dnl Function checks dnl AC_FUNC_GETGROUPS -AC_CHECK_FUNCS_ONCE([fexecve killpg nl_langinfo strftime pread pwrite openat faccessat wordexp]) +AC_CHECK_FUNCS_ONCE([fexecve killpg nl_langinfo strftime pread pwrite openat faccessat wordexp vsyslog]) case "$host_os" in hpux*) if test X"$ac_cv_func_pread" = X"yes"; then diff --git a/plugins/sudoers/logging.c b/plugins/sudoers/logging.c index 64bd794e0..be31f6c2e 100644 --- a/plugins/sudoers/logging.c +++ b/plugins/sudoers/logging.c @@ -72,18 +72,24 @@ static char *new_logline(const char *, int); static void mysyslog(int pri, const char *fmt, ...) { - char *buf; va_list ap; debug_decl(mysyslog, SUDOERS_DEBUG_LOGGING) va_start(ap, fmt); openlog("sudo", 0, def_syslog); - if (vasprintf(&buf, fmt, ap) == -1) { - sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); - } else { - syslog(pri, "%s", buf); - free(buf); - } +#ifdef HAVE_VSYSLOG + vsyslog(pri, fmt, ap); +#else + do { + char *buf; + if (vasprintf(&buf, fmt, ap) == -1) { + sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory")); + } else { + syslog(pri, "%s", buf); + free(buf); + } + } while (0); +#endif va_end(ap); closelog(); debug_return;