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 struct imsg; 24 25 struct module_handlers { 26 /* Should send IMSG_OK or IMSG_NG */ 27 void (*config_set)(void *ctx, const char *paramname, int paramvalc, 28 char * const * paramvalv); 29 30 void (*start)(void *ctx); 31 32 void (*stop)(void *ctx); 33 34 void (*userpass)(void *ctx, u_int query_id, const char *user, 35 const char *pass); 36 37 void (*access_request)(void *ctx, u_int query_id, const u_char *pkt, 38 size_t pktlen); 39 /* User-Password Attribute is encrypted if the module has the secret */ 40 41 void (*next_response)(void *ctx, u_int query_id, const u_char *pkt, 42 size_t pktlen); 43 44 void (*request_decoration)(void *ctx, u_int query_id, const u_char *pkt, 45 size_t pktlen); 46 47 void (*response_decoration)(void *ctx, u_int query_id, 48 const u_char *req, size_t reqlen, const u_char *res, size_t reslen); 49 50 void (*accounting_request)(void *ctx, u_int query_id, const u_char *pkt, 51 size_t pktlen); 52 53 void (*dispatch_control)(void *ctx, struct imsg *); 54 }; 55 56 #define SYNTAX_ASSERT(_cond, _msg) \ 57 do { \ 58 if (!(_cond)) { \ 59 errmsg = (_msg); \ 60 goto syntax_error; \ 61 } \ 62 } while (0 /* CONSTCOND */) 63 64 __BEGIN_DECLS 65 66 struct module_base *module_create(int, void *, struct module_handlers *); 67 void module_start(struct module_base *); 68 void module_stop(struct module_base *); 69 int module_run(struct module_base *); 70 void module_destroy(struct module_base *); 71 void module_load(struct module_base *); 72 void module_drop_privilege(struct module_base *, int); 73 int module_notify_secret(struct module_base *, 74 const char *); 75 int module_send_message(struct module_base *, uint32_t, 76 const char *, ...) 77 __attribute__((__format__ (__printf__, 3, 4))); 78 int module_userpass_ok(struct module_base *, u_int, 79 const char *); 80 int module_userpass_fail(struct module_base *, u_int, 81 const char *); 82 int module_accsreq_answer(struct module_base *, u_int, 83 const u_char *, size_t); 84 int module_accsreq_next(struct module_base *, u_int, 85 const u_char *, size_t); 86 int module_accsreq_aborted(struct module_base *, u_int); 87 int module_reqdeco_done(struct module_base *, u_int, 88 const u_char *, size_t); 89 int module_resdeco_done(struct module_base *, u_int, 90 const u_char *, size_t); 91 int module_imsg_compose(struct module_base *, uint32_t, 92 uint32_t, pid_t, int, const void *, size_t); 93 int module_imsg_composev(struct module_base *, uint32_t, 94 uint32_t, pid_t, int, const struct iovec *, int); 95 96 __END_DECLS 97 98 #endif 99