]> jfr.im git - irc/rqf/shadowircd.git/blobdiff - src/parse.c
parse(): make reentrant
[irc/rqf/shadowircd.git] / src / parse.c
index 40dbc5499b118330d289c7943800e16398cdd805..a8ce091c77e76a4c83b446c3f0e3a9bb600a40ef 100644 (file)
@@ -22,7 +22,6 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  *  USA
  *
- *  $Id: parse.c 3177 2007-02-01 00:19:14Z jilles $
  */
 
 #include "stdinc.h"
 static struct Dictionary *cmd_dict = NULL;
 struct Dictionary *alias_dict = NULL;
 
-/*
- * NOTE: parse() should not be called recursively by other functions!
- */
-static char *sender;
-
-/* parv[0] == source, and parv[LAST] == NULL */
+/* parv[0] is not used, and parv[LAST] == NULL */
 static char *para[MAXPARA + 2];
 
 static void cancel_clients(struct Client *, struct Client *, char *);
@@ -104,7 +98,7 @@ string_to_array(char *string, char **parv)
                if(*buf == '\0')
                        return x;
        }
-       /* we can go upto parv[MAXPARA], as parv[0] is taken by source */
+       /* we can go upto parv[MAXPARA], as parv[0] is skipped */
        while (x < MAXPARA);
 
        if(*p == ':')
@@ -117,12 +111,13 @@ string_to_array(char *string, char **parv)
 
 /* parse()
  *
- * given a raw buffer, parses it and generates parv, parc and sender
+ * given a raw buffer, parses it and generates parv and parc
  */
 void
 parse(struct Client *client_p, char *pbuffer, char *bufend)
 {
        struct Client *from = client_p;
+       char *sender;
        char *ch;
        char *s;
        char *end;
@@ -131,7 +126,7 @@ parse(struct Client *client_p, char *pbuffer, char *bufend)
        struct Message *mptr;
 
        s_assert(MyConnect(client_p));
-       s_assert(client_p->localClient->F->fd >= 0);
+       s_assert(client_p->localClient->F != NULL);
        if(IsAnyDead(client_p))
                return;
 
@@ -364,7 +359,7 @@ handle_command(struct Message *mptr, struct Client *client_p,
                ilog(L_SERVER,
                     "Insufficient parameters (%d < %d) for command '%s' from %s.",
                     i, ehandler.min_para, mptr->cmd, client_p->name);
-               snprintf(squitreason, sizeof squitreason,
+               rb_snprintf(squitreason, sizeof squitreason,
                                "Insufficient parameters (%d < %d) for command '%s'",
                                i, ehandler.min_para, mptr->cmd);
                exit_client(client_p, client_p, client_p, squitreason);
@@ -532,8 +527,10 @@ static void
 remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
 {
        int slen = strlen(lsender);
+       char sid[4];
+       struct Client *server;
 
-       /* meepfoo      is a nickname (KILL)
+       /* meepfoo      is a nickname (ignore)
         * #XXXXXXXX    is a UID (KILL)
         * #XX          is a SID (SQUIT)
         * meep.foo     is a server (SQUIT)
@@ -550,9 +547,21 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
                           get_id(&me, client_p), lsender, 
                           lbuffer, client_p->name);
        }
+       else if(!IsDigit(lsender[0]))
+               ;
+       else if(slen != 9)
+               sendto_realops_snomask(SNO_DEBUG, L_ALL,
+                                    "Invalid prefix (%s) from %s",
+                                    lbuffer, client_p->name);
        else
-               sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", 
-                          get_id(&me, client_p), lsender, me.name);
+       {
+               memcpy(sid, lsender, 3);
+               sid[3] = '\0';
+               server = find_server(NULL, sid);
+               if (server != NULL && server->from == client_p)
+                       sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", 
+                                       get_id(&me, client_p), lsender, me.name);
+       }
 }
 
 
@@ -560,7 +569,6 @@ remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
 /*
  *
  *      parc    number of arguments ('sender' counted as one!)
- *      parv[0] pointer to 'sender' (may point to empty string) (not used)
  *      parv[1]..parv[parc-1]
  *              pointers to additional parameters, this is a NULL
  *              terminated list (parv[parc] == NULL).