]> jfr.im git - solanum.git/blame - authd/auth.h
auth: minor changes
[solanum.git] / authd / auth.h
CommitLineData
05e17ac2
EM
1/* authd/auth.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_AUTH_H__
22#define __CHARYBDIS_AUTHD_AUTH_H__
23
24#include "stdinc.h"
25
26/* Arbitrary limit */
27#define MAX_CLIENTS 1024
28
29/* Registered providers */
30typedef enum
31{
32 PROVIDER_NULL = 0x0, /* Dummy value */
33 PROVIDER_RDNS = 0x1,
34 PROVIDER_IDENT = 0x2,
35 PROVIDER_BLACKLIST = 0x4,
36 PROVIDER_DUMMY = 0x8,
37} provider_t;
38
39struct auth_client
40{
41 uint16_t cid; /* Client ID */
42
43 char l_ip[HOSTIPLEN + 1]; /* Listener IP address */
44 uint16_t l_port; /* Listener port */
45
46 char c_ip[HOSTIPLEN + 1]; /* Client IP address */
47 uint16_t c_port; /* Client port */
48
49 char hostname[IRCD_RES_HOSTLEN + 1]; /* Used for DNS lookup */
50 char username[USERLEN + 1]; /* Used for ident lookup */
51
52 unsigned int providers; /* Providers at work,
53 * none left when set to 0 */
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 provider_t provider;
65
66 provider_init_t init; /* Initalise the provider */
67 provider_destroy_t destroy; /* Terminate the provider */
68
69 provider_perform_t start; /* Perform authentication */
70 provider_cancel_t cancel; /* Authentication cancelled */
71 provider_complete_t completed; /* Callback for when other performers complete (think dependency chains) */
72};
73
74#define AUTH_PROVIDER_FOREACH(a) for((a) = auth_providers; (a)->provider; (a)++)
75
76void init_providers(void);
77void destroy_providers(void);
78void cancel_providers(struct auth_client *auth);
79
80void provider_done(struct auth_client *auth, provider_t provider);
f42aa1a9
EM
81void reject_client(struct auth_client *auth, provider_t provider, const char *reason);
82void accept_client(struct auth_client *auth, provider_t provider);
05e17ac2 83
05e17ac2
EM
84void notice_client(struct auth_client *auth, const char *notice);
85
86void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port);
87void handle_new_connection(int parc, char *parv[]);
88
89/* Provider is operating on this auth_client (set this if you have async work to do) */
90static inline void set_provider(struct auth_client *auth, provider_t provider)
91{
92 auth->providers |= provider;
93}
94
95/* Provider is no longer operating on this auth client (you should use provider_done) */
96static inline void unset_provider(struct auth_client *auth, provider_t provider)
97{
98 auth->providers &= ~provider;
99}
100
101/* Check if provider is operating on this auth client */
102static inline bool is_provider(struct auth_client *auth, provider_t provider)
103{
104 return auth->providers & provider;
105}
106
107#endif /* __CHARYBDIS_AUTHD_AUTH_H__ */