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