]>
Commit | Line | Data |
---|---|---|
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 */ | |
30 | typedef enum | |
31 | { | |
3e875f62 EM |
32 | PROVIDER_RDNS, |
33 | PROVIDER_IDENT, | |
34 | PROVIDER_BLACKLIST, | |
2b0cc3d3 EM |
35 | } provider_t; |
36 | ||
b2ede1aa EM |
37 | typedef 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 |
45 | struct 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 */ |
a7d5aea1 | 62 | uint32_t providers_done; /* Providers completed */ |
f7b37c1d | 63 | |
3e875f62 | 64 | void *data[MAX_PROVIDERS]; /* Provider-specific data slots */ |
2b0cc3d3 EM |
65 | }; |
66 | ||
67 | typedef bool (*provider_init_t)(void); | |
2b0cc3d3 EM |
68 | typedef void (*provider_destroy_t)(void); |
69 | ||
89d22b9a EM |
70 | typedef bool (*provider_start_t)(struct auth_client *); |
71 | typedef void (*provider_cancel_t)(struct auth_client *); | |
72 | typedef void (*provider_complete_t)(struct auth_client *, provider_t provider); | |
73 | ||
2b0cc3d3 EM |
74 | struct auth_provider |
75 | { | |
76 | rb_dlink_node node; | |
77 | ||
78 | provider_t id; | |
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 */ |
2b0cc3d3 EM |
84 | provider_cancel_t cancel; /* Authentication cancelled */ |
85 | provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */ | |
86 | }; | |
87 | ||
88 | extern rb_dlink_list auth_providers; | |
a52c7a8e | 89 | extern rb_dictionary *auth_clients; |
3e875f62 | 90 | |
2b0cc3d3 EM |
91 | extern struct auth_provider rdns_provider; |
92 | extern struct auth_provider ident_provider; | |
add80afd | 93 | extern struct auth_provider blacklist_provider; |
2b0cc3d3 | 94 | |
2b0cc3d3 EM |
95 | void load_provider(struct auth_provider *provider); |
96 | void unload_provider(struct auth_provider *provider); | |
97 | ||
98 | void init_providers(void); | |
99 | void destroy_providers(void); | |
100 | void cancel_providers(struct auth_client *auth); | |
101 | ||
102 | void provider_done(struct auth_client *auth, provider_t id); | |
103 | void accept_client(struct auth_client *auth, provider_t id); | |
f7b37c1d | 104 | void reject_client(struct auth_client *auth, provider_t id, const char *reason); |
2b0cc3d3 | 105 | |
89d22b9a | 106 | void notice_client(struct auth_client *auth, const char *fmt, ...); |
b2ede1aa | 107 | void warn_opers(notice_level_t level, const char *fmt, ...); |
2b0cc3d3 EM |
108 | |
109 | void handle_new_connection(int parc, char *parv[]); | |
110 | ||
111 | /* Provider is operating on this auth_client (set this if you have async work to do) */ | |
a7d5aea1 | 112 | static inline void set_provider_on(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 113 | { |
3e875f62 | 114 | auth->providers |= (1 << provider); |
2b0cc3d3 EM |
115 | } |
116 | ||
117 | /* Provider is no longer operating on this auth client (you should use provider_done) */ | |
a7d5aea1 | 118 | static inline void set_provider_off(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 119 | { |
3e875f62 | 120 | auth->providers &= ~(1 << provider); |
2b0cc3d3 EM |
121 | } |
122 | ||
a7d5aea1 EM |
123 | /* Set the provider to done (you should use provider_done) */ |
124 | static inline void set_provider_done(struct auth_client *auth, provider_t provider) | |
125 | { | |
126 | auth->providers_done |= (1 << provider); | |
127 | } | |
128 | ||
2b0cc3d3 | 129 | /* Check if provider is operating on this auth client */ |
a7d5aea1 | 130 | static inline bool is_provider_on(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 131 | { |
3e875f62 | 132 | return auth->providers & (1 << provider); |
2b0cc3d3 EM |
133 | } |
134 | ||
a7d5aea1 EM |
135 | static inline bool is_provider_done(struct auth_client *auth, provider_t provider) |
136 | { | |
137 | return auth->providers_done & (1 << provider); | |
138 | } | |
139 | ||
2b0cc3d3 | 140 | #endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */ |