mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-31 14:25:15 +00:00
Use stdbool.h instead of rolling our own TRUE/FALSE macros.
This commit is contained in:
@@ -30,6 +30,11 @@
|
||||
# include <stdlib.h>
|
||||
# endif
|
||||
#endif /* STDC_HEADERS */
|
||||
#ifdef HAVE_STDBOOL_H
|
||||
# include <stdbool.h>
|
||||
#else
|
||||
# include "compat/stdbool.h"
|
||||
#endif /* HAVE_STDBOOL_H */
|
||||
#ifdef HAVE_STRING_H
|
||||
# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
|
||||
# include <memory.h>
|
||||
@@ -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 = {
|
||||
|
Reference in New Issue
Block a user