diff options
author | наб <[email protected]> | 2022-01-22 23:24:14 +0100 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2022-03-15 15:14:23 -0700 |
commit | 7c17e82cbe42d01511e86465cb9bc20d56f03325 (patch) | |
tree | b9338d4700927faa8cbdb724ff5092fd4d8619d9 /cmd | |
parent | c79787845dfc9386d89e821963506d9c90c36677 (diff) |
zfs: get: only accept whole column for -o, not col[=whatever]
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes #12996
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/zfs/zfs_main.c | 60 |
1 files changed, 26 insertions, 34 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c index 2a16bd0b4..5d7599d3e 100644 --- a/cmd/zfs/zfs_main.c +++ b/cmd/zfs/zfs_main.c @@ -2038,11 +2038,17 @@ zfs_do_get(int argc, char **argv) * the structure to give us a blank slate. */ memset(&cb.cb_columns, 0, sizeof (cb.cb_columns)); + i = 0; - while (*optarg != '\0') { - static char *col_subopts[] = - { "name", "property", "value", "received", - "source", "all", NULL }; + for (char *tok; (tok = strsep(&optarg, ",")); ) { + static const char *const col_subopts[] = + { "name", "property", "value", + "received", "source", "all" }; + static const zfs_get_column_t col_subopt_col[] = + { GET_COL_NAME, GET_COL_PROPERTY, GET_COL_VALUE, + GET_COL_RECVD, GET_COL_SOURCE }; + static const int col_subopt_flags[] = + { 0, 0, 0, ZFS_ITER_RECVD_PROPS, 0 }; if (i == ZFS_GET_NCOLS) { (void) fprintf(stderr, gettext("too " @@ -2051,25 +2057,16 @@ zfs_do_get(int argc, char **argv) usage(B_FALSE); } - switch (getsubopt(&optarg, col_subopts, - &value)) { - case 0: - cb.cb_columns[i++] = GET_COL_NAME; - break; - case 1: - cb.cb_columns[i++] = GET_COL_PROPERTY; - break; - case 2: - cb.cb_columns[i++] = GET_COL_VALUE; - break; - case 3: - cb.cb_columns[i++] = GET_COL_RECVD; - flags |= ZFS_ITER_RECVD_PROPS; - break; - case 4: - cb.cb_columns[i++] = GET_COL_SOURCE; - break; - case 5: + for (c = 0; c < ARRAY_SIZE(col_subopts); ++c) + if (strcmp(tok, col_subopts[c]) == 0) + goto found; + + (void) fprintf(stderr, + gettext("invalid column name '%s'\n"), tok); + usage(B_FALSE); + +found: + if (c >= 5) { if (i > 0) { (void) fprintf(stderr, gettext("\"all\" conflicts " @@ -2077,19 +2074,14 @@ zfs_do_get(int argc, char **argv) "given to -o option\n")); usage(B_FALSE); } - cb.cb_columns[0] = GET_COL_NAME; - cb.cb_columns[1] = GET_COL_PROPERTY; - cb.cb_columns[2] = GET_COL_VALUE; - cb.cb_columns[3] = GET_COL_RECVD; - cb.cb_columns[4] = GET_COL_SOURCE; + + memcpy(cb.cb_columns, col_subopt_col, + sizeof (col_subopt_col)); flags |= ZFS_ITER_RECVD_PROPS; i = ZFS_GET_NCOLS; - break; - default: - (void) fprintf(stderr, - gettext("invalid column name " - "'%s'\n"), value); - usage(B_FALSE); + } else { + cb.cb_columns[i++] = col_subopt_col[c]; + flags |= col_subopt_flags[c]; } } break; |