zfs: get: only accept whole type for -t, not tp[=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:41:36 +01:00 committed by Brian Behlendorf
parent 7867f430b4
commit 4695230021

View File

@ -1997,7 +1997,7 @@ zfs_do_get(int argc, char **argv)
zprop_get_cbdata_t cb = { 0 }; zprop_get_cbdata_t cb = { 0 };
int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS; int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS;
int types = ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK; int types = ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK;
char *value, *fields; char *fields;
int ret = 0; int ret = 0;
int limit = 0; int limit = 0;
zprop_list_t fake_name = { 0 }; zprop_list_t fake_name = { 0 };
@ -2115,37 +2115,29 @@ found2:;
case 't': case 't':
types = 0; types = 0;
flags &= ~ZFS_ITER_PROP_LISTSNAPS; flags &= ~ZFS_ITER_PROP_LISTSNAPS;
while (*optarg != '\0') {
static char *type_subopts[] = { "filesystem",
"volume", "snapshot", "snap", "bookmark",
"all", NULL };
switch (getsubopt(&optarg, type_subopts, for (char *tok; (tok = strsep(&optarg, ",")); ) {
&value)) { static const char *const type_opts[] = {
case 0: "filesystem", "volume",
types |= ZFS_TYPE_FILESYSTEM; "snapshot", "snap",
break; "bookmark",
case 1: "all" };
types |= ZFS_TYPE_VOLUME; static const int type_types[] = {
break; ZFS_TYPE_FILESYSTEM, ZFS_TYPE_VOLUME,
case 2: ZFS_TYPE_SNAPSHOT, ZFS_TYPE_SNAPSHOT,
case 3: ZFS_TYPE_BOOKMARK,
types |= ZFS_TYPE_SNAPSHOT; ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK };
break;
case 4:
types |= ZFS_TYPE_BOOKMARK;
break;
case 5:
types = ZFS_TYPE_DATASET |
ZFS_TYPE_BOOKMARK;
break;
default: for (i = 0; i < ARRAY_SIZE(type_opts); ++i)
(void) fprintf(stderr, if (strcmp(tok, type_opts[i]) == 0) {
gettext("invalid type '%s'\n"), types |= type_types[i];
value); goto found3;
usage(B_FALSE); }
}
(void) fprintf(stderr,
gettext("invalid type '%s'\n"), tok);
usage(B_FALSE);
found3:;
} }
break; break;