bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
c2d398246d2a5bb42beb083370695484142295f6Phil Carmodystatic struct anvil_connection *anvil_connections = NULL;
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenstatic const char *const *
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenanvil_connection_next_line(struct anvil_connection *conn)
7a60e1dc9e93ef3f7c7fe1af6385a0bfa1e31bc3Timo Sirainen return line == NULL ? NULL : t_strsplit_tabescaped(line);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenanvil_connection_request(struct anvil_connection *conn,
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen const char *const *args, const char **error_r)
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen connect_limit_connect(connect_limit, pid, args[1]);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen *error_r = "DISCONNECT: Not enough parameters";
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen connect_limit_disconnect(connect_limit, pid, args[1]);
fc0b7b7df3888ffd6292050d066919dd31e9c0ccTimo Sirainen } else if (strcmp(cmd, "CONNECT-DUMP") == 0) {
fc0b7b7df3888ffd6292050d066919dd31e9c0ccTimo Sirainen connect_limit_dump(connect_limit, conn->output);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen *error_r = "KILL sent by a non-master connection";
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen connect_limit_disconnect_pid(connect_limit, pid);
5dd73391f9dfb2396cf2060402017f6080c93dc7Timo Sirainen *error_r = "LOOKUP on a FIFO, can't send reply";
7e7cdca78e6a67757188406c8de9db42fcd17881Timo Sirainen value = connect_limit_lookup(connect_limit, args[0]);
7e7cdca78e6a67757188406c8de9db42fcd17881Timo Sirainen *error_r = "PENALTY-GET: Not enough parameters";
7e7cdca78e6a67757188406c8de9db42fcd17881Timo Sirainen value = penalty_get(penalty, args[0], &stamp);
7e7cdca78e6a67757188406c8de9db42fcd17881Timo Sirainen t_strdup_printf("%u %s\n", value, dec2str(stamp)));
5566faf0b48f0b77b0134f34130bdc7842c844ebTimo Sirainen if (args[0] == NULL || args[1] == NULL || args[2] == NULL) {
5566faf0b48f0b77b0134f34130bdc7842c844ebTimo Sirainen *error_r = "PENALTY-INC: Not enough parameters";
5566faf0b48f0b77b0134f34130bdc7842c844ebTimo Sirainen penalty_inc(penalty, args[0], checksum, value);
7e7cdca78e6a67757188406c8de9db42fcd17881Timo Sirainen } else if (strcmp(cmd, "PENALTY-SET-EXPIRE-SECS") == 0) {
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen if (args[0] == NULL || str_to_uint(args[0], &value) < 0) {
9261dbf0675204898c6557591c7aa376e23a52b2Timo Sirainen "Invalid parameters";
8825740187b8aaca9c39c4fd6a0b79d480eb143fTimo Sirainen } else if (strcmp(cmd, "PENALTY-DUMP") == 0) {
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen *error_r = t_strconcat("Unknown command: ", cmd, NULL);
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainenstatic void anvil_connection_input(struct anvil_connection *conn)
12db7b091f9866c2f2e81205350d3bb452d31aa2Timo Sirainen i_error("BUG: Anvil client connection sent too much data");
f158d9a303bb15a6848ca276c9391c7ca52e452bTimo Sirainen if ((line = i_stream_next_line(conn->input)) == NULL)
ab96e72a574ff5e579500513cd62f14ec142e467Timo Sirainen if (anvil_restarted && (conn->master || conn->fifo)) {
ab96e72a574ff5e579500513cd62f14ec142e467Timo Sirainen /* old pending data. ignore input until we get
ab96e72a574ff5e579500513cd62f14ec142e467Timo Sirainen the handshake. */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen i_error("Anvil client not compatible with this server "
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen while ((args = anvil_connection_next_line(conn)) != NULL) {
c87043283d789e8dc544162ca8e0ddf74a98fb3cTimo Sirainen if (anvil_connection_request(conn, args, &error) < 0) {
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen i_error("Anvil client input error: %s", error);
5dd73391f9dfb2396cf2060402017f6080c93dc7Timo Sirainenanvil_connection_create(int fd, bool master, bool fifo)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi conn->output = o_stream_create_fd(fd, (size_t)-1);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_set_no_error_handling(conn->output, TRUE);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen conn->io = io_add(fd, IO_READ, anvil_connection_input, conn);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenvoid anvil_connection_destroy(struct anvil_connection *conn)