From: Todd C. Miller Date: Mon, 15 Mar 2010 11:14:45 +0000 (-0400) Subject: Make _warning in error.c use the conversation function and remove X-Git-Tag: SUDO_1_8_0~814 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5e2f61a0981faf1c9806acf522de19d17fe2a884;p=sudo Make _warning in error.c use the conversation function and remove commented out warning/warningx in sudoers.c. --- diff --git a/plugins/sudoers/error.c b/plugins/sudoers/error.c index 629d4cce0..504096848 100644 --- a/plugins/sudoers/error.c +++ b/plugins/sudoers/error.c @@ -22,7 +22,8 @@ #include #include -#include "error.h" +#include +#include static void _warning(int, const char *, va_list); void cleanup(int); @@ -37,10 +38,7 @@ error(int eval, const char *fmt, ...) _warning(1, fmt, ap); va_end(ap); cleanup(0); - if (error_jmp) - siglongjmp(error_jmp, 1); - else - exit(eval); + siglongjmp(error_jmp, 1); } void @@ -51,10 +49,7 @@ errorx(int eval, const char *fmt, ...) _warning(0, fmt, ap); va_end(ap); cleanup(0); - if (error_jmp) - siglongjmp(error_jmp, 1); - else - exit(eval); + siglongjmp(error_jmp, 1); } void @@ -78,16 +73,28 @@ warningx(const char *fmt, ...) static void _warning(int use_errno, const char *fmt, va_list ap) { - int serrno = errno; + struct sudo_conv_message msg[5]; + struct sudo_conv_reply repl[5]; + char *str; + int nmsgs = 3; - fputs(getprogname(), stderr); - if (fmt != NULL) { - fputs(": ", stderr); - vfprintf(stderr, fmt, ap); - } - if (use_errno) { - fputs(": ", stderr); - fputs(strerror(serrno), stderr); - } - putc('\n', stderr); + 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 = 5; + } + memset(&repl, 0, sizeof(repl)); + sudo_conv(nmsgs, msg, repl); } diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 7dab3b117..fe8ece6b9 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1993-1996, 1998-2009 Todd C. Miller + * Copyright (c) 1993-1996, 1998-2010 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1266,55 +1266,6 @@ deserialize_info(char * const settings[], char * const user_info[]) return flags; } -#if 0 /* move to error.c */ -void -warning(const char *fmt, ...) -{ - struct sudo_conv_message msg; - struct sudo_conv_reply repl; - va_list ap; - char *str, *tmp; - - va_start(ap, fmt); - evasprintf(&tmp, fmt, ap); - va_end(ap); - easprintf(&str, "%s: %s: %s\n", getprogname(), tmp, strerror(errno)); - efree(tmp); - - /* Call conversation function */ - memset(&msg, 0, sizeof(msg)); - msg.msg_type = SUDO_CONV_ERROR_MSG; - msg.msg = str; - memset(&repl, 0, sizeof(repl)); - sudo_conv(1, &msg, &repl); -} - -void -warningx(const char *fmt, ...) -{ - struct sudo_conv_message msg; - struct sudo_conv_reply repl; - va_list ap; - char *str, *tmp; - int rc; - - va_start(ap, fmt); - rc = wvasprintf(&tmp, fmt, ap); - va_end(ap); - if (rc == -1) - return; - easprintf(&str, "%s: %s\n", getprogname(), tmp); - efree(tmp); - - /* Call conversation function */ - memset(&msg, 0, sizeof(msg)); - msg.msg_type = SUDO_CONV_ERROR_MSG; - msg.msg = str; - memset(&repl, 0, sizeof(repl)); - sudo_conv(1, &msg, &repl); -} -#endif - struct policy_plugin sudoers_policy = { SUDO_POLICY_PLUGIN, SUDO_API_VERSION,