Use providers_active for provider activity tracking.
/* Cancel outstanding connections */
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
+ auth_client_ref(auth);
+
/* TBD - is this the right thing? */
reject_client(auth, UINT32_MAX, "destroy",
"Authentication system is down... try reconnecting in a few seconds");
+
+ auth_client_unref(auth);
}
RB_DLINK_FOREACH_SAFE(ptr, nptr, auth_providers.head)
auth->providers_cancelled = true;
- if(auth->refcount > 0)
+ if(auth->providers_active > 0)
{
rb_dlink_node *ptr;
set_provider_done(auth, id);
- if(auth->refcount == 0 && !auth->providers_starting)
+ if(auth->providers_active == 0 && !auth->providers_starting)
{
/* All done */
accept_client(auth, UINT32_MAX);
void
reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...)
{
- unsigned int refcount = auth->refcount;
char buf[BUFSIZE];
va_list args;
void
accept_client(struct auth_client *auth, uint32_t id)
{
- unsigned int refcount = auth->refcount;
-
rb_helper_write(authd_helper, "A %x %s %s", auth->cid, auth->username, auth->hostname);
if(id != UINT32_MAX)
return;
auth = rb_malloc(sizeof(struct auth_client));
+ auth_client_ref(auth);
auth->cid = (uint32_t)lcid;
if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
/* Execute providers */
if(!provider->start(auth))
/* Rejected immediately */
- return;
+ goto done;
if(auth->providers_cancelled)
break;
auth->providers_starting = false;
/* If no providers are running, accept the client */
- if(auth->refcount == 0)
+ if(auth->providers_active == 0)
accept_client(auth, UINT32_MAX);
+
+done:
+ auth_client_unref(auth);
}
/* Callback for the initiation */
return;
}
+ auth_client_ref(auth);
cancel_providers(auth);
+ auth_client_unref(auth);
}
static void
{
rb_dlink_node *ptr;
+ auth_client_ref(auth);
+
RB_DLINK_FOREACH(ptr, auth_providers.head)
{
struct auth_provider *provider = ptr->data;
provider->timeout(auth);
}
}
+
+ auth_client_unref(auth);
}
}
bool providers_starting; /* Providers are still warming up */
bool providers_cancelled; /* Providers are being cancelled */
+ unsigned int providers_active; /* Number of active providers */
unsigned int refcount; /* Held references */
struct auth_client_data *data; /* Provider-specific data */
static inline void
set_provider_running(struct auth_client *auth, uint32_t provider)
{
- auth_client_ref(auth);
+ auth->providers_active++;
set_provider_status(auth, provider, PROVIDER_STATUS_RUNNING);
}
set_provider_done(struct auth_client *auth, uint32_t provider)
{
set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
- auth_client_unref(auth);
+ auth->providers_active--;
}
/* Check if provider is operating on this auth client */
set_provider_data(auth, SELF_PID, NULL);
set_provider_timeout_absolute(auth, SELF_PID, 0);
provider_done(auth, SELF_PID);
+
+ auth_client_unref(auth);
}
}
/* Nothing to do... */
return true;
+ auth_client_ref(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)) &&
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
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
blacklists_cancel(auth);
+ /* auth is now invalid as we have no reference */
}
delete_all_blacklists();
notice_client(auth->cid, messages[report]);
provider_done(auth, SELF_PID);
+
+ auth_client_unref(auth);
}
static void
notice_client(auth->cid, messages[REPORT_FOUND]);
provider_done(auth, SELF_PID);
+
+ auth_client_unref(auth);
}
/* get_valid_ident
{
if(get_provider_data(auth, SELF_PID) != NULL)
client_fail(auth, REPORT_FAIL);
+ /* auth is now invalid as we have no reference */
}
}
return true;
}
+ auth_client_ref(auth);
+
notice_client(auth->cid, messages[REPORT_LOOKUP]);
set_provider_data(auth, SELF_PID, query);
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
opm_cancel(auth);
+ /* auth is now invalid as we have no reference */
}
/* Copy data */
/* Nothing to do... */
return true;
+ auth_client_ref(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)) &&
set_provider_data(auth, SELF_PID, NULL);
set_provider_timeout_absolute(auth, SELF_PID, 0);
provider_done(auth, SELF_PID);
+
+ auth_client_unref(auth);
}
}
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
opm_cancel(auth);
+ /* auth is now invalid as we have no reference */
}
}
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
opm_cancel(auth);
+ /* auth is now invalid as we have no reference */
}
}
}
if(lookup == NULL)
continue;
+ auth_client_ref(auth);
+
RB_DLINK_FOREACH(ptr, lookup->scans.head)
{
struct opm_scan *scan = ptr->data;
break;
}
}
+
+ auth_client_unref(auth);
}
rb_dlinkDelete(&proxy->node, &proxy_scanners);
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
{
opm_cancel(auth);
+ /* auth is now invalid as we have no reference */
}
opm_enable = false;
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
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
{
if(get_provider_data(auth, SELF_PID) != NULL)
client_fail(auth, REPORT_FAIL);
+ /* auth is now invalid as we have no reference */
}
}
{
struct user_query *query = rb_malloc(sizeof(struct user_query));
+ auth_client_ref(auth);
+
set_provider_data(auth, SELF_PID, query);
set_provider_timeout_relative(auth, SELF_PID, rdns_timeout);