From 21a2f95821c350a8e748025059b6362e3d635182 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 2 Dec 2011 11:27:33 -0500 Subject: [PATCH] Use stdbool.h instead of rolling our own TRUE/FALSE macros. --- common/fileops.c | 19 ++- common/sudo_debug.c | 10 +- configure | 4 +- configure.in | 4 +- include/fileops.h | 2 +- plugins/sample/Makefile.in | 2 +- plugins/sample/sample_plugin.c | 56 ++++--- plugins/sample_group/Makefile.in | 2 +- plugins/sample_group/sample_group.c | 28 ++-- plugins/sudoers/alias.c | 6 +- plugins/sudoers/auth/sudo_auth.c | 14 +- plugins/sudoers/check.c | 32 ++-- plugins/sudoers/defaults.c | 234 +++++++++++++-------------- plugins/sudoers/defaults.h | 2 +- plugins/sudoers/env.c | 110 ++++++------- plugins/sudoers/find_path.c | 4 +- plugins/sudoers/goodpath.c | 8 +- plugins/sudoers/gram.c | 219 +++++++++++++------------ plugins/sudoers/gram.y | 51 +++--- plugins/sudoers/group_plugin.c | 15 +- plugins/sudoers/iolog.c | 40 ++--- plugins/sudoers/iolog_path.c | 5 +- plugins/sudoers/ldap.c | 239 ++++++++++++++-------------- plugins/sudoers/match.c | 116 +++++++------- plugins/sudoers/match_addr.c | 26 +-- plugins/sudoers/parse.c | 18 +-- plugins/sudoers/parse.h | 20 +-- plugins/sudoers/pwutil.c | 13 +- plugins/sudoers/sudo_nss.c | 38 ++--- plugins/sudoers/sudoers.c | 59 +++---- plugins/sudoers/sudoers.h | 25 ++- plugins/sudoers/testsudoers.c | 12 +- plugins/sudoers/toke.c | 203 +++++++++++------------ plugins/sudoers/toke.h | 10 +- plugins/sudoers/toke.l | 73 ++++----- plugins/sudoers/toke_util.c | 26 +-- plugins/sudoers/visudo.c | 143 ++++++++--------- src/exec.c | 9 +- src/exec_pty.c | 79 +++++---- src/load_plugins.c | 34 ++-- src/sudo.c | 40 ++--- src/sudo.h | 17 +- src/sudo_exec.h | 6 +- src/sudo_plugin_int.h | 2 +- src/utmp.c | 33 ++-- 45 files changed, 1060 insertions(+), 1048 deletions(-) diff --git a/common/fileops.c b/common/fileops.c index 7e48a66a8..f99710c03 100644 --- a/common/fileops.c +++ b/common/fileops.c @@ -28,6 +28,11 @@ # include #endif /* HAVE_FLOCK */ #include +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif #ifdef HAVE_STRING_H # include #endif /* HAVE_STRING_H */ @@ -84,7 +89,7 @@ touch(int fd, char *path, struct timeval *tvp) * Lock/unlock a file. */ #ifdef HAVE_LOCKF -int +bool lock_file(int fd, int lockit) { int op = 0; @@ -101,10 +106,10 @@ lock_file(int fd, int lockit) op = F_ULOCK; break; } - debug_return_int(lockf(fd, op, 0) == 0); + debug_return_bool(lockf(fd, op, 0) == 0); } #elif HAVE_FLOCK -int +bool lock_file(int fd, int lockit) { int op = 0; @@ -121,10 +126,10 @@ lock_file(int fd, int lockit) op = LOCK_UN; break; } - debug_return_int(flock(fd, op) == 0); + debug_return_bool(flock(fd, op) == 0); } #else -int +bool lock_file(int fd, int lockit) { #ifdef F_SETLK @@ -139,9 +144,9 @@ lock_file(int fd, int lockit) lock.l_whence = SEEK_SET; func = (lockit == SUDO_LOCK) ? F_SETLKW : F_SETLK; - debug_return_int(fcntl(fd, func, &lock) == 0); + debug_return_bool(fcntl(fd, func, &lock) == 0); #else - return TRUE; + return true; #endif } #endif diff --git a/common/sudo_debug.c b/common/sudo_debug.c index 6de605fdd..ea38d2448 100644 --- a/common/sudo_debug.c +++ b/common/sudo_debug.c @@ -29,6 +29,11 @@ # include # endif #endif /* STDC_HEADERS */ +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif #ifdef HAVE_STRING_H # include #endif /* HAVE_STRING_H */ @@ -195,15 +200,16 @@ void sudo_debug_exit_long(const char *func, const char *file, int line, void sudo_debug_exit_size_t(const char *func, const char *file, int line, int subsys, size_t rval) { - /* XXX - should use %zu but snprintf.c doesn't support it */ + /* XXX - should use %zu but our snprintf.c doesn't support it */ sudo_debug_printf2(subsys | SUDO_DEBUG_TRACE, "<- %s @ %s:%d := %lu", func, file, line, (unsigned long)rval); } +/* We use int, not bool, here for functions that return -1 on error. */ void sudo_debug_exit_bool(const char *func, const char *file, int line, int subsys, int rval) { - if (rval == 0 || rval == 1) { + if (rval == true || rval == false) { sudo_debug_printf2(subsys | SUDO_DEBUG_TRACE, "<- %s @ %s:%d := %s", func, file, line, rval ? "true" : "false"); } else { diff --git a/configure b/configure index 036709b1f..13e16c892 100755 --- a/configure +++ b/configure @@ -5461,12 +5461,12 @@ fi if test "$env_reset" = "on"; then { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 $as_echo "yes" >&6; } - $as_echo "#define ENV_RESET TRUE" >>confdefs.h + $as_echo "#define ENV_RESET 1" >>confdefs.h else { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - $as_echo "#define ENV_RESET FALSE" >>confdefs.h + $as_echo "#define ENV_RESET 0" >>confdefs.h fi diff --git a/configure.in b/configure.in index a91ae0192..9051c6df7 100644 --- a/configure.in +++ b/configure.in @@ -1272,10 +1272,10 @@ AC_ARG_ENABLE(env_reset, ]) if test "$env_reset" = "on"; then AC_MSG_RESULT(yes) - AC_DEFINE(ENV_RESET, TRUE) + AC_DEFINE(ENV_RESET, 1) else AC_MSG_RESULT(no) - AC_DEFINE(ENV_RESET, FALSE) + AC_DEFINE(ENV_RESET, 0) fi AC_ARG_ENABLE(warnings, diff --git a/include/fileops.h b/include/fileops.h index e1c93a69f..cd0a0dfe8 100644 --- a/include/fileops.h +++ b/include/fileops.h @@ -26,7 +26,7 @@ struct timeval; -int lock_file(int, int); +bool lock_file(int, int); int touch(int, char *, struct timeval *); char *sudo_parseln(FILE *); diff --git a/plugins/sample/Makefile.in b/plugins/sample/Makefile.in index 12d77d48e..3ace25459 100644 --- a/plugins/sample/Makefile.in +++ b/plugins/sample/Makefile.in @@ -36,7 +36,7 @@ INSTALL = $(SHELL) $(top_srcdir)/install-sh -c LIBS = $(LIBOBJDIR)/libreplace.la # C preprocessor flags -CPPFLAGS = -I$(incdir) -I$(top_builddir) @CPPFLAGS@ +CPPFLAGS = -I$(incdir) -I$(top_builddir) -I$(top_srcdir) @CPPFLAGS@ # Usually -O and/or -g CFLAGS = @CFLAGS@ diff --git a/plugins/sample/sample_plugin.c b/plugins/sample/sample_plugin.c index 5ac19a42b..51ec2451a 100644 --- a/plugins/sample/sample_plugin.c +++ b/plugins/sample/sample_plugin.c @@ -30,6 +30,11 @@ # include # endif #endif /* STDC_HEADERS */ +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif /* HAVE_STDBOOL_H */ #ifdef HAVE_STRING_H # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) # include @@ -65,13 +70,6 @@ # define ROOT_UID 0 #endif -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE 0 -#undef ERROR -#define ERROR -1 - static struct plugin_state { char **envp; char * const *settings; @@ -82,7 +80,7 @@ static sudo_printf_t sudo_log; static FILE *input, *output; static uid_t runas_uid = ROOT_UID; static gid_t runas_gid = -1; -static int use_sudoedit = FALSE; +static int use_sudoedit = false; /* * Allocate storage for a name=value string and return it. @@ -130,7 +128,7 @@ policy_open(unsigned int version, sudo_conv_t conversation, sudo_log(SUDO_CONV_ERROR_MSG, "the sample plugin requires API version %d.x\n", SUDO_API_VERSION_MAJOR); - return ERROR; + return -1; } /* Only allow commands to be run as root. */ @@ -149,7 +147,7 @@ policy_open(unsigned int version, sudo_conv_t conversation, /* Check to see if sudo was called as sudoedit or with -e flag. */ if (strncmp(*ui, "sudoedit=", sizeof("sudoedit=") - 1) == 0) { if (strcasecmp(*ui + sizeof("sudoedit=") - 1, "true") == 0) - use_sudoedit = TRUE; + use_sudoedit = true; } /* This plugin doesn't support running sudo with no arguments. */ if (strncmp(*ui, "implied_shell=", sizeof("implied_shell=") - 1) == 0) { @@ -229,13 +227,13 @@ check_passwd(void) sudo_conv(1, &msg, &repl); if (repl.reply == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "missing password\n"); - return FALSE; + return false; } if (strcmp(repl.reply, "test") != 0) { sudo_log(SUDO_CONV_ERROR_MSG, "incorrect password\n"); - return FALSE; + return false; } - return TRUE; + return true; } static char ** @@ -341,30 +339,30 @@ policy_check(int argc, char * const argv[], if (!argc || argv[0] == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "no command specified\n"); - return FALSE; + return false; } if (!check_passwd()) - return FALSE; + return false; command = find_in_path(argv[0], plugin_state.envp); if (command == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "%s: command not found\n", argv[0]); - return FALSE; + return false; } /* If "sudo vi" is run, auto-convert to sudoedit. */ if (strcmp(command, _PATH_VI) == 0) - use_sudoedit = TRUE; + use_sudoedit = true; if (use_sudoedit) { /* Rebuild argv using editor */ command = find_editor(argc - 1, argv + 1, argv_out); if (command == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "unable to find valid editor\n"); - return ERROR; + return -1; } - use_sudoedit = TRUE; + use_sudoedit = true; } else { /* No changes needd to argv */ *argv_out = (char **)argv; @@ -377,10 +375,10 @@ policy_check(int argc, char * const argv[], *command_info_out = build_command_info(command); if (*command_info_out == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "out of memory\n"); - return ERROR; + return -1; } - return TRUE; + return true; } static int @@ -390,14 +388,14 @@ policy_list(int argc, char * const argv[], int verbose, const char *list_user) * List user's capabilities. */ sudo_log(SUDO_CONV_INFO_MSG, "Validated users may run any command\n"); - return TRUE; + return true; } static int policy_version(int verbose) { sudo_log(SUDO_CONV_INFO_MSG, "Sample policy plugin version %s\n", PACKAGE_VERSION); - return TRUE; + return true; } static void @@ -439,17 +437,17 @@ io_open(unsigned int version, sudo_conv_t conversation, (unsigned int)getpid()); fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd == -1) - return FALSE; + return false; output = fdopen(fd, "w"); snprintf(path, sizeof(path), "/var/tmp/sample-%u.input", (unsigned int)getpid()); fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0644); if (fd == -1) - return FALSE; + return false; input = fdopen(fd, "w"); - return TRUE; + return true; } static void @@ -464,21 +462,21 @@ io_version(int verbose) { sudo_log(SUDO_CONV_INFO_MSG, "Sample I/O plugin version %s\n", PACKAGE_VERSION); - return TRUE; + return true; } static int io_log_input(const char *buf, unsigned int len) { fwrite(buf, len, 1, input); - return TRUE; + return true; } static int io_log_output(const char *buf, unsigned int len) { fwrite(buf, len, 1, output); - return TRUE; + return true; } struct policy_plugin sample_policy = { diff --git a/plugins/sample_group/Makefile.in b/plugins/sample_group/Makefile.in index 9c4207ad7..5c208ea0c 100644 --- a/plugins/sample_group/Makefile.in +++ b/plugins/sample_group/Makefile.in @@ -36,7 +36,7 @@ INSTALL = $(SHELL) $(top_srcdir)/install-sh -c LIBS = $(LIBOBJDIR)/libreplace.la # C preprocessor flags -CPPFLAGS = -I$(incdir) -I$(top_builddir) @CPPFLAGS@ +CPPFLAGS = -I$(incdir) -I$(top_builddir) -I$(top_srcdir) @CPPFLAGS@ # Usually -O and/or -g CFLAGS = @CFLAGS@ diff --git a/plugins/sample_group/sample_group.c b/plugins/sample_group/sample_group.c index dbd1c2709..2e3628d24 100644 --- a/plugins/sample_group/sample_group.c +++ b/plugins/sample_group/sample_group.c @@ -29,6 +29,11 @@ # include # endif #endif /* STDC_HEADERS */ +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif /* HAVE_STDBOOL_H */ #ifdef HAVE_STRING_H # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS) # include @@ -56,13 +61,6 @@ * same format as /etc/group. */ -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE 0 -#undef ERROR -#define ERROR -1 - static sudo_printf_t sudo_log; extern void mysetgrfile(const char *); @@ -82,30 +80,30 @@ sample_init(int version, sudo_printf_t sudo_printf, char *const argv[]) "sample_group: incompatible major version %d, expected %d\n", GROUP_API_VERSION_GET_MAJOR(version), GROUP_API_VERSION_MAJOR); - return ERROR; + return -1; } /* Sanity check the specified group file. */ if (argv == NULL || argv[0] == NULL) { sudo_log(SUDO_CONV_ERROR_MSG, "sample_group: path to group file not specified\n"); - return ERROR; + return -1; } if (stat(argv[0], &sb) != 0) { sudo_log(SUDO_CONV_ERROR_MSG, "sample_group: %s: %s\n", argv[0], strerror(errno)); - return ERROR; + return -1; } if ((sb.st_mode & (S_IWGRP|S_IWOTH)) != 0) { sudo_log(SUDO_CONV_ERROR_MSG, "%s must be only be writable by owner\n", argv[0]); - return ERROR; + return -1; } mysetgrfile(argv[0]); mysetgrent(); - return TRUE; + return true; } static void @@ -115,7 +113,7 @@ sample_cleanup(void) } /* - * Returns TRUE if "user" is a member of "group", else FALSE. + * Returns true if "user" is a member of "group", else false. */ static int sample_query(const char *user, const char *group, const struct passwd *pwd) @@ -127,11 +125,11 @@ sample_query(const char *user, const char *group, const struct passwd *pwd) if (grp != NULL) { for (member = grp->gr_mem; *member != NULL; member++) { if (strcasecmp(user, *member) == 0) - return TRUE; + return true; } } - return FALSE; + return false; } struct sudoers_group_plugin group_plugin = { diff --git a/plugins/sudoers/alias.c b/plugins/sudoers/alias.c index 14ed9bf3d..aaba72881 100644 --- a/plugins/sudoers/alias.c +++ b/plugins/sudoers/alias.c @@ -143,13 +143,13 @@ alias_apply(int (*func)(void *, void *), void *cookie) } /* - * Returns TRUE if there are no aliases, else FALSE. + * Returns true if there are no aliases, else false. */ -int +bool no_aliases(void) { debug_decl(no_aliases, SUDO_DEBUG_ALIAS) - debug_return_int(rbisempty(aliases)); + debug_return_bool(rbisempty(aliases)); } /* diff --git a/plugins/sudoers/auth/sudo_auth.c b/plugins/sudoers/auth/sudo_auth.c index bc1c4eae9..dded9cc53 100644 --- a/plugins/sudoers/auth/sudo_auth.c +++ b/plugins/sudoers/auth/sudo_auth.c @@ -108,7 +108,7 @@ sudo_auth_init(struct passwd *pw) debug_decl(sudo_auth_init, SUDO_DEBUG_AUTH) if (auth_switch[0].name == NULL) - debug_return_int(TRUE); + debug_return_int(true); /* Make sure we haven't mixed standalone and shared auth methods. */ standalone = IS_STANDALONE(&auth_switch[0]); @@ -143,7 +143,7 @@ sudo_auth_init(struct passwd *pw) } } } - debug_return_int(status == AUTH_FATAL ? -1 : TRUE); + debug_return_int(status == AUTH_FATAL ? -1 : true); } int @@ -171,7 +171,7 @@ sudo_auth_cleanup(struct passwd *pw) } } } - debug_return_int(status == AUTH_FATAL ? -1 : TRUE); + debug_return_int(status == AUTH_FATAL ? -1 : true); } int @@ -259,7 +259,7 @@ done: switch (success) { case AUTH_SUCCESS: (void) sigaction(SIGTSTP, &osa, NULL); - rval = TRUE; + rval = true; break; case AUTH_INTR: case AUTH_FAILURE: @@ -273,7 +273,7 @@ done: def_passwd_tries - counter), def_passwd_tries - counter); } audit_failure(NewArgv, "authentication failure"); - rval = FALSE; + rval = false; break; case AUTH_FATAL: default: @@ -302,7 +302,7 @@ sudo_auth_begin_session(struct passwd *pw) } } } - debug_return_bool(TRUE); + debug_return_bool(true); } int @@ -321,7 +321,7 @@ sudo_auth_end_session(struct passwd *pw) } } } - debug_return_bool(TRUE); + debug_return_bool(true); } static void diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c index 7d74bab63..2850fe83a 100644 --- a/plugins/sudoers/check.c +++ b/plugins/sudoers/check.c @@ -89,11 +89,11 @@ static int timestamp_status(char *, char *, char *, int); static char *expand_prompt(char *, char *, char *); static void lecture(int); static void update_timestamp(char *, char *); -static int tty_is_devpts(const char *); +static bool tty_is_devpts(const char *); static struct passwd *get_authpw(void); /* - * Returns TRUE if the user successfully authenticates, else FALSE. + * Returns true if the user successfully authenticates, else false. */ int check_user(int validated, int mode) @@ -103,8 +103,8 @@ check_user(int validated, int mode) char *timestampfile = NULL; char *prompt; struct stat sb; - int status, rval = TRUE; - int need_pass = def_authenticate; + int status, rval = true; + bool need_pass = def_authenticate; debug_decl(check_user, SUDO_DEBUG_AUTH) /* @@ -129,7 +129,7 @@ check_user(int validated, int mode) if (user_uid == 0 || (user_uid == runas_pw->pw_uid && (!runas_gr || user_in_group(sudo_user.pw, runas_gr->gr_name))) || user_is_exempt()) - need_pass = FALSE; + need_pass = false; } } if (!need_pass) @@ -170,7 +170,7 @@ check_user(int validated, int mode) rval = verify_user(auth_pw, prompt); } /* Only update timestamp if user was validated. */ - if (rval == TRUE && ISSET(validated, VALIDATE_OK) && + if (rval == true && ISSET(validated, VALIDATE_OK) && !ISSET(mode, MODE_IGNORE_TICKET) && status != TS_ERROR) update_timestamp(timestampdir, timestampfile); efree(timestampdir); @@ -180,7 +180,7 @@ done: sudo_auth_cleanup(auth_pw); pw_delref(auth_pw); - debug_return_int(rval); + debug_return_bool(rval); } #define DEFAULT_LECTURE "\n" \ @@ -399,10 +399,10 @@ oflow: /* * Checks if the user is exempt from supplying a password. */ -int +bool user_is_exempt(void) { - int rval = FALSE; + bool rval = false; debug_decl(user_is_exempt, SUDO_DEBUG_AUTH) if (def_exempt_group) @@ -660,7 +660,7 @@ done: * Remove the timestamp ticket file/dir. */ void -remove_timestamp(int remove) +remove_timestamp(bool remove) { struct timeval tv; char *timestampdir, *timestampfile, *path; @@ -683,7 +683,7 @@ remove_timestamp(int remove) log_error(NO_EXIT, _("unable to remove %s (%s), will reset to the epoch"), path, strerror(errno)); - remove = FALSE; + remove = false; } } if (!remove) { @@ -699,17 +699,17 @@ remove_timestamp(int remove) } /* - * Returns TRUE if tty lives on a devpts or /devices filesystem, else FALSE. + * Returns true if tty lives on a devpts or /devices filesystem, else false. * Unlike most filesystems, the ctime of devpts nodes is not updated when * the device node is written to, only when the inode's status changes, * typically via the chmod, chown, link, rename, or utimes system calls. * Since the ctime is "stable" in this case, we can stash it the tty ticket * file and use it to determine whether the tty ticket file is stale. */ -static int +static bool tty_is_devpts(const char *tty) { - int retval = FALSE; + bool retval = false; #ifdef __linux__ struct statfs sfs; debug_decl(tty_is_devpts, SUDO_DEBUG_PTY) @@ -720,7 +720,7 @@ tty_is_devpts(const char *tty) if (statfs(tty, &sfs) == 0) { if (sfs.f_type == DEVPTS_SUPER_MAGIC) - retval = TRUE; + retval = true; } #elif defined(__sun) && defined(__SVR4) struct statvfs sfs; @@ -728,7 +728,7 @@ tty_is_devpts(const char *tty) if (statvfs(tty, &sfs) == 0) { if (strcmp(sfs.f_fstr, "devices") == 0) - retval = TRUE; + retval = true; } #else debug_decl(tty_is_devpts, SUDO_DEBUG_PTY) diff --git a/plugins/sudoers/defaults.c b/plugins/sudoers/defaults.c index c0943a9cd..717cbf79d 100644 --- a/plugins/sudoers/defaults.c +++ b/plugins/sudoers/defaults.c @@ -91,15 +91,15 @@ static struct strmap priorities[] = { /* * Local prototypes. */ -static int store_int(char *, struct sudo_defs_types *, int); -static int store_list(char *, struct sudo_defs_types *, int); -static int store_mode(char *, struct sudo_defs_types *, int); -static int store_str(char *, struct sudo_defs_types *, int); -static int store_syslogfac(char *, struct sudo_defs_types *, int); -static int store_syslogpri(char *, struct sudo_defs_types *, int); -static int store_tuple(char *, struct sudo_defs_types *, int); -static int store_uint(char *, struct sudo_defs_types *, int); -static int store_float(char *, struct sudo_defs_types *, int); +static bool store_int(char *, struct sudo_defs_types *, bool); +static bool store_list(char *, struct sudo_defs_types *, bool); +static bool store_mode(char *, struct sudo_defs_types *, bool); +static bool store_str(char *, struct sudo_defs_types *, bool); +static bool store_syslogfac(char *, struct sudo_defs_types *, bool); +static bool store_syslogpri(char *, struct sudo_defs_types *, bool); +static bool store_tuple(char *, struct sudo_defs_types *, bool); +static bool store_uint(char *, struct sudo_defs_types *, bool); +static bool store_float(char *, struct sudo_defs_types *, bool); static void list_op(char *, size_t, struct sudo_defs_types *, enum list_ops); static const char *logfac2str(int); static const char *logpri2str(int); @@ -193,8 +193,8 @@ dump_defaults(void) * Eg. you may want to turn off logging to a file for some hosts. * This is only meaningful for variables that are *optional*. */ -int -set_default(char *var, char *val, int op) +bool +set_default(char *var, char *val, bool op) { struct sudo_defs_types *cur; int num; @@ -206,7 +206,7 @@ set_default(char *var, char *val, int op) } if (!cur->name) { warningx(_("unknown defaults entry `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } switch (cur->type & T_MASK) { @@ -217,7 +217,7 @@ set_default(char *var, char *val, int op) val, var); else warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_LOGPRI: @@ -227,111 +227,111 @@ set_default(char *var, char *val, int op) val, var); else warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_STR: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (ISSET(cur->type, T_PATH) && val && *val != '/') { warningx(_("values for `%s' must start with a '/'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } if (!store_str(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_INT: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (!store_int(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_UINT: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (!store_uint(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_FLOAT: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (!store_float(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_MODE: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (!store_mode(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_FLAG: if (val) { warningx(_("option `%s' does not take a value"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } cur->sd_un.flag = op; break; case T_LIST: if (!val) { /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { + if (!ISSET(cur->type, T_BOOL) || op != false) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (!store_list(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; case T_TUPLE: if (!val && !ISSET(cur->type, T_BOOL)) { warningx(_("no value specified for `%s'"), var); - debug_return_bool(FALSE); + debug_return_bool(false); } if (!store_tuple(val, cur, op)) { warningx(_("value `%s' is invalid for option `%s'"), val, var); - debug_return_bool(FALSE); + debug_return_bool(false); } break; } - debug_return_bool(TRUE); + debug_return_bool(true); } /* @@ -363,78 +363,78 @@ init_defaults(void) /* First initialize the flags. */ #ifdef LONG_OTP_PROMPT - def_long_otp_prompt = TRUE; + def_long_otp_prompt = true; #endif #ifdef IGNORE_DOT_PATH - def_ignore_dot = TRUE; + def_ignore_dot = true; #endif #ifdef ALWAYS_SEND_MAIL - def_mail_always = TRUE; + def_mail_always = true; #endif #ifdef SEND_MAIL_WHEN_NO_USER - def_mail_no_user = TRUE; + def_mail_no_user = true; #endif #ifdef SEND_MAIL_WHEN_NO_HOST - def_mail_no_host = TRUE; + def_mail_no_host = true; #endif #ifdef SEND_MAIL_WHEN_NOT_OK - def_mail_no_perms = TRUE; + def_mail_no_perms = true; #endif #ifndef NO_TTY_TICKETS - def_tty_tickets = TRUE; + def_tty_tickets = true; #endif #ifndef NO_LECTURE def_lecture = once; #endif #ifndef NO_AUTHENTICATION - def_authenticate = TRUE; + def_authenticate = true; #endif #ifndef NO_ROOT_SUDO - def_root_sudo = TRUE; + def_root_sudo = true; #endif #ifdef HOST_IN_LOG - def_log_host = TRUE; + def_log_host = true; #endif #ifdef SHELL_IF_NO_ARGS - def_shell_noargs = TRUE; + def_shell_noargs = true; #endif #ifdef SHELL_SETS_HOME - def_set_home = TRUE; + def_set_home = true; #endif #ifndef DONT_LEAK_PATH_INFO - def_path_info = TRUE; + def_path_info = true; #endif #ifdef FQDN - def_fqdn = TRUE; + def_fqdn = true; #endif #ifdef USE_INSULTS - def_insults = TRUE; + def_insults = true; #endif #ifdef ENV_EDITOR - def_env_editor = TRUE; + def_env_editor = true; #endif #ifdef UMASK_OVERRIDE - def_umask_override = TRUE; + def_umask_override = true; #endif def_iolog_file = estrdup("%{seq}"); def_iolog_dir = estrdup(_PATH_SUDO_IO_LOGDIR); def_sudoers_locale = estrdup("C"); def_env_reset = ENV_RESET; - def_set_logname = TRUE; + def_set_logname = true; def_closefrom = STDERR_FILENO + 1; /* Syslog options need special care since they both strings and ints */ #if (LOGGING & SLOG_SYSLOG) - (void) store_syslogfac(LOGFAC, &sudo_defs_table[I_SYSLOG], TRUE); + (void) store_syslogfac(LOGFAC, &sudo_defs_table[I_SYSLOG], true); (void) store_syslogpri(PRI_SUCCESS, &sudo_defs_table[I_SYSLOG_GOODPRI], - TRUE); + true); (void) store_syslogpri(PRI_FAILURE, &sudo_defs_table[I_SYSLOG_BADPRI], - TRUE); + true); #endif /* Password flags also have a string and integer component. */ - (void) store_tuple("any", &sudo_defs_table[I_LISTPW], TRUE); - (void) store_tuple("all", &sudo_defs_table[I_VERIFYPW], TRUE); + (void) store_tuple("any", &sudo_defs_table[I_LISTPW], true); + (void) store_tuple("all", &sudo_defs_table[I_VERIFYPW], true); /* Then initialize the int-like things. */ #ifdef SUDO_UMASK @@ -447,7 +447,7 @@ init_defaults(void) def_passwd_timeout = PASSWORD_TIMEOUT; def_passwd_tries = TRIES_FOR_PASSWORD; #ifdef HAVE_ZLIB_H - def_compress_io = TRUE; + def_compress_io = true; #endif /* Now do the strings */ @@ -471,7 +471,7 @@ init_defaults(void) def_secure_path = estrdup(SECURE_PATH); #endif def_editor = estrdup(EDITOR); - def_set_utmp = TRUE; + def_set_utmp = true; /* Finally do the lists (currently just environment tables). */ init_envtables(); @@ -489,110 +489,110 @@ int update_defaults(int what) { struct defaults *def; - int rc = TRUE; - debug_decl(init_defaults, SUDO_DEBUG_DEFAULTS) + bool rc = true; + debug_decl(update_defaults, SUDO_DEBUG_DEFAULTS) tq_foreach_fwd(&defaults, def) { switch (def->type) { case DEFAULTS: if (ISSET(what, SETDEF_GENERIC) && !set_default(def->var, def->val, def->op)) - rc = FALSE; + rc = false; break; case DEFAULTS_USER: if (ISSET(what, SETDEF_USER) && userlist_matches(sudo_user.pw, &def->binding) == ALLOW && !set_default(def->var, def->val, def->op)) - rc = FALSE; + rc = false; break; case DEFAULTS_RUNAS: if (ISSET(what, SETDEF_RUNAS) && runaslist_matches(&def->binding, NULL) == ALLOW && !set_default(def->var, def->val, def->op)) - rc = FALSE; + rc = false; break; case DEFAULTS_HOST: if (ISSET(what, SETDEF_HOST) && hostlist_matches(&def->binding) == ALLOW && !set_default(def->var, def->val, def->op)) - rc = FALSE; + rc = false; break; case DEFAULTS_CMND: if (ISSET(what, SETDEF_CMND) && cmndlist_matches(&def->binding) == ALLOW && !set_default(def->var, def->val, def->op)) - rc = FALSE; + rc = false; break; } } debug_return_bool(rc); } -static int -store_int(char *val, struct sudo_defs_types *def, int op) +static bool +store_int(char *val, struct sudo_defs_types *def, bool op) { char *endp; long l; debug_decl(store_int, SUDO_DEBUG_DEFAULTS) - if (op == FALSE) { + if (op == false) { def->sd_un.ival = 0; } else { l = strtol(val, &endp, 10); if (*endp != '\0') - debug_return_bool(FALSE); + debug_return_bool(false); /* XXX - should check against INT_MAX */ def->sd_un.ival = (int)l; } if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_uint(char *val, struct sudo_defs_types *def, int op) +static bool +store_uint(char *val, struct sudo_defs_types *def, bool op) { char *endp; long l; debug_decl(store_uint, SUDO_DEBUG_DEFAULTS) - if (op == FALSE) { + if (op == false) { def->sd_un.ival = 0; } else { l = strtol(val, &endp, 10); if (*endp != '\0' || l < 0) - debug_return_bool(FALSE); + debug_return_bool(false); /* XXX - should check against INT_MAX */ def->sd_un.ival = (unsigned int)l; } if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_float(char *val, struct sudo_defs_types *def, int op) +static bool +store_float(char *val, struct sudo_defs_types *def, bool op) { char *endp; double d; debug_decl(store_float, SUDO_DEBUG_DEFAULTS) - if (op == FALSE) { + if (op == false) { def->sd_un.fval = 0.0; } else { d = strtod(val, &endp); if (*endp != '\0') - debug_return_bool(FALSE); + debug_return_bool(false); /* XXX - should check against HUGE_VAL */ def->sd_un.fval = d; } if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_tuple(char *val, struct sudo_defs_types *def, int op) +static bool +store_tuple(char *val, struct sudo_defs_types *def, bool op) { struct def_values *v; debug_decl(store_tuple, SUDO_DEBUG_DEFAULTS) @@ -605,7 +605,7 @@ store_tuple(char *val, struct sudo_defs_types *def, int op) * be the equivalent to a boolean "false". */ if (!val) { - def->sd_un.ival = (op == FALSE) ? 0 : 1; + def->sd_un.ival = (op == false) ? 0 : 1; } else { for (v = def->values; v->sval != NULL; v++) { if (strcmp(v->sval, val) == 0) { @@ -614,40 +614,40 @@ store_tuple(char *val, struct sudo_defs_types *def, int op) } } if (v->sval == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); } if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_str(char *val, struct sudo_defs_types *def, int op) +static bool +store_str(char *val, struct sudo_defs_types *def, bool op) { debug_decl(store_str, SUDO_DEBUG_DEFAULTS) efree(def->sd_un.str); - if (op == FALSE) + if (op == false) def->sd_un.str = NULL; else def->sd_un.str = estrdup(val); if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_list(char *str, struct sudo_defs_types *def, int op) +static bool +store_list(char *str, struct sudo_defs_types *def, bool op) { char *start, *end; debug_decl(store_list, SUDO_DEBUG_DEFAULTS) /* Remove all old members. */ - if (op == FALSE || op == TRUE) + if (op == false || op == true) list_op(NULL, 0, def, freeall); /* Split str into multiple space-separated words and act on each one. */ - if (op != FALSE) { + if (op != false) { end = str; do { /* Remove leading blanks, if nothing but blanks we are done. */ @@ -662,32 +662,32 @@ store_list(char *str, struct sudo_defs_types *def, int op) list_op(start, end - start, def, op == '-' ? delete : add); } while (*end++ != '\0'); } - debug_return_bool(TRUE); + debug_return_bool(true); } -static int -store_syslogfac(char *val, struct sudo_defs_types *def, int op) +static bool +store_syslogfac(char *val, struct sudo_defs_types *def, bool op) { struct strmap *fac; debug_decl(store_syslogfac, SUDO_DEBUG_DEFAULTS) - if (op == FALSE) { - def->sd_un.ival = FALSE; - debug_return_bool(TRUE); + if (op == false) { + def->sd_un.ival = false; + debug_return_bool(true); } #ifdef LOG_NFACILITIES if (!val) - debug_return_bool(FALSE); + debug_return_bool(false); for (fac = facilities; fac->name && strcmp(val, fac->name); fac++) ; if (fac->name == NULL) - debug_return_bool(FALSE); /* not found */ + debug_return_bool(false); /* not found */ def->sd_un.ival = fac->num; #else def->sd_un.ival = -1; #endif /* LOG_NFACILITIES */ - debug_return_bool(TRUE); + debug_return_bool(true); } static const char * @@ -705,22 +705,22 @@ logfac2str(int n) #endif /* LOG_NFACILITIES */ } -static int -store_syslogpri(char *val, struct sudo_defs_types *def, int op) +static bool +store_syslogpri(char *val, struct sudo_defs_types *def, bool op) { struct strmap *pri; debug_decl(store_syslogpri, SUDO_DEBUG_DEFAULTS) - if (op == FALSE || !val) - debug_return_bool(FALSE); + if (op == false || !val) + debug_return_bool(false); for (pri = priorities; pri->name && strcmp(val, pri->name); pri++) ; if (pri->name == NULL) - debug_return_bool(FALSE); /* not found */ + debug_return_bool(false); /* not found */ def->sd_un.ival = pri->num; - debug_return_bool(TRUE); + debug_return_bool(true); } static const char * @@ -734,24 +734,24 @@ logpri2str(int n) debug_return_str(pri->name); } -static int -store_mode(char *val, struct sudo_defs_types *def, int op) +static bool +store_mode(char *val, struct sudo_defs_types *def, bool op) { char *endp; long l; debug_decl(store_mode, SUDO_DEBUG_DEFAULTS) - if (op == FALSE) { + if (op == false) { def->sd_un.mode = (mode_t)0777; } else { l = strtol(val, &endp, 8); if (*endp != '\0' || l < 0 || l > 0777) - debug_return_bool(FALSE); + debug_return_bool(false); def->sd_un.mode = (mode_t)l; } if (def->callback) debug_return_bool(def->callback(val)); - debug_return_bool(TRUE); + debug_return_bool(true); } static void diff --git a/plugins/sudoers/defaults.h b/plugins/sudoers/defaults.h index 05e2b6f49..038ab4194 100644 --- a/plugins/sudoers/defaults.h +++ b/plugins/sudoers/defaults.h @@ -107,7 +107,7 @@ struct sudo_defs_types { */ void dump_default(void); void init_defaults(void); -int set_default(char *, char *, int); +bool set_default(char *, char *, bool); int update_defaults(int); extern struct sudo_defs_types sudo_defs_table[]; diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index 482712f83..725212036 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -257,7 +257,7 @@ sudo_setenv(const char *var, const char *val, int dupcheck) errorx(1, _("internal error, sudo_setenv() overflow")); } - sudo_putenv(estring, dupcheck, TRUE); + sudo_putenv(estring, dupcheck, true); debug_return; } @@ -273,7 +273,7 @@ sudo_putenv(char *str, int dupcheck, int overwrite) { char **ep; size_t len; - int found = FALSE; + bool found = false; debug_decl(sudo_putenv, SUDO_DEBUG_ENV) /* Make sure there is room for the new entry plus a NULL. */ @@ -297,7 +297,7 @@ sudo_putenv(char *str, int dupcheck, int overwrite) if (strncmp(str, *ep, len) == 0) { if (overwrite) *ep = str; - found = TRUE; + found = true; } } /* Prune out duplicate variables. */ @@ -326,14 +326,15 @@ sudo_putenv(char *str, int dupcheck, int overwrite) /* * Check the env_delete blacklist. - * Returns TRUE if the variable was found, else false. + * Returns true if the variable was found, else false. */ -static int +static bool matches_env_delete(const char *var) { struct list_member *cur; size_t len; - int iswild, match = FALSE; + bool iswild; + bool match = false; debug_decl(matches_env_delete, SUDO_DEBUG_ENV) /* Skip anything listed in env_delete. */ @@ -342,12 +343,12 @@ matches_env_delete(const char *var) /* Deal with '*' wildcard */ if (cur->value[len - 1] == '*') { len--; - iswild = TRUE; + iswild = true; } else - iswild = FALSE; + iswild = false; if (strncmp(cur->value, var, len) == 0 && (iswild || var[len] == '=')) { - match = TRUE; + match = true; break; } } @@ -356,7 +357,7 @@ matches_env_delete(const char *var) /* * Apply the env_check list. - * Returns TRUE if the variable is allowed, FALSE if denied + * Returns true if the variable is allowed, false if denied * or -1 if no match. */ static int @@ -364,7 +365,8 @@ matches_env_check(const char *var) { struct list_member *cur; size_t len; - int iswild, keepit = -1; + bool iswild; + int keepit = -1; debug_decl(matches_env_check, SUDO_DEBUG_ENV) for (cur = def_env_check; cur; cur = cur->next) { @@ -372,9 +374,9 @@ matches_env_check(const char *var) /* Deal with '*' wildcard */ if (cur->value[len - 1] == '*') { len--; - iswild = TRUE; + iswild = true; } else - iswild = FALSE; + iswild = false; if (strncmp(cur->value, var, len) == 0 && (iswild || var[len] == '=')) { keepit = !strpbrk(var, "/%"); @@ -386,30 +388,30 @@ matches_env_check(const char *var) /* * Check the env_keep list. - * Returns TRUE if the variable is allowed else FALSE. + * Returns true if the variable is allowed else false. */ -static int +static bool matches_env_keep(const char *var) { struct list_member *cur; size_t len; - int iswild, keepit = FALSE; + bool iswild, keepit = false; /* Preserve SHELL variable for "sudo -s". */ if (ISSET(sudo_mode, MODE_SHELL) && strncmp(var, "SHELL=", 6) == 0) - return TRUE; + return true; for (cur = def_env_keep; cur; cur = cur->next) { len = strlen(cur->value); /* Deal with '*' wildcard */ if (cur->value[len - 1] == '*') { len--; - iswild = TRUE; + iswild = true; } else - iswild = FALSE; + iswild = false; if (strncmp(cur->value, var, len) == 0 && (iswild || var[len] == '=')) { - keepit = TRUE; + keepit = true; break; } } @@ -427,7 +429,7 @@ rebuild_env(void) char **old_envp, **ep, *cp, *ps1; char idbuf[MAX_UID_T_LEN]; unsigned int didvar; - int reset_home = FALSE; + bool reset_home = false; /* * Either clean out the environment or reset to a safe default. @@ -447,7 +449,7 @@ rebuild_env(void) if (def_always_set_home || ISSET(sudo_mode, MODE_RESET_HOME | MODE_LOGIN_SHELL) || (ISSET(sudo_mode, MODE_SHELL) && def_set_home)) - reset_home = TRUE; + reset_home = true; } if (def_env_reset || ISSET(sudo_mode, MODE_LOGIN_SHELL)) { @@ -508,7 +510,7 @@ rebuild_env(void) SET(didvar, DID_USERNAME); break; } - sudo_putenv(*ep, FALSE, FALSE); + sudo_putenv(*ep, false, false); } } didvar |= didvar << 8; /* convert DID_* to KEPT_* */ @@ -527,18 +529,18 @@ rebuild_env(void) ISSET(didvar, DID_USERNAME)); } else { if (!ISSET(didvar, DID_SHELL)) - sudo_setenv("SHELL", sudo_user.pw->pw_shell, FALSE); + sudo_setenv("SHELL", sudo_user.pw->pw_shell, false); if (!ISSET(didvar, DID_LOGNAME)) - sudo_setenv("LOGNAME", user_name, FALSE); + sudo_setenv("LOGNAME", user_name, false); if (!ISSET(didvar, DID_USER)) - sudo_setenv("USER", user_name, FALSE); + sudo_setenv("USER", user_name, false); if (!ISSET(didvar, DID_USERNAME)) - sudo_setenv("USERNAME", user_name, FALSE); + sudo_setenv("USERNAME", user_name, false); } /* If we didn't keep HOME, reset it based on target user. */ if (!ISSET(didvar, KEPT_HOME)) - reset_home = TRUE; + reset_home = true; /* * Set MAIL to target user in -i mode or if MAIL is not preserved @@ -550,7 +552,7 @@ rebuild_env(void) easprintf(&cp, "MAIL=%s%s", _PATH_MAILDIR, runas_pw->pw_name); else easprintf(&cp, "MAIL=%s/%s", _PATH_MAILDIR, runas_pw->pw_name); - sudo_putenv(cp, ISSET(didvar, DID_MAIL), TRUE); + sudo_putenv(cp, ISSET(didvar, DID_MAIL), true); } } else { /* @@ -558,7 +560,7 @@ rebuild_env(void) * env_check. */ for (ep = old_envp; *ep; ep++) { - int okvar; + bool okvar; /* Skip variables with values beginning with () (bash functions) */ if ((cp = strchr(*ep, '=')) != NULL) { @@ -570,9 +572,9 @@ rebuild_env(void) * First check variables against the blacklist in env_delete. * If no match there check for '%' and '/' characters. */ - okvar = matches_env_delete(*ep) != TRUE; + okvar = matches_env_delete(*ep) != true; if (okvar) - okvar = matches_env_check(*ep) != FALSE; + okvar = matches_env_check(*ep) != false; if (okvar) { if (strncmp(*ep, "SUDO_PS1=", 9) == 0) @@ -581,13 +583,13 @@ rebuild_env(void) SET(didvar, DID_PATH); else if (strncmp(*ep, "TERM=", 5) == 0) SET(didvar, DID_TERM); - sudo_putenv(*ep, FALSE, FALSE); + sudo_putenv(*ep, false, false); } } } /* Replace the PATH envariable with a secure one? */ if (def_secure_path && !user_is_exempt()) { - sudo_setenv("PATH", def_secure_path, TRUE); + sudo_setenv("PATH", def_secure_path, true); SET(didvar, DID_PATH); } @@ -599,42 +601,42 @@ rebuild_env(void) */ if (def_set_logname && !ISSET(sudo_mode, MODE_LOGIN_SHELL|MODE_EDIT)) { if (!ISSET(didvar, KEPT_LOGNAME)) - sudo_setenv("LOGNAME", runas_pw->pw_name, TRUE); + sudo_setenv("LOGNAME", runas_pw->pw_name, true); if (!ISSET(didvar, KEPT_USER)) - sudo_setenv("USER", runas_pw->pw_name, TRUE); + sudo_setenv("USER", runas_pw->pw_name, true); if (!ISSET(didvar, KEPT_USERNAME)) - sudo_setenv("USERNAME", runas_pw->pw_name, TRUE); + sudo_setenv("USERNAME", runas_pw->pw_name, true); } /* Set $HOME to target user if not preserving user's value. */ if (reset_home) - sudo_setenv("HOME", runas_pw->pw_dir, TRUE); + sudo_setenv("HOME", runas_pw->pw_dir, true); /* Provide default values for $TERM and $PATH if they are not set. */ if (!ISSET(didvar, DID_TERM)) - sudo_putenv("TERM=unknown", FALSE, FALSE); + sudo_putenv("TERM=unknown", false, false); if (!ISSET(didvar, DID_PATH)) - sudo_setenv("PATH", _PATH_STDPATH, FALSE); + sudo_setenv("PATH", _PATH_STDPATH, false); /* Set PS1 if SUDO_PS1 is set. */ if (ps1 != NULL) - sudo_putenv(ps1, TRUE, TRUE); + sudo_putenv(ps1, true, true); /* Add the SUDO_COMMAND envariable (cmnd + args). */ if (user_args) { easprintf(&cp, "%s %s", user_cmnd, user_args); - sudo_setenv("SUDO_COMMAND", cp, TRUE); + sudo_setenv("SUDO_COMMAND", cp, true); efree(cp); } else { - sudo_setenv("SUDO_COMMAND", user_cmnd, TRUE); + sudo_setenv("SUDO_COMMAND", user_cmnd, true); } /* Add the SUDO_USER, SUDO_UID, SUDO_GID environment variables. */ - sudo_setenv("SUDO_USER", user_name, TRUE); + sudo_setenv("SUDO_USER", user_name, true); snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) user_uid); - sudo_setenv("SUDO_UID", idbuf, TRUE); + sudo_setenv("SUDO_UID", idbuf, true); snprintf(idbuf, sizeof(idbuf), "%u", (unsigned int) user_gid); - sudo_setenv("SUDO_GID", idbuf, TRUE); + sudo_setenv("SUDO_GID", idbuf, true); /* Free old environment. */ efree(old_envp); @@ -650,7 +652,7 @@ insert_env_vars(char * const envp[]) /* Add user-specified environment variables. */ for (ep = envp; *ep != NULL; ep++) - sudo_putenv(*ep, TRUE, TRUE); + sudo_putenv(*ep, true, true); } /* @@ -664,7 +666,7 @@ validate_env_vars(char * const env_vars[]) char * const *ep; char *eq, *bad = NULL; size_t len, blen = 0, bsize = 0; - int okvar; + bool okvar; if (env_vars == NULL) return; @@ -673,17 +675,17 @@ validate_env_vars(char * const env_vars[]) for (ep = env_vars; *ep != NULL; ep++) { if (def_secure_path && !user_is_exempt() && strncmp(*ep, "PATH=", 5) == 0) { - okvar = FALSE; + okvar = false; } else if (def_env_reset) { okvar = matches_env_check(*ep); if (okvar == -1) okvar = matches_env_keep(*ep); } else { - okvar = matches_env_delete(*ep) == FALSE; - if (okvar == FALSE) - okvar = matches_env_check(*ep) != FALSE; + okvar = matches_env_delete(*ep) == false; + if (okvar == false) + okvar = matches_env_check(*ep) != false; } - if (okvar == FALSE) { + if (okvar == false) { /* Not allowed, add to error string, allocating as needed. */ if ((eq = strchr(*ep, '=')) != NULL) *eq = '\0'; @@ -763,7 +765,7 @@ read_env_file(const char *path, int overwrite) memcpy(cp, var, var_len + 1); /* includes '=' */ memcpy(cp + var_len + 1, val, val_len + 1); /* includes NUL */ - sudo_putenv(cp, TRUE, overwrite); + sudo_putenv(cp, true, overwrite); } fclose(fp); } diff --git a/plugins/sudoers/find_path.c b/plugins/sudoers/find_path.c index 0415b36e3..208b88e40 100644 --- a/plugins/sudoers/find_path.c +++ b/plugins/sudoers/find_path.c @@ -60,8 +60,8 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path, static char command[PATH_MAX]; /* qualified filename */ char *n; /* for traversing path */ char *origpath; /* so we can free path later */ - int found = FALSE; /* did we find the command? */ - int checkdot = FALSE; /* check current dir? */ + bool found = false; /* did we find the command? */ + bool checkdot = false; /* check current dir? */ int len; /* length parameter */ debug_decl(find_path, SUDO_DEBUG_UTIL) diff --git a/plugins/sudoers/goodpath.c b/plugins/sudoers/goodpath.c index 09fb76510..2a8446b1c 100644 --- a/plugins/sudoers/goodpath.c +++ b/plugins/sudoers/goodpath.c @@ -41,22 +41,22 @@ /* * Verify that path is a normal file and executable by root. */ -int +bool sudo_goodpath(const char *path, struct stat *sbp) { struct stat sb; - int rval = FALSE; + bool rval = false; debug_decl(sudo_goodpath, SUDO_DEBUG_UTIL) if (path != NULL && stat(path, &sb) == 0) { /* Make sure path describes an executable regular file. */ if (S_ISREG(sb.st_mode) && ISSET(sb.st_mode, 0111)) - rval = TRUE; + rval = true; else errno = EACCES; if (sbp) (void) memcpy(sbp, &sb, sizeof(struct stat)); } - debug_return_int(rval); + debug_return_bool(rval); } diff --git a/plugins/sudoers/gram.c b/plugins/sudoers/gram.c index 11d5ef5e7..9384968df 100644 --- a/plugins/sudoers/gram.c +++ b/plugins/sudoers/gram.c @@ -64,7 +64,7 @@ #include "sudoers.h" /* XXX */ #include "parse.h" #include "toke.h" -#include +#include "gram.h" /* * We must define SIZE_MAX for yacc's skeleton.c. @@ -85,9 +85,8 @@ extern int sudolineno; extern int last_token; extern char *sudoers; -static int verbose = FALSE; -int parse_error = FALSE; -int pedantic = FALSE; +static bool verbose = false; +bool parse_error = false; int errorlineno = -1; char *errorfile = NULL; @@ -122,10 +121,10 @@ yyerror(const char *s) } else if (verbose && s != NULL) { warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno); } - parse_error = TRUE; + parse_error = true; debug_return; } -#line 118 "gram.y" +#line 117 "gram.y" #ifndef YYSTYPE_DEFINED #define YYSTYPE_DEFINED typedef union { @@ -141,7 +140,7 @@ typedef union { int tok; } YYSTYPE; #endif /* YYSTYPE_DEFINED */ -#line 144 "y.tab.c" +#line 143 "y.tab.c" #define COMMAND 257 #define ALIAS 258 #define DEFVAR 259 @@ -639,7 +638,7 @@ short *yyss; short *yysslim; YYSTYPE *yyvs; int yystacksize; -#line 612 "gram.y" +#line 611 "gram.y" static struct defaults * new_default(char *var, char *val, int op) { @@ -821,14 +820,14 @@ init_parser(const char *path, int quiet) efree(sudoers); sudoers = path ? estrdup(path) : NULL; - parse_error = FALSE; + parse_error = false; errorlineno = -1; errorfile = NULL; verbose = !quiet; debug_return; } -#line 779 "y.tab.c" +#line 778 "y.tab.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ #if defined(__cplusplus) || defined(__STDC__) static int yygrowstack(void) @@ -1034,127 +1033,127 @@ yyreduce: switch (yyn) { case 1: -#line 193 "gram.y" +#line 192 "gram.y" { ; } break; case 5: -#line 201 "gram.y" +#line 200 "gram.y" { ; } break; case 6: -#line 204 "gram.y" +#line 203 "gram.y" { yyerrok; } break; case 7: -#line 207 "gram.y" +#line 206 "gram.y" { add_userspec(yyvsp[-1].member, yyvsp[0].privilege); } break; case 8: -#line 210 "gram.y" +#line 209 "gram.y" { ; } break; case 9: -#line 213 "gram.y" +#line 212 "gram.y" { ; } break; case 10: -#line 216 "gram.y" +#line 215 "gram.y" { ; } break; case 11: -#line 219 "gram.y" +#line 218 "gram.y" { ; } break; case 12: -#line 222 "gram.y" +#line 221 "gram.y" { add_defaults(DEFAULTS, NULL, yyvsp[0].defaults); } break; case 13: -#line 225 "gram.y" +#line 224 "gram.y" { add_defaults(DEFAULTS_USER, yyvsp[-1].member, yyvsp[0].defaults); } break; case 14: -#line 228 "gram.y" +#line 227 "gram.y" { add_defaults(DEFAULTS_RUNAS, yyvsp[-1].member, yyvsp[0].defaults); } break; case 15: -#line 231 "gram.y" +#line 230 "gram.y" { add_defaults(DEFAULTS_HOST, yyvsp[-1].member, yyvsp[0].defaults); } break; case 16: -#line 234 "gram.y" +#line 233 "gram.y" { add_defaults(DEFAULTS_CMND, yyvsp[-1].member, yyvsp[0].defaults); } break; case 18: -#line 240 "gram.y" +#line 239 "gram.y" { list_append(yyvsp[-2].defaults, yyvsp[0].defaults); yyval.defaults = yyvsp[-2].defaults; } break; case 19: -#line 246 "gram.y" +#line 245 "gram.y" { - yyval.defaults = new_default(yyvsp[0].string, NULL, TRUE); + yyval.defaults = new_default(yyvsp[0].string, NULL, true); } break; case 20: -#line 249 "gram.y" +#line 248 "gram.y" { - yyval.defaults = new_default(yyvsp[0].string, NULL, FALSE); + yyval.defaults = new_default(yyvsp[0].string, NULL, false); } break; case 21: -#line 252 "gram.y" +#line 251 "gram.y" { - yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, TRUE); + yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, true); } break; case 22: -#line 255 "gram.y" +#line 254 "gram.y" { yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, '+'); } break; case 23: -#line 258 "gram.y" +#line 257 "gram.y" { yyval.defaults = new_default(yyvsp[-2].string, yyvsp[0].string, '-'); } break; case 25: -#line 264 "gram.y" +#line 263 "gram.y" { list_append(yyvsp[-2].privilege, yyvsp[0].privilege); yyval.privilege = yyvsp[-2].privilege; } break; case 26: -#line 270 "gram.y" +#line 269 "gram.y" { struct privilege *p = emalloc(sizeof(*p)); list2tq(&p->hostlist, yyvsp[-2].member); @@ -1165,51 +1164,51 @@ case 26: } break; case 27: -#line 280 "gram.y" +#line 279 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = FALSE; + yyval.member->negated = false; } break; case 28: -#line 284 "gram.y" +#line 283 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = TRUE; + yyval.member->negated = true; } break; case 29: -#line 290 "gram.y" +#line 289 "gram.y" { yyval.member = new_member(yyvsp[0].string, ALIAS); } break; case 30: -#line 293 "gram.y" +#line 292 "gram.y" { yyval.member = new_member(NULL, ALL); } break; case 31: -#line 296 "gram.y" +#line 295 "gram.y" { yyval.member = new_member(yyvsp[0].string, NETGROUP); } break; case 32: -#line 299 "gram.y" +#line 298 "gram.y" { yyval.member = new_member(yyvsp[0].string, NTWKADDR); } break; case 33: -#line 302 "gram.y" +#line 301 "gram.y" { yyval.member = new_member(yyvsp[0].string, WORD); } break; case 35: -#line 308 "gram.y" +#line 307 "gram.y" { list_append(yyvsp[-2].cmndspec, yyvsp[0].cmndspec); #ifdef HAVE_SELINUX @@ -1242,7 +1241,7 @@ case 35: } break; case 36: -#line 340 "gram.y" +#line 339 "gram.y" { struct cmndspec *cs = emalloc(sizeof(*cs)); if (yyvsp[-3].runas != NULL) { @@ -1269,80 +1268,80 @@ case 36: } break; case 37: -#line 366 "gram.y" +#line 365 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = FALSE; + yyval.member->negated = false; } break; case 38: -#line 370 "gram.y" +#line 369 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = TRUE; + yyval.member->negated = true; } break; case 39: -#line 376 "gram.y" +#line 375 "gram.y" { yyval.string = yyvsp[0].string; } break; case 40: -#line 381 "gram.y" +#line 380 "gram.y" { yyval.string = yyvsp[0].string; } break; case 41: -#line 386 "gram.y" +#line 385 "gram.y" { yyval.seinfo.role = NULL; yyval.seinfo.type = NULL; } break; case 42: -#line 390 "gram.y" +#line 389 "gram.y" { yyval.seinfo.role = yyvsp[0].string; yyval.seinfo.type = NULL; } break; case 43: -#line 394 "gram.y" +#line 393 "gram.y" { yyval.seinfo.type = yyvsp[0].string; yyval.seinfo.role = NULL; } break; case 44: -#line 398 "gram.y" +#line 397 "gram.y" { yyval.seinfo.role = yyvsp[-1].string; yyval.seinfo.type = yyvsp[0].string; } break; case 45: -#line 402 "gram.y" +#line 401 "gram.y" { yyval.seinfo.type = yyvsp[-1].string; yyval.seinfo.role = yyvsp[0].string; } break; case 46: -#line 408 "gram.y" +#line 407 "gram.y" { yyval.runas = NULL; } break; case 47: -#line 411 "gram.y" +#line 410 "gram.y" { yyval.runas = yyvsp[-1].runas; } break; case 48: -#line 416 "gram.y" +#line 415 "gram.y" { yyval.runas = emalloc(sizeof(struct runascontainer)); yyval.runas->runasusers = yyvsp[0].member; @@ -1350,7 +1349,7 @@ case 48: } break; case 49: -#line 421 "gram.y" +#line 420 "gram.y" { yyval.runas = emalloc(sizeof(struct runascontainer)); yyval.runas->runasusers = yyvsp[-2].member; @@ -1358,7 +1357,7 @@ case 49: } break; case 50: -#line 426 "gram.y" +#line 425 "gram.y" { yyval.runas = emalloc(sizeof(struct runascontainer)); yyval.runas->runasusers = NULL; @@ -1366,86 +1365,86 @@ case 50: } break; case 51: -#line 433 "gram.y" +#line 432 "gram.y" { yyval.tag.nopasswd = yyval.tag.noexec = yyval.tag.setenv = yyval.tag.log_input = yyval.tag.log_output = UNSPEC; } break; case 52: -#line 437 "gram.y" +#line 436 "gram.y" { - yyval.tag.nopasswd = TRUE; + yyval.tag.nopasswd = true; } break; case 53: -#line 440 "gram.y" +#line 439 "gram.y" { - yyval.tag.nopasswd = FALSE; + yyval.tag.nopasswd = false; } break; case 54: -#line 443 "gram.y" +#line 442 "gram.y" { - yyval.tag.noexec = TRUE; + yyval.tag.noexec = true; } break; case 55: -#line 446 "gram.y" +#line 445 "gram.y" { - yyval.tag.noexec = FALSE; + yyval.tag.noexec = false; } break; case 56: -#line 449 "gram.y" +#line 448 "gram.y" { - yyval.tag.setenv = TRUE; + yyval.tag.setenv = true; } break; case 57: -#line 452 "gram.y" +#line 451 "gram.y" { - yyval.tag.setenv = FALSE; + yyval.tag.setenv = false; } break; case 58: -#line 455 "gram.y" +#line 454 "gram.y" { - yyval.tag.log_input = TRUE; + yyval.tag.log_input = true; } break; case 59: -#line 458 "gram.y" +#line 457 "gram.y" { - yyval.tag.log_input = FALSE; + yyval.tag.log_input = false; } break; case 60: -#line 461 "gram.y" +#line 460 "gram.y" { - yyval.tag.log_output = TRUE; + yyval.tag.log_output = true; } break; case 61: -#line 464 "gram.y" +#line 463 "gram.y" { - yyval.tag.log_output = FALSE; + yyval.tag.log_output = false; } break; case 62: -#line 469 "gram.y" +#line 468 "gram.y" { yyval.member = new_member(NULL, ALL); } break; case 63: -#line 472 "gram.y" +#line 471 "gram.y" { yyval.member = new_member(yyvsp[0].string, ALIAS); } break; case 64: -#line 475 "gram.y" +#line 474 "gram.y" { struct sudo_command *c = emalloc(sizeof(*c)); c->cmnd = yyvsp[0].command.cmnd; @@ -1454,7 +1453,7 @@ case 64: } break; case 67: -#line 487 "gram.y" +#line 486 "gram.y" { char *s; if ((s = alias_add(yyvsp[-2].string, HOSTALIAS, yyvsp[0].member)) != NULL) { @@ -1464,14 +1463,14 @@ case 67: } break; case 69: -#line 497 "gram.y" +#line 496 "gram.y" { list_append(yyvsp[-2].member, yyvsp[0].member); yyval.member = yyvsp[-2].member; } break; case 72: -#line 507 "gram.y" +#line 506 "gram.y" { char *s; if ((s = alias_add(yyvsp[-2].string, CMNDALIAS, yyvsp[0].member)) != NULL) { @@ -1481,14 +1480,14 @@ case 72: } break; case 74: -#line 517 "gram.y" +#line 516 "gram.y" { list_append(yyvsp[-2].member, yyvsp[0].member); yyval.member = yyvsp[-2].member; } break; case 77: -#line 527 "gram.y" +#line 526 "gram.y" { char *s; if ((s = alias_add(yyvsp[-2].string, RUNASALIAS, yyvsp[0].member)) != NULL) { @@ -1498,7 +1497,7 @@ case 77: } break; case 80: -#line 540 "gram.y" +#line 539 "gram.y" { char *s; if ((s = alias_add(yyvsp[-2].string, USERALIAS, yyvsp[0].member)) != NULL) { @@ -1508,96 +1507,96 @@ case 80: } break; case 82: -#line 550 "gram.y" +#line 549 "gram.y" { list_append(yyvsp[-2].member, yyvsp[0].member); yyval.member = yyvsp[-2].member; } break; case 83: -#line 556 "gram.y" +#line 555 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = FALSE; + yyval.member->negated = false; } break; case 84: -#line 560 "gram.y" +#line 559 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = TRUE; + yyval.member->negated = true; } break; case 85: -#line 566 "gram.y" +#line 565 "gram.y" { yyval.member = new_member(yyvsp[0].string, ALIAS); } break; case 86: -#line 569 "gram.y" +#line 568 "gram.y" { yyval.member = new_member(NULL, ALL); } break; case 87: -#line 572 "gram.y" +#line 571 "gram.y" { yyval.member = new_member(yyvsp[0].string, NETGROUP); } break; case 88: -#line 575 "gram.y" +#line 574 "gram.y" { yyval.member = new_member(yyvsp[0].string, USERGROUP); } break; case 89: -#line 578 "gram.y" +#line 577 "gram.y" { yyval.member = new_member(yyvsp[0].string, WORD); } break; case 91: -#line 584 "gram.y" +#line 583 "gram.y" { list_append(yyvsp[-2].member, yyvsp[0].member); yyval.member = yyvsp[-2].member; } break; case 92: -#line 590 "gram.y" +#line 589 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = FALSE; + yyval.member->negated = false; } break; case 93: -#line 594 "gram.y" +#line 593 "gram.y" { yyval.member = yyvsp[0].member; - yyval.member->negated = TRUE; + yyval.member->negated = true; } break; case 94: -#line 600 "gram.y" +#line 599 "gram.y" { yyval.member = new_member(yyvsp[0].string, ALIAS); } break; case 95: -#line 603 "gram.y" +#line 602 "gram.y" { yyval.member = new_member(NULL, ALL); } break; case 96: -#line 606 "gram.y" +#line 605 "gram.y" { yyval.member = new_member(yyvsp[0].string, WORD); } break; -#line 1548 "y.tab.c" +#line 1547 "y.tab.c" } yyssp -= yym; yystate = *yyssp; diff --git a/plugins/sudoers/gram.y b/plugins/sudoers/gram.y index 030959226..3b64fc4ca 100644 --- a/plugins/sudoers/gram.y +++ b/plugins/sudoers/gram.y @@ -73,9 +73,8 @@ extern int sudolineno; extern int last_token; extern char *sudoers; -static int verbose = FALSE; -int parse_error = FALSE; -int pedantic = FALSE; +static bool verbose = false; +bool parse_error = false; int errorlineno = -1; char *errorfile = NULL; @@ -110,7 +109,7 @@ yyerror(const char *s) } else if (verbose && s != NULL) { warningx(_(">>> %s: %s near line %d <<<"), sudoers, s, sudolineno); } - parse_error = TRUE; + parse_error = true; debug_return; } %} @@ -244,13 +243,13 @@ defaults_list : defaults_entry ; defaults_entry : DEFVAR { - $$ = new_default($1, NULL, TRUE); + $$ = new_default($1, NULL, true); } | '!' DEFVAR { - $$ = new_default($2, NULL, FALSE); + $$ = new_default($2, NULL, false); } | DEFVAR '=' WORD { - $$ = new_default($1, $3, TRUE); + $$ = new_default($1, $3, true); } | DEFVAR '+' WORD { $$ = new_default($1, $3, '+'); @@ -279,11 +278,11 @@ privilege : hostlist '=' cmndspeclist { ophost : host { $$ = $1; - $$->negated = FALSE; + $$->negated = false; } | '!' host { $$ = $2; - $$->negated = TRUE; + $$->negated = true; } ; @@ -365,11 +364,11 @@ cmndspec : runasspec selinux cmndtag opcmnd { opcmnd : cmnd { $$ = $1; - $$->negated = FALSE; + $$->negated = false; } | '!' cmnd { $$ = $2; - $$->negated = TRUE; + $$->negated = true; } ; @@ -435,34 +434,34 @@ cmndtag : /* empty */ { $$.log_input = $$.log_output = UNSPEC; } | cmndtag NOPASSWD { - $$.nopasswd = TRUE; + $$.nopasswd = true; } | cmndtag PASSWD { - $$.nopasswd = FALSE; + $$.nopasswd = false; } | cmndtag NOEXEC { - $$.noexec = TRUE; + $$.noexec = true; } | cmndtag EXEC { - $$.noexec = FALSE; + $$.noexec = false; } | cmndtag SETENV { - $$.setenv = TRUE; + $$.setenv = true; } | cmndtag NOSETENV { - $$.setenv = FALSE; + $$.setenv = false; } | cmndtag LOG_INPUT { - $$.log_input = TRUE; + $$.log_input = true; } | cmndtag NOLOG_INPUT { - $$.log_input = FALSE; + $$.log_input = false; } | cmndtag LOG_OUTPUT { - $$.log_output = TRUE; + $$.log_output = true; } | cmndtag NOLOG_OUTPUT { - $$.log_output = FALSE; + $$.log_output = false; } ; @@ -555,11 +554,11 @@ userlist : opuser opuser : user { $$ = $1; - $$->negated = FALSE; + $$->negated = false; } | '!' user { $$ = $2; - $$->negated = TRUE; + $$->negated = true; } ; @@ -589,11 +588,11 @@ grouplist : opgroup opgroup : group { $$ = $1; - $$->negated = FALSE; + $$->negated = false; } | '!' group { $$ = $2; - $$->negated = TRUE; + $$->negated = true; } ; @@ -790,7 +789,7 @@ init_parser(const char *path, int quiet) efree(sudoers); sudoers = path ? estrdup(path) : NULL; - parse_error = FALSE; + parse_error = false; errorlineno = -1; errorfile = NULL; verbose = !quiet; diff --git a/plugins/sudoers/group_plugin.c b/plugins/sudoers/group_plugin.c index 9caea154f..b7ffcd9e6 100644 --- a/plugins/sudoers/group_plugin.c +++ b/plugins/sudoers/group_plugin.c @@ -131,14 +131,15 @@ group_plugin_load(char *plugin_info) * Split args into a vector if specified. */ if (args != NULL) { - int ac = 0, wasblank = TRUE; + int ac = 0; + bool wasblank = true; char *cp; for (cp = args; *cp != '\0'; cp++) { if (isblank((unsigned char)*cp)) { - wasblank = TRUE; + wasblank = true; } else if (wasblank) { - wasblank = FALSE; + wasblank = false; ac++; } } @@ -155,7 +156,7 @@ group_plugin_load(char *plugin_info) done: efree(argv); - if (rc != TRUE) { + if (rc != true) { if (group_handle != NULL) { dlclose(group_handle); group_handle = NULL; @@ -189,7 +190,7 @@ group_plugin_query(const char *user, const char *group, debug_decl(group_plugin_query, SUDO_DEBUG_UTIL) if (group_plugin == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); debug_return_bool((group_plugin->query)(user, group, pwd)); } @@ -203,7 +204,7 @@ int group_plugin_load(char *plugin_info) { debug_decl(group_plugin_load, SUDO_DEBUG_UTIL) - debug_return_bool(FALSE); + debug_return_bool(false); } void @@ -218,7 +219,7 @@ group_plugin_query(const char *user, const char *group, const struct passwd *pwd) { debug_decl(group_plugin_query, SUDO_DEBUG_UTIL) - debug_return_bool(FALSE); + debug_return_bool(false); } #endif /* HAVE_DLOPEN || HAVE_SHL_LOAD */ diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index 028c846c3..ac84940c2 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -240,11 +240,11 @@ mkdir_iopath(const char *iolog_path, char *pathbuf, size_t pathsize) /* * Append suffix to pathbuf after len chars and open the resulting file. * Note that the size of pathbuf is assumed to be PATH_MAX. - * Uses zlib if docompress is TRUE. + * Uses zlib if docompress is true. * Returns the open file handle which has the close-on-exec flag set. */ static void * -open_io_fd(char *pathbuf, size_t len, const char *suffix, int docompress) +open_io_fd(char *pathbuf, size_t len, const char *suffix, bool docompress) { void *vfd = NULL; int fd; @@ -320,33 +320,33 @@ iolog_deserialize_info(struct iolog_details *details, char * const user_info[], continue; } if (strncmp(*cur, "iolog_stdin=", sizeof("iolog_stdin=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_stdin=") - 1) == TRUE) - details->iolog_stdin = TRUE; + if (atobool(*cur + sizeof("iolog_stdin=") - 1) == true) + details->iolog_stdin = true; continue; } if (strncmp(*cur, "iolog_stdout=", sizeof("iolog_stdout=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_stdout=") - 1) == TRUE) - details->iolog_stdout = TRUE; + if (atobool(*cur + sizeof("iolog_stdout=") - 1) == true) + details->iolog_stdout = true; continue; } if (strncmp(*cur, "iolog_stderr=", sizeof("iolog_stderr=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_stderr=") - 1) == TRUE) - details->iolog_stderr = TRUE; + if (atobool(*cur + sizeof("iolog_stderr=") - 1) == true) + details->iolog_stderr = true; continue; } if (strncmp(*cur, "iolog_ttyin=", sizeof("iolog_ttyin=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_ttyin=") - 1) == TRUE) - details->iolog_ttyin = TRUE; + if (atobool(*cur + sizeof("iolog_ttyin=") - 1) == true) + details->iolog_ttyin = true; continue; } if (strncmp(*cur, "iolog_ttyout=", sizeof("iolog_ttyout=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_ttyout=") - 1) == TRUE) - details->iolog_ttyout = TRUE; + if (atobool(*cur + sizeof("iolog_ttyout=") - 1) == true) + details->iolog_ttyout = true; continue; } if (strncmp(*cur, "iolog_compress=", sizeof("iolog_compress=") - 1) == 0) { - if (atobool(*cur + sizeof("iolog_compress=") - 1) == TRUE) - iolog_compress = TRUE; /* must be global */ + if (atobool(*cur + sizeof("iolog_compress=") - 1) == true) + iolog_compress = true; /* must be global */ continue; } break; @@ -435,7 +435,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, /* If we have no command (because -V was specified) just return. */ if (argc == 0) - debug_return_bool(TRUE); + debug_return_bool(true); if (sigsetjmp(error_jmp, 1)) { /* called via error(), errorx() or log_error() */ @@ -456,7 +456,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, if (!details.iolog_stdin && !details.iolog_ttyin && !details.iolog_stdout && !details.iolog_stderr && !details.iolog_ttyout) { - rval = FALSE; + rval = false; goto done; } @@ -483,7 +483,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, /* * We create 7 files: a log file, a timing file and 5 for input/output. */ - io_logfile = open_io_fd(pathbuf, len, "/log", FALSE); + io_logfile = open_io_fd(pathbuf, len, "/log", false); if (io_logfile == NULL) log_error(USE_ERRNO, _("unable to create %s"), pathbuf); @@ -549,7 +549,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, fputc('\n', io_logfile); fclose(io_logfile); - rval = TRUE; + rval = true; done: efree(tofree); @@ -600,7 +600,7 @@ sudoers_io_version(int verbose) sudo_printf(SUDO_CONV_INFO_MSG, "Sudoers I/O plugin version %s\n", PACKAGE_VERSION); - debug_return_bool(TRUE); + debug_return_bool(true); } /* @@ -639,7 +639,7 @@ sudoers_io_log(const char *buf, unsigned int len, int idx) last_time.tv_sec = now.tv_sec; last_time.tv_usec = now.tv_usec; - debug_return_bool(TRUE); + debug_return_bool(true); } static int diff --git a/plugins/sudoers/iolog_path.c b/plugins/sudoers/iolog_path.c index 55175fd54..964068009 100644 --- a/plugins/sudoers/iolog_path.c +++ b/plugins/sudoers/iolog_path.c @@ -166,7 +166,8 @@ expand_iolog_path(const char *prefix, const char *dir, const char *file, size_t len, prelen = 0; char *dst, *dst0, *path, *pathend, tmpbuf[PATH_MAX]; const char *endbrace, *src = dir; - int pass, strfit; + int pass; + bool strfit; debug_decl(expand_iolog_path, SUDO_DEBUG_UTIL) /* Expanded path must be <= PATH_MAX */ @@ -188,7 +189,7 @@ expand_iolog_path(const char *prefix, const char *dir, const char *file, file++; for (pass = 0; pass < 3; pass++) { - strfit = FALSE; + strfit = false; switch (pass) { case 0: src = dir; diff --git a/plugins/sudoers/ldap.c b/plugins/sudoers/ldap.c index fbd622755..a1942de94 100644 --- a/plugins/sudoers/ldap.c +++ b/plugins/sudoers/ldap.c @@ -223,90 +223,90 @@ static struct ldap_config { } ldap_conf; static struct ldap_config_table ldap_conf_table[] = { - { "sudoers_debug", CONF_INT, FALSE, -1, &ldap_conf.debug }, - { "host", CONF_STR, FALSE, -1, &ldap_conf.host }, - { "port", CONF_INT, FALSE, -1, &ldap_conf.port }, - { "ssl", CONF_STR, FALSE, -1, &ldap_conf.ssl }, - { "sslpath", CONF_STR, FALSE, -1, &ldap_conf.tls_certfile }, - { "uri", CONF_LIST_STR, FALSE, -1, &ldap_conf.uri }, + { "sudoers_debug", CONF_INT, false, -1, &ldap_conf.debug }, + { "host", CONF_STR, false, -1, &ldap_conf.host }, + { "port", CONF_INT, false, -1, &ldap_conf.port }, + { "ssl", CONF_STR, false, -1, &ldap_conf.ssl }, + { "sslpath", CONF_STR, false, -1, &ldap_conf.tls_certfile }, + { "uri", CONF_LIST_STR, false, -1, &ldap_conf.uri }, #ifdef LDAP_OPT_DEBUG_LEVEL - { "debug", CONF_INT, FALSE, LDAP_OPT_DEBUG_LEVEL, &ldap_conf.ldap_debug }, + { "debug", CONF_INT, false, LDAP_OPT_DEBUG_LEVEL, &ldap_conf.ldap_debug }, #endif #ifdef LDAP_OPT_PROTOCOL_VERSION - { "ldap_version", CONF_INT, TRUE, LDAP_OPT_PROTOCOL_VERSION, + { "ldap_version", CONF_INT, true, LDAP_OPT_PROTOCOL_VERSION, &ldap_conf.version }, #endif #ifdef LDAP_OPT_X_TLS_REQUIRE_CERT - { "tls_checkpeer", CONF_BOOL, FALSE, LDAP_OPT_X_TLS_REQUIRE_CERT, + { "tls_checkpeer", CONF_BOOL, false, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_conf.tls_checkpeer }, #else - { "tls_checkpeer", CONF_BOOL, FALSE, -1, &ldap_conf.tls_checkpeer }, + { "tls_checkpeer", CONF_BOOL, false, -1, &ldap_conf.tls_checkpeer }, #endif #ifdef LDAP_OPT_X_TLS_CACERTFILE - { "tls_cacertfile", CONF_STR, FALSE, LDAP_OPT_X_TLS_CACERTFILE, + { "tls_cacertfile", CONF_STR, false, LDAP_OPT_X_TLS_CACERTFILE, &ldap_conf.tls_cacertfile }, - { "tls_cacert", CONF_STR, FALSE, LDAP_OPT_X_TLS_CACERTFILE, + { "tls_cacert", CONF_STR, false, LDAP_OPT_X_TLS_CACERTFILE, &ldap_conf.tls_cacertfile }, #endif #ifdef LDAP_OPT_X_TLS_CACERTDIR - { "tls_cacertdir", CONF_STR, FALSE, LDAP_OPT_X_TLS_CACERTDIR, + { "tls_cacertdir", CONF_STR, false, LDAP_OPT_X_TLS_CACERTDIR, &ldap_conf.tls_cacertdir }, #endif #ifdef LDAP_OPT_X_TLS_RANDOM_FILE - { "tls_randfile", CONF_STR, FALSE, LDAP_OPT_X_TLS_RANDOM_FILE, + { "tls_randfile", CONF_STR, false, LDAP_OPT_X_TLS_RANDOM_FILE, &ldap_conf.tls_random_file }, #endif #ifdef LDAP_OPT_X_TLS_CIPHER_SUITE - { "tls_ciphers", CONF_STR, FALSE, LDAP_OPT_X_TLS_CIPHER_SUITE, + { "tls_ciphers", CONF_STR, false, LDAP_OPT_X_TLS_CIPHER_SUITE, &ldap_conf.tls_cipher_suite }, #endif #ifdef LDAP_OPT_X_TLS_CERTFILE - { "tls_cert", CONF_STR, FALSE, LDAP_OPT_X_TLS_CERTFILE, + { "tls_cert", CONF_STR, false, LDAP_OPT_X_TLS_CERTFILE, &ldap_conf.tls_certfile }, #else - { "tls_cert", CONF_STR, FALSE, -1, &ldap_conf.tls_certfile }, + { "tls_cert", CONF_STR, false, -1, &ldap_conf.tls_certfile }, #endif #ifdef LDAP_OPT_X_TLS_KEYFILE - { "tls_key", CONF_STR, FALSE, LDAP_OPT_X_TLS_KEYFILE, + { "tls_key", CONF_STR, false, LDAP_OPT_X_TLS_KEYFILE, &ldap_conf.tls_keyfile }, #else - { "tls_key", CONF_STR, FALSE, -1, &ldap_conf.tls_keyfile }, + { "tls_key", CONF_STR, false, -1, &ldap_conf.tls_keyfile }, #endif #ifdef LDAP_OPT_NETWORK_TIMEOUT - { "bind_timelimit", CONF_INT, TRUE, -1 /* needs timeval, set manually */, + { "bind_timelimit", CONF_INT, true, -1 /* needs timeval, set manually */, &ldap_conf.bind_timelimit }, - { "network_timeout", CONF_INT, TRUE, -1 /* needs timeval, set manually */, + { "network_timeout", CONF_INT, true, -1 /* needs timeval, set manually */, &ldap_conf.bind_timelimit }, #elif defined(LDAP_X_OPT_CONNECT_TIMEOUT) - { "bind_timelimit", CONF_INT, TRUE, LDAP_X_OPT_CONNECT_TIMEOUT, + { "bind_timelimit", CONF_INT, true, LDAP_X_OPT_CONNECT_TIMEOUT, &ldap_conf.bind_timelimit }, - { "network_timeout", CONF_INT, TRUE, LDAP_X_OPT_CONNECT_TIMEOUT, + { "network_timeout", CONF_INT, true, LDAP_X_OPT_CONNECT_TIMEOUT, &ldap_conf.bind_timelimit }, #endif - { "timelimit", CONF_INT, TRUE, LDAP_OPT_TIMELIMIT, &ldap_conf.timelimit }, + { "timelimit", CONF_INT, true, LDAP_OPT_TIMELIMIT, &ldap_conf.timelimit }, #ifdef LDAP_OPT_TIMEOUT - { "timeout", CONF_INT, TRUE, -1 /* needs timeval, set manually */, + { "timeout", CONF_INT, true, -1 /* needs timeval, set manually */, &ldap_conf.timeout }, #endif #ifdef LDAP_OPT_DEREF - { "deref", CONF_DEREF_VAL, TRUE, LDAP_OPT_DEREF, &ldap_conf.deref }, + { "deref", CONF_DEREF_VAL, true, LDAP_OPT_DEREF, &ldap_conf.deref }, #endif - { "binddn", CONF_STR, FALSE, -1, &ldap_conf.binddn }, - { "bindpw", CONF_STR, FALSE, -1, &ldap_conf.bindpw }, - { "rootbinddn", CONF_STR, FALSE, -1, &ldap_conf.rootbinddn }, - { "sudoers_base", CONF_LIST_STR, FALSE, -1, &ldap_conf.base }, - { "sudoers_timed", CONF_BOOL, FALSE, -1, &ldap_conf.timed }, - { "sudoers_search_filter", CONF_STR, FALSE, -1, &ldap_conf.search_filter }, + { "binddn", CONF_STR, false, -1, &ldap_conf.binddn }, + { "bindpw", CONF_STR, false, -1, &ldap_conf.bindpw }, + { "rootbinddn", CONF_STR, false, -1, &ldap_conf.rootbinddn }, + { "sudoers_base", CONF_LIST_STR, false, -1, &ldap_conf.base }, + { "sudoers_timed", CONF_BOOL, false, -1, &ldap_conf.timed }, + { "sudoers_search_filter", CONF_STR, false, -1, &ldap_conf.search_filter }, #ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S - { "use_sasl", CONF_BOOL, FALSE, -1, &ldap_conf.use_sasl }, - { "sasl_auth_id", CONF_STR, FALSE, -1, &ldap_conf.sasl_auth_id }, - { "rootuse_sasl", CONF_BOOL, FALSE, -1, &ldap_conf.rootuse_sasl }, - { "rootsasl_auth_id", CONF_STR, FALSE, -1, &ldap_conf.rootsasl_auth_id }, + { "use_sasl", CONF_BOOL, false, -1, &ldap_conf.use_sasl }, + { "sasl_auth_id", CONF_STR, false, -1, &ldap_conf.sasl_auth_id }, + { "rootuse_sasl", CONF_BOOL, false, -1, &ldap_conf.rootuse_sasl }, + { "rootsasl_auth_id", CONF_STR, false, -1, &ldap_conf.rootsasl_auth_id }, # ifdef LDAP_OPT_X_SASL_SECPROPS - { "sasl_secprops", CONF_STR, TRUE, LDAP_OPT_X_SASL_SECPROPS, + { "sasl_secprops", CONF_STR, true, LDAP_OPT_X_SASL_SECPROPS, &ldap_conf.sasl_secprops }, # endif - { "krb5_ccname", CONF_STR, FALSE, -1, &ldap_conf.krb5_ccname }, + { "krb5_ccname", CONF_STR, false, -1, &ldap_conf.krb5_ccname }, #endif /* HAVE_LDAP_SASL_INTERACTIVE_BIND_S */ { NULL } }; @@ -578,59 +578,59 @@ done: } /* - * Walk through search results and return TRUE if we have a matching - * netgroup, else FALSE. + * Walk through search results and return true if we have a matching + * netgroup, else false. */ -static int +static bool sudo_ldap_check_user_netgroup(LDAP *ld, LDAPMessage *entry, char *user) { struct berval **bv, **p; char *val; - int ret = FALSE; + int ret = false; debug_decl(sudo_ldap_check_user_netgroup, SUDO_DEBUG_LDAP) if (!entry) - debug_return_int(ret); + debug_return_bool(ret); /* get the values from the entry */ bv = ldap_get_values_len(ld, entry, "sudoUser"); if (bv == NULL) - debug_return_int(ret); + debug_return_bool(ret); /* walk through values */ for (p = bv; *p != NULL && !ret; p++) { val = (*p)->bv_val; /* match any */ if (netgr_matches(val, NULL, NULL, user)) - ret = TRUE; + ret = true; DPRINTF(("ldap sudoUser netgroup '%s' ... %s", val, ret ? "MATCH!" : "not"), 2 + ((ret) ? 0 : 1)); } ldap_value_free_len(bv); /* cleanup */ - debug_return_int(ret); + debug_return_bool(ret); } /* -* Walk through search results and return TRUE if we have a -* host match, else FALSE. +* Walk through search results and return true if we have a +* host match, else false. */ -static int +static bool sudo_ldap_check_host(LDAP *ld, LDAPMessage *entry) { struct berval **bv, **p; char *val; - int ret = FALSE; + bool ret = false; debug_decl(sudo_ldap_check_host, SUDO_DEBUG_LDAP) if (!entry) - debug_return_int(ret); + debug_return_bool(ret); /* get the values from the entry */ bv = ldap_get_values_len(ld, entry, "sudoHost"); if (bv == NULL) - debug_return_int(ret); + debug_return_bool(ret); /* walk through values */ for (p = bv; *p != NULL && !ret; p++) { @@ -639,14 +639,14 @@ sudo_ldap_check_host(LDAP *ld, LDAPMessage *entry) if (!strcmp(val, "ALL") || addr_matches(val) || netgr_matches(val, user_host, user_shost, NULL) || hostname_matches(user_shost, user_host, val)) - ret = TRUE; + ret = true; DPRINTF(("ldap sudoHost '%s' ... %s", val, ret ? "MATCH!" : "not"), 2); } ldap_value_free_len(bv); /* cleanup */ - debug_return_int(ret); + debug_return_bool(ret); } static int @@ -654,11 +654,11 @@ sudo_ldap_check_runas_user(LDAP *ld, LDAPMessage *entry) { struct berval **bv, **p; char *val; - int ret = FALSE; + bool ret = false; debug_decl(sudo_ldap_check_runas_user, SUDO_DEBUG_LDAP) if (!runas_pw) - debug_return_int(UNSPEC); + debug_return_bool(UNSPEC); /* get the runas user from the entry */ bv = ldap_get_values_len(ld, entry, "sudoRunAsUser"); @@ -687,7 +687,7 @@ sudo_ldap_check_runas_user(LDAP *ld, LDAPMessage *entry) * what the user specified on the command line. */ if (bv == NULL) - debug_return_int(!strcasecmp(runas_pw->pw_name, def_runas_default)); + debug_return_bool(!strcasecmp(runas_pw->pw_name, def_runas_default)); /* walk through values returned, looking for a match */ for (p = bv; *p != NULL && !ret; p++) { @@ -695,21 +695,21 @@ sudo_ldap_check_runas_user(LDAP *ld, LDAPMessage *entry) switch (val[0]) { case '+': if (netgr_matches(val, NULL, NULL, runas_pw->pw_name)) - ret = TRUE; + ret = true; break; case '%': if (usergr_matches(val, runas_pw->pw_name, runas_pw)) - ret = TRUE; + ret = true; break; case 'A': if (strcmp(val, "ALL") == 0) { - ret = TRUE; + ret = true; break; } /* FALLTHROUGH */ default: if (strcasecmp(val, runas_pw->pw_name) == 0) - ret = TRUE; + ret = true; break; } DPRINTF(("ldap sudoRunAsUser '%s' ... %s", val, @@ -718,7 +718,7 @@ sudo_ldap_check_runas_user(LDAP *ld, LDAPMessage *entry) ldap_value_free_len(bv); /* cleanup */ - debug_return_int(ret); + debug_return_bool(ret); } static int @@ -726,61 +726,62 @@ sudo_ldap_check_runas_group(LDAP *ld, LDAPMessage *entry) { struct berval **bv, **p; char *val; - int ret = FALSE; + bool ret = false; debug_decl(sudo_ldap_check_runas_group, SUDO_DEBUG_LDAP) /* runas_gr is only set if the user specified the -g flag */ if (!runas_gr) - debug_return_int(UNSPEC); + debug_return_bool(UNSPEC); /* get the values from the entry */ bv = ldap_get_values_len(ld, entry, "sudoRunAsGroup"); if (bv == NULL) - debug_return_int(ret); + debug_return_bool(ret); /* walk through values returned, looking for a match */ for (p = bv; *p != NULL && !ret; p++) { val = (*p)->bv_val; if (strcmp(val, "ALL") == 0 || group_matches(val, runas_gr)) - ret = TRUE; + ret = true; DPRINTF(("ldap sudoRunAsGroup '%s' ... %s", val, ret ? "MATCH!" : "not"), 2); } ldap_value_free_len(bv); /* cleanup */ - debug_return_int(ret); + debug_return_bool(ret); } /* - * Walk through search results and return TRUE if we have a runas match, - * else FALSE. RunAs info is optional. + * Walk through search results and return true if we have a runas match, + * else false. RunAs info is optional. */ -static int +static bool sudo_ldap_check_runas(LDAP *ld, LDAPMessage *entry) { - int ret; + bool ret; debug_decl(sudo_ldap_check_runas, SUDO_DEBUG_LDAP) if (!entry) - debug_return_bool(FALSE); + debug_return_bool(false); - ret = sudo_ldap_check_runas_user(ld, entry) != FALSE && - sudo_ldap_check_runas_group(ld, entry) != FALSE; + ret = sudo_ldap_check_runas_user(ld, entry) != false && + sudo_ldap_check_runas_group(ld, entry) != false; debug_return_bool(ret); } /* - * Walk through search results and return TRUE if we have a command match, - * FALSE if disallowed and UNSPEC if not matched. + * Walk through search results and return true if we have a command match, + * false if disallowed and UNSPEC if not matched. */ static int sudo_ldap_check_command(LDAP *ld, LDAPMessage *entry, int *setenv_implied) { struct berval **bv, **p; char *allowed_cmnd, *allowed_args, *val; - int foundbang, ret = UNSPEC; + bool foundbang; + int ret = UNSPEC; debug_decl(sudo_ldap_check_command, SUDO_DEBUG_LDAP) if (!entry) @@ -790,23 +791,23 @@ sudo_ldap_check_command(LDAP *ld, LDAPMessage *entry, int *setenv_implied) if (bv == NULL) debug_return_bool(ret); - for (p = bv; *p != NULL && ret != FALSE; p++) { + for (p = bv; *p != NULL && ret != false; p++) { val = (*p)->bv_val; /* Match against ALL ? */ if (!strcmp(val, "ALL")) { - ret = TRUE; + ret = true; if (setenv_implied != NULL) - *setenv_implied = TRUE; + *setenv_implied = true; DPRINTF(("ldap sudoCommand '%s' ... MATCH!", val), 2); continue; } /* check for !command */ if (*val == '!') { - foundbang = TRUE; + foundbang = true; allowed_cmnd = estrdup(1 + val); /* !command */ } else { - foundbang = FALSE; + foundbang = false; allowed_cmnd = estrdup(val); /* command */ } @@ -821,10 +822,10 @@ sudo_ldap_check_command(LDAP *ld, LDAPMessage *entry, int *setenv_implied) * If allowed (no bang) set ret but keep on checking. * If disallowed (bang), exit loop. */ - ret = foundbang ? FALSE : TRUE; + ret = foundbang ? false : true; } DPRINTF(("ldap sudoCommand '%s' ... %s", val, - ret == TRUE ? "MATCH!" : "not"), 2); + ret == true ? "MATCH!" : "not"), 2); efree(allowed_cmnd); /* cleanup */ } @@ -836,7 +837,7 @@ sudo_ldap_check_command(LDAP *ld, LDAPMessage *entry, int *setenv_implied) /* * Search for boolean "option" in sudoOption. - * Returns TRUE if found and allowed, FALSE if negated, else UNSPEC. + * Returns true if found and allowed, false if negated, else UNSPEC. */ static int sudo_ldap_check_bool(LDAP *ld, LDAPMessage *entry, char *option) @@ -903,14 +904,14 @@ sudo_ldap_parse_options(LDAP *ld, LDAPMessage *entry) set_default(var, val, (int) op); } else { /* case var=val */ - set_default(var, val, TRUE); + set_default(var, val, true); } } else if (*var == '!') { /* case !var Boolean False */ - set_default(var + 1, NULL, FALSE); + set_default(var + 1, NULL, false); } else { /* case var Boolean True */ - set_default(var, NULL, TRUE); + set_default(var, NULL, true); } efree(var); } @@ -1152,7 +1153,7 @@ sudo_ldap_read_secret(const char *path) debug_return; } -static int +static bool sudo_ldap_read_config(void) { FILE *fp; @@ -1172,7 +1173,7 @@ sudo_ldap_read_config(void) ldap_conf.deref = -1; if ((fp = fopen(_PATH_LDAP_CONF, "r")) == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); while ((cp = sudo_parseln(fp)) != NULL) { if (*cp == '\0') @@ -1205,7 +1206,7 @@ sudo_ldap_read_config(void) *(int *)(cur->valp) = LDAP_DEREF_NEVER; break; case CONF_BOOL: - *(int *)(cur->valp) = atobool(value) == TRUE; + *(int *)(cur->valp) = atobool(value) == true; break; case CONF_INT: *(int *)(cur->valp) = atoi(value); @@ -1337,7 +1338,7 @@ sudo_ldap_read_config(void) sudo_printf(SUDO_CONV_ERROR_MSG, "===================\n"); } if (!ldap_conf.base) - debug_return_bool(FALSE); /* if no base is defined, ignore LDAP */ + debug_return_bool(false); /* if no base is defined, ignore LDAP */ if (ldap_conf.bind_timelimit > 0) ldap_conf.bind_timelimit *= 1000; /* convert to ms */ @@ -1348,7 +1349,7 @@ sudo_ldap_read_config(void) if (ldap_conf.ssl != NULL) { if (strcasecmp(ldap_conf.ssl, "start_tls") == 0) ldap_conf.ssl_mode = SUDO_LDAP_STARTTLS; - else if (atobool(ldap_conf.ssl) == TRUE) + else if (atobool(ldap_conf.ssl) == true) ldap_conf.ssl_mode = SUDO_LDAP_SSL; } @@ -1364,7 +1365,7 @@ sudo_ldap_read_config(void) if (ldap_conf.uri) { struct ldap_config_list_str *uri = ldap_conf.uri; if (sudo_ldap_parse_uri(uri) != 0) - debug_return_bool(FALSE); + debug_return_bool(false); do { ldap_conf.uri = uri->next; efree(uri); @@ -1426,7 +1427,7 @@ sudo_ldap_read_config(void) } } #endif - debug_return_bool(TRUE); + debug_return_bool(true); } /* @@ -1717,7 +1718,8 @@ sudo_ldap_display_cmnd(struct sudo_nss *nss, struct passwd *pw) LDAP *ld; struct ldap_result *lres; LDAPMessage *entry; - int i, found = FALSE; + bool found = false; + int i; debug_decl(sudo_ldap_display_cmnd, SUDO_DEBUG_LDAP) if (handle == NULL || handle->ld == NULL) @@ -1734,7 +1736,7 @@ sudo_ldap_display_cmnd(struct sudo_nss *nss, struct passwd *pw) entry = lres->entries[i].entry; if (sudo_ldap_check_command(ld, entry, NULL) && sudo_ldap_check_runas(ld, entry)) { - found = TRUE; + found = true; goto done; } } @@ -1892,8 +1894,8 @@ sudo_ldap_result_alloc(void) result->nentries = 0; result->entries = NULL; result->allocated_entries = 0; - result->user_matches = FALSE; - result->host_matches = FALSE; + result->user_matches = false; + result->host_matches = false; debug_return_ptr(result); } @@ -1965,8 +1967,8 @@ sudo_ldap_bind_s(LDAP *ld) debug_decl(sudo_ldap_bind_s, SUDO_DEBUG_LDAP) #ifdef HAVE_LDAP_SASL_INTERACTIVE_BIND_S - if (ldap_conf.rootuse_sasl == TRUE || - (ldap_conf.rootuse_sasl != FALSE && ldap_conf.use_sasl == TRUE)) { + if (ldap_conf.rootuse_sasl == true || + (ldap_conf.rootuse_sasl != false && ldap_conf.use_sasl == true)) { void *auth_id = ldap_conf.rootsasl_auth_id ? ldap_conf.rootsasl_auth_id : ldap_conf.sasl_auth_id; @@ -1978,7 +1980,7 @@ sudo_ldap_bind_s(LDAP *ld) DPRINTF(("gss_krb5_ccache_name() failed: %d", status), 1); } # else - setenv("KRB5CCNAME", ldap_conf.krb5_ccname, TRUE); + setenv("KRB5CCNAME", ldap_conf.krb5_ccname, true); # endif } rc = ldap_sasl_interactive_bind_s(ld, ldap_conf.binddn, "GSSAPI", @@ -1989,7 +1991,7 @@ sudo_ldap_bind_s(LDAP *ld) DPRINTF(("gss_krb5_ccache_name() failed: %d", status), 1); # else if (old_ccname != NULL) - setenv("KRB5CCNAME", old_ccname, TRUE); + setenv("KRB5CCNAME", old_ccname, true); else unsetenv("KRB5CCNAME"); # endif @@ -2038,7 +2040,8 @@ static int sudo_ldap_open(struct sudo_nss *nss) { LDAP *ld; - int rc, ldapnoinit = FALSE; + int rc; + bool ldapnoinit = false; struct sudo_ldap_handle *handle; debug_decl(sudo_ldap_open, SUDO_DEBUG_LDAP) @@ -2047,8 +2050,8 @@ sudo_ldap_open(struct sudo_nss *nss) /* Prevent reading of user ldaprc and system defaults. */ if (getenv("LDAPNOINIT") == NULL) { - ldapnoinit = TRUE; - setenv("LDAPNOINIT", "1", TRUE); + ldapnoinit = true; + setenv("LDAPNOINIT", "1", true); } /* Connect to LDAP server */ @@ -2187,15 +2190,15 @@ sudo_ldap_lookup(struct sudo_nss *nss, int ret, int pwflag) DPRINTF(("perform search for pwflag %d", pwflag), 1); for (i = 0; i < lres->nentries; i++) { entry = lres->entries[i].entry; - if ((pwcheck == any && doauth != FALSE) || - (pwcheck == all && doauth == FALSE)) { + if ((pwcheck == any && doauth != false) || + (pwcheck == all && doauth == false)) { doauth = sudo_ldap_check_bool(ld, entry, "authenticate"); } /* Only check the command when listing another user. */ if (user_uid == 0 || list_pw == NULL || user_uid == list_pw->pw_uid || sudo_ldap_check_command(ld, entry, NULL)) { - matched = TRUE; + matched = true; break; } } @@ -2209,11 +2212,11 @@ sudo_ldap_lookup(struct sudo_nss *nss, int ret, int pwflag) break; case all: case any: - if (doauth == FALSE) - def_authenticate = FALSE; + if (doauth == false) + def_authenticate = false; break; case never: - def_authenticate = FALSE; + def_authenticate = false; break; default: break; @@ -2225,7 +2228,7 @@ sudo_ldap_lookup(struct sudo_nss *nss, int ret, int pwflag) DPRINTF(("searching LDAP for sudoers entries"), 1); - setenv_implied = FALSE; + setenv_implied = false; for (i = 0; i < lres->nentries; i++) { entry = lres->entries[i].entry; if (!sudo_ldap_check_runas(ld, entry)) @@ -2233,12 +2236,12 @@ sudo_ldap_lookup(struct sudo_nss *nss, int ret, int pwflag) rc = sudo_ldap_check_command(ld, entry, &setenv_implied); if (rc != UNSPEC) { /* We have a match. */ - DPRINTF(("Command %sallowed", rc == TRUE ? "" : "NOT "), 1); - if (rc == TRUE) { + DPRINTF(("Command %sallowed", rc == true ? "" : "NOT "), 1); + if (rc == true) { DPRINTF(("LDAP entry: %p", entry), 1); /* Apply entry-specific options. */ if (setenv_implied) - def_setenv = TRUE; + def_setenv = true; sudo_ldap_parse_options(ld, entry); #ifdef HAVE_SELINUX /* Set role and type if not specified on command line. */ @@ -2446,7 +2449,7 @@ sudo_ldap_result_get(struct sudo_nss *nss, struct passwd *pw) DPRINTF(("nothing found for '%s'", filt), 1); continue; } - lres->user_matches = TRUE; + lres->user_matches = true; /* Add the seach result to list of search results. */ DPRINTF(("adding search result"), 1); @@ -2455,7 +2458,7 @@ sudo_ldap_result_get(struct sudo_nss *nss, struct passwd *pw) if ((!do_netgr || sudo_ldap_check_user_netgroup(ld, entry, pw->pw_name)) && sudo_ldap_check_host(ld, entry)) { - lres->host_matches = TRUE; + lres->host_matches = true; sudo_ldap_result_add_entry(lres, entry); } } diff --git a/plugins/sudoers/match.c b/plugins/sudoers/match.c index 618c70ad0..47e167636 100644 --- a/plugins/sudoers/match.c +++ b/plugins/sudoers/match.c @@ -87,13 +87,13 @@ static struct member_list empty; -static int command_matches_dir(char *, size_t); -static int command_matches_glob(char *, char *); -static int command_matches_fnmatch(char *, char *); -static int command_matches_normal(char *, char *); +static bool command_matches_dir(char *, size_t); +static bool command_matches_glob(char *, char *); +static bool command_matches_fnmatch(char *, char *); +static bool command_matches_normal(char *, char *); /* - * Returns TRUE if string 's' contains meta characters. + * Returns true if string 's' contains meta characters. */ #define has_meta(s) (strpbrk(s, "\\?*[]") != NULL) @@ -356,7 +356,7 @@ cmnd_matches(struct member *m) debug_return_bool(matched); } -static int +static bool command_args_match(sudoers_cmnd, sudoers_args) char *sudoers_cmnd; char *sudoers_args; @@ -370,7 +370,7 @@ command_args_match(sudoers_cmnd, sudoers_args) */ if (!sudoers_args || (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args))) - debug_return_bool(TRUE); + debug_return_bool(true); /* * If args are specified in sudoers, they must match the user args. * If running as sudoedit, all args are assumed to be paths. @@ -380,16 +380,16 @@ command_args_match(sudoers_cmnd, sudoers_args) if (strcmp(sudoers_cmnd, "sudoedit") == 0) flags = FNM_PATHNAME; if (fnmatch(sudoers_args, user_args ? user_args : "", flags) == 0) - debug_return_bool(TRUE); + debug_return_bool(true); } - debug_return_bool(FALSE); + debug_return_bool(false); } /* - * If path doesn't end in /, return TRUE iff cmnd & path name the same inode; - * otherwise, return TRUE if user_cmnd names one of the inodes in path. + * If path doesn't end in /, return true iff cmnd & path name the same inode; + * otherwise, return true if user_cmnd names one of the inodes in path. */ -int +bool command_matches(char *sudoers_cmnd, char *sudoers_args) { debug_decl(command_matches, SUDO_DEBUG_MATCH) @@ -404,13 +404,13 @@ command_matches(char *sudoers_cmnd, char *sudoers_args) */ if (strcmp(sudoers_cmnd, "sudoedit") != 0 || strcmp(user_cmnd, "sudoedit") != 0) - debug_return_bool(FALSE); + debug_return_bool(false); if (command_args_match(sudoers_cmnd, sudoers_args)) { efree(safe_cmnd); safe_cmnd = estrdup(sudoers_cmnd); - debug_return_bool(TRUE); + debug_return_bool(true); } else - debug_return_bool(FALSE); + debug_return_bool(false); } if (has_meta(sudoers_cmnd)) { @@ -425,7 +425,7 @@ command_matches(char *sudoers_cmnd, char *sudoers_args) debug_return_bool(command_matches_normal(sudoers_cmnd, sudoers_args)); } -static int +static bool command_matches_fnmatch(char *sudoers_cmnd, char *sudoers_args) { debug_decl(command_matches_fnmatch, SUDO_DEBUG_MATCH) @@ -438,17 +438,17 @@ command_matches_fnmatch(char *sudoers_cmnd, char *sudoers_args) * else return false. */ if (fnmatch(sudoers_cmnd, user_cmnd, FNM_PATHNAME) != 0) - debug_return_bool(FALSE); + debug_return_bool(false); if (command_args_match(sudoers_cmnd, sudoers_args)) { if (safe_cmnd) free(safe_cmnd); safe_cmnd = estrdup(user_cmnd); - debug_return_bool(TRUE); + debug_return_bool(true); } - debug_return_bool(FALSE); + debug_return_bool(false); } -static int +static bool command_matches_glob(char *sudoers_cmnd, char *sudoers_args) { struct stat sudoers_stat; @@ -467,7 +467,7 @@ command_matches_glob(char *sudoers_cmnd, char *sudoers_args) if ((base = strrchr(sudoers_cmnd, '/')) != NULL) { base++; if (!has_meta(base) && strcmp(user_base, base) != 0) - debug_return_bool(FALSE); + debug_return_bool(false); } } /* @@ -480,7 +480,7 @@ command_matches_glob(char *sudoers_cmnd, char *sudoers_args) #define GLOB_FLAGS (GLOB_NOSORT | GLOB_MARK | GLOB_BRACE | GLOB_TILDE) if (glob(sudoers_cmnd, GLOB_FLAGS, NULL, &gl) != 0 || gl.gl_pathc == 0) { globfree(&gl); - debug_return_bool(FALSE); + debug_return_bool(false); } /* For each glob match, compare basename, st_dev and st_ino. */ for (ap = gl.gl_pathv; (cp = *ap) != NULL; ap++) { @@ -488,7 +488,7 @@ command_matches_glob(char *sudoers_cmnd, char *sudoers_args) dlen = strlen(cp); if (cp[dlen - 1] == '/') { if (command_matches_dir(cp, dlen)) - debug_return_bool(TRUE); + debug_return_bool(true); continue; } @@ -510,17 +510,17 @@ command_matches_glob(char *sudoers_cmnd, char *sudoers_args) } globfree(&gl); if (cp == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); if (command_args_match(sudoers_cmnd, sudoers_args)) { efree(safe_cmnd); safe_cmnd = estrdup(user_cmnd); - debug_return_bool(TRUE); + debug_return_bool(true); } - debug_return_bool(FALSE); + debug_return_bool(false); } -static int +static bool command_matches_normal(char *sudoers_cmnd, char *sudoers_args) { struct stat sudoers_stat; @@ -540,7 +540,7 @@ command_matches_normal(char *sudoers_cmnd, char *sudoers_args) base++; if (strcmp(user_base, base) != 0 || stat(sudoers_cmnd, &sudoers_stat) == -1) - debug_return_bool(FALSE); + debug_return_bool(false); /* * Return true if inode/device matches AND @@ -551,19 +551,19 @@ command_matches_normal(char *sudoers_cmnd, char *sudoers_args) if (user_stat != NULL && (user_stat->st_dev != sudoers_stat.st_dev || user_stat->st_ino != sudoers_stat.st_ino)) - debug_return_bool(FALSE); + debug_return_bool(false); if (command_args_match(sudoers_cmnd, sudoers_args)) { efree(safe_cmnd); safe_cmnd = estrdup(sudoers_cmnd); - debug_return_bool(TRUE); + debug_return_bool(true); } - debug_return_bool(FALSE); + debug_return_bool(false); } /* - * Return TRUE if user_cmnd names one of the inodes in dir, else FALSE. + * Return true if user_cmnd names one of the inodes in dir, else false. */ -static int +static bool command_matches_dir(char *sudoers_dir, size_t dlen) { struct stat sudoers_stat; @@ -577,11 +577,11 @@ command_matches_dir(char *sudoers_dir, size_t dlen) */ dirp = opendir(sudoers_dir); if (dirp == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); if (strlcpy(buf, sudoers_dir, sizeof(buf)) >= sizeof(buf)) { closedir(dirp); - debug_return_bool(FALSE); + debug_return_bool(false); } while ((dent = readdir(dirp)) != NULL) { /* ignore paths > PATH_MAX (XXX - log) */ @@ -607,9 +607,9 @@ command_matches_dir(char *sudoers_dir, size_t dlen) } /* - * Returns TRUE if the hostname matches the pattern, else FALSE + * Returns true if the hostname matches the pattern, else false */ -int +bool hostname_matches(char *shost, char *lhost, char *pattern) { debug_decl(hostname_matches, SUDO_DEBUG_MATCH) @@ -628,10 +628,10 @@ hostname_matches(char *shost, char *lhost, char *pattern) } /* - * Returns TRUE if the user/uid from sudoers matches the specified user/uid, - * else returns FALSE. + * Returns true if the user/uid from sudoers matches the specified user/uid, + * else returns false. */ -int +bool userpw_matches(char *sudoers_user, char *user, struct passwd *pw) { debug_decl(userpw_matches, SUDO_DEBUG_MATCH) @@ -639,16 +639,16 @@ userpw_matches(char *sudoers_user, char *user, struct passwd *pw) if (pw != NULL && *sudoers_user == '#') { uid_t uid = (uid_t) atoi(sudoers_user + 1); if (uid == pw->pw_uid) - debug_return_bool(TRUE); + debug_return_bool(true); } debug_return_bool(strcmp(sudoers_user, user) == 0); } /* - * Returns TRUE if the group/gid from sudoers matches the specified group/gid, - * else returns FALSE. + * Returns true if the group/gid from sudoers matches the specified group/gid, + * else returns false. */ -int +bool group_matches(char *sudoers_group, struct group *gr) { debug_decl(group_matches, SUDO_DEBUG_MATCH) @@ -656,19 +656,19 @@ group_matches(char *sudoers_group, struct group *gr) if (*sudoers_group == '#') { gid_t gid = (gid_t) atoi(sudoers_group + 1); if (gid == gr->gr_gid) - debug_return_bool(TRUE); + debug_return_bool(true); } debug_return_bool(strcmp(gr->gr_name, sudoers_group) == 0); } /* - * Returns TRUE if the given user belongs to the named group, - * else returns FALSE. + * Returns true if the given user belongs to the named group, + * else returns false. */ -int +bool usergr_matches(char *group, char *user, struct passwd *pw) { - int matched = FALSE; + int matched = false; struct passwd *pw0 = NULL; debug_decl(usergr_matches, SUDO_DEBUG_MATCH) @@ -689,13 +689,13 @@ usergr_matches(char *group, char *user, struct passwd *pw) } if (user_in_group(pw, group)) { - matched = TRUE; + matched = true; goto done; } /* not a Unix group, could be an external group */ if (def_group_plugin && group_plugin_query(user, group, pw)) { - matched = TRUE; + matched = true; goto done; } @@ -707,13 +707,13 @@ done: } /* - * Returns TRUE if "host" and "user" belong to the netgroup "netgr", - * else return FALSE. Either of "host", "shost" or "user" may be NULL + * Returns true if "host" and "user" belong to the netgroup "netgr", + * else return false. Either of "host", "shost" or "user" may be NULL * in which case that argument is not checked... * * XXX - swap order of host & shost */ -int +bool netgr_matches(char *netgr, char *lhost, char *shost, char *user) { static char *domain; @@ -724,7 +724,7 @@ netgr_matches(char *netgr, char *lhost, char *shost, char *user) /* make sure we have a valid netgroup, sudo style */ if (*netgr++ != '+') - debug_return_bool(FALSE); + debug_return_bool(false); #ifdef HAVE_GETDOMAINNAME /* get the domain name (if any) */ @@ -740,10 +740,10 @@ netgr_matches(char *netgr, char *lhost, char *shost, char *user) #ifdef HAVE_INNETGR if (innetgr(netgr, lhost, user, domain)) - debug_return_bool(TRUE); + debug_return_bool(true); else if (lhost != shost && innetgr(netgr, shost, user, domain)) - debug_return_bool(TRUE); + debug_return_bool(true); #endif /* HAVE_INNETGR */ - debug_return_bool(FALSE); + debug_return_bool(false); } diff --git a/plugins/sudoers/match_addr.c b/plugins/sudoers/match_addr.c index fa8a23a5d..9634eaca8 100644 --- a/plugins/sudoers/match_addr.c +++ b/plugins/sudoers/match_addr.c @@ -50,7 +50,7 @@ #include "sudoers.h" #include "interfaces.h" -static int +static bool addr_matches_if(char *n) { union sudo_in_addr_un addr; @@ -79,27 +79,27 @@ addr_matches_if(char *n) if (ifp->addr.ip4.s_addr == addr.ip4.s_addr || (ifp->addr.ip4.s_addr & ifp->netmask.ip4.s_addr) == addr.ip4.s_addr) - debug_return_bool(TRUE); + debug_return_bool(true); break; #ifdef HAVE_STRUCT_IN6_ADDR case AF_INET6: if (memcmp(ifp->addr.ip6.s6_addr, addr.ip6.s6_addr, sizeof(addr.ip6.s6_addr)) == 0) - debug_return_bool(TRUE); + debug_return_bool(true); for (j = 0; j < sizeof(addr.ip6.s6_addr); j++) { if ((ifp->addr.ip6.s6_addr[j] & ifp->netmask.ip6.s6_addr[j]) != addr.ip6.s6_addr[j]) break; } if (j == sizeof(addr.ip6.s6_addr)) - debug_return_bool(TRUE); + debug_return_bool(true); #endif /* HAVE_STRUCT_IN6_ADDR */ } } - debug_return_bool(FALSE); + debug_return_bool(false); } -static int +static bool addr_matches_if_netmask(char *n, char *m) { int i; @@ -159,7 +159,7 @@ addr_matches_if_netmask(char *n, char *m) switch(family) { case AF_INET: if ((ifp->addr.ip4.s_addr & mask.ip4.s_addr) == addr.ip4.s_addr) - debug_return_bool(TRUE); + debug_return_bool(true); #ifdef HAVE_STRUCT_IN6_ADDR case AF_INET6: for (j = 0; j < sizeof(addr.ip6.s6_addr); j++) { @@ -167,23 +167,23 @@ addr_matches_if_netmask(char *n, char *m) break; } if (j == sizeof(addr.ip6.s6_addr)) - debug_return_bool(TRUE); + debug_return_bool(true); #endif /* HAVE_STRUCT_IN6_ADDR */ } } - debug_return_bool(FALSE); + debug_return_bool(false); } /* - * Returns TRUE if "n" is one of our ip addresses or if - * "n" is a network that we are on, else returns FALSE. + * Returns true if "n" is one of our ip addresses or if + * "n" is a network that we are on, else returns false. */ -int +bool addr_matches(char *n) { char *m; - int retval; + bool retval; debug_decl(addr_matches, SUDO_DEBUG_MATCH) /* If there's an explicit netmask, use it. */ diff --git a/plugins/sudoers/parse.c b/plugins/sudoers/parse.c index a045c6f92..6d0393830 100644 --- a/plugins/sudoers/parse.c +++ b/plugins/sudoers/parse.c @@ -85,7 +85,7 @@ sudo_file_open(struct sudo_nss *nss) if (def_ignore_local_sudoers) debug_return_int(-1); - nss->handle = open_sudoers(sudoers_file, FALSE, NULL); + nss->handle = open_sudoers(sudoers_file, false, NULL); debug_return_int(nss->handle ? 0 : -1); } @@ -164,11 +164,11 @@ sudo_file_lookup(struct sudo_nss *nss, int validated, int pwflag) * Always check the host and user. */ if (pwflag) { - int nopass; + bool nopass; enum def_tuple pwcheck; pwcheck = (pwflag == -1) ? never : sudo_defs_table[pwflag].sd_un.tuple; - nopass = (pwcheck == all) ? TRUE : FALSE; + nopass = (pwcheck == all) ? true : false; if (list_pw == NULL) SET(validated, FLAG_NO_CHECK); @@ -187,8 +187,8 @@ sudo_file_lookup(struct sudo_nss *nss, int validated, int pwflag) user_uid == list_pw->pw_uid || cmnd_matches(cs->cmnd) == ALLOW) match = ALLOW; - if ((pwcheck == any && cs->tags.nopasswd == TRUE) || - (pwcheck == all && cs->tags.nopasswd != TRUE)) + if ((pwcheck == any && cs->tags.nopasswd == true) || + (pwcheck == all && cs->tags.nopasswd != true)) nopass = cs->tags.nopasswd; } } @@ -200,8 +200,8 @@ sudo_file_lookup(struct sudo_nss *nss, int validated, int pwflag) SET(validated, VALIDATE_NOT_OK); if (pwcheck == always && def_authenticate) SET(validated, FLAG_CHECK_USER); - else if (pwcheck == never || nopass == TRUE) - def_authenticate = FALSE; + else if (pwcheck == never || nopass == true) + def_authenticate = false; debug_return_int(validated); } @@ -485,7 +485,7 @@ sudo_file_display_defaults(struct sudo_nss *nss, struct passwd *pw, lbuf_append_quoted(lbuf, SUDOERS_QUOTED, "%s", d->val); } else lbuf_append(lbuf, "%s%s%s", prefix, - d->op == FALSE ? "!" : "", d->var); + d->op == false ? "!" : "", d->var); prefix = ", "; nfound++; } @@ -564,7 +564,7 @@ display_bound_defaults(int dtype, struct lbuf *lbuf) lbuf_append(lbuf, "%s%s%s", d->var, d->op == '+' ? "+=" : d->op == '-' ? "-=" : "=", d->val); } else - lbuf_append(lbuf, "%s%s", d->op == FALSE ? "!" : "", d->var); + lbuf_append(lbuf, "%s%s", d->op == false ? "!" : "", d->var); } debug_return_int(nfound); diff --git a/plugins/sudoers/parse.h b/plugins/sudoers/parse.h index 6976b16d5..3b1a5b50d 100644 --- a/plugins/sudoers/parse.h +++ b/plugins/sudoers/parse.h @@ -37,7 +37,7 @@ struct sudo_command { /* * Tags associated with a command. - * Possible valus: TRUE, FALSE, UNSPEC. + * Possible values: true, false, UNSPEC. */ struct cmndtag { __signed int nopasswd: 3; @@ -148,7 +148,7 @@ struct defaults { char *val; /* variable value */ struct member_list binding; /* user/host/runas binding */ int type; /* DEFAULTS{,_USER,_RUNAS,_HOST} */ - int op; /* TRUE, FALSE, '+', '-' */ + int op; /* true, false, '+', '-' */ }; /* @@ -166,19 +166,19 @@ extern unsigned int alias_seqno; * Prototypes */ char *alias_add(char *, int, struct member *); -int addr_matches(char *); +bool addr_matches(char *); int cmnd_matches(struct member *); int cmndlist_matches(struct member_list *); -int command_matches(char *, char *); +bool command_matches(char *, char *); int hostlist_matches(struct member_list *); -int hostname_matches(char *, char *, char *); -int netgr_matches(char *, char *, char *, char *); -int no_aliases(void); +bool hostname_matches(char *, char *, char *); +bool netgr_matches(char *, char *, char *, char *); +bool no_aliases(void); int runaslist_matches(struct member_list *, struct member_list *); int userlist_matches(struct passwd *, struct member_list *); -int usergr_matches(char *, char *, struct passwd *); -int userpw_matches(char *, char *, struct passwd *); -int group_matches(char *, struct group *); +bool usergr_matches(char *, char *, struct passwd *); +bool userpw_matches(char *, char *, struct passwd *); +bool group_matches(char *, struct group *); struct alias *alias_find(char *, int); struct alias *alias_remove(char *, int); void alias_free(void *); diff --git a/plugins/sudoers/pwutil.c b/plugins/sudoers/pwutil.c index b368371ad..c1a80dc34 100644 --- a/plugins/sudoers/pwutil.c +++ b/plugins/sudoers/pwutil.c @@ -905,12 +905,13 @@ set_group_list(const char *user, GETGROUPS_T *gids, int ngids) debug_return; } -int +bool user_in_group(struct passwd *pw, const char *group) { struct group_list *grlist; struct group *grp = NULL; - int i, matched = FALSE; + int i; + bool matched = false; debug_decl(user_in_group, SUDO_DEBUG_NSS) if ((grlist = get_group_list(pw)) != NULL) { @@ -920,12 +921,12 @@ user_in_group(struct passwd *pw, const char *group) if (group[0] == '#') { gid_t gid = atoi(group + 1); if (gid == pw->pw_gid) { - matched = TRUE; + matched = true; goto done; } for (i = 0; i < grlist->ngids; i++) { if (gid == grlist->gids[i]) { - matched = TRUE; + matched = true; goto done; } } @@ -937,7 +938,7 @@ user_in_group(struct passwd *pw, const char *group) */ for (i = 0; i < grlist->ngroups; i++) { if (strcasecmp(group, grlist->groups[i]) == 0) { - matched = TRUE; + matched = true; goto done; } } @@ -945,7 +946,7 @@ user_in_group(struct passwd *pw, const char *group) /* Finally check against user's primary (passwd file) group. */ if ((grp = sudo_getgrgid(pw->pw_gid)) != NULL) { if (strcasecmp(group, grp->gr_name) == 0) { - matched = TRUE; + matched = true; goto done; } } diff --git a/plugins/sudoers/sudo_nss.c b/plugins/sudoers/sudo_nss.c index a3f446545..d8ed0f5de 100644 --- a/plugins/sudoers/sudo_nss.c +++ b/plugins/sudoers/sudo_nss.c @@ -58,9 +58,9 @@ sudo_read_nss(void) { FILE *fp; char *cp; - int saw_files = FALSE; - int saw_ldap = FALSE; - int got_match = FALSE; + bool saw_files = false; + bool saw_ldap = false; + bool got_match = false; static struct sudo_nss_list snl; debug_decl(sudo_read_nss, SUDO_DEBUG_NSS) @@ -80,16 +80,16 @@ sudo_read_nss(void) for ((cp = strtok(cp + 8, " \t")); cp != NULL; (cp = strtok(NULL, " \t"))) { if (strcasecmp(cp, "files") == 0 && !saw_files) { tq_append(&snl, &sudo_nss_file); - got_match = TRUE; + got_match = true; } else if (strcasecmp(cp, "ldap") == 0 && !saw_ldap) { tq_append(&snl, &sudo_nss_ldap); - got_match = TRUE; + got_match = true; } else if (strcasecmp(cp, "[NOTFOUND=return]") == 0 && got_match) { /* NOTFOUND affects the most recent entry */ - tq_last(&snl)->ret_if_notfound = TRUE; - got_match = FALSE; + tq_last(&snl)->ret_if_notfound = true; + got_match = false; } else - got_match = FALSE; + got_match = false; } /* Only parse the first "sudoers:" line */ break; @@ -117,9 +117,9 @@ sudo_read_nss(void) { FILE *fp; char *cp, *ep; - int saw_files = FALSE; - int saw_ldap = FALSE; - int got_match = FALSE; + bool saw_files = false; + bool saw_ldap = false; + bool got_match = false; static struct sudo_nss_list snl; debug_decl(sudo_read_nss, SUDO_DEBUG_NSS) @@ -149,15 +149,15 @@ sudo_read_nss(void) if (!saw_files && strncasecmp(cp, "files", 5) == 0 && (isspace((unsigned char)cp[5]) || cp[5] == '\0')) { tq_append(&snl, &sudo_nss_file); - got_match = TRUE; + got_match = true; ep = &cp[5]; } else if (!saw_ldap && strncasecmp(cp, "ldap", 4) == 0 && (isspace((unsigned char)cp[4]) || cp[4] == '\0')) { tq_append(&snl, &sudo_nss_ldap); - got_match = TRUE; + got_match = true; ep = &cp[4]; } else { - got_match = FALSE; + got_match = false; } /* check for = auth qualifier */ @@ -167,7 +167,7 @@ sudo_read_nss(void) cp++; if (strncasecmp(cp, "auth", 4) == 0 && (isspace((unsigned char)cp[4]) || cp[4] == '\0')) { - tq_last(&snl)->ret_if_found = TRUE; + tq_last(&snl)->ret_if_found = true; } } } @@ -289,9 +289,9 @@ display_privs(struct sudo_nss_list *snl, struct passwd *pw) /* * Check user_cmnd against sudoers and print the matching entry if the * command is allowed. - * Returns TRUE if the command is allowed, else FALSE. + * Returns true if the command is allowed, else false. */ -int +bool display_cmnd(struct sudo_nss_list *snl, struct passwd *pw) { struct sudo_nss *nss; @@ -299,7 +299,7 @@ display_cmnd(struct sudo_nss_list *snl, struct passwd *pw) tq_foreach_fwd(snl, nss) { if (nss->display_cmnd(nss, pw) == 0) - debug_return_bool(TRUE); + debug_return_bool(true); } - debug_return_bool(FALSE); + debug_return_bool(false); } diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 647ee4ad9..bf228e1a5 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -109,7 +109,7 @@ struct interface *interfaces; int long_list; uid_t timestamp_uid; extern int errorlineno; -extern int parse_error; +extern bool parse_error; extern char *errorfile; #ifdef HAVE_LOGIN_CAP_H login_cap_t *lc; @@ -212,7 +212,7 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation, * Initialize external group plugin, if any. */ if (def_group_plugin) { - if (group_plugin_load(def_group_plugin) != TRUE) + if (group_plugin_load(def_group_plugin) != true) def_group_plugin = NULL; } @@ -239,7 +239,7 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation, restore_perms(); - debug_return_bool(TRUE); + debug_return_bool(true); } static void @@ -297,7 +297,7 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], struct sudo_nss *nss; int cmnd_status = -1, validated; volatile int info_len = 0; - volatile int rval = TRUE; + volatile int rval = true; debug_decl(sudoers_policy_main, SUDO_DEBUG_PLUGIN) if (sigsetjmp(error_jmp, 1)) { @@ -348,7 +348,7 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], /* If given the -P option, set the "preserve_groups" flag. */ if (ISSET(sudo_mode, MODE_PRESERVE_GROUPS)) - def_preserve_groups = TRUE; + def_preserve_groups = true; /* Find command in path */ cmnd_status = set_cmnd(); @@ -434,14 +434,14 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], */ if (ISSET(sudo_mode, MODE_EDIT) || (ISSET(sudo_mode, MODE_PRESERVE_ENV) && def_setenv)) - def_env_reset = FALSE; + def_env_reset = false; /* Build a new environment that avoids any nasty bits. */ rebuild_env(); /* Require a password if sudoers says so. */ rval = check_user(validated, sudo_mode); - if (rval != TRUE) + if (rval != true) goto done; /* If run as root with SUDO_USER set, set sudo_user.pw to that user. */ @@ -591,13 +591,13 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], #if defined(__linux__) || defined(_AIX) /* Insert system-wide environment variables. */ - read_env_file(_PATH_ENVIRONMENT, TRUE); + read_env_file(_PATH_ENVIRONMENT, true); #endif } /* Insert system-wide environment variables. */ if (def_env_file) - read_env_file(def_env_file, FALSE); + read_env_file(def_env_file, false); /* Insert user-specified environment variables. */ insert_env_vars(sudo_user.env_vars); @@ -688,7 +688,7 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], goto done; bad: - rval = FALSE; + rval = false; done: rewind_perms(); @@ -926,7 +926,7 @@ set_cmnd(void) * Returns a handle to the sudoers file or NULL on error. */ FILE * -open_sudoers(const char *sudoers, int doedit, int *keepopen) +open_sudoers(const char *sudoers, bool doedit, bool *keepopen) { struct stat statbuf; FILE *fp = NULL; @@ -1135,7 +1135,7 @@ cb_runas_default(const char *user) /* Only reset runaspw if user didn't specify one. */ if (!runas_user && !runas_group) set_runaspw(user); - return TRUE; + return true; } /* @@ -1190,7 +1190,7 @@ sudoers_policy_version(int verbose) dump_interfaces(interfaces_string); sudo_printf(SUDO_CONV_INFO_MSG, "\n"); } - debug_return_bool(TRUE); + debug_return_bool(true); } static int @@ -1225,59 +1225,59 @@ deserialize_info(char * const settings[], char * const user_info[]) } if (MATCHES(*cur, "prompt=")) { user_prompt = *cur + sizeof("prompt=") - 1; - def_passprompt_override = TRUE; + def_passprompt_override = true; continue; } if (MATCHES(*cur, "set_home=")) { - if (atobool(*cur + sizeof("set_home=") - 1) == TRUE) + if (atobool(*cur + sizeof("set_home=") - 1) == true) SET(flags, MODE_RESET_HOME); continue; } if (MATCHES(*cur, "preserve_environment=")) { - if (atobool(*cur + sizeof("preserve_environment=") - 1) == TRUE) + if (atobool(*cur + sizeof("preserve_environment=") - 1) == true) SET(flags, MODE_PRESERVE_ENV); continue; } if (MATCHES(*cur, "run_shell=")) { - if (atobool(*cur + sizeof("run_shell=") - 1) == TRUE) + if (atobool(*cur + sizeof("run_shell=") - 1) == true) SET(flags, MODE_SHELL); continue; } if (MATCHES(*cur, "login_shell=")) { - if (atobool(*cur + sizeof("login_shell=") - 1) == TRUE) { + if (atobool(*cur + sizeof("login_shell=") - 1) == true) { SET(flags, MODE_LOGIN_SHELL); - def_env_reset = TRUE; + def_env_reset = true; } continue; } if (MATCHES(*cur, "implied_shell=")) { - if (atobool(*cur + sizeof("implied_shell=") - 1) == TRUE) + if (atobool(*cur + sizeof("implied_shell=") - 1) == true) SET(flags, MODE_IMPLIED_SHELL); continue; } if (MATCHES(*cur, "preserve_groups=")) { - if (atobool(*cur + sizeof("preserve_groups=") - 1) == TRUE) + if (atobool(*cur + sizeof("preserve_groups=") - 1) == true) SET(flags, MODE_PRESERVE_GROUPS); continue; } if (MATCHES(*cur, "ignore_ticket=")) { - if (atobool(*cur + sizeof("ignore_ticket=") - 1) == TRUE) + if (atobool(*cur + sizeof("ignore_ticket=") - 1) == true) SET(flags, MODE_IGNORE_TICKET); continue; } if (MATCHES(*cur, "noninteractive=")) { - if (atobool(*cur + sizeof("noninteractive=") - 1) == TRUE) + if (atobool(*cur + sizeof("noninteractive=") - 1) == true) SET(flags, MODE_NONINTERACTIVE); continue; } if (MATCHES(*cur, "sudoedit=")) { - if (atobool(*cur + sizeof("sudoedit=") - 1) == TRUE) + if (atobool(*cur + sizeof("sudoedit=") - 1) == true) SET(flags, MODE_EDIT); continue; } if (MATCHES(*cur, "login_class=")) { login_class = *cur + sizeof("login_class=") - 1; - def_use_loginclass = TRUE; + def_use_loginclass = true; continue; } #ifdef HAVE_SELINUX @@ -1421,7 +1421,8 @@ static char * resolve_editor(char *editor, int nfiles, char **files, char ***argv_out) { char *cp, **nargv, *editor_path = NULL; - int ac, i, nargc, wasblank; + int ac, i, nargc; + bool wasblank; debug_decl(resolve_editor, SUDO_DEBUG_PLUGIN) editor = estrdup(editor); /* becomes part of argv_out */ @@ -1432,11 +1433,11 @@ resolve_editor(char *editor, int nfiles, char **files, char ***argv_out) * line args so look for those and alloc space for them too. */ nargc = 1; - for (wasblank = FALSE, cp = editor; *cp != '\0'; cp++) { + for (wasblank = false, cp = editor; *cp != '\0'; cp++) { if (isblank((unsigned char) *cp)) - wasblank = TRUE; + wasblank = true; else if (wasblank) { - wasblank = FALSE; + wasblank = false; nargc++; } } diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 0fed51148..1d4f3e9d4 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -23,6 +23,11 @@ #define _SUDO_SUDOERS_H #include +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif /* HAVE_STDBOOL_H */ #include #include "missing.h" @@ -98,14 +103,6 @@ struct sudo_user { #define FLAG_NO_HOST 0x040 #define FLAG_NO_CHECK 0x080 -/* - * Pseudo-boolean values - */ -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE 0 - /* * find_path()/load_cmnd() return values */ @@ -207,15 +204,15 @@ struct timeval; #define YY_DECL int yylex(void) /* goodpath.c */ -int sudo_goodpath(const char *, struct stat *); +bool sudo_goodpath(const char *, struct stat *); /* findpath.c */ int find_path(char *, char **, struct stat *, char *, int); /* check.c */ int check_user(int, int); -void remove_timestamp(int); -int user_is_exempt(void); +void remove_timestamp(bool); +bool user_is_exempt(void); /* sudo_auth.c */ int verify_user(struct passwd *, char *); @@ -259,7 +256,7 @@ void zero_bytes(volatile void *, size_t); /* sudo_nss.c */ void display_privs(struct sudo_nss_list *, struct passwd *); -int display_cmnd(struct sudo_nss_list *, struct passwd *); +bool display_cmnd(struct sudo_nss_list *, struct passwd *); /* pwutil.c */ void sudo_setgrent(void); @@ -283,7 +280,7 @@ void gr_addref(struct group *); void gr_delref(struct group *); void pw_addref(struct passwd *); void pw_delref(struct passwd *); -int user_in_group(struct passwd *, const char *); +bool user_in_group(struct passwd *, const char *); /* timestr.c */ char *get_timestr(time_t, int); @@ -316,7 +313,7 @@ char *fmt_string(const char *, const char *); /* sudoers.c */ void plugin_cleanup(int); void set_fqdn(void); -FILE *open_sudoers(const char *, int, int *); +FILE *open_sudoers(const char *, bool, bool *); /* aix.c */ void aix_restoreauthdb(void); diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index ad01bbc16..67a139c0b 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -253,7 +253,7 @@ main(int argc, char *argv[]) init_parser("sudoers", 0); if (yyparse() != 0 || parse_error) { - parse_error = TRUE; + parse_error = true; if (errorlineno != -1) (void) printf("Parse error in %s near line %d", errorfile, errorlineno); @@ -267,7 +267,7 @@ main(int argc, char *argv[]) (void) fputs(" (problem with defaults entries)", stdout); puts("."); - if (def_group_plugin && group_plugin_load(def_group_plugin) != TRUE) + if (def_group_plugin && group_plugin_load(def_group_plugin) != true) def_group_plugin = NULL; /* @@ -370,7 +370,7 @@ cb_runas_default(const char *user) /* Only reset runaspw if user didn't specify one. */ if (!runas_user && !runas_group) set_runaspw(user); - return TRUE; + return true; } void @@ -392,7 +392,7 @@ set_fqdn(void) } FILE * -open_sudoers(const char *path, int isdir, int *keepopen) +open_sudoers(const char *path, bool doedit, bool *keepopen) { return fopen(path, "r"); } @@ -468,9 +468,9 @@ print_defaults(void) putchar(','); print_member(m); } - printf("\t%s%s", d->op == FALSE ? "!" : "", d->var); + printf("\t%s%s", d->op == false ? "!" : "", d->var); if (d->val != NULL) { - printf("%c%s", d->op == TRUE ? '=' : d->op, d->val); + printf("%c%s", d->op == true ? '=' : d->op, d->val); } putchar('\n'); } diff --git a/plugins/sudoers/toke.c b/plugins/sudoers/toke.c index 072d73dd4..c007c8d13 100644 --- a/plugins/sudoers/toke.c +++ b/plugins/sudoers/toke.c @@ -1478,15 +1478,16 @@ char *yytext; #include "lbuf.h" extern YYSTYPE yylval; -extern int parse_error; +extern bool parse_error; int sudolineno; int last_token; char *sudoers; -static int continued, prev_state, sawspace; +static bool continued, sawspace; +static int prev_state; -static int _push_include(char *, int); -static int pop_include(void); +static bool _push_include(char *, bool); +static bool pop_include(void); static char *parse_include(char *); static int sudoers_trace_print(const char *msg); @@ -1497,8 +1498,8 @@ int (*trace_print)(const char *msg) = sudoers_trace_print; return (n); \ } while (0) -#define push_include(_p) (_push_include((_p), FALSE)) -#define push_includedir(_p) (_push_include((_p), TRUE)) +#define push_include(_p) (_push_include((_p), false)) +#define push_includedir(_p) (_push_include((_p), true)) #define YY_NO_INPUT 1 #define YY_NO_UNPUT 1 #define GOTDEFS 1 @@ -1511,7 +1512,7 @@ int (*trace_print)(const char *msg) = sudoers_trace_print; #define INSTR 5 -#line 1514 "lex.yy.c" +#line 1515 "lex.yy.c" /* Macros after this point can all be overridden by user definitions in * section 1. @@ -1665,9 +1666,9 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 122 "toke.l" +#line 123 "toke.l" -#line 1670 "lex.yy.c" +#line 1671 "lex.yy.c" if ( yy_init ) { @@ -1753,7 +1754,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 123 "toke.l" +#line 124 "toke.l" { LEXTRACE(", "); LEXRETURN(','); @@ -1761,12 +1762,12 @@ YY_RULE_SETUP YY_BREAK case 2: YY_RULE_SETUP -#line 128 "toke.l" +#line 129 "toke.l" BEGIN STARTDEFS; YY_BREAK case 3: YY_RULE_SETUP -#line 130 "toke.l" +#line 131 "toke.l" { BEGIN INDEFS; LEXTRACE("DEFVAR "); @@ -1778,7 +1779,7 @@ YY_RULE_SETUP case 4: YY_RULE_SETUP -#line 139 "toke.l" +#line 140 "toke.l" { BEGIN STARTDEFS; LEXTRACE(", "); @@ -1787,7 +1788,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 145 "toke.l" +#line 146 "toke.l" { LEXTRACE("= "); LEXRETURN('='); @@ -1795,7 +1796,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 150 "toke.l" +#line 151 "toke.l" { LEXTRACE("+= "); LEXRETURN('+'); @@ -1803,7 +1804,7 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 155 "toke.l" +#line 156 "toke.l" { LEXTRACE("-= "); LEXRETURN('-'); @@ -1811,7 +1812,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 160 "toke.l" +#line 161 "toke.l" { LEXTRACE("BEGINSTR "); yylval.string = NULL; @@ -1821,7 +1822,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 167 "toke.l" +#line 168 "toke.l" { LEXTRACE("WORD(2) "); if (!fill(yytext, yyleng)) @@ -1833,16 +1834,16 @@ YY_RULE_SETUP case 10: YY_RULE_SETUP -#line 176 "toke.l" +#line 177 "toke.l" { /* Line continuation char followed by newline. */ sudolineno++; - continued = TRUE; + continued = true; } YY_BREAK case 11: YY_RULE_SETUP -#line 182 "toke.l" +#line 183 "toke.l" { LEXTRACE("ENDSTR "); BEGIN prev_state; @@ -1877,7 +1878,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 214 "toke.l" +#line 215 "toke.l" { LEXTRACE("BACKSLASH "); if (!append(yytext, yyleng)) @@ -1886,7 +1887,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 220 "toke.l" +#line 221 "toke.l" { LEXTRACE("STRBODY "); if (!append(yytext, yyleng)) @@ -1897,29 +1898,29 @@ YY_RULE_SETUP case 14: YY_RULE_SETUP -#line 228 "toke.l" +#line 229 "toke.l" { /* quoted fnmatch glob char, pass verbatim */ LEXTRACE("QUOTEDCHAR "); if (!fill_args(yytext, 2, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } YY_BREAK case 15: YY_RULE_SETUP -#line 236 "toke.l" +#line 237 "toke.l" { /* quoted sudoers special char, strip backslash */ LEXTRACE("QUOTEDCHAR "); if (!fill_args(yytext + 1, 1, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } YY_BREAK case 16: YY_RULE_SETUP -#line 244 "toke.l" +#line 245 "toke.l" { BEGIN INITIAL; yyless(0); @@ -1928,18 +1929,18 @@ YY_RULE_SETUP YY_BREAK case 17: YY_RULE_SETUP -#line 250 "toke.l" +#line 251 "toke.l" { LEXTRACE("ARG "); if (!fill_args(yytext, yyleng, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } /* a command line arg */ YY_BREAK case 18: YY_RULE_SETUP -#line 258 "toke.l" +#line 259 "toke.l" { char *path; @@ -1960,7 +1961,7 @@ YY_RULE_SETUP YY_BREAK case 19: YY_RULE_SETUP -#line 276 "toke.l" +#line 277 "toke.l" { char *path; @@ -1984,7 +1985,7 @@ YY_RULE_SETUP YY_BREAK case 20: YY_RULE_SETUP -#line 297 "toke.l" +#line 298 "toke.l" { char deftype; int n; @@ -2027,7 +2028,7 @@ YY_RULE_SETUP YY_BREAK case 21: YY_RULE_SETUP -#line 337 "toke.l" +#line 338 "toke.l" { int n; @@ -2056,7 +2057,7 @@ YY_RULE_SETUP YY_BREAK case 22: YY_RULE_SETUP -#line 363 "toke.l" +#line 364 "toke.l" { /* cmnd does not require passwd for this user */ LEXTRACE("NOPASSWD "); @@ -2065,7 +2066,7 @@ YY_RULE_SETUP YY_BREAK case 23: YY_RULE_SETUP -#line 369 "toke.l" +#line 370 "toke.l" { /* cmnd requires passwd for this user */ LEXTRACE("PASSWD "); @@ -2074,7 +2075,7 @@ YY_RULE_SETUP YY_BREAK case 24: YY_RULE_SETUP -#line 375 "toke.l" +#line 376 "toke.l" { LEXTRACE("NOEXEC "); LEXRETURN(NOEXEC); @@ -2082,7 +2083,7 @@ YY_RULE_SETUP YY_BREAK case 25: YY_RULE_SETUP -#line 380 "toke.l" +#line 381 "toke.l" { LEXTRACE("EXEC "); LEXRETURN(EXEC); @@ -2090,7 +2091,7 @@ YY_RULE_SETUP YY_BREAK case 26: YY_RULE_SETUP -#line 385 "toke.l" +#line 386 "toke.l" { LEXTRACE("SETENV "); LEXRETURN(SETENV); @@ -2098,7 +2099,7 @@ YY_RULE_SETUP YY_BREAK case 27: YY_RULE_SETUP -#line 390 "toke.l" +#line 391 "toke.l" { LEXTRACE("NOSETENV "); LEXRETURN(NOSETENV); @@ -2106,7 +2107,7 @@ YY_RULE_SETUP YY_BREAK case 28: YY_RULE_SETUP -#line 395 "toke.l" +#line 396 "toke.l" { LEXTRACE("LOG_OUTPUT "); LEXRETURN(LOG_OUTPUT); @@ -2114,7 +2115,7 @@ YY_RULE_SETUP YY_BREAK case 29: YY_RULE_SETUP -#line 400 "toke.l" +#line 401 "toke.l" { LEXTRACE("NOLOG_OUTPUT "); LEXRETURN(NOLOG_OUTPUT); @@ -2122,7 +2123,7 @@ YY_RULE_SETUP YY_BREAK case 30: YY_RULE_SETUP -#line 405 "toke.l" +#line 406 "toke.l" { LEXTRACE("LOG_INPUT "); LEXRETURN(LOG_INPUT); @@ -2130,7 +2131,7 @@ YY_RULE_SETUP YY_BREAK case 31: YY_RULE_SETUP -#line 410 "toke.l" +#line 411 "toke.l" { LEXTRACE("NOLOG_INPUT "); LEXRETURN(NOLOG_INPUT); @@ -2138,7 +2139,7 @@ YY_RULE_SETUP YY_BREAK case 32: YY_RULE_SETUP -#line 415 "toke.l" +#line 416 "toke.l" { /* empty group or netgroup */ LEXTRACE("ERROR "); @@ -2147,7 +2148,7 @@ YY_RULE_SETUP YY_BREAK case 33: YY_RULE_SETUP -#line 421 "toke.l" +#line 422 "toke.l" { /* netgroup */ if (!fill(yytext, yyleng)) @@ -2158,7 +2159,7 @@ YY_RULE_SETUP YY_BREAK case 34: YY_RULE_SETUP -#line 429 "toke.l" +#line 430 "toke.l" { /* group */ if (!fill(yytext, yyleng)) @@ -2169,7 +2170,7 @@ YY_RULE_SETUP YY_BREAK case 35: YY_RULE_SETUP -#line 437 "toke.l" +#line 438 "toke.l" { if (!fill(yytext, yyleng)) yyterminate(); @@ -2179,7 +2180,7 @@ YY_RULE_SETUP YY_BREAK case 36: YY_RULE_SETUP -#line 444 "toke.l" +#line 445 "toke.l" { if (!fill(yytext, yyleng)) yyterminate(); @@ -2189,7 +2190,7 @@ YY_RULE_SETUP YY_BREAK case 37: YY_RULE_SETUP -#line 451 "toke.l" +#line 452 "toke.l" { if (!ipv6_valid(yytext)) { LEXTRACE("ERROR "); @@ -2203,7 +2204,7 @@ YY_RULE_SETUP YY_BREAK case 38: YY_RULE_SETUP -#line 462 "toke.l" +#line 463 "toke.l" { if (!ipv6_valid(yytext)) { LEXTRACE("ERROR "); @@ -2217,7 +2218,7 @@ YY_RULE_SETUP YY_BREAK case 39: YY_RULE_SETUP -#line 473 "toke.l" +#line 474 "toke.l" { LEXTRACE("ALL "); LEXRETURN(ALL); @@ -2226,7 +2227,7 @@ YY_RULE_SETUP YY_BREAK case 40: YY_RULE_SETUP -#line 479 "toke.l" +#line 480 "toke.l" { #ifdef HAVE_SELINUX LEXTRACE("ROLE "); @@ -2238,7 +2239,7 @@ YY_RULE_SETUP YY_BREAK case 41: YY_RULE_SETUP -#line 488 "toke.l" +#line 489 "toke.l" { #ifdef HAVE_SELINUX LEXTRACE("TYPE "); @@ -2250,7 +2251,7 @@ YY_RULE_SETUP YY_BREAK case 42: YY_RULE_SETUP -#line 497 "toke.l" +#line 498 "toke.l" { #ifndef HAVE_SELINUX got_alias: @@ -2263,7 +2264,7 @@ YY_RULE_SETUP YY_BREAK case 43: YY_RULE_SETUP -#line 507 "toke.l" +#line 508 "toke.l" { /* no command args allowed for Defaults!/path */ if (!fill_cmnd(yytext, yyleng)) @@ -2274,7 +2275,7 @@ YY_RULE_SETUP YY_BREAK case 44: YY_RULE_SETUP -#line 515 "toke.l" +#line 516 "toke.l" { BEGIN GOTCMND; LEXTRACE("COMMAND "); @@ -2284,7 +2285,7 @@ YY_RULE_SETUP YY_BREAK case 45: YY_RULE_SETUP -#line 522 "toke.l" +#line 523 "toke.l" { /* directories can't have args... */ if (yytext[yyleng - 1] == '/') { @@ -2302,7 +2303,7 @@ YY_RULE_SETUP YY_BREAK case 46: YY_RULE_SETUP -#line 537 "toke.l" +#line 538 "toke.l" { LEXTRACE("BEGINSTR "); yylval.string = NULL; @@ -2312,7 +2313,7 @@ YY_RULE_SETUP YY_BREAK case 47: YY_RULE_SETUP -#line 544 "toke.l" +#line 545 "toke.l" { /* a word */ if (!fill(yytext, yyleng)) @@ -2323,7 +2324,7 @@ YY_RULE_SETUP YY_BREAK case 48: YY_RULE_SETUP -#line 552 "toke.l" +#line 553 "toke.l" { LEXTRACE("( "); LEXRETURN('('); @@ -2331,7 +2332,7 @@ YY_RULE_SETUP YY_BREAK case 49: YY_RULE_SETUP -#line 557 "toke.l" +#line 558 "toke.l" { LEXTRACE(") "); LEXRETURN(')'); @@ -2339,7 +2340,7 @@ YY_RULE_SETUP YY_BREAK case 50: YY_RULE_SETUP -#line 562 "toke.l" +#line 563 "toke.l" { LEXTRACE(", "); LEXRETURN(','); @@ -2347,7 +2348,7 @@ YY_RULE_SETUP YY_BREAK case 51: YY_RULE_SETUP -#line 567 "toke.l" +#line 568 "toke.l" { LEXTRACE("= "); LEXRETURN('='); @@ -2355,7 +2356,7 @@ YY_RULE_SETUP YY_BREAK case 52: YY_RULE_SETUP -#line 572 "toke.l" +#line 573 "toke.l" { LEXTRACE(": "); LEXRETURN(':'); @@ -2363,7 +2364,7 @@ YY_RULE_SETUP YY_BREAK case 53: YY_RULE_SETUP -#line 577 "toke.l" +#line 578 "toke.l" { if (yyleng & 1) { LEXTRACE("!"); @@ -2373,7 +2374,7 @@ YY_RULE_SETUP YY_BREAK case 54: YY_RULE_SETUP -#line 584 "toke.l" +#line 585 "toke.l" { if (YY_START == INSTR) { LEXTRACE("ERROR "); @@ -2381,41 +2382,41 @@ YY_RULE_SETUP } BEGIN INITIAL; sudolineno++; - continued = FALSE; + continued = false; LEXTRACE("\n"); LEXRETURN(COMMENT); } /* return newline */ YY_BREAK case 55: YY_RULE_SETUP -#line 596 "toke.l" +#line 597 "toke.l" { /* throw away space/tabs */ - sawspace = TRUE; /* but remember for fill_args */ + sawspace = true; /* but remember for fill_args */ } YY_BREAK case 56: YY_RULE_SETUP -#line 600 "toke.l" +#line 601 "toke.l" { - sawspace = TRUE; /* remember for fill_args */ + sawspace = true; /* remember for fill_args */ sudolineno++; - continued = TRUE; + continued = true; } /* throw away EOL after \ */ YY_BREAK case 57: YY_RULE_SETUP -#line 606 "toke.l" +#line 607 "toke.l" { BEGIN INITIAL; sudolineno++; - continued = FALSE; + continued = false; LEXTRACE("#\n"); LEXRETURN(COMMENT); } /* comment, not uid/gid */ YY_BREAK case 58: YY_RULE_SETUP -#line 614 "toke.l" +#line 615 "toke.l" { LEXTRACE("ERROR "); LEXRETURN(ERROR); @@ -2427,7 +2428,7 @@ case YY_STATE_EOF(GOTCMND): case YY_STATE_EOF(STARTDEFS): case YY_STATE_EOF(INDEFS): case YY_STATE_EOF(INSTR): -#line 619 "toke.l" +#line 620 "toke.l" { if (YY_START != INITIAL) { BEGIN INITIAL; @@ -2440,10 +2441,10 @@ case YY_STATE_EOF(INSTR): YY_BREAK case 59: YY_RULE_SETUP -#line 629 "toke.l" +#line 630 "toke.l" ECHO; YY_BREAK -#line 2446 "lex.yy.c" +#line 2447 "lex.yy.c" case YY_END_OF_BUFFER: { @@ -3334,7 +3335,7 @@ int main() return 0; } #endif -#line 629 "toke.l" +#line 630 "toke.l" struct path_list { char *path; @@ -3346,7 +3347,7 @@ struct include_stack { char *path; struct path_list *more; /* more files in case of includedir */ int lineno; - int keepopen; + bool keepopen; }; static int @@ -3458,7 +3459,7 @@ bad: static size_t istacksize, idepth; static struct include_stack *istack; -static int keepopen; +static bool keepopen; void init_lexer(void) @@ -3482,16 +3483,16 @@ init_lexer(void) istack = NULL; istacksize = idepth = 0; sudolineno = 1; - keepopen = FALSE; - sawspace = FALSE; - continued = FALSE; + keepopen = false; + sawspace = false; + continued = false; prev_state = INITIAL; debug_return; } -static int -_push_include(char *path, int isdir) +static bool +_push_include(char *path, bool isdir) { struct path_list *pl; FILE *fp; @@ -3501,32 +3502,32 @@ _push_include(char *path, int isdir) if (idepth >= istacksize) { if (idepth > MAX_SUDOERS_DEPTH) { yyerror(_("too many levels of includes")); - debug_return_bool(FALSE); + debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); if (istack == NULL) { yyerror(_("unable to allocate memory")); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (isdir) { if (!(path = switch_dir(&istack[idepth], path))) { /* switch_dir() called yyerror() for us */ - debug_return_bool(FALSE); + debug_return_bool(false); } - while ((fp = open_sudoers(path, FALSE, &keepopen)) == NULL) { + while ((fp = open_sudoers(path, false, &keepopen)) == NULL) { /* Unable to open path in includedir, go to next one, if any. */ efree(path); if ((pl = istack[idepth].more) == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); path = pl->path; istack[idepth].more = pl->next; efree(pl); } } else { - if ((fp = open_sudoers(path, TRUE, &keepopen)) == NULL) { + if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { char *errbuf; if (asprintf(&errbuf, _("%s: %s"), path, strerror(errno)) != -1) { yyerror(errbuf); @@ -3534,7 +3535,7 @@ _push_include(char *path, int isdir) } else { yyerror(_("unable to allocate memory")); } - debug_return_bool(FALSE); + debug_return_bool(false); } istack[idepth].more = NULL; } @@ -3548,10 +3549,10 @@ _push_include(char *path, int isdir) sudoers = path; yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int +static bool pop_include(void) { struct path_list *pl; @@ -3559,14 +3560,14 @@ pop_include(void) debug_decl(pop_include, SUDO_DEBUG_PARSER) if (idepth == 0) - debug_return_bool(FALSE); + debug_return_bool(false); if (!keepopen) fclose(YY_CURRENT_BUFFER->yy_input_file); yy_delete_buffer(YY_CURRENT_BUFFER); /* If we are in an include dir, move to the next file. */ while ((pl = istack[idepth - 1].more) != NULL) { - fp = open_sudoers(pl->path, FALSE, &keepopen); + fp = open_sudoers(pl->path, false, &keepopen); if (fp != NULL) { istack[idepth - 1].more = pl->next; efree(sudoers); @@ -3590,7 +3591,7 @@ pop_include(void) sudolineno = istack[idepth].lineno; keepopen = istack[idepth].keepopen; } - debug_return_bool(TRUE); + debug_return_bool(true); } static char * @@ -3669,11 +3670,11 @@ sudoers_trace_print(const char *msg) static int sudoers_trace_print(const char *msg) { - static int initialized; + static bool initialized; static struct lbuf lbuf; if (!initialized) { - initialized = TRUE; + initialized = true; lbuf_init(&lbuf, NULL, 0, NULL, 0); } diff --git a/plugins/sudoers/toke.h b/plugins/sudoers/toke.h index 9947f80e1..aed6dc379 100644 --- a/plugins/sudoers/toke.h +++ b/plugins/sudoers/toke.h @@ -17,11 +17,11 @@ #ifndef _SUDO_TOKE_H #define _SUDO_TOKE_H -int append(const char *, int); -int fill_args(const char *, int, int); -int fill_cmnd(const char *, int); -int fill_txt(const char *, int, int); -int ipv6_valid(const char *s); +bool append(const char *, int); +bool fill_args(const char *, int, int); +bool fill_cmnd(const char *, int); +bool fill_txt(const char *, int, int); +bool ipv6_valid(const char *s); void yyerror(const char *); #ifndef FLEX_SCANNER diff --git a/plugins/sudoers/toke.l b/plugins/sudoers/toke.l index ffddc6882..ced224876 100644 --- a/plugins/sudoers/toke.l +++ b/plugins/sudoers/toke.l @@ -74,15 +74,16 @@ #include "lbuf.h" extern YYSTYPE yylval; -extern int parse_error; +extern bool parse_error; int sudolineno; int last_token; char *sudoers; -static int continued, prev_state, sawspace; +static bool continued, sawspace; +static int prev_state; -static int _push_include(char *, int); -static int pop_include(void); +static bool _push_include(char *, bool); +static bool pop_include(void); static char *parse_include(char *); static int sudoers_trace_print(const char *msg); @@ -93,8 +94,8 @@ int (*trace_print)(const char *msg) = sudoers_trace_print; return (n); \ } while (0) -#define push_include(_p) (_push_include((_p), FALSE)) -#define push_includedir(_p) (_push_include((_p), TRUE)) +#define push_include(_p) (_push_include((_p), false)) +#define push_includedir(_p) (_push_include((_p), true)) %} HEX16 [0-9A-Fa-f]{1,4} @@ -176,7 +177,7 @@ DEFVAR [a-z_]+ \\[[:blank:]]*\n[[:blank:]]* { /* Line continuation char followed by newline. */ sudolineno++; - continued = TRUE; + continued = true; } \" { @@ -230,7 +231,7 @@ DEFVAR [a-z_]+ LEXTRACE("QUOTEDCHAR "); if (!fill_args(yytext, 2, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } \\[:\\,= \t#] { @@ -238,7 +239,7 @@ DEFVAR [a-z_]+ LEXTRACE("QUOTEDCHAR "); if (!fill_args(yytext + 1, 1, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } [#:\,=\n] { @@ -251,7 +252,7 @@ DEFVAR [a-z_]+ LEXTRACE("ARG "); if (!fill_args(yytext, yyleng, sawspace)) yyterminate(); - sawspace = FALSE; + sawspace = false; } /* a command line arg */ } @@ -588,25 +589,25 @@ sudoedit { } BEGIN INITIAL; sudolineno++; - continued = FALSE; + continued = false; LEXTRACE("\n"); LEXRETURN(COMMENT); } /* return newline */ <*>[[:blank:]]+ { /* throw away space/tabs */ - sawspace = TRUE; /* but remember for fill_args */ + sawspace = true; /* but remember for fill_args */ } <*>\\[[:blank:]]*\n { - sawspace = TRUE; /* remember for fill_args */ + sawspace = true; /* remember for fill_args */ sudolineno++; - continued = TRUE; + continued = true; } /* throw away EOL after \ */ #(-[^\n0-9].*|[^\n0-9-].*)?\n { BEGIN INITIAL; sudolineno++; - continued = FALSE; + continued = false; LEXTRACE("#\n"); LEXRETURN(COMMENT); } /* comment, not uid/gid */ @@ -637,7 +638,7 @@ struct include_stack { char *path; struct path_list *more; /* more files in case of includedir */ int lineno; - int keepopen; + bool keepopen; }; static int @@ -749,7 +750,7 @@ bad: static size_t istacksize, idepth; static struct include_stack *istack; -static int keepopen; +static bool keepopen; void init_lexer(void) @@ -773,16 +774,16 @@ init_lexer(void) istack = NULL; istacksize = idepth = 0; sudolineno = 1; - keepopen = FALSE; - sawspace = FALSE; - continued = FALSE; + keepopen = false; + sawspace = false; + continued = false; prev_state = INITIAL; debug_return; } -static int -_push_include(char *path, int isdir) +static bool +_push_include(char *path, bool isdir) { struct path_list *pl; FILE *fp; @@ -792,32 +793,32 @@ _push_include(char *path, int isdir) if (idepth >= istacksize) { if (idepth > MAX_SUDOERS_DEPTH) { yyerror(_("too many levels of includes")); - debug_return_bool(FALSE); + debug_return_bool(false); } istacksize += SUDOERS_STACK_INCREMENT; istack = (struct include_stack *) realloc(istack, sizeof(*istack) * istacksize); if (istack == NULL) { yyerror(_("unable to allocate memory")); - debug_return_bool(FALSE); + debug_return_bool(false); } } if (isdir) { if (!(path = switch_dir(&istack[idepth], path))) { /* switch_dir() called yyerror() for us */ - debug_return_bool(FALSE); + debug_return_bool(false); } - while ((fp = open_sudoers(path, FALSE, &keepopen)) == NULL) { + while ((fp = open_sudoers(path, false, &keepopen)) == NULL) { /* Unable to open path in includedir, go to next one, if any. */ efree(path); if ((pl = istack[idepth].more) == NULL) - debug_return_bool(FALSE); + debug_return_bool(false); path = pl->path; istack[idepth].more = pl->next; efree(pl); } } else { - if ((fp = open_sudoers(path, TRUE, &keepopen)) == NULL) { + if ((fp = open_sudoers(path, true, &keepopen)) == NULL) { char *errbuf; if (asprintf(&errbuf, _("%s: %s"), path, strerror(errno)) != -1) { yyerror(errbuf); @@ -825,7 +826,7 @@ _push_include(char *path, int isdir) } else { yyerror(_("unable to allocate memory")); } - debug_return_bool(FALSE); + debug_return_bool(false); } istack[idepth].more = NULL; } @@ -839,10 +840,10 @@ _push_include(char *path, int isdir) sudoers = path; yy_switch_to_buffer(yy_create_buffer(fp, YY_BUF_SIZE)); - debug_return_bool(TRUE); + debug_return_bool(true); } -static int +static bool pop_include(void) { struct path_list *pl; @@ -850,14 +851,14 @@ pop_include(void) debug_decl(pop_include, SUDO_DEBUG_PARSER) if (idepth == 0) - debug_return_bool(FALSE); + debug_return_bool(false); if (!keepopen) fclose(YY_CURRENT_BUFFER->yy_input_file); yy_delete_buffer(YY_CURRENT_BUFFER); /* If we are in an include dir, move to the next file. */ while ((pl = istack[idepth - 1].more) != NULL) { - fp = open_sudoers(pl->path, FALSE, &keepopen); + fp = open_sudoers(pl->path, false, &keepopen); if (fp != NULL) { istack[idepth - 1].more = pl->next; efree(sudoers); @@ -881,7 +882,7 @@ pop_include(void) sudolineno = istack[idepth].lineno; keepopen = istack[idepth].keepopen; } - debug_return_bool(TRUE); + debug_return_bool(true); } static char * @@ -960,11 +961,11 @@ sudoers_trace_print(const char *msg) static int sudoers_trace_print(const char *msg) { - static int initialized; + static bool initialized; static struct lbuf lbuf; if (!initialized) { - initialized = TRUE; + initialized = true; lbuf_init(&lbuf, NULL, 0, NULL, 0); } diff --git a/plugins/sudoers/toke_util.c b/plugins/sudoers/toke_util.c index dca7a48fe..330279452 100644 --- a/plugins/sudoers/toke_util.c +++ b/plugins/sudoers/toke_util.c @@ -102,7 +102,7 @@ hexchar(const char *s) debug_return_int(result); } -int +bool fill_txt(const char *src, int len, int olen) { char *dst; @@ -111,7 +111,7 @@ fill_txt(const char *src, int len, int olen) dst = olen ? realloc(yylval.string, olen + len + 1) : malloc(len + 1); if (dst == NULL) { yyerror(_("unable to allocate memory")); - debug_return_bool(FALSE); + debug_return_bool(false); } yylval.string = dst; @@ -135,10 +135,10 @@ fill_txt(const char *src, int len, int olen) } } *dst = '\0'; - debug_return_bool(TRUE); + debug_return_bool(true); } -int +bool append(const char *src, int len) { int olen = 0; @@ -153,7 +153,7 @@ append(const char *src, int len) #define SPECIAL(c) \ ((c) == ',' || (c) == ':' || (c) == '=' || (c) == ' ' || (c) == '\t' || (c) == '#') -int +bool fill_cmnd(const char *src, int len) { char *dst; @@ -165,7 +165,7 @@ fill_cmnd(const char *src, int len) dst = yylval.command.cmnd = (char *) malloc(len + 1); if (yylval.command.cmnd == NULL) { yyerror(_("unable to allocate memory")); - debug_return_bool(FALSE); + debug_return_bool(false); } /* Copy the string and collapse any escaped sudo-specific characters. */ @@ -178,10 +178,10 @@ fill_cmnd(const char *src, int len) *dst = '\0'; yylval.command.args = NULL; - debug_return_bool(TRUE); + debug_return_bool(true); } -int +bool fill_args(const char *s, int len, int addspace) { int new_len; @@ -205,7 +205,7 @@ fill_args(const char *s, int len, int addspace) if (p == NULL) { efree(yylval.command.args); yyerror(_("unable to allocate memory")); - debug_return_bool(FALSE); + debug_return_bool(false); } else yylval.command.args = p; } @@ -216,18 +216,18 @@ fill_args(const char *s, int len, int addspace) *p++ = ' '; if (strlcpy(p, s, arg_size - (p - yylval.command.args)) != len) { yyerror(_("fill_args: buffer overflow")); /* paranoia */ - debug_return_bool(FALSE); + debug_return_bool(false); } arg_len = new_len; - debug_return_bool(TRUE); + debug_return_bool(true); } /* * Check to make sure an IPv6 address does not contain multiple instances * of the string "::". Assumes strlen(s) >= 1. - * Returns TRUE if address is valid else FALSE. + * Returns true if address is valid else false. */ -int +bool ipv6_valid(const char *s) { int nmatch = 0; diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index 0f1fa09dd..4d82fc12d 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -105,12 +105,12 @@ static char *get_args(char *); static char *get_editor(char **); static void get_hostname(void); static char whatnow(void); -static int check_aliases(int, int); -static int check_syntax(char *, int, int); -static int edit_sudoers(struct sudoersfile *, char *, char *, int); -static int install_sudoers(struct sudoersfile *, int); +static int check_aliases(bool, bool); +static int check_syntax(char *, bool, bool); +static bool edit_sudoers(struct sudoersfile *, char *, char *, int); +static bool install_sudoers(struct sudoersfile *, bool); static int print_unused(void *, void *); -static int reparse_sudoers(char *, char *, int, int); +static bool 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); @@ -148,7 +148,8 @@ main(int argc, char *argv[]) { struct sudoersfile *sp; char *args, *editor, *sudoers_path; - int ch, checkonly, quiet, strict, oldperms; + int ch; + bool checkonly, quiet, strict, oldperms; #if defined(SUDO_DEVEL) && defined(__OpenBSD__) extern char *malloc_options; malloc_options = "AFGJPR"; @@ -170,7 +171,7 @@ main(int argc, char *argv[]) /* * Arg handling. */ - checkonly = oldperms = quiet = strict = FALSE; + checkonly = oldperms = quiet = strict = false; sudoers_path = _PATH_SUDOERS; while ((ch = getopt(argc, argv, "Vcf:sq")) != -1) { switch (ch) { @@ -183,7 +184,7 @@ main(int argc, char *argv[]) break; case 'f': sudoers_path = optarg; /* sudoers file path */ - oldperms = TRUE; + oldperms = true; break; case 'h': help(); @@ -222,7 +223,7 @@ main(int argc, char *argv[]) * Parse the existing sudoers file(s) in quiet mode to highlight any * existing errors and to pull in editor and env_editor conf values. */ - if ((yyin = open_sudoers(sudoers_path, TRUE, NULL)) == NULL) { + if ((yyin = open_sudoers(sudoers_path, true, NULL)) == NULL) { error(1, "%s", sudoers_path); } init_parser(sudoers_path, 0); @@ -283,13 +284,13 @@ static char *lineno_editors[] = { /* * Edit each sudoers file. - * Returns TRUE on success, else FALSE. + * Returns true on success, else false. */ -static int +static bool edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) { int tfd; /* sudoers temp file descriptor */ - int modified; /* was the file modified? */ + bool modified; /* was the file modified? */ int ac; /* argument count */ char **av; /* argument vector for run_command */ char *cp; /* scratch char pointer */ @@ -362,14 +363,14 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) /* Find the length of the argument vector */ ac = 3 + (lineno > 0); if (args) { - int wasblank; + bool wasblank; ac++; - for (wasblank = FALSE, cp = args; *cp; cp++) { + for (wasblank = false, cp = args; *cp; cp++) { if (isblank((unsigned char) *cp)) - wasblank = TRUE; + wasblank = true; else if (wasblank) { - wasblank = FALSE; + wasblank = false; ac++; } } @@ -408,21 +409,21 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) if (stat(sp->tpath, &sb) < 0) { warningx(_("unable to stat temporary file (%s), %s unchanged"), sp->tpath, sp->path); - return FALSE; + return false; } if (sb.st_size == 0 && orig_size != 0) { warningx(_("zero length temporary file (%s), %s unchanged"), sp->tpath, sp->path); - sp->modified = TRUE; - return FALSE; + sp->modified = true; + return false; } } else { warningx(_("editor (%s) failed, %s unchanged"), editor, sp->path); - return FALSE; + return false; } /* Set modified bit if use changed the file. */ - modified = TRUE; + modified = true; mtim_get(&sb, &tv); if (orig_size == sb.st_size && timevalcmp(&orig_mtim, &tv, ==)) { /* @@ -431,7 +432,7 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) */ timevalsub(&tv1, &tv2); if (timevalisset(&tv2)) - modified = FALSE; + modified = false; } /* @@ -442,15 +443,15 @@ edit_sudoers(struct sudoersfile *sp, char *editor, char *args, int lineno) else warningx(_("%s unchanged"), sp->tpath); - return TRUE; + return true; } /* * Parse sudoers after editing and re-edit any ones that caused a parse error. - * Returns TRUE on success, else FALSE. + * Returns true on success, else false. */ -static int -reparse_sudoers(char *editor, char *args, int strict, int quiet) +static bool +reparse_sudoers(char *editor, char *args, bool strict, bool quiet) { struct sudoersfile *sp, *last; FILE *fp; @@ -476,14 +477,14 @@ reparse_sudoers(char *editor, char *args, int strict, int quiet) if (yyparse() && !parse_error) { warningx(_("unabled to parse temporary file (%s), unknown error"), sp->tpath); - parse_error = TRUE; + parse_error = true; errorfile = sp->path; } fclose(yyin); if (!parse_error) { if (!update_defaults(SETDEF_GENERIC|SETDEF_HOST|SETDEF_USER) || check_aliases(strict, quiet) != 0) { - parse_error = TRUE; + parse_error = true; errorfile = sp->path; } } @@ -493,7 +494,7 @@ reparse_sudoers(char *editor, char *args, int strict, int quiet) */ if (parse_error) { switch (whatnow()) { - case 'Q' : parse_error = FALSE; /* ignore parse error */ + case 'Q' : parse_error = false; /* ignore parse error */ break; case 'x' : cleanup(0); exit(0); @@ -523,15 +524,15 @@ reparse_sudoers(char *editor, char *args, int strict, int quiet) } } while (parse_error); - return TRUE; + return true; } /* * Set the owner and mode on a sudoers temp file and - * move it into place. Returns TRUE on success, else FALSE. + * move it into place. Returns true on success, else false. */ -static int -install_sudoers(struct sudoersfile *sp, int oldperms) +static bool +install_sudoers(struct sudoersfile *sp, bool oldperms) { struct stat sb; @@ -546,7 +547,7 @@ install_sudoers(struct sudoersfile *sp, int oldperms) if ((sb.st_mode & 0777) != SUDOERS_MODE) (void) chmod(sp->path, SUDOERS_MODE); } - return TRUE; + return true; } /* @@ -569,12 +570,12 @@ install_sudoers(struct sudoersfile *sp, int oldperms) if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) { warning(_("unable to set (uid, gid) of %s to (%u, %u)"), sp->tpath, SUDOERS_UID, SUDOERS_GID); - return FALSE; + return false; } if (chmod(sp->tpath, SUDOERS_MODE) != 0) { warning(_("unable to change mode of %s to 0%o"), sp->tpath, SUDOERS_MODE); - return FALSE; + return false; } } @@ -608,17 +609,17 @@ install_sudoers(struct sudoersfile *sp, int oldperms) (void) unlink(sp->tpath); efree(sp->tpath); sp->tpath = NULL; - return FALSE; + return false; } efree(sp->tpath); sp->tpath = NULL; } else { warning(_("error renaming %s, %s unchanged"), sp->tpath, sp->path); (void) unlink(sp->tpath); - return FALSE; + return false; } } - return TRUE; + return true; } /* STUB */ @@ -636,10 +637,10 @@ init_envtables(void) } /* STUB */ -int +bool user_is_exempt(void) { - return FALSE; + return false; } /* STUB */ @@ -660,7 +661,7 @@ sudo_endspent(void) int group_plugin_query(const char *user, const char *group, const struct passwd *pw) { - return FALSE; + return false; } /* @@ -746,10 +747,10 @@ run_command(char *path, char **argv) } static int -check_syntax(char *sudoers_path, int quiet, int strict) +check_syntax(char *sudoers_path, bool quiet, bool strict) { struct stat sb; - int error; + int rval; if (strcmp(sudoers_path, "-") == 0) { yyin = stdin; @@ -763,14 +764,14 @@ check_syntax(char *sudoers_path, int quiet, int strict) if (yyparse() && !parse_error) { if (!quiet) warningx(_("failed to parse %s file, unknown error"), sudoers_path); - parse_error = TRUE; + parse_error = true; errorfile = sudoers_path; } if (!parse_error && check_aliases(strict, quiet) != 0) { - parse_error = TRUE; + parse_error = true; errorfile = sudoers_path; } - error = parse_error; + rval = parse_error; if (!quiet) { if (parse_error) { if (errorlineno != -1) @@ -785,7 +786,7 @@ check_syntax(char *sudoers_path, int quiet, int strict) /* Check mode and owner in strict mode. */ if (strict && yyin != stdin && fstat(fileno(yyin), &sb) == 0) { if (sb.st_uid != SUDOERS_UID || sb.st_gid != SUDOERS_GID) { - error = TRUE; + rval = 1; if (!quiet) { fprintf(stderr, _("%s: wrong owner (uid, gid) should be (%u, %u)\n"), @@ -793,7 +794,7 @@ check_syntax(char *sudoers_path, int quiet, int strict) } } if ((sb.st_mode & 07777) != SUDOERS_MODE) { - error = TRUE; + rval = 1; if (!quiet) { fprintf(stderr, _("%s: bad permissions, should be mode 0%o\n"), sudoers_path, SUDOERS_MODE); @@ -801,7 +802,7 @@ check_syntax(char *sudoers_path, int quiet, int strict) } } - return error; + return rval; } /* @@ -809,7 +810,7 @@ check_syntax(char *sudoers_path, int quiet, int strict) * any subsequent files #included via a callback from the parser. */ FILE * -open_sudoers(const char *path, int doedit, int *keepopen) +open_sudoers(const char *path, bool doedit, bool *keepopen) { struct sudoersfile *entry; FILE *fp; @@ -850,7 +851,7 @@ open_sudoers(const char *path, int doedit, int *keepopen) } } if (keepopen != NULL) - *keepopen = TRUE; + *keepopen = true; return fp; } @@ -997,18 +998,18 @@ get_hostname(void) } } -static int +static bool alias_remove_recursive(char *name, int type) { struct member *m; struct alias *a; - int rval = TRUE; + bool rval = true; if ((a = alias_find(name, type)) != NULL) { tq_foreach_fwd(&a->members, m) { if (m->type == ALIAS) { if (!alias_remove_recursive(m->name, type)) - rval = FALSE; + rval = false; } } } @@ -1024,13 +1025,13 @@ check_alias(char *name, int type, int strict, int quiet) { struct member *m; struct alias *a; - int error = 0; + int errors = 0; if ((a = alias_find(name, type)) != NULL) { /* check alias contents */ tq_foreach_fwd(&a->members, m) { if (m->type == ALIAS) - error += check_alias(m->name, type, strict, quiet); + errors += check_alias(m->name, type, strict, quiet); } } else { if (!quiet) { @@ -1049,10 +1050,10 @@ check_alias(char *name, int type, int strict, int quiet) type == USERALIAS ? "User" : type == RUNASALIAS ? "Runas" : "Unknown", name); } - error++; + errors++; } - return error; + return errors; } /* @@ -1060,14 +1061,14 @@ check_alias(char *name, int type, int strict, int quiet) * aliases or unused aliases. */ static int -check_aliases(int strict, int quiet) +check_aliases(bool strict, bool quiet) { struct cmndspec *cs; struct member *m, *binding; struct privilege *priv; struct userspec *us; struct defaults *d; - int atype, error = 0; + int atype, errors = 0; alias_freelist = rbcreate(alias_compare); @@ -1076,26 +1077,26 @@ check_aliases(int strict, int quiet) tq_foreach_fwd(&us->users, m) { if (m->type == ALIAS) { alias_seqno++; - error += check_alias(m->name, USERALIAS, strict, quiet); + errors += check_alias(m->name, USERALIAS, strict, quiet); } } tq_foreach_fwd(&us->privileges, priv) { tq_foreach_fwd(&priv->hostlist, m) { if (m->type == ALIAS) { alias_seqno++; - error += check_alias(m->name, HOSTALIAS, strict, quiet); + errors += check_alias(m->name, HOSTALIAS, strict, quiet); } } tq_foreach_fwd(&priv->cmndlist, cs) { tq_foreach_fwd(&cs->runasuserlist, m) { if (m->type == ALIAS) { alias_seqno++; - error += check_alias(m->name, RUNASALIAS, strict, quiet); + errors += check_alias(m->name, RUNASALIAS, strict, quiet); } } if ((m = cs->cmnd)->type == ALIAS) { alias_seqno++; - error += check_alias(m->name, CMNDALIAS, strict, quiet); + errors += check_alias(m->name, CMNDALIAS, strict, quiet); } } } @@ -1107,7 +1108,7 @@ check_aliases(int strict, int quiet) if (m->type == ALIAS) { alias_seqno++; if (!alias_remove_recursive(m->name, USERALIAS)) - error++; + errors++; } } tq_foreach_fwd(&us->privileges, priv) { @@ -1115,7 +1116,7 @@ check_aliases(int strict, int quiet) if (m->type == ALIAS) { alias_seqno++; if (!alias_remove_recursive(m->name, HOSTALIAS)) - error++; + errors++; } } tq_foreach_fwd(&priv->cmndlist, cs) { @@ -1123,13 +1124,13 @@ check_aliases(int strict, int quiet) if (m->type == ALIAS) { alias_seqno++; if (!alias_remove_recursive(m->name, RUNASALIAS)) - error++; + errors++; } } if ((m = cs->cmnd)->type == ALIAS) { alias_seqno++; if (!alias_remove_recursive(m->name, CMNDALIAS)) - error++; + errors++; } } } @@ -1156,7 +1157,7 @@ check_aliases(int strict, int quiet) if (m->type == ALIAS) { alias_seqno++; if (!alias_remove_recursive(m->name, atype)) - error++; + errors++; } } } @@ -1167,7 +1168,7 @@ check_aliases(int strict, int quiet) if (!no_aliases() && !quiet) alias_apply(print_unused, strict ? "Error" : "Warning"); - return strict ? error : 0; + return strict ? errors : 0; } static int diff --git a/src/exec.c b/src/exec.c index e1129100f..959f61299 100644 --- a/src/exec.c +++ b/src/exec.c @@ -132,7 +132,7 @@ static int fork_cmnd(struct command_details *details, int sv[2]) close(signal_pipe[1]); fcntl(sv[1], F_SETFD, FD_CLOEXEC); restore_signals(); - if (exec_setup(details, NULL, -1) == TRUE) { + if (exec_setup(details, NULL, -1) == true) { /* headed for execve() */ sudo_debug_execve(SUDO_DEBUG_INFO, details->command, details->argv, details->envp); @@ -221,8 +221,9 @@ restore_signals(void) int sudo_execve(struct command_details *details, struct command_status *cstat) { - int maxfd, n, nready, sv[2], log_io = FALSE; + int maxfd, n, nready, sv[2]; const char *utmp_user = NULL; + bool log_io = false; fd_set *fdsr, *fdsw; sigaction_t sa; pid_t child; @@ -254,7 +255,7 @@ sudo_execve(struct command_details *details, struct command_status *cstat) * as the io plugin tailqueue will be empty and no I/O logging will occur. */ if (!tq_empty(&io_plugins) || ISSET(details->flags, CD_USE_PTY)) { - log_io = TRUE; + log_io = true; if (ISSET(details->flags, CD_SET_UTMP)) utmp_user = details->utmp_user ? details->utmp_user : user_details.username; sudo_debug_printf(SUDO_DEBUG_INFO, "allocate pty for I/O logging"); @@ -501,7 +502,7 @@ handle_signals(int fd, pid_t child, int log_io, struct command_status *cstat) } else { /* Nothing listening on sv[0], send directly. */ if (signo == SIGALRM) - terminate_child(child, FALSE); + terminate_child(child, false); else if (kill(child, signo) != 0) warning("kill(%d, %d)", (int)child, signo); } diff --git a/src/exec_pty.c b/src/exec_pty.c index 8c2350f4f..f8e59caa2 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -85,15 +85,13 @@ struct io_buffer { int off; /* write position (how much already consumed) */ int rfd; /* reader (producer) */ int wfd; /* writer (consumer) */ - int (*action)(const char *buf, unsigned int len); + bool (*action)(const char *buf, unsigned int len); char buf[16 * 1024]; }; static char slavename[PATH_MAX]; -static int foreground; +static bool foreground, pipeline, tty_initialized; static int io_fds[6] = { -1, -1, -1, -1, -1, -1}; -static int pipeline = FALSE; -static int tty_initialized; static int ttymode = TERM_COOKED; static pid_t ppgrp, child, child_pgrp; static sigset_t ttyblock; @@ -149,118 +147,118 @@ pty_setup(uid_t uid, const char *tty, const char *utmp_user) } /* Call I/O plugin tty input log method. */ -static int +static bool log_ttyin(const char *buf, unsigned int n) { struct plugin_container *plugin; sigset_t omask; - int rval = TRUE; + bool rval = true; debug_decl(log_ttyin, SUDO_DEBUG_EXEC); sigprocmask(SIG_BLOCK, &ttyblock, &omask); tq_foreach_fwd(&io_plugins, plugin) { if (plugin->u.io->log_ttyin) { if (!plugin->u.io->log_ttyin(buf, n)) { - rval = FALSE; + rval = false; break; } } } sigprocmask(SIG_SETMASK, &omask, NULL); - debug_return_int(rval); + debug_return_bool(rval); } /* Call I/O plugin stdin log method. */ -static int +static bool log_stdin(const char *buf, unsigned int n) { struct plugin_container *plugin; sigset_t omask; - int rval = TRUE; + bool rval = true; debug_decl(log_stdin, SUDO_DEBUG_EXEC); sigprocmask(SIG_BLOCK, &ttyblock, &omask); tq_foreach_fwd(&io_plugins, plugin) { if (plugin->u.io->log_stdin) { if (!plugin->u.io->log_stdin(buf, n)) { - rval = FALSE; + rval = false; break; } } } sigprocmask(SIG_SETMASK, &omask, NULL); - debug_return_int(rval); + debug_return_bool(rval); } /* Call I/O plugin tty output log method. */ -static int +static bool log_ttyout(const char *buf, unsigned int n) { struct plugin_container *plugin; sigset_t omask; - int rval = TRUE; + bool rval = true; debug_decl(log_ttyout, SUDO_DEBUG_EXEC); sigprocmask(SIG_BLOCK, &ttyblock, &omask); tq_foreach_fwd(&io_plugins, plugin) { if (plugin->u.io->log_ttyout) { if (!plugin->u.io->log_ttyout(buf, n)) { - rval = FALSE; + rval = false; break; } } } sigprocmask(SIG_SETMASK, &omask, NULL); - debug_return_int(rval); + debug_return_bool(rval); } /* Call I/O plugin stdout log method. */ -static int +static bool log_stdout(const char *buf, unsigned int n) { struct plugin_container *plugin; sigset_t omask; - int rval = TRUE; + bool rval = true; debug_decl(log_stdout, SUDO_DEBUG_EXEC); sigprocmask(SIG_BLOCK, &ttyblock, &omask); tq_foreach_fwd(&io_plugins, plugin) { if (plugin->u.io->log_stdout) { if (!plugin->u.io->log_stdout(buf, n)) { - rval = FALSE; + rval = false; break; } } } sigprocmask(SIG_SETMASK, &omask, NULL); - debug_return_int(rval); + debug_return_bool(rval); } /* Call I/O plugin stderr log method. */ -static int +static bool log_stderr(const char *buf, unsigned int n) { struct plugin_container *plugin; sigset_t omask; - int rval = TRUE; + bool rval = true; debug_decl(log_stderr, SUDO_DEBUG_EXEC); sigprocmask(SIG_BLOCK, &ttyblock, &omask); tq_foreach_fwd(&io_plugins, plugin) { if (plugin->u.io->log_stderr) { if (!plugin->u.io->log_stderr(buf, n)) { - rval = FALSE; + rval = false; break; } } } sigprocmask(SIG_SETMASK, &omask, NULL); - debug_return_int(rval); + debug_return_bool(rval); } /* @@ -277,7 +275,7 @@ check_foreground(void) foreground = tcgetpgrp(io_fds[SFD_USERTTY]) == ppgrp; if (foreground && !tty_initialized) { if (term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) { - tty_initialized = 1; + tty_initialized = true; sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]); } } @@ -372,7 +370,7 @@ suspend_parent(int signo) * Kill child with increasing urgency. */ void -terminate_child(pid_t pid, int use_pgrp) +terminate_child(pid_t pid, bool use_pgrp) { debug_decl(terminate_child, SUDO_DEBUG_EXEC); @@ -401,7 +399,7 @@ terminate_child(pid_t pid, int use_pgrp) } static struct io_buffer * -io_buf_new(int rfd, int wfd, int (*action)(const char *, unsigned int), +io_buf_new(int rfd, int wfd, bool (*action)(const char *, unsigned int), struct io_buffer *head) { struct io_buffer *iob; @@ -453,7 +451,7 @@ perform_io(fd_set *fdsr, fd_set *fdsw, struct command_status *cstat) break; default: if (!iob->action(iob->buf + iob->len, n)) - terminate_child(child, TRUE); + terminate_child(child, true); iob->len += n; break; } @@ -554,7 +552,7 @@ fork_pty(struct command_details *details, int sv[], int *maxfd) */ memset(io_pipe, 0, sizeof(io_pipe)); if (io_fds[SFD_STDIN] == -1 || !isatty(STDIN_FILENO)) { - pipeline = TRUE; + pipeline = true; if (pipe(io_pipe[STDIN_FILENO]) != 0) error(1, _("unable to create pipe")); iobufs = io_buf_new(STDIN_FILENO, io_pipe[STDIN_FILENO][1], @@ -562,7 +560,7 @@ fork_pty(struct command_details *details, int sv[], int *maxfd) io_fds[SFD_STDIN] = io_pipe[STDIN_FILENO][0]; } if (io_fds[SFD_STDOUT] == -1 || !isatty(STDOUT_FILENO)) { - pipeline = TRUE; + pipeline = true; if (pipe(io_pipe[STDOUT_FILENO]) != 0) error(1, _("unable to create pipe")); iobufs = io_buf_new(io_pipe[STDOUT_FILENO][0], STDOUT_FILENO, @@ -585,7 +583,7 @@ fork_pty(struct command_details *details, int sv[], int *maxfd) if (foreground) { /* Copy terminal attrs from user tty -> pty slave. */ if (term_copy(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE])) { - tty_initialized = 1; + tty_initialized = true; sync_ttysize(io_fds[SFD_USERTTY], io_fds[SFD_SLAVE]); } @@ -611,7 +609,7 @@ fork_pty(struct command_details *details, int sv[], int *maxfd) close(signal_pipe[0]); close(signal_pipe[1]); fcntl(sv[1], F_SETFD, FD_CLOEXEC); - if (exec_setup(details, slavename, io_fds[SFD_SLAVE]) == TRUE) { + if (exec_setup(details, slavename, io_fds[SFD_SLAVE]) == true) { /* Close the other end of the stdin/stdout/stderr pipes and exec. */ if (io_pipe[STDIN_FILENO][1]) close(io_pipe[STDIN_FILENO][1]); @@ -743,7 +741,7 @@ deliver_signal(pid_t pid, int signo) sudo_debug_printf(SUDO_DEBUG_INFO, "received signal %d from parent", signo); switch (signo) { case SIGALRM: - terminate_child(pid, TRUE); + terminate_child(pid, true); break; case SIGCONT_FG: /* Continue in foreground, grant it controlling tty. */ @@ -800,12 +798,13 @@ send_status(int fd, struct command_status *cstat) * Wait for child status after receiving SIGCHLD. * If the child was stopped, the status is send back to the parent. * Otherwise, cstat is filled in but not sent. - * Returns TRUE if child is still alive, else FALSE. + * Returns true if child is still alive, else false. */ -static int +static bool handle_sigchld(int backchannel, struct command_status *cstat) { - int status, alive = TRUE; + bool alive = true; + int status; pid_t pid; debug_decl(handle_sigchld, SUDO_DEBUG_EXEC); @@ -834,9 +833,9 @@ handle_sigchld(int backchannel, struct command_status *cstat) } } if (!WIFSTOPPED(status)) - alive = FALSE; + alive = false; } - debug_return_int(alive); + debug_return_bool(alive); } /* @@ -854,7 +853,7 @@ exec_monitor(struct command_details *details, int backchannel) fd_set *fdsr; sigaction_t sa; int errpipe[2], maxfd, n, status; - int alive = TRUE; + bool alive = true; unsigned char signo; debug_decl(exec_monitor, SUDO_DEBUG_EXEC); @@ -916,7 +915,7 @@ exec_monitor(struct command_details *details, int backchannel) * when it needs access to the controlling tty. */ if (pipeline) - foreground = 0; + foreground = false; /* Start command and wait for it to stop or exit */ if (pipe(errpipe) == -1) diff --git a/src/load_plugins.c b/src/load_plugins.c index 4911aee07..5fb677b74 100644 --- a/src/load_plugins.c +++ b/src/load_plugins.c @@ -66,7 +66,7 @@ const char *debug_flags; struct sudo_conf_table { const char *name; unsigned int namelen; - int (*setter)(const char *entry, void *data); + bool (*setter)(const char *entry, void *data); }; struct sudo_conf_paths { @@ -75,9 +75,9 @@ struct sudo_conf_paths { const char **pval; }; -static int set_debug(const char *entry, void *data); -static int set_path(const char *entry, void *data); -static int set_plugin(const char *entry, void *data); +static bool set_debug(const char *entry, void *data); +static bool set_path(const char *entry, void *data); +static bool set_plugin(const char *entry, void *data); static struct plugin_info_list plugin_info_list; @@ -99,7 +99,7 @@ static struct sudo_conf_paths sudo_conf_paths[] = { /* * "Debug progname debug_file debug_flags" */ -static int +static bool set_debug(const char *entry, void *data) { size_t filelen, proglen; @@ -113,14 +113,14 @@ set_debug(const char *entry, void *data) proglen = strlen(progname); if (strncmp(entry, progname, proglen) != 0 || !isblank((unsigned char)entry[proglen])) - return FALSE; + return false; entry += proglen + 1; while (isblank((unsigned char)*entry)) entry++; debug_flags = strpbrk(entry, " \t"); if (debug_flags == NULL) - return FALSE; + return false; filelen = (size_t)(debug_flags - entry); while (isblank((unsigned char)*debug_flags)) debug_flags++; @@ -131,10 +131,10 @@ set_debug(const char *entry, void *data) sudo_debug_init(debug_file, debug_flags); efree(debug_file); - return TRUE; + return true; } -static int +static bool set_path(const char *entry, void *data) { const char *name, *path; @@ -144,7 +144,7 @@ set_path(const char *entry, void *data) name = entry; path = strpbrk(entry, " \t"); if (path == NULL) - return FALSE; + return false; while (isblank((unsigned char)*path)) path++; @@ -157,10 +157,10 @@ set_path(const char *entry, void *data) } } - return TRUE; + return true; } -static int +static bool set_plugin(const char *entry, void *data) { struct plugin_info_list *pil = data; @@ -172,7 +172,7 @@ set_plugin(const char *entry, void *data) name = entry; path = strpbrk(entry, " \t"); if (path == NULL) - return FALSE; + return false; namelen = (size_t)(path - name); while (isblank((unsigned char)*path)) path++; @@ -184,7 +184,7 @@ set_plugin(const char *entry, void *data) info->next = NULL; tq_append(pil, info); - return TRUE; + return true; } /* @@ -243,7 +243,7 @@ done: /* * Load the plugins listed in sudo.conf. */ -int +bool sudo_load_plugins(struct plugin_container *policy_plugin, struct plugin_container_list *io_plugins) { @@ -253,7 +253,7 @@ sudo_load_plugins(struct plugin_container *policy_plugin, struct stat sb; void *handle; char path[PATH_MAX]; - int rval = FALSE; + bool rval = false; /* Walk plugin list. */ tq_foreach_fwd(&plugin_info_list, info) { @@ -336,7 +336,7 @@ sudo_load_plugins(struct plugin_container *policy_plugin, goto done; } - rval = TRUE; + rval = true; done: return rval; diff --git a/src/sudo.c b/src/sudo.c index 0d343d8eb..b0b81d5b0 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -223,7 +223,7 @@ main(int argc, char *argv[], char *envp[]) /* Open policy plugin. */ ok = policy_open(&policy_plugin, settings, user_info, envp); - if (ok != TRUE) { + if (ok != 1) { if (ok == -2) usage(1); else @@ -236,14 +236,14 @@ main(int argc, char *argv[], char *envp[]) tq_foreach_fwd(&io_plugins, plugin) { ok = iolog_open(plugin, settings, user_info, NULL, nargc, nargv, envp); - if (ok == TRUE) + if (ok == 1) iolog_show_version(plugin, !user_details.uid); } break; case MODE_VALIDATE: case MODE_VALIDATE|MODE_INVALIDATE: ok = policy_validate(&policy_plugin); - exit(ok != TRUE); + exit(ok != 1); case MODE_KILL: case MODE_INVALIDATE: policy_invalidate(&policy_plugin, sudo_mode == MODE_KILL); @@ -255,13 +255,13 @@ main(int argc, char *argv[], char *envp[]) case MODE_LIST|MODE_INVALIDATE: ok = policy_list(&policy_plugin, nargc, nargv, ISSET(sudo_mode, MODE_LONG_LIST), list_user); - exit(ok != TRUE); + exit(ok != 1); case MODE_EDIT: case MODE_RUN: ok = policy_check(&policy_plugin, nargc, nargv, env_add, &command_info, &argv_out, &user_env_out); sudo_debug_printf(SUDO_DEBUG_INFO, "policy plugin returns %d", ok); - if (ok != TRUE) { + if (ok != 1) { if (ok == -2) usage(1); exit(1); /* plugin printed error message */ @@ -272,9 +272,9 @@ main(int argc, char *argv[], char *envp[]) ok = iolog_open(plugin, settings, user_info, command_info, nargc, nargv, envp); switch (ok) { - case TRUE: + case 1: break; - case FALSE: + case 0: /* I/O plugin asked to be disabled, remove from list. */ tq_remove(&io_plugins, plugin); break; @@ -557,7 +557,7 @@ command_info_to_details(char * const info[], struct command_details *details) break; } if (strncmp("noexec=", info[i], sizeof("noexec=") - 1) == 0) { - if (atobool(info[i] + sizeof("noexec=") - 1) == TRUE) + if (atobool(info[i] + sizeof("noexec=") - 1) == true) SET(details->flags, CD_NOEXEC); break; } @@ -571,7 +571,7 @@ command_info_to_details(char * const info[], struct command_details *details) break; case 'p': if (strncmp("preserve_groups=", info[i], sizeof("preserve_groups=") - 1) == 0) { - if (atobool(info[i] + sizeof("preserve_groups=") - 1) == TRUE) + if (atobool(info[i] + sizeof("preserve_groups=") - 1) == true) SET(details->flags, CD_PRESERVE_GROUPS); break; } @@ -665,12 +665,12 @@ command_info_to_details(char * const info[], struct command_details *details) SET_STRING("selinux_role=", selinux_role) SET_STRING("selinux_type=", selinux_type) if (strncmp("set_utmp=", info[i], sizeof("set_utmp=") - 1) == 0) { - if (atobool(info[i] + sizeof("set_utmp=") - 1) == TRUE) + if (atobool(info[i] + sizeof("set_utmp=") - 1) == true) SET(details->flags, CD_SET_UTMP); break; } if (strncmp("sudoedit=", info[i], sizeof("sudoedit=") - 1) == 0) { - if (atobool(info[i] + sizeof("sudoedit=") - 1) == TRUE) + if (atobool(info[i] + sizeof("sudoedit=") - 1) == true) SET(details->flags, CD_SUDOEDIT); break; } @@ -707,7 +707,7 @@ command_info_to_details(char * const info[], struct command_details *details) break; } if (strncmp("use_pty=", info[i], sizeof("use_pty=") - 1) == 0) { - if (atobool(info[i] + sizeof("use_pty=") - 1) == TRUE) + if (atobool(info[i] + sizeof("use_pty=") - 1) == true) SET(details->flags, CD_USE_PTY); break; } @@ -906,12 +906,12 @@ disable_execute(struct command_details *details) /* * Setup the execution environment immediately prior to the call to execve() - * Returns TRUE on success and FALSE on failure. + * Returns true on success and false on failure. */ -int +bool exec_setup(struct command_details *details, const char *ptyname, int ptyfd) { - int rval = FALSE; + bool rval = false; struct passwd *pw; debug_decl(exec_setup, SUDO_DEBUG_EXEC) @@ -927,7 +927,7 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd) * Call policy plugin's session init before other setup occurs. * The session init code is expected to print an error as needed. */ - if (policy_init_session(&policy_plugin, pw) != TRUE) + if (policy_init_session(&policy_plugin, pw) != true) goto done; #ifdef HAVE_SELINUX @@ -1063,7 +1063,7 @@ exec_setup(struct command_details *details, const char *ptyname, int ptyfd) } #endif - rval = TRUE; + rval = true; done: debug_return_bool(rval); @@ -1160,7 +1160,7 @@ policy_list(struct plugin_container *plugin, int argc, char * const argv[], if (plugin->u.policy->list == NULL) { warningx(_("policy plugin %s does not support listing privileges"), plugin->name); - debug_return_bool(FALSE); + debug_return_bool(false); } debug_return_bool(plugin->u.policy->list(argc, argv, verbose, list_user)); } @@ -1172,7 +1172,7 @@ policy_validate(struct plugin_container *plugin) if (plugin->u.policy->validate == NULL) { warningx(_("policy plugin %s does not support the -v option"), plugin->name); - debug_return_bool(FALSE); + debug_return_bool(false); } debug_return_bool(plugin->u.policy->validate()); } @@ -1195,7 +1195,7 @@ policy_init_session(struct plugin_container *plugin, struct passwd *pwd) debug_decl(policy_init_session, SUDO_DEBUG_PCOMM) if (plugin->u.policy->init_session) debug_return_bool(plugin->u.policy->init_session(pwd)); - debug_return_bool(TRUE); + debug_return_bool(true); } static int diff --git a/src/sudo.h b/src/sudo.h index 0892a7d94..f0a604620 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -26,6 +26,11 @@ #include #include +#ifdef HAVE_STDBOOL_H +# include +#else +# include "compat/stdbool.h" +#endif /* HAVE_STDBOOL_H */ #include "missing.h" #include "alloc.h" @@ -41,14 +46,6 @@ # define ROOT_UID 0 #endif -/* - * Pseudo-boolean values - */ -#undef TRUE -#define TRUE 1 -#undef FALSE -#define FALSE 0 - /* * Various modes sudo can be in (based on arguments) in hex */ @@ -187,7 +184,7 @@ int term_restore(int, int); char *fmt_string(const char *var, const char *value); /* atobool.c */ -int atobool(const char *str); +bool atobool(const char *str); /* parse_args.c */ int parse_args(int argc, char **argv, int *nargc, char ***nargv, @@ -201,7 +198,7 @@ int get_pty(int *master, int *slave, char *name, size_t namesz, uid_t uid); void get_ttysize(int *rowp, int *colp); /* sudo.c */ -int exec_setup(struct command_details *details, const char *ptyname, int ptyfd); +bool exec_setup(struct command_details *details, const char *ptyname, int ptyfd); int run_command(struct command_details *details); extern int debug_level; extern const char *list_user, *runas_user, *runas_group; diff --git a/src/sudo_exec.h b/src/sudo_exec.h index 744dd6a3d..afbcb7c65 100644 --- a/src/sudo_exec.h +++ b/src/sudo_exec.h @@ -39,12 +39,12 @@ void fd_set_iobs(fd_set *fdsr, fd_set *fdsw); void handler(int s); void pty_close(struct command_status *cstat); void pty_setup(uid_t uid, const char *tty, const char *utmp_user); -void terminate_child(pid_t pid, int use_pgrp); +void terminate_child(pid_t pid, bool use_pgrp); extern int signal_pipe[2]; /* utmp.c */ -int utmp_login(const char *from_line, const char *to_line, int ttyfd, +bool utmp_login(const char *from_line, const char *to_line, int ttyfd, const char *user); -int utmp_logout(const char *line, int status); +bool utmp_logout(const char *line, int status); #endif /* _SUDO_EXEC_H */ diff --git a/src/sudo_plugin_int.h b/src/sudo_plugin_int.h index c7ab89e59..364bd0c44 100644 --- a/src/sudo_plugin_int.h +++ b/src/sudo_plugin_int.h @@ -79,7 +79,7 @@ int sudo_conversation(int num_msgs, const struct sudo_conv_message msgs[], int _sudo_printf(int msg_type, const char *fmt, ...); void sudo_read_conf(void); -int sudo_load_plugins(struct plugin_container *policy_plugin, +bool sudo_load_plugins(struct plugin_container *policy_plugin, struct plugin_container_list *io_plugins); #endif /* _SUDO_PLUGIN_INT_H */ diff --git a/src/utmp.c b/src/utmp.c index 7650d3545..7f8113bd5 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -181,12 +181,12 @@ utmp_fill(const char *line, const char *user, sudo_utmp_t *ut_old, * Legacy: sparse file indexed by ttyslot() * sizeof(struct utmp) */ #if defined(HAVE_GETUTXID) || defined(HAVE_GETUTID) -int +bool utmp_login(const char *from_line, const char *to_line, int ttyfd, const char *user) { sudo_utmp_t utbuf, *ut_old = NULL; - int rval = FALSE; + bool rval = false; debug_decl(utmp_login, SUDO_DEBUG_UTMP) /* Strip off /dev/ prefix from line as needed. */ @@ -204,16 +204,16 @@ utmp_login(const char *from_line, const char *to_line, int ttyfd, } utmp_fill(to_line, user, ut_old, &utbuf); if (pututxline(&utbuf) != NULL) - rval = TRUE; + rval = true; endutxent(); - debug_return_int(rval); + debug_return_bool(rval); } -int +bool utmp_logout(const char *line, int status) { - int rval = FALSE; + bool rval = false; sudo_utmp_t *ut, utbuf; debug_decl(utmp_logout, SUDO_DEBUG_UTMP) @@ -234,9 +234,9 @@ utmp_logout(const char *line, int status) # endif utmp_settime(ut); if (pututxline(ut) != NULL) - rval = TRUE; + rval = true; } - debug_return_int(rval); + debug_return_bool(rval); } #else /* !HAVE_GETUTXID && !HAVE_GETUTID */ @@ -287,12 +287,13 @@ utmp_slot(const char *line, int ttyfd) } # endif /* HAVE_GETTTYENT */ -int +bool utmp_login(const char *from_line, const char *to_line, int ttyfd, const char *user) { sudo_utmp_t utbuf, *ut_old = NULL; - int slot, rval = FALSE; + bool rval = false; + int slot; FILE *fp; debug_decl(utmp_login, SUDO_DEBUG_UTMP) @@ -328,19 +329,19 @@ utmp_login(const char *from_line, const char *to_line, int ttyfd, utmp_fill(to_line, user, ut_old, &utbuf); if (fseek(fp, slot * (long)sizeof(utbuf), SEEK_SET) == 0) { if (fwrite(&utbuf, sizeof(utbuf), 1, fp) == 1) - rval = TRUE; + rval = true; } fclose(fp); done: - debug_return_int(rval); + debug_return_bool(rval); } -int +bool utmp_logout(const char *line, int status) { sudo_utmp_t utbuf; - int rval = FALSE; + bool rval = false; FILE *fp; debug_decl(utmp_logout, SUDO_DEBUG_UTMP) @@ -361,13 +362,13 @@ utmp_logout(const char *line, int status) /* Back up and overwrite record. */ if (fseek(fp, 0L - (long)sizeof(utbuf), SEEK_CUR) == 0) { if (fwrite(&utbuf, sizeof(utbuf), 1, fp) == 1) - rval = TRUE; + rval = true; } break; } } fclose(fp); - debug_return_int(rval); + debug_return_bool(rval); } #endif /* HAVE_GETUTXID || HAVE_GETUTID */ -- 2.40.0