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);
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;
-
- 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);
+ unsigned int i, net_bits;
+
+ 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)
}
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) {
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);