]> jfr.im git - solanum.git/blobdiff - modules/m_sasl.c
msg: remove last vestiges of the fakelag system. charybdis has never supported fakelag.
[solanum.git] / modules / m_sasl.c
index 211084d3f46e0f3a15515ba1d82056c1d88c87cd..84a9a850a07993d0b6da7e7f4f4d91e32b7515af 100644 (file)
 #include "s_newconf.h"
 #include "s_conf.h"
 
-static int m_authenticate(struct Client *, struct Client *, int, const char **);
-static int me_sasl(struct Client *, struct Client *, int, const char **);
+static int m_authenticate(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
+static int me_sasl(struct MsgBuf *, struct Client *, struct Client *, int, const char **);
 
 static void abort_sasl(struct Client *);
 static void abort_sasl_exit(hook_data_client_exit *);
 
+static void advertise_sasl(struct Client *);
+static void advertise_sasl_exit(hook_data_client_exit *);
+
 struct Message authenticate_msgtab = {
-       "AUTHENTICATE", 0, 0, 0, MFLG_SLOW,
+       "AUTHENTICATE", 0, 0, 0, 0,
        {{m_authenticate, 2}, {m_authenticate, 2}, mg_ignore, mg_ignore, mg_ignore, {m_authenticate, 2}}
 };
 struct Message sasl_msgtab = {
-       "SASL", 0, 0, 0, MFLG_SLOW,
+       "SASL", 0, 0, 0, 0,
        {mg_ignore, mg_ignore, mg_ignore, mg_ignore, {me_sasl, 5}, mg_ignore}
 };
 
@@ -64,13 +67,15 @@ mapi_clist_av1 sasl_clist[] = {
 mapi_hfn_list_av1 sasl_hfnlist[] = {
        { "new_local_user",     (hookfn) abort_sasl },
        { "client_exit",        (hookfn) abort_sasl_exit },
+       { "new_remote_user",    (hookfn) advertise_sasl },
+       { "client_exit",        (hookfn) advertise_sasl_exit },
        { NULL, NULL }
 };
 
 DECLARE_MODULE_AV1(sasl, NULL, NULL, sasl_clist, NULL, sasl_hfnlist, "$Revision: 1409 $");
 
 static int
-m_authenticate(struct Client *client_p, struct Client *source_p,
+m_authenticate(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *agent_p = NULL;
@@ -80,12 +85,6 @@ m_authenticate(struct Client *client_p, struct Client *source_p,
        if(!IsCapable(source_p, CLICAP_SASL))
                return 0;
 
-       if(IsRegisteredUser(source_p) && !IsCapable(source_p, CLICAP_SASL_REAUTH))
-       {
-               sendto_one(source_p, form_str(ERR_ALREADYREGISTRED), me.name, source_p->name);
-               return 0;
-       }
-
        if (strlen(client_p->id) == 3)
        {
                exit_client(client_p, client_p, client_p, "Mixing client and server protocol");
@@ -101,13 +100,7 @@ m_authenticate(struct Client *client_p, struct Client *source_p,
 
        if(source_p->localClient->sasl_complete)
        {
-               if (!IsCapable(source_p, CLICAP_SASL_REAUTH))
-               {
-                       sendto_one(source_p, form_str(ERR_SASLALREADY), me.name, EmptyString(source_p->name) ? "*" : source_p->name);
-                       return 0;
-               }
-
-               /* we're doing a reauth. */
+               *source_p->localClient->sasl_agent = '\0';
                source_p->localClient->sasl_complete = 0;
        }
 
@@ -129,20 +122,24 @@ m_authenticate(struct Client *client_p, struct Client *source_p,
 
        if(agent_p == NULL)
        {
+               sendto_one(saslserv_p, ":%s ENCAP %s SASL %s %s H %s %s",
+                                       me.id, saslserv_p->servptr->name, source_p->id, saslserv_p->id,
+                                       source_p->host, source_p->sockhost);
+
                if (!strcmp(parv[1], "EXTERNAL") && source_p->certfp != NULL)
-                       sendto_one(saslserv_p, ":%s ENCAP %s SASL %s %s S %s %s", me.id, saslserv_p->servptr->name,
-                                       source_p->id, saslserv_p->id,
-                                       parv[1], source_p->certfp);
+                       sendto_one(saslserv_p, ":%s ENCAP %s SASL %s %s S %s %s",
+                                               me.id, saslserv_p->servptr->name, source_p->id, saslserv_p->id,
+                                               parv[1], source_p->certfp);
                else
-                       sendto_one(saslserv_p, ":%s ENCAP %s SASL %s %s S %s", me.id, saslserv_p->servptr->name,
-                                       source_p->id, saslserv_p->id,
-                                       parv[1]);
+                       sendto_one(saslserv_p, ":%s ENCAP %s SASL %s %s S %s",
+                                               me.id, saslserv_p->servptr->name, source_p->id, saslserv_p->id,
+                                               parv[1]);
 
                rb_strlcpy(source_p->localClient->sasl_agent, saslserv_p->id, IDLEN);
        }
        else
-               sendto_one(agent_p, ":%s ENCAP %s SASL %s %s C %s", me.id, agent_p->servptr->name,
-                               source_p->id, agent_p->id,
+               sendto_one(agent_p, ":%s ENCAP %s SASL %s %s C %s",
+                               me.id, agent_p->servptr->name, source_p->id, agent_p->id,
                                parv[1]);
        source_p->localClient->sasl_out++;
 
@@ -150,7 +147,7 @@ m_authenticate(struct Client *client_p, struct Client *source_p,
 }
 
 static int
-me_sasl(struct Client *client_p, struct Client *source_p,
+me_sasl(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
        int parc, const char *parv[])
 {
        struct Client *target_p, *agent_p;
@@ -164,9 +161,6 @@ me_sasl(struct Client *client_p, struct Client *source_p,
        if((target_p = find_id(parv[2])) == NULL)
                return 0;
 
-       if(target_p->preClient == NULL)
-               return 0;
-
        if((agent_p = find_id(parv[1])) == NULL)
                return 0;
 
@@ -237,7 +231,30 @@ abort_sasl(struct Client *data)
 static void
 abort_sasl_exit(hook_data_client_exit *data)
 {
-       if (data->target->preClient)
+       if (data->target->localClient)
                abort_sasl(data->target);
 }
 
+static void
+advertise_sasl(struct Client *client_p)
+{
+       if (!ConfigFileEntry.sasl_service)
+               return;
+
+       if (irccmp(client_p->name, ConfigFileEntry.sasl_service))
+               return;
+
+       sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * NEW :sasl", me.name);
+}
+
+static void
+advertise_sasl_exit(hook_data_client_exit *data)
+{
+       if (!ConfigFileEntry.sasl_service)
+               return;
+
+       if (irccmp(data->target->name, ConfigFileEntry.sasl_service))
+               return;
+
+       sendto_local_clients_with_capability(CLICAP_CAP_NOTIFY, ":%s CAP * DEL :sasl", me.name);
+}