From bdddd9ba832ccb67b7f41170b9f61df3cb5dc463 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Mon, 4 Apr 2016 04:32:55 -0500 Subject: [PATCH] authd: update all providers to new timeout API --- authd/providers/blacklist.c | 6 +++--- authd/providers/ident.c | 6 +++--- authd/providers/opm.c | 4 ++-- authd/providers/rdns.c | 31 +++++++++++++++++-------------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/authd/providers/blacklist.c b/authd/providers/blacklist.c index 79561325..d387541e 100644 --- a/authd/providers/blacklist.c +++ b/authd/providers/blacklist.c @@ -261,7 +261,7 @@ blacklist_dns_callback(const char *result, bool status, query_type type, void *d rb_dlink_list_length(&blacklist_list) > 1 ? "s" : ""); rb_free(bluser); set_provider_data(auth, PROVIDER_BLACKLIST, NULL); - auth->timeout[PROVIDER_BLACKLIST] = 0; + set_provider_timeout_absolute(auth, PROVIDER_BLACKLIST, 0); provider_done(auth, PROVIDER_BLACKLIST); } } @@ -311,7 +311,7 @@ lookup_all_blacklists(struct auth_client *auth) initiate_blacklist_dnsquery(bl, auth); } - auth->timeout[PROVIDER_BLACKLIST] = rb_current_time() + blacklist_timeout; + set_provider_timeout_relative(auth, PROVIDER_BLACKLIST, blacklist_timeout); } static inline void @@ -407,7 +407,7 @@ blacklists_cancel(struct auth_client *auth) rb_free(bluser); set_provider_data(auth, PROVIDER_BLACKLIST, NULL); - auth->timeout[PROVIDER_BLACKLIST] = 0; + set_provider_timeout_absolute(auth, PROVIDER_BLACKLIST, 0); provider_done(auth, PROVIDER_BLACKLIST); } diff --git a/authd/providers/ident.c b/authd/providers/ident.c index 6c24ec80..9a31b911 100644 --- a/authd/providers/ident.c +++ b/authd/providers/ident.c @@ -181,7 +181,7 @@ client_fail(struct auth_client *auth, ident_message report) rb_free(query); set_provider_data(auth, PROVIDER_IDENT, NULL); - auth->timeout[PROVIDER_IDENT] = 0; + set_provider_timeout_absolute(auth, PROVIDER_IDENT, 0); notice_client(auth->cid, messages[report]); provider_done(auth, PROVIDER_IDENT); @@ -199,7 +199,7 @@ client_success(struct auth_client *auth) rb_free(query); set_provider_data(auth, PROVIDER_IDENT, NULL); - auth->timeout[PROVIDER_IDENT] = 0; + set_provider_timeout_absolute(auth, PROVIDER_IDENT, 0); notice_client(auth->cid, messages[REPORT_FOUND]); provider_done(auth, PROVIDER_IDENT); @@ -303,7 +303,7 @@ ident_start(struct auth_client *auth) notice_client(auth->cid, messages[REPORT_LOOKUP]); set_provider_data(auth, PROVIDER_IDENT, query); - auth->timeout[PROVIDER_IDENT] = rb_current_time() + ident_timeout; + set_provider_timeout_relative(auth, PROVIDER_IDENT, ident_timeout); if((query->F = rb_socket(family, SOCK_STREAM, 0, "ident")) == NULL) { diff --git a/authd/providers/opm.c b/authd/providers/opm.c index 1dd064f3..1d76f647 100644 --- a/authd/providers/opm.c +++ b/authd/providers/opm.c @@ -618,7 +618,7 @@ opm_scan(struct auth_client *auth) lrb_assert(auth != NULL); lookup = get_provider_data(auth, PROVIDER_OPM); - auth->timeout[PROVIDER_OPM] = rb_current_time() + opm_timeout; + set_provider_timeout_relative(auth, PROVIDER_OPM, opm_timeout); lookup->in_progress = true; @@ -695,7 +695,7 @@ opm_cancel(struct auth_client *auth) rb_free(lookup); set_provider_data(auth, PROVIDER_OPM, NULL); - auth->timeout[PROVIDER_OPM] = 0; + set_provider_timeout_absolute(auth, PROVIDER_OPM, 0); provider_done(auth, PROVIDER_OPM); } } diff --git a/authd/providers/rdns.c b/authd/providers/rdns.c index a00512cd..6338143f 100644 --- a/authd/providers/rdns.c +++ b/authd/providers/rdns.c @@ -58,9 +58,11 @@ static void dns_answer_callback(const char *res, bool status, query_type type, void *data) { 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) + lrb_assert(query != NULL); + + if(res == NULL || status == false) client_fail(auth, REPORT_FAIL); else if(strlen(res) > HOSTLEN) client_fail(auth, REPORT_TOOLONG); @@ -74,10 +76,9 @@ 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 = auth->data[PROVIDER_RDNS]; + struct user_query *query = get_provider_data(auth, PROVIDER_RDNS); - if(query == NULL) - return; + lrb_assert(query != NULL); rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname)); @@ -85,24 +86,26 @@ client_fail(struct auth_client *auth, dns_message report) cancel_query(query->query); rb_free(query); - auth->data[PROVIDER_RDNS] = NULL; - auth->timeout[PROVIDER_RDNS] = 0; + set_provider_data(auth, PROVIDER_RDNS, NULL); + set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0); provider_done(auth, PROVIDER_RDNS); } static void client_success(struct auth_client *auth) { - struct user_query *query = auth->data[PROVIDER_RDNS]; + struct user_query *query = get_provider_data(auth, PROVIDER_RDNS); + + lrb_assert(query != NULL); notice_client(auth->cid, messages[REPORT_FOUND]); cancel_query(query->query); rb_free(query); - auth->data[PROVIDER_RDNS] = NULL; - auth->timeout[PROVIDER_RDNS] = 0; + set_provider_data(auth, PROVIDER_RDNS, NULL); + set_provider_timeout_absolute(auth, PROVIDER_RDNS, 0); provider_done(auth, PROVIDER_RDNS); } @@ -114,7 +117,7 @@ rdns_destroy(void) RB_DICTIONARY_FOREACH(auth, &iter, auth_clients) { - if(auth->data[PROVIDER_RDNS] != NULL) + if(get_provider_data(auth, PROVIDER_RDNS) != NULL) client_fail(auth, REPORT_FAIL); } } @@ -124,8 +127,8 @@ rdns_start(struct auth_client *auth) { struct user_query *query = rb_malloc(sizeof(struct user_query)); - auth->data[PROVIDER_RDNS] = query; - auth->timeout[PROVIDER_RDNS] = rb_current_time() + rdns_timeout; + set_provider_data(auth, PROVIDER_RDNS, query); + set_provider_timeout_relative(auth, PROVIDER_RDNS, rdns_timeout); query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth); @@ -137,7 +140,7 @@ rdns_start(struct auth_client *auth) static void rdns_cancel(struct auth_client *auth) { - struct user_query *query = auth->data[PROVIDER_RDNS]; + struct user_query *query = get_provider_data(auth, PROVIDER_RDNS); if(query != NULL) client_fail(auth, REPORT_FAIL);