it was always 1.
debug_decl(aix_setlimits, SUDO_DEBUG_UTIL)
if (setuserdb(S_READ) != 0)
- error(1, "unable to open userdb");
+ fatal("unable to open userdb");
/*
* For each resource limit, get the soft/hard values for the user
if (user != NULL) {
if (setuserdb(S_READ) != 0)
- error(1, _("unable to open userdb"));
+ fatal(_("unable to open userdb"));
if (getuserattr(user, S_REGISTRY, ®istry, SEC_CHAR) == 0) {
if (setauthdb(registry, NULL) != 0)
- error(1, _("unable to switch to registry \"%s\" for %s"),
+ fatal(_("unable to switch to registry \"%s\" for %s"),
registry, user);
}
enduserdb();
debug_decl(aix_setauthdb, SUDO_DEBUG_UTIL)
if (setauthdb(NULL, NULL) != 0)
- error(1, _("unable to restore registry"));
+ fatal(_("unable to restore registry"));
debug_return;
}
void *ptr;
if (size == 0)
- errorx_nodebug(1, _("internal error, tried to emalloc(0)"));
+ fatalx_nodebug(_("internal error, tried to emalloc(0)"));
if ((ptr = malloc(size)) == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return ptr;
}
void *ptr;
if (nmemb == 0 || size == 0)
- errorx_nodebug(1, _("internal error, tried to emalloc2(0)"));
+ fatalx_nodebug(_("internal error, tried to emalloc2(0)"));
if (nmemb > SIZE_MAX / size)
- errorx_nodebug(1, _("internal error, %s overflow"), "emalloc2()");
+ fatalx_nodebug(_("internal error, %s overflow"), "emalloc2()");
size *= nmemb;
if ((ptr = malloc(size)) == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return ptr;
}
void *ptr;
if (nmemb == 0 || size == 0)
- errorx_nodebug(1, _("internal error, tried to ecalloc(0)"));
+ fatalx_nodebug(_("internal error, tried to ecalloc(0)"));
if (nmemb != 1) {
if (nmemb > SIZE_MAX / size)
- errorx_nodebug(1, _("internal error, %s overflow"), "ecalloc()");
+ fatalx_nodebug(_("internal error, %s overflow"), "ecalloc()");
size *= nmemb;
}
if ((ptr = malloc(size)) == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
memset(ptr, 0, size);
return ptr;
}
{
if (size == 0)
- errorx_nodebug(1, _("internal error, tried to erealloc(0)"));
+ fatalx_nodebug(_("internal error, tried to erealloc(0)"));
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return ptr;
}
{
if (nmemb == 0 || size == 0)
- errorx_nodebug(1, _("internal error, tried to erealloc3(0)"));
+ fatalx_nodebug(_("internal error, tried to erealloc3(0)"));
if (nmemb > SIZE_MAX / size)
- errorx_nodebug(1, _("internal error, %s overflow"), "erealloc3()");
+ fatalx_nodebug(_("internal error, %s overflow"), "erealloc3()");
size *= nmemb;
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return ptr;
}
size_t size;
if (nmemb == 0 || msize == 0)
- errorx_nodebug(1, _("internal error, tried to erecalloc(0)"));
+ fatalx_nodebug(_("internal error, tried to erecalloc(0)"));
if (nmemb > SIZE_MAX / msize)
- errorx_nodebug(1, _("internal error, %s overflow"), "erecalloc()");
+ fatalx_nodebug(_("internal error, %s overflow"), "erecalloc()");
size = nmemb * msize;
ptr = ptr ? realloc(ptr, size) : malloc(size);
if (ptr == NULL)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
if (nmemb > onmemb) {
size = (nmemb - onmemb) * msize;
memset((char *)ptr + (onmemb * msize), 0, size);
va_end(ap);
if (len == -1)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return len;
}
int len;
if ((len = vasprintf(ret, format, args)) == -1)
- errorx_nodebug(1, NULL);
+ fatalx_nodebug(NULL);
return len;
}
#define DEFAULT_TEXT_DOMAIN "sudo"
#include "gettext.h"
-sigjmp_buf error_jmp;
+sigjmp_buf fatal_jmp;
static bool setjmp_enabled = false;
-static struct sudo_error_callback {
+static struct sudo_fatal_callback {
void (*func)(void);
- struct sudo_error_callback *next;
+ struct sudo_fatal_callback *next;
} *callbacks;
static void _warning(int, const char *, va_list);
static void
do_cleanup(void)
{
- struct sudo_error_callback *cb;
+ struct sudo_fatal_callback *cb;
/* Run callbacks, removing them from the list as we go. */
while ((cb = callbacks) != NULL) {
}
void
-error2(int eval, const char *fmt, ...)
+fatal2(const char *fmt, ...)
{
va_list ap;
va_end(ap);
do_cleanup();
if (setjmp_enabled)
- siglongjmp(error_jmp, eval);
+ siglongjmp(fatal_jmp, 1);
else
- exit(eval);
+ exit(1);
}
void
-errorx2(int eval, const char *fmt, ...)
+fatalx2(const char *fmt, ...)
{
va_list ap;
va_end(ap);
do_cleanup();
if (setjmp_enabled)
- siglongjmp(error_jmp, eval);
+ siglongjmp(fatal_jmp, 1);
else
- exit(eval);
+ exit(1);
}
void
-verror2(int eval, const char *fmt, va_list ap)
+vfatal2(const char *fmt, va_list ap)
{
_warning(1, fmt, ap);
do_cleanup();
if (setjmp_enabled)
- siglongjmp(error_jmp, eval);
+ siglongjmp(fatal_jmp, 1);
else
- exit(eval);
+ exit(1);
}
void
-verrorx2(int eval, const char *fmt, va_list ap)
+vfatalx2(const char *fmt, va_list ap)
{
_warning(0, fmt, ap);
do_cleanup();
if (setjmp_enabled)
- siglongjmp(error_jmp, eval);
+ siglongjmp(fatal_jmp, 1);
else
- exit(eval);
+ exit(1);
}
void
}
int
-error_callback_register(void (*func)(void))
+fatal_callback_register(void (*func)(void))
{
- struct sudo_error_callback *cb;
+ struct sudo_fatal_callback *cb;
cb = malloc(sizeof(*cb));
if (cb == NULL)
}
void
-error_disable_setjmp(void)
+fatal_disable_setjmp(void)
{
setjmp_enabled = false;
}
void
-error_enable_setjmp(void)
+fatal_enable_setjmp(void)
{
setjmp_enabled = true;
}
/*
- * Copyright (c) 2004, 2010-2012 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2004, 2010-2013 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
#include <setjmp.h>
/*
- * We wrap error/errorx and warn/warnx so that the same output can
+ * We wrap fatal/fatalx and warning/warningx so that the same output can
* go to the debug file, if there is one.
*/
#if defined(SUDO_ERROR_WRAP) && SUDO_ERROR_WRAP == 0
# if defined(__GNUC__) && __GNUC__ == 2
-# define error(rval, fmt...) error_nodebug((rval), fmt)
-# define errorx(rval, fmt...) errorx_nodebug((rval), fmt)
+# define fatal(fmt...) fatal_nodebug(fmt)
+# define fatalx(fmt...) fatalx_nodebug(fmt)
# define warning(fmt...) warning_nodebug(fmt)
# define warningx(fmt...) warningx_nodebug(fmt)
# else
-# define error(rval, ...) error_nodebug((rval), __VA_ARGS__)
-# define errorx(rval, ...) errorx_nodebug((rval), __VA_ARGS__)
+# define fatal(...) fatal_nodebug(__VA_ARGS__)
+# define fatalx(...) fatalx_nodebug(__VA_ARGS__)
# define warning(...) warning_nodebug(__VA_ARGS__)
# define warningx(...) warningx_nodebug(__VA_ARGS__)
# endif /* __GNUC__ == 2 */
-# define verror(rval, fmt, ap) error_nodebug((rval), (fmt), (ap))
-# define verrorx(rval, fmt, ap) errorx_nodebug((rval), (fmt), (ap))
+# define vfatal(fmt, ap) fatal_nodebug((fmt), (ap))
+# define vfatalx(fmt, ap) fatalx_nodebug((fmt), (ap))
# define vwarning(fmt, ap) warning_nodebug((fmt), (ap))
# define vwarningx(fmt, ap) warningx_nodebug((fmt), (ap))
#else /* SUDO_ERROR_WRAP */
# if defined(__GNUC__) && __GNUC__ == 2
-# define error(rval, fmt...) do { \
+# define fatal(fmt...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
fmt); \
- error_nodebug((rval), fmt); \
+ fatal_nodebug(fmt); \
} while (0)
-# define errorx(rval, fmt...) do { \
+# define fatalx(fmt...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt); \
- errorx_nodebug((rval), fmt); \
+ fatalx_nodebug(fmt); \
} while (0)
# define warning(fmt...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
warningx_nodebug(fmt); \
} while (0)
# else
-# define error(rval, ...) do { \
+# define fatal(...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
__VA_ARGS__); \
- error_nodebug((rval), __VA_ARGS__); \
+ fatal_nodebug(__VA_ARGS__); \
} while (0)
-# define errorx(rval, ...) do { \
+# define fatalx(...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, __VA_ARGS__); \
- errorx_nodebug((rval), __VA_ARGS__); \
+ fatalx_nodebug(__VA_ARGS__); \
} while (0)
# define warning(...) do { \
sudo_debug_printf2(__func__, __FILE__, __LINE__, \
warningx_nodebug(__VA_ARGS__); \
} while (0)
# endif /* __GNUC__ == 2 */
-# define verror(rval, fmt, ap) do { \
+# define vfatal(fmt, ap) do { \
sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
(fmt), (ap)); \
- verror_nodebug((rval), (fmt), (ap)); \
+ vfatal_nodebug((fmt), (ap)); \
} while (0)
-# define verrorx(rval, fmt, ap) do { \
+# define vfatalx(fmt, ap) do { \
sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, (fmt), (ap)); \
- verrorx_nodebug((rval), (fmt), (ap)); \
+ vfatalx_nodebug((fmt), (ap)); \
} while (0)
# define vwarning(fmt, ap) do { \
sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
#endif /* SUDO_ERROR_WRAP */
#if defined(__GNUC__) && __GNUC__ == 2
-# define error_nodebug(rval, fmt...) do { \
+# define fatal_nodebug(fmt...) do { \
warning_set_locale(); \
- error2((rval), fmt); \
+ fatal2(fmt); \
} while (0)
-# define errorx_nodebug(rval, fmt...) do { \
+# define fatalx_nodebug(fmt...) do { \
warning_set_locale(); \
- errorx2((rval), fmt); \
+ fatalx2(fmt); \
} while (0)
# define warning_nodebug(fmt...) do { \
warning_set_locale(); \
warning_restore_locale(); \
} while (0)
#else
-# define error_nodebug(rval, ...) do { \
+# define fatal_nodebug(...) do { \
warning_set_locale(); \
- error2((rval), __VA_ARGS__); \
+ fatal2(__VA_ARGS__); \
} while (0)
-# define errorx_nodebug(rval, ...) do { \
+# define fatalx_nodebug(...) do { \
warning_set_locale(); \
- errorx2((rval), __VA_ARGS__); \
+ fatalx2(__VA_ARGS__); \
} while (0)
# define warning_nodebug(...) do { \
warning_set_locale(); \
warning_restore_locale(); \
} while (0)
#endif /* __GNUC__ == 2 */
-#define verror_nodebug(rval, fmt, ap) do { \
+#define vfatal_nodebug(fmt, ap) do { \
warning_set_locale(); \
- verror2((rval), (fmt), (ap)); \
+ vfatal2((fmt), (ap)); \
} while (0)
-#define verrorx_nodebug(rval, fmt, ap) do { \
+#define vfatalx_nodebug(fmt, ap) do { \
warning_set_locale(); \
- verrorx2((rval), (fmt), (ap)); \
+ vfatalx2((fmt), (ap)); \
} while (0)
#define vwarning_nodebug(fmt, ap) do { \
warning_set_locale(); \
warning_restore_locale(); \
} while (0)
-#define error_setjmp() (error_enable_setjmp(), sigsetjmp(error_jmp, 1))
-#define error_longjmp(val) siglongjmp(error_jmp, val)
+#define fatal_setjmp() (fatal_enable_setjmp(), sigsetjmp(fatal_jmp, 1))
+#define fatal_longjmp(val) siglongjmp(fatal_jmp, val)
extern int (*sudo_printf)(int msg_type, const char *fmt, ...);
-extern sigjmp_buf error_jmp;
+extern sigjmp_buf fatal_jmp;
-int error_callback_register(void (*func)(void));
-void error_disable_setjmp(void);
-void error_enable_setjmp(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__));
-void verrorx2(int, const char *, va_list ap) __attribute__((__noreturn__));
+int fatal_callback_register(void (*func)(void));
+void fatal_disable_setjmp(void);
+void fatal_enable_setjmp(void);
+void fatal2(const char *, ...) __printflike(1, 2) __attribute__((__noreturn__));
+void fatalx2(const char *, ...) __printflike(1, 2) __attribute__((__noreturn__));
+void vfatal2(const char *, va_list ap) __attribute__((__noreturn__));
+void vfatalx2(const char *, va_list ap) __attribute__((__noreturn__));
void warning2(const char *, ...) __printflike(1, 2);
void warningx2(const char *, ...) __printflike(1, 2);
void vwarning2(const char *, va_list ap);
if (getaudit_addr(&ainfo_addr, sizeof(ainfo_addr)) < 0) {
if (errno == ENOSYS) {
if (getaudit(&ainfo) < 0)
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
mask = &ainfo.ai_mask;
} else
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
} else
mask = &ainfo_addr.ai_mask;
sorf = (sf == 0) ? AU_PRS_SUCCESS : AU_PRS_FAILURE;
if (auditon(A_GETCOND, (caddr_t)&au_cond, sizeof(long)) < 0) {
if (errno == AUDIT_NOT_CONFIGURED)
return;
- error(1, _("Could not determine audit condition"));
+ fatal(_("Could not determine audit condition"));
}
if (au_cond == AUC_NOAUDIT)
debug_return;
if (!audit_sudo_selected(0))
debug_return;
if (getauid(&auid) < 0)
- error(1, _("getauid: failed"));
+ fatal(_("getauid: failed"));
if ((aufd = au_open()) == -1)
- error(1, _("au_open: failed"));
+ fatal(_("au_open: failed"));
if (getaudit_addr(&ainfo_addr, sizeof(ainfo_addr)) == 0) {
tok = au_to_subject_ex(auid, geteuid(), getegid(), getuid(),
getuid(), pid, pid, &ainfo_addr.ai_termid);
* NB: We should probably watch out for ERANGE here.
*/
if (getaudit(&ainfo) < 0)
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
tok = au_to_subject(auid, geteuid(), getegid(), getuid(),
getuid(), pid, pid, &ainfo.ai_termid);
} else
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
if (tok == NULL)
- error(1, _("au_to_subject: failed"));
+ fatal(_("au_to_subject: failed"));
au_write(aufd, tok);
tok = au_to_exec_args(exec_args);
if (tok == NULL)
- error(1, _("au_to_exec_args: failed"));
+ fatal(_("au_to_exec_args: failed"));
au_write(aufd, tok);
tok = au_to_return32(0, 0);
if (tok == NULL)
- error(1, _("au_to_return32: failed"));
+ fatal(_("au_to_return32: failed"));
au_write(aufd, tok);
if (au_close(aufd, 1, AUE_sudo) == -1)
- error(1, _("unable to commit audit record"));
+ fatal(_("unable to commit audit record"));
debug_return;
}
if (auditon(A_GETCOND, &au_cond, sizeof(long)) < 0) {
if (errno == AUDIT_NOT_CONFIGURED)
debug_return;
- error(1, _("Could not determine audit condition"));
+ fatal(_("Could not determine audit condition"));
}
if (au_cond == AUC_NOAUDIT)
debug_return;
if (!audit_sudo_selected(1))
debug_return;
if (getauid(&auid) < 0)
- error(1, _("getauid: failed"));
+ fatal(_("getauid: failed"));
if ((aufd = au_open()) == -1)
- error(1, _("au_open: failed"));
+ fatal(_("au_open: failed"));
if (getaudit_addr(&ainfo_addr, sizeof(ainfo_addr)) == 0) {
tok = au_to_subject_ex(auid, geteuid(), getegid(), getuid(),
getuid(), pid, pid, &ainfo_addr.ai_termid);
} else if (errno == ENOSYS) {
if (getaudit(&ainfo) < 0)
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
tok = au_to_subject(auid, geteuid(), getegid(), getuid(),
getuid(), pid, pid, &ainfo.ai_termid);
} else
- error(1, _("getaudit: failed"));
+ fatal(_("getaudit: failed"));
if (tok == NULL)
- error(1, _("au_to_subject: failed"));
+ fatal(_("au_to_subject: failed"));
au_write(aufd, tok);
tok = au_to_exec_args(exec_args);
if (tok == NULL)
- error(1, _("au_to_exec_args: failed"));
+ fatal(_("au_to_exec_args: failed"));
au_write(aufd, tok);
(void) vsnprintf(text, sizeof(text), fmt, ap);
tok = au_to_text(text);
if (tok == NULL)
- error(1, _("au_to_text: failed"));
+ fatal(_("au_to_text: failed"));
au_write(aufd, tok);
tok = au_to_return32(EPERM, 1);
if (tok == NULL)
- error(1, _("au_to_return32: failed"));
+ fatal(_("au_to_return32: failed"));
au_write(aufd, tok);
if (au_close(aufd, 1, AUE_sudo) == -1)
- error(1, _("unable to commit audit record"));
+ fatal(_("unable to commit audit record"));
debug_return;
}
size_t nsize;
if (env.env_size > SIZE_MAX - 128) {
- errorx_nodebug(1, _("internal error, %s overflow"),
+ fatalx_nodebug(_("internal error, %s overflow"),
"sudo_putenv_nodebug()");
}
nsize = env.env_size + 128;
if (nsize > SIZE_MAX / sizeof(char *)) {
- errorx_nodebug(1, _("internal error, %s overflow"),
+ fatalx_nodebug(_("internal error, %s overflow"),
"sudo_putenv_nodebug()");
}
nenvp = realloc(env.envp, nsize * sizeof(char *));
if (rval == -1) {
#ifdef ENV_DEBUG
if (env.envp[env.env_len] != NULL)
- errorx(1, _("sudo_putenv: corrupted envp, length mismatch"));
+ fatalx(_("sudo_putenv: corrupted envp, length mismatch"));
#endif
- errorx(1, NULL);
+ fatalx(NULL);
}
debug_return_int(rval);
}
strlcat(estring, "=", esize) >= esize ||
strlcat(estring, val, esize) >= esize) {
- errorx(1, _("internal error, %s overflow"), "sudo_setenv2()");
+ fatalx(_("internal error, %s overflow"), "sudo_setenv2()");
}
rval = sudo_putenv(estring, dupcheck, overwrite);
if (rval == -1)
if (strlen(infile) >= PATH_MAX) {
errno = ENAMETOOLONG;
- error(1, "%s", infile);
+ fatal("%s", infile);
}
/*
len = snprintf(command, sizeof(command), "%s/%s", path, infile);
if (len <= 0 || len >= sizeof(command)) {
errno = ENAMETOOLONG;
- error(1, "%s", infile);
+ fatal("%s", infile);
}
if ((found = sudo_goodpath(command, sbp)))
break;
len = snprintf(command, sizeof(command), "./%s", infile);
if (len <= 0 || len >= sizeof(command)) {
errno = ENAMETOOLONG;
- error(1, "%s", infile);
+ fatal("%s", infile);
}
found = sudo_goodpath(command, sbp);
if (found && ignore_dot)
break;
default:
/* Should not happen. */
- errorx(1, "internal error, \\x%s not in proper hex format", s);
+ fatalx("internal error, \\x%s not in proper hex format", s);
}
}
debug_return_int((result[0] << 4) | result[1]);
memset(&details, 0, sizeof(details));
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
rval = -1;
goto done;
rval = true;
done:
- error_disable_setjmp();
+ fatal_disable_setjmp();
efree(tofree);
if (details.runas_pw)
sudo_pw_delref(details.runas_pw);
int i;
debug_decl(sudoers_io_close, SUDO_DEBUG_PLUGIN)
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return;
}
{
debug_decl(sudoers_io_version, SUDO_DEBUG_PLUGIN)
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return_bool(-1);
}
gettimeofday(&now, NULL);
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return_bool(-1);
}
hostbuf[0] = '\0';
if (snprintf(defport, sizeof(defport), ":%d", ldap_conf.port) >= sizeof(defport))
- errorx(1, _("sudo_ldap_conf_add_ports: port too large"));
+ fatalx(_("sudo_ldap_conf_add_ports: port too large"));
for ((host = strtok(ldap_conf.host, " \t")); host; (host = strtok(NULL, " \t"))) {
if (hostbuf[0] != '\0') {
debug_return;
toobig:
- errorx(1, _("sudo_ldap_conf_add_ports: out of space expanding hostbuf"));
+ fatalx(_("sudo_ldap_conf_add_ports: out of space expanding hostbuf"));
}
#endif
debug_return_int(rc);
toobig:
- errorx(1, _("sudo_ldap_parse_uri: out of space building hostbuf"));
+ fatalx(_("sudo_ldap_parse_uri: out of space building hostbuf"));
}
#else
static char *
/* Add ALL to list and end the global OR */
if (strlcat(buf, "(sudoUser=ALL)", sz) >= sz)
- errorx(1, _("sudo_ldap_build_pass1 allocation mismatch"));
+ fatalx(_("sudo_ldap_build_pass1 allocation mismatch"));
/* Add the time restriction, or simply end the global OR. */
if (ldap_conf.timed) {
if (au_fd == -1) {
/* Kernel may not have audit support. */
if (errno != EINVAL && errno != EPROTONOSUPPORT && errno != EAFNOSUPPORT)
- error(1, _("unable to open audit system"));
+ fatal(_("unable to open audit system"));
} else {
(void)fcntl(au_fd, F_SETFD, FD_CLOEXEC);
}
for (av = argv; *av != NULL; av++) {
n = strlcpy(cp, *av, size - (cp - command));
if (n >= size - (cp - command)) {
- errorx(1, _("internal error, %s overflow"),
+ fatalx(_("internal error, %s overflow"),
"linux_audit_command()");
}
cp += n;
/* Exit the plugin. */
sudoers_cleanup();
sudo_debug_exit(__func__, __FILE__, __LINE__, sudo_debug_subsys);
- error_longjmp(1);
+ fatal_longjmp(1);
}
#define MAX_MAILFLAGS 63
switch (pid = sudo_debug_fork()) {
case -1:
/* Error. */
- error(1, _("unable to fork"));
+ fatal(_("unable to fork"));
break;
case 0:
/* Child. */
debug_return_str(line);
toobig:
- errorx(1, _("internal error: insufficient space for log line"));
+ fatalx(_("internal error: insufficient space for log line"));
}
(unsigned int)runas_pw->pw_gid;
len = snprintf(cp, glsize - (cp - gid_list), "%u", egid);
if (len < 0 || len >= glsize - (cp - gid_list))
- errorx(1, _("internal error, %s overflow"), "runas_groups");
+ fatalx(_("internal error, %s overflow"), "runas_groups");
cp += len;
for (i = 0; i < grlist->ngids; i++) {
if (grlist->gids[i] != egid) {
len = snprintf(cp, glsize - (cp - gid_list), ",%u",
(unsigned int) grlist->gids[i]);
if (len < 0 || len >= glsize - (cp - gid_list))
- errorx(1, _("internal error, %s overflow"), "runas_groups");
+ fatalx(_("internal error, %s overflow"), "runas_groups");
cp += len;
}
}
if (sudo_version < SUDO_API_MKVERSION(1, 2))
args = NULL;
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
rewind_perms();
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return_bool(-1);
}
{
debug_decl(sudoers_policy_close, SUDO_DEBUG_PLUGIN)
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return;
}
if (sudo_version < SUDO_API_MKVERSION(1, 2))
user_env = NULL;
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* called via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return_bool(-1);
}
debug_decl(sudoers_policy_invalidate, SUDO_DEBUG_PLUGIN)
user_cmnd = "kill";
- if (error_setjmp() == 0) {
+ if (fatal_setjmp() == 0) {
remove_timestamp(remove);
sudoers_cleanup();
}
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return;
}
{
debug_decl(sudoers_policy_version, SUDO_DEBUG_PLUGIN)
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* error recovery via error(), errorx() or log_fatal() */
- error_disable_setjmp();
+ fatal_disable_setjmp();
debug_return_bool(-1);
}
oflow:
/* We pre-allocate enough space, so this should never happen. */
- errorx(1, _("internal error, %s overflow"), "expand_prompt()");
+ fatalx(_("internal error, %s overflow"), "expand_prompt()");
}
/* item->d.pw = NULL; */
}
if (rbinsert(pwcache_byuid, item) != NULL)
- errorx(1, _("unable to cache uid %u, already exists"),
+ fatalx(_("unable to cache uid %u, already exists"),
(unsigned int) uid);
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
/* item->d.pw = NULL; */
}
if (rbinsert(pwcache_byname, item) != NULL)
- errorx(1, _("unable to cache user %s, already exists"), name);
+ fatalx(_("unable to cache user %s, already exists"), name);
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
#endif
/* item->d.gr = NULL; */
}
if (rbinsert(grcache_bygid, item) != NULL)
- errorx(1, _("unable to cache gid %u, already exists"),
+ fatalx(_("unable to cache gid %u, already exists"),
(unsigned int) gid);
done:
item->refcnt++;
/* item->d.gr = NULL; */
}
if (rbinsert(grcache_byname, item) != NULL)
- errorx(1, _("unable to cache group %s, already exists"), name);
+ fatalx(_("unable to cache group %s, already exists"), name);
done:
item->refcnt++;
debug_return_ptr(item->d.gr);
/* item->d.grlist = NULL; */
}
if (rbinsert(grlist_cache, item) != NULL)
- errorx(1, _("unable to cache group list for %s, already exists"),
+ fatalx(_("unable to cache group list for %s, already exists"),
pw->pw_name);
done:
item->refcnt++;
key.k.name = pw->pw_name;
if ((node = rbfind(grlist_cache, &key)) == NULL) {
if ((item = sudo_make_grlist_item(pw, groups, gids)) == NULL)
- errorx(1, _("unable to parse groups for %s"), pw->pw_name);
+ fatalx(_("unable to parse groups for %s"), pw->pw_name);
if (rbinsert(grlist_cache, item) != NULL)
- errorx(1, _("unable to cache group list for %s, already exists"),
+ fatalx(_("unable to cache group list for %s, already exists"),
pw->pw_name);
}
debug_return;
handle = dlopen(plugin_path, RTLD_LAZY|RTLD_GLOBAL);
if (handle == NULL)
- errorx_nodebug(1, "unable to dlopen %s: %s", plugin_path, dlerror());
+ fatalx_nodebug("unable to dlopen %s: %s", plugin_path, dlerror());
fp = fopen(symbols_file, "r");
if (fp == NULL)
- error_nodebug(1, "unable to open %s", symbols_file);
+ fatal_nodebug("unable to open %s", symbols_file);
while (fgets(line, sizeof(line), fp) != NULL) {
ntests++;
fp = fopen(argv[1], "r");
if (fp == NULL)
- errorx(1, "unable to open %s", argv[1]);
+ fatalx("unable to open %s", argv[1]);
memset(&pw, 0, sizeof(pw));
memset(&rpw, 0, sizeof(rpw));
tests++;
break;
default:
- errorx(1, "internal error, invalid state %d", state);
+ fatalx("internal error, invalid state %d", state);
}
state = (state + 1) % MAX_STATE;
}
fp = fopen(argv[1], "r");
if (fp == NULL)
- errorx(1, "unable to open %s", argv[1]);
+ fatalx("unable to open %s", argv[1]);
/*
* Each test record consists of a log entry on one line and a list of
fp = fopen(argv[1], "r");
if (fp == NULL)
- errorx(1, "unable to open %s", argv[1]);
+ fatalx("unable to open %s", argv[1]);
/*
* Input is in the following format. There are two types of
sudo_setgrent();
/* Register error/errorx callback. */
- error_callback_register(sudoers_cleanup);
+ fatal_callback_register(sudoers_cleanup);
/* Initialize environment functions (including replacements). */
env_init(envp);
debug_decl(sudoers_policy_main, SUDO_DEBUG_PLUGIN)
/* XXX - would like to move this to policy.c but need the cleanup. */
- if (error_setjmp() != 0) {
+ if (fatal_setjmp() != 0) {
/* error recovery via error(), errorx() or log_fatal() */
rval = -1;
goto done;
rval = false;
done:
- error_disable_setjmp();
+ fatal_disable_setjmp();
rewind_perms();
/* Close the password and group files and free up memory. */
* YP/NIS/NIS+/LDAP/etc daemon has died.
*/
if (sudo_mode == MODE_KILL || sudo_mode == MODE_INVALIDATE)
- errorx(1, _("unknown uid: %u"), (unsigned int) user_uid);
+ fatalx(_("unknown uid: %u"), (unsigned int) user_uid);
/* Need to make a fake struct passwd for the call to log_fatal(). */
sudo_user.pw = sudo_fakepwnamid(user_name, user_uid, user_gid);
for (to = user_args, av = NewArgv + 1; *av; av++) {
n = strlcpy(to, *av, size - (to - user_args));
if (n >= size - (to - user_args))
- errorx(1, _("internal error, %s overflow"), "set_cmnd()");
+ fatalx(_("internal error, %s overflow"), "set_cmnd()");
to += n;
*to++ = ' ';
}
}
if (strlen(user_cmnd) >= PATH_MAX) {
errno = ENAMETOOLONG;
- error(1, "%s", user_cmnd);
+ fatal("%s", user_cmnd);
}
if ((user_base = strrchr(user_cmnd, '/')) != NULL)
if (login_class && strcmp(login_class, "-") != 0) {
if (user_uid != 0 &&
strcmp(runas_user ? runas_user : def_runas_default, "root") != 0)
- errorx(1, _("only root can use `-c %s'"), login_class);
+ fatalx(_("only root can use `-c %s'"), login_class);
} else {
login_class = pw->pw_class;
if (!login_class || !*login_class)
textdomain("sudoers");
/* Register error/errorx callback. */
- error_callback_register(sudoreplay_cleanup);
+ fatal_callback_register(sudoreplay_cleanup);
/* Read sudo.conf. */
sudo_conf_read(NULL);
else if (strcmp(cp, "ttyout") == 0)
SET(replay_filter, 1 << IOFD_TTYOUT);
else
- errorx(1, _("invalid filter option: %s"), optarg);
+ fatalx(_("invalid filter option: %s"), optarg);
}
break;
case 'h':
errno = 0;
max_wait = strtod(optarg, &ep);
if (*ep != '\0' || errno != 0)
- errorx(1, _("invalid max wait: %s"), optarg);
+ fatalx(_("invalid max wait: %s"), optarg);
break;
case 's':
errno = 0;
speed = strtod(optarg, &ep);
if (*ep != '\0' || errno != 0)
- errorx(1, _("invalid speed factor: %s"), optarg);
+ fatalx(_("invalid speed factor: %s"), optarg);
break;
case 'V':
(void) printf(_("%s version %s\n"), getprogname(), PACKAGE_VERSION);
plen = snprintf(path, sizeof(path), "%s/%.2s/%.2s/%.2s/timing",
session_dir, id, &id[2], &id[4]);
if (plen <= 0 || plen >= sizeof(path))
- errorx(1, _("%s/%.2s/%.2s/%.2s/timing: %s"), session_dir,
+ fatalx(_("%s/%.2s/%.2s/%.2s/timing: %s"), session_dir,
id, &id[2], &id[4], strerror(ENAMETOOLONG));
} else {
plen = snprintf(path, sizeof(path), "%s/%s/timing",
session_dir, id);
if (plen <= 0 || plen >= sizeof(path))
- errorx(1, _("%s/%s/timing: %s"), session_dir,
+ fatalx(_("%s/%s/timing: %s"), session_dir,
id, strerror(ENAMETOOLONG));
}
plen -= 7;
for (idx = 0; idx < IOFD_MAX; idx++) {
if (ISSET(replay_filter, 1 << idx) || idx == IOFD_TIMING) {
if (open_io_fd(path, plen, io_fnames[idx], &io_fds[idx]) == -1)
- error(1, _("unable to open %s"), path);
+ fatal(_("unable to open %s"), path);
}
}
if (ch != -1)
(void) fcntl(STDIN_FILENO, F_SETFL, ch | O_NONBLOCK);
if (!term_raw(STDIN_FILENO, 1))
- error(1, _("unable to set tty to raw mode"));
+ fatal(_("unable to set tty to raw mode"));
iovmax = 32;
iov = ecalloc(iovmax, sizeof(*iov));
}
char last_char = '\0';
if (!parse_timing(buf, decimal, &idx, &seconds, &nbytes))
- errorx(1, _("invalid timing file line: %s"), buf);
+ fatalx(_("invalid timing file line: %s"), buf);
if (interactive)
check_input(STDIN_FILENO, &speed);
iovcnt = 1;
}
if (atomic_writev(STDOUT_FILENO, iov, iovcnt) == -1)
- error(1, _("writing to standard output"));
+ fatal(_("writing to standard output"));
}
}
term_restore(STDIN_FILENO, 1);
rval = nanosleep(&ts, &rts);
} while (rval == -1 && errno == EINTR);
if (rval == -1) {
- error_nodebug(1, _("nanosleep: tv_sec %ld, tv_nsec %ld"),
+ fatal_nodebug(_("nanosleep: tv_sec %ld, tv_nsec %ld"),
(long)ts.tv_sec, (long)ts.tv_nsec);
}
}
continue;
case 'c': /* command */
if (av[0][1] == '\0')
- errorx(1, _("ambiguous expression \"%s\""), *av);
+ fatalx(_("ambiguous expression \"%s\""), *av);
if (strncmp(*av, "cwd", strlen(*av)) == 0)
type = ST_CWD;
else if (strncmp(*av, "command", strlen(*av)) == 0)
break;
case 't': /* tty or to date */
if (av[0][1] == '\0')
- errorx(1, _("ambiguous expression \"%s\""), *av);
+ fatalx(_("ambiguous expression \"%s\""), *av);
if (strncmp(*av, "todate", strlen(*av)) == 0)
type = ST_TODATE;
else if (strncmp(*av, "tty", strlen(*av)) == 0)
if (av[0][1] != '\0')
goto bad;
if (stack_top + 1 == STACK_NODE_SIZE) {
- errorx(1, _("too many parenthesized expressions, max %d"),
+ fatalx(_("too many parenthesized expressions, max %d"),
STACK_NODE_SIZE);
}
node_stack[stack_top++] = sn;
goto bad;
/* pop */
if (--stack_top < 0)
- errorx(1, _("unmatched ')' in expression"));
+ fatalx(_("unmatched ')' in expression"));
if (node_stack[stack_top])
sn->next = node_stack[stack_top]->next;
debug_return_int(av - argv + 1);
bad:
default:
- errorx(1, _("unknown search term \"%s\""), *av);
+ fatalx(_("unknown search term \"%s\""), *av);
/* NOTREACHED */
}
av += parse_expr(&newsn->u.expr, av + 1);
} else {
if (*(++av) == NULL)
- errorx(1, _("%s requires an argument"), av[-1]);
+ fatalx(_("%s requires an argument"), av[-1]);
#ifdef HAVE_REGCOMP
if (type == ST_PATTERN) {
if (regcomp(&newsn->u.cmdre, *av, REG_EXTENDED|REG_NOSUB) != 0)
- errorx(1, _("invalid regular expression: %s"), *av);
+ fatalx(_("invalid regular expression: %s"), *av);
} else
#endif
if (type == ST_TODATE || type == ST_FROMDATE) {
newsn->u.tstamp = get_date(*av);
if (newsn->u.tstamp == -1)
- errorx(1, _("could not parse date \"%s\""), *av);
+ fatalx(_("could not parse date \"%s\""), *av);
} else {
newsn->u.ptr = *av;
}
sn = newsn;
}
if (stack_top)
- errorx(1, _("unmatched '(' in expression"));
+ fatalx(_("unmatched '(' in expression"));
if (or)
- errorx(1, _("illegal trailing \"or\""));
+ fatalx(_("illegal trailing \"or\""));
if (not)
- errorx(1, _("illegal trailing \"!\""));
+ fatalx(_("illegal trailing \"!\""));
debug_return_int(av - argv);
}
if (rc && rc != REG_NOMATCH) {
char buf[BUFSIZ];
regerror(rc, &sn->u.cmdre, buf, sizeof(buf));
- errorx(1, "%s", buf);
+ fatalx("%s", buf);
}
matched = rc == REG_NOMATCH ? 0 : 1;
#else
d = opendir(dir);
if (d == NULL)
- error(1, _("unable to open %s"), dir);
+ fatal(_("unable to open %s"), dir);
/* XXX - would be faster to chdir and use relative names */
sdlen = strlcpy(pathbuf, dir, sizeof(pathbuf));
if (sdlen + 1 >= sizeof(pathbuf)) {
errno = ENAMETOOLONG;
- error(1, "%s/", dir);
+ fatal("%s/", dir);
}
pathbuf[sdlen++] = '/';
pathbuf[sdlen] = '\0';
"%s/log", sessions[i]);
if (len <= 0 || len >= sizeof(pathbuf) - sdlen) {
errno = ENAMETOOLONG;
- error(1, "%s/%s/log", dir, sessions[i]);
+ fatal("%s/%s/log", dir, sessions[i]);
}
efree(sessions[i]);
if (pattern) {
re = &rebuf;
if (regcomp(re, pattern, REG_EXTENDED|REG_NOSUB) != 0)
- errorx(1, _("invalid regular expression: %s"), pattern);
+ fatalx(_("invalid regular expression: %s"), pattern);
}
#else
re = (char *) pattern;
argc -= 2;
}
if ((sudo_user.pw = sudo_getpwnam(user_name)) == NULL)
- errorx(1, _("unknown user: %s"), user_name);
+ fatalx(_("unknown user: %s"), user_name);
if (user_host == NULL) {
if (gethostname(hbuf, sizeof(hbuf)) != 0)
- error(1, "gethostname");
+ fatal("gethostname");
hbuf[sizeof(hbuf) - 1] = '\0';
user_host = hbuf;
}
for (to = user_args, from = argv; *from; from++) {
n = strlcpy(to, *from, size - (to - user_args));
if (n >= size - (to - user_args))
- errorx(1, _("internal error, %s overflow"), "init_vars()");
+ fatalx(_("internal error, %s overflow"), "init_vars()");
to += n;
*to++ = ' ';
}
runas_pw = sudo_fakepwnam(user, runas_gr ? runas_gr->gr_gid : 0);
} else {
if ((runas_pw = sudo_getpwnam(user)) == NULL)
- errorx(1, _("unknown user: %s"), user);
+ fatalx(_("unknown user: %s"), user);
}
debug_return;
runas_gr = sudo_fakegrnam(group);
} else {
if ((runas_gr = sudo_getgrnam(group)) == NULL)
- errorx(1, _("unknown group: %s"), group);
+ fatalx(_("unknown group: %s"), group);
}
debug_return;
if (!remove) {
timevalclear(&tv);
if (touch(-1, path, &tv) == -1 && errno != ENOENT)
- error(1, _("unable to reset %s to the epoch"), path);
+ fatal(_("unable to reset %s to the epoch"), path);
}
}
usage(1);
/* Register error/errorx callback. */
- error_callback_register(visudo_cleanup);
+ fatal_callback_register(visudo_cleanup);
/* Read sudo.conf. */
sudo_conf_read(NULL);
/* Mock up a fake sudo_user struct. */
user_cmnd = "";
if ((sudo_user.pw = sudo_getpwuid(getuid())) == NULL)
- errorx(1, _("you do not exist in the %s database"), "passwd");
+ fatalx(_("you do not exist in the %s database"), "passwd");
get_hostname();
/* Setup defaults data structures. */
debug_decl(edit_sudoers, SUDO_DEBUG_UTIL)
if (fstat(sp->fd, &sb) == -1)
- error(1, _("unable to stat %s"), sp->path);
+ fatal(_("unable to stat %s"), sp->path);
orig_size = sb.st_size;
mtim_get(&sb, &orig_mtim);
easprintf(&sp->tpath, "%s.tmp", sp->path);
tfd = open(sp->tpath, O_WRONLY | O_CREAT | O_TRUNC, 0600);
if (tfd < 0)
- error(1, "%s", sp->tpath);
+ fatal("%s", sp->tpath);
/* Copy sp->path -> sp->tpath and reset the mtime. */
if (orig_size != 0) {
(void) lseek(sp->fd, (off_t)0, SEEK_SET);
while ((nread = read(sp->fd, buf, sizeof(buf))) > 0)
if (write(tfd, buf, nread) != nread)
- error(1, _("write error"));
+ fatal(_("write error"));
/* Add missing newline at EOF if needed. */
if (nread > 0 && buf[nread - 1] != '\n') {
buf[0] = '\n';
if (write(tfd, buf, 1) != 1)
- error(1, _("write error"));
+ fatal(_("write error"));
}
}
(void) close(tfd);
last = tq_last(&sudoerslist);
fp = fopen(sp->tpath, "r+");
if (fp == NULL)
- errorx(1, _("unable to re-open temporary file (%s), %s unchanged."),
+ fatalx(_("unable to re-open temporary file (%s), %s unchanged."),
sp->tpath, sp->path);
/* Clean slate for each parse */
}
}
if (errorfile != NULL && sp == NULL) {
- errorx(1, _("internal error, unable to find %s in list!"),
+ fatalx(_("internal error, unable to find %s in list!"),
sudoers);
}
}
if (oldperms) {
/* Use perms of the existing file. */
if (fstat(sp->fd, &sb) == -1)
- error(1, _("unable to stat %s"), sp->path);
+ fatal(_("unable to stat %s"), sp->path);
if (chown(sp->tpath, sb.st_uid, sb.st_gid) != 0) {
warning(_("unable to set (uid, gid) of %s to (%u, %u)"),
sp->tpath, (unsigned int)sb.st_uid, (unsigned int)sb.st_gid);
switch (pid = sudo_debug_fork()) {
case -1:
- error(1, _("unable to execute %s"), path);
+ fatal(_("unable to execute %s"), path);
break; /* NOTREACHED */
case 0:
sudo_endpwent();
debug_return_ptr(NULL);
}
if (!checkonly && !lock_file(entry->fd, SUDO_TLOCK))
- errorx(1, _("%s busy, try again later"), entry->path);
+ fatalx(_("%s busy, try again later"), entry->path);
if ((fp = fdopen(entry->fd, "r")) == NULL)
- error(1, "%s", entry->path);
+ fatal("%s", entry->path);
tq_append(&sudoerslist, entry);
} else {
/* Already exists, open .tmp version if there is one. */
if (entry->tpath != NULL) {
if ((fp = fopen(entry->tpath, "r")) == NULL)
- error(1, "%s", entry->tpath);
+ fatal("%s", entry->tpath);
} else {
if ((fp = fdopen(entry->fd, "r")) == NULL)
- error(1, "%s", entry->path);
+ fatal("%s", entry->path);
rewind(fp);
}
}
} else {
if (def_env_editor) {
/* If we are honoring $EDITOR this is a fatal error. */
- errorx(1, _("specified editor (%s) doesn't exist"), UserEditor);
+ fatalx(_("specified editor (%s) doesn't exist"), UserEditor);
} else {
/* Otherwise, just ignore $EDITOR. */
UserEditor = NULL;
if (stat(UserEditor, &user_editor_sb) != 0) {
/* Should never happen since we already checked above. */
- error(1, _("unable to stat editor (%s)"), UserEditor);
+ fatal(_("unable to stat editor (%s)"), UserEditor);
}
EditorPath = estrdup(def_editor);
Editor = strtok(EditorPath, ":");
/* Bleah, none of the editors existed! */
if (Editor == NULL || *Editor == '\0')
- errorx(1, _("no editor found (editor path = %s)"), def_editor);
+ fatalx(_("no editor found (editor path = %s)"), def_editor);
}
*args = EditorArgs;
debug_return_str(Editor);
* or certain pam modules won't be able to track their state.
*/
if (policy_init_session(details) != true)
- errorx(1, _("policy plugin failed session initialization"));
+ fatalx(_("policy plugin failed session initialization"));
cmnd_pid = sudo_debug_fork();
switch (cmnd_pid) {
case -1:
- error(1, _("unable to fork"));
+ fatal(_("unable to fork"));
break;
case 0:
/* child */
* Parent sends signal info to child and child sends back wait status.
*/
if (socketpair(PF_UNIX, SOCK_DGRAM, 0, sv) == -1)
- error(1, _("unable to create sockets"));
+ fatal(_("unable to create sockets"));
/*
* Signals to forward to the child process (excluding SIGALRM and SIGCHLD).
preload = fmt_string(RTLD_PRELOAD_VAR, sudo_conf_noexec_path());
# endif
if (preload == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
nenvp[env_len++] = preload;
nenvp[env_len] = NULL;
} else {
if (io_fds[SFD_USERTTY] != -1) {
if (!get_pty(&io_fds[SFD_MASTER], &io_fds[SFD_SLAVE],
slavename, sizeof(slavename), uid))
- error(1, _("unable to allocate pty"));
+ fatal(_("unable to allocate pty"));
/* Add entry to utmp/utmpx? */
if (utmp_user != NULL)
utmp_login(tty, slavename, io_fds[SFD_SLAVE], utmp_user);
sudo_debug_printf(SUDO_DEBUG_INFO, "stdin not a tty, creating a pipe");
pipeline = true;
if (pipe(io_pipe[STDIN_FILENO]) != 0)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
iobufs = io_buf_new(STDIN_FILENO, io_pipe[STDIN_FILENO][1],
log_stdin, iobufs);
io_fds[SFD_STDIN] = io_pipe[STDIN_FILENO][0];
sudo_debug_printf(SUDO_DEBUG_INFO, "stdout not a tty, creating a pipe");
pipeline = true;
if (pipe(io_pipe[STDOUT_FILENO]) != 0)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
iobufs = io_buf_new(io_pipe[STDOUT_FILENO][0], STDOUT_FILENO,
log_stdout, iobufs);
io_fds[SFD_STDOUT] = io_pipe[STDOUT_FILENO][1];
if (io_fds[SFD_STDERR] == -1 || !isatty(STDERR_FILENO)) {
sudo_debug_printf(SUDO_DEBUG_INFO, "stderr not a tty, creating a pipe");
if (pipe(io_pipe[STDERR_FILENO]) != 0)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
iobufs = io_buf_new(io_pipe[STDERR_FILENO][0], STDERR_FILENO,
log_stderr, iobufs);
io_fds[SFD_STDERR] = io_pipe[STDERR_FILENO][1];
n = term_raw(io_fds[SFD_USERTTY], 0);
} while (!n && errno == EINTR);
if (!n)
- error(1, _("unable to set terminal to raw mode"));
+ fatal(_("unable to set terminal to raw mode"));
}
}
* or certain pam modules won't be able to track their state.
*/
if (policy_init_session(details) != true)
- errorx(1, _("policy plugin failed session initialization"));
+ fatalx(_("policy plugin failed session initialization"));
/*
* Block some signals until cmnd_pid is set in the parent to avoid a
child = sudo_debug_fork();
switch (child) {
case -1:
- error(1, _("unable to fork"));
+ fatal(_("unable to fork"));
break;
case 0:
/* child */
* the select() loop.
*/
if (pipe_nonblock(signal_pipe) != 0)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
/* Reset SIGWINCH and SIGALRM. */
memset(&sa, 0, sizeof(sa));
if (io_fds[SFD_SLAVE] != -1) {
#ifdef TIOCSCTTY
if (ioctl(io_fds[SFD_SLAVE], TIOCSCTTY, NULL) != 0)
- error(1, _("unable to set controlling tty"));
+ fatal(_("unable to set controlling tty"));
#else
/* Set controlling tty by reopening slave. */
if ((n = open(slavename, O_RDWR)) >= 0)
/* Start command and wait for it to stop or exit */
if (pipe(errpipe) == -1)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
cmnd_pid = sudo_debug_fork();
if (cmnd_pid == -1) {
warning(_("unable to fork"));
debug_decl(exec_pty, SUDO_DEBUG_EXEC);
/* Register cleanup function */
- error_callback_register(pty_cleanup);
+ fatal_callback_register(pty_cleanup);
/* Set command process group here too to avoid a race. */
setpgid(0, self);
if (dup2(io_fds[SFD_STDIN], STDIN_FILENO) == -1 ||
dup2(io_fds[SFD_STDOUT], STDOUT_FILENO) == -1 ||
dup2(io_fds[SFD_STDERR], STDERR_FILENO) == -1)
- error(1, "dup2");
+ fatal("dup2");
/* Wait for parent to grant us the tty if we are foreground. */
if (foreground && !ISSET(details->flags, CD_EXEC_BG)) {
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
- error(1, _("unable to open socket"));
+ fatal(_("unable to open socket"));
/*
* Get interface configuration or return.
break;
case 'U':
if ((getpwnam(optarg)) == NULL)
- errorx(1, _("unknown user: %s"), optarg);
+ fatalx(_("unknown user: %s"), optarg);
list_user = optarg;
break;
case 'u':
settings[j] = fmt_string(sudo_settings[i].name,
sudo_settings[i].value);
if (settings[j] == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
j++;
}
}
argv--;
argv[0] = "sudoedit";
#else
- errorx(1, _("sudoedit is not supported on this platform"));
+ fatalx(_("sudoedit is not supported on this platform"));
#endif
}
/* Kernel may not have audit support. */
if (errno != EINVAL && errno != EPROTONOSUPPORT && errno != EAFNOSUPPORT
)
- error(1, _("unable to open audit system"));
+ fatal(_("unable to open audit system"));
} else {
/* audit role change using the same format as newrole(1) */
easprintf(&message, "newrole: old-context=%s new-context=%s",
* the select() loop without races (we may not have pselect()).
*/
if (pipe_nonblock(signal_pipe) != 0)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
memset(&sa, 0, sizeof(sa));
sigfillset(&sa.sa_mask);
/* Load plugins. */
if (!sudo_load_plugins(&policy_plugin, &io_plugins))
- errorx(1, _("fatal error, unable to load plugins"));
+ fatalx(_("fatal error, unable to load plugins"));
/* Open policy plugin. */
ok = policy_open(&policy_plugin, settings, user_info, envp);
if (ok == -2)
usage(1);
else
- errorx(1, _("unable to initialize policy plugin"));
+ fatalx(_("unable to initialize policy plugin"));
}
init_signals();
usage(1);
break;
default:
- errorx(1, _("error initializing I/O plugin %s"),
+ fatalx(_("error initializing I/O plugin %s"),
plugin->name);
}
}
/* The close method was called by sudo_edit/run_command. */
break;
default:
- errorx(1, _("unexpected sudo mode 0x%x"), sudo_mode);
+ fatalx(_("unexpected sudo mode 0x%x"), sudo_mode);
}
sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, exitcode);
exit(exitcode);
miss[STDERR_FILENO] = fcntl(STDERR_FILENO, F_GETFL, 0) == -1;
if (miss[STDIN_FILENO] || miss[STDOUT_FILENO] || miss[STDERR_FILENO]) {
if ((devnull = open(_PATH_DEVNULL, O_RDWR, 0644)) == -1)
- error(1, _("unable to open %s"), _PATH_DEVNULL);
+ fatal(_("unable to open %s"), _PATH_DEVNULL);
if (miss[STDIN_FILENO] && dup2(devnull, STDIN_FILENO) == -1)
- error(1, "dup2");
+ fatal("dup2");
if (miss[STDOUT_FILENO] && dup2(devnull, STDOUT_FILENO) == -1)
- error(1, "dup2");
+ fatal("dup2");
if (miss[STDERR_FILENO] && dup2(devnull, STDERR_FILENO) == -1)
- error(1, "dup2");
+ fatal("dup2");
if (devnull > STDERR_FILENO)
close(devnull);
}
* Typically, this is because NFS can only support up to 16 groups.
*/
if (fill_group_list(ud, maxgroups) == -1)
- error(1, _("unable to get group vector"));
+ fatal(_("unable to get group vector"));
}
/*
pw = getpwuid(ud->uid);
if (pw == NULL)
- errorx(1, _("unknown uid %u: who are you?"), (unsigned int)ud->uid);
+ fatalx(_("unknown uid %u: who are you?"), (unsigned int)ud->uid);
user_info[i] = fmt_string("user", pw->pw_name);
if (user_info[i] == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
ud->username = user_info[i] + sizeof("user=") - 1;
/* Stash user's shell for use with the -s flag; don't pass to plugin. */
if (getcwd(cwd, sizeof(cwd)) != NULL) {
user_info[++i] = fmt_string("cwd", cwd);
if (user_info[i] == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
ud->cwd = user_info[i] + sizeof("cwd=") - 1;
}
if ((cp = get_process_ttyname()) != NULL) {
user_info[++i] = fmt_string("tty", cp);
if (user_info[i] == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
ud->tty = user_info[i] + sizeof("tty=") - 1;
efree(cp);
}
strlcpy(host, "localhost", sizeof(host));
user_info[++i] = fmt_string("host", host);
if (user_info[i] == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
ud->host = user_info[i] + sizeof("host=") - 1;
get_ttysize(&ud->ts_lines, &ud->ts_cols);
#endif
details->pw = getpwuid(details->euid);
if (details->pw != NULL && (details->pw = pw_dup(details->pw)) == NULL)
- errorx(1, NULL);
+ fatalx(NULL);
#ifdef HAVE_SETAUTHDB
aix_restoreauthdb();
#endif
if (strchr(path, '/') != NULL && stat(path, &sb) == 0) {
/* Try to determine why sudo was not running as root. */
if (sb.st_uid != ROOT_UID || !ISSET(sb.st_mode, S_ISUID)) {
- errorx(1,
+ fatalx(
_("%s must be owned by uid %d and have the setuid bit set"),
path, ROOT_UID);
} else {
- errorx(1, _("effective uid is not %d, is %s on a file system "
+ fatalx(_("effective uid is not %d, is %s on a file system "
"with the 'nosuid' option set or an NFS file system without"
" root privileges?"), ROOT_UID, path);
}
} else {
- errorx(1,
+ fatalx(
_("effective uid is not %d, is sudo installed setuid root?"),
ROOT_UID);
}
{
debug_decl(policy_check, SUDO_DEBUG_PCOMM)
if (plugin->u.policy->check_policy == NULL) {
- errorx(1, _("policy plugin %s is missing the `check_policy' method"),
+ fatalx(_("policy plugin %s is missing the `check_policy' method"),
plugin->name);
}
debug_return_bool(plugin->u.policy->check_policy(argc, argv, env_add,
{
debug_decl(policy_invalidate, SUDO_DEBUG_PCOMM)
if (plugin->u.policy->invalidate == NULL) {
- errorx(1, _("policy plugin %s does not support the -k/-K options"),
+ fatalx(_("policy plugin %s does not support the -k/-K options"),
plugin->name);
}
plugin->u.policy->invalidate(remove);
/* When restoring root, change euid first; otherwise change it last. */
if (euid == ROOT_UID) {
if (seteuid(ROOT_UID) != 0)
- error(1, "seteuid(ROOT_UID)");
+ fatal("seteuid(ROOT_UID)");
}
if (setegid(egid) != 0)
- error(1, "setegid(%d)", (int)egid);
+ fatal("setegid(%d)", (int)egid);
if (ngroups != -1) {
if (sudo_setgroups(ngroups, groups) != 0)
- error(1, "setgroups");
+ fatal("setgroups");
}
if (euid != ROOT_UID) {
if (seteuid(euid) != 0)
- error(1, "seteuid(%d)", (int)euid);
+ fatal("seteuid(%d)", (int)euid);
}
errno = serrno;
easprintf(&tf[j].tfile, "%.*s/%s.XXXXXXXX", tmplen, tmpdir, cp);
}
if (seteuid(user_details.uid) != 0)
- error(1, "seteuid(%d)", (int)user_details.uid);
+ fatal("seteuid(%d)", (int)user_details.uid);
tfd = mkstemps(tf[j].tfile, suff ? strlen(suff) : 0);
if (seteuid(ROOT_UID) != 0)
- error(1, "seteuid(ROOT_UID)");
+ fatal("seteuid(ROOT_UID)");
if (tfd == -1) {
warning("mkstemps");
goto cleanup;
for (i = 0; i < nfiles; i++) {
rc = -1;
if (seteuid(user_details.uid) != 0)
- error(1, "seteuid(%d)", (int)user_details.uid);
+ fatal("seteuid(%d)", (int)user_details.uid);
if ((tfd = open(tf[i].tfile, O_RDONLY, 0644)) != -1) {
rc = fstat(tfd, &sb);
}
if (seteuid(ROOT_UID) != 0)
- error(1, "seteuid(ROOT_UID)");
+ fatal("seteuid(ROOT_UID)");
if (rc || !S_ISREG(sb.st_mode)) {
if (rc)
warning("%s", tf[i].tfile);
/* If using a helper program to get the password, run it instead. */
if (ISSET(flags, TGP_ASKPASS)) {
if (askpass == NULL || *askpass == '\0')
- errorx(1, _("no askpass program specified, try setting SUDO_ASKPASS"));
+ fatalx(_("no askpass program specified, try setting SUDO_ASKPASS"));
debug_return_str_masked(sudo_askpass(askpass, prompt));
}
debug_decl(sudo_askpass, SUDO_DEBUG_CONV)
if (pipe(pfd) == -1)
- error(1, _("unable to create pipe"));
+ fatal(_("unable to create pipe"));
if ((pid = fork()) == -1)
- error(1, _("unable to fork"));
+ fatal(_("unable to fork"));
if (pid == 0) {
/* child, point stdout to output side of the pipe and exec askpass */
* doesn't take an argument.
*/
if ((sfd = dup(STDIN_FILENO)) == -1)
- error(1, _("unable to save stdin"));
+ fatal(_("unable to save stdin"));
if (dup2(ttyfd, STDIN_FILENO) == -1)
- error(1, _("unable to dup2 stdin"));
+ fatal(_("unable to dup2 stdin"));
slot = ttyslot();
if (dup2(sfd, STDIN_FILENO) == -1)
- error(1, _("unable to restore stdin"));
+ fatal(_("unable to restore stdin"));
close(sfd);
debug_return_int(slot);