lib/util/progname.c
lib/util/pw_dup.c
lib/util/reallocarray.c
+lib/util/vsyslog.c
lib/util/regress/atofoo/atofoo_test.c
lib/util/regress/fnmatch/fnm_test.c
lib/util/regress/fnmatch/fnm_test.in
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.
-
-
case "$host_os" in
done
fi
+for ac_func in vsyslog
+do :
+ ac_fn_c_check_func "$LINENO" "vsyslog" "ac_cv_func_vsyslog"
+if test "x$ac_cv_func_vsyslog" = xyes; then :
+ cat >>confdefs.h <<_ACEOF
+#define HAVE_VSYSLOG 1
+_ACEOF
+
+else
+
+ case " $LIBOBJS " in
+ *" vsyslog.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS vsyslog.$ac_objext"
+ ;;
+esac
+
+
+ for _sym in sudo_vsyslog; do
+ COMPAT_EXP="${COMPAT_EXP}${_sym}
+"
+ done
+
+
+fi
+done
+
if test X"$with_noexec" != X"no"; then
# Check for non-standard exec functions
for ac_func in exect execvP execvpe
dnl Function checks
dnl
AC_FUNC_GETGROUPS
-AC_CHECK_FUNCS_ONCE([fexecve killpg nl_langinfo strftime pread pwrite openat faccessat wordexp vsyslog])
+AC_CHECK_FUNCS_ONCE([fexecve killpg nl_langinfo strftime pread pwrite openat faccessat wordexp])
case "$host_os" in
hpux*)
if test X"$ac_cv_func_pread" = X"yes"; then
AC_LIBOBJ(sha2)
SUDO_APPEND_COMPAT_EXP(sudo_SHA224Final sudo_SHA224Init sudo_SHA224Pad sudo_SHA224Transform sudo_SHA224Update sudo_SHA256Final sudo_SHA256Init sudo_SHA256Pad sudo_SHA256Transform sudo_SHA256Update sudo_SHA384Final sudo_SHA384Init sudo_SHA384Pad sudo_SHA384Transform sudo_SHA384Update sudo_SHA512Final sudo_SHA512Init sudo_SHA512Pad sudo_SHA512Transform sudo_SHA512Update)
fi
+AC_CHECK_FUNCS([vsyslog], [], [
+ AC_LIBOBJ(vsyslog)
+ SUDO_APPEND_COMPAT_EXP(sudo_vsyslog)
+])
dnl
dnl Function checks for sudo_noexec
dnl
# undef reallocarray
# define reallocarray(_a, _b, _c) sudo_reallocarray((_a), (_b), (_c))
#endif /* HAVE_REALLOCARRAY */
+#ifndef HAVE_VSYSLOG
+__dso_public void sudo_vsyslog(int pri, const char *fmt, va_list ap);
+# undef vsyslog
+# define vsyslog(_a, _b, _c) sudo_vsyslog((_a), (_b), (_c))
+#endif /* HAVE_VSYSLOG */
#endif /* SUDO_COMPAT_H */
--- /dev/null
+/*
+ * Copyright (c) 2016 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif /* HAVE_STRING_H */
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif /* HAVE_STRINGS_H */
+#include <syslog.h>
+
+#include "sudo_compat.h"
+
+#ifndef HAVE_VSYSLOG
+void
+sudo_vsyslog(int pri, const char *fmt, va_list ap)
+{
+ int saved_errno = errno;
+ char *buf, *cp, *ep, new_fmt[1024];
+ size_t len;
+
+ /* Rewrite fmt, replacing %m with an errno string. */
+ for (cp = new_fmt, ep = new_fmt + sizeof(new_fmt); *fmt != '\0'; fmt++) {
+ if (fmt[0] == '%' && fmt[1] == 'm') {
+ fmt++;
+ len = strlcpy(cp, strerror(saved_errno), (ep - cp));
+ if (len >= (size_t)(ep - cp))
+ len = (size_t)(ep - cp) - 1;
+ cp += len;
+ break;
+ } else {
+ if (fmt[0] == '%' && fmt[1] == '%') {
+ fmt++;
+ if (cp < ep - 1)
+ *cp++ = '%';
+ }
+ if (cp < ep - 1)
+ *cp++ = *fmt;
+ }
+ }
+ *cp = '\0';
+
+ /* Format message and log it. */
+ if (vasprintf(&buf, new_fmt, ap) != -1) {
+ syslog(pri, "%s", buf);
+ free(buf);
+ }
+}
+#endif /* HAVE_VSYSLOG */
* We do an openlog(3)/closelog(3) for each message because some
* authentication methods (notably PAM) use syslog(3) for their
* own nefarious purposes and may call openlog(3) and closelog(3).
- * Note that because we don't want to assume that all systems have
- * vsyslog(3) (HP-UX doesn't) "%m" will not be expanded.
*/
static void
mysyslog(int pri, const char *fmt, ...)
va_start(ap, fmt);
openlog("sudo", 0, def_syslog);
-#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;