From bfd95f010b0aaa29f367e13e617baf49a5b22a70 Mon Sep 17 00:00:00 2001 From: Simon Arlott Date: Sun, 12 Aug 2018 11:05:59 +0100 Subject: [PATCH] authd: fix "is provider done" logic in blacklist/opm providers This fixes #262. --- authd/provider.h | 13 +++++++++++++ authd/providers/blacklist.c | 30 ++++++++++-------------------- authd/providers/opm.c | 21 +++++++-------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/authd/provider.h b/authd/provider.h index 97f177e9..74e1309e 100644 --- a/authd/provider.h +++ b/authd/provider.h @@ -193,6 +193,19 @@ is_provider_done(struct auth_client *auth, uint32_t provider) return get_provider_status(auth, provider) == PROVIDER_STATUS_DONE; } +/* Check if provider doesn't exist or has finished on this client */ +static inline bool +run_after_provider(struct auth_client *auth, const char *name) +{ + uint32_t id; + + if (get_provider_id(name, &id)) { + return get_provider_status(auth, id) == PROVIDER_STATUS_DONE; + } else { + return true; + } +} + /* Get provider auth client data */ static inline void * get_provider_data(struct auth_client *auth, uint32_t id) diff --git a/authd/providers/blacklist.c b/authd/providers/blacklist.c index 1b04bcbc..f105c011 100644 --- a/authd/providers/blacklist.c +++ b/authd/providers/blacklist.c @@ -93,6 +93,7 @@ struct blacklist_filter /* Blacklist user data attached to auth_client instance */ struct blacklist_user { + bool started; rb_dlink_list queries; /* Blacklist queries in flight */ }; @@ -315,7 +316,7 @@ lookup_all_blacklists(struct auth_client *auth) else return false; - + bluser->started = true; notice_client(auth->cid, "*** Checking your IP against DNS blacklist%s", rb_dlink_list_length(&blacklist_list) > 1 ? "s" : ""); @@ -363,11 +364,9 @@ delete_all_blacklists(void) static bool blacklists_start(struct auth_client *auth) { - uint32_t rdns_pid, ident_pid; - lrb_assert(get_provider_data(auth, SELF_PID) == NULL); - if(!rb_dlink_list_length(&blacklist_list)) { + if (!rb_dlink_list_length(&blacklist_list)) { /* Nothing to do... */ provider_done(auth, SELF_PID); return true; @@ -377,12 +376,9 @@ blacklists_start(struct auth_client *auth) set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct blacklist_user))); - if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) && - (!get_provider_id("ident", &ident_pid) || is_provider_done(auth, ident_pid))) - { + if (run_after_provider(auth, "rdns") && run_after_provider(auth, "ident")) { /* Start the lookup if ident and rdns are finished, or not loaded. */ - if(!lookup_all_blacklists(auth)) - { + if (!lookup_all_blacklists(auth)) { blacklists_cancel_none(auth); return true; } @@ -396,25 +392,19 @@ static void blacklists_initiate(struct auth_client *auth, uint32_t provider) { struct blacklist_user *bluser = get_provider_data(auth, SELF_PID); - uint32_t rdns_pid, ident_pid; lrb_assert(provider != SELF_PID); lrb_assert(!is_provider_done(auth, SELF_PID)); lrb_assert(rb_dlink_list_length(&blacklist_list) > 0); - if(bluser == NULL || rb_dlink_list_length(&bluser->queries)) + if (bluser == NULL || bluser->started) { /* Nothing to do */ return; - else if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) && - (!get_provider_id("ident", &ident_pid) || is_provider_done(auth, ident_pid))) - { - /* Don't start until ident and rdns are finished (or not loaded) */ - return; - } - else - { - if(!lookup_all_blacklists(auth)) + } else if (run_after_provider(auth, "rdns") && run_after_provider(auth, "ident")) { + /* Start the lookup if ident and rdns are finished, or not loaded. */ + if (!lookup_all_blacklists(auth)) { blacklists_cancel_none(auth); + } } } diff --git a/authd/providers/opm.c b/authd/providers/opm.c index 72c6035d..5476ed3d 100644 --- a/authd/providers/opm.c +++ b/authd/providers/opm.c @@ -585,31 +585,26 @@ static void opm_initiate(struct auth_client *auth, uint32_t provider) { struct opm_lookup *lookup = get_provider_data(auth, SELF_PID); - uint32_t rdns_pid, ident_pid; lrb_assert(provider != SELF_PID); lrb_assert(!is_provider_done(auth, SELF_PID)); lrb_assert(rb_dlink_list_length(&proxy_scanners) > 0); - if(lookup == NULL || lookup->in_progress) + if (lookup == NULL || lookup->in_progress) { /* Nothing to do */ return; - else if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) && - (!get_provider_id("ident", &ident_pid) || is_provider_done(auth, ident_pid))) - /* Don't start until ident and rdns are finished (or not loaded) */ - return; - else + } else if (run_after_provider(auth, "rdns") && run_after_provider(auth,"ident")) { + /* Start scanning if ident and rdns are finished, or not loaded. */ opm_scan(auth); + } } static bool opm_start(struct auth_client *auth) { - uint32_t rdns_pid, ident_pid; - lrb_assert(get_provider_data(auth, SELF_PID) == NULL); - if(!opm_enable || rb_dlink_list_length(&proxy_scanners) == 0) { + if (!opm_enable || rb_dlink_list_length(&proxy_scanners) == 0) { /* Nothing to do... */ provider_done(auth, SELF_PID); return true; @@ -619,10 +614,8 @@ opm_start(struct auth_client *auth) set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct opm_lookup))); - if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) && - (!get_provider_id("ident", &ident_pid) || is_provider_done(auth, ident_pid))) - { - /* Don't start until ident and rdns are finished (or not loaded) */ + if (run_after_provider(auth, "rdns") && run_after_provider(auth, "ident")) { + /* Start scanning if ident and rdns are finished, or not loaded. */ opm_scan(auth); }