]> jfr.im git - solanum.git/blob - ircd/authproc.c
Add tests for valid_temp_time
[solanum.git] / ircd / authproc.c
1 /*
2 * authd.c: An interface to authd.
3 * (based somewhat on ircd-ratbox dns.c)
4 *
5 * Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
6 * Copyright (C) 2005-2012 ircd-ratbox development team
7 * Copyright (C) 2016 Ariadne Conill <ariadne@dereferenced.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
22 * USA
23 */
24
25 #include "stdinc.h"
26 #include "rb_lib.h"
27 #include "client.h"
28 #include "ircd_defs.h"
29 #include "parse.h"
30 #include "authproc.h"
31 #include "match.h"
32 #include "logger.h"
33 #include "s_conf.h"
34 #include "s_stats.h"
35 #include "client.h"
36 #include "packet.h"
37 #include "hash.h"
38 #include "send.h"
39 #include "numeric.h"
40 #include "msg.h"
41 #include "dns.h"
42
43 typedef void (*authd_cb_t)(int, char **);
44
45 struct authd_cb
46 {
47 authd_cb_t fn;
48 int min_parc;
49 };
50
51 static int start_authd(void);
52 static void parse_authd_reply(rb_helper * helper);
53 static void restart_authd_cb(rb_helper * helper);
54 static EVH timeout_dead_authd_clients;
55
56 static void cmd_accept_client(int parc, char **parv);
57 static void cmd_reject_client(int parc, char **parv);
58 static void cmd_dns_result(int parc, char **parv);
59 static void cmd_notice_client(int parc, char **parv);
60 static void cmd_oper_warn(int parc, char **parv);
61 static void cmd_stats_results(int parc, char **parv);
62
63 rb_helper *authd_helper;
64 static char *authd_path;
65
66 uint32_t cid;
67 static rb_dictionary *cid_clients;
68 static struct ev_entry *timeout_ev;
69
70 rb_dictionary *dnsbl_stats;
71
72 rb_dlink_list opm_list;
73 struct OPMListener opm_listeners[LISTEN_LAST];
74
75 static struct authd_cb authd_cmd_tab[256] =
76 {
77 ['A'] = { cmd_accept_client, 4 },
78 ['E'] = { cmd_dns_result, 5 },
79 ['N'] = { cmd_notice_client, 3 },
80 ['R'] = { cmd_reject_client, 7 },
81 ['W'] = { cmd_oper_warn, 3 },
82 ['X'] = { cmd_stats_results, 3 },
83 ['Y'] = { cmd_stats_results, 3 },
84 ['Z'] = { cmd_stats_results, 3 },
85 };
86
87 static int
88 start_authd(void)
89 {
90 char fullpath[PATH_MAX + 1];
91
92 if(authd_path == NULL)
93 {
94 snprintf(fullpath, sizeof(fullpath), "%s/authd", ircd_paths[IRCD_PATH_LIBEXEC]);
95
96 if(access(fullpath, X_OK) == -1)
97 {
98 snprintf(fullpath, sizeof(fullpath), "%s/bin/authd", ConfigFileEntry.dpath);
99 if(access(fullpath, X_OK) == -1)
100 {
101 ierror("Unable to execute authd in %s or %s/bin",
102 ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
103 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
104 "Unable to execute authd in %s or %s/bin",
105 ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
106 return 1;
107 }
108
109 }
110
111 authd_path = rb_strdup(fullpath);
112 }
113
114 if(cid_clients == NULL)
115 cid_clients = rb_dictionary_create("authd cid to uid mapping", rb_uint32cmp);
116
117 if(timeout_ev == NULL)
118 timeout_ev = rb_event_addish("timeout_dead_authd_clients", timeout_dead_authd_clients, NULL, 1);
119
120 authd_helper = rb_helper_start("authd", authd_path, parse_authd_reply, restart_authd_cb);
121
122 if(authd_helper == NULL)
123 {
124 ierror("Unable to start authd helper: %s", strerror(errno));
125 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Unable to start authd helper: %s", strerror(errno));
126 return 1;
127 }
128
129 ilog(L_MAIN, "authd helper started");
130 sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authd helper started");
131 rb_helper_run(authd_helper);
132 return 0;
133 }
134
135 static inline uint32_t
136 str_to_cid(const char *str)
137 {
138 long lcid = strtol(str, NULL, 16);
139
140 if(lcid > UINT32_MAX || lcid <= 0)
141 {
142 iwarn("authd sent us back a bad client ID: %lx", lcid);
143 restart_authd();
144 return 0;
145 }
146
147 return (uint32_t)lcid;
148 }
149
150 static inline struct Client *
151 cid_to_client(uint32_t ncid, bool del)
152 {
153 struct Client *client_p;
154
155 if(del)
156 client_p = rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(ncid));
157 else
158 client_p = rb_dictionary_retrieve(cid_clients, RB_UINT_TO_POINTER(ncid));
159
160 /* If the client's not found, that's okay, it may have already gone away.
161 * --Elizafox */
162
163 return client_p;
164 }
165
166 static inline struct Client *
167 str_cid_to_client(const char *str, bool del)
168 {
169 uint32_t ncid = str_to_cid(str);
170
171 if(ncid == 0)
172 return NULL;
173
174 return cid_to_client(ncid, del);
175 }
176
177 static void
178 cmd_accept_client(int parc, char **parv)
179 {
180 struct Client *client_p;
181
182 /* cid to uid (retrieve and delete) */
183 if((client_p = str_cid_to_client(parv[1], true)) == NULL)
184 return;
185
186 authd_accept_client(client_p, parv[2], parv[3]);
187 }
188
189 static void
190 cmd_dns_result(int parc, char **parv)
191 {
192 dns_results_callback(parv[1], parv[2], parv[3], parv[4]);
193 }
194
195 static void
196 cmd_notice_client(int parc, char **parv)
197 {
198 struct Client *client_p;
199
200 if ((client_p = str_cid_to_client(parv[1], false)) == NULL)
201 return;
202
203 if (IsAnyDead(client_p))
204 return;
205
206 sendto_one_notice(client_p, ":%s", parv[2]);
207 }
208
209 static void
210 cmd_reject_client(int parc, char **parv)
211 {
212 struct Client *client_p;
213
214 /* cid to uid (retrieve and delete) */
215 if((client_p = str_cid_to_client(parv[1], true)) == NULL)
216 return;
217
218 authd_reject_client(client_p, parv[3], parv[4], toupper(*parv[2]), parv[5], parv[6]);
219 }
220
221 static void
222 cmd_oper_warn(int parc, char **parv)
223 {
224 switch(*parv[1])
225 {
226 case 'D': /* Debug */
227 sendto_realops_snomask(SNO_DEBUG, L_ALL, "authd debug: %s", parv[2]);
228 idebug("authd: %s", parv[2]);
229 break;
230 case 'I': /* Info */
231 sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd info: %s", parv[2]);
232 inotice("authd: %s", parv[2]);
233 break;
234 case 'W': /* Warning */
235 sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd WARNING: %s", parv[2]);
236 iwarn("authd: %s", parv[2]);
237 break;
238 case 'C': /* Critical (error) */
239 sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd CRITICAL: %s", parv[2]);
240 ierror("authd: %s", parv[2]);
241 break;
242 default: /* idk */
243 sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd sent us an unknown oper notice type (%s): %s", parv[1], parv[2]);
244 ilog(L_MAIN, "authd unknown oper notice type (%s): %s", parv[1], parv[2]);
245 break;
246 }
247 }
248
249 static void
250 cmd_stats_results(int parc, char **parv)
251 {
252 /* Select by type */
253 switch(*parv[2])
254 {
255 case 'D':
256 /* parv[0] conveys status */
257 if(parc < 4)
258 {
259 iwarn("authd sent a result with wrong number of arguments: got %d", parc);
260 restart_authd();
261 return;
262 }
263 dns_stats_results_callback(parv[1], parv[0], parc - 3, (const char **)&parv[3]);
264 break;
265 default:
266 break;
267 }
268 }
269
270 static void
271 parse_authd_reply(rb_helper * helper)
272 {
273 ssize_t len;
274 int parc;
275 char buf[READBUF_SIZE];
276 char *parv[MAXPARA];
277
278 while((len = rb_helper_read(helper, buf, sizeof(buf))) > 0)
279 {
280 struct authd_cb *cmd;
281
282 parc = rb_string_to_array(buf, parv, sizeof(parv));
283 cmd = &authd_cmd_tab[(unsigned char)*parv[0]];
284 if(cmd->fn != NULL)
285 {
286 if(cmd->min_parc > parc)
287 {
288 iwarn("authd sent a result with wrong number of arguments: expected %d, got %d",
289 cmd->min_parc, parc);
290 restart_authd();
291 continue;
292 }
293
294 cmd->fn(parc, parv);
295 }
296 else
297 {
298 iwarn("authd sent us a bad command type: %c", *parv[0]);
299 restart_authd();
300 continue;
301 }
302 }
303 }
304
305 void
306 init_authd(void)
307 {
308 if(start_authd())
309 {
310 ierror("Unable to start authd helper: %s", strerror(errno));
311 exit(0);
312 }
313 }
314
315 void
316 configure_authd(void)
317 {
318 /* Timeouts */
319 set_authd_timeout("ident_timeout", GlobalSetOptions.ident_timeout);
320 set_authd_timeout("rdns_timeout", ConfigFileEntry.connect_timeout);
321 set_authd_timeout("rbl_timeout", ConfigFileEntry.connect_timeout);
322
323 ident_check_enable(!ConfigFileEntry.disable_auth);
324
325 /* Configure OPM */
326 if(rb_dlink_list_length(&opm_list) > 0 &&
327 (opm_listeners[LISTEN_IPV4].ipaddr[0] != '\0' ||
328 opm_listeners[LISTEN_IPV6].ipaddr[0] != '\0'))
329 {
330 rb_dlink_node *ptr;
331
332 if(opm_listeners[LISTEN_IPV4].ipaddr[0] != '\0')
333 rb_helper_write(authd_helper, "O opm_listener %s %hu",
334 opm_listeners[LISTEN_IPV4].ipaddr, opm_listeners[LISTEN_IPV4].port);
335
336 if(opm_listeners[LISTEN_IPV6].ipaddr[0] != '\0')
337 rb_helper_write(authd_helper, "O opm_listener %s %hu",
338 opm_listeners[LISTEN_IPV6].ipaddr, opm_listeners[LISTEN_IPV6].port);
339
340 RB_DLINK_FOREACH(ptr, opm_list.head)
341 {
342 struct OPMScanner *scanner = ptr->data;
343 rb_helper_write(authd_helper, "O opm_scanner %s %hu",
344 scanner->type, scanner->port);
345 }
346
347 opm_check_enable(true);
348 }
349 else
350 opm_check_enable(false);
351 }
352
353 static void
354 authd_free_client(struct Client *client_p)
355 {
356 if(client_p == NULL || client_p->preClient == NULL)
357 return;
358
359 if(client_p->preClient->auth.cid == 0)
360 return;
361
362 if(authd_helper != NULL)
363 rb_helper_write(authd_helper, "E %x", client_p->preClient->auth.cid);
364
365 client_p->preClient->auth.accepted = true;
366 client_p->preClient->auth.cid = 0;
367 }
368
369 static void
370 authd_free_client_cb(rb_dictionary_element *delem, void *unused)
371 {
372 struct Client *client_p = delem->data;
373 authd_free_client(client_p);
374 }
375
376 void
377 authd_abort_client(struct Client *client_p)
378 {
379 rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
380 authd_free_client(client_p);
381 }
382
383 static void
384 restart_authd_cb(rb_helper * helper)
385 {
386 iwarn("authd: restart_authd_cb called, authd died?");
387 sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd: restart_authd_cb called, authd died?");
388
389 if(helper != NULL)
390 {
391 rb_helper_close(helper);
392 authd_helper = NULL;
393 }
394
395 rb_dictionary_destroy(cid_clients, authd_free_client_cb, NULL);
396 cid_clients = NULL;
397
398 start_authd();
399 configure_authd();
400 }
401
402 void
403 restart_authd(void)
404 {
405 ierror("authd restarting...");
406 restart_authd_cb(authd_helper);
407 }
408
409 void
410 rehash_authd(void)
411 {
412 rb_helper_write(authd_helper, "R");
413 }
414
415 void
416 check_authd(void)
417 {
418 if(authd_helper == NULL)
419 restart_authd();
420 }
421
422 static inline uint32_t
423 generate_cid(void)
424 {
425 if(++cid == 0)
426 cid = 1;
427
428 return cid;
429 }
430
431 /* Basically when this is called we begin handing off the client to authd for
432 * processing. authd "owns" the client until processing is finished, or we
433 * timeout from authd. authd will make a decision whether or not to accept the
434 * client, but it's up to other parts of the code (for now) to decide if we're
435 * gonna accept the client and ignore authd's suggestion.
436 *
437 * --Elizafox
438 *
439 * If this is an SSL connection we must defer handing off the client for
440 * reading until it is open and we have the certificate fingerprint, otherwise
441 * it's possible for the client to immediately send data before authd completes
442 * and before the status of the connection is communicated via ssld. This data
443 * could then be processed too early by read_packet().
444 */
445 void
446 authd_initiate_client(struct Client *client_p, bool defer)
447 {
448 char client_ipaddr[HOSTIPLEN+1];
449 char listen_ipaddr[HOSTIPLEN+1];
450 uint16_t client_port, listen_port;
451 uint32_t authd_cid;
452
453 if(client_p->preClient == NULL || client_p->preClient->auth.cid != 0)
454 return;
455
456 authd_cid = client_p->preClient->auth.cid = generate_cid();
457
458 /* Collisions are extremely unlikely, so disregard the possibility */
459 rb_dictionary_add(cid_clients, RB_UINT_TO_POINTER(authd_cid), client_p);
460
461 /* Retrieve listener and client IP's */
462 rb_inet_ntop_sock((struct sockaddr *)&client_p->preClient->lip, listen_ipaddr, sizeof(listen_ipaddr));
463 rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip, client_ipaddr, sizeof(client_ipaddr));
464
465 /* Retrieve listener and client ports */
466 listen_port = ntohs(GET_SS_PORT(&client_p->preClient->lip));
467 client_port = ntohs(GET_SS_PORT(&client_p->localClient->ip));
468
469 if(defer)
470 client_p->preClient->auth.flags |= AUTHC_F_DEFERRED;
471
472 /* Add a bit of a fudge factor... */
473 client_p->preClient->auth.timeout = rb_current_time() + ConfigFileEntry.connect_timeout + 10;
474
475 rb_helper_write(authd_helper, "C %x %s %hu %s %hu %x", authd_cid, listen_ipaddr, listen_port, client_ipaddr, client_port,
476 #ifdef HAVE_LIBSCTP
477 IsSCTP(client_p) ? IPPROTO_SCTP : IPPROTO_TCP);
478 #else
479 IPPROTO_TCP);
480 #endif
481 }
482
483 static inline void
484 authd_read_client(struct Client *client_p)
485 {
486 /*
487 * When a client has auth'ed, we want to start reading what it sends
488 * us. This is what read_packet() does.
489 * -- adrian
490 *
491 * Above comment was originally in s_auth.c, but moved here with below code.
492 * --Elizafox
493 */
494 rb_dlinkAddTail(client_p, &client_p->node, &global_client_list);
495 read_packet(client_p->localClient->F, client_p);
496 }
497
498 /* When this is called we have a decision on client acceptance.
499 *
500 * After this point authd no longer "owns" the client, but if
501 * it's flagged as deferred then we're still waiting for a call
502 * to authd_deferred_client().
503 */
504 static inline void
505 authd_decide_client(struct Client *client_p, const char *ident, const char *host, bool accept, char cause, const char *data, const char *reason)
506 {
507 if(client_p->preClient == NULL || client_p->preClient->auth.cid == 0)
508 return;
509
510 if(*ident != '*')
511 {
512 rb_strlcpy(client_p->username, ident, sizeof(client_p->username));
513 SetGotId(client_p);
514 ServerStats.is_asuc++;
515 }
516 else
517 ServerStats.is_abad++; /* s_auth used to do this, stay compatible */
518
519 if(*host != '*')
520 rb_strlcpy(client_p->host, host, sizeof(client_p->host));
521
522 rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
523
524 client_p->preClient->auth.accepted = accept;
525 client_p->preClient->auth.cause = cause;
526 client_p->preClient->auth.data = (data == NULL ? NULL : rb_strdup(data));
527 client_p->preClient->auth.reason = (reason == NULL ? NULL : rb_strdup(reason));
528 client_p->preClient->auth.cid = 0;
529
530 client_p->preClient->auth.flags |= AUTHC_F_COMPLETE;
531 if((client_p->preClient->auth.flags & AUTHC_F_DEFERRED) == 0)
532 authd_read_client(client_p);
533 }
534
535 void
536 authd_deferred_client(struct Client *client_p)
537 {
538 client_p->preClient->auth.flags &= ~AUTHC_F_DEFERRED;
539 if(client_p->preClient->auth.flags & AUTHC_F_COMPLETE)
540 authd_read_client(client_p);
541 }
542
543 /* Convenience function to accept client */
544 void
545 authd_accept_client(struct Client *client_p, const char *ident, const char *host)
546 {
547 authd_decide_client(client_p, ident, host, true, '\0', NULL, NULL);
548 }
549
550 /* Convenience function to reject client */
551 void
552 authd_reject_client(struct Client *client_p, const char *ident, const char *host, char cause, const char *data, const char *reason)
553 {
554 authd_decide_client(client_p, ident, host, false, cause, data, reason);
555 }
556
557 static void
558 timeout_dead_authd_clients(void *notused __unused)
559 {
560 rb_dictionary_iter iter;
561 struct Client *client_p;
562 rb_dlink_list freelist = { NULL, NULL, 0 };
563 rb_dlink_node *ptr, *nptr;
564
565 RB_DICTIONARY_FOREACH(client_p, &iter, cid_clients)
566 {
567 if(client_p->preClient->auth.timeout < rb_current_time())
568 {
569 authd_free_client(client_p);
570 rb_dlinkAddAlloc(client_p, &freelist);
571 }
572 }
573
574 /* RB_DICTIONARY_FOREACH is not safe for deletion, so we do this crap */
575 RB_DLINK_FOREACH_SAFE(ptr, nptr, freelist.head)
576 {
577 client_p = ptr->data;
578 rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
579 }
580 }
581
582 /* Send a new DNSBL entry to authd */
583 void
584 add_dnsbl_entry(const char *host, const char *reason, uint8_t iptype, rb_dlink_list *filters)
585 {
586 rb_dlink_node *ptr;
587 struct DNSBLEntryStats *stats = rb_malloc(sizeof(*stats));
588 char filterbuf[BUFSIZE] = "*";
589 size_t s = 0;
590
591 if(dnsbl_stats == NULL)
592 dnsbl_stats = rb_dictionary_create("dnsbl statistics", rb_strcasecmp);
593
594 /* Build a list of comma-separated values for authd.
595 * We don't check for validity - do it elsewhere.
596 */
597 RB_DLINK_FOREACH(ptr, filters->head)
598 {
599 char *filter = ptr->data;
600 size_t filterlen = strlen(filter) + 1;
601
602 if(s + filterlen > sizeof(filterbuf))
603 break;
604
605 snprintf(&filterbuf[s], sizeof(filterbuf) - s, "%s,", filter);
606
607 s += filterlen;
608 }
609
610 if(s)
611 filterbuf[s - 1] = '\0';
612
613 stats->host = rb_strdup(host);
614 stats->iptype = iptype;
615 stats->hits = 0;
616 rb_dictionary_add(dnsbl_stats, stats->host, stats);
617
618 rb_helper_write(authd_helper, "O rbl %s %hhu %s :%s", host, iptype, filterbuf, reason);
619 }
620
621 /* Delete a DNSBL entry. */
622 void
623 del_dnsbl_entry(const char *host)
624 {
625 struct DNSBLEntryStats *stats = rb_dictionary_retrieve(dnsbl_stats, host);
626 if(stats != NULL)
627 {
628 rb_dictionary_delete(dnsbl_stats, host);
629 rb_free(stats->host);
630 rb_free(stats);
631 }
632
633 rb_helper_write(authd_helper, "O rbl_del %s", host);
634 }
635
636 static void
637 dnsbl_delete_elem(rb_dictionary_element *delem, void *unused)
638 {
639 struct DNSBLEntryStats *stats = delem->data;
640
641 rb_free(stats->host);
642 rb_free(stats);
643 }
644
645 /* Delete all the DNSBL entries. */
646 void
647 del_dnsbl_entry_all(void)
648 {
649 if(dnsbl_stats != NULL)
650 rb_dictionary_destroy(dnsbl_stats, dnsbl_delete_elem, NULL);
651 dnsbl_stats = NULL;
652
653 rb_helper_write(authd_helper, "O rbl_del_all");
654 }
655
656 /* Adjust an authd timeout value */
657 bool
658 set_authd_timeout(const char *key, int timeout)
659 {
660 if(timeout <= 0)
661 return false;
662
663 rb_helper_write(authd_helper, "O %s %d", key, timeout);
664 return true;
665 }
666
667 /* Enable identd checks */
668 void
669 ident_check_enable(bool enabled)
670 {
671 rb_helper_write(authd_helper, "O ident_enabled %d", enabled ? 1 : 0);
672 }
673
674 /* Create an OPM listener
675 * XXX - This is a big nasty hack, but it avoids resending duplicate data when
676 * configure_authd() is called.
677 */
678 void
679 conf_create_opm_listener(const char *ip, uint16_t port)
680 {
681 char ipbuf[HOSTIPLEN];
682 struct OPMListener *listener;
683
684 rb_strlcpy(ipbuf, ip, sizeof(ipbuf));
685 if(ipbuf[0] == ':')
686 {
687 memmove(ipbuf + 1, ipbuf, sizeof(ipbuf) - 1);
688 ipbuf[0] = '0';
689 }
690
691 /* I am much too lazy to use rb_inet_pton and GET_SS_FAMILY for now --Elizafox */
692 listener = &opm_listeners[(strchr(ipbuf, ':') != NULL ? LISTEN_IPV6 : LISTEN_IPV4)];
693 rb_strlcpy(listener->ipaddr, ipbuf, sizeof(listener->ipaddr));
694 listener->port = port;
695 }
696
697 void
698 create_opm_listener(const char *ip, uint16_t port)
699 {
700 char ipbuf[HOSTIPLEN];
701
702 /* XXX duplicated in conf_create_opm_listener */
703 rb_strlcpy(ipbuf, ip, sizeof(ipbuf));
704 if(ipbuf[0] == ':')
705 {
706 memmove(ipbuf + 1, ipbuf, sizeof(ipbuf) - 1);
707 ipbuf[0] = '0';
708 }
709
710 conf_create_opm_listener(ip, port);
711 rb_helper_write(authd_helper, "O opm_listener %s %hu", ipbuf, port);
712 }
713
714 void
715 delete_opm_listener_all(void)
716 {
717 memset(&opm_listeners, 0, sizeof(opm_listeners));
718 rb_helper_write(authd_helper, "O opm_listener_del_all");
719 }
720
721 /* Disable all OPM scans */
722 void
723 opm_check_enable(bool enabled)
724 {
725 rb_helper_write(authd_helper, "O opm_enabled %d", enabled ? 1 : 0);
726 }
727
728 /* Create an OPM proxy scanner
729 * XXX - This is a big nasty hack, but it avoids resending duplicate data when
730 * configure_authd() is called.
731 */
732 void
733 conf_create_opm_proxy_scanner(const char *type, uint16_t port)
734 {
735 struct OPMScanner *scanner = rb_malloc(sizeof(struct OPMScanner));
736
737 rb_strlcpy(scanner->type, type, sizeof(scanner->type));
738 scanner->port = port;
739 rb_dlinkAdd(scanner, &scanner->node, &opm_list);
740 }
741
742 void
743 create_opm_proxy_scanner(const char *type, uint16_t port)
744 {
745 conf_create_opm_proxy_scanner(type, port);
746 rb_helper_write(authd_helper, "O opm_scanner %s %hu", type, port);
747 }
748
749 void
750 delete_opm_proxy_scanner(const char *type, uint16_t port)
751 {
752 rb_dlink_node *ptr, *nptr;
753
754 RB_DLINK_FOREACH_SAFE(ptr, nptr, opm_list.head)
755 {
756 struct OPMScanner *scanner = ptr->data;
757
758 if(rb_strncasecmp(scanner->type, type, sizeof(scanner->type)) == 0 &&
759 scanner->port == port)
760 {
761 rb_dlinkDelete(ptr, &opm_list);
762 rb_free(scanner);
763 break;
764 }
765 }
766
767 rb_helper_write(authd_helper, "O opm_scanner_del %s %hu", type, port);
768 }
769
770 void
771 delete_opm_proxy_scanner_all(void)
772 {
773 rb_dlink_node *ptr, *nptr;
774
775 RB_DLINK_FOREACH_SAFE(ptr, nptr, opm_list.head)
776 {
777 struct OPMScanner *scanner = ptr->data;
778
779 rb_dlinkDelete(ptr, &opm_list);
780 rb_free(scanner);
781 }
782
783 rb_helper_write(authd_helper, "O opm_scanner_del_all");
784 }