# HG changeset patch # User Aki Tuomi # Date 1456678775 -7200 # Node ID 6f760a1def9f56571b96716bb24fc3c5b3c25298 # Parent ef466c52207b9b23f5aca7ef9880345f3423121f doveadm kick: Don't show who command's help on duplicate network/username masks diff -r ef466c52207b -r 6f760a1def9f src/doveadm/doveadm-kick.c --- a/src/doveadm/doveadm-kick.c Sun Feb 28 18:48:15 2016 +0200 +++ b/src/doveadm/doveadm-kick.c Sun Feb 28 18:59:35 2016 +0200 @@ -196,7 +196,8 @@ i_fatal_status(EX_USAGE, "user and/or ip[/bits] must be specified."); } - who_parse_args(&ctx.who, argv); + if (who_parse_args(&ctx.who, (const char *const *)argv + 1) < 0) + help(&doveadm_cmd_kick); who_lookup(&ctx.who, kick_aggregate_line); kick_users(&ctx); diff -r ef466c52207b -r 6f760a1def9f src/doveadm/doveadm-who.c --- a/src/doveadm/doveadm-who.c Sun Feb 28 18:48:15 2016 +0200 +++ b/src/doveadm/doveadm-who.c Sun Feb 28 18:59:35 2016 +0200 @@ -112,24 +112,30 @@ array_append(&user->pids, &line->pid, 1); } -void who_parse_args(struct who_context *ctx, char **args) +int who_parse_args(struct who_context *ctx, const char *const *masks) { struct ip_addr net_ip; - unsigned int net_bits; + unsigned int i, net_bits; - while (args[1] != NULL) { - if (net_parse_range(args[1], &net_ip, &net_bits) == 0) { - if (ctx->filter.net_bits != 0) - help(&doveadm_cmd_who); + for (i = 0; masks[i] != NULL; i++) { + if (net_parse_range(masks[i], &net_ip, &net_bits) == 0) { + if (ctx->filter.net_bits != 0) { + i_error("Multiple network masks not supported"); + doveadm_exit_code = EX_USAGE; + return -1; + } ctx->filter.net_ip = net_ip; ctx->filter.net_bits = net_bits; } else { - if (ctx->filter.username != NULL) - help(&doveadm_cmd_who); - ctx->filter.username = args[1]; + if (ctx->filter.username != NULL) { + i_error("Multiple username masks not supported"); + doveadm_exit_code = EX_USAGE; + return -1; + } + ctx->filter.username = masks[i]; } - args++; } + return 0; } void who_lookup(struct who_context *ctx, who_callback_t *callback) @@ -293,7 +299,8 @@ } argv += optind - 1; - who_parse_args(&ctx, argv); + if (who_parse_args(&ctx, (const char *const *)argv + 1) < 0) + help(&doveadm_cmd_who); doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); if (!separate_connections) { diff -r ef466c52207b -r 6f760a1def9f src/doveadm/doveadm-who.h --- a/src/doveadm/doveadm-who.h Sun Feb 28 18:48:15 2016 +0200 +++ b/src/doveadm/doveadm-who.h Sun Feb 28 18:59:35 2016 +0200 @@ -27,7 +27,7 @@ typedef void who_callback_t(struct who_context *ctx, const struct who_line *line); -void who_parse_args(struct who_context *ctx, char **args); +int who_parse_args(struct who_context *ctx, const char *const *masks); void who_lookup(struct who_context *ctx, who_callback_t *callback);