]>
Commit | Line | Data |
---|---|---|
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" | |
25 | ||
26 | /* Arbitrary limit */ | |
f169fc88 | 27 | #define MAX_CLIENTS 4096 |
05e17ac2 EM |
28 | |
29 | /* Registered providers */ | |
30 | typedef enum | |
31 | { | |
32 | PROVIDER_NULL = 0x0, /* Dummy value */ | |
33 | PROVIDER_RDNS = 0x1, | |
34 | PROVIDER_IDENT = 0x2, | |
35 | PROVIDER_BLACKLIST = 0x4, | |
05e17ac2 EM |
36 | } provider_t; |
37 | ||
38 | struct auth_client | |
39 | { | |
be67cfca | 40 | uint16_t cid; /* Client ID */ |
05e17ac2 | 41 | |
5bfc606f | 42 | struct rb_sockaddr_storage l_ip; /* Listener IP address */ |
be67cfca | 43 | uint16_t l_port; /* Listener port */ |
05e17ac2 | 44 | |
18764319 | 45 | struct rb_sockaddr_storage c_addr; /* Client IP address */ |
be67cfca | 46 | uint16_t c_port; /* Client port */ |
05e17ac2 | 47 | |
5bfc606f | 48 | char hostname[HOSTLEN + 1]; /* Used for DNS lookup */ |
be67cfca | 49 | char username[USERLEN + 1]; /* Used for ident lookup */ |
05e17ac2 | 50 | |
be67cfca EM |
51 | unsigned int providers; /* Providers at work, |
52 | * none left when set to 0 */ | |
05e17ac2 EM |
53 | }; |
54 | ||
55 | typedef bool (*provider_init_t)(void); | |
56 | typedef bool (*provider_perform_t)(struct auth_client *); | |
57 | typedef void (*provider_complete_t)(struct auth_client *, provider_t provider); | |
58 | typedef void (*provider_cancel_t)(struct auth_client *); | |
59 | typedef void (*provider_destroy_t)(void); | |
60 | ||
61 | struct auth_provider | |
62 | { | |
99e53867 EM |
63 | rb_dlink_node node; |
64 | ||
65 | provider_t id; | |
05e17ac2 EM |
66 | |
67 | provider_init_t init; /* Initalise the provider */ | |
68 | provider_destroy_t destroy; /* Terminate the provider */ | |
69 | ||
70 | provider_perform_t start; /* Perform authentication */ | |
71 | provider_cancel_t cancel; /* Authentication cancelled */ | |
72 | provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */ | |
73 | }; | |
74 | ||
9b5b2ded | 75 | extern rb_dlink_list auth_providers; |
18764319 | 76 | extern struct auth_provider rdns_provider; |
9b5b2ded EM |
77 | |
78 | extern struct auth_client auth_clients[MAX_CLIENTS]; | |
79 | ||
80 | void load_provider(struct auth_provider *provider); | |
81 | void unload_provider(struct auth_provider *provider); | |
82 | ||
05e17ac2 EM |
83 | void init_providers(void); |
84 | void destroy_providers(void); | |
85 | void cancel_providers(struct auth_client *auth); | |
86 | ||
87 | void provider_done(struct auth_client *auth, provider_t provider); | |
f42aa1a9 EM |
88 | void reject_client(struct auth_client *auth, provider_t provider, const char *reason); |
89 | void accept_client(struct auth_client *auth, provider_t provider); | |
05e17ac2 | 90 | |
05e17ac2 EM |
91 | void notice_client(struct auth_client *auth, const char *notice); |
92 | ||
05e17ac2 EM |
93 | void handle_new_connection(int parc, char *parv[]); |
94 | ||
95 | /* Provider is operating on this auth_client (set this if you have async work to do) */ | |
96 | static inline void set_provider(struct auth_client *auth, provider_t provider) | |
97 | { | |
98 | auth->providers |= provider; | |
99 | } | |
100 | ||
101 | /* Provider is no longer operating on this auth client (you should use provider_done) */ | |
102 | static inline void unset_provider(struct auth_client *auth, provider_t provider) | |
103 | { | |
104 | auth->providers &= ~provider; | |
105 | } | |
106 | ||
107 | /* Check if provider is operating on this auth client */ | |
108 | static inline bool is_provider(struct auth_client *auth, provider_t provider) | |
109 | { | |
110 | return auth->providers & provider; | |
111 | } | |
112 | ||
0f95a274 | 113 | #endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */ |