Make _warning in error.c use the conversation function and remove

commented out warning/warningx in sudoers.c.
This commit is contained in:
Todd C. Miller
2010-03-15 07:14:45 -04:00
parent dbbc0cea56
commit 5e2f61a098
2 changed files with 28 additions and 70 deletions

View File

@@ -22,7 +22,8 @@
#include <config.h> #include <config.h>
#include <compat.h> #include <compat.h>
#include "error.h" #include <error.h>
#include <sudo_plugin.h>
static void _warning(int, const char *, va_list); static void _warning(int, const char *, va_list);
void cleanup(int); void cleanup(int);
@@ -37,10 +38,7 @@ error(int eval, const char *fmt, ...)
_warning(1, fmt, ap); _warning(1, fmt, ap);
va_end(ap); va_end(ap);
cleanup(0); cleanup(0);
if (error_jmp) siglongjmp(error_jmp, 1);
siglongjmp(error_jmp, 1);
else
exit(eval);
} }
void void
@@ -51,10 +49,7 @@ errorx(int eval, const char *fmt, ...)
_warning(0, fmt, ap); _warning(0, fmt, ap);
va_end(ap); va_end(ap);
cleanup(0); cleanup(0);
if (error_jmp) siglongjmp(error_jmp, 1);
siglongjmp(error_jmp, 1);
else
exit(eval);
} }
void void
@@ -78,16 +73,28 @@ warningx(const char *fmt, ...)
static void static void
_warning(int use_errno, const char *fmt, va_list ap) _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); evasprintf(&str, fmt, ap);
if (fmt != NULL) {
fputs(": ", stderr); /* Call conversation function */
vfprintf(stderr, fmt, ap); memset(&msg, 0, sizeof(msg));
} msg[0].msg_type = SUDO_CONV_ERROR_MSG;
if (use_errno) { msg[0].msg = getprogname();
fputs(": ", stderr); msg[1].msg_type = SUDO_CONV_ERROR_MSG;
fputs(strerror(serrno), stderr); msg[1].msg = ":";
} msg[2].msg_type = SUDO_CONV_ERROR_MSG;
putc('\n', stderr); 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);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1993-1996, 1998-2009 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1993-1996, 1998-2010 Todd C. Miller <Todd.Miller@courtesan.com>
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * 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; 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 = { struct policy_plugin sudoers_policy = {
SUDO_POLICY_PLUGIN, SUDO_POLICY_PLUGIN,
SUDO_API_VERSION, SUDO_API_VERSION,