#define SUDO_DEBUG_UTMP (14<<6) /* utmp file ops */
#define SUDO_DEBUG_ALL 0xffff0000 /* all subsystems */
+/* Error return for sudo_debug_register(). */
+#define SUDO_DEBUG_INSTANCE_ERROR -2
+
/* Initializer for instance index to indicate that debugging is not setup. */
#define SUDO_DEBUG_INSTANCE_INITIALIZER -1
* If subsystem names are specified they override the default values.
* NOTE: subsystems must not be freed by caller unless deregistered.
* Sets the active instance to the newly registered instance.
- * Returns instance index on success or SUDO_DEBUG_INSTANCE_INITIALIZER
- * on failure.
+ * Returns instance index on success, SUDO_DEBUG_INSTANCE_INITIALIZER
+ * if no debug files are specified and SUDO_DEBUG_INSTANCE_ERROR
+ * on error.
*/
int
sudo_debug_register_v1(const char *program, const char *const subsystems[],
subsystems = sudo_debug_default_subsystems;
} else if (ids == NULL) {
/* If subsystems are specified we must have ids[] too. */
- return SUDO_DEBUG_INSTANCE_INITIALIZER;
+ return SUDO_DEBUG_INSTANCE_ERROR;
}
/* Search for existing instance. */
if (idx == SUDO_DEBUG_INSTANCE_MAX) {
/* XXX - realloc? */
sudo_warnx_nodebug("too many debug instances (max %d)", SUDO_DEBUG_INSTANCE_MAX);
- return SUDO_DEBUG_INSTANCE_INITIALIZER;
+ return SUDO_DEBUG_INSTANCE_ERROR;
}
if (idx != sudo_debug_last_instance + 1 && idx != free_idx) {
sudo_warnx_nodebug("%s: instance number mismatch: expected %d or %d, got %d", __func__, sudo_debug_last_instance + 1, free_idx, idx);
- return SUDO_DEBUG_INSTANCE_INITIALIZER;
+ return SUDO_DEBUG_INSTANCE_ERROR;
}
if ((instance = malloc(sizeof(*instance))) == NULL)
- return SUDO_DEBUG_INSTANCE_INITIALIZER;
+ return SUDO_DEBUG_INSTANCE_ERROR;
if ((instance->program = strdup(program)) == NULL) {
free(instance);
- return SUDO_DEBUG_INSTANCE_INITIALIZER;
+ return SUDO_DEBUG_INSTANCE_ERROR;
}
instance->subsystems = subsystems;
instance->subsystem_ids = ids;
continue;
}
}
- sudoers_debug_register(plugin_path, &debug_files);
+ if (!sudoers_debug_register(plugin_path, &debug_files)) {
+ ret = -1;
+ goto done;
+ }
/*
* Pull iolog settings out of command_info.
continue;
}
}
- sudoers_debug_register(plugin_path, &debug_files);
+ if (!sudoers_debug_register(plugin_path, &debug_files))
+ debug_return_int(-1);
/* Call the sudoers init function. */
info.settings = settings;
/* sudoers_debug.c */
bool sudoers_debug_parse_flags(struct sudo_conf_debug_file_list *debug_files, const char *entry);
-void sudoers_debug_register(const char *plugin_path, struct sudo_conf_debug_file_list *debug_files);
+bool sudoers_debug_register(const char *plugin_path, struct sudo_conf_debug_file_list *debug_files);
void sudoers_debug_deregister(void);
/* policy.c */
* debug subsystem, freeing the debug list when done.
* Sets the active debug instance as a side effect.
*/
-void
+bool
sudoers_debug_register(const char *program,
struct sudo_conf_debug_file_list *debug_files)
{
if (program != NULL) {
sudoers_debug_instance = sudo_debug_register(program,
sudoers_subsystem_names, sudoers_subsystem_ids, debug_files);
+ if (sudoers_debug_instance == SUDO_DEBUG_INSTANCE_ERROR)
+ return false;
}
TAILQ_FOREACH_SAFE(debug_file, debug_files, entries, debug_next) {
TAILQ_REMOVE(debug_files, debug_file, entries);
free(debug_file);
}
}
+ return true;
}
/*
exit(EXIT_FAILURE);
/* Initialize the debug subsystem. */
- sudoers_debug_register(getprogname(), sudo_conf_debug_files(getprogname()));
+ if (!sudoers_debug_register(getprogname(), sudo_conf_debug_files(getprogname())))
+ exit(EXIT_FAILURE);
/* Parse sudoers plugin options, if any. */
parse_sudoers_options();
exit(EXIT_FAILURE);
sudo_debug_instance = sudo_debug_register(getprogname(),
NULL, NULL, sudo_conf_debug_files(getprogname()));
+ if (sudo_debug_instance == SUDO_DEBUG_INSTANCE_ERROR)
+ exit(EXIT_FAILURE);
/* Make sure we are setuid root. */
sudo_check_suid(argc > 0 ? argv[0] : "sudo");