diff options
author | наб <[email protected]> | 2022-01-22 23:33:44 +0100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2022-03-15 15:14:29 -0700 |
commit | 7867f430b4c15b94fccac9cd4829b811bbf7383b (patch) | |
tree | 5ff5b9c14b7ce79f0670c5ac7dac1bab13ebe1f8 /cmd/zfs | |
parent | 7c17e82cbe42d01511e86465cb9bc20d56f03325 (diff) |
zfs: get: only accept whole source for -s, not src[=whatever]
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12996
Diffstat (limited to 'cmd/zfs')
-rw-r--r-- | cmd/zfs/zfs_main.c | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 5d7599d3e..b7a26242b 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -2088,38 +2088,27 @@ found: case 's': cb.cb_sources = 0; - while (*optarg != '\0') { - static char *source_subopts[] = { - "local", "default", "inherited", - "received", "temporary", "none", - NULL }; - switch (getsubopt(&optarg, source_subopts, - &value)) { - case 0: - cb.cb_sources |= ZPROP_SRC_LOCAL; - break; - case 1: - cb.cb_sources |= ZPROP_SRC_DEFAULT; - break; - case 2: - cb.cb_sources |= ZPROP_SRC_INHERITED; - break; - case 3: - cb.cb_sources |= ZPROP_SRC_RECEIVED; - break; - case 4: - cb.cb_sources |= ZPROP_SRC_TEMPORARY; - break; - case 5: - cb.cb_sources |= ZPROP_SRC_NONE; - break; - default: - (void) fprintf(stderr, - gettext("invalid source " - "'%s'\n"), value); - usage(B_FALSE); - } + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const source_opt[] = { + "local", "default", + "inherited", "received", + "temporary", "none" }; + static const int source_flg[] = { + ZPROP_SRC_LOCAL, ZPROP_SRC_DEFAULT, + ZPROP_SRC_INHERITED, ZPROP_SRC_RECEIVED, + ZPROP_SRC_TEMPORARY, ZPROP_SRC_NONE }; + + for (i = 0; i < ARRAY_SIZE(source_opt); ++i) + if (strcmp(tok, source_opt[i]) == 0) { + cb.cb_sources |= source_flg[i]; + goto found2; + } + + (void) fprintf(stderr, + gettext("invalid source '%s'\n"), tok); + usage(B_FALSE); +found2:; } break; |