Move warn/error into common and make static builds work.

This commit is contained in:
Todd C. Miller
2012-11-25 09:34:40 -05:00
parent c2c6616a0c
commit 2632ec7e69
22 changed files with 202 additions and 266 deletions

View File

@@ -11,6 +11,7 @@ common/Makefile.in
common/aix.c
common/alloc.c
common/atobool.c
common/error.c
common/fileops.c
common/fmt_string.c
common/lbuf.c
@@ -194,7 +195,6 @@ plugins/sudoers/match_addr.c
plugins/sudoers/mkdefaults
plugins/sudoers/parse.c
plugins/sudoers/parse.h
plugins/sudoers/plugin_error.c
plugins/sudoers/po/README
plugins/sudoers/po/da.mo
plugins/sudoers/po/da.po
@@ -296,13 +296,13 @@ pp
src/Makefile.in
src/conversation.c
src/env_hooks.c
src/error.c
src/exec.c
src/exec_common.c
src/exec_pty.c
src/get_pty.c
src/hooks.c
src/load_plugins.c
src/locale_stub.c
src/net_ifs.c
src/openbsd.c
src/parse_args.c

View File

@@ -57,7 +57,7 @@ DEFS = @OSDEFS@ -D_PATH_SUDO_CONF=\"$(sysconfdir)/sudo.conf\"
SHELL = @SHELL@
LTOBJS = alloc.lo atobool.lo fileops.lo fmt_string.lo lbuf.lo list.lo \
LTOBJS = alloc.lo atobool.lo error.lo fileops.lo fmt_string.lo lbuf.lo list.lo \
secure_path.lo setgroups.lo sudo_conf.lo sudo_debug.lo sudo_printf.lo \
term.lo ttysize.lo zero_bytes.lo @COMMON_OBJS@
@@ -118,6 +118,10 @@ alloc.lo: $(srcdir)/alloc.c $(top_builddir)/config.h $(incdir)/missing.h \
atobool.lo: $(srcdir)/atobool.c $(top_builddir)/config.h $(incdir)/missing.h \
$(incdir)/sudo_debug.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/atobool.c
error.lo: $(srcdir)/error.c $(top_builddir)/config.h \
$(top_srcdir)/compat/stdbool.h $(incdir)/missing.h $(incdir)/alloc.h \
$(incdir)/error.h $(incdir)/sudo_plugin.h $(incdir)/gettext.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/error.c
fileops.lo: $(srcdir)/fileops.c $(top_builddir)/config.h \
$(top_srcdir)/compat/stdbool.h $(top_srcdir)/compat/timespec.h \
$(incdir)/missing.h $(incdir)/fileops.h $(incdir)/sudo_debug.h
@@ -148,11 +152,11 @@ sudo_conf.lo: $(srcdir)/sudo_conf.c $(top_builddir)/config.h \
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/sudo_conf.c
sudo_debug.lo: $(srcdir)/sudo_debug.c $(top_builddir)/config.h \
$(top_srcdir)/compat/stdbool.h $(incdir)/missing.h \
$(incdir)/alloc.h $(incdir)/error.h $(incdir)/gettext.h \
$(incdir)/sudo_plugin.h $(incdir)/sudo_debug.h
$(incdir)/alloc.h $(incdir)/error.h $(incdir)/sudo_plugin.h \
$(incdir)/sudo_debug.h $(incdir)/gettext.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/sudo_debug.c
sudo_printf.lo: $(srcdir)/sudo_printf.c $(top_builddir)/config.h \
$(incdir)/sudo_plugin.h
$(incdir)/sudo_plugin.h $(incdir)/sudo_debug.h
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/sudo_printf.c
term.lo: $(srcdir)/term.c $(top_builddir)/config.h $(incdir)/missing.h \
$(incdir)/sudo_debug.h

View File

@@ -32,17 +32,32 @@
#include "missing.h"
#include "alloc.h"
#include "error.h"
#include "logging.h"
#include "sudo_plugin.h"
#define DEFAULT_TEXT_DOMAIN "sudoers"
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "gettext.h"
static void _warning(int, const char *, va_list);
void sudoers_cleanup(int);
static sigjmp_buf error_jmp;
static bool setjmp_enabled = false;
static struct sudo_error_callback {
void (*func)(void);
struct sudo_error_callback *next;
} *callbacks;
static void _warning(int, const char *, va_list);
static void
do_cleanup(void)
{
struct sudo_error_callback *cb;
/* Run callbacks, removing them from the list as we go. */
while ((cb = callbacks) != NULL) {
callbacks = cb->next;
cb->func();
free(cb);
}
}
void
error2(int eval, const char *fmt, ...)
@@ -52,7 +67,7 @@ error2(int eval, const char *fmt, ...)
va_start(ap, fmt);
_warning(1, fmt, ap);
va_end(ap);
sudoers_cleanup(0);
do_cleanup();
if (setjmp_enabled)
siglongjmp(error_jmp, eval);
else
@@ -67,7 +82,7 @@ errorx2(int eval, const char *fmt, ...)
va_start(ap, fmt);
_warning(0, fmt, ap);
va_end(ap);
sudoers_cleanup(0);
do_cleanup();
if (setjmp_enabled)
siglongjmp(error_jmp, eval);
else
@@ -78,7 +93,7 @@ void
verror2(int eval, const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
sudoers_cleanup(0);
do_cleanup();
if (setjmp_enabled)
siglongjmp(error_jmp, eval);
else
@@ -89,7 +104,7 @@ void
verrorx2(int eval, const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
sudoers_cleanup(0);
do_cleanup();
if (setjmp_enabled)
siglongjmp(error_jmp, eval);
else
@@ -150,18 +165,19 @@ _warning(int use_errno, const char *fmt, va_list ap)
errno = serrno;
}
static int oldlocale;
void
warning_set_locale(void)
int
error_callback_register(void (*func)(void))
{
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
}
struct sudo_error_callback *cb;
void
warning_restore_locale(void)
{
sudoers_setlocale(oldlocale, NULL);
cb = malloc(sizeof(*cb));
if (cb == NULL)
return -1;
cb->func = func;
cb->next = callbacks;
callbacks = cb;
return 0;
}
int

View File

@@ -36,40 +36,34 @@ int
_sudo_printf(int msg_type, const char *fmt, ...)
{
va_list ap;
FILE *fp;
int len;
char *buf;
int len = -1;
switch (msg_type) {
case SUDO_CONV_INFO_MSG:
fp = stdout;
va_start(ap, fmt);
len = vfprintf(stdout, fmt, ap);
va_end(ap);
break;
case SUDO_CONV_ERROR_MSG:
fp = stderr;
va_start(ap, fmt);
len = vfprintf(stderr, fmt, ap);
va_end(ap);
break;
case SUDO_CONV_DEBUG_MSG:
{
char *buf;
va_list ap;
/* XXX - add debug version of vfprintf()? */
va_start(ap, fmt);
len = vasprintf(&buf, fmt, ap);
va_end(ap);
if (len == -1)
return -1;
if (len != -1)
sudo_debug_write(buf, len, 0);
break;
}
default:
errno = EINVAL;
return -1;
break;
}
va_start(ap, fmt);
len = vfprintf(fp, fmt, ap);
va_end(ap);
return len;
}
int (*sudo_printf)(int msg_type, const char *fmt, ...) = _sudo_printf;
sudo_printf_t sudo_printf = _sudo_printf;

4
configure vendored
View File

@@ -20191,13 +20191,13 @@ case "$lt_cv_dlopen" in
dlopen)
$as_echo "#define HAVE_DLOPEN 1" >>confdefs.h
SUDOERS_OBJS="$SUDOERS_OBJS plugin_error.lo"
SUDO_OBJS="$SUDO_OBJS locale_stub.lo"
LT_STATIC="--tag=disable-static"
;;
shl_load)
$as_echo "#define HAVE_SHL_LOAD 1" >>confdefs.h
SUDOERS_OBJS="$SUDOERS_OBJS plugin_error.lo"
SUDO_OBJS="$SUDO_OBJS locale_stub.lo"
LT_STATIC="--tag=disable-static"
case " $LIBOBJS " in
*" dlopen.$ac_objext "* ) ;;

View File

@@ -3208,12 +3208,12 @@ fi
case "$lt_cv_dlopen" in
dlopen)
AC_DEFINE(HAVE_DLOPEN)
SUDOERS_OBJS="$SUDOERS_OBJS plugin_error.lo"
SUDO_OBJS="$SUDO_OBJS locale_stub.lo"
LT_STATIC="--tag=disable-static"
;;
shl_load)
AC_DEFINE(HAVE_SHL_LOAD)
SUDOERS_OBJS="$SUDOERS_OBJS plugin_error.lo"
SUDO_OBJS="$SUDO_OBJS locale_stub.lo"
LT_STATIC="--tag=disable-static"
AC_LIBOBJ(dlopen)
;;

View File

@@ -18,7 +18,6 @@
#define _SUDO_ERROR_H_
#include <stdarg.h>
#include <sudo_plugin.h>
/*
* We wrap error/errorx and warn/warnx so that the same output can
@@ -171,8 +170,9 @@
warning_restore_locale(); \
} while (0)
extern sudo_printf_t sudo_printf;
extern int (*sudo_printf)(int msg_type, const char *fmt, ...);
int error_callback_register(void (*func)(void));
void error2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
void errorx2(int, const char *, ...) __printflike(2, 3) __attribute__((__noreturn__));
void verror2(int, const char *, va_list ap) __attribute__((__noreturn__));

View File

@@ -52,7 +52,7 @@ sub mkdep {
$makefile =~ s:\@DEV\@::g;
$makefile =~ s:\@COMMON_OBJS\@:aix.lo:;
$makefile =~ s:\@SUDO_OBJS\@:openbsd.o preload.o selinux.o sesh.o solaris.o sudo_noexec.lo:;
$makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo plugin_error.lo sssd.lo:;
$makefile =~ s:\@SUDOERS_OBJS\@:bsm_audit.lo linux_audit.lo ldap.lo sssd.lo:;
# XXX - fill in AUTH_OBJS from contents of the auth dir instead
$makefile =~ s:\@AUTH_OBJS\@:afs.lo aix_auth.lo bsdauth.lo dce.lo fwtk.lo getspwuid.lo kerb5.lo pam.lo passwd.lo rfc1938.lo secureware.lo securid5.lo sia.lo:;
$makefile =~ s:\@LTLIBOBJS\@:closefrom.lo dlopen.lo fnmatch.lo getcwd.lo getgrouplist.lo getline.lo getprogname.lo glob.lo isblank.lo memrchr.lo mksiglist.lo mksigname.lo mktemp.lo nanosleep.lo pw_dup.lo sig2str.lo siglist.lo signame.lo snprintf.lo strlcat.lo strlcpy.lo strsignal.lo utimes.lo globtest.o fnm_test.o:;

View File

@@ -133,23 +133,23 @@ SUDOERS_OBJS = $(AUTH_OBJS) boottime.lo check.lo env.lo find_path.lo \
policy.lo prompt.lo set_perms.lo sudo_nss.lo sudoers.lo \
timestamp.lo @SUDOERS_OBJS@
VISUDO_OBJS = find_path.o goodpath.o locale.o plugin_error.o visudo.o
VISUDO_OBJS = find_path.o goodpath.o locale.o visudo.o
REPLAY_OBJS = getdate.o locale.o plugin_error.o sudoreplay.o
REPLAY_OBJS = getdate.o locale.o sudoreplay.o
TEST_OBJS = group_plugin.o interfaces.o locale.o net_ifs.o plugin_error.o \
TEST_OBJS = group_plugin.o interfaces.o locale.o net_ifs.o \
testsudoers.o tsgetgrpw.o
CHECK_ADDR_OBJS = check_addr.o interfaces.o locale.o match_addr.o plugin_error.o
CHECK_ADDR_OBJS = check_addr.o interfaces.o locale.o match_addr.o
CHECK_FILL_OBJS = check_fill.o locale.o plugin_error.o toke_util.o
CHECK_FILL_OBJS = check_fill.o locale.o toke_util.o
CHECK_IOLOG_PATH_OBJS = check_iolog_path.o iolog_path.o locale.o \
plugin_error.o pwutil.o pwutil_impl.o redblack.o
pwutil.o pwutil_impl.o redblack.o
CHECK_SYMBOLS_OBJS = check_symbols.o locale.o plugin_error.o
CHECK_SYMBOLS_OBJS = check_symbols.o locale.o
CHECK_WRAP_OBJS = check_wrap.o locale.o logwrap.o plugin_error.o
CHECK_WRAP_OBJS = check_wrap.o locale.o logwrap.o
LIBOBJDIR = $(top_builddir)/@ac_config_libobj_dir@/
@@ -464,9 +464,9 @@ check_addr.o: $(srcdir)/regress/parser/check_addr.c $(top_builddir)/config.h \
$(srcdir)/interfaces.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/regress/parser/check_addr.c
check_fill.o: $(srcdir)/regress/parser/check_fill.c $(top_builddir)/config.h \
$(top_srcdir)/compat/stdbool.h $(incdir)/list.h \
$(srcdir)/parse.h $(srcdir)/toke.h $(incdir)/sudo_plugin.h \
$(devdir)/gram.h
$(top_srcdir)/compat/stdbool.h $(incdir)/missing.h \
$(incdir)/list.h $(srcdir)/parse.h $(srcdir)/toke.h \
$(incdir)/sudo_plugin.h $(devdir)/gram.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/regress/parser/check_fill.c
check_iolog_path.o: $(srcdir)/regress/iolog_path/check_iolog_path.c \
$(top_builddir)/config.h $(srcdir)/sudoers.h \
@@ -676,12 +676,6 @@ passwd.lo: $(authdir)/passwd.c $(top_builddir)/config.h $(srcdir)/sudoers.h \
$(devdir)/def_data.h $(srcdir)/logging.h $(srcdir)/sudo_nss.h \
$(incdir)/sudo_plugin.h $(incdir)/sudo_debug.h $(incdir)/gettext.h
$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(authdir)/passwd.c
plugin_error.lo: $(srcdir)/plugin_error.c $(top_builddir)/config.h \
$(top_srcdir)/compat/stdbool.h $(incdir)/missing.h \
$(incdir)/alloc.h $(incdir)/error.h $(srcdir)/logging.h \
$(incdir)/sudo_plugin.h $(incdir)/gettext.h
$(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/plugin_error.c
plugin_error.o: plugin_error.lo
policy.lo: $(srcdir)/policy.c $(top_builddir)/config.h $(srcdir)/sudoers.h \
$(top_srcdir)/compat/stdbool.h $(top_builddir)/pathnames.h \
$(incdir)/missing.h $(incdir)/error.h $(incdir)/alloc.h \

View File

@@ -98,3 +98,17 @@ sudoers_setlocale(int newlocale, int *prevlocale)
}
return res ? true : false;
}
static int warning_locale;
void
warning_set_locale(void)
{
sudoers_setlocale(SUDOERS_LOCALE_USER, &warning_locale);
}
void
warning_restore_locale(void)
{
sudoers_setlocale(warning_locale, NULL);
}

View File

@@ -525,7 +525,7 @@ log_fatal(int flags, const char *fmt, ...)
va_end(ap);
/* Exit the plugin. */
sudoers_cleanup(0);
sudoers_cleanup();
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
plugin_longjmp(1);
}

View File

@@ -579,7 +579,7 @@ sudoers_policy_invalidate(int remove)
user_cmnd = "kill";
if (plugin_setjmp() == 0) {
remove_timestamp(remove);
sudoers_cleanup(0);
sudoers_cleanup();
}
plugin_clearjmp();

View File

@@ -131,6 +131,9 @@ sudoers_policy_init(void *info, char * const envp[])
sudo_setpwent();
sudo_setgrent();
/* Register error/errorx callback. */
error_callback_register(sudoers_cleanup);
/* Initialize environment functions (including replacements). */
env_init(envp);
@@ -901,7 +904,6 @@ cb_runas_default(const char *user)
return true;
}
/*
/*
* Callback for sudoers_locale sudoers setting.
*/
@@ -916,12 +918,11 @@ cb_sudoers_locale(const char *locale)
* Cleanup hook for error()/errorx()
*/
void
sudoers_cleanup(int gotsignal)
sudoers_cleanup(void)
{
struct sudo_nss *nss;
if (!gotsignal) {
debug_decl(sudoers_cleanup, SUDO_DEBUG_PLUGIN)
if (snl != NULL) {
tq_foreach_fwd(snl, nss)
nss->close(nss);
@@ -930,8 +931,8 @@ sudoers_cleanup(int gotsignal)
group_plugin_unload();
sudo_endpwent();
sudo_endgrent();
debug_return;
}
}
static char *

View File

@@ -350,7 +350,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_cleanup(int);
void sudoers_cleanup(void);
/* policy.c */
int sudoers_policy_deserialize_info(void *v, char **runas_user, char **runas_group);

View File

@@ -200,7 +200,6 @@ extern char *get_timestr(time_t, int);
extern int term_raw(int, int);
extern int term_restore(int, int);
extern void get_ttysize(int *rowp, int *colp);
void sudoers_cleanup(int);
static int list_sessions(int, char **, const char *, const char *, const char *);
static int parse_expr(struct search_node **, char **);
@@ -213,6 +212,8 @@ static int parse_timing(const char *buf, const char *decimal, int *idx, double *
static struct log_info *parse_logfile(char *logfile);
static void free_log_info(struct log_info *li);
static size_t atomic_writev(int fd, struct iovec *iov, int iovcnt);
static void sudoreplay_handler(int);
static void sudoreplay_cleanup(void);
#ifdef HAVE_REGCOMP
# define REGEX_T regex_t
@@ -267,6 +268,9 @@ main(int argc, char *argv[])
bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have sudoreplay domain */
textdomain("sudoers");
/* Register error/errorx callback. */
error_callback_register(sudoreplay_cleanup);
/* Read sudo.conf. */
sudo_conf_read();
@@ -376,7 +380,7 @@ main(int argc, char *argv[])
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESETHAND;
sa.sa_handler = sudoers_cleanup;
sa.sa_handler = sudoreplay_handler;
(void) sigaction(SIGINT, &sa, NULL);
(void) sigaction(SIGKILL, &sa, NULL);
(void) sigaction(SIGTERM, &sa, NULL);
@@ -1205,10 +1209,19 @@ help(void)
/*
* Cleanup hook for error()/errorx()
*/
void
sudoers_cleanup(int signo)
static void
sudoreplay_cleanup(void)
{
term_restore(STDIN_FILENO, 0);
}
/*
* Signal handler for SIGINT, SIGKILL, SIGTERM, SIGHUP
* Must be installed with SA_RESETHAND enabled.
*/
static void
sudoreplay_handler(int signo)
{
term_restore(STDIN_FILENO, 0);
if (signo)
kill(getpid(), signo);
}

View File

@@ -78,7 +78,6 @@ void print_defaults(void);
void print_privilege(struct privilege *);
void print_userspecs(void);
void usage(void) __attribute__((__noreturn__));
void sudoers_cleanup(int);
static void set_runaspw(const char *);
static void set_runasgr(const char *);
static int cb_runas_default(const char *);
@@ -465,15 +464,6 @@ restore_perms(void)
{
}
void
sudoers_cleanup(int gotsignal)
{
if (!gotsignal) {
sudo_endpwent();
sudo_endgrent();
}
}
void
print_member(struct member *m)
{

View File

@@ -36,6 +36,7 @@
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
#ifndef __TANDEM
# include <sys/file.h>
#endif
@@ -108,8 +109,7 @@ static int run_command(char *, char **);
static void setup_signals(void);
static void help(void) __attribute__((__noreturn__));
static void usage(int);
void sudoers_cleanup(int);
static void visudo_cleanup(void);
extern void sudoerserror(const char *);
extern void sudoersrestart(FILE *);
@@ -164,6 +164,9 @@ main(int argc, char *argv[])
if (argc < 1)
usage(1);
/* Register error/errorx callback. */
error_callback_register(visudo_cleanup);
/* Read sudo.conf. */
sudo_conf_read();
@@ -506,7 +509,7 @@ reparse_sudoers(char *editor, char *args, bool strict, bool quiet)
case 'Q' : parse_error = false; /* ignore parse error */
break;
case 'x' : /* XXX - should return instead of exiting */
sudoers_cleanup(0);
visudo_cleanup();
sudo_debug_exit_int(__func__, __FILE__,
__LINE__, sudo_debug_subsys, 0);
exit(0);
@@ -1249,8 +1252,8 @@ print_unused(void *v1, void *v2)
/*
* Unlink any sudoers temp files that remain.
*/
void
sudoers_cleanup(int gotsignal)
static void
visudo_cleanup(void)
{
struct sudoersfile *sp;
@@ -1258,10 +1261,8 @@ sudoers_cleanup(int gotsignal)
if (sp->tpath != NULL)
(void) unlink(sp->tpath);
}
if (!gotsignal) {
sudo_endpwent();
sudo_endgrent();
}
}
/*
@@ -1270,16 +1271,24 @@ sudoers_cleanup(int gotsignal)
static void
quit(int signo)
{
const char *signame, *myname;
struct sudoersfile *sp;
struct iovec iov[4];
tq_foreach_fwd(&sudoerslist, sp) {
if (sp->tpath != NULL)
(void) unlink(sp->tpath);
}
sudoers_cleanup(signo);
#define emsg " exiting due to signal: "
myname = getprogname();
signame = strsignal(signo);
ignore_result(write(STDERR_FILENO, myname, strlen(myname)));
ignore_result(write(STDERR_FILENO, emsg, sizeof(emsg) - 1));
ignore_result(write(STDERR_FILENO, signame, strlen(signame)));
ignore_result(write(STDERR_FILENO, "\n", 1));
iov[0].iov_base = (char *)getprogname();
iov[0].iov_len = strlen(iov[0].iov_base);
iov[1].iov_base = emsg;
iov[1].iov_len = sizeof(emsg) - 1;
iov[2].iov_base = strsignal(signo);
iov[2].iov_len = strlen(iov[2].iov_base);
iov[3].iov_base = "\n";
iov[3].iov_len = 1;
ignore_result(writev(STDERR_FILENO, iov, 4));
_exit(signo);
}

View File

@@ -80,9 +80,9 @@ SHELL = @SHELL@
PROGS = @PROGS@
OBJS = conversation.o env_hooks.o error.o exec.o exec_common.o exec_pty.o \
get_pty.o hooks.o net_ifs.o load_plugins.o parse_args.o sudo.o \
sudo_edit.o tgetpass.o ttyname.o utmp.o @SUDO_OBJS@
OBJS = conversation.o env_hooks.o exec.o exec_common.o exec_pty.o get_pty.o \
hooks.o net_ifs.o load_plugins.o parse_args.o sudo.o sudo_edit.o \
tgetpass.o ttyname.o utmp.o @SUDO_OBJS@
LIBOBJDIR = $(top_builddir)/@ac_config_libobj_dir@/
@@ -107,8 +107,8 @@ sudo: $(OBJS) $(LT_LIBS)
libsudo_noexec.la: sudo_noexec.lo
$(LIBTOOL) --mode=link $(CC) $(LDFLAGS) $(LT_LDFLAGS) -o $@ sudo_noexec.lo -avoid-version -rpath $(noexecdir)
sesh: sesh.o error.o exec_common.o @LIBINTL@ $(LT_LIBS)
$(LIBTOOL) --mode=link $(CC) -o $@ sesh.o error.o exec_common.o $(LDFLAGS) $(PIE_LDFLAGS) @LIBINTL@ $(LIBS)
sesh: sesh.o locale_stub.o exec_common.o @LIBINTL@ $(LT_LIBS)
$(LIBTOOL) --mode=link $(CC) -o $@ sesh.o locale_stub.o exec_common.o $(LDFLAGS) $(PIE_LDFLAGS) @LIBINTL@ $(LIBS)
pre-install:
@@ -174,9 +174,6 @@ env_hooks.o: $(srcdir)/env_hooks.c $(top_builddir)/config.h \
$(incdir)/list.h $(incdir)/sudo_debug.h $(incdir)/gettext.h \
$(incdir)/sudo_plugin.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/env_hooks.c
error.o: $(srcdir)/error.c $(top_builddir)/config.h $(incdir)/missing.h \
$(incdir)/error.h $(incdir)/gettext.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/error.c
exec.o: $(srcdir)/exec.c $(top_builddir)/config.h $(srcdir)/sudo.h \
$(top_builddir)/pathnames.h $(top_srcdir)/compat/stdbool.h \
$(incdir)/missing.h $(incdir)/alloc.h $(incdir)/error.h \
@@ -223,6 +220,9 @@ load_plugins.o: $(srcdir)/load_plugins.c $(top_builddir)/config.h \
$(incdir)/sudo_plugin.h $(srcdir)/sudo_plugin_int.h \
$(incdir)/sudo_conf.h $(incdir)/list.h $(incdir)/sudo_debug.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/load_plugins.c
locale_stub.o: $(srcdir)/locale_stub.c $(top_builddir)/config.h \
$(incdir)/missing.h $(incdir)/error.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/locale_stub.c
net_ifs.o: $(srcdir)/net_ifs.c $(top_builddir)/config.h $(incdir)/missing.h \
$(incdir)/alloc.h $(incdir)/error.h $(incdir)/sudo_debug.h \
$(incdir)/gettext.h

View File

@@ -1,131 +0,0 @@
/*
* Copyright (c) 2004-2005, 2010-2012 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "missing.h"
#include "error.h"
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "gettext.h"
static void _warning(int, const char *, va_list);
void cleanup(int);
void
error2(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_warning(1, fmt, ap);
va_end(ap);
cleanup(0);
exit(eval);
}
void
errorx2(int eval, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_warning(0, fmt, ap);
va_end(ap);
cleanup(0);
exit(eval);
}
void
verror2(int eval, const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
cleanup(0);
exit(eval);
}
void
verrorx2(int eval, const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
cleanup(0);
exit(eval);
}
void
warning2(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_warning(1, fmt, ap);
va_end(ap);
}
void
warningx2(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_warning(0, fmt, ap);
va_end(ap);
}
void
vwarning2(const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
}
void
vwarningx2(const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
}
static void
_warning(int use_errno, const char *fmt, va_list ap)
{
int serrno = errno;
fputs(getprogname(), stderr);
if (fmt != NULL) {
fputs(_(": "), stderr);
vfprintf(stderr, fmt, ap);
}
if (use_errno) {
fputs(_(": "), stderr);
fputs(strerror(serrno), stderr);
}
putc('\n', stderr);
}
/* No need to swap locales in the front end. */
void
warning_set_locale(void)
{
return;
}
void
warning_restore_locale(void)
{
return;
}

View File

@@ -121,8 +121,8 @@ static void check_foreground(void);
/*
* Cleanup hook for error()/errorx()
*/
void
cleanup(int gotsignal)
static void
pty_cleanup(void)
{
debug_decl(cleanup, SUDO_DEBUG_EXEC);
@@ -1294,6 +1294,9 @@ exec_pty(struct command_details *details, int *errfd)
pid_t self = getpid();
debug_decl(exec_pty, SUDO_DEBUG_EXEC);
/* Register cleanup function */
error_callback_register(pty_cleanup);
/* Set command process group here too to avoid a race. */
setpgid(0, self);

38
src/locale_stub.c Normal file
View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <config.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "missing.h"
#include "error.h"
/* No need to swap locales in the front end. */
void
warning_set_locale(void)
{
return;
}
void
warning_restore_locale(void)
{
return;
}

View File

@@ -42,15 +42,6 @@
__dso_public int main(int argc, char *argv[], char *envp[]);
/*
* Cleanup hook for error()/errorx()
*/
void
cleanup(int gotsignal)
{
return;
}
int
main(int argc, char *argv[], char *envp[])
{