]> jfr.im git - solanum.git/blame - authd/provider.h
opm: downgrade a non-fatal warning
[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,
15c49abb 36 PROVIDER_OPM,
05e17ac2
EM
37} provider_t;
38
39struct auth_client
40{
be67cfca 41 uint16_t cid; /* Client ID */
05e17ac2 42
2b0cc3d3
EM
43 char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
44 uint16_t l_port; /* Listener port */
9c7498d5 45 struct rb_sockaddr_storage l_addr; /* Listener address/port */
2b0cc3d3
EM
46
47 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
48 uint16_t c_port; /* Client port */
9c7498d5 49 struct rb_sockaddr_storage c_addr; /* Client address/port */
05e17ac2 50
5bfc606f 51 char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
be67cfca 52 char username[USERLEN + 1]; /* Used for ident lookup */
05e17ac2 53
3e875f62 54 uint32_t providers; /* Providers at work,
2b0cc3d3 55 * none left when set to 0 */
a7d5aea1 56 uint32_t providers_done; /* Providers completed */
247b304f 57 bool providers_starting; /* Providers are still warming up */
f7b37c1d 58
3e875f62 59 void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
15c49abb 60 time_t timeout[MAX_PROVIDERS]; /* When to call timeout callback */
2b0cc3d3
EM
61};
62
63typedef bool (*provider_init_t)(void);
2b0cc3d3
EM
64typedef void (*provider_destroy_t)(void);
65
89d22b9a
EM
66typedef bool (*provider_start_t)(struct auth_client *);
67typedef void (*provider_cancel_t)(struct auth_client *);
15c49abb 68typedef void (*provider_timeout_t)(struct auth_client *);
a51487e0 69typedef void (*provider_complete_t)(struct auth_client *, provider_t);
89d22b9a 70
ee7f9271
EM
71struct auth_stats_handler
72{
73 const char letter;
74 authd_stat_handler handler;
75};
76
05e17ac2
EM
77struct auth_provider
78{
99e53867
EM
79 rb_dlink_node node;
80
81 provider_t id;
05e17ac2
EM
82
83 provider_init_t init; /* Initalise the provider */
84 provider_destroy_t destroy; /* Terminate the provider */
85
89d22b9a 86 provider_start_t start; /* Perform authentication */
05e17ac2 87 provider_cancel_t cancel; /* Authentication cancelled */
15c49abb 88 provider_timeout_t timeout; /* Timeout callback */
05e17ac2 89 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
a51487e0 90
ee7f9271
EM
91 struct auth_stats_handler stats_handler;
92
a51487e0 93 struct auth_opts_handler *opt_handlers;
05e17ac2
EM
94};
95
9b5b2ded 96extern rb_dlink_list auth_providers;
a52c7a8e 97extern rb_dictionary *auth_clients;
3e875f62 98
18764319 99extern struct auth_provider rdns_provider;
f1861e48 100extern struct auth_provider ident_provider;
add80afd 101extern struct auth_provider blacklist_provider;
4e85459a 102extern struct auth_provider opm_provider;
9b5b2ded
EM
103
104void load_provider(struct auth_provider *provider);
105void unload_provider(struct auth_provider *provider);
106
05e17ac2
EM
107void init_providers(void);
108void destroy_providers(void);
109void cancel_providers(struct auth_client *auth);
110
91f870b3
EM
111void provider_done(struct auth_client *auth, provider_t id);
112void accept_client(struct auth_client *auth, provider_t id);
64afc358 113void reject_client(struct auth_client *auth, provider_t id, const char *data, const char *fmt, ...);
05e17ac2 114
05e17ac2 115void handle_new_connection(int parc, char *parv[]);
60374ac9 116void handle_cancel_connection(int parc, char *parv[]);
05e17ac2 117
cdf15929 118/* Provider is operating on this auth_client (set this if you have async work to do) */
60374ac9
EM
119static inline void
120set_provider_on(struct auth_client *auth, provider_t provider)
05e17ac2 121{
3e875f62 122 auth->providers |= (1 << provider);
05e17ac2
EM
123}
124
125/* Provider is no longer operating on this auth client (you should use provider_done) */
60374ac9
EM
126static inline void
127set_provider_off(struct auth_client *auth, provider_t provider)
2b0cc3d3 128{
3e875f62 129 auth->providers &= ~(1 << provider);
2b0cc3d3
EM
130}
131
a7d5aea1 132/* Set the provider to done (you should use provider_done) */
60374ac9
EM
133static inline void
134set_provider_done(struct auth_client *auth, provider_t provider)
05e17ac2 135{
a7d5aea1 136 auth->providers_done |= (1 << provider);
05e17ac2
EM
137}
138
139/* Check if provider is operating on this auth client */
60374ac9
EM
140static inline bool
141is_provider_on(struct auth_client *auth, provider_t provider)
2b0cc3d3 142{
3e875f62 143 return auth->providers & (1 << provider);
2b0cc3d3
EM
144}
145
60374ac9
EM
146static inline bool
147is_provider_done(struct auth_client *auth, provider_t provider)
05e17ac2 148{
a7d5aea1 149 return auth->providers_done & (1 << provider);
05e17ac2
EM
150}
151
0f95a274 152#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */