common/setgroups.c
common/sudo_conf.c
common/sudo_debug.c
+common/sudo_printf.c
common/term.c
common/ttysize.c
common/zero_bytes.c
SHELL = @SHELL@
LTOBJS = alloc.lo atobool.lo fileops.lo fmt_string.lo lbuf.lo list.lo \
- secure_path.lo setgroups.lo sudo_conf.lo sudo_debug.lo term.lo \
- ttysize.lo zero_bytes.lo @COMMON_OBJS@
+ secure_path.lo setgroups.lo sudo_conf.lo sudo_debug.lo sudo_printf.lo \
+ term.lo ttysize.lo zero_bytes.lo @COMMON_OBJS@
all: libcommon.la
$(incdir)/alloc.h $(incdir)/error.h $(incdir)/gettext.h \
$(incdir)/sudo_plugin.h $(incdir)/sudo_debug.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
+ $(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
$(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/term.c
static char sudo_debug_pidstr[(((sizeof(int) * 8) + 2) / 3) + 3];
static size_t sudo_debug_pidlen;
-extern sudo_conv_t sudo_conv;
-
/*
* Parse settings string from sudo.conf and open debugfile.
* Returns 1 on success, 0 if cannot open debugfile.
sudo_debug_write_conv(const char *func, const char *file, int lineno,
const char *str, int len, int errno_val)
{
- struct sudo_conv_message msg;
- struct sudo_conv_reply repl;
- char *buf = NULL;
-
- /* Call conversation function */
- if (sudo_conv != NULL) {
- /* Remove the newline at the end if appending extra info. */
- if (str[len - 1] == '\n')
- len--;
-
- if (func != NULL && file != NULL && lineno != 0) {
- if (errno_val) {
- easprintf(&buf, "%.*s: %s @ %s() %s:%d", len, str,
- strerror(errno_val), func, file, lineno);
- } else {
- easprintf(&buf, "%.*s @ %s() %s:%d", len, str,
- func, file, lineno);
- }
- str = buf;
- } else if (errno_val) {
- easprintf(&buf, "%.*s: %s", len, str, strerror(errno_val));
- str = buf;
+ /* Remove the newline at the end if appending extra info. */
+ if (str[len - 1] == '\n')
+ len--;
+
+ if (func != NULL && file != NULL && lineno != 0) {
+ if (errno_val) {
+ sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s @ %s() %s:%d",
+ len, str, strerror(errno_val), func, file, lineno);
+ } else {
+ sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s @ %s() %s:%d",
+ len, str, func, file, lineno);
}
- memset(&msg, 0, sizeof(msg));
- memset(&repl, 0, sizeof(repl));
- msg.msg_type = SUDO_CONV_DEBUG_MSG;
- msg.msg = str;
- sudo_conv(1, &msg, &repl);
- if (buf != NULL)
- efree(buf);
+ } else if (errno_val) {
+ sudo_printf(SUDO_CONV_DEBUG_MSG, "%.*s: %s",
+ len, str, strerror(errno_val));
}
}
--- /dev/null
+/*
+ * Copyright (c) 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 <stdio.h>
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
+#endif /* STDC_HEADERS */
+#include <stdarg.h>
+#include <errno.h>
+
+#include "sudo_plugin.h"
+#include "sudo_debug.h"
+
+int
+_sudo_printf(int msg_type, const char *fmt, ...)
+{
+ va_list ap;
+ FILE *fp;
+ int len;
+
+ switch (msg_type) {
+ case SUDO_CONV_INFO_MSG:
+ fp = stdout;
+ break;
+ case SUDO_CONV_ERROR_MSG:
+ fp = stderr;
+ 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);
+ break;
+ }
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+
+ 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;
#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;
+
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__));
$(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) $(srcdir)/locale.c
+locale.o: locale.lo
logging.lo: $(srcdir)/logging.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 \
$(top_srcdir)/compat/timespec.h $(top_srcdir)/compat/stdbool.h \
$(top_builddir)/pathnames.h $(incdir)/missing.h \
$(incdir)/alloc.h $(incdir)/error.h $(incdir)/gettext.h \
- $(incdir)/sudo_plugin.h $(incdir)/sudo_conf.h $(incdir)/list.h \
- $(incdir)/sudo_debug.h
+ $(srcdir)/logging.h $(incdir)/sudo_plugin.h \
+ $(incdir)/sudo_conf.h $(incdir)/list.h $(incdir)/sudo_debug.h
$(CC) -c $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(DEFS) $(srcdir)/sudoreplay.c
testsudoers.o: $(srcdir)/testsudoers.c $(top_builddir)/config.h \
$(top_srcdir)/compat/fnmatch.h $(srcdir)/tsgetgrpw.h \
LEXTRACE("<*> ");
#ifndef TRACELEXER
if (trace_print == NULL || trace_print == sudoers_trace_print) {
- int oldlocale;
const char fmt[] = ">>> %s: %s near line %d <<<\n";
+ int oldlocale;
/* Warnings are displayed in the user's locale. */
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
- if (sudo_conv != NULL) {
- struct sudo_conv_message msg;
- struct sudo_conv_reply repl;
- char *str;
-
- easprintf(&str, _(fmt), sudoers, _(s), sudolineno);
-
- memset(&msg, 0, sizeof(repl));
- memset(&repl, 0, sizeof(repl));
- msg.msg_type = SUDO_CONV_ERROR_MSG;
- msg.msg = str;
- sudo_conv(1, &msg, &repl);
- efree(str);
- } else {
- fprintf(stderr, _(fmt), sudoers, _(s), sudolineno);
- }
+ sudo_printf(SUDO_CONV_ERROR_MSG, _(fmt), sudoers, _(s), sudolineno);
sudoers_setlocale(oldlocale, NULL);
}
#endif
LEXTRACE("<*> ");
#ifndef TRACELEXER
if (trace_print == NULL || trace_print == sudoers_trace_print) {
- int oldlocale;
const char fmt[] = ">>> %s: %s near line %d <<<\n";
+ int oldlocale;
/* Warnings are displayed in the user's locale. */
sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale);
- if (sudo_conv != NULL) {
- struct sudo_conv_message msg;
- struct sudo_conv_reply repl;
- char *str;
-
- easprintf(&str, _(fmt), sudoers, _(s), sudolineno);
-
- memset(&msg, 0, sizeof(repl));
- memset(&repl, 0, sizeof(repl));
- msg.msg_type = SUDO_CONV_ERROR_MSG;
- msg.msg = str;
- sudo_conv(1, &msg, &repl);
- efree(str);
- } else {
- fprintf(stderr, _(fmt), sudoers, _(s), sudolineno);
- }
+ sudo_printf(SUDO_CONV_ERROR_MSG, _(fmt), sudoers, _(s), sudolineno);
sudoers_setlocale(oldlocale, NULL);
}
#endif
int rval = -1;
debug_decl(sudoers_io_open, SUDO_DEBUG_PLUGIN)
- if (!sudo_conv)
- sudo_conv = conversation;
- if (!sudo_printf)
- sudo_printf = plugin_printf;
+ sudo_conv = conversation;
+ sudo_printf = plugin_printf;
/* If we have no command (because -V was specified) just return. */
if (argc == 0)
static sigjmp_buf error_jmp;
static bool setjmp_enabled = false;
-extern sudo_conv_t sudo_conv;
-
void
error2(int eval, const char *fmt, ...)
{
_warning(int use_errno, const char *fmt, va_list ap)
{
int serrno = errno;
+ char *str;
- if (sudo_conv != NULL) {
- struct sudo_conv_message msg[6];
- struct sudo_conv_reply repl[6];
- int nmsgs = 4;
- char *str;
-
- 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);
+ evasprintf(&str, fmt, ap);
+ if (use_errno) {
if (fmt != NULL) {
- fputs(_(": "), stderr);
- vfprintf(stderr, _(fmt), ap);
+ sudo_printf(SUDO_CONV_ERROR_MSG,
+ _("%s: %s: %s\n"), getprogname(), str, strerror(serrno));
+ } else {
+ sudo_printf(SUDO_CONV_ERROR_MSG,
+ _("%s: %s\n"), getprogname(), strerror(serrno));
}
- if (use_errno) {
- fputs(_(": "), stderr);
- fputs(strerror(serrno), stderr);
- }
- putc('\n', stderr);
+ } else {
+ sudo_printf(SUDO_CONV_ERROR_MSG,
+ _("%s: %s\n"), getprogname(), str ? str : "(null)");
}
+ efree(str);
+ errno = serrno;
}
static int oldlocale;
debug_decl(sudoers_policy_open, SUDO_DEBUG_PLUGIN)
sudo_version = version;
- if (!sudo_conv)
- sudo_conv = conversation;
- if (!sudo_printf)
- sudo_printf = plugin_printf;
+ sudo_conv = conversation;
+ sudo_printf = plugin_printf;
/* Plugin args are only specified for API version 1.2 and higher. */
if (sudo_version < SUDO_API_MKVERSION(1, 2))
}
void
-cleanup(int gotsig)
+sudoers_cleanup(int gotsig)
{
return;
}
struct sudo_user sudo_user;
struct passwd *list_pw;
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
static char sessid[7];
}
void
-cleanup(int gotsig)
+sudoers_cleanup(int gotsig)
{
return;
}
#include "error.h"
#include "sudo_plugin.h"
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
extern void writeln_wrap(FILE *fp, char *line, size_t len, size_t maxlen);
__dso_public int main(int argc, char *argv[]);
}
void
-cleanup(int gotsig)
+sudoers_cleanup(int gotsig)
{
return;
}
struct interface *interfaces;
sudo_printf_t sudo_printf = check_addr_printf;
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
static int
check_addr(char *input)
{
/* STUB */
void
-cleanup(int gotsig)
+sudoers_cleanup(int gotsig)
{
return;
}
#define SUDO_ERROR_WRAP 0
+#include "missing.h"
#include "list.h"
#include "parse.h"
#include "toke.h"
* TODO: test realloc
*/
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
YYSTYPE sudoerslval;
struct fill_test {
/* STUB */
void
-cleanup(int gotsig)
+sudoers_cleanup(int gotsig)
{
return;
}
char *login_style;
#endif /* HAVE_BSD_AUTH_H */
sudo_conv_t sudo_conv;
-sudo_printf_t sudo_printf;
int sudo_mode;
static char *prev_user;
} u;
} *search_expr;
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
#define STACK_NODE_SIZE 32
static struct search_node *node_stack[32];
static int stack_top;
static void set_runaspw(const char *);
static void set_runasgr(const char *);
static int cb_runas_default(const char *);
-static int testsudoers_printf(int msg_type, const char *fmt, ...);
static int testsudoers_print(const char *msg);
extern void setgrfile(const char *);
extern int errorlineno;
extern bool parse_error;
extern char *errorfile;
-sudo_printf_t sudo_printf = testsudoers_printf;
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
/* For getopt(3) */
extern char *optarg;
debug_return;
}
-static int
-testsudoers_printf(int msg_type, const char *fmt, ...)
-{
- va_list ap;
- FILE *fp;
- debug_decl(testsudoers_printf, SUDO_DEBUG_UTIL)
-
- switch (msg_type) {
- case SUDO_CONV_INFO_MSG:
- fp = stdout;
- break;
- case SUDO_CONV_ERROR_MSG:
- fp = stderr;
- break;
- default:
- errno = EINVAL;
- debug_return_int(-1);
- }
-
- va_start(ap, fmt);
- vfprintf(fp, fmt, ap);
- va_end(ap);
-
- debug_return_int(0);
-}
-
void
dump_sudoers(void)
{
};
TQ_DECLARE(sudoersfile)
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
/*
* Function prototypes
*/
static int print_unused(void *, void *);
static void reparse_sudoers(char *, char *, bool, bool);
static int run_command(char *, char **);
-static int visudo_printf(int msg_type, const char *fmt, ...);
static void setup_signals(void);
static void help(void) __attribute__((__noreturn__));
static void usage(int);
*/
struct sudo_user sudo_user;
struct passwd *list_pw;
-sudo_printf_t sudo_printf = visudo_printf;
static struct sudoersfile_list sudoerslist;
static struct rbtree *alias_freelist;
static bool checkonly;
" -V display version information and exit"));
exit(0);
}
-
-static int
-visudo_printf(int msg_type, const char *fmt, ...)
-{
- va_list ap;
- FILE *fp;
-
- switch (msg_type) {
- case SUDO_CONV_INFO_MSG:
- fp = stdout;
- break;
- case SUDO_CONV_ERROR_MSG:
- fp = stderr;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- va_start(ap, fmt);
- vfprintf(fp, fmt, ap);
- va_end(ap);
-
- return 0;
-}
$(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)/alloc.h $(incdir)/error.h $(incdir)/gettext.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 \
extern int tgetpass_flags; /* XXX */
-#if defined(HAVE_DLOPEN) || defined(HAVE_SHL_LOAD)
-sudo_conv_t sudo_conv; /* NULL in sudo front-end */
-#endif
-
/*
* Sudo conversation function.
*/
return -1;
}
-
-int
-_sudo_printf(int msg_type, const char *fmt, ...)
-{
- va_list ap;
- FILE *fp;
- int len;
-
- switch (msg_type) {
- case SUDO_CONV_INFO_MSG:
- fp = stdout;
- break;
- case SUDO_CONV_ERROR_MSG:
- fp = stderr;
- break;
- default:
- errno = EINVAL;
- return -1;
- }
-
- va_start(ap, fmt);
- len = vfprintf(fp, fmt, ap);
- va_end(ap);
-
- return len;
-}
#include "sudo_exec.h"
#include "sudo_plugin.h"
-sudo_conv_t sudo_conv; /* NULL in non-plugin */
-
__dso_public int main(int argc, char *argv[], char *envp[]);
/*