]> jfr.im git - solanum.git/blobdiff - authd/providers/rdns.c
m_kline: check only the added K-line
[solanum.git] / authd / providers / rdns.c
index 8b4dd5002e4c73220d940f349a0ae6e2f77d04f6..a0232f60e49c2dad64a507eccc2bd67f973c4668 100644 (file)
@@ -26,6 +26,8 @@
 #include "res.h"
 #include "dns.h"
 
+#define SELF_PID (rdns_provider.id)
+
 struct user_query
 {
        struct dns_query *query;                /* Pending DNS query */
@@ -50,15 +52,12 @@ static void client_fail(struct auth_client *auth, dns_message 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 int rdns_timeout = 15;
+static int rdns_timeout = RDNS_TIMEOUT_DEFAULT;
 
 static void
 dns_answer_callback(const char *res, bool status, query_type type, void *data)
 {
        struct auth_client *auth = data;
-       struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
-
-       lrb_assert(query != NULL);
 
        if(res == NULL || status == false)
                client_fail(auth, REPORT_FAIL);
@@ -74,7 +73,7 @@ dns_answer_callback(const char *res, bool status, query_type type, void *data)
 static void
 client_fail(struct auth_client *auth, dns_message report)
 {
-       struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
+       struct user_query *query = get_provider_data(auth, SELF_PID);
 
        lrb_assert(query != NULL);
 
@@ -85,15 +84,17 @@ client_fail(struct auth_client *auth, dns_message report)
 
        rb_free(query);
 
-       set_provider_data(auth, PROVIDER_RDNS, NULL);
-       set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0);
-       provider_done(auth, PROVIDER_RDNS);
+       set_provider_data(auth, SELF_PID, NULL);
+       set_provider_timeout_absolute(auth, SELF_PID, 0);
+       provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
 client_success(struct auth_client *auth)
 {
-       struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
+       struct user_query *query = get_provider_data(auth, SELF_PID);
 
        lrb_assert(query != NULL);
 
@@ -102,9 +103,11 @@ client_success(struct auth_client *auth)
 
        rb_free(query);
 
-       set_provider_data(auth, PROVIDER_RDNS, NULL);
-       set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0);
-       provider_done(auth, PROVIDER_RDNS);
+       set_provider_data(auth, SELF_PID, NULL);
+       set_provider_timeout_absolute(auth, SELF_PID, 0);
+       provider_done(auth, SELF_PID);
+
+       auth_client_unref(auth);
 }
 
 static void
@@ -115,8 +118,9 @@ rdns_destroy(void)
 
        RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
        {
-               if(get_provider_data(auth, PROVIDER_RDNS) != NULL)
+               if(get_provider_data(auth, SELF_PID) != NULL)
                        client_fail(auth, REPORT_FAIL);
+               /* auth is now invalid as we have no reference */
        }
 }
 
@@ -125,20 +129,21 @@ rdns_start(struct auth_client *auth)
 {
        struct user_query *query = rb_malloc(sizeof(struct user_query));
 
-       set_provider_data(auth, PROVIDER_RDNS, query);
-       set_provider_timeout_relative(auth, PROVIDER_RDNS, rdns_timeout);
+       auth_client_ref(auth);
+
+       set_provider_data(auth, SELF_PID, query);
+       set_provider_timeout_relative(auth, SELF_PID, rdns_timeout);
 
        query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
 
        notice_client(auth->cid, messages[REPORT_LOOKUP]);
-       set_provider_on(auth, PROVIDER_RDNS);
        return true;
 }
 
 static void
 rdns_cancel(struct auth_client *auth)
 {
-       struct user_query *query = get_provider_data(auth, PROVIDER_RDNS);
+       struct user_query *query = get_provider_data(auth, SELF_PID);
 
        if(query != NULL)
                client_fail(auth, REPORT_FAIL);
@@ -166,7 +171,8 @@ struct auth_opts_handler rdns_options[] =
 
 struct auth_provider rdns_provider =
 {
-       .id = PROVIDER_RDNS,
+       .name = "rdns",
+       .letter = 'R',
        .destroy = rdns_destroy,
        .start = rdns_start,
        .cancel = rdns_cancel,