diff --git a/authd/provider.c b/authd/provider.c index 43475170..58294488 100644 --- a/authd/provider.c +++ b/authd/provider.c @@ -165,6 +165,7 @@ cancel_providers(struct auth_client *auth) } rb_dictionary_delete(auth_clients, RB_UINT_TO_POINTER(auth->cid)); + rb_free(auth->data); rb_free(auth); } @@ -285,7 +286,8 @@ start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname)); rb_strlcpy(auth->username, "*", sizeof(auth->username)); - memset(auth->data, 0, sizeof(auth->data)); + auth->data = rb_malloc(rb_dlink_list_length(&auth_providers) * + sizeof(struct auth_client_data)); auth->providers_starting = true; RB_DLINK_FOREACH(ptr, auth_providers.head) @@ -364,7 +366,7 @@ provider_timeout_event(void *notused __unused) RB_DLINK_FOREACH(ptr, auth_providers.head) { struct auth_provider *provider = ptr->data; - const time_t timeout = auth->timeout[provider->id]; + const time_t timeout = get_provider_timeout(auth, provider->id); if(is_provider_on(auth, provider->id) && provider->timeout != NULL && timeout > 0 && timeout < curtime) @@ -379,27 +381,33 @@ void * get_provider_data(struct auth_client *auth, uint32_t id) { lrb_assert(id < rb_dlink_list_length(&auth_providers)); - return auth->data[(size_t)id]; + return auth->data[id].data; } void set_provider_data(struct auth_client *auth, uint32_t id, void *data) { lrb_assert(id < rb_dlink_list_length(&auth_providers)); - auth->data[(size_t)id] = data; + auth->data[id].data = data; } void set_provider_timeout_relative(struct auth_client *auth, uint32_t id, time_t timeout) { lrb_assert(id < rb_dlink_list_length(&auth_providers)); - auth->timeout[(size_t)id] = timeout + rb_current_time(); + auth->data[id].timeout = timeout + rb_current_time(); } void set_provider_timeout_absolute(struct auth_client *auth, uint32_t id, time_t timeout) { lrb_assert(id < rb_dlink_list_length(&auth_providers)); - auth->timeout[(size_t)id] = timeout; + auth->data[id].timeout = timeout; } +time_t +get_provider_timeout(struct auth_client *auth, uint32_t id) +{ + lrb_assert(id < rb_dlink_list_length(&auth_providers)); + return auth->data[id].timeout; +} diff --git a/authd/provider.h b/authd/provider.h index 8e9a7863..3e57fa18 100644 --- a/authd/provider.h +++ b/authd/provider.h @@ -36,6 +36,12 @@ typedef enum PROVIDER_OPM, } provider_t; +struct auth_client_data +{ + time_t timeout; /* Provider timeout */ + void *data; /* Proivder data */ +}; + struct auth_client { uint16_t cid; /* Client ID */ @@ -56,8 +62,7 @@ struct auth_client uint32_t providers_done; /* Providers completed */ bool providers_starting; /* Providers are still warming up */ - void *data[MAX_PROVIDERS]; /* Provider-specific data slots */ - time_t timeout[MAX_PROVIDERS]; /* When to call timeout callback */ + struct auth_client_data *data; /* Provider-specific data */ }; typedef bool (*provider_init_t)(void); @@ -119,6 +124,7 @@ void *get_provider_data(struct auth_client *auth, uint32_t id); void set_provider_data(struct auth_client *auth, uint32_t id, void *data); void set_provider_timeout_relative(struct auth_client *auth, uint32_t id, time_t timeout); void set_provider_timeout_absolute(struct auth_client *auth, uint32_t id, time_t timeout); +time_t get_provider_timeout(struct auth_client *auth, uint32_t id); /* Provider is operating on this auth_client (set this if you have async work to do) */ static inline void