#include "rb_commio.h"
#include "authd.h"
#include "provider.h"
+#include "notice.h"
#include "res.h"
#include "dns.h"
struct user_query
{
struct dns_query *query; /* Pending DNS query */
- time_t timeout; /* When the request times out */
};
/* Goinked from old s_auth.c --Elizabeth */
static const char *messages[] =
{
"*** Looking up your hostname...",
- "*** Found your hostname",
"*** Couldn't look up your hostname",
"*** Your hostname is too long, ignoring hostname",
};
typedef enum
{
REPORT_LOOKUP,
- REPORT_FOUND,
REPORT_FAIL,
REPORT_TOOLONG,
} dns_message;
static void client_success(struct auth_client *auth);
static void dns_answer_callback(const char *res, bool status, query_type type, void *data);
-static struct ev_entry *timeout_ev;
-static EVH timeout_dns_queries_event;
-static int rdns_timeout = 30;
+static int rdns_timeout = 15;
-
-bool client_dns_init(void)
+static void
+dns_answer_callback(const char *res, bool status, query_type type, void *data)
{
- timeout_ev = rb_event_addish("timeout_dns_queries_event", timeout_dns_queries_event, NULL, 5);
- return (timeout_ev != NULL);
-}
+ struct auth_client *auth = data;
+ struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
-void client_dns_destroy(void)
-{
- struct auth_client *auth;
- rb_dictionary_iter iter;
+ lrb_assert(query != NULL);
- RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
+ if(res == NULL || status == false)
+ client_fail(auth, REPORT_FAIL);
+ else if(strlen(res) > HOSTLEN)
+ client_fail(auth, REPORT_TOOLONG);
+ else
{
- if(auth->data[PROVIDER_RDNS] != NULL)
- client_fail(auth, REPORT_FAIL);
+ rb_strlcpy(auth->hostname, res, HOSTLEN + 1);
+ client_success(auth);
}
-
- rb_event_delete(timeout_ev);
}
-bool client_dns_start(struct auth_client *auth)
+static void
+client_fail(struct auth_client *auth, dns_message report)
{
- struct user_query *query = rb_malloc(sizeof(struct user_query));
-
- query->timeout = rb_current_time() + rdns_timeout;
+ struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
- auth->data[PROVIDER_RDNS] = query;
+ lrb_assert(query != NULL);
- query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
+ rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname));
- notice_client(auth, messages[REPORT_LOOKUP]);
- set_provider(auth, PROVIDER_RDNS);
- return true;
-}
+ notice_client(auth->cid, messages[report]);
+ cancel_query(query->query);
-void client_dns_cancel(struct auth_client *auth)
-{
- struct user_query *query = auth->data[PROVIDER_RDNS];
+ rb_free(query);
- if(query != NULL)
- client_fail(auth, REPORT_FAIL);
+ set_provider_data(auth, PROVIDER_RDNS, NULL);
+ set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0);
+ provider_done(auth, PROVIDER_RDNS);
}
static void
-dns_answer_callback(const char *res, bool status, query_type type, void *data)
+client_success(struct auth_client *auth)
{
- struct auth_client *auth = data;
- struct user_query *query = auth->data[PROVIDER_RDNS];
+ struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
- if(query == NULL || res == NULL || status == false)
- client_fail(auth, REPORT_FAIL);
- else if(strlen(res) > HOSTLEN)
- client_fail(auth, REPORT_TOOLONG);
- else
- {
- rb_strlcpy(auth->hostname, res, HOSTLEN + 1);
- client_success(auth);
- }
+ lrb_assert(query != NULL);
+
+ notice_client(auth->cid, "*** Found your hostname: %s", auth->hostname);
+ cancel_query(query->query);
+
+ rb_free(query);
+
+ set_provider_data(auth, PROVIDER_RDNS, NULL);
+ set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0);
+ provider_done(auth, PROVIDER_RDNS);
}
-/* Timeout outstanding queries */
-static void timeout_dns_queries_event(void *notused)
+static void
+rdns_destroy(void)
{
struct auth_client *auth;
rb_dictionary_iter iter;
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
- struct user_query *query = auth->data[PROVIDER_RDNS];
-
- if(query != NULL && query->timeout < rb_current_time())
- {
+ if(get_provider_data(auth, PROVIDER_RDNS) != NULL)
client_fail(auth, REPORT_FAIL);
- return;
- }
}
}
-static void client_fail(struct auth_client *auth, dns_message report)
+static bool
+rdns_start(struct auth_client *auth)
{
- struct user_query *query = auth->data[PROVIDER_RDNS];
+ struct user_query *query = rb_malloc(sizeof(struct user_query));
- if(query == NULL)
- return;
+ set_provider_data(auth, PROVIDER_RDNS, query);
+ set_provider_timeout_relative(auth, PROVIDER_RDNS, rdns_timeout);
- rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname));
+ query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
- notice_client(auth, messages[report]);
- cancel_query(query->query);
+ notice_client(auth->cid, messages[REPORT_LOOKUP]);
+ set_provider_on(auth, PROVIDER_RDNS);
+ return true;
+}
- rb_free(query);
- auth->data[PROVIDER_RDNS] = NULL;
+static void
+rdns_cancel(struct auth_client *auth)
+{
+ struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
- provider_done(auth, PROVIDER_RDNS);
+ if(query != NULL)
+ client_fail(auth, REPORT_FAIL);
}
-static void client_success(struct auth_client *auth)
+static void
+add_conf_dns_timeout(const char *key, int parc, const char **parv)
{
- struct user_query *query = auth->data[PROVIDER_RDNS];
+ int timeout = atoi(parv[0]);
- notice_client(auth, messages[REPORT_FOUND]);
- cancel_query(query->query);
-
- rb_free(query);
- auth->data[PROVIDER_RDNS] = NULL;
+ if(timeout < 0)
+ {
+ warn_opers(L_CRIT, "rDNS: DNS timeout < 0 (value: %d)", timeout);
+ exit(EX_PROVIDER_ERROR);
+ }
- provider_done(auth, PROVIDER_RDNS);
+ rdns_timeout = timeout;
}
+struct auth_opts_handler rdns_options[] =
+{
+ { "rdns_timeout", 1, add_conf_dns_timeout },
+ { NULL, 0, NULL },
+};
+
struct auth_provider rdns_provider =
{
.id = PROVIDER_RDNS,
- .init = client_dns_init,
- .destroy = client_dns_destroy,
- .start = client_dns_start,
- .cancel = client_dns_cancel,
- .completed = NULL,
+ .destroy = rdns_destroy,
+ .start = rdns_start,
+ .cancel = rdns_cancel,
+ .timeout = rdns_cancel,
+ .opt_handlers = rdns_options,
};