]> jfr.im git - solanum.git/blame - authd/provider.h
authd/provider: add stats handling hooking
[solanum.git] / authd / provider.h
CommitLineData
0f95a274 1/* authd/provider.h - authentication provider framework
05e17ac2
EM
2 * Copyright (c) 2016 Elizabeth Myers <elizabeth@interlinked.me>
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice is present in all copies.
7 *
8 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
9 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
10 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
11 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
12 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
14 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
15 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
16 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
17 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
18 * POSSIBILITY OF SUCH DAMAGE.
19 */
20
0f95a274
EM
21#ifndef __CHARYBDIS_AUTHD_PROVIDER_H__
22#define __CHARYBDIS_AUTHD_PROVIDER_H__
05e17ac2
EM
23
24#include "stdinc.h"
a51487e0 25#include "authd.h"
3e875f62 26#include "rb_dictionary.h"
05e17ac2 27
3e875f62 28#define MAX_PROVIDERS 32 /* This should be enough */
05e17ac2
EM
29
30/* Registered providers */
31typedef enum
32{
3e875f62
EM
33 PROVIDER_RDNS,
34 PROVIDER_IDENT,
35 PROVIDER_BLACKLIST,
05e17ac2
EM
36} provider_t;
37
38struct auth_client
39{
be67cfca 40 uint16_t cid; /* Client ID */
05e17ac2 41
2b0cc3d3
EM
42 char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
43 uint16_t l_port; /* Listener port */
9c7498d5 44 struct rb_sockaddr_storage l_addr; /* Listener address/port */
2b0cc3d3
EM
45
46 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
47 uint16_t c_port; /* Client port */
9c7498d5 48 struct rb_sockaddr_storage c_addr; /* Client address/port */
05e17ac2 49
5bfc606f 50 char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
be67cfca 51 char username[USERLEN + 1]; /* Used for ident lookup */
05e17ac2 52
3e875f62 53 uint32_t providers; /* Providers at work,
2b0cc3d3 54 * none left when set to 0 */
a7d5aea1 55 uint32_t providers_done; /* Providers completed */
247b304f 56 bool providers_starting; /* Providers are still warming up */
f7b37c1d 57
3e875f62 58 void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
2b0cc3d3
EM
59};
60
61typedef bool (*provider_init_t)(void);
2b0cc3d3
EM
62typedef void (*provider_destroy_t)(void);
63
89d22b9a
EM
64typedef bool (*provider_start_t)(struct auth_client *);
65typedef void (*provider_cancel_t)(struct auth_client *);
a51487e0 66typedef void (*provider_complete_t)(struct auth_client *, provider_t);
89d22b9a 67
ee7f9271
EM
68struct auth_stats_handler
69{
70 const char letter;
71 authd_stat_handler handler;
72};
73
05e17ac2
EM
74struct auth_provider
75{
99e53867
EM
76 rb_dlink_node node;
77
78 provider_t id;
05e17ac2
EM
79
80 provider_init_t init; /* Initalise the provider */
81 provider_destroy_t destroy; /* Terminate the provider */
82
89d22b9a 83 provider_start_t start; /* Perform authentication */
05e17ac2
EM
84 provider_cancel_t cancel; /* Authentication cancelled */
85 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
a51487e0 86
ee7f9271
EM
87 struct auth_stats_handler stats_handler;
88
a51487e0 89 struct auth_opts_handler *opt_handlers;
05e17ac2
EM
90};
91
9b5b2ded 92extern rb_dlink_list auth_providers;
a52c7a8e 93extern rb_dictionary *auth_clients;
3e875f62 94
18764319 95extern struct auth_provider rdns_provider;
f1861e48 96extern struct auth_provider ident_provider;
add80afd 97extern struct auth_provider blacklist_provider;
9b5b2ded
EM
98
99void load_provider(struct auth_provider *provider);
100void unload_provider(struct auth_provider *provider);
101
05e17ac2
EM
102void init_providers(void);
103void destroy_providers(void);
104void cancel_providers(struct auth_client *auth);
105
91f870b3
EM
106void provider_done(struct auth_client *auth, provider_t id);
107void accept_client(struct auth_client *auth, provider_t id);
6535177f 108void reject_client(struct auth_client *auth, provider_t id, const char *data, const char *reason);
05e17ac2 109
05e17ac2 110void handle_new_connection(int parc, char *parv[]);
60374ac9 111void handle_cancel_connection(int parc, char *parv[]);
05e17ac2 112
cdf15929 113/* Provider is operating on this auth_client (set this if you have async work to do) */
60374ac9
EM
114static inline void
115set_provider_on(struct auth_client *auth, provider_t provider)
05e17ac2 116{
3e875f62 117 auth->providers |= (1 << provider);
05e17ac2
EM
118}
119
120/* Provider is no longer operating on this auth client (you should use provider_done) */
60374ac9
EM
121static inline void
122set_provider_off(struct auth_client *auth, provider_t provider)
2b0cc3d3 123{
3e875f62 124 auth->providers &= ~(1 << provider);
2b0cc3d3
EM
125}
126
a7d5aea1 127/* Set the provider to done (you should use provider_done) */
60374ac9
EM
128static inline void
129set_provider_done(struct auth_client *auth, provider_t provider)
05e17ac2 130{
a7d5aea1 131 auth->providers_done |= (1 << provider);
05e17ac2
EM
132}
133
134/* Check if provider is operating on this auth client */
60374ac9
EM
135static inline bool
136is_provider_on(struct auth_client *auth, provider_t provider)
2b0cc3d3 137{
3e875f62 138 return auth->providers & (1 << provider);
2b0cc3d3
EM
139}
140
60374ac9
EM
141static inline bool
142is_provider_done(struct auth_client *auth, provider_t provider)
05e17ac2 143{
a7d5aea1 144 return auth->providers_done & (1 << provider);
05e17ac2
EM
145}
146
0f95a274 147#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */