From 89d22b9af5597800fa9cb711f42daecfb6800029 Mon Sep 17 00:00:00 2001 From: Elizabeth Myers Date: Thu, 24 Mar 2016 19:23:49 -0500 Subject: [PATCH] authd/provider: cleanups --- authd/provider.c | 35 +++++++++++++++++++++++++++++------ authd/provider.h | 12 +++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/authd/provider.c b/authd/provider.c index 3cd489c2..d227bed3 100644 --- a/authd/provider.c +++ b/authd/provider.c @@ -18,14 +18,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* So the basic design here is to have "authentication providers" that do - * things like query ident and blacklists and even open proxies. +/* The basic design here is to have "authentication providers" that do things + * like query ident and blacklists and even open proxies. * * Providers are registered in the auth_providers linked list. It is planned to * use a bitmap to store provider ID's later. * - * Providers can either return failure immediately, immediate acceptance, or - * do work in the background (calling set_provider to signal this). + * Providers can either return failure immediately, immediate acceptance, or do + * work in the background (calling set_provider to signal this). * * Provider-specific data for each client can be kept in an index of the data * struct member (using the provider's ID). @@ -40,6 +40,9 @@ * should call provider_done. Do NOT call this if you have accepted or rejected * the client. * + * Eventually, stuff like *:line handling will be moved here, but that means we + * have to talk to bandb directly first. + * * --Elizafox, 9 March 2016 */ @@ -185,9 +188,29 @@ void accept_client(struct auth_client *auth, provider_t id) } /* Send a notice to a client */ -void notice_client(struct auth_client *auth, const char *notice) +void notice_client(struct auth_client *auth, const char *fmt, ...) { - rb_helper_write(authd_helper, "N %x :%s", auth->cid, notice); + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "N %x :%s", auth->cid, buf); +} + +/* Send a warning to the IRC daemon for logging, etc. */ +void warn_opers(provider_t id, const char *fmt, ...) +{ + char buf[BUFSIZE]; + va_list args; + + va_start(args, fmt); + vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + rb_helper_write(authd_helper, "W %c :%s", id, buf); } /* Begin authenticating user */ diff --git a/authd/provider.h b/authd/provider.h index 5fa0962b..84d62318 100644 --- a/authd/provider.h +++ b/authd/provider.h @@ -56,11 +56,12 @@ struct auth_client }; typedef bool (*provider_init_t)(void); -typedef bool (*provider_perform_t)(struct auth_client *); -typedef void (*provider_complete_t)(struct auth_client *, provider_t provider); -typedef void (*provider_cancel_t)(struct auth_client *); typedef void (*provider_destroy_t)(void); +typedef bool (*provider_start_t)(struct auth_client *); +typedef void (*provider_cancel_t)(struct auth_client *); +typedef void (*provider_complete_t)(struct auth_client *, provider_t provider); + struct auth_provider { rb_dlink_node node; @@ -70,7 +71,7 @@ struct auth_provider provider_init_t init; /* Initalise the provider */ provider_destroy_t destroy; /* Terminate the provider */ - provider_perform_t start; /* Perform authentication */ + provider_start_t start; /* Perform authentication */ provider_cancel_t cancel; /* Authentication cancelled */ provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */ }; @@ -92,7 +93,8 @@ void provider_done(struct auth_client *auth, provider_t id); void accept_client(struct auth_client *auth, provider_t id); void reject_client(struct auth_client *auth, provider_t id, const char *reason); -void notice_client(struct auth_client *auth, const char *notice); +void notice_client(struct auth_client *auth, const char *fmt, ...); +void warn_opers(provider_t id, const char *fmt, ...); void handle_new_connection(int parc, char *parv[]);