/*
- * Copyright (c) 2009-2011 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2009-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
#if TIME_WITH_SYS_TIME
# include <time.h>
#endif
-#ifndef HAVE_TIMESPEC
+#ifndef HAVE_STRUCT_TIMESPEC
# include "compat/timespec.h"
#endif
#include <ctype.h>
# include <locale.h>
#endif
#include <signal.h>
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#else
+# include "compat/stdbool.h"
+#endif /* HAVE_STDBOOL_H */
#include <pathnames.h>
#include "alloc.h"
#include "error.h"
#include "gettext.h"
+#include "sudo_plugin.h"
+#include "sudo_conf.h"
+#include "sudo_debug.h"
#ifndef LINE_MAX
# define LINE_MAX 2048
} 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;
int
main(int argc, char *argv[])
{
- int ch, idx, plen, nready, interactive = 0, listonly = 0;
+ int ch, idx, plen, nready, exitcode = 0, interactive = 0, listonly = 0;
const char *id, *user = NULL, *pattern = NULL, *tty = NULL, *decimal = ".";
char path[PATH_MAX], buf[LINE_MAX], *cp, *ep;
double seconds, to_wait, speed = 1.0, max_wait = 0;
sigaction_t sa;
size_t len, nbytes, nread, off;
ssize_t nwritten;
+ debug_decl(main, SUDO_DEBUG_MAIN)
+
+#if defined(SUDO_DEVEL) && defined(__OpenBSD__)
+ {
+ extern char *malloc_options;
+ malloc_options = "AFGJPR";
+ }
+#endif
#if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
setprogname(argc > 0 ? argv[0] : "sudoreplay");
bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have sudoreplay domain */
textdomain("sudoers");
+ /* Read sudo.conf. */
+ sudo_conf_read();
+
while ((ch = getopt(argc, argv, "d:f:hlm:s:V")) != -1) {
switch(ch) {
case 'd':
break;
case 'V':
(void) printf(_("%s version %s\n"), getprogname(), PACKAGE_VERSION);
- exit(0);
+ goto done;
default:
usage(1);
/* NOTREACHED */
argc -= optind;
argv += optind;
- if (listonly)
- exit(list_sessions(argc, argv, pattern, user, tty));
+ if (listonly) {
+ exitcode = list_sessions(argc, argv, pattern, user, tty);
+ goto done;
+ }
if (argc != 1)
usage(1);
}
}
term_restore(STDIN_FILENO, 1);
- exit(0);
+done:
+ sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
+ exit(exitcode);
}
static void
rval = nanosleep(&ts, &rts);
} while (rval == -1 && errno == EINTR);
if (rval == -1) {
- error(1, _("nanosleep: tv_sec %ld, tv_nsec %ld"),
+ error2(1, _("nanosleep: tv_sec %ld, tv_nsec %ld"),
(long)ts.tv_sec, (long)ts.tv_nsec);
}
}
{
path[len] = '\0';
strlcat(path, suffix, PATH_MAX);
+ debug_decl(open_io_fd, SUDO_DEBUG_UTIL)
#ifdef HAVE_ZLIB_H
fdp->g = gzopen(path, "r");
- return fdp->g ? 0 : -1;
#else
fdp->f = fopen(path, "r");
- return fdp->f ? 0 : -1;
#endif
+ debug_return_int(fdp->v ? 0 : -1);
}
/*
{
struct search_node *sn, *newsn;
char or = 0, not = 0, type, **av;
+ debug_decl(parse_expr, SUDO_DEBUG_UTIL)
sn = *headp;
for (av = argv; *av; av++) {
errorx(1, _("unmatched ')' in expression"));
if (node_stack[stack_top])
sn->next = node_stack[stack_top]->next;
- return av - argv + 1;
+ debug_return_int(av - argv + 1);
bad:
default:
errorx(1, _("unknown search term \"%s\""), *av);
if (not)
errorx(1, _("illegal trailing \"!\""));
- return av - argv;
+ debug_return_int(av - argv);
}
-static int
+static bool
match_expr(struct search_node *head, struct log_info *log)
{
struct search_node *sn;
- int matched = 1, rc;
+ bool matched = true, rc;
+ debug_decl(match_expr, SUDO_DEBUG_UTIL)
for (sn = head; sn; sn = sn->next) {
/* If we have no match, skip ahead to the next OR entry. */
if (sn->negated)
matched = !matched;
}
- return matched;
+ debug_return_bool(matched);
}
static int
struct log_info li;
size_t bufsize = 0, cwdsize = 0, cmdsize = 0;
int rval = -1;
+ debug_decl(list_session, SUDO_DEBUG_UTIL)
fp = fopen(logfile, "r");
if (fp == NULL) {
done:
fclose(fp);
- return rval;
+ debug_return_int(rval);
}
+/* XXX - always returns 0, calls error() on failure */
static int
find_sessions(const char *dir, REGEX_T *re, const char *user, const char *tty)
{
size_t sdlen;
int len;
char pathbuf[PATH_MAX];
+ debug_decl(find_sessions, SUDO_DEBUG_UTIL)
d = opendir(dir);
if (d == NULL)
}
closedir(d);
- return 0;
+ debug_return_int(0);
}
+/* XXX - always returns 0, calls error() on failure */
static int
list_sessions(int argc, char **argv, const char *pattern, const char *user,
const char *tty)
{
REGEX_T rebuf, *re = NULL;
+ debug_decl(list_sessions, SUDO_DEBUG_UTIL)
/* Parse search expression if present */
parse_expr(&search_expr, argv);
re = (char *) pattern;
#endif /* HAVE_REGCOMP */
- return find_sessions(session_dir, re, user, tty);
+ debug_return_int(find_sessions(session_dir, re, user, tty));
}
/*
struct timeval tv;
char ch;
ssize_t n;
+ debug_decl(check_input, SUDO_DEBUG_UTIL)
fdsr = (fd_set *)emalloc2(howmany(ttyfd + 1, NFDBITS), sizeof(fd_mask));
}
}
free(fdsr);
+ debug_return;
}
/*
long l;
double d, fract = 0;
char *cp, *ep;
+ debug_decl(parse_timing, SUDO_DEBUG_UTIL)
/* Parse index */
ul = strtoul(buf, &ep, 10);
goto bad;
*nbytes = (size_t)ul;
- return 1;
+ debug_return_int(1);
bad:
- return 0;
+ debug_return_int(0);
}
static void