authd: fix "is provider done" logic in blacklist/opm providers

This fixes #262.
This commit is contained in:
Simon Arlott 2018-08-12 11:05:59 +01:00
parent 258eb31c9c
commit bfd95f010b
No known key found for this signature in database
GPG key ID: 49BFFEEFD4C3ED53
3 changed files with 30 additions and 34 deletions

View file

@ -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)

View 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 */
};
@ -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);
}
}
}

View file

@ -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);
}