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