Author: Isomer <isomer@coders.net>
[ircu2.10.12-pk.git] / ircd / parse.c
index 7d78eca91443e4633eed714ad58b560100a4fdd2..59951d154beb0a4539b8c0184679c85f5febc8b2 100644 (file)
@@ -19,6 +19,8 @@
  *
  * $Id$
  */
+#include "config.h"
+
 #include "parse.h"
 #include "client.h"
 #include "channel.h"
 #include "ircd.h"
 #include "ircd_alloc.h"
 #include "ircd_chattr.h"
+#include "ircd_features.h"
+#include "ircd_policy.h"
 #include "ircd_reply.h"
 #include "ircd_string.h"
-#include "map.h"
 #include "msg.h"
 #include "numeric.h"
 #include "numnicks.h"
@@ -181,6 +184,13 @@ struct Message msgtab[] = {
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
     { m_unregistered, m_not_oper, ms_wallops, mo_wallops, m_ignore }
   },
+  {
+    MSG_WALLUSERS,
+    TOK_WALLUSERS,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, ms_wallusers, mo_wallusers, m_ignore }
+  },
   {
     MSG_DESYNCH,
     TOK_DESYNCH,
@@ -193,7 +203,7 @@ struct Message msgtab[] = {
     TOK_PING,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-    { m_unregistered, m_ping, ms_ping, m_ping, m_ignore }
+    { m_unregistered, m_ping, ms_ping, mo_ping, m_ignore }
   },
   {
     MSG_PONG,
@@ -305,14 +315,18 @@ struct Message msgtab[] = {
     TOK_TRACE,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+#ifdef HEAD_IN_SAND_TRACE
+    { m_unregistered, m_not_oper, ms_trace, mo_trace, m_ignore }
+#else
     { m_unregistered, m_trace, ms_trace, mo_trace, m_ignore }
+#endif
   },
   {
     MSG_PASS,
     TOK_PASS,
     0, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-    { m_pass, m_registered, m_ignore, m_registered, m_ignore }
+    { mr_pass, m_registered, m_ignore, m_registered, m_ignore }
   },
   {
     MSG_LUSERS,
@@ -354,11 +368,7 @@ struct Message msgtab[] = {
     TOK_OPER,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-#ifndef NOOPER    
     { m_unregistered, m_oper, ms_oper, mo_oper, m_ignore }
-#else
-    { m_unregistered, m_oper, m_ignore, m_ignore, m_ignore }
-#endif
   },
   {
     MSG_CONNECT,
@@ -372,7 +382,11 @@ struct Message msgtab[] = {
     TOK_MAP,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+#ifdef HEAD_IN_SAND_MAP
+    { m_unregistered, m_map_redirect, m_ignore, m_map, m_ignore }
+#else
     { m_unregistered, m_map, m_ignore, m_map, m_ignore }
+#endif
   },
   {
     MSG_VERSION,
@@ -393,7 +407,11 @@ struct Message msgtab[] = {
     TOK_LINKS,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+#ifdef HEAD_IN_SAND_LINKS
+    { m_unregistered, m_links_redirect, ms_links, m_links, m_ignore }
+#else
     { m_unregistered, m_links, ms_links, m_links, m_ignore }
+#endif
   },
   {
     MSG_ADMIN,
@@ -449,11 +467,7 @@ struct Message msgtab[] = {
     TOK_JUPE,
     0, MAXPARA, MFLG_SLOW, 0,
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
-#ifdef CONFIG_OPERCMDS
     { m_unregistered, m_jupe, ms_jupe, mo_jupe, m_ignore }
-#else
-    { m_unregistered, m_jupe, ms_jupe, m_jupe, m_ignore }
-#endif /* CONFIG_OPERCMDS */
   },
   {
     MSG_OPMODE,
@@ -532,14 +546,51 @@ struct Message msgtab[] = {
     /* UNREG, CLIENT, SERVER, OPER, SERVICE */
     { m_proto, m_proto, m_proto, m_proto, m_ignore }
   },
+  {
+    MSG_SET,
+    TOK_SET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_set, m_ignore }
+  },
+  {
+    MSG_RESET,
+    TOK_RESET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_reset, m_ignore }
+  },
+  {
+    MSG_GET,
+    TOK_GET,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_get, m_ignore }
+  },
+  {
+    MSG_PRIVS,
+    TOK_PRIVS,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_unregistered, m_not_oper, m_ignore, mo_privs, m_ignore }
+  },
+  /* This command is an alias for QUIT during the unregistered part of
+   * of the server.  This is because someone jumping via a broken web
+   * proxy will send a 'POST' as their first command - which we will
+   * obviously disconnect them immediately for, stopping people abusing
+   * open gateways
+   */
+  {
+    MSG_POST,
+    TOK_POST,
+    0, MAXPARA, MFLG_SLOW, 0,
+    /* UNREG, CLIENT, SERVER, OPER, SERVICE */
+    { m_quit, m_ignore, m_ignore, m_ignore, m_ignore }
+  },  
   { 0 }
 }; 
 
 
-#ifdef GODMODE
-extern int sdbflag;
-#endif /* GODMODE */
-
 static char *para[MAXPARA + 2]; /* leave room for prefix and null */
 
 /*
@@ -694,7 +745,7 @@ void initmsgtree(void)
   int ii;
   struct Message **msgtab_tok;
   struct Message **msgtok;
-
+  
   for (i = 0; msg->cmd; ++i, ++msg)
     continue;
   qsort(msgtab, i, sizeof(struct Message),
@@ -769,12 +820,12 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   struct Message* mptr;
   MessageHandler  handler = 0;
 
-  Debug((DEBUG_DEBUG, "Parsing: %s", buffer));
+  Debug((DEBUG_DEBUG, "Client Parsing: %s", buffer));
 
   if (IsDead(cptr))
     return 0;
 
-  para[0] = from->name;
+  para[0] = cli_name(from);
   for (ch = buffer; *ch == ' '; ch++);  /* Eat leading spaces */
   if (*ch == ':')               /* Is any client doing this ? */
   {
@@ -789,7 +840,7 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   {
     ServerStats->is_empt++;
     Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
-        cptr->name, from->name));
+        cli_name(cptr), cli_name(from)));
     return (-1);
   }
 
@@ -828,7 +879,7 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   i = bufend - ((s) ? s : ch);
   mptr->bytes += i;
   if ((mptr->flags & MFLG_SLOW))
-    cptr->since += (2 + i / 120);
+    cli_since(cptr) += (2 + i / 120);
   /*
    * Allow only 1 msg per 2 seconds
    * (on average) to prevent dumping.
@@ -880,25 +931,13 @@ int parse_client(struct Client *cptr, char *buffer, char *bufend)
   }
   para[++i] = NULL;
   ++mptr->count;
-#if 0
-  /*
-   * The "unregistered command check" was ugly and mildly inefficient.
-   * I fixed it. :)  --Shadow
-   */
-  if (!IsUser(cptr) && 0 == (mptr->flags & MFLG_UNREG)) {
-    if (0 == (mptr->flags & MFLG_IGNORE))
-      sendto_one(from, ":%s %d * %s :Register first.", /* XXX DEAD */
-                 me.name, ERR_NOTREGISTERED, ch);
-    return -1;
-  }
-#endif
-  handler = mptr->handlers[cptr->handler];
+
+  handler = mptr->handlers[cli_handler(cptr)];
   assert(0 != handler);
 
-#ifndef IDLE_FROM_MSG
-  if (IsUser(cptr) && handler != m_ping && handler != m_ignore)
-    from->user->last = CurrentTime;
-#endif
+  if (!feature_bool(FEAT_IDLE_FROM_MSG) && IsUser(cptr) &&
+      handler != m_ping && handler != m_ignore)
+    cli_user(from)->last = CurrentTime;
 
   return (*handler) (cptr, from, i, para);
 }
@@ -914,28 +953,12 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
   int             paramcount;
   struct Message* mptr;
 
-  Debug((DEBUG_DEBUG, "Parsing: %s", buffer));
-
-#ifdef GODMODE
-  len = strlen(buffer);
-  sdbflag = 1;
-  if (len > 402)
-  {
-    char c = buffer[200];
-    buffer[200] = 0;
-    sendto_ops("RCV:%-8.8s(%.4d): \"%s...%s\"",
-        cptr->name, len, buffer, &buffer[len - 200]);
-    buffer[200] = c;
-  }
-  else
-    sendto_ops("RCV:%-8.8s(%.4d): \"%s\"", cptr->name, len, buffer);
-  sdbflag = 0;
-#endif /* GODMODE */
+  Debug((DEBUG_DEBUG, "Server Parsing: %s", buffer));
 
   if (IsDead(cptr))
     return 0;
 
-  para[0] = from->name;
+  para[0] = cli_name(from);
 
   /*
    * A server ALWAYS sends a prefix. When it starts with a ':' it's the
@@ -964,7 +987,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     if (!from)
     {
       Debug((DEBUG_NOTICE, "Unknown prefix (%s)(%s) from (%s)",
-          para[0], buffer, cptr->name));
+          para[0], buffer, cli_name(cptr)));
       ++ServerStats->is_unpf;
       while (*ch == ' ')
         ch++;
@@ -976,22 +999,21 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
        */
       if (ch[1] == 'Q')
       {
-        para[0] = cptr->name;
+        para[0] = cli_name(cptr);
         from = cptr;
       }
       else
         return 0;
     }
-    else if (from->from != cptr)
+    else if (cli_from(from) != cptr)
     {
       ++ServerStats->is_wrdi;
       Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
-          buffer, cptr->name));
+          buffer, cli_name(cptr)));
       return 0;
     }
   }
-  else if (Protocol(cptr) > 9)  /* Well, not ALWAYS, 2.9 can send no prefix */
-  {
+  else {
     char numeric_prefix[6];
     int  i;
     for (i = 0; i < 5; ++i) {
@@ -1000,12 +1022,17 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
       }
     }
     numeric_prefix[i] = '\0';
+
     /*
      * We got a numeric nick as prefix
      * 1 or 2 character prefixes are from servers
      * 3 or 5 chars are from clients
      */
-    if (' ' == ch[1] || ' ' == ch[2])
+    if (0 == i) {
+      protocol_violation(cptr,"Missing Prefix");
+      from = cptr;
+    }
+    else if (' ' == ch[1] || ' ' == ch[2])
       from = FindNServer(numeric_prefix);
     else 
       from = findNUser(numeric_prefix);
@@ -1039,9 +1066,9 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
         struct Client *server;
         /* Kill the unknown numeric prefix upstream if
          * it's server still exists: */
-        if ((server = FindNServer(numeric_prefix)) && server->from == cptr)
+        if ((server = FindNServer(numeric_prefix)) && cli_from(server) == cptr)
          sendcmdto_one(&me, CMD_KILL, cptr, "%s :%s (Unknown numeric nick)",
-                       numeric_prefix, me.name);
+                       numeric_prefix, cli_name(&me));
       }
       /*
        * Things that must be allowed to travel
@@ -1055,13 +1082,13 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     }
 
     /* Let para[0] point to the name of the sender */
-    para[0] = from->name;
+    para[0] = cli_name(from);
 
-    if (from->from != cptr)
+    if (cli_from(from) != cptr)
     {
       ServerStats->is_wrdi++;
       Debug((DEBUG_NOTICE, "Fake direction: Message (%s) coming from (%s)",
-          buffer, cptr->name));
+          buffer, cli_name(cptr)));
       return 0;
     }
   }
@@ -1072,7 +1099,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
   {
     ServerStats->is_empt++;
     Debug((DEBUG_NOTICE, "Empty message from host %s:%s",
-        cptr->name, from->name));
+        cli_name(cptr), cli_name(from)));
     return (-1);
   }
 
@@ -1088,7 +1115,7 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
   if (len == 3 && IsDigit(*ch))
   {
     numeric = (*ch - '0') * 100 + (*(ch + 1) - '0') * 10 + (*(ch + 2) - '0');
-    paramcount = MAXPARA;
+    paramcount = 2; /* destination, and the rest of it */
     ServerStats->is_num++;
     mptr = NULL;                /* Init. to avoid stupid compiler warning :/ */
   }
@@ -1183,7 +1210,10 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
          * The rest is single parameter--can
          * include blanks also.
          */
-        para[++i] = s + 1;
+       if (numeric)
+         para[++i] = s; /* preserve the colon to make do_numeric happy */
+       else
+         para[++i] = s + 1;
         break;
       }
       para[++i] = s;
@@ -1197,5 +1227,5 @@ int parse_server(struct Client *cptr, char *buffer, char *bufend)
     return (do_numeric(numeric, (*buffer != ':'), cptr, from, i, para));
   mptr->count++;
 
-  return (*mptr->handlers[cptr->handler]) (cptr, from, i, para);
+  return (*mptr->handlers[cli_handler(cptr)]) (cptr, from, i, para);
 }