]>
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 | ||
37 | struct auth_client | |
38 | { | |
39 | uint16_t cid; /* Client ID */ | |
40 | ||
41 | char l_ip[HOSTIPLEN + 1]; /* Listener IP address */ | |
42 | uint16_t l_port; /* Listener port */ | |
9c7498d5 | 43 | struct rb_sockaddr_storage l_addr; /* Listener address/port */ |
2b0cc3d3 EM |
44 | |
45 | char c_ip[HOSTIPLEN + 1]; /* Client IP address */ | |
46 | uint16_t c_port; /* Client port */ | |
9c7498d5 | 47 | struct rb_sockaddr_storage c_addr; /* Client address/port */ |
2b0cc3d3 EM |
48 | |
49 | char hostname[HOSTLEN + 1]; /* Used for DNS lookup */ | |
50 | char username[USERLEN + 1]; /* Used for ident lookup */ | |
51 | ||
3e875f62 | 52 | uint32_t providers; /* Providers at work, |
2b0cc3d3 | 53 | * none left when set to 0 */ |
a7d5aea1 | 54 | uint32_t providers_done; /* Providers completed */ |
f7b37c1d | 55 | |
3e875f62 | 56 | void *data[MAX_PROVIDERS]; /* Provider-specific data slots */ |
2b0cc3d3 EM |
57 | }; |
58 | ||
59 | typedef bool (*provider_init_t)(void); | |
2b0cc3d3 EM |
60 | typedef void (*provider_destroy_t)(void); |
61 | ||
89d22b9a EM |
62 | typedef bool (*provider_start_t)(struct auth_client *); |
63 | typedef void (*provider_cancel_t)(struct auth_client *); | |
64 | typedef void (*provider_complete_t)(struct auth_client *, provider_t provider); | |
65 | ||
2b0cc3d3 EM |
66 | struct auth_provider |
67 | { | |
68 | rb_dlink_node node; | |
69 | ||
70 | provider_t id; | |
71 | ||
72 | provider_init_t init; /* Initalise the provider */ | |
73 | provider_destroy_t destroy; /* Terminate the provider */ | |
74 | ||
89d22b9a | 75 | provider_start_t start; /* Perform authentication */ |
2b0cc3d3 EM |
76 | provider_cancel_t cancel; /* Authentication cancelled */ |
77 | provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */ | |
78 | }; | |
79 | ||
80 | extern rb_dlink_list auth_providers; | |
a52c7a8e | 81 | extern rb_dictionary *auth_clients; |
3e875f62 | 82 | |
2b0cc3d3 EM |
83 | extern struct auth_provider rdns_provider; |
84 | extern struct auth_provider ident_provider; | |
add80afd | 85 | extern struct auth_provider blacklist_provider; |
2b0cc3d3 | 86 | |
2b0cc3d3 EM |
87 | void load_provider(struct auth_provider *provider); |
88 | void unload_provider(struct auth_provider *provider); | |
89 | ||
90 | void init_providers(void); | |
91 | void destroy_providers(void); | |
92 | void cancel_providers(struct auth_client *auth); | |
93 | ||
94 | void provider_done(struct auth_client *auth, provider_t id); | |
95 | void accept_client(struct auth_client *auth, provider_t id); | |
f7b37c1d | 96 | void reject_client(struct auth_client *auth, provider_t id, const char *reason); |
2b0cc3d3 | 97 | |
2b0cc3d3 EM |
98 | void handle_new_connection(int parc, char *parv[]); |
99 | ||
100 | /* Provider is operating on this auth_client (set this if you have async work to do) */ | |
a7d5aea1 | 101 | static inline void set_provider_on(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 102 | { |
3e875f62 | 103 | auth->providers |= (1 << provider); |
2b0cc3d3 EM |
104 | } |
105 | ||
106 | /* Provider is no longer operating on this auth client (you should use provider_done) */ | |
a7d5aea1 | 107 | static inline void set_provider_off(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 108 | { |
3e875f62 | 109 | auth->providers &= ~(1 << provider); |
2b0cc3d3 EM |
110 | } |
111 | ||
a7d5aea1 EM |
112 | /* Set the provider to done (you should use provider_done) */ |
113 | static inline void set_provider_done(struct auth_client *auth, provider_t provider) | |
114 | { | |
115 | auth->providers_done |= (1 << provider); | |
116 | } | |
117 | ||
2b0cc3d3 | 118 | /* Check if provider is operating on this auth client */ |
a7d5aea1 | 119 | static inline bool is_provider_on(struct auth_client *auth, provider_t provider) |
2b0cc3d3 | 120 | { |
3e875f62 | 121 | return auth->providers & (1 << provider); |
2b0cc3d3 EM |
122 | } |
123 | ||
a7d5aea1 EM |
124 | static inline bool is_provider_done(struct auth_client *auth, provider_t provider) |
125 | { | |
126 | return auth->providers_done & (1 << provider); | |
127 | } | |
128 | ||
2b0cc3d3 | 129 | #endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */ |