2016-03-17 21:23:27 +00:00
|
|
|
/* authd/provider.c - authentication provider framework
|
|
|
|
* Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice is present in all copies.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-03-25 00:23:49 +00:00
|
|
|
/* The basic design here is to have "authentication providers" that do things
|
|
|
|
* like query ident and blacklists and even open proxies.
|
2016-03-17 21:23:27 +00:00
|
|
|
*
|
2016-03-19 20:02:11 +00:00
|
|
|
* Providers are registered in the auth_providers linked list. It is planned to
|
|
|
|
* use a bitmap to store provider ID's later.
|
2016-03-17 21:23:27 +00:00
|
|
|
*
|
2016-03-25 00:23:49 +00:00
|
|
|
* Providers can either return failure immediately, immediate acceptance, or do
|
|
|
|
* work in the background (calling set_provider to signal this).
|
2016-03-17 21:23:27 +00:00
|
|
|
*
|
2016-03-23 00:13:54 +00:00
|
|
|
* Provider-specific data for each client can be kept in an index of the data
|
|
|
|
* struct member (using the provider's ID).
|
2016-03-17 21:23:27 +00:00
|
|
|
*
|
|
|
|
* All providers must implement at a minimum a perform_provider function. You
|
|
|
|
* don't have to implement the others if you don't need them.
|
|
|
|
*
|
|
|
|
* Providers may kick clients off by rejecting them. Upon rejection, all
|
|
|
|
* providers are cancelled. They can also unconditionally accept them.
|
|
|
|
*
|
|
|
|
* When a provider is done and is neutral on accepting/rejecting a client, it
|
|
|
|
* should call provider_done. Do NOT call this if you have accepted or rejected
|
|
|
|
* the client.
|
|
|
|
*
|
2016-03-25 00:23:49 +00:00
|
|
|
* Eventually, stuff like *:line handling will be moved here, but that means we
|
|
|
|
* have to talk to bandb directly first.
|
|
|
|
*
|
2016-03-17 21:23:27 +00:00
|
|
|
* --Elizafox, 9 March 2016
|
|
|
|
*/
|
|
|
|
|
2016-03-30 07:22:43 +00:00
|
|
|
#include "stdinc.h"
|
2016-05-01 00:20:12 +00:00
|
|
|
#include "rb_dictionary.h"
|
2016-05-01 09:49:12 +00:00
|
|
|
#include "rb_lib.h"
|
2016-03-17 21:23:27 +00:00
|
|
|
#include "authd.h"
|
|
|
|
#include "provider.h"
|
2016-03-26 02:29:44 +00:00
|
|
|
#include "notice.h"
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-30 22:20:27 +00:00
|
|
|
static EVH provider_timeout_event;
|
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
rb_dictionary *auth_clients;
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_list auth_providers;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-04-05 09:31:22 +00:00
|
|
|
static rb_dlink_list free_pids;
|
2016-05-01 10:38:32 +00:00
|
|
|
static uint32_t allocated_pids;
|
2016-03-30 22:20:27 +00:00
|
|
|
static struct ev_entry *timeout_ev;
|
|
|
|
|
2017-08-20 11:53:44 +00:00
|
|
|
/* Set a provider's raw status */
|
|
|
|
static inline void
|
|
|
|
set_provider_status(struct auth_client *auth, uint32_t provider, provider_status_t status)
|
|
|
|
{
|
|
|
|
auth->data[provider].status = status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the provider as running */
|
|
|
|
static inline void
|
|
|
|
set_provider_running(struct auth_client *auth, uint32_t provider)
|
|
|
|
{
|
|
|
|
auth->providers_active++;
|
|
|
|
set_provider_status(auth, provider, PROVIDER_STATUS_RUNNING);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Provider is no longer operating on this auth client */
|
|
|
|
static inline void
|
|
|
|
set_provider_done(struct auth_client *auth, uint32_t provider)
|
|
|
|
{
|
|
|
|
set_provider_status(auth, provider, PROVIDER_STATUS_DONE);
|
|
|
|
auth->providers_active--;
|
|
|
|
}
|
|
|
|
|
2016-04-05 09:31:22 +00:00
|
|
|
/* Initalise all providers */
|
|
|
|
void
|
|
|
|
init_providers(void)
|
|
|
|
{
|
2016-05-01 00:20:12 +00:00
|
|
|
auth_clients = rb_dictionary_create("pending auth clients", rb_uint32cmp);
|
2016-04-05 09:31:22 +00:00
|
|
|
timeout_ev = rb_event_addish("provider_timeout_event", provider_timeout_event, NULL, 1);
|
|
|
|
|
2017-08-20 11:53:44 +00:00
|
|
|
/* FIXME must be started before rdns/ident to receive completion notification from them */
|
2016-04-05 09:31:22 +00:00
|
|
|
load_provider(&blacklist_provider);
|
|
|
|
load_provider(&opm_provider);
|
2017-08-20 11:53:44 +00:00
|
|
|
|
|
|
|
/* FIXME must be started after blacklist/opm in case of early completion notifications */
|
|
|
|
load_provider(&rdns_provider);
|
|
|
|
load_provider(&ident_provider);
|
2016-04-05 09:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Terminate all providers */
|
|
|
|
void
|
|
|
|
destroy_providers(void)
|
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_node *ptr, *nptr;
|
2016-05-01 00:20:12 +00:00
|
|
|
rb_dictionary_iter iter;
|
|
|
|
struct auth_client *auth;
|
2016-04-05 09:31:22 +00:00
|
|
|
|
|
|
|
/* Cancel outstanding connections */
|
2016-05-01 00:20:12 +00:00
|
|
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
2016-04-05 09:31:22 +00:00
|
|
|
{
|
2016-05-01 10:31:05 +00:00
|
|
|
auth_client_ref(auth);
|
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
/* TBD - is this the right thing? */
|
2016-04-06 16:43:05 +00:00
|
|
|
reject_client(auth, UINT32_MAX, "destroy",
|
|
|
|
"Authentication system is down... try reconnecting in a few seconds");
|
2016-05-01 10:31:05 +00:00
|
|
|
|
|
|
|
auth_client_unref(auth);
|
2016-04-05 09:31:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
RB_DLINK_FOREACH_SAFE(ptr, nptr, auth_providers.head)
|
2016-04-05 09:31:22 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
struct auth_provider *provider = ptr->data;
|
|
|
|
|
2016-04-05 09:31:22 +00:00
|
|
|
if(provider->destroy)
|
|
|
|
provider->destroy();
|
2016-05-01 09:49:12 +00:00
|
|
|
|
|
|
|
rb_dlinkDelete(ptr, &auth_providers);
|
2016-04-05 09:31:22 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
rb_dictionary_destroy(auth_clients, NULL, NULL);
|
2016-04-05 09:31:22 +00:00
|
|
|
rb_event_delete(timeout_ev);
|
|
|
|
}
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
/* Load a provider */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
|
|
|
load_provider(struct auth_provider *provider)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-04-05 09:31:22 +00:00
|
|
|
/* Assign a PID */
|
|
|
|
if(rb_dlink_list_length(&free_pids) > 0)
|
2016-03-25 00:36:41 +00:00
|
|
|
{
|
2016-04-05 09:31:22 +00:00
|
|
|
/* use the free list */
|
|
|
|
provider->id = RB_POINTER_TO_UINT(free_pids.head->data);
|
|
|
|
rb_dlinkDestroy(free_pids.head, &free_pids);
|
2016-03-25 00:36:41 +00:00
|
|
|
}
|
2016-04-05 09:31:22 +00:00
|
|
|
else
|
2016-04-06 16:43:05 +00:00
|
|
|
{
|
2016-05-01 10:38:32 +00:00
|
|
|
if(allocated_pids == MAX_PROVIDERS || allocated_pids == UINT32_MAX)
|
2016-04-06 16:43:05 +00:00
|
|
|
{
|
|
|
|
warn_opers(L_WARN, "Cannot load additional provider, max reached!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-01 10:38:32 +00:00
|
|
|
provider->id = allocated_pids++;
|
2016-04-06 16:43:05 +00:00
|
|
|
}
|
2016-03-23 00:13:54 +00:00
|
|
|
|
2016-03-26 04:04:00 +00:00
|
|
|
if(provider->opt_handlers != NULL)
|
|
|
|
{
|
|
|
|
struct auth_opts_handler *handler;
|
|
|
|
|
|
|
|
for(handler = provider->opt_handlers; handler->option != NULL; handler++)
|
|
|
|
rb_dictionary_add(authd_option_handlers, handler->option, handler);
|
|
|
|
}
|
|
|
|
|
2016-03-27 22:15:08 +00:00
|
|
|
if(provider->stats_handler.letter != '\0')
|
2016-04-23 03:06:42 +00:00
|
|
|
authd_stat_handlers[(unsigned char)provider->stats_handler.letter] = provider->stats_handler.handler;
|
2016-03-27 22:15:08 +00:00
|
|
|
|
2016-03-31 04:17:21 +00:00
|
|
|
if(provider->init != NULL)
|
|
|
|
provider->init();
|
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlinkAdd(provider, &provider->node, &auth_providers);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
|
|
|
unload_provider(struct auth_provider *provider)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-26 04:04:00 +00:00
|
|
|
if(provider->opt_handlers != NULL)
|
|
|
|
{
|
|
|
|
struct auth_opts_handler *handler;
|
|
|
|
|
|
|
|
for(handler = provider->opt_handlers; handler->option != NULL; handler++)
|
|
|
|
rb_dictionary_delete(authd_option_handlers, handler->option);
|
|
|
|
}
|
2016-03-27 22:15:08 +00:00
|
|
|
|
|
|
|
if(provider->stats_handler.letter != '\0')
|
2016-04-23 03:06:42 +00:00
|
|
|
authd_stat_handlers[(unsigned char)provider->stats_handler.letter] = NULL;
|
2016-03-27 22:15:08 +00:00
|
|
|
|
2016-03-31 04:17:21 +00:00
|
|
|
if(provider->destroy != NULL)
|
|
|
|
provider->destroy();
|
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlinkDelete(&provider->node, &auth_providers);
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-04-05 09:31:22 +00:00
|
|
|
/* Reclaim ID */
|
|
|
|
rb_dlinkAddAlloc(RB_UINT_TO_POINTER(provider->id), &free_pids);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 00:26:02 +00:00
|
|
|
void
|
|
|
|
auth_client_free(struct auth_client *auth)
|
|
|
|
{
|
|
|
|
rb_dictionary_delete(auth_clients, RB_UINT_TO_POINTER(auth->cid));
|
|
|
|
rb_free(auth->data);
|
|
|
|
rb_free(auth);
|
|
|
|
}
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-05-01 00:26:02 +00:00
|
|
|
/* Cancel outstanding providers for a client (if any). */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
|
|
|
cancel_providers(struct auth_client *auth)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:53:34 +00:00
|
|
|
if(auth->providers_cancelled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
auth->providers_cancelled = true;
|
|
|
|
|
2016-05-01 10:31:05 +00:00
|
|
|
if(auth->providers_active > 0)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_node *ptr;
|
2016-04-06 16:43:05 +00:00
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
2016-04-06 16:43:05 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
struct auth_provider *provider = ptr->data;
|
|
|
|
|
2016-04-06 16:43:05 +00:00
|
|
|
if(provider->cancel != NULL && is_provider_running(auth, provider->id))
|
|
|
|
/* Cancel if required */
|
|
|
|
provider->cancel(auth);
|
|
|
|
}
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 10:50:26 +00:00
|
|
|
/* Provider is done */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
2016-04-05 09:31:22 +00:00
|
|
|
provider_done(struct auth_client *auth, uint32_t id)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_node *ptr;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-04-06 16:43:05 +00:00
|
|
|
lrb_assert(is_provider_running(auth, id));
|
|
|
|
lrb_assert(id != UINT32_MAX);
|
2016-05-01 10:38:32 +00:00
|
|
|
lrb_assert(id < allocated_pids);
|
2016-04-06 16:43:05 +00:00
|
|
|
|
|
|
|
set_provider_done(auth, id);
|
|
|
|
|
2016-05-01 10:31:05 +00:00
|
|
|
if(auth->providers_active == 0 && !auth->providers_starting)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-04-06 16:43:05 +00:00
|
|
|
/* All done */
|
2016-05-01 10:44:04 +00:00
|
|
|
accept_client(auth);
|
2016-03-17 21:23:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
struct auth_provider *provider = ptr->data;
|
|
|
|
|
2016-04-05 08:30:02 +00:00
|
|
|
if(provider->completed != NULL && is_provider_running(auth, provider->id))
|
2016-03-17 21:23:27 +00:00
|
|
|
/* Notify pending clients who asked for it */
|
|
|
|
provider->completed(auth, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-01 10:50:26 +00:00
|
|
|
/* Reject a client and cancel any outstanding providers */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
2016-04-05 09:31:22 +00:00
|
|
|
reject_client(struct auth_client *auth, uint32_t id, const char *data, const char *fmt, ...)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-30 06:29:21 +00:00
|
|
|
char buf[BUFSIZE];
|
|
|
|
va_list args;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-30 08:38:30 +00:00
|
|
|
va_start(args, fmt);
|
2016-03-30 06:29:21 +00:00
|
|
|
vsnprintf(buf, sizeof(buf), fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
2016-03-26 02:08:46 +00:00
|
|
|
/* We send back username and hostname in case ircd wants to overrule our decision.
|
|
|
|
* In the future this may not be the case.
|
|
|
|
* --Elizafox
|
|
|
|
*/
|
2016-04-05 09:31:22 +00:00
|
|
|
rb_helper_write(authd_helper, "R %x %c %s %s %s :%s",
|
2016-05-01 10:50:26 +00:00
|
|
|
auth->cid, id != UINT32_MAX ? auth->data[id].provider->letter : '*',
|
2016-04-05 09:31:22 +00:00
|
|
|
auth->username, auth->hostname,
|
2016-04-06 16:43:05 +00:00
|
|
|
data == NULL ? "*" : data, buf);
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-04-06 16:43:05 +00:00
|
|
|
if(id != UINT32_MAX)
|
|
|
|
set_provider_done(auth, id);
|
|
|
|
|
|
|
|
cancel_providers(auth);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 10:44:04 +00:00
|
|
|
/* Accept a client and cancel outstanding providers if any */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
2016-05-01 10:44:04 +00:00
|
|
|
accept_client(struct auth_client *auth)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
|
|
|
rb_helper_write(authd_helper, "A %x %s %s", auth->cid, auth->username, auth->hostname);
|
2016-04-06 16:43:05 +00:00
|
|
|
cancel_providers(auth);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Begin authenticating user */
|
2016-03-27 04:54:21 +00:00
|
|
|
static void
|
|
|
|
start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:59:22 +00:00
|
|
|
struct auth_client *auth;
|
2016-05-01 10:12:34 +00:00
|
|
|
unsigned long long lcid = strtoull(cid, NULL, 16);
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_node *ptr;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-05-01 10:12:34 +00:00
|
|
|
if(lcid == 0 || lcid > UINT32_MAX)
|
2016-03-17 21:23:27 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-01 09:59:22 +00:00
|
|
|
auth = rb_malloc(sizeof(struct auth_client));
|
2016-05-01 10:31:05 +00:00
|
|
|
auth_client_ref(auth);
|
2016-03-23 00:13:54 +00:00
|
|
|
auth->cid = (uint32_t)lcid;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
if(rb_dictionary_find(auth_clients, RB_UINT_TO_POINTER(auth->cid)) == NULL)
|
|
|
|
rb_dictionary_add(auth_clients, RB_UINT_TO_POINTER(auth->cid), auth);
|
2016-03-27 01:32:35 +00:00
|
|
|
else
|
|
|
|
{
|
2016-05-01 10:12:34 +00:00
|
|
|
warn_opers(L_CRIT, "provider: duplicate client added via start_auth: %s", cid);
|
2016-03-31 05:26:48 +00:00
|
|
|
exit(EX_PROVIDER_ERROR);
|
2016-03-27 01:32:35 +00:00
|
|
|
}
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
rb_strlcpy(auth->l_ip, l_ip, sizeof(auth->l_ip));
|
|
|
|
auth->l_port = (uint16_t)atoi(l_port); /* should be safe */
|
2016-03-24 00:06:33 +00:00
|
|
|
(void) rb_inet_pton_sock(l_ip, (struct sockaddr *)&auth->l_addr);
|
2016-03-31 08:00:29 +00:00
|
|
|
SET_SS_PORT(&auth->l_addr, htons(auth->l_port));
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
rb_strlcpy(auth->c_ip, c_ip, sizeof(auth->c_ip));
|
|
|
|
auth->c_port = (uint16_t)atoi(c_port);
|
2016-03-24 00:06:33 +00:00
|
|
|
(void) rb_inet_pton_sock(c_ip, (struct sockaddr *)&auth->c_addr);
|
2016-03-31 08:00:29 +00:00
|
|
|
SET_SS_PORT(&auth->c_addr, htons(auth->c_port));
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-28 21:46:52 +00:00
|
|
|
rb_strlcpy(auth->hostname, "*", sizeof(auth->hostname));
|
|
|
|
rb_strlcpy(auth->username, "*", sizeof(auth->username));
|
|
|
|
|
2016-05-01 10:38:32 +00:00
|
|
|
auth->data = rb_malloc(allocated_pids * sizeof(struct auth_client_data));
|
2016-03-26 23:01:58 +00:00
|
|
|
|
2016-03-27 01:32:35 +00:00
|
|
|
auth->providers_starting = true;
|
2016-05-01 09:49:12 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
struct auth_provider *provider = ptr->data;
|
|
|
|
|
2016-04-05 09:31:22 +00:00
|
|
|
auth->data[provider->id].provider = provider;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
2016-03-27 01:32:35 +00:00
|
|
|
lrb_assert(provider->start != NULL);
|
|
|
|
|
2016-03-17 21:23:27 +00:00
|
|
|
/* Execute providers */
|
2017-08-20 11:53:44 +00:00
|
|
|
set_provider_running(auth, provider->id);
|
2016-03-17 21:23:27 +00:00
|
|
|
if(!provider->start(auth))
|
|
|
|
/* Rejected immediately */
|
2016-05-01 10:31:05 +00:00
|
|
|
goto done;
|
2016-05-01 09:53:34 +00:00
|
|
|
|
|
|
|
if(auth->providers_cancelled)
|
|
|
|
break;
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
2016-03-27 01:32:35 +00:00
|
|
|
auth->providers_starting = false;
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
/* If no providers are running, accept the client */
|
2016-05-01 10:31:05 +00:00
|
|
|
if(auth->providers_active == 0)
|
2016-05-01 10:44:04 +00:00
|
|
|
accept_client(auth);
|
2016-05-01 10:31:05 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
auth_client_unref(auth);
|
2016-03-17 21:23:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for the initiation */
|
2016-03-27 04:54:21 +00:00
|
|
|
void
|
|
|
|
handle_new_connection(int parc, char *parv[])
|
2016-03-17 21:23:27 +00:00
|
|
|
{
|
2016-03-26 23:01:58 +00:00
|
|
|
if(parc < 6)
|
2016-03-25 00:36:41 +00:00
|
|
|
{
|
2016-03-31 05:26:48 +00:00
|
|
|
warn_opers(L_CRIT, "provider: received too few params for new connection (6 expected, got %d)", parc);
|
|
|
|
exit(EX_PROVIDER_ERROR);
|
2016-03-25 00:36:41 +00:00
|
|
|
}
|
2016-03-17 21:23:27 +00:00
|
|
|
|
|
|
|
start_auth(parv[1], parv[2], parv[3], parv[4], parv[5]);
|
|
|
|
}
|
2016-03-27 04:54:21 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
handle_cancel_connection(int parc, char *parv[])
|
|
|
|
{
|
|
|
|
struct auth_client *auth;
|
2016-05-01 10:12:34 +00:00
|
|
|
unsigned long long lcid;
|
2016-03-27 04:54:21 +00:00
|
|
|
|
|
|
|
if(parc < 2)
|
|
|
|
{
|
2016-03-31 05:26:48 +00:00
|
|
|
warn_opers(L_CRIT, "provider: received too few params for new connection (2 expected, got %d)", parc);
|
|
|
|
exit(EX_PROVIDER_ERROR);
|
2016-03-27 04:54:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 10:12:34 +00:00
|
|
|
lcid = strtoull(parv[1], NULL, 16);
|
|
|
|
if(lcid == 0 || lcid > UINT32_MAX)
|
2016-03-27 04:54:21 +00:00
|
|
|
{
|
2016-05-01 10:12:34 +00:00
|
|
|
warn_opers(L_CRIT, "provider: got a request to cancel a connection that can't exist: %s", parv[1]);
|
2016-03-31 05:26:48 +00:00
|
|
|
exit(EX_PROVIDER_ERROR);
|
2016-03-27 04:54:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
if((auth = rb_dictionary_retrieve(auth_clients, RB_UINT_TO_POINTER((uint32_t)lcid))) == NULL)
|
2016-03-27 04:54:21 +00:00
|
|
|
{
|
2016-04-02 08:49:31 +00:00
|
|
|
/* This could happen as a race if we've accepted/rejected but they cancel, so don't die here.
|
|
|
|
* --Elizafox */
|
2016-04-02 08:48:37 +00:00
|
|
|
return;
|
2016-03-27 04:54:21 +00:00
|
|
|
}
|
|
|
|
|
2016-05-01 10:31:05 +00:00
|
|
|
auth_client_ref(auth);
|
2016-03-27 04:54:21 +00:00
|
|
|
cancel_providers(auth);
|
2016-05-01 10:31:05 +00:00
|
|
|
auth_client_unref(auth);
|
2016-03-27 04:54:21 +00:00
|
|
|
}
|
2016-03-30 22:20:27 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
provider_timeout_event(void *notused __unused)
|
|
|
|
{
|
|
|
|
struct auth_client *auth;
|
2016-05-01 00:20:12 +00:00
|
|
|
rb_dictionary_iter iter;
|
2016-03-30 22:20:27 +00:00
|
|
|
const time_t curtime = rb_current_time();
|
|
|
|
|
2016-05-01 00:20:12 +00:00
|
|
|
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
2016-03-30 22:20:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
rb_dlink_node *ptr;
|
2016-03-30 22:20:27 +00:00
|
|
|
|
2016-05-01 10:31:05 +00:00
|
|
|
auth_client_ref(auth);
|
|
|
|
|
2016-05-01 09:49:12 +00:00
|
|
|
RB_DLINK_FOREACH(ptr, auth_providers.head)
|
2016-03-30 22:20:27 +00:00
|
|
|
{
|
2016-05-01 09:49:12 +00:00
|
|
|
struct auth_provider *provider = ptr->data;
|
2016-04-05 08:08:52 +00:00
|
|
|
const time_t timeout = get_provider_timeout(auth, provider->id);
|
2016-03-30 22:20:27 +00:00
|
|
|
|
2016-04-05 08:30:02 +00:00
|
|
|
if(is_provider_running(auth, provider->id) && provider->timeout != NULL &&
|
2016-03-31 05:26:48 +00:00
|
|
|
timeout > 0 && timeout < curtime)
|
2016-03-30 22:20:27 +00:00
|
|
|
{
|
|
|
|
provider->timeout(auth);
|
|
|
|
}
|
|
|
|
}
|
2016-05-01 10:31:05 +00:00
|
|
|
|
|
|
|
auth_client_unref(auth);
|
2016-03-30 22:20:27 +00:00
|
|
|
}
|
|
|
|
}
|