bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainenstatic void dns_client_destroy(struct dns_client **client);
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainenstatic int dns_client_input_line(struct dns_client *client, const char *line)
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen ret = net_gethostbyname(line + 3, &ips, &ips_count);
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen /* shouldn't happen, but fix it anyway.. */
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen for (i = 0; i < ips_count; i++) {
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(client->output, t_strconcat(
d29c3ac4da9857ffcce57eec726d042c292e2becTimo Sirainen else if ((ret = net_gethostbyaddr(&ip, &name)) != 0) {
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_nsend_str(client->output, "Unknown command\n");
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainenstatic void dns_client_input(struct dns_client *client)
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen while ((line = i_stream_read_next_line(client->input)) != NULL) {
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen if (dns_client_input_line(client, line) < 0) {
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen if (client->input->eof || client->input->stream_errno != 0 || ret < 0)
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainenstatic struct dns_client *dns_client_create(int fd)
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi client->input = i_stream_create_fd(fd, MAX_INBUF_SIZE);
e93184a9055c2530366dfe617e07199603c399ddMartti Rannanjärvi client->output = o_stream_create_fd(fd, MAX_OUTBUF_SIZE);
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen o_stream_set_no_error_handling(client->output, TRUE);
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen client->io = io_add(fd, IO_READ, dns_client_input, client);
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainenstatic void dns_client_destroy(struct dns_client **_client)
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen master_service_client_connection_destroyed(master_service);
db693bf6fcae96d834567f1782257517b7207655Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen i_error("dns-client must be configured with client_limit=1");
db693bf6fcae96d834567f1782257517b7207655Timo Sirainen master_service_client_connection_accept(conn);
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainen master_service = master_service_init("dns-client", 0, &argc, &argv, "");
17fc2a887a5683b2e1bbd6bd9fdf0cdb97b509fbTimo Sirainen master_service_init_log(master_service, "dns-client: ");
816d20be0cf95fc4eb1a8aa716639e73b8ba525eMartti Rannanjärvi restrict_access_by_env(RESTRICT_ACCESS_FLAG_ALLOW_ROOT, NULL);