m_cap.c: Do not allow CAP ACK to set prohibited caps, or clear sticky ones.
[ircu2.10.12-pk.git] / ircd / m_cap.c
index a41593306cd0e7d66b760592955cedf4f5b56faa..a2cc79947d45ba41f0a1719a183685c6edc64002 100644 (file)
@@ -36,6 +36,7 @@
 #include "msg.h"
 #include "numeric.h"
 #include "send.h"
+#include "s_auth.h"
 #include "s_user.h"
 
 #include <stdlib.h>
@@ -193,8 +194,7 @@ static int
 cap_ls(struct Client *sptr, const char *caplist)
 {
   if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
-    cli_unreg(sptr) |= CLIREG_CAP;
-
+    auth_cap_start(cli_auth(sptr));
   return send_caplist(sptr, 0, 0, "LS"); /* send list of capabilities */
 }
 
@@ -209,7 +209,7 @@ cap_req(struct Client *sptr, const char *caplist)
   int neg;
 
   if (IsUnknown(sptr)) /* registration hasn't completed; suspend it... */
-    cli_unreg(sptr) |= CLIREG_CAP;
+    auth_cap_start(cli_auth(sptr));
 
   memset(&set, 0, sizeof(set));
   memset(&rem, 0, sizeof(rem));
@@ -260,10 +260,15 @@ cap_ack(struct Client *sptr, const char *caplist)
        (neg ? HasCap(sptr, cap->cap) : !HasCap(sptr, cap->cap))) /* uh... */
       continue;
 
-    if (neg) /* set or clear the active capability... */
+    if (neg) { /* set or clear the active capability... */
+      if (cap->flags & CAPFL_STICKY)
+        continue; /* but don't clear sticky capabilities */
       CapClr(cli_active(sptr), cap->cap);
-    else
+    } else {
+      if (cap->flags & CAPFL_PROHIBIT)
+        continue; /* and don't set prohibited ones */
       CapSet(cli_active(sptr), cap->cap);
+    }
   }
 
   return 0;
@@ -300,12 +305,7 @@ cap_end(struct Client *sptr, const char *caplist)
   if (!IsUnknown(sptr)) /* registration has completed... */
     return 0; /* so just ignore the message... */
 
-  cli_unreg(sptr) &= ~CLIREG_CAP; /* capability negotiation is now done... */
-
-  if (!cli_unreg(sptr)) /* if client is now done... */
-    return register_user(sptr, sptr, cli_name(sptr), cli_user(sptr)->username);
-
-  return 0; /* Can't do registration yet... */
+  return auth_cap_done(cli_auth(sptr));
 }
 
 static int