static void login_proxy_cmd_kick(struct ipc_cmd *cmd, const char *const *args) { struct login_proxy *proxy, *next; unsigned int count = 0; if (args[0] == NULL) { ipc_cmd_fail(&cmd, "Missing parameter"); return; } for (proxy = login_proxies; proxy != NULL; proxy = next) { next = proxy->next; if (strcmp(proxy->client->virtual_user, args[0]) == 0) { login_proxy_free_delayed(&proxy, KILLED_BY_ADMIN_REASON); count++; } } for (proxy = login_proxies_pending; proxy != NULL; proxy = next) { next = proxy->next; if (strcmp(proxy->client->virtual_user, args[0]) == 0) { client_destroy(proxy->client, "Connection kicked"); count++; } } ipc_cmd_success_reply(&cmd, t_strdup_printf("%u", count)); }
static void login_proxy_free_errstr(struct login_proxy **_proxy, const char *errstr, bool server) { struct login_proxy *proxy = *_proxy; string_t *reason = t_str_new(128); str_printfa(reason, "Disconnected by %s", server ? "server" : "client"); if (errstr[0] != '\0') str_printfa(reason, ": %s", errstr); str_printfa(reason, "(%ds idle, in=%"PRIuUOFF_T", out=%"PRIuUOFF_T, (int)(ioloop_time - proxy->last_io), proxy->server_output->offset, proxy->client_output->offset); if (o_stream_get_buffer_used_size(proxy->client_output) > 0) { str_printfa(reason, "+%"PRIuSIZE_T, o_stream_get_buffer_used_size(proxy->client_output)); } if (proxy->server_io == NULL) str_append(reason, ", client output blocked"); if (proxy->client_io == NULL) str_append(reason, ", server output blocked"); str_append_c(reason, ')'); if (server) login_proxy_free_delayed(_proxy, str_c(reason)); else login_proxy_free_reason(_proxy, str_c(reason)); }
static void login_proxy_cmd_kick_full(struct ipc_cmd *cmd, const char *const *args, bool (*want_kick)(struct client *, const char *const *, unsigned int), unsigned int key_idx) { struct login_proxy *proxy, *next; unsigned int count = 0; if (args[0] == NULL) { ipc_cmd_fail(&cmd, "Missing parameter"); return; } for (proxy = login_proxies; proxy != NULL; proxy = next) { next = proxy->next; if (want_kick(proxy->client, args, key_idx)) { login_proxy_free_delayed(&proxy, KILLED_BY_ADMIN_REASON); count++; } } for (proxy = login_proxies_pending; proxy != NULL; proxy = next) { next = proxy->next; if (want_kick(proxy->client, args, key_idx)) { client_destroy(proxy->client, "Connection kicked"); count++; } } ipc_cmd_success_reply(&cmd, t_strdup_printf("%u", count)); }
static void login_proxy_cmd_kick_director_hash(struct ipc_cmd *cmd, const char *const *args) { struct login_proxy *proxy, *next; struct ip_addr except_ip; unsigned int hash, proxy_hash, count = 0; if (args[0] == NULL || str_to_uint(args[0], &hash) < 0) { ipc_cmd_fail(&cmd, "Invalid parameters"); return; } /* optional except_ip parameter specifies that we're not killing the connections that are proxying to the except_ip backend */ except_ip.family = 0; if (args[1] != NULL && args[1][0] != '\0' && net_addr2ip(args[1], &except_ip) < 0) { ipc_cmd_fail(&cmd, "Invalid except_ip parameter"); return; } for (proxy = login_proxies; proxy != NULL; proxy = next) { next = proxy->next; if (director_username_hash(proxy->client, &proxy_hash) && proxy_hash == hash && !net_ip_compare(&proxy->ip, &except_ip)) { login_proxy_free_delayed(&proxy, KILLED_BY_DIRECTOR_REASON); count++; } } for (proxy = login_proxies_pending; proxy != NULL; proxy = next) { next = proxy->next; if (director_username_hash(proxy->client, &proxy_hash) && proxy_hash == hash && !net_ip_compare(&proxy->ip, &except_ip)) { client_destroy(proxy->client, "Connection kicked"); count++; } } ipc_cmd_success_reply(&cmd, t_strdup_printf("%u", count)); }