xref: /openbsd/usr.sbin/radiusd/radiusd_module.h (revision 264ca280)
1 #ifndef _RADIUS_MODULE_H
2 #define _RADIUS_MODULE_H
3 
4 /*
5  * Copyright (c) 2015 YASUOKA Masahiko <yasuoka@ysauoka.net>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #include "radiusd.h"
21 
22 struct module_ctx;
23 
24 struct module_handlers {
25 	/* Should send IMSG_OK or IMSG_NG */
26 	void (*config_set)(void *ctx, const char *paramname, int paramvalc,
27 	    char * const * paramvalv);
28 
29 	void (*start)(void *ctx);
30 
31 	void (*stop)(void *ctx);
32 
33 	void (*userpass)(void *ctx, u_int query_id, const char *user,
34 	    const char *pass);
35 
36 	void (*access_request)(void *ctx, u_int query_id, const u_char *pkt,
37 	    size_t pktlen);
38 
39 	/* User-Password Attribute is encrypted if the module has the secret */
40 };
41 
42 #define SYNTAX_ASSERT(_cond, _msg)				\
43 	do {							\
44 		if (!(_cond)) {					\
45 			errmsg = (_msg);			\
46 			goto syntax_error;			\
47 		}						\
48 	} while (0 /* CONSTCOND */)
49 #include <sys/cdefs.h>
50 
51 __BEGIN_DECLS
52 
53 struct module_base	*module_create(int, void *, struct module_handlers *);
54 void			 module_start(struct module_base *);
55 int			 module_run(struct module_base *);
56 void			 module_destroy(struct module_base *);
57 void			 module_load(struct module_base *);
58 void			 module_drop_privilege(struct module_base *);
59 int			 module_notify_secret(struct module_base *,
60 			    const char *);
61 int			 module_send_message(struct module_base *, uint32_t,
62 			    const char *, ...)
63 			    __attribute__((__format__ (__printf__, 3, 4)));
64 int			 module_userpass_ok(struct module_base *, u_int,
65 			    const char *);
66 int			 module_userpass_fail(struct module_base *, u_int,
67 			    const char *);
68 int			 module_accsreq_answer(struct module_base *, u_int,
69 			    int, const u_char *, size_t);
70 int			 module_accsreq_aborted(struct module_base *, u_int);
71 
72 __END_DECLS
73 
74 #endif
75