Move _sudo_printf from src/conversation.c to common/sudo_printf.c.

Add sudo_printf function pointer that is initialized to _sudo_printf()
instead of requiring a sudo_conv function pointer everywhere.  The
plugin will reset sudo_printf to point to the version passed in via
the plugin open function.  Now plugin_error.c can just call sudo_printf
in all cases.  The sudoers binaries no longer need their own version
of sudo_printf.
This commit is contained in:
Todd C. Miller
2012-11-25 09:34:33 -05:00
parent 5496ffe1e8
commit c2c6616a0c
23 changed files with 128 additions and 221 deletions

View File

@@ -44,8 +44,6 @@ static void _warning(int, const char *, va_list);
static sigjmp_buf error_jmp;
static bool setjmp_enabled = false;
extern sudo_conv_t sudo_conv;
void
error2(int eval, const char *fmt, ...)
{
@@ -133,47 +131,23 @@ static void
_warning(int use_errno, const char *fmt, va_list ap)
{
int serrno = errno;
char *str;
if (sudo_conv != NULL) {
struct sudo_conv_message msg[6];
struct sudo_conv_reply repl[6];
int nmsgs = 4;
char *str;
evasprintf(&str, _(fmt), ap);
/* Call conversation function */
memset(&msg, 0, sizeof(msg));
msg[0].msg_type = SUDO_CONV_ERROR_MSG;
msg[0].msg = getprogname();
msg[1].msg_type = SUDO_CONV_ERROR_MSG;
msg[1].msg = _(": ");
msg[2].msg_type = SUDO_CONV_ERROR_MSG;
msg[2].msg = str;
if (use_errno) {
msg[3].msg_type = SUDO_CONV_ERROR_MSG;
msg[3].msg = _(": ");
msg[4].msg_type = SUDO_CONV_ERROR_MSG;
msg[4].msg = strerror(errno);
nmsgs = 6;
}
msg[nmsgs - 1].msg_type = SUDO_CONV_ERROR_MSG;
msg[nmsgs - 1].msg = "\n";
memset(&repl, 0, sizeof(repl));
sudo_conv(nmsgs, msg, repl);
efree(str);
} else {
fputs(getprogname(), stderr);
evasprintf(&str, fmt, ap);
if (use_errno) {
if (fmt != NULL) {
fputs(_(": "), stderr);
vfprintf(stderr, _(fmt), ap);
sudo_printf(SUDO_CONV_ERROR_MSG,
_("%s: %s: %s\n"), getprogname(), str, strerror(serrno));
} else {
sudo_printf(SUDO_CONV_ERROR_MSG,
_("%s: %s\n"), getprogname(), strerror(serrno));
}
if (use_errno) {
fputs(_(": "), stderr);
fputs(strerror(serrno), stderr);
}
putc('\n', stderr);
} else {
sudo_printf(SUDO_CONV_ERROR_MSG,
_("%s: %s\n"), getprogname(), str ? str : "(null)");
}
efree(str);
errno = serrno;
}
static int oldlocale;