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