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:
@@ -44,7 +44,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <setjmp.h>
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#ifdef HAVE_ZLIB_H
|
#ifdef HAVE_ZLIB_H
|
||||||
|
@@ -57,7 +57,6 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
#include "sudoers.h"
|
#include "sudoers.h"
|
||||||
|
|
||||||
@@ -528,7 +527,7 @@ log_fatal(int flags, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
/* Exit the plugin. */
|
/* Exit the plugin. */
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
|
||||||
siglongjmp(error_jmp, 1);
|
siglongjmp(error_jmp, 1);
|
||||||
}
|
}
|
||||||
|
@@ -39,9 +39,9 @@
|
|||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
|
||||||
static void _warning(int, const char *, va_list);
|
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;
|
extern sudo_conv_t sudo_conv;
|
||||||
|
|
||||||
@@ -53,8 +53,11 @@ error2(int eval, const char *fmt, ...)
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warning(1, fmt, ap);
|
_warning(1, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
siglongjmp(error_jmp, eval);
|
if (sudo_conv != NULL)
|
||||||
|
siglongjmp(error_jmp, eval);
|
||||||
|
else
|
||||||
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -65,24 +68,33 @@ errorx2(int eval, const char *fmt, ...)
|
|||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
_warning(0, fmt, ap);
|
_warning(0, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
siglongjmp(error_jmp, eval);
|
if (sudo_conv != NULL)
|
||||||
|
siglongjmp(error_jmp, eval);
|
||||||
|
else
|
||||||
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
verror2(int eval, const char *fmt, va_list ap)
|
verror2(int eval, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
_warning(1, fmt, ap);
|
_warning(1, fmt, ap);
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
siglongjmp(error_jmp, eval);
|
if (sudo_conv != NULL)
|
||||||
|
siglongjmp(error_jmp, eval);
|
||||||
|
else
|
||||||
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
verrorx2(int eval, const char *fmt, va_list ap)
|
verrorx2(int eval, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
_warning(0, fmt, ap);
|
_warning(0, fmt, ap);
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
siglongjmp(error_jmp, eval);
|
if (sudo_conv != NULL)
|
||||||
|
siglongjmp(error_jmp, eval);
|
||||||
|
else
|
||||||
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -119,36 +131,51 @@ vwarningx2(const char *fmt, va_list ap)
|
|||||||
static void
|
static void
|
||||||
_warning(int use_errno, const char *fmt, va_list ap)
|
_warning(int use_errno, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
struct sudo_conv_message msg[6];
|
int oldlocale, serrno = errno;
|
||||||
struct sudo_conv_reply repl[6];
|
|
||||||
char *str;
|
|
||||||
int oldlocale, nmsgs = 4;
|
|
||||||
|
|
||||||
/* Warnings are displayed in the user's locale. */
|
/* Warnings are displayed in the user's locale. */
|
||||||
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
|
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 */
|
evasprintf(&str, _(fmt), ap);
|
||||||
memset(&msg, 0, sizeof(msg));
|
|
||||||
msg[0].msg_type = SUDO_CONV_ERROR_MSG;
|
/* Call conversation function */
|
||||||
msg[0].msg = getprogname();
|
memset(&msg, 0, sizeof(msg));
|
||||||
msg[1].msg_type = SUDO_CONV_ERROR_MSG;
|
msg[0].msg_type = SUDO_CONV_ERROR_MSG;
|
||||||
msg[1].msg = _(": ");
|
msg[0].msg = getprogname();
|
||||||
msg[2].msg_type = SUDO_CONV_ERROR_MSG;
|
msg[1].msg_type = SUDO_CONV_ERROR_MSG;
|
||||||
msg[2].msg = str;
|
msg[1].msg = _(": ");
|
||||||
if (use_errno) {
|
msg[2].msg_type = SUDO_CONV_ERROR_MSG;
|
||||||
msg[3].msg_type = SUDO_CONV_ERROR_MSG;
|
msg[2].msg = str;
|
||||||
msg[3].msg = _(": ");
|
if (use_errno) {
|
||||||
msg[4].msg_type = SUDO_CONV_ERROR_MSG;
|
msg[3].msg_type = SUDO_CONV_ERROR_MSG;
|
||||||
msg[4].msg = strerror(errno);
|
msg[3].msg = _(": ");
|
||||||
nmsgs = 6;
|
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);
|
sudoers_setlocale(oldlocale, NULL);
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,6 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <setjmp.h>
|
|
||||||
|
|
||||||
#include "sudoers.h"
|
#include "sudoers.h"
|
||||||
#include "sudoers_version.h"
|
#include "sudoers_version.h"
|
||||||
@@ -581,7 +580,7 @@ sudoers_policy_invalidate(int remove)
|
|||||||
user_cmnd = "kill";
|
user_cmnd = "kill";
|
||||||
if (sigsetjmp(error_jmp, 1) == 0) {
|
if (sigsetjmp(error_jmp, 1) == 0) {
|
||||||
remove_timestamp(remove);
|
remove_timestamp(remove);
|
||||||
sudoers_plugin_cleanup(0);
|
sudoers_cleanup(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_return;
|
debug_return;
|
||||||
|
@@ -71,7 +71,6 @@
|
|||||||
# include <selinux/selinux.h>
|
# include <selinux/selinux.h>
|
||||||
#endif
|
#endif
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <setjmp.h>
|
|
||||||
#ifndef HAVE_GETADDRINFO
|
#ifndef HAVE_GETADDRINFO
|
||||||
# include "compat/getaddrinfo.h"
|
# include "compat/getaddrinfo.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -120,9 +119,6 @@ static struct sudo_nss_list *snl;
|
|||||||
int NewArgc;
|
int NewArgc;
|
||||||
char **NewArgv;
|
char **NewArgv;
|
||||||
|
|
||||||
/* Declared here instead of plugin_error.c for static sudo builds. */
|
|
||||||
sigjmp_buf error_jmp;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
sudoers_policy_init(void *info, char * const envp[])
|
sudoers_policy_init(void *info, char * const envp[])
|
||||||
{
|
{
|
||||||
@@ -905,12 +901,12 @@ cb_runas_default(const char *user)
|
|||||||
* Cleanup hook for error()/errorx()
|
* Cleanup hook for error()/errorx()
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
sudoers_plugin_cleanup(int gotsignal)
|
sudoers_cleanup(int gotsignal)
|
||||||
{
|
{
|
||||||
struct sudo_nss *nss;
|
struct sudo_nss *nss;
|
||||||
|
|
||||||
if (!gotsignal) {
|
if (!gotsignal) {
|
||||||
debug_decl(sudoers_plugin_cleanup, SUDO_DEBUG_PLUGIN)
|
debug_decl(sudoers_cleanup, SUDO_DEBUG_PLUGIN)
|
||||||
if (snl != NULL) {
|
if (snl != NULL) {
|
||||||
tq_foreach_fwd(snl, nss)
|
tq_foreach_fwd(snl, nss)
|
||||||
nss->close(nss);
|
nss->close(nss);
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#define _SUDO_SUDOERS_H
|
#define _SUDO_SUDOERS_H
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <setjmp.h>
|
||||||
#ifdef HAVE_STDBOOL_H
|
#ifdef HAVE_STDBOOL_H
|
||||||
# include <stdbool.h>
|
# include <stdbool.h>
|
||||||
#else
|
#else
|
||||||
@@ -352,7 +353,7 @@ char *fmt_string(const char *, const char *);
|
|||||||
FILE *open_sudoers(const char *, bool, bool *);
|
FILE *open_sudoers(const char *, bool, bool *);
|
||||||
int sudoers_policy_init(void *info, char * const envp[]);
|
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);
|
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 */
|
/* policy.c */
|
||||||
int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group);
|
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 */
|
/* setgroups.c */
|
||||||
int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
|
int sudo_setgroups(int ngids, const GETGROUPS_T *gids);
|
||||||
|
|
||||||
|
/* plugin_error.c */
|
||||||
|
extern sigjmp_buf error_jmp;
|
||||||
|
|
||||||
#ifndef _SUDO_MAIN
|
#ifndef _SUDO_MAIN
|
||||||
extern struct sudo_user sudo_user;
|
extern struct sudo_user sudo_user;
|
||||||
extern struct passwd *list_pw;
|
extern struct passwd *list_pw;
|
||||||
|
Reference in New Issue
Block a user