Lines Matching full:base
93 struct module_base *base; in module_create() local
95 if ((base = calloc(1, sizeof(struct module_base))) == NULL) in module_create()
98 if (imsgbuf_init(&base->ibuf, sock) == -1) { in module_create()
99 free(base); in module_create()
102 base->ctx = ctx; in module_create()
115 return (base); in module_create()
119 module_start(struct module_base *base) in module_start() argument
124 if ((ival = fcntl(base->ibuf.fd, F_GETFL)) == -1) in module_start()
126 if (fcntl(base->ibuf.fd, F_SETFL, ival | O_NONBLOCK) == -1) in module_start()
128 event_set(&base->ev, base->ibuf.fd, EV_READ, module_on_event, base); in module_start()
129 event_add(&base->ev, NULL); in module_start()
134 module_run(struct module_base *base) in module_run() argument
138 ret = module_recv_imsg(base); in module_run()
140 imsgbuf_flush(&base->ibuf); in module_run()
146 module_destroy(struct module_base *base) in module_destroy() argument
148 if (base != NULL) { in module_destroy()
149 free(base->radpkt); in module_destroy()
150 free(base->radpkt2); in module_destroy()
151 imsgbuf_clear(&base->ibuf); in module_destroy()
153 free(base); in module_destroy()
157 module_load(struct module_base *base) in module_load() argument
176 imsg_compose(&base->ibuf, IMSG_RADIUSD_MODULE_LOAD, 0, 0, -1, &load, in module_load()
178 imsgbuf_flush(&base->ibuf); in module_load()
182 module_drop_privilege(struct module_base *base, int nochroot) in module_drop_privilege() argument
199 base->priv_dropped = true; in module_drop_privilege()
206 module_notify_secret(struct module_base *base, const char *secret) in module_notify_secret() argument
210 ret = imsg_compose(&base->ibuf, IMSG_RADIUSD_MODULE_NOTIFY_SECRET, in module_notify_secret()
212 module_reset_event(base); in module_notify_secret()
218 module_send_message(struct module_base *base, uint32_t cmd, const char *fmt, in module_send_message() argument
226 ret = imsg_compose(&base->ibuf, cmd, 0, 0, -1, NULL, 0); in module_send_message()
233 ret = imsg_compose(&base->ibuf, cmd, 0, 0, -1, msg, in module_send_message()
237 module_reset_event(base); in module_send_message()
243 module_userpass_ok(struct module_base *base, u_int q_id, const char *msg) in module_userpass_ok() argument
252 ret = imsg_composev(&base->ibuf, IMSG_RADIUSD_MODULE_USERPASS_OK, in module_userpass_ok()
254 module_reset_event(base); in module_userpass_ok()
260 module_userpass_fail(struct module_base *base, u_int q_id, const char *msg) in module_userpass_fail() argument
269 ret = imsg_composev(&base->ibuf, IMSG_RADIUSD_MODULE_USERPASS_FAIL, in module_userpass_fail()
271 module_reset_event(base); in module_userpass_fail()
277 module_accsreq_answer(struct module_base *base, u_int q_id, const u_char *pkt, in module_accsreq_answer() argument
280 return (module_common_radpkt(base, IMSG_RADIUSD_MODULE_ACCSREQ_ANSWER, in module_accsreq_answer()
285 module_accsreq_next(struct module_base *base, u_int q_id, const u_char *pkt, in module_accsreq_next() argument
288 return (module_common_radpkt(base, IMSG_RADIUSD_MODULE_ACCSREQ_NEXT, in module_accsreq_next()
293 module_accsreq_aborted(struct module_base *base, u_int q_id) in module_accsreq_aborted() argument
297 ret = imsg_compose(&base->ibuf, IMSG_RADIUSD_MODULE_ACCSREQ_ABORTED, in module_accsreq_aborted()
299 module_reset_event(base); in module_accsreq_aborted()
305 module_reqdeco_done(struct module_base *base, u_int q_id, const u_char *pkt, in module_reqdeco_done() argument
308 return (module_common_radpkt(base, IMSG_RADIUSD_MODULE_REQDECO_DONE, in module_reqdeco_done()
313 module_resdeco_done(struct module_base *base, u_int q_id, const u_char *pkt, in module_resdeco_done() argument
316 return (module_common_radpkt(base, IMSG_RADIUSD_MODULE_RESDECO_DONE, in module_resdeco_done()
321 module_common_radpkt(struct module_base *base, uint32_t imsg_type, u_int q_id, in module_common_radpkt() argument
345 ret = imsg_composev(&base->ibuf, imsg_type, 0, 0, -1, iov, in module_common_radpkt()
351 module_reset_event(base); in module_common_radpkt()
357 module_recv_imsg(struct module_base *base) in module_recv_imsg() argument
362 if ((n = imsgbuf_read(&base->ibuf)) != 1) { in module_recv_imsg()
365 module_stop(base); in module_recv_imsg()
369 if ((n = imsg_get(&base->ibuf, &imsg)) == -1) { in module_recv_imsg()
371 module_stop(base); in module_recv_imsg()
376 module_imsg_handler(base, &imsg); in module_recv_imsg()
379 module_reset_event(base); in module_recv_imsg()
385 module_imsg_handler(struct module_base *base, struct imsg *imsg) in module_imsg_handler() argument
404 module_send_message(base, IMSG_NG, in module_imsg_handler()
420 module_config_set(base->ctx, arg->paramname, in module_imsg_handler()
423 module_send_message(base, IMSG_NG, in module_imsg_handler()
431 module_start_module(base->ctx); in module_imsg_handler()
432 if (!base->priv_dropped) { in module_imsg_handler()
438 if (!base->priv_dropped) { in module_imsg_handler()
443 module_send_message(base, IMSG_OK, NULL); in module_imsg_handler()
447 module_stop(base); in module_imsg_handler()
465 module_userpass(base->ctx, userpass->q_id, userpass->user, in module_imsg_handler()
529 if (base->radpktsiz < accessreq->pktlen) { in module_imsg_handler()
531 if ((nradpkt = realloc(base->radpkt, in module_imsg_handler()
535 base->radpktoff = 0; in module_imsg_handler()
538 base->radpkt = nradpkt; in module_imsg_handler()
539 base->radpktsiz = accessreq->pktlen; in module_imsg_handler()
542 if (chunklen > base->radpktsiz - base->radpktoff){ in module_imsg_handler()
546 base->radpktoff = 0; in module_imsg_handler()
549 memcpy(base->radpkt + base->radpktoff, in module_imsg_handler()
551 base->radpktoff += chunklen; in module_imsg_handler()
554 if (base->radpktoff != accessreq->pktlen) { in module_imsg_handler()
558 base->radpktoff = 0; in module_imsg_handler()
562 module_access_request(base->ctx, accessreq->q_id, in module_imsg_handler()
563 base->radpkt, base->radpktoff); in module_imsg_handler()
565 module_next_response(base->ctx, accessreq->q_id, in module_imsg_handler()
566 base->radpkt, base->radpktoff); in module_imsg_handler()
568 module_request_decoration(base->ctx, accessreq->q_id, in module_imsg_handler()
569 base->radpkt, base->radpktoff); in module_imsg_handler()
572 if (base->radpktoff > base->radpkt2siz) { in module_imsg_handler()
574 if ((nradpkt = realloc(base->radpkt2, in module_imsg_handler()
575 base->radpktoff)) == NULL) { in module_imsg_handler()
578 base->radpktoff = 0; in module_imsg_handler()
581 base->radpkt2 = nradpkt; in module_imsg_handler()
582 base->radpkt2siz = base->radpktoff; in module_imsg_handler()
584 memcpy(base->radpkt2, base->radpkt, base->radpktoff); in module_imsg_handler()
585 base->radpkt2len = base->radpktoff; in module_imsg_handler()
587 module_response_decoration(base->ctx, accessreq->q_id, in module_imsg_handler()
588 base->radpkt2, base->radpkt2len, base->radpkt, in module_imsg_handler()
589 base->radpktoff); in module_imsg_handler()
590 base->radpkt2len = 0; in module_imsg_handler()
592 module_accounting_request(base->ctx, accessreq->q_id, in module_imsg_handler()
593 base->radpkt, base->radpktoff); in module_imsg_handler()
594 base->radpktoff = 0; in module_imsg_handler()
607 imsg_compose(&base->ibuf, IMSG_NG, in module_imsg_handler()
610 module_dispatch_control(base->ctx, imsg); in module_imsg_handler()
618 module_stop(struct module_base *base) in module_stop() argument
621 module_stop_module(base->ctx); in module_stop()
623 event_del(&base->ev); in module_stop()
624 base->stopped = true; in module_stop()
626 close(base->ibuf.fd); in module_stop()
633 struct module_base *base = ctx; in module_on_event() local
636 base->ev_onhandler = true; in module_on_event()
638 base->writeready = true; in module_on_event()
639 if (imsgbuf_write(&base->ibuf) == -1) { in module_on_event()
641 module_stop(base); in module_on_event()
644 base->writeready = false; in module_on_event()
647 ret = module_recv_imsg(base); in module_on_event()
651 base->ev_onhandler = false; in module_on_event()
652 module_reset_event(base); in module_on_event()
658 module_reset_event(struct module_base *base) in module_reset_event() argument
664 if (base->ev_onhandler) in module_reset_event()
666 if (base->stopped) in module_reset_event()
668 event_del(&base->ev); in module_reset_event()
671 if (imsgbuf_queuelen(&base->ibuf) > 0) { in module_reset_event()
672 if (!base->writeready) in module_reset_event()
677 event_set(&base->ev, base->ibuf.fd, evmask, module_on_event, base); in module_reset_event()
678 if (event_add(&base->ev, tvp) == -1) in module_reset_event()
684 module_imsg_compose(struct module_base *base, uint32_t type, uint32_t id, in module_imsg_compose() argument
689 if ((ret = imsg_compose(&base->ibuf, type, id, pid, fd, data, datalen)) in module_imsg_compose()
691 module_reset_event(base); in module_imsg_compose()
697 module_imsg_composev(struct module_base *base, uint32_t type, uint32_t id, in module_imsg_composev() argument
702 if ((ret = imsg_composev(&base->ibuf, type, id, pid, fd, iov, iovcnt)) in module_imsg_composev()
704 module_reset_event(base); in module_imsg_composev()