]> jfr.im git - solanum.git/blame - authd/provider.h
providers/ident: fix inet_ntop/inet_pton mixup
[solanum.git] / authd / provider.h
CommitLineData
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 */
30typedef enum
31{
3e875f62
EM
32 PROVIDER_RDNS,
33 PROVIDER_IDENT,
34 PROVIDER_BLACKLIST,
2b0cc3d3
EM
35} provider_t;
36
37struct 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 */
43
44 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
45 uint16_t c_port; /* Client port */
46
47 char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
48 char username[USERLEN + 1]; /* Used for ident lookup */
49
3e875f62 50 uint32_t providers; /* Providers at work,
2b0cc3d3 51 * none left when set to 0 */
f7b37c1d 52
3e875f62 53 void *data[MAX_PROVIDERS]; /* Provider-specific data slots */
2b0cc3d3
EM
54};
55
56typedef bool (*provider_init_t)(void);
57typedef bool (*provider_perform_t)(struct auth_client *);
58typedef void (*provider_complete_t)(struct auth_client *, provider_t provider);
59typedef void (*provider_cancel_t)(struct auth_client *);
60typedef void (*provider_destroy_t)(void);
61
62struct auth_provider
63{
64 rb_dlink_node node;
65
66 provider_t id;
67
68 provider_init_t init; /* Initalise the provider */
69 provider_destroy_t destroy; /* Terminate the provider */
70
71 provider_perform_t start; /* Perform authentication */
72 provider_cancel_t cancel; /* Authentication cancelled */
73 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
74};
75
76extern rb_dlink_list auth_providers;
a52c7a8e 77extern rb_dictionary *auth_clients;
3e875f62 78
2b0cc3d3
EM
79extern struct auth_provider rdns_provider;
80extern struct auth_provider ident_provider;
81
2b0cc3d3
EM
82void load_provider(struct auth_provider *provider);
83void unload_provider(struct auth_provider *provider);
84
85void init_providers(void);
86void destroy_providers(void);
87void cancel_providers(struct auth_client *auth);
88
89void provider_done(struct auth_client *auth, provider_t id);
90void accept_client(struct auth_client *auth, provider_t id);
f7b37c1d 91void reject_client(struct auth_client *auth, provider_t id, const char *reason);
2b0cc3d3
EM
92
93void notice_client(struct auth_client *auth, const char *notice);
94
95void handle_new_connection(int parc, char *parv[]);
96
97/* Provider is operating on this auth_client (set this if you have async work to do) */
98static inline void set_provider(struct auth_client *auth, provider_t provider)
99{
3e875f62 100 auth->providers |= (1 << provider);
2b0cc3d3
EM
101}
102
103/* Provider is no longer operating on this auth client (you should use provider_done) */
104static inline void unset_provider(struct auth_client *auth, provider_t provider)
105{
3e875f62 106 auth->providers &= ~(1 << provider);
2b0cc3d3
EM
107}
108
109/* Check if provider is operating on this auth client */
110static inline bool is_provider(struct auth_client *auth, provider_t provider)
111{
3e875f62 112 return auth->providers & (1 << provider);
2b0cc3d3
EM
113}
114
115#endif /* __CHARYBDIS_AUTHD_PROVIDER_H__ */