From 89d64eee9d7a01c92b94f382b6783fb82bb1c417 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 14 May 2022 13:39:31 +0200 Subject: Prepare for multiple different modifier options Signed-off-by: Tom Smeding --- bubblewrap.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/bubblewrap.c b/bubblewrap.c index b17ff99..24a402c 100644 --- a/bubblewrap.c +++ b/bubblewrap.c @@ -1575,25 +1575,9 @@ print_version_and_exit (void) } static int -takes_perms (const char *next_option) +is_modifier_option (const char *option) { - static const char *const options_that_take_perms[] = - { - "--bind-data", - "--dir", - "--file", - "--ro-bind-data", - "--tmpfs", - }; - size_t i; - - for (i = 0; i < N_ELEMENTS (options_that_take_perms); i++) - { - if (strcmp (options_that_take_perms[i], next_option) == 0) - return 1; - } - - return 0; + return strcmp (option, "--perms") == 0; } static void @@ -1630,9 +1614,6 @@ parse_args_recurse (int *argcp, { const char *arg = argv[0]; - if (next_perms >= 0 && !takes_perms (arg)) - die ("--perms must be followed by an option that creates a file"); - if (strcmp (arg, "--help") == 0) { usage (EXIT_SUCCESS, stdout); @@ -2383,6 +2364,9 @@ parse_args_recurse (int *argcp, if (argc < 2) die ("--perms takes an argument"); + if (next_perms != -1) + die ("--perms given twice for the same action"); + perms = strtoul (argv[1], &endptr, 8); if (argv[1][0] == '\0' @@ -2435,6 +2419,12 @@ parse_args_recurse (int *argcp, break; } + /* If --perms was set for the current action but the current action + * didn't consume the setting, apparently --perms wasn't suitable for + * this action. */ + if (!is_modifier_option(arg) && next_perms >= 0) + die ("--perms must be followed by an option that creates a file"); + argv++; argc--; } -- cgit v1.2.1