doveadm-kick.c revision a7fc192e2177fd869bca779e9f6014f7149cda2d
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen bool kick_me; /* true if username and/or ip[/mask] matches.
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi ignored when the -f switch is given. */
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenkick_aggregate_line(struct who_context *_ctx, const struct who_line *line)
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen struct kick_context *ctx = (struct kick_context *)_ctx;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen const bool user_match = who_line_filter_match(line, &ctx->who.filter);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen k_pid = hash_table_lookup(ctx->pids, POINTER_CAST(line->pid));
f300f927771a39549ce6cb7607129508e9041b4aStephan Bosch k_pid = p_new(ctx->who.pool, struct kick_pid, 1);
e60c3e17c656c53da60f0ac51aa15e9ef2742d77Stephan Bosch p_array_init(&k_pid->users, ctx->who.pool, 5);
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi hash_table_insert(ctx->pids, POINTER_CAST(line->pid), k_pid);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen array_foreach_modifiable(&k_pid->users, user) {
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen if (strcmp(line->username, user->username) == 0) {
1e11a94ec50fc9b57eb2c859771c6a326ccaf86fAki Tuomi new_user.username = p_strdup(ctx->who.pool, line->username);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainenkick_pid_want_kicked(struct kick_context *ctx, const struct kick_pid *k_pid,
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen unsigned int kick_count = 0;
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen if (kick_count < array_count(&k_pid->users) &&
a2fdfd2efdbb2d912aad23900a466cf74114920bTimo Sirainenkick_print_kicked(struct kick_context *ctx, const bool show_warning)
45ead232666a47819e89dc71dec57767340d0b62Timo Sirainen unsigned int i, count;
f36c4185474823594a78b3f252e79d8923522c36Timo Sirainen const char *const *users;
2d1892aaeb63b9774237b6e60d6bb04bf6f8259cTimo Sirainen printf("warning: other connections would also be "
838d6a4751c3fbe17c3ec45c0e109629c4156815Timo Sirainen "kicked from following users:\n");
c1fc5a97a15332f1253ee13a9cab65a7b4b6cd5fTimo Sirainen printf("kicked connections from the following users:\n");
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen users = array_get(&ctx->kicked_users, &count);
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainen printf("Use the '-f' option to enforce the disconnect.\n");
107659c01b2359b0ee426bde020c8d4e29ede30dTimo Sirainenstatic void kick_users(struct kick_context *ctx)
c1fc5a97a15332f1253ee13a9cab65a7b4b6cd5fTimo Sirainen p_array_init(&ctx->kicked_users, ctx->who.pool, 10);
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen while (hash_table_iterate(iter, ctx->pids, &key, &k_pid)) {
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen if (kick_pid_want_kicked(ctx, k_pid, &show_enforce_warning))
71df09024cea5f2faa93da3bb9513ee96ba6bf22Timo Sirainen while (hash_table_iterate(iter, ctx->pids, &key, &k_pid)) {