auth: minor changes

This commit is contained in:
Elizabeth Myers 2016-03-10 01:59:37 -06:00
parent 05e17ac208
commit f42aa1a9e5
2 changed files with 15 additions and 45 deletions

View file

@ -35,7 +35,9 @@
* Providers may kick clients off by rejecting them. Upon rejection, all * Providers may kick clients off by rejecting them. Upon rejection, all
* providers are cancelled. They can also unconditionally accept them. * providers are cancelled. They can also unconditionally accept them.
* *
* When a provider has done its work, it should call provider_done. * 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.
* *
* --Elizafox, 9 March 2016 * --Elizafox, 9 March 2016
*/ */
@ -43,32 +45,6 @@
#include "authd.h" #include "authd.h"
#include "auth.h" #include "auth.h"
/*****************************************************************************/
/* This is just some test code for the system */
bool dummy_init(void)
{
/* Do a dummy init */
return true;
}
void dummy_destroy(void)
{
/* Do a dummy destroy */
}
bool dummy_start(struct auth_client *auth)
{
/* Set the client's username to testhost as a test */
strcpy(auth->username, "testhost");
return true;
}
void dummy_cancel(struct auth_client *auth)
{
/* Does nothing */
}
/*****************************************************************************/
#define NULL_PROVIDER { \ #define NULL_PROVIDER { \
.provider = PROVIDER_NULL, \ .provider = PROVIDER_NULL, \
.init = NULL, \ .init = NULL, \
@ -78,20 +54,10 @@ void dummy_cancel(struct auth_client *auth)
.completed = NULL, \ .completed = NULL, \
} }
#define DUMMY_PROVIDER { \
.provider = PROVIDER_DUMMY, \
.init = dummy_init, \
.destroy = dummy_destroy, \
.start = dummy_start, \
.cancel = dummy_cancel, \
.completed = NULL, \
}
/* Providers */ /* Providers */
static struct auth_provider auth_providers[] = static struct auth_provider auth_providers[] =
{ {
NULL_PROVIDER, NULL_PROVIDER,
DUMMY_PROVIDER
}; };
/* Clients waiting */ /* Clients waiting */
@ -111,7 +77,7 @@ void init_providers(void)
} }
/* Terminate all providers */ /* Terminate all providers */
void destroy_providerss(void) void destroy_providers(void)
{ {
struct auth_provider *pptr; struct auth_provider *pptr;
@ -122,7 +88,7 @@ void destroy_providerss(void)
{ {
/* TBD - is this the right thing? /* TBD - is this the right thing?
* (NOTE - this error message is designed for morons) */ * (NOTE - this error message is designed for morons) */
reject_client(&auth_clients[i], reject_client(&auth_clients[i], 0,
"IRC server reloading... try reconnecting in a few seconds"); "IRC server reloading... try reconnecting in a few seconds");
} }
} }
@ -157,7 +123,7 @@ void provider_done(struct auth_client *auth, provider_t provider)
if(!auth->providers) if(!auth->providers)
{ {
/* No more providers, done */ /* No more providers, done */
accept_client(auth); accept_client(auth, 0);
return; return;
} }
@ -170,12 +136,14 @@ void provider_done(struct auth_client *auth, provider_t provider)
} }
/* Reject a client, cancel outstanding providers if any */ /* Reject a client, cancel outstanding providers if any */
void reject_client(struct auth_client *auth, const char *reason) void reject_client(struct auth_client *auth, provider_t provider, const char *reason)
{ {
uint16_t cid = auth->cid; uint16_t cid = auth->cid;
rb_helper_write(authd_helper, "R %x :%s", auth->cid, reason); rb_helper_write(authd_helper, "R %x :%s", auth->cid, reason);
unset_provider(auth, provider);
if(auth->providers) if(auth->providers)
cancel_providers(auth); cancel_providers(auth);
@ -183,12 +151,14 @@ void reject_client(struct auth_client *auth, const char *reason)
} }
/* Accept a client, cancel outstanding providers if any */ /* Accept a client, cancel outstanding providers if any */
void accept_client(struct auth_client *auth) void accept_client(struct auth_client *auth, provider_t provider)
{ {
uint16_t cid = auth->cid; uint16_t cid = auth->cid;
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);
unset_provider(auth, provider);
if(auth->providers) if(auth->providers)
cancel_providers(auth); cancel_providers(auth);
@ -237,7 +207,7 @@ void start_auth(const char *cid, const char *l_ip, const char *l_port, const cha
/* If no providers are running, accept the client */ /* If no providers are running, accept the client */
if(!auth->providers) if(!auth->providers)
accept_client(auth); accept_client(auth, 0);
} }
/* Callback for the initiation */ /* Callback for the initiation */

View file

@ -78,9 +78,9 @@ void destroy_providers(void);
void cancel_providers(struct auth_client *auth); void cancel_providers(struct auth_client *auth);
void provider_done(struct auth_client *auth, provider_t provider); void provider_done(struct auth_client *auth, provider_t provider);
void reject_client(struct auth_client *auth, provider_t provider, const char *reason);
void accept_client(struct auth_client *auth, provider_t provider);
void reject_client(struct auth_client *auth, const char *reason);
void accept_client(struct auth_client *auth);
void notice_client(struct auth_client *auth, const char *notice); void notice_client(struct auth_client *auth, const char *notice);
void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port); void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port);