]> jfr.im git - solanum.git/blobdiff - ircd/authd.c
authd: add API for setting OPM listeners
[solanum.git] / ircd / authd.c
index 32e4f9c201609555e1d47877f64b664677bcc388..816b1a6d557b4c01dde6d81b2fbfcc2da7e07d71 100644 (file)
@@ -73,9 +73,8 @@ start_authd(void)
                                 ConfigFileEntry.dpath, RB_PATH_SEPARATOR, RB_PATH_SEPARATOR, suffix);
                        if(access(fullpath, X_OK) == -1)
                        {
-                               ilog(L_MAIN,
-                                    "Unable to execute authd in %s or %s/bin",
-                                    ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
+                               ierror("Unable to execute authd in %s or %s/bin",
+                                       ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
                                sendto_realops_snomask(SNO_GENERAL, L_ALL,
                                                       "Unable to execute authd in %s or %s/bin",
                                                       ircd_paths[IRCD_PATH_LIBEXEC], ConfigFileEntry.dpath);
@@ -100,7 +99,7 @@ start_authd(void)
 
        if(authd_helper == NULL)
        {
-               ilog(L_MAIN, "Unable to start authd helper: %s", strerror(errno));
+               ierror("Unable to start authd helper: %s", strerror(errno));
                sendto_realops_snomask(SNO_GENERAL, L_ALL, "Unable to start authd helper: %s", strerror(errno));
                return 1;
        }
@@ -211,7 +210,7 @@ parse_authd_reply(rb_helper * helper)
                case 'E':       /* DNS Result */
                        if(parc != 5)
                        {
-                               ilog(L_MAIN, "authd sent a result with wrong number of arguments: got %d", parc);
+                               iwarn("authd sent a result with wrong number of arguments: got %d", parc);
                                restart_authd();
                                return;
                        }
@@ -220,7 +219,7 @@ parse_authd_reply(rb_helper * helper)
                case 'W':       /* Oper warning */
                        if(parc != 3)
                        {
-                               ilog(L_MAIN, "authd sent a result with wrong number of arguments: got %d", parc);
+                               iwarn("authd sent a result with wrong number of arguments: got %d", parc);
                                restart_authd();
                                return;
                        }
@@ -229,18 +228,19 @@ parse_authd_reply(rb_helper * helper)
                        {
                        case 'D':       /* Debug */
                                sendto_realops_snomask(SNO_DEBUG, L_ALL, "authd debug: %s", parv[3]);
+                               idebug("authd: %s", parv[3]);
                                break;
                        case 'I':       /* Info */
                                sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd info: %s", parv[3]);
-                               inotice("authd info: %s", parv[3]);
+                               inotice("authd: %s", parv[3]);
                                break;
                        case 'W':       /* Warning */
                                sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd WARNING: %s", parv[3]);
-                               iwarn("authd warning: %s", parv[3]);
+                               iwarn("authd: %s", parv[3]);
                                break;
                        case 'C':       /* Critical (error) */
                                sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd CRITICAL: %s", parv[3]);
-                               ierror("authd critical: %s", parv[3]);
+                               ierror("authd: %s", parv[3]);
                                break;
                        default:        /* idk */
                                sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd sent us an unknown oper notice type (%s): %s", parv[2], parv[3]);
@@ -255,7 +255,7 @@ parse_authd_reply(rb_helper * helper)
                case 'Z':       /* End of stats reply */
                        if(parc < 3)
                        {
-                               ilog(L_MAIN, "authd sent a result with wrong number of arguments: got %d", parc);
+                               iwarn("authd sent a result with wrong number of arguments: got %d", parc);
                                restart_authd();
                                return;
                        }
@@ -267,7 +267,7 @@ parse_authd_reply(rb_helper * helper)
                                /* parv[0] conveys status */
                                if(parc < 4)
                                {
-                                       ilog(L_MAIN, "authd sent a result with wrong number of arguments: got %d", parc);
+                                       iwarn("authd sent a result with wrong number of arguments: got %d", parc);
                                        restart_authd();
                                        return;
                                }
@@ -288,7 +288,7 @@ init_authd(void)
 {
        if(start_authd())
        {
-               ilog(L_MAIN, "Unable to start authd helper: %s", strerror(errno));
+               ierror("Unable to start authd helper: %s", strerror(errno));
                exit(0);
        }
 }
@@ -306,13 +306,24 @@ configure_authd(void)
 static void
 restart_authd_cb(rb_helper * helper)
 {
-       ilog(L_MAIN, "authd: restart_authd_cb called, authd died?");
+       rb_dictionary_iter iter;
+       struct Client *client_p;
+
+       iwarn("authd: restart_authd_cb called, authd died?");
        sendto_realops_snomask(SNO_GENERAL, L_ALL, "authd: restart_authd_cb called, authd died?");
+
        if(helper != NULL)
        {
                rb_helper_close(helper);
                authd_helper = NULL;
        }
+
+       RB_DICTIONARY_FOREACH(client_p, &iter, cid_clients)
+       {
+               /* Abort any existing clients */
+               authd_abort_client(client_p);
+       }
+
        start_authd();
 }
 
@@ -374,22 +385,11 @@ authd_initiate_client(struct Client *client_p)
        rb_inet_ntop_sock((struct sockaddr *)&client_p->localClient->ip, client_ipaddr, sizeof(client_ipaddr));
 
        /* Retrieve listener and client ports */
-#ifdef RB_IPV6
-       if(GET_SS_FAMILY(&client_p->preClient->lip) == AF_INET6)
-               listen_port = ntohs(((struct sockaddr_in6 *)&client_p->preClient->lip)->sin6_port);
-       else
-#endif
-               listen_port = ntohs(((struct sockaddr_in *)&client_p->preClient->lip)->sin_port);
-
-#ifdef RB_IPV6
-       if(GET_SS_FAMILY(&client_p->localClient->ip) == AF_INET6)
-               client_port = ntohs(((struct sockaddr_in6 *)&client_p->localClient->ip)->sin6_port);
-       else
-#endif
-               client_port = ntohs(((struct sockaddr_in *)&client_p->localClient->ip)->sin_port);
+       listen_port = ntohs(GET_SS_PORT(&client_p->preClient->lip));
+       client_port = ntohs(GET_SS_PORT(&client_p->localClient->ip));
 
        /* Add a bit of a fudge factor... */
-       client_p->preClient->authd_timeout = rb_current_time() + ConfigFileEntry.connect_timeout + 5;
+       client_p->preClient->authd_timeout = rb_current_time() + ConfigFileEntry.connect_timeout + 10;
 
        rb_helper_write(authd_helper, "C %x %s %hu %s %hu", authd_cid, listen_ipaddr, listen_port, client_ipaddr, client_port);
 }
@@ -407,10 +407,10 @@ authd_decide_client(struct Client *client_p, const char *ident, const char *host
        if(*ident != '*')
        {
                rb_strlcpy(client_p->username, ident, sizeof(client_p->username));
-               ServerStats.is_abad++; /* s_auth used to do this, stay compatible */
+               ServerStats.is_asuc++;
        }
        else
-               ServerStats.is_asuc++;
+               ServerStats.is_abad++; /* s_auth used to do this, stay compatible */
 
        if(*host != '*')
                rb_strlcpy(client_p->host, host, sizeof(client_p->host));
@@ -421,7 +421,6 @@ authd_decide_client(struct Client *client_p, const char *ident, const char *host
        client_p->preClient->authd_reason = (reason == NULL ? NULL : rb_strdup(reason));
 
        rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->authd_cid));
-
        client_p->preClient->authd_cid = 0;
 
        /*
@@ -439,7 +438,7 @@ authd_decide_client(struct Client *client_p, const char *ident, const char *host
 void
 authd_abort_client(struct Client *client_p)
 {
-       if(client_p->preClient == NULL)
+       if(client_p == NULL || client_p->preClient == NULL)
                return;
 
        if(client_p->preClient->authd_cid == 0)
@@ -447,7 +446,12 @@ authd_abort_client(struct Client *client_p)
 
        rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->authd_cid));
 
-       rb_helper_write(authd_helper, "E %x", client_p->preClient->authd_cid);
+       if(authd_helper != NULL)
+               rb_helper_write(authd_helper, "E %x", client_p->preClient->authd_cid);
+
+       /* XXX should we blindly allow like this? */
+       authd_decide_client(client_p, "*", "*", true, '\0', NULL, NULL);
+
        client_p->preClient->authd_cid = 0;
 }
 
@@ -460,11 +464,7 @@ timeout_dead_authd_clients(void *notused __unused)
        RB_DICTIONARY_FOREACH(client_p, &iter, cid_clients)
        {
                if(client_p->preClient->authd_timeout < rb_current_time())
-               {
-                       rb_helper_write(authd_helper, "E %x", client_p->preClient->authd_cid);
-                       rb_free(id);
-                       rb_dictionary_delete(cid_clients, RB_UINT_TO_POINTER(client_p->preClient->authd_cid));
-               }
+                       authd_abort_client(client_p);
        }
 }
 
@@ -546,14 +546,39 @@ del_blacklist_all(void)
 }
 
 /* Adjust an authd timeout value */
-void
+bool
 set_authd_timeout(const char *key, int timeout)
 {
+       if(timeout <= 0)
+               return false;
+
        rb_helper_write(authd_helper, "O %s %d", key, timeout);
+       return true;
 }
 
+/* Enable identd checks */
 void
 ident_check_enable(bool enabled)
 {
        rb_helper_write(authd_helper, "O ident_enabled %d", enabled ? 1 : 0);
 }
+
+/* Create an OPM listener */
+bool
+create_opm_listener(struct rb_sockaddr_storage *addr)
+{
+       char addrbuf[HOSTIPLEN];
+
+       if(!rb_inet_ntop_sock((struct sockaddr *)addr, addrbuf, sizeof(addrbuf)))
+               return false;
+
+       if(addrbuf[0] == ':')
+       {
+               /* Reformat for authd sending */
+               memmove(addrbuf + 1, addrbuf, sizeof(addrbuf) - 1);
+               addrbuf[0] = '0';
+       }
+
+       rb_helper_write(authd_helper, "O opm_listener %s %hu", addrbuf, ntohs(GET_SS_PORT(addr)));
+       return true;
+}