Include setjmp.h in sudoers.h

Move error_jmp into plugin_error.c
Rename sudoers_plugin_cleanup sudoers_cleanup
Make sudoers warning/error functions work when sudo_conv is NULL
This commit is contained in:
Todd C. Miller
2012-11-25 09:33:33 -05:00
parent 3b5f786994
commit 3e5bd8dc52
6 changed files with 70 additions and 46 deletions

View File

@@ -44,7 +44,6 @@
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <setjmp.h>
#include <pwd.h>
#include <grp.h>
#ifdef HAVE_ZLIB_H

View File

@@ -57,7 +57,6 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include "sudoers.h"
@@ -528,7 +527,7 @@ log_fatal(int flags, const char *fmt, ...)
va_end(ap);
/* Exit the plugin. */
sudoers_plugin_cleanup(0);
sudoers_cleanup(0);
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
siglongjmp(error_jmp, 1);
}

View File

@@ -39,9 +39,9 @@
#include "gettext.h"
static void _warning(int, const char *, va_list);
void sudoers_plugin_cleanup(int);
void sudoers_cleanup(int);
extern sigjmp_buf error_jmp;
sigjmp_buf error_jmp;
extern sudo_conv_t sudo_conv;
@@ -53,8 +53,11 @@ error2(int eval, const char *fmt, ...)
va_start(ap, fmt);
_warning(1, fmt, ap);
va_end(ap);
sudoers_plugin_cleanup(0);
siglongjmp(error_jmp, eval);
sudoers_cleanup(0);
if (sudo_conv != NULL)
siglongjmp(error_jmp, eval);
else
exit(eval);
}
void
@@ -65,24 +68,33 @@ errorx2(int eval, const char *fmt, ...)
va_start(ap, fmt);
_warning(0, fmt, ap);
va_end(ap);
sudoers_plugin_cleanup(0);
siglongjmp(error_jmp, eval);
sudoers_cleanup(0);
if (sudo_conv != NULL)
siglongjmp(error_jmp, eval);
else
exit(eval);
}
void
verror2(int eval, const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
sudoers_plugin_cleanup(0);
siglongjmp(error_jmp, eval);
sudoers_cleanup(0);
if (sudo_conv != NULL)
siglongjmp(error_jmp, eval);
else
exit(eval);
}
void
verrorx2(int eval, const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
sudoers_plugin_cleanup(0);
siglongjmp(error_jmp, eval);
sudoers_cleanup(0);
if (sudo_conv != NULL)
siglongjmp(error_jmp, eval);
else
exit(eval);
}
void
@@ -119,36 +131,51 @@ vwarningx2(const char *fmt, va_list ap)
static void
_warning(int use_errno, const char *fmt, va_list ap)
{
struct sudo_conv_message msg[6];
struct sudo_conv_reply repl[6];
char *str;
int oldlocale, nmsgs = 4;
int oldlocale, serrno = errno;
/* Warnings are displayed in the user's locale. */
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
evasprintf(&str, _(fmt), ap);
if (sudo_conv != NULL) {
struct sudo_conv_message msg[6];
struct sudo_conv_reply repl[6];
int nmsgs = 4;
char *str;
/* 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;
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);
if (fmt != NULL) {
fputs(_(": "), stderr);
vfprintf(stderr, _(fmt), ap);
}
if (use_errno) {
fputs(_(": "), stderr);
fputs(strerror(serrno), stderr);
}
putc('\n', stderr);
}
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);
sudoers_setlocale(oldlocale, NULL);
}

View File

@@ -43,7 +43,6 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#include <setjmp.h>
#include "sudoers.h"
#include "sudoers_version.h"
@@ -581,7 +580,7 @@ sudoers_policy_invalidate(int remove)
user_cmnd = "kill";
if (sigsetjmp(error_jmp, 1) == 0) {
remove_timestamp(remove);
sudoers_plugin_cleanup(0);
sudoers_cleanup(0);
}
debug_return;

View File

@@ -71,7 +71,6 @@
# include <selinux/selinux.h>
#endif
#include <ctype.h>
#include <setjmp.h>
#ifndef HAVE_GETADDRINFO
# include "compat/getaddrinfo.h"
#endif
@@ -120,9 +119,6 @@ static struct sudo_nss_list *snl;
int NewArgc;
char **NewArgv;
/* Declared here instead of plugin_error.c for static sudo builds. */
sigjmp_buf error_jmp;
int
sudoers_policy_init(void *info, char * const envp[])
{
@@ -905,12 +901,12 @@ cb_runas_default(const char *user)
* Cleanup hook for error()/errorx()
*/
void
sudoers_plugin_cleanup(int gotsignal)
sudoers_cleanup(int gotsignal)
{
struct sudo_nss *nss;
if (!gotsignal) {
debug_decl(sudoers_plugin_cleanup, SUDO_DEBUG_PLUGIN)
debug_decl(sudoers_cleanup, SUDO_DEBUG_PLUGIN)
if (snl != NULL) {
tq_foreach_fwd(snl, nss)
nss->close(nss);

View File

@@ -23,6 +23,7 @@
#define _SUDO_SUDOERS_H
#include <limits.h>
#include <setjmp.h>
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
@@ -352,7 +353,7 @@ char *fmt_string(const char *, const char *);
FILE *open_sudoers(const char *, bool, bool *);
int sudoers_policy_init(void *info, char * const envp[]);
int sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], void *closure);
void sudoers_plugin_cleanup(int);
void sudoers_cleanup(int);
/* policy.c */
int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group);
@@ -371,6 +372,9 @@ int group_plugin_query(const char *user, const char *group,
/* setgroups.c */
int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
/* plugin_error.c */
extern sigjmp_buf error_jmp;
#ifndef _SUDO_MAIN
extern struct sudo_user sudo_user;
extern struct passwd *list_pw;