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