authd/provider: cleanups

This commit is contained in:
Elizabeth Myers 2016-03-24 19:23:49 -05:00
parent 410fcc233f
commit 89d22b9af5
2 changed files with 36 additions and 11 deletions

View file

@ -18,14 +18,14 @@
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
/* So the basic design here is to have "authentication providers" that do /* The basic design here is to have "authentication providers" that do things
* things like query ident and blacklists and even open proxies. * like query ident and blacklists and even open proxies.
* *
* Providers are registered in the auth_providers linked list. It is planned to * Providers are registered in the auth_providers linked list. It is planned to
* use a bitmap to store provider ID's later. * use a bitmap to store provider ID's later.
* *
* Providers can either return failure immediately, immediate acceptance, or * Providers can either return failure immediately, immediate acceptance, or do
* do work in the background (calling set_provider to signal this). * 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 * Provider-specific data for each client can be kept in an index of the data
* struct member (using the provider's ID). * 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 * should call provider_done. Do NOT call this if you have accepted or rejected
* the client. * 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 * --Elizafox, 9 March 2016
*/ */
@ -185,9 +188,29 @@ void accept_client(struct auth_client *auth, provider_t id)
} }
/* Send a notice to a client */ /* 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 */ /* Begin authenticating user */

View file

@ -56,11 +56,12 @@ struct auth_client
}; };
typedef bool (*provider_init_t)(void); 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 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 struct auth_provider
{ {
rb_dlink_node node; rb_dlink_node node;
@ -70,7 +71,7 @@ struct auth_provider
provider_init_t init; /* Initalise the provider */ provider_init_t init; /* Initalise the provider */
provider_destroy_t destroy; /* Terminate 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_cancel_t cancel; /* Authentication cancelled */
provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */ 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 accept_client(struct auth_client *auth, provider_t id);
void reject_client(struct auth_client *auth, provider_t id, const char *reason); 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[]); void handle_new_connection(int parc, char *parv[]);