c\bcv\bvt\bts\bsu\bud\bdo\boe\ber\brs\bs can be used to convert a policy file in _\bs_\bu_\bd_\bo_\be_\br_\bs format to
other formats. The default output format is JSON.
- If no _\bs_\bu_\bd_\bo_\be_\br_\bs_\b__\bf_\bi_\bl_\be is specified, or if it is `-', the policy is read from
- the standard input. By default, the result is written to the standard
- output.
+ If _\bs_\bu_\bd_\bo_\be_\br_\bs_\b__\bf_\bi_\bl_\be is `-', the policy is read from the standard input. If
+ no _\bs_\bu_\bd_\bo_\be_\br_\bs_\b__\bf_\bi_\bl_\be is specified, _\b/_\be_\bt_\bc_\b/_\bs_\bu_\bd_\bo_\be_\br_\bs will be used. By default, the
+ result is written to the standard output.
The options are as follows:
format to other formats.
The default output format is JSON.
.PP
-If no
+If
\fIsudoers_file\fR
-is specified, or if it is
+is
\(oq-\(cq,
the policy is read from the standard input.
+If no
+\fIsudoers_file\fR
+is specified,
+\fI@sysconfdir@/sudoers\fR
+will be used.
By default, the result is written to the standard output.
.PP
The options are as follows:
format to other formats.
The default output format is JSON.
.Pp
-If no
+If
.Ar sudoers_file
-is specified, or if it is
+is
.Ql - ,
the policy is read from the standard input.
+If no
+.Ar sudoers_file
+is specified,
+.Pa @sysconfdir@/sudoers
+will be used.
By default, the result is written to the standard output.
.Pp
The options are as follows:
#endif /* HAVE_GETOPT_LONG */
extern bool convert_sudoers_json(const char *, const char *);
+extern void parse_sudoers_options(void);
extern void get_hostname(void);
/*
main(int argc, char *argv[])
{
int ch, exitcode = EXIT_FAILURE;
- const char *input_file = "-", *output_file = "-";
+ const char *input_file = NULL;
+ const char *output_file = "-";
const char *output_format = "JSON";
debug_decl(main, SUDOERS_DEBUG_MAIN)
if (!sudoers_debug_register(getprogname(), sudo_conf_debug_files(getprogname())))
goto done;
+ /* Parse sudoers plugin options, if any. */
+ parse_sudoers_options();
+
/*
* Arg handling.
*/
argc -= optind;
argv += optind;
- /* Input file (defaults to stdin). */
+ /* Input file (defaults to /etc/sudoers). */
if (argc > 0) {
/* XXX - allow multiple input files? */
if (argc > 1)
usage(1);
input_file = argv[0];
+ } else {
+ input_file = sudoers_file;
}
if (strcmp(input_file, "-") != 0) {
debug_return;
}
+
+/*
+ * Parse sudoers plugin options.
+ * May set sudoers_file, sudoers_uid, sudoers_gid or sudoers_mode globals.
+ */
+void
+parse_sudoers_options(void)
+{
+ struct plugin_info_list *plugins;
+ debug_decl(parse_sudoers_options, SUDOERS_DEBUG_UTIL)
+
+ plugins = sudo_conf_plugins();
+ if (plugins) {
+ struct plugin_info *info;
+
+ TAILQ_FOREACH(info, plugins, entries) {
+ if (strcmp(info->symbol_name, "sudoers_policy") == 0)
+ break;
+ }
+ if (info != NULL && info->options != NULL) {
+ char * const *cur;
+
+#define MATCHES(s, v) \
+ (strncmp((s), (v), sizeof(v) - 1) == 0 && (s)[sizeof(v) - 1] != '\0')
+
+ for (cur = info->options; *cur != NULL; cur++) {
+ const char *errstr, *p;
+ id_t id;
+
+ if (MATCHES(*cur, "sudoers_file=")) {
+ sudoers_file = *cur + sizeof("sudoers_file=") - 1;
+ continue;
+ }
+ if (MATCHES(*cur, "sudoers_uid=")) {
+ p = *cur + sizeof("sudoers_uid=") - 1;
+ id = sudo_strtoid(p, NULL, NULL, &errstr);
+ if (errstr == NULL)
+ sudoers_uid = (uid_t) id;
+ continue;
+ }
+ if (MATCHES(*cur, "sudoers_gid=")) {
+ p = *cur + sizeof("sudoers_gid=") - 1;
+ id = sudo_strtoid(p, NULL, NULL, &errstr);
+ if (errstr == NULL)
+ sudoers_gid = (gid_t) id;
+ continue;
+ }
+ if (MATCHES(*cur, "sudoers_mode=")) {
+ p = *cur + sizeof("sudoers_mode=") - 1;
+ id = (id_t) sudo_strtomode(p, &errstr);
+ if (errstr == NULL)
+ sudoers_mode = (mode_t) id;
+ continue;
+ }
+ }
+#undef MATCHES
+ }
+ }
+ debug_return;
+}
static int print_unused(void *, void *);
static bool reparse_sudoers(char *, int, char **, bool, bool);
static int run_command(char *, char **);
-static void parse_sudoers_options(void);
static void setup_signals(void);
static void help(void) __attribute__((__noreturn__));
static void usage(int);
extern void get_hostname(void);
extern void sudoersrestart(FILE *);
+extern void parse_sudoers_options(void);
/*
* Globals
return 0;
}
-static void
-parse_sudoers_options(void)
-{
- struct plugin_info_list *plugins;
- debug_decl(parse_sudoers_options, SUDOERS_DEBUG_UTIL)
-
- plugins = sudo_conf_plugins();
- if (plugins) {
- struct plugin_info *info;
-
- TAILQ_FOREACH(info, plugins, entries) {
- if (strcmp(info->symbol_name, "sudoers_policy") == 0)
- break;
- }
- if (info != NULL && info->options != NULL) {
- char * const *cur;
-
-#define MATCHES(s, v) \
- (strncmp((s), (v), sizeof(v) - 1) == 0 && (s)[sizeof(v) - 1] != '\0')
-
- for (cur = info->options; *cur != NULL; cur++) {
- const char *errstr, *p;
- id_t id;
-
- if (MATCHES(*cur, "sudoers_file=")) {
- sudoers_file = *cur + sizeof("sudoers_file=") - 1;
- continue;
- }
- if (MATCHES(*cur, "sudoers_uid=")) {
- p = *cur + sizeof("sudoers_uid=") - 1;
- id = sudo_strtoid(p, NULL, NULL, &errstr);
- if (errstr == NULL)
- sudoers_uid = (uid_t) id;
- continue;
- }
- if (MATCHES(*cur, "sudoers_gid=")) {
- p = *cur + sizeof("sudoers_gid=") - 1;
- id = sudo_strtoid(p, NULL, NULL, &errstr);
- if (errstr == NULL)
- sudoers_gid = (gid_t) id;
- continue;
- }
- if (MATCHES(*cur, "sudoers_mode=")) {
- p = *cur + sizeof("sudoers_mode=") - 1;
- id = (id_t) sudo_strtomode(p, &errstr);
- if (errstr == NULL)
- sudoers_mode = (mode_t) id;
- continue;
- }
- }
-#undef MATCHES
- }
- }
- debug_return;
-}
-
/*
* Unlink any sudoers temp files that remain.
*/