zfs: get: only accept whole source for -s, not src[=whatever]

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12996
This commit is contained in:
наб 2022-01-22 23:33:44 +01:00 committed by Brian Behlendorf
parent 7c17e82cbe
commit 7867f430b4

View File

@ -2088,38 +2088,27 @@ found:
case 's': case 's':
cb.cb_sources = 0; cb.cb_sources = 0;
while (*optarg != '\0') {
static char *source_subopts[] = {
"local", "default", "inherited",
"received", "temporary", "none",
NULL };
switch (getsubopt(&optarg, source_subopts, for (char *tok; (tok = strsep(&optarg, ",")); ) {
&value)) { static const char *const source_opt[] = {
case 0: "local", "default",
cb.cb_sources |= ZPROP_SRC_LOCAL; "inherited", "received",
break; "temporary", "none" };
case 1: static const int source_flg[] = {
cb.cb_sources |= ZPROP_SRC_DEFAULT; ZPROP_SRC_LOCAL, ZPROP_SRC_DEFAULT,
break; ZPROP_SRC_INHERITED, ZPROP_SRC_RECEIVED,
case 2: ZPROP_SRC_TEMPORARY, ZPROP_SRC_NONE };
cb.cb_sources |= ZPROP_SRC_INHERITED;
break; for (i = 0; i < ARRAY_SIZE(source_opt); ++i)
case 3: if (strcmp(tok, source_opt[i]) == 0) {
cb.cb_sources |= ZPROP_SRC_RECEIVED; cb.cb_sources |= source_flg[i];
break; goto found2;
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);
} }
(void) fprintf(stderr,
gettext("invalid source '%s'\n"), tok);
usage(B_FALSE);
found2:;
} }
break; break;