]> jfr.im git - irc/charybdis-ircd/charybdis.git/commitdiff
authd: fix "is provider done" logic in blacklist/opm providers
authorSimon Arlott <sa.me.uk>
Sun, 12 Aug 2018 10:05:59 +0000 (11:05 +0100)
committerSimon Arlott <sa.me.uk>
Sun, 12 Aug 2018 10:20:11 +0000 (11:20 +0100)
This fixes #262.

authd/provider.h
authd/providers/blacklist.c
authd/providers/opm.c

index 07b8a794a1508db11070d978f62b5353a01aeb2a..dd6b2487c659fb5b41432fedf93c85c2b789c354 100644 (file)
@@ -191,6 +191,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)
index 1855c1d8cc494fd055355ba6affd47816122c5e2..a0b8be6a4e706fd3af6f0c2f80e69cdc3610d417 100644 (file)
@@ -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 */
 };
 
@@ -317,7 +318,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" : "");
 
@@ -365,11 +366,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;
@@ -379,12 +378,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;
                }
@@ -398,25 +394,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);
+               }
        }
 }
 
index 22b9ba3f174840dec01b558bdb8ba8c0347360fc..29e4a1970ae54fe3726c70e4c5eeabf54eefe1f2 100644 (file)
@@ -595,31 +595,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;
@@ -629,10 +624,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);
        }