diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2022-01-22 23:41:36 +0100 |
---|---|---|
committer | Brian Behlendorf <behlendorf1@llnl.gov> | 2022-03-15 15:14:33 -0700 |
commit | 46952300210647faeef391e2df2a59ec6a185591 (patch) | |
tree | 52f5be471c43f723833b122eab2f0d9a03b868ff /cmd/zfs | |
parent | 7867f430b4c15b94fccac9cd4829b811bbf7383b (diff) |
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
Diffstat (limited to 'cmd/zfs')
-rw-r--r-- | cmd/zfs/zfs_main.c | 52 |
1 files changed, 22 insertions, 30 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index b7a26242b..2db42dfc6 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -1997,7 +1997,7 @@ zfs_do_get(int argc, char **argv) zprop_get_cbdata_t cb = { 0 }; int i, c, flags = ZFS_ITER_ARGS_CAN_BE_PATHS; int types = ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK; - char *value, *fields; + char *fields; int ret = 0; int limit = 0; zprop_list_t fake_name = { 0 }; @@ -2115,37 +2115,29 @@ found2:; case 't': types = 0; flags &= ~ZFS_ITER_PROP_LISTSNAPS; - while (*optarg != '\0') { - static char *type_subopts[] = { "filesystem", - "volume", "snapshot", "snap", "bookmark", - "all", NULL }; - switch (getsubopt(&optarg, type_subopts, - &value)) { - case 0: - types |= ZFS_TYPE_FILESYSTEM; - break; - case 1: - types |= ZFS_TYPE_VOLUME; - break; - case 2: - case 3: - types |= ZFS_TYPE_SNAPSHOT; - break; - case 4: - types |= ZFS_TYPE_BOOKMARK; - break; - case 5: - types = ZFS_TYPE_DATASET | - ZFS_TYPE_BOOKMARK; - break; + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const type_opts[] = { + "filesystem", "volume", + "snapshot", "snap", + "bookmark", + "all" }; + static const int type_types[] = { + ZFS_TYPE_FILESYSTEM, ZFS_TYPE_VOLUME, + ZFS_TYPE_SNAPSHOT, ZFS_TYPE_SNAPSHOT, + ZFS_TYPE_BOOKMARK, + ZFS_TYPE_DATASET | ZFS_TYPE_BOOKMARK }; + + for (i = 0; i < ARRAY_SIZE(type_opts); ++i) + if (strcmp(tok, type_opts[i]) == 0) { + types |= type_types[i]; + goto found3; + } - default: - (void) fprintf(stderr, - gettext("invalid type '%s'\n"), - value); - usage(B_FALSE); - } + (void) fprintf(stderr, + gettext("invalid type '%s'\n"), tok); + usage(B_FALSE); +found3:; } break; |