]> jfr.im git - solanum.git/blobdiff - ircd/authproc.c
support RSFNC indicating type of FNC (e.g. FORCE vs REGAIN) (#406)
[solanum.git] / ircd / authproc.c
index 68078c0e5d93fabe8427f7f1093b17b8bac77808..a8a5d0db81a4b2974450749a804944fbd69de8ee 100644 (file)
@@ -4,7 +4,7 @@
  *
  *  Copyright (C) 2005 Aaron Sethman <androsyn@ratbox.org>
  *  Copyright (C) 2005-2012 ircd-ratbox development team
- *  Copyright (C) 2016 William Pitcock <nenolod@dereferenced.org>
+ *  Copyright (C) 2016 Ariadne Conill <ariadne@dereferenced.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -67,7 +67,7 @@ uint32_t cid;
 static rb_dictionary *cid_clients;
 static struct ev_entry *timeout_ev;
 
-rb_dictionary *dnsbl_stats;
+rb_dictionary *dnsbl_stats = NULL;
 
 rb_dlink_list opm_list;
 struct OPMListener opm_listeners[LISTEN_LAST];
@@ -88,24 +88,19 @@ static int
 start_authd(void)
 {
        char fullpath[PATH_MAX + 1];
-#ifdef _WIN32
-       const char *suffix = ".exe";
-#else
-       const char *suffix = "";
-#endif
+
        if(authd_path == NULL)
        {
-               snprintf(fullpath, sizeof(fullpath), "%s%cauthd%s", ircd_paths[IRCD_PATH_LIBEXEC], RB_PATH_SEPARATOR, suffix);
+               snprintf(fullpath, sizeof(fullpath), "%s/authd", ircd_paths[IRCD_PATH_LIBEXEC]);
 
                if(access(fullpath, X_OK) == -1)
                {
-                       snprintf(fullpath, sizeof(fullpath), "%s%cbin%cauthd%s",
-                                ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
+                       snprintf(fullpath, sizeof(fullpath), "%s/bin/authd", ConfigFileEntry.dpath);
                        if(access(fullpath, X_OK) == -1)
                        {
                                ierror("Unable to execute authd in %s or %s/bin",
                                        ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
-                               sendto_realops_snomask(SNO_GENERAL, L_ALL,
+                               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE,
                                                       "Unable to execute authd in %s or %s/bin",
                                                       ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                return 1;
@@ -127,12 +122,12 @@ start_authd(void)
        if(authd_helper == NULL)
        {
                ierror("Unable to start authd helper: %s", strerror(errno));
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "Unable to start authd helper: %s", strerror(errno));
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "Unable to start authd helper: %s", strerror(errno));
                return 1;
        }
 
        ilog(L_MAIN, "authd helper started");
-       sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd helper started");
+       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authd helper started");
        rb_helper_run(authd_helper);
        return 0;
 }
@@ -202,7 +197,10 @@ cmd_notice_client(int parc, char **parv)
 {
        struct Client *client_p;
 
-       if((client_p = str_cid_to_client(parv[1], false)) == NULL)
+       if ((client_p = str_cid_to_client(parv[1], false)) == NULL)
+               return;
+
+       if (IsAnyDead(client_p))
                return;
 
        sendto_one_notice(client_p, ":%s", parv[2]);
@@ -226,23 +224,23 @@ cmd_oper_warn(int parc, char **parv)
        switch(*parv[1])
        {
        case 'D':       /* Debug */
-               sendto_realops_snomask(SNO_DEBUG, L_ALL, "authd debug: %s", parv[2]);
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, "authd debug: %s", parv[2]);
                idebug("authd: %s", parv[2]);
                break;
        case 'I':       /* Info */
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd info: %s", parv[2]);
+               sendto_realops_snomask(SNO_DEBUG, L_NETWIDE, "authd info: %s", parv[2]);
                inotice("authd: %s", parv[2]);
                break;
        case 'W':       /* Warning */
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd WARNING: %s", parv[2]);
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authd WARNING: %s", parv[2]);
                iwarn("authd: %s", parv[2]);
                break;
        case 'C':       /* Critical (error) */
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd CRITICAL: %s", parv[2]);
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authd CRITICAL: %s", parv[2]);
                ierror("authd: %s", parv[2]);
                break;
        default:        /* idk */
-               sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd sent us an unknown oper notice type (%s): %s", parv[1], parv[2]);
+               sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authd sent us an unknown oper notice type (%s): %s", parv[1], parv[2]);
                ilog(L_MAIN, "authd unknown oper notice type (%s): %s", parv[1], parv[2]);
                break;
        }
@@ -350,6 +348,18 @@ configure_authd(void)
        }
        else
                opm_check_enable(false);
+
+       /* Configure DNSBLs */
+       if (dnsbl_stats != NULL)
+       {
+               rb_dictionary_iter iter;
+               struct DNSBLEntry *entry;
+               RB_DICTIONARY_FOREACH(entry, &iter, dnsbl_stats)
+               {
+                       rb_helper_write(authd_helper, "O rbl %s %hhu %s :%s", entry->host,
+                                       entry->iptype, entry->filters, entry->reason);
+               }
+       }
 }
 
 static void
@@ -385,8 +395,8 @@ authd_abort_client(struct Client *client_p)
 static void
 restart_authd_cb(rb_helper * helper)
 {
-       iwarn("authd: restart_authd_cb called, authd died?");
-       sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd: restart_authd_cb called, authd died?");
+       iwarn("authd helper died - attempting to restart");
+       sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, "authdd helper died - attempting to restart");
 
        if(helper != NULL)
        {
@@ -568,7 +578,6 @@ timeout_dead_authd_clients(void *notused __unused)
        {
                if(client_p->preClient->auth.timeout < rb_current_time())
                {
-                       authd_free_client(client_p);
                        rb_dlinkAddAlloc(client_p, &freelist);
                }
        }
@@ -577,7 +586,8 @@ timeout_dead_authd_clients(void *notused __unused)
        RB_DLINK_FOREACH_SAFE(ptr, nptr, freelist.head)
        {
                client_p = ptr->data;
-               rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->auth.cid));
+               authd_abort_client(client_p);
+               rb_dlinkDestroy(ptr, &freelist);
        }
 }
 
@@ -586,7 +596,7 @@ void
 add_dnsbl_entry(const char *host, const char *reason, uint8_t iptype, rb_dlink_list *filters)
 {
        rb_dlink_node *ptr;
-       struct DNSBLEntryStats *stats = rb_malloc(sizeof(*stats));
+       struct DNSBLEntry *entry = rb_malloc(sizeof(*entry));
        char filterbuf[BUFSIZE] = "*";
        size_t s = 0;
 
@@ -612,11 +622,13 @@ add_dnsbl_entry(const char *host, const char *reason, uint8_t iptype, rb_dlink_l
        if(s)
                filterbuf[s - 1] = '\0';
 
-       stats->host = rb_strdup(host);
-       stats->iptype = iptype;
-       stats->hits = 0;
-       rb_dictionary_add(dnsbl_stats, stats->host, stats);
+       entry->host = rb_strdup(host);
+       entry->reason = rb_strdup(reason);
+       entry->filters = rb_strdup(filterbuf);
+       entry->iptype = iptype;
+       entry->hits = 0;
 
+       rb_dictionary_add(dnsbl_stats, entry->host, entry);
        rb_helper_write(authd_helper, "O rbl %s %hhu %s :%s", host, iptype, filterbuf, reason);
 }
 
@@ -624,12 +636,15 @@ add_dnsbl_entry(const char *host, const char *reason, uint8_t iptype, rb_dlink_l
 void
 del_dnsbl_entry(const char *host)
 {
-       struct DNSBLEntryStats *stats = rb_dictionary_retrieve(dnsbl_stats, host);
-       if(stats != NULL)
+       struct DNSBLEntry *entry = rb_dictionary_retrieve(dnsbl_stats, host);
+
+       if(entry != NULL)
        {
-               rb_dictionary_delete(dnsbl_stats, host);
-               rb_free(stats->host);
-               rb_free(stats);
+               rb_dictionary_delete(dnsbl_stats, entry->host);
+               rb_free(entry->host);
+               rb_free(entry->reason);
+               rb_free(entry->filters);
+               rb_free(entry);
        }
 
        rb_helper_write(authd_helper, "O rbl_del %s", host);
@@ -638,10 +653,12 @@ del_dnsbl_entry(const char *host)
 static void
 dnsbl_delete_elem(rb_dictionary_element *delem, void *unused)
 {
-       struct DNSBLEntryStats *stats = delem->data;
+       struct DNSBLEntry *entry = delem->data;
 
-       rb_free(stats->host);
-       rb_free(stats);
+       rb_free(entry->host);
+       rb_free(entry->reason);
+       rb_free(entry->filters);
+       rb_free(entry);
 }
 
 /* Delete all the DNSBL entries. */