]> jfr.im git - solanum.git/blame - authd/provider.h
authd/provider: add blacklist provider.
[solanum.git] / authd / provider.h
CommitLineData
2b0cc3d3
EM
1/* authd/provider.h - authentication provider framework
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
21#ifndef __CHARYBDIS_AUTHD_PROVIDER_H__
22#define __CHARYBDIS_AUTHD_PROVIDER_H__
23
24#include "stdinc.h"
3e875f62 25#include "rb_dictionary.h"
2b0cc3d3 26
3e875f62 27#define MAX_PROVIDERS 32 /* This should be enough */
2b0cc3d3
EM
28
29/* Registered providers */
30typedef enum
31{
3e875f62
EM
32 PROVIDER_RDNS,
33 PROVIDER_IDENT,
34 PROVIDER_BLACKLIST,
2b0cc3d3
EM
35} provider_t;
36
b2ede1aa
EM
37typedef enum
38{
39 L_DEBUG = 'D',
40 L_INFO = 'I',
41 L_WARN = 'W',
42 L_CRIT ='C',
43} notice_level_t;
44
2b0cc3d3
EM
45struct auth_client
46{
47 uint16_t cid; /* Client ID */
48
49 char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
50 uint16_t l_port; /* Listener port */
9c7498d5 51 struct rb_sockaddr_storage l_addr; /* Listener address/port */
2b0cc3d3
EM
52
53 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
54 uint16_t c_port; /* Client port */
9c7498d5 55 struct rb_sockaddr_storage c_addr; /* Client address/port */
2b0cc3d3
EM
56
57 char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
58 char username[USERLEN + 1]; /* Used for ident lookup */
59
3e875f62 60 uint32_t providers; /* Providers at work,
2b0cc3d3 61 * none left when set to 0 */
f7b37c1d 62
3e875f62 63 void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
2b0cc3d3
EM
64};
65
66typedef bool (*provider_init_t)(void);
2b0cc3d3
EM
67typedef void (*provider_destroy_t)(void);
68
89d22b9a
EM
69typedef bool (*provider_start_t)(struct auth_client *);
70typedef void (*provider_cancel_t)(struct auth_client *);
71typedef void (*provider_complete_t)(struct auth_client *, provider_t provider);
72
2b0cc3d3
EM
73struct auth_provider
74{
75 rb_dlink_node node;
76
77 provider_t id;
78
79 provider_init_t init; /* Initalise the provider */
80 provider_destroy_t destroy; /* Terminate the provider */
81
89d22b9a 82 provider_start_t start; /* Perform authentication */
2b0cc3d3
EM
83 provider_cancel_t cancel; /* Authentication cancelled */
84 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
85};
86
87extern rb_dlink_list auth_providers;
a52c7a8e 88extern rb_dictionary *auth_clients;
3e875f62 89
2b0cc3d3
EM
90extern struct auth_provider rdns_provider;
91extern struct auth_provider ident_provider;
add80afd 92extern struct auth_provider blacklist_provider;
2b0cc3d3 93
2b0cc3d3
EM
94void load_provider(struct auth_provider *provider);
95void unload_provider(struct auth_provider *provider);
96
97void init_providers(void);
98void destroy_providers(void);
99void cancel_providers(struct auth_client *auth);
100
101void provider_done(struct auth_client *auth, provider_t id);
102void accept_client(struct auth_client *auth, provider_t id);
f7b37c1d 103void reject_client(struct auth_client *auth, provider_t id, const char *reason);
2b0cc3d3 104
89d22b9a 105void notice_client(struct auth_client *auth, const char *fmt, ...);
b2ede1aa 106void warn_opers(notice_level_t level, const char *fmt, ...);
2b0cc3d3
EM
107
108void handle_new_connection(int parc, char *parv[]);
109
110/* Provider is operating on this auth_client (set this if you have async work to do) */
111static inline void set_provider(struct auth_client *auth, provider_t provider)
112{
3e875f62 113 auth->providers |= (1 << provider);
2b0cc3d3
EM
114}
115
116/* Provider is no longer operating on this auth client (you should use provider_done) */
117static inline void unset_provider(struct auth_client *auth, provider_t provider)
118{
3e875f62 119 auth->providers &= ~(1 << provider);
2b0cc3d3
EM
120}
121
122/* Check if provider is operating on this auth client */
123static inline bool is_provider(struct auth_client *auth, provider_t provider)
124{
3e875f62 125 return auth->providers & (1 << provider);
2b0cc3d3
EM
126}
127
128#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */