]> jfr.im git - solanum.git/blob - authd/provider.h
Merge branch 'authd-framework-2' into authd-framework
[solanum.git] / authd / provider.h
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"
25 #include "authd.h"
26 #include "rb_dictionary.h"
27
28 #define MAX_PROVIDERS 32 /* This should be enough */
29
30 /* Registered providers */
31 typedef enum
32 {
33 PROVIDER_RDNS,
34 PROVIDER_IDENT,
35 PROVIDER_BLACKLIST,
36 } provider_t;
37
38 struct auth_client
39 {
40 uint16_t cid; /* Client ID */
41
42 <<<<<<< HEAD
43 struct rb_sockaddr_storage l_addr; /* Listener IP address */
44 struct rb_sockaddr_storage c_addr; /* Client IP address */
45 =======
46 char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
47 uint16_t l_port; /* Listener port */
48 struct rb_sockaddr_storage l_addr; /* Listener address/port */
49
50 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
51 uint16_t c_port; /* Client port */
52 struct rb_sockaddr_storage c_addr; /* Client address/port */
53 >>>>>>> authd-framework-2
54
55 char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
56 char username[USERLEN + 1]; /* Used for ident lookup */
57
58 <<<<<<< HEAD
59 unsigned int providers; /* Providers at work,
60 * none left when set to 0 */
61 };
62
63 typedef bool (*provider_init_t)(void);
64 typedef bool (*provider_perform_t)(struct auth_client *);
65 typedef void (*provider_complete_t)(struct auth_client *, provider_t provider);
66 typedef void (*provider_cancel_t)(struct auth_client *);
67 typedef void (*provider_destroy_t)(void);
68
69 =======
70 uint32_t providers; /* Providers at work,
71 * none left when set to 0 */
72 uint32_t providers_done; /* Providers completed */
73
74 void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
75 };
76
77 typedef bool (*provider_init_t)(void);
78 typedef void (*provider_destroy_t)(void);
79
80 typedef bool (*provider_start_t)(struct auth_client *);
81 typedef void (*provider_cancel_t)(struct auth_client *);
82 typedef void (*provider_complete_t)(struct auth_client *, provider_t);
83
84 >>>>>>> authd-framework-2
85 struct auth_provider
86 {
87 rb_dlink_node node;
88
89 provider_t id;
90
91 provider_init_t init; /* Initalise the provider */
92 provider_destroy_t destroy; /* Terminate the provider */
93
94 provider_start_t start; /* Perform authentication */
95 provider_cancel_t cancel; /* Authentication cancelled */
96 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
97
98 struct auth_opts_handler *opt_handlers;
99 };
100
101 extern rb_dlink_list auth_providers;
102 extern rb_dictionary *auth_clients;
103
104 extern struct auth_provider rdns_provider;
105 extern struct auth_provider ident_provider;
106 extern struct auth_provider blacklist_provider;
107
108 void load_provider(struct auth_provider *provider);
109 void unload_provider(struct auth_provider *provider);
110
111 void init_providers(void);
112 void destroy_providers(void);
113 void cancel_providers(struct auth_client *auth);
114
115 void provider_done(struct auth_client *auth, provider_t id);
116 void accept_client(struct auth_client *auth, provider_t id);
117 void reject_client(struct auth_client *auth, provider_t id, const char *reason);
118
119 void handle_new_connection(int parc, char *parv[]);
120
121 static inline void set_provider_on(struct auth_client *auth, provider_t provider)
122 {
123 auth->providers |= (1 << provider);
124 }
125
126 /* Provider is no longer operating on this auth client (you should use provider_done) */
127 static inline void set_provider_off(struct auth_client *auth, provider_t provider)
128 {
129 auth->providers &= ~(1 << provider);
130 }
131
132 /* Set the provider to done (you should use provider_done) */
133 static inline void set_provider_done(struct auth_client *auth, provider_t provider)
134 {
135 auth->providers_done |= (1 << provider);
136 }
137
138 /* Check if provider is operating on this auth client */
139 static inline bool is_provider_on(struct auth_client *auth, provider_t provider)
140 {
141 return auth->providers & (1 << provider);
142 }
143
144 static inline bool is_provider_done(struct auth_client *auth, provider_t provider)
145 {
146 return auth->providers_done & (1 << provider);
147 }
148
149 #endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */