summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2022-05-14 13:39:31 +0200
committerTom Smeding <tom@tomsmeding.com>2022-05-14 13:45:41 +0200
commit89d64eee9d7a01c92b94f382b6783fb82bb1c417 (patch)
treedf106a3d1c1850911981e6f4ca7b70253c75b90a
parentc54bbc6d7b78e7a45016efe0c4ac8af9d209aa20 (diff)
downloadbubblewrap-89d64eee9d7a01c92b94f382b6783fb82bb1c417.tar.gz
Prepare for multiple different modifier options
Signed-off-by: Tom Smeding <tom@tomsmeding.com>
-rw-r--r--bubblewrap.c32
1 files 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--;
}