]> granicus.if.org Git - sudo/commitdiff
Move warn/error into common and make static builds work.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 25 Nov 2012 14:34:40 +0000 (09:34 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sun, 25 Nov 2012 14:34:40 +0000 (09:34 -0500)
22 files changed:
MANIFEST
common/Makefile.in
common/error.c [moved from plugins/sudoers/plugin_error.c with 82% similarity]
common/sudo_printf.c
configure
configure.in
include/error.h
mkdep.pl
plugins/sudoers/Makefile.in
plugins/sudoers/locale.c
plugins/sudoers/logging.c
plugins/sudoers/policy.c
plugins/sudoers/sudoers.c
plugins/sudoers/sudoers.h
plugins/sudoers/sudoreplay.c
plugins/sudoers/testsudoers.c
plugins/sudoers/visudo.c
src/Makefile.in
src/error.c [deleted file]
src/exec_pty.c
src/locale_stub.c [new file with mode: 0644]
src/sesh.c

index 534b1bfc0da8c05719a4174dd1668bdc31b898d8..48454ecac0261cf27fd54140ba47d88fbdcc2fe4 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -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
index 099768bdd2f45078a1dfb5939194d2f3139044c5..dd0c3cc314814f3c3689bddb44888f9a8d5e80be 100644 (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
similarity index 82%
rename from plugins/sudoers/plugin_error.c
rename to common/error.c
index 55723df86df1bd25429e7da850bb407e10334044..fd6cd85b5b9844d9fc20bc0052aee484f6022675 100644 (file)
 #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
index e794eb7933d08324ac5ddf1c24015c613b28a23c..bf3e812f6e9218d4afc52208a46322c5649caf93 100644 (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;
-       sudo_debug_write(buf, len, 0);
+       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;
index d3b8c62e8baacabcb1bb5b682c4f2de3e0c495dd..f715b4d5642227793a424450a6afaabfcdc64dd1 100755 (executable)
--- a/configure
+++ b/configure
@@ -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 "* ) ;;
index 3d0f0af6fab0087934d4e1ac3857008ee1af0838..d63e91c68c5becd161b2727f0f36a18b90641437 100644 (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)
        ;;
index 7c293be306315f81231b87fee71017e9b3e44e7e..8d80cf7fd758d04b9cd6ec688dd35b84b9c56090 100644 (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
     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__));
index 0521e336d9dcaac44cce0aff89e10f58d625f2c3..519e22b0f7ff782ac20d8731820f3561fac7abfc 100755 (executable)
--- a/mkdep.pl
+++ b/mkdep.pl
@@ -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:;
index 9317d8aee235e3bfb788db35568210ec85d4ee1a..1dc8d213233d18ab8332e513f794d81ee3c4c4f2 100644 (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 \
index 4244b2f5247efc8582221591eb8f3bbbef1422fa..197c09fd4e6efe1d5de56c923e4997c2e3e1fe3e 100644 (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);
+}
index 6c62c3a38c662a43478b6926b163c7cb34aa6b83..3aed994b024c2162a3a11e3c76bce6f730271760 100644 (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);
 }
index 566bf6f7c764f786fdab35ea65a355a2074b13ff..eaf49b129d805a0c139848ccd64b038e58af72e3 100644 (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();
 
index 8dc2220e5f3b0dddce5f1818bafe538303d740d7..a35df036d82eb40deee8b4c3b950d3dcea7b7ff9 100644 (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,22 +918,21 @@ cb_sudoers_locale(const char *locale)
  * Cleanup hook for error()/errorx()
  */
 void
-sudoers_cleanup(int gotsignal)
+sudoers_cleanup(void)
 {
     struct sudo_nss *nss;
+    debug_decl(sudoers_cleanup, SUDO_DEBUG_PLUGIN)
 
-    if (!gotsignal) {
-       debug_decl(sudoers_cleanup, SUDO_DEBUG_PLUGIN)
-       if (snl != NULL) {
-           tq_foreach_fwd(snl, nss)
-               nss->close(nss);
-       }
-       if (def_group_plugin)
-           group_plugin_unload();
-       sudo_endpwent();
-       sudo_endgrent();
-       debug_return;
+    if (snl != NULL) {
+       tq_foreach_fwd(snl, nss)
+           nss->close(nss);
     }
+    if (def_group_plugin)
+       group_plugin_unload();
+    sudo_endpwent();
+    sudo_endgrent();
+
+    debug_return;
 }
 
 static char *
index 1b5eafb79bef19c5ee246a47ddc44e56cfd914b4..3acf6daecaaa7e409121ad9e6ecff060cf7f2d97 100644 (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);
index 251c196ec198143a8fed7639cea8955c227ce842..fa08b4720991ad670a39a02e68dcccd3a546495f 100644 (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);
+    kill(getpid(), signo);
 }
index 5fb11f7492984bf0bb03a4132034aa2a4cf194ce..bf1a16aab1399c5e46867809333056ad66b7a665 100644 (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)
 {
index adb42c8179d94a4ffc46d1e1d28e812082e55888..6ed97edd0525e1177d45716705e4d3fef659209c 100644 (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();
-    }
+    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);
 }
 
index b9ba1d82d377c02e9ba2866fba54240ce97ade43..e26f1e0f826059e1b53a80d34ee8415bc878a5f8 100644 (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
diff --git a/src/error.c b/src/error.c
deleted file mode 100644 (file)
index ee758a0..0000000
+++ /dev/null
@@ -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;
-}
index 30b4ea0442d7510e22adccfaa6e4027e6ae6b972..98fb557788cccf206c168007fac96d7345de1a02 100644 (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);
 
diff --git a/src/locale_stub.c b/src/locale_stub.c
new file mode 100644 (file)
index 0000000..11edfda
--- /dev/null
@@ -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;
+}
index 76c69d68a8cd8b2f4a9cdfeebb516a017cc5f78f..9b376287f5a3085fe943b375d7ae3d3c4303717c 100644 (file)
 
 __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[])
 {