mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 18:22:50 +01:00
authd: Only use refcount for reference counting
Use providers_active for provider activity tracking.
This commit is contained in:
parent
2392770f4d
commit
a5f52774bb
6 changed files with 54 additions and 9 deletions
|
@ -87,9 +87,13 @@ destroy_providers(void)
|
||||||
/* Cancel outstanding connections */
|
/* Cancel outstanding connections */
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
/* TBD - is this the right thing? */
|
/* TBD - is this the right thing? */
|
||||||
reject_client(auth, UINT32_MAX, "destroy",
|
reject_client(auth, UINT32_MAX, "destroy",
|
||||||
"Authentication system is down... try reconnecting in a few seconds");
|
"Authentication system is down... try reconnecting in a few seconds");
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
RB_DLINK_FOREACH_SAFE(ptr, nptr, auth_providers.head)
|
RB_DLINK_FOREACH_SAFE(ptr, nptr, auth_providers.head)
|
||||||
|
@ -187,7 +191,7 @@ cancel_providers(struct auth_client *auth)
|
||||||
|
|
||||||
auth->providers_cancelled = true;
|
auth->providers_cancelled = true;
|
||||||
|
|
||||||
if(auth->refcount > 0)
|
if(auth->providers_active > 0)
|
||||||
{
|
{
|
||||||
rb_dlink_node *ptr;
|
rb_dlink_node *ptr;
|
||||||
|
|
||||||
|
@ -215,7 +219,7 @@ provider_done(struct auth_client *auth, uint32_t id)
|
||||||
|
|
||||||
set_provider_done(auth, id);
|
set_provider_done(auth, id);
|
||||||
|
|
||||||
if(auth->refcount == 0 && !auth->providers_starting)
|
if(auth->providers_active == 0 && !auth->providers_starting)
|
||||||
{
|
{
|
||||||
/* All done */
|
/* All done */
|
||||||
accept_client(auth, UINT32_MAX);
|
accept_client(auth, UINT32_MAX);
|
||||||
|
@ -237,7 +241,6 @@ provider_done(struct auth_client *auth, uint32_t id)
|
||||||
void
|
void
|
||||||
reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...)
|
reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
unsigned int refcount = auth->refcount;
|
|
||||||
char buf[BUFSIZE];
|
char buf[BUFSIZE];
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
@ -265,8 +268,6 @@ reject_client(struct auth_client *auth, uint32_t id, const char *data, const cha
|
||||||
void
|
void
|
||||||
accept_client(struct auth_client *auth, uint32_t id)
|
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);
|
rb_helper_write(authd_helper, "A %x %s %s", auth->cid, auth->username, auth->hostname);
|
||||||
|
|
||||||
if(id != UINT32_MAX)
|
if(id != UINT32_MAX)
|
||||||
|
@ -287,6 +288,7 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auth = rb_malloc(sizeof(struct auth_client));
|
auth = rb_malloc(sizeof(struct auth_client));
|
||||||
|
auth_client_ref(auth);
|
||||||
auth->cid = (uint32_t)lcid;
|
auth->cid = (uint32_t)lcid;
|
||||||
|
|
||||||
if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
|
if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
|
||||||
|
@ -328,7 +330,7 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
|
||||||
/* Execute providers */
|
/* Execute providers */
|
||||||
if(!provider->start(auth))
|
if(!provider->start(auth))
|
||||||
/* Rejected immediately */
|
/* Rejected immediately */
|
||||||
return;
|
goto done;
|
||||||
|
|
||||||
if(auth->providers_cancelled)
|
if(auth->providers_cancelled)
|
||||||
break;
|
break;
|
||||||
|
@ -336,8 +338,11 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_
|
||||||
auth->providers_starting = false;
|
auth->providers_starting = false;
|
||||||
|
|
||||||
/* If no providers are running, accept the client */
|
/* If no providers are running, accept the client */
|
||||||
if(auth->refcount == 0)
|
if(auth->providers_active == 0)
|
||||||
accept_client(auth, UINT32_MAX);
|
accept_client(auth, UINT32_MAX);
|
||||||
|
|
||||||
|
done:
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Callback for the initiation */
|
/* Callback for the initiation */
|
||||||
|
@ -379,7 +384,9 @@ handle_cancel_connection(int parc, char *parv[])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
cancel_providers(auth);
|
cancel_providers(auth);
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -393,6 +400,8 @@ provider_timeout_event(void *notused __unused)
|
||||||
{
|
{
|
||||||
rb_dlink_node *ptr;
|
rb_dlink_node *ptr;
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
||||||
{
|
{
|
||||||
struct auth_provider *provider = ptr->data;
|
struct auth_provider *provider = ptr->data;
|
||||||
|
@ -404,5 +413,7 @@ provider_timeout_event(void *notused __unused)
|
||||||
provider->timeout(auth);
|
provider->timeout(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ struct auth_client
|
||||||
|
|
||||||
bool providers_starting; /* Providers are still warming up */
|
bool providers_starting; /* Providers are still warming up */
|
||||||
bool providers_cancelled; /* Providers are being cancelled */
|
bool providers_cancelled; /* Providers are being cancelled */
|
||||||
|
unsigned int providers_active; /* Number of active providers */
|
||||||
unsigned int refcount; /* Held references */
|
unsigned int refcount; /* Held references */
|
||||||
|
|
||||||
struct auth_client_data *data; /* Provider-specific data */
|
struct auth_client_data *data; /* Provider-specific data */
|
||||||
|
@ -188,7 +189,7 @@ set_provider_status(struct auth_client *auth, uint32_t provider, provider_status
|
||||||
static inline void
|
static inline void
|
||||||
set_provider_running(struct auth_client *auth, uint32_t provider)
|
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_status(auth, provider, PROVIDER_STATUS_RUNNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +199,7 @@ static inline void
|
||||||
set_provider_done(struct auth_client *auth, uint32_t provider)
|
set_provider_done(struct auth_client *auth, uint32_t provider)
|
||||||
{
|
{
|
||||||
set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
|
set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
|
||||||
auth_client_unref(auth);
|
auth->providers_active--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if provider is operating on this auth client */
|
/* Check if provider is operating on this auth client */
|
||||||
|
|
|
@ -266,6 +266,8 @@ blacklist_dns_callback(const char *result, bool status, query_type type, void *d
|
||||||
set_provider_data(auth, SELF_PID, NULL);
|
set_provider_data(auth, SELF_PID, NULL);
|
||||||
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +354,8 @@ blacklists_start(struct auth_client *auth)
|
||||||
/* Nothing to do... */
|
/* Nothing to do... */
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct blacklist_user)));
|
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)) &&
|
if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) &&
|
||||||
|
@ -416,6 +420,8 @@ blacklists_cancel(struct auth_client *auth)
|
||||||
set_provider_data(auth, SELF_PID, NULL);
|
set_provider_data(auth, SELF_PID, NULL);
|
||||||
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -427,6 +433,7 @@ blacklists_destroy(void)
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
blacklists_cancel(auth);
|
blacklists_cancel(auth);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
|
|
||||||
delete_all_blacklists();
|
delete_all_blacklists();
|
||||||
|
|
|
@ -188,6 +188,8 @@ client_fail(struct auth_client *auth, ident_message report)
|
||||||
|
|
||||||
notice_client(auth->cid, messages[report]);
|
notice_client(auth->cid, messages[report]);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -206,6 +208,8 @@ client_success(struct auth_client *auth)
|
||||||
|
|
||||||
notice_client(auth->cid, messages[REPORT_FOUND]);
|
notice_client(auth->cid, messages[REPORT_FOUND]);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get_valid_ident
|
/* get_valid_ident
|
||||||
|
@ -283,6 +287,7 @@ ident_destroy(void)
|
||||||
{
|
{
|
||||||
if(get_provider_data(auth, SELF_PID) != NULL)
|
if(get_provider_data(auth, SELF_PID) != NULL)
|
||||||
client_fail(auth, REPORT_FAIL);
|
client_fail(auth, REPORT_FAIL);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,6 +308,8 @@ ident_start(struct auth_client *auth)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
notice_client(auth->cid, messages[REPORT_LOOKUP]);
|
notice_client(auth->cid, messages[REPORT_LOOKUP]);
|
||||||
|
|
||||||
set_provider_data(auth, SELF_PID, query);
|
set_provider_data(auth, SELF_PID, query);
|
||||||
|
|
|
@ -563,6 +563,7 @@ create_listener(const char *ip, uint16_t port)
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
opm_cancel(auth);
|
opm_cancel(auth);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy data */
|
/* Copy data */
|
||||||
|
@ -631,6 +632,8 @@ opm_start(struct auth_client *auth)
|
||||||
/* Nothing to do... */
|
/* Nothing to do... */
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
set_provider_data(auth, SELF_PID, rb_malloc(sizeof(struct opm_lookup)));
|
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)) &&
|
if((!get_provider_id("rdns", &rdns_pid) || is_provider_done(auth, rdns_pid)) &&
|
||||||
|
@ -668,6 +671,8 @@ opm_cancel(struct auth_client *auth)
|
||||||
set_provider_data(auth, SELF_PID, NULL);
|
set_provider_data(auth, SELF_PID, NULL);
|
||||||
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,6 +686,7 @@ opm_destroy(void)
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
opm_cancel(auth);
|
opm_cancel(auth);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,6 +729,7 @@ set_opm_enabled(const char *key __unused, int parc __unused, const char **parv)
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
opm_cancel(auth);
|
opm_cancel(auth);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -847,6 +854,8 @@ delete_opm_scanner(const char *key __unused, int parc __unused, const char **par
|
||||||
if(lookup == NULL)
|
if(lookup == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
RB_DLINK_FOREACH(ptr, lookup->scans.head)
|
RB_DLINK_FOREACH(ptr, lookup->scans.head)
|
||||||
{
|
{
|
||||||
struct opm_scan *scan = ptr->data;
|
struct opm_scan *scan = ptr->data;
|
||||||
|
@ -863,6 +872,8 @@ delete_opm_scanner(const char *key __unused, int parc __unused, const char **par
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_dlinkDelete(&proxy->node, &proxy_scanners);
|
rb_dlinkDelete(&proxy->node, &proxy_scanners);
|
||||||
|
@ -888,6 +899,7 @@ delete_opm_scanner_all(const char *key __unused, int parc __unused, const char *
|
||||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||||
{
|
{
|
||||||
opm_cancel(auth);
|
opm_cancel(auth);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
|
|
||||||
opm_enable = false;
|
opm_enable = false;
|
||||||
|
|
|
@ -90,6 +90,8 @@ client_fail(struct auth_client *auth, dns_message report)
|
||||||
set_provider_data(auth, SELF_PID, NULL);
|
set_provider_data(auth, SELF_PID, NULL);
|
||||||
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -107,6 +109,8 @@ client_success(struct auth_client *auth)
|
||||||
set_provider_data(auth, SELF_PID, NULL);
|
set_provider_data(auth, SELF_PID, NULL);
|
||||||
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
set_provider_timeout_absolute(auth, SELF_PID, 0);
|
||||||
provider_done(auth, SELF_PID);
|
provider_done(auth, SELF_PID);
|
||||||
|
|
||||||
|
auth_client_unref(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -119,6 +123,7 @@ rdns_destroy(void)
|
||||||
{
|
{
|
||||||
if(get_provider_data(auth, SELF_PID) != NULL)
|
if(get_provider_data(auth, SELF_PID) != NULL)
|
||||||
client_fail(auth, REPORT_FAIL);
|
client_fail(auth, REPORT_FAIL);
|
||||||
|
/* auth is now invalid as we have no reference */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +132,8 @@ rdns_start(struct auth_client *auth)
|
||||||
{
|
{
|
||||||
struct user_query *query = rb_malloc(sizeof(struct user_query));
|
struct user_query *query = rb_malloc(sizeof(struct user_query));
|
||||||
|
|
||||||
|
auth_client_ref(auth);
|
||||||
|
|
||||||
set_provider_data(auth, SELF_PID, query);
|
set_provider_data(auth, SELF_PID, query);
|
||||||
set_provider_timeout_relative(auth, SELF_PID, rdns_timeout);
|
set_provider_timeout_relative(auth, SELF_PID, rdns_timeout);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue