Lines Matching defs:module

232 	struct radiusd_module	*module;
284 TAILQ_FOREACH(module, &radiusd->module, next) {
286 radiusd_module_set(module, "_debug", 0, NULL);
287 radiusd_module_start(module);
303 struct radiusd_module *module;
322 TAILQ_FOREACH(module, &radiusd->module, next) {
323 radiusd_module_stop(module);
324 radiusd_module_close(module);
342 struct radiusd_module *module, *modulet;
372 TAILQ_FOREACH_SAFE(module, &radiusd->module, next, modulet) {
373 TAILQ_REMOVE(&radiusd->module, module, next);
374 radiusd_module_unload(module);
581 if (!MODULE_DO_USERPASS(authen->auth->module) &&
582 !MODULE_DO_ACCSREQ(authen->auth->module)) {
584 "username=%s: module `%s' is not running.",
586 req_id, username, authen->auth->module->name);
593 q->username, q->id, q->authen->auth->module->name);
628 /* pass NULL to hadnle this self without module */
665 if (q->deco == NULL || MODULE_DO_REQDECO(q->deco->module))
670 radiusd_module_request_decoration(q->deco->module, q);
673 if (MODULE_DO_ACCSREQ(authen->auth->module))
674 radiusd_module_access_request(authen->auth->module, q);
675 else if (MODULE_DO_USERPASS(authen->auth->module))
676 radiusd_module_userpass(authen->auth->module, q);
695 if (q->deco == NULL || MODULE_DO_RESDECO(q->deco->module))
700 radiusd_module_response_decoration(q->deco->module, q);
705 if (MODULE_DO_NEXTRES(q->prev->authen->auth->module)) {
714 radiusd_module_next_response(q->authen->auth->module,
757 /* handle by the module */
758 if (MODULE_DO_ACCTREQ(accounting->acct->module))
759 radiusd_module_account_request(accounting->acct->module,
835 q->authen->auth->module->name);
852 log_warnx("q=%u module `%s' requested next authentication "
854 q->authen->auth->module->name);
925 struct radiusd_module *module;
933 TAILQ_FOREACH(module, &radiusd->module, next) {
934 if (module->pid == pid) {
936 log_warnx("module `%s'(pid=%d) exited "
937 "with status %d", module->name,
940 log_warnx("module `%s'(pid=%d) exited "
941 "by signal %d", module->name,
947 if (!module) {
1018 TAILQ_INIT(&conf->module);
1039 authen_secret = q0->authen->auth->module->secret;
1041 q->authen->auth->module->secret;
1126 struct radiusd_module *module;
1128 TAILQ_FOREACH(module, &radiusd_s->module, next) {
1129 if (strcmp(module->name, module_name) == 0)
1132 if (module == NULL ||
1133 (module->capabilities & RADIUSD_MODULE_CAP_CONTROL) == 0 ||
1134 module->fd < 0)
1137 if (imsg_compose(&module->ibuf, type, id, pid, fd, data,
1140 radiusd_module_reset_ev_handler(module);
1146 * radiusd module handling
1151 struct radiusd_module *module = NULL;
1158 module = calloc(1, sizeof(struct radiusd_module));
1159 if (module == NULL)
1161 module->radiusd = radiusd;
1164 log_warn("Could not load module `%s'(%s): pipe()", name, path);
1170 log_warn("Could not load module `%s'(%s): fork()", name, path);
1189 module->fd = pairsock[0];
1190 if ((ival = fcntl(module->fd, F_GETFL)) == -1) {
1191 log_warn("Could not load module `%s': fcntl(F_GETFL)",
1195 if (fcntl(module->fd, F_SETFL, ival | O_NONBLOCK) == -1) {
1197 "Could not load module `%s': fcntl(F_SETFL,O_NONBLOCK)",
1201 strlcpy(module->name, name, sizeof(module->name));
1202 module->pid = pid;
1203 if (imsgbuf_init(&module->ibuf, module->fd) == -1) {
1204 log_warn("Could not load module `%s': imsgbuf_init", name);
1208 if (imsg_sync_read(&module->ibuf, MODULE_IO_TIMEOUT) <= 0 ||
1209 (n = imsg_get(&module->ibuf, &imsg)) <= 0) {
1210 log_warnx("Could not load module `%s': module didn't "
1216 log_warnx("Could not load module `%s': unknown imsg type=%d",
1221 module->capabilities =
1224 log_debug("Loaded module `%s' successfully. pid=%d", module->name,
1225 module->pid);
1228 return (module);
1231 free(module);
1241 radiusd_module_start(struct radiusd_module *module)
1247 RADIUSD_ASSERT(module->fd >= 0);
1248 imsg_compose(&module->ibuf, IMSG_RADIUSD_MODULE_START, 0, 0, -1,
1250 imsg_sync_flush(&module->ibuf, MODULE_IO_TIMEOUT);
1251 if (imsg_sync_read(&module->ibuf, MODULE_IO_TIMEOUT) <= 0 ||
1252 imsg_get(&module->ibuf, &imsg) <= 0) {
1254 module->name);
1263 module->name, (char *)imsg.data);
1266 module->name);
1268 log_warnx("Module `%s' could not started: module "
1269 "returned unknown message type %d", module->name,
1274 event_set(&module->ev, module->fd, EV_READ, radiusd_module_on_imsg_io,
1275 module);
1276 event_add(&module->ev, &tv);
1277 log_debug("Module `%s' started successfully", module->name);
1281 radiusd_module_close(module);
1286 radiusd_module_stop(struct radiusd_module *module)
1288 module->stopped = true;
1290 if (module->secret != NULL) {
1291 freezero(module->secret, strlen(module->secret));
1292 module->secret = NULL;
1295 if (module->fd >= 0) {
1296 imsg_compose(&module->ibuf, IMSG_RADIUSD_MODULE_STOP, 0, 0, -1,
1298 radiusd_module_reset_ev_handler(module);
1303 radiusd_module_close(struct radiusd_module *module)
1305 if (module->fd >= 0) {
1306 event_del(&module->ev);
1307 imsgbuf_clear(&module->ibuf);
1308 close(module->fd);
1309 module->fd = -1;
1314 radiusd_module_unload(struct radiusd_module *module)
1316 free(module->radpkt);
1317 radiusd_module_close(module);
1318 free(module);
1324 struct radiusd_module *module = ctx;
1327 module->writeready = true;
1328 if (imsgbuf_write(&module->ibuf) == -1) {
1329 log_warn("Failed to write to module `%s': "
1330 "imsgbuf_write()", module->name);
1333 module->writeready = false;
1337 if (radiusd_module_imsg_read(module) == -1)
1341 radiusd_module_reset_ev_handler(module);
1345 radiusd_module_close(module);
1349 radiusd_module_reset_ev_handler(struct radiusd_module *module)
1354 RADIUSD_ASSERT(module->fd >= 0);
1355 event_del(&module->ev);
1358 if (imsgbuf_queuelen(&module->ibuf) > 0) {
1359 if (!module->writeready)
1365 /* module stopped and no event handler is set */
1366 if (evmask & EV_WRITE && tvp == NULL && module->stopped) {
1368 radiusd_module_close(module);
1372 event_set(&module->ev, module->fd, evmask, radiusd_module_on_imsg_io,
1373 module);
1374 if (event_add(&module->ev, tvp) == -1) {
1375 log_warn("Could not set event handlers for module `%s': "
1376 "event_add()", module->name);
1377 radiusd_module_close(module);
1382 radiusd_module_imsg_read(struct radiusd_module *module)
1387 if ((n = imsgbuf_read(&module->ibuf)) != 1) {
1389 log_warn("Receiving a message from module `%s' "
1390 "failed: imsgbuf_read", module->name);
1392 radiusd_module_close(module);
1396 if ((n = imsg_get(&module->ibuf, &imsg)) == -1) {
1397 log_warn("Receiving a message from module `%s' failed: "
1398 "imsg_get", module->name);
1403 radiusd_module_imsg(module, &imsg);
1411 radiusd_module_imsg(struct radiusd_module *module, struct imsg *imsg)
1421 module->secret = strdup(imsg->data);
1422 if (module->secret == NULL)
1424 "from `%s'", module->name);
1440 q = radiusd_find_query(module->radiusd, q_id);
1443 "unknown", msgtypestr, module->name, q_id);
1493 q = radiusd_find_query(module->radiusd, q_id);
1496 "unknown", typestr, module->name, q_id);
1499 if ((ans = radiusd_module_recv_radpkt(module, imsg,
1503 if (module->radpktoff > 0 &&
1505 module->radpkt, module->radpktoff)) == NULL) {
1511 module->radpktoff = 0;
1530 log_warnx("q=%u wrong pkt from module",
1540 log_warnx("q=%u wrong pkt from module",
1576 q = radiusd_find_query(module->radiusd, q_id);
1579 "id=%u unknown", module->name, q_id);
1586 control_conn_bind(imsg->hdr.peerid, module->name);
1593 imsg->hdr.type, module->name));
1598 radiusd_module_recv_radpkt(struct radiusd_module *module, struct imsg *imsg,
1606 if (module->radpktsiz < ans->pktlen) {
1608 if ((nradpkt = realloc(module->radpkt, ans->pktlen)) == NULL) {
1610 "`%s'", type_str, module->name);
1613 module->radpkt = nradpkt;
1614 module->radpktsiz = ans->pktlen;
1617 if (chunklen > module->radpktsiz - module->radpktoff) {
1619 "received length is too big", type_str, module->name);
1623 memcpy(module->radpkt + module->radpktoff,
1625 module->radpktoff += chunklen;
1629 if (module->radpktoff != ans->pktlen) {
1631 "length is mismatch", type_str, module->name);
1637 module->radpktoff = 0;
1642 radiusd_module_set(struct radiusd_module *module, const char *name,
1670 "module `%s': realloc", module->name);
1687 if (imsg_composev(&module->ibuf, IMSG_RADIUSD_MODULE_SET_CONFIG, 0, 0,
1689 log_warn("Failed to set config parameter to module `%s': "
1690 "imsg_composev", module->name);
1693 if (imsg_sync_flush(&module->ibuf, MODULE_IO_TIMEOUT) == -1) {
1694 log_warn("Failed to set config parameter to module `%s': "
1695 "imsg_flush_timeout", module->name);
1699 if (imsg_sync_read(&module->ibuf, MODULE_IO_TIMEOUT) <= 0) {
1700 log_warn("Failed to get reply from module `%s': "
1701 "imsg_sync_read", module->name);
1704 if ((n = imsg_get(&module->ibuf, &imsg)) > 0)
1707 log_warn("Failed to get reply from module `%s': "
1708 "imsg_get", module->name);
1713 log_warnx("Could not set `%s' for module `%s': %s", name,
1714 module->name, (char *)imsg.data);
1718 log_warnx("Failed to get reply from module `%s': "
1719 "unknown imsg type=%d", module->name, imsg.hdr.type);
1733 radiusd_module_userpass(struct radiusd_module *module, struct radius_query *q)
1750 imsg_compose(&module->ibuf, IMSG_RADIUSD_MODULE_USERPASS, 0, 0, -1,
1752 radiusd_module_reset_ev_handler(module);
1759 radiusd_module_access_request(struct radiusd_module *module,
1768 module->name);
1778 if (imsg_compose_radius_packet(&module->ibuf,
1781 module->name);
1784 radiusd_module_reset_ev_handler(module);
1789 radiusd_module_next_response(struct radiusd_module *module,
1792 if (imsg_compose_radius_packet(&module->ibuf,
1795 module->name);
1798 radiusd_module_reset_ev_handler(module);
1802 radiusd_module_request_decoration(struct radiusd_module *module,
1805 if (module->fd < 0) {
1806 log_warnx("q=%u Could not send REQDECO to `%s': module is "
1807 "not running?", q->id, module->name);
1811 if (imsg_compose_radius_packet(&module->ibuf,
1814 module->name);
1820 radiusd_module_reset_ev_handler(module);
1824 radiusd_module_response_decoration(struct radiusd_module *module,
1827 if (module->fd < 0) {
1828 log_warnx("q=%u Could not send RESDECO to `%s': module is "
1829 "not running?", q->id, module->name);
1833 if (imsg_compose_radius_packet(&module->ibuf,
1836 module->name);
1840 if (imsg_compose_radius_packet(&module->ibuf,
1843 module->name);
1849 radiusd_module_reset_ev_handler(module);
1853 radiusd_module_account_request(struct radiusd_module *module,
1861 module->name);
1865 if (imsg_compose_radius_packet(&module->ibuf,
1868 module->name);
1871 radiusd_module_reset_ev_handler(module);