ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/parse.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/parse.c (file contents), Revision 896 by michael, Sat Nov 3 08:54:09 2007 UTC vs.
ircd-hybrid/trunk/src/parse.c (file contents), Revision 2786 by michael, Mon Jan 6 22:33:53 2014 UTC

# Line 23 | Line 23
23   */
24  
25   #include "stdinc.h"
26 – #include "parse.h"
26   #include "client.h"
27 + #include "parse.h"
28   #include "channel.h"
29 – #include "handlers.h"
30 – #include "common.h"
29   #include "hash.h"
30   #include "irc_string.h"
33 – #include "sprintf_irc.h"
31   #include "ircd.h"
32   #include "numeric.h"
33 < #include "s_log.h"
33 > #include "log.h"
34   #include "send.h"
35 < #include "ircd_handler.h"
39 < #include "msg.h"
40 < #include "s_conf.h"
35 > #include "conf.h"
36   #include "memory.h"
37   #include "s_user.h"
38   #include "s_serv.h"
# Line 59 | Line 54
54   *                               'i' -> [MessageTree *] -> 'e' and matches
55   *
56   * BUGS (Limitations!)
57 < *
57 > *
58   * I designed this trie to parse ircd commands. Hence it currently
59   * casefolds. This is trivial to fix by increasing MAXPTRLEN.
60   * This trie also "folds" '{' etc. down. This means, the input to this
# Line 69 | Line 64
64   * MAXPTRLEN 128.
65   *
66   * This is also not a patricia trie. On short ircd tokens, this is
67 < * not likely going to matter.
67 > * not likely going to matter.
68   *
69   * Diane Bruce (Dianora), June 6 2003
70   */
71  
72 < #define MAXPTRLEN       32
72 > #define MAXPTRLEN 32
73                                  /* Must be a power of 2, and
74                                   * larger than 26 [a-z]|[A-Z]
75                                   * its used to allocate the set
# Line 93 | Line 88
88  
89   struct MessageTree
90   {
91 <  int links; /* Count of all pointers (including msg) at this node
92 <              * used as reference count for deletion of _this_ node.
93 <              */
91 >  int links; /* Count of all pointers (including msg) at this node
92 >              * used as reference count for deletion of _this_ node.
93 >              */
94    struct Message *msg;
95    struct MessageTree *pointers[MAXPTRLEN];
96   };
# Line 106 | Line 101 | static struct MessageTree msg_tree;
101   * NOTE: parse() should not be called recursively by other functions!
102   */
103   static char *sender;
104 < static char *para[MAXPARA + 1];
110 < static char buffer[1024];
104 > static char *para[MAXPARA + 2]; /* <prefix> + <params> + NULL */
105  
106   static int cancel_clients(struct Client *, struct Client *, char *);
107   static void remove_unknown(struct Client *, char *, char *);
108 < static void do_numeric(char[], struct Client *, struct Client *, int, char **);
109 < static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
116 < static void recurse_report_messages(struct Client *source_p, struct MessageTree *mtree);
117 < static void add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, const char *cmd);
118 < static void del_msg_element(struct MessageTree *mtree_p, const char *cmd);
119 <
120 < /* turn a string into a parc/parv pair */
121 < static inline int
122 < string_to_array(char *string, char *parv[MAXPARA])
123 < {
124 <  char *p;
125 <  char *buf = string;
126 <  int x = 1;
108 > static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]);
109 > static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]);
110  
128 –  parv[x] = NULL;
129 –
130 –  while (*buf == ' ') /* skip leading spaces */
131 –    buf++;
132 –
133 –  if (*buf == '\0') /* ignore all-space args */
134 –    return(x);
135 –
136 –  do
137 –  {
138 –    if (*buf == ':') /* Last parameter */
139 –    {
140 –      buf++;
141 –      parv[x++] = buf;
142 –      parv[x]   = NULL;
143 –      return(x);
144 –    }
145 –    else
146 –    {
147 –      parv[x++] = buf;
148 –      parv[x]   = NULL;
149 –
150 –      if ((p = strchr(buf, ' ')) != NULL)
151 –      {
152 –        *p++ = '\0';
153 –        buf  = p;
154 –      }
155 –      else
156 –        return(x);
157 –    }      
158 –
159 –    while (*buf == ' ')
160 –      buf++;
161 –
162 –    if (*buf == '\0')
163 –      return(x);
164 –  } while (x < MAXPARA - 1);
165 –
166 –  if (*p == ':')
167 –    p++;
168 –
169 –  parv[x++] = p;
170 –  parv[x]   = NULL;
171 –  return(x);
172 – }
111  
112   /*
113   * parse a buffer.
# Line 180 | Line 118 | void
118   parse(struct Client *client_p, char *pbuffer, char *bufend)
119   {
120    struct Client *from = client_p;
121 <  char *ch;
122 <  char *s;
123 <  char *numeric = 0;
124 <  unsigned int i = 0;
125 <  int paramcount;
126 <  int mpara = 0;
189 <  struct Message *mptr = NULL;
121 >  struct Message *msg_ptr = NULL;
122 >  char *ch = NULL;
123 >  char *s = NULL;
124 >  char *numeric = NULL;
125 >  unsigned int parc = 0;
126 >  unsigned int paramcount;
127  
128    if (IsDefunct(client_p))
129      return;
130  
131    assert(client_p->localClient->fd.flags.open);
132 <  assert((bufend - pbuffer) < 512);
132 >  assert((bufend - pbuffer) < IRCD_BUFSIZE);
133  
134 <  for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
135 <    /* null statement */ ;
199 <
200 <  para[0] = from->name;
134 >  for (ch = pbuffer; *ch == ' '; ++ch)  /* skip spaces */
135 >    /* null statement */  ;
136  
137    if (*ch == ':')
138    {
139 <    ch++;
140 <
206 <    /* Copy the prefix to 'sender' assuming it terminates
139 >    /*
140 >     * Copy the prefix to 'sender' assuming it terminates
141       * with SPACE (or NULL, which is an error, though).
142       */
143 <    sender = ch;
143 >    sender = ++ch;
144  
145      if ((s = strchr(ch, ' ')) != NULL)
146      {
147        *s = '\0';
148 <      s++;
215 <      ch = s;
148 >      ch = ++s;
149      }
150  
151      if (*sender && IsServer(client_p))
152      {
220 –      /*
221 –       * XXX it could be useful to know which of these occurs most frequently.
222 –       * the ID check should always come first, though, since it is so easy.
223 –       */
153        if ((from = find_person(client_p, sender)) == NULL)
154 <      {
226 <        from = find_server(sender);
154 >        from = hash_find_server(sender);
155  
156 <        if (from == NULL && IsCapable(client_p, CAP_TS6) &&
157 <          client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
158 <        {
159 <          /* Dirty hack to allow messages from masked SIDs (i.e. the ones
232 <           * hidden by fakename="..."). It shouldn't break anything, since
233 <           * unknown SIDs don't happen during normal ircd work --adx
234 <           */
235 <          from = client_p;
236 <        }
237 <      }
238 <      
239 <      /* Hmm! If the client corresponding to the
240 <       * prefix is not found--what is the correct
241 <       * action??? Now, I will ignore the message
242 <       * (old IRC just let it through as if the
243 <       * prefix just wasn't there...) --msa
156 >      /*
157 >       * Hmm! If the client corresponding to the prefix is not found--what is
158 >       * the correct action??? Now, I will ignore the message (old IRC just
159 >       * let it through as if the prefix just wasn't there...) --msa
160         */
161        if (from == NULL)
162        {
# Line 249 | Line 165 | parse(struct Client *client_p, char *pbu
165          return;
166        }
167  
252 –      para[0] = from->name;
253 –
168        if (from->from != client_p)
169        {
170          ++ServerStats.is_wrdi;
# Line 260 | Line 174 | parse(struct Client *client_p, char *pbu
174      }
175  
176      while (*ch == ' ')
177 <      ch++;
177 >      ++ch;
178    }
179  
180    if (*ch == '\0')
# Line 269 | Line 183 | parse(struct Client *client_p, char *pbu
183      return;
184    }
185  
186 <  /* Extract the command code from the packet.  Point s to the end
186 >  /*
187 >   * Extract the command code from the packet. Point s to the end
188     * of the command code and calculate the length using pointer
189 <   * arithmetic.  Note: only need length for numerics and *all*
189 >   * arithmetic. Note: only need length for numerics and *all*
190     * numerics must have parameters and thus a space after the command
191     * code. -avalon
192     */
# Line 280 | Line 195 | parse(struct Client *client_p, char *pbu
195    if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
196        IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
197    {
283 –    mptr = NULL;
198      numeric = ch;
199 <    paramcount = MAXPARA;
199 >    paramcount = 2;  /* destination, and the rest of it */
200      ++ServerStats.is_num;
201      s = ch + 3;  /* I know this is ' ' from above if            */
202 <    *s++ = '\0'; /* blow away the ' ', and point s to next part */
202 >    *s++ = '\0';  /* blow away the ' ', and point s to next part */
203    }
204    else
205 <  {
206 <    int ii = 0;
205 >  {
206 >    unsigned int ii = 0;
207  
208      if ((s = strchr(ch, ' ')) != NULL)
209        *s++ = '\0';
210  
211 <    if ((mptr = find_command(ch)) == NULL)
211 >    if ((msg_ptr = find_command(ch)) == NULL)
212      {
213 <      /* Note: Give error message *only* to recognized
213 >      /*
214 >       * Note: Give error message *only* to recognized
215         * persons. It's a nightmare situation to have
216         * two programs sending "Unknown command"'s or
217         * equivalent to each other at full blast....
# Line 306 | Line 221 | parse(struct Client *client_p, char *pbu
221         * Hm, when is the buffer empty -- if a command
222         * code has been found ?? -Armin
223         */
224 <      if (pbuffer[0] != '\0')
224 >      if (*pbuffer != '\0')
225        {
226          if (IsClient(from))
227            sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
# Line 317 | Line 232 | parse(struct Client *client_p, char *pbu
232        return;
233      }
234  
235 <    assert(mptr->cmd != NULL);
321 <
322 <    paramcount = mptr->parameters;
323 <    mpara      = mptr->maxpara;
235 >    assert(msg_ptr->cmd != NULL);
236  
237 +    paramcount = msg_ptr->args_max;
238      ii = bufend - ((s) ? s : ch);
239 <    mptr->bytes += ii;
239 >    msg_ptr->bytes += ii;
240    }
241  
242 <  if (s != NULL)
243 <    i = string_to_array(s, para);
244 <  else
242 >  /*
243 >   * Must the following loop really be so devious? On surface it
244 >   * splits the message to parameters from blank spaces. But, if
245 >   * paramcount has been reached, the rest of the message goes into
246 >   * this last parameter (about same effect as ":" has...) --msa
247 >   */
248 >
249 >  /* Note initially true: s==NULL || *(s-1) == '\0' !! */
250 >
251 >  para[parc] = from->name;
252 >
253 >  if (s)
254    {
255 <    i = 0;
256 <    para[1] = NULL;
255 >    if (paramcount > MAXPARA)
256 >      paramcount = MAXPARA;
257 >
258 >    while (1)
259 >    {
260 >       while (*s == ' ')
261 >         *s++ = '\0';
262 >
263 >       if (*s == '\0')
264 >         break;
265 >
266 >       if (*s == ':')
267 >       {
268 >         /* The rest is a single parameter */
269 >         para[++parc] = s + (!numeric);  /* keep the colon if it's a numeric */
270 >         break;
271 >       }
272 >
273 >       para[++parc] = s;
274 >
275 >       if (parc >= paramcount)
276 >         break;
277 >
278 >       while (*s && *s != ' ')
279 >         ++s;
280 >    }
281    }
282  
283 <  if (mptr == NULL)
284 <    do_numeric(numeric, client_p, from, i, para);
283 >  para[++parc] = NULL;
284 >
285 >  if (msg_ptr != NULL)
286 >    handle_command(msg_ptr, client_p, from, parc, para);
287    else
288 <    handle_command(mptr, client_p, from, i, para);
288 >    handle_numeric(numeric, client_p, from, parc, para);
289   }
290  
291   /* handle_command()
# Line 352 | Line 300 | parse(struct Client *client_p, char *pbu
300   */
301   static void
302   handle_command(struct Message *mptr, struct Client *client_p,
303 <               struct Client *from, unsigned int i, char *hpara[MAXPARA])
303 >               struct Client *from, unsigned int i, char *hpara[])
304   {
305    MessageHandler handler = 0;
306  
# Line 361 | Line 309 | handle_command(struct Message *mptr, str
309  
310    mptr->count++;
311  
364 –  /* New patch to avoid server flooding from unregistered connects
365 –   * - Pie-Man 07/27/2000 */
366 –  if (!IsRegistered(client_p))
367 –  {
368 –    /* if its from a possible server connection
369 –     * ignore it.. more than likely its a header thats sneaked through
370 –     */
371 –    if ((IsHandshake(client_p) || IsConnecting(client_p) ||
372 –        IsServer(client_p)) && !(mptr->flags & MFLG_UNREG))
373 –      return;
374 –  }
375 –
312    handler = mptr->handlers[client_p->handler];
313  
314    /* check right amount of params is passed... --is */
315 <  if (i < mptr->parameters)
315 >  if (i < mptr->args_min)
316    {
317      if (!IsServer(client_p))
318      {
319 <      sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
320 <                   me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
319 >      sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS), me.name,
320 >                 EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
321      }
322      else
323      {
324 <      sendto_realops_flags(UMODE_ALL, L_ALL,
324 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
325                             "Dropping server %s due to (invalid) command '%s' "
326                             "with only %d arguments (expecting %d).",
327 <                           client_p->name, mptr->cmd, i, mptr->parameters);
328 <      ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
327 >                           client_p->name, mptr->cmd, i, mptr->args_min);
328 >      ilog(LOG_TYPE_IRCD, "Insufficient parameters (%d) for command '%s' from %s.",
329             i, mptr->cmd, client_p->name);
330        exit_client(client_p, client_p,
331                    "Not enough arguments to server command.");
# Line 399 | Line 335 | handle_command(struct Message *mptr, str
335      (*handler)(client_p, from, i, hpara);
336   }
337  
402 – /* clear_tree_parse()
403 – *
404 – * inputs       - NONE
405 – * output       - NONE
406 – * side effects - MUST MUST be called at startup ONCE before
407 – *                any other keyword routine is used.
408 – */
409 – void
410 – clear_tree_parse(void)
411 – {
412 –  memset(&msg_tree, 0, sizeof(msg_tree));
413 – }
414 –
338   /* add_msg_element()
339   *
340   * inputs       - pointer to MessageTree
# Line 433 | Line 356 | clear_tree_parse(void)
356   * in the parent.
357   */
358   static void
359 < add_msg_element(struct MessageTree *mtree_p,
360 <                struct Message *msg_p, const char *cmd)
359 > add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p,
360 >                const char *cmd)
361   {
362    struct MessageTree *ntree_p;
363  
364    if (*cmd == '\0')
365    {
366      mtree_p->msg = msg_p;
367 <    mtree_p->links++;           /* Have msg pointer, so up ref count */
367 >    mtree_p->links++;  /* Have msg pointer, so up ref count */
368    }
369    else
370    {
371 <    /* *cmd & (MAXPTRLEN-1)
371 >    /*
372 >     * *cmd & (MAXPTRLEN-1)
373       * convert the char pointed to at *cmd from ASCII to an integer
374       * between 0 and MAXPTRLEN.
375       * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
376       */
377 <
454 <    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
377 >    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL)
378      {
379 <      ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
380 <      mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;
379 >      ntree_p = MyMalloc(sizeof(struct MessageTree));
380 >      mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = ntree_p;
381  
382 <      mtree_p->links++;         /* Have new pointer, so up ref count */
382 >      mtree_p->links++;  /* Have new pointer, so up ref count */
383      }
384  
385 <    add_msg_element(ntree_p, msg_p, cmd+1);
385 >    add_msg_element(ntree_p, msg_p, cmd + 1);
386    }
387   }
388  
# Line 491 | Line 414 | del_msg_element(struct MessageTree *mtre
414   {
415    struct MessageTree *ntree_p;
416  
417 <  /* In case this is called for a nonexistent command
417 >  /*
418 >   * In case this is called for a nonexistent command
419     * check that there is a msg pointer here, else links-- goes -ve
420     * -db
421     */
498 –
422    if ((*cmd == '\0') && (mtree_p->msg != NULL))
423    {
424      mtree_p->msg = NULL;
# Line 503 | Line 426 | del_msg_element(struct MessageTree *mtre
426    }
427    else
428    {
429 <    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) != NULL)
429 >    if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) != NULL)
430      {
431 <      del_msg_element(ntree_p, cmd+1);
431 >      del_msg_element(ntree_p, cmd + 1);
432  
433        if (ntree_p->links == 0)
434        {
435 <        mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL;
436 <        mtree_p->links--;
437 <        MyFree(ntree_p);
435 >        mtree_p->pointers[*cmd & (MAXPTRLEN - 1)] = NULL;
436 >        mtree_p->links--;
437 >        MyFree(ntree_p);
438        }
439      }
440    }
# Line 525 | Line 448 | del_msg_element(struct MessageTree *mtre
448   * side effects - none
449   */
450   static struct Message *
451 < msg_tree_parse(const char *cmd, struct MessageTree *root)
451 > msg_tree_parse(const char *cmd)
452   {
453 <  struct MessageTree *mtree = root;
453 >  struct MessageTree *mtree = &msg_tree;
454    assert(cmd && *cmd);
455  
456    while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
# Line 548 | Line 471 | msg_tree_parse(const char *cmd, struct M
471   void
472   mod_add_cmd(struct Message *msg)
473   {
474 <  struct Message *found_msg;
552 <
553 <  if (msg == NULL)
554 <    return;
555 <
556 <  /* someone loaded a module with a bad messagetab */
557 <  assert(msg->cmd != NULL);
474 >  assert(msg && msg->cmd);
475  
476    /* command already added? */
477 <  if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
477 >  if (msg_tree_parse(msg->cmd))
478      return;
479  
480    add_msg_element(&msg_tree, msg, msg->cmd);
# Line 573 | Line 490 | mod_add_cmd(struct Message *msg)
490   void
491   mod_del_cmd(struct Message *msg)
492   {
493 <  assert(msg != NULL);
577 <
578 <  if (msg == NULL)
579 <    return;
493 >  assert(msg && msg->cmd);
494  
495    del_msg_element(&msg_tree, msg->cmd);
496   }
# Line 590 | Line 504 | mod_del_cmd(struct Message *msg)
504   struct Message *
505   find_command(const char *cmd)
506   {
507 <  return msg_tree_parse(cmd, &msg_tree);
507 >  return msg_tree_parse(cmd);
508 > }
509 >
510 > static void
511 > recurse_report_messages(struct Client *source_p, const struct MessageTree *mtree)
512 > {
513 >  unsigned int i;
514 >
515 >  if (mtree->msg != NULL)
516 >    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
517 >               me.name, source_p->name, mtree->msg->cmd,
518 >               mtree->msg->count, mtree->msg->bytes,
519 >               mtree->msg->rcount);
520 >
521 >  for (i = 0; i < MAXPTRLEN; ++i)
522 >    if (mtree->pointers[i] != NULL)
523 >      recurse_report_messages(source_p, mtree->pointers[i]);
524   }
525  
526   /* report_messages()
# Line 602 | Line 532 | find_command(const char *cmd)
532   void
533   report_messages(struct Client *source_p)
534   {
535 <  struct MessageTree *mtree = &msg_tree;
536 <  int i;
607 <
608 <  for (i = 0; i < MAXPTRLEN; i++)
609 <    if (mtree->pointers[i] != NULL)
610 <      recurse_report_messages(source_p, mtree->pointers[i]);
611 < }
612 <
613 < static void
614 < recurse_report_messages(struct Client *source_p, struct MessageTree *mtree)
615 < {
616 <  int i;
535 >  const struct MessageTree *mtree = &msg_tree;
536 >  unsigned int i;
537  
538 <  if (mtree->msg != NULL)
619 <    sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
620 <               me.name, source_p->name, mtree->msg->cmd,
621 <               mtree->msg->count, mtree->msg->bytes,
622 <               mtree->msg->rcount);
623 <
624 <  for (i = 0; i < MAXPTRLEN; i++)
538 >  for (i = 0; i < MAXPTRLEN; ++i)
539      if (mtree->pointers[i] != NULL)
540        recurse_report_messages(source_p, mtree->pointers[i]);
541   }
542  
543   /* cancel_clients()
544   *
545 < * inputs       -
546 < * output       -
547 < * side effects -
545 > * inputs       -
546 > * output       -
547 > * side effects -
548   */
549   static int
550   cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
551   {
552 <  /* kill all possible points that are causing confusion here,
552 >  /*
553 >   * Kill all possible points that are causing confusion here,
554     * I'm not sure I've got this all right...
555     * - avalon
556     *
557 <   * knowing avalon, probably not.
557 >   * Knowing avalon, probably not.
558     */
559  
560 <  /* with TS, fake prefixes are a common thing, during the
560 >  /*
561 >   * With TS, fake prefixes are a common thing, during the
562     * connect burst when there's a nick collision, and they
563     * must be ignored rather than killed because one of the
564     * two is surviving.. so we don't bother sending them to
# Line 651 | Line 567 | cancel_clients(struct Client *client_p,
567     * servers to be dropped though, as well as the ones from
568     * non-TS servers -orabidoo
569     */
570 <  /* Incorrect prefix for a server from some connection.  If it is a
570 >  /*
571 >   * Incorrect prefix for a server from some connection. If it is a
572     * client trying to be annoying, just QUIT them, if it is a server
573     * then the same deal.
574     */
575    if (IsServer(source_p) || IsMe(source_p))
576    {
577 <    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
577 >    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
578 >                         "Message for %s[%s] from %s",
579                           source_p->name, source_p->from->name,
580                           get_client_name(client_p, SHOW_IP));
581 <    sendto_realops_flags(UMODE_DEBUG, L_OPER,  "Message for %s[%s] from %s",
581 >    sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
582 >                         "Message for %s[%s] from %s",
583                           source_p->name, source_p->from->name,
584                           get_client_name(client_p, MASK_IP));
585 <    sendto_realops_flags(UMODE_DEBUG, L_ALL,
585 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
586                           "Not dropping server %s (%s) for Fake Direction",
587                           client_p->name, source_p->name);
588      return -1;
589      /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
590    }
591  
592 <  /* Ok, someone is trying to impose as a client and things are
593 <   * confused.  If we got the wrong prefix from a server, send out a
592 >  /*
593 >   * Ok, someone is trying to impose as a client and things are
594 >   * confused. If we got the wrong prefix from a server, send out a
595     * kill, else just exit the lame client.
596     */
597 <  /* If the fake prefix is coming from a TS server, discard it
597 >  /*
598 >   * If the fake prefix is coming from a TS server, discard it
599     * silently -orabidoo
600     *
601     * all servers must be TS these days --is
602     */
603 <  sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
603 >  sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
604                         "Message for %s[%s@%s!%s] from %s (TS, ignored)",
605                         source_p->name, source_p->username, source_p->host,
606                         source_p->from->name, get_client_name(client_p, SHOW_IP));
607 <  sendto_realops_flags(UMODE_DEBUG, L_OPER,
607 >  sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
608                         "Message for %s[%s@%s!%s] from %s (TS, ignored)",
609                         source_p->name, source_p->username, source_p->host,
610                         source_p->from->name, get_client_name(client_p, MASK_IP));
# Line 693 | Line 614 | cancel_clients(struct Client *client_p,
614  
615   /* remove_unknown()
616   *
617 < * inputs       -
618 < * output       -
619 < * side effects -
617 > * inputs       -
618 > * output       -
619 > * side effects -
620   */
621   static void
622   remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
623   {
624 <  /* Do kill if it came from a server because it means there is a ghost
624 >  /*
625 >   * Do kill if it came from a server because it means there is a ghost
626     * user on the other server which needs to be removed. -avalon
627     * Tell opers about this. -Taner
628     */
629 <  /* '[0-9]something'  is an ID      (KILL/SQUIT depending on its length)
629 >  /*
630 >   * '[0-9]something'  is an ID      (KILL/SQUIT depending on its length)
631     * 'nodots'          is a nickname (KILL)
632     * 'no.dot.at.start' is a server   (SQUIT)
633     */
634    if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
635        strchr(lsender, '.') != NULL)
636    {
637 <    sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
637 >    sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE,
638                           "Unknown prefix (%s) from %s, Squitting %s",
639                           lbuffer, get_client_name(client_p, SHOW_IP), lsender);
640 <    sendto_realops_flags(UMODE_DEBUG, L_OPER,
640 >    sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE,
641                           "Unknown prefix (%s) from %s, Squitting %s",
642                           lbuffer, client_p->name, lsender);
643      sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
# Line 738 | Line 661 | remove_unknown(struct Client *client_p,
661   *      wrong with the message, just *DROP* it! Don't even think of
662   *      sending back a neat error message -- big danger of creating
663   *      a ping pong error message...
664 + *
665 + * Rewritten by Nemesi, Jan 1999, to support numeric nicks in parv[1]
666 + *
667 + * Called when we get a numeric message from a remote _server_ and we are
668 + * supposed to forward it somewhere. Note that we always ignore numerics sent
669 + * to 'me' and simply drop the message if we can't handle with this properly:
670 + * the savvy approach is NEVER generate an error in response to an... error :)
671   */
672   static void
673 < do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
674 <           int parc, char *parv[])
673 > handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
674 >               int parc, char *parv[])
675   {
676 <  struct Client *target_p;
677 <  struct Channel *chptr;
748 <  char *t;    /* current position within the buffer */
749 <  int i, tl;  /* current length of presently being built string in t */
676 >  struct Client *target_p = NULL;
677 >  struct Channel *chptr = NULL;
678  
679 +  /*
680 +   * Avoid trash, we need it to come from a server and have a target
681 +   */
682    if (parc < 2 || !IsServer(source_p))
683      return;
684  
685 <  /* Remap low number numerics. */
686 <  if (numeric[0] == '0')
687 <    numeric[0] = '1';
688 <
689 <  /* Prepare the parameter portion of the message into 'buffer'.
690 <   * (Because the buffer is twice as large as the message buffer
760 <   * for the socket, no overflow can occur here... ...on current
761 <   * assumptions--bets are off, if these are changed --msa)
685 >  /*
686 >   * Who should receive this message ? Will we do something with it ?
687 >   * Note that we use findUser functions, so the target can't be neither
688 >   * a server, nor a channel (?) nor a list of targets (?) .. u2.10
689 >   * should never generate numeric replies to non-users anyway
690 >   * Ahem... it can be a channel actually, csc bots use it :\ --Nem
691     */
692 <  t = buffer;
693 <  for (i = 2; i < (parc - 1); i++)
694 <  {
695 <    tl = ircsprintf(t, " %s", parv[i]);
767 <    t += tl;
768 <  }
769 <
770 <  ircsprintf(t," :%s", parv[parc-1]);
771 <
772 <  if (((target_p = find_person(client_p, parv[1])) != NULL) ||
773 <      ((target_p = find_server(parv[1])) != NULL))
774 <  {
775 <    if (IsMe(target_p))
776 <    {
777 <      int num;
778 <
779 <      /*
780 <       * We shouldn't get numerics sent to us,
781 <       * any numerics we do get indicate a bug somewhere..
782 <       */
783 <      /* ugh.  this is here because of nick collisions.  when two servers
784 <       * relink, they burst each other their nicks, then perform collides.
785 <       * if there is a nick collision, BOTH servers will kill their own
786 <       * nicks, and BOTH will kill the other servers nick, which wont exist,
787 <       * because it will have been already killed by the local server.
788 <       *
789 <       * unfortunately, as we cant guarantee other servers will do the
790 <       * "right thing" on a nick collision, we have to keep both kills.  
791 <       * ergo we need to ignore ERR_NOSUCHNICK. --fl_
792 <       */
793 <      /* quick comment. This _was_ tried. i.e. assume the other servers
794 <       * will do the "right thing" and kill a nick that is colliding.
795 <       * unfortunately, it did not work. --Dianora
796 <       */
692 >  if (IsChanPrefix(*parv[1]))
693 >    chptr = hash_find_channel(parv[1]);
694 >  else
695 >    target_p = find_person(client_p, parv[1]);
696  
697 <      /* Yes, a good compiler would have optimised this, but
698 <       * this is probably easier to read. -db
800 <       */
801 <      num = atoi(numeric);
697 >  if (((!target_p) || (target_p->from == client_p)) && !chptr)
698 >    return;
699  
700 <      if ((num != ERR_NOSUCHNICK))
701 <        sendto_realops_flags(UMODE_ALL, L_ADMIN,
702 <                             "*** %s(via %s) sent a %s numeric to me: %s",
703 <                             source_p->name, client_p->name, numeric, buffer);
704 <      return;
705 <    }
706 <    else if (target_p->from == client_p)
707 <    {
708 <      /* This message changed direction (nick collision?)
709 <       * ignore it.
710 <       */
814 <      return;
815 <    }
700 >  /*
701 >   * Remap low number numerics, not that I understand WHY.. --Nemesi
702 >   */
703 >  /*
704 >   * Numerics below 100 talk about the current 'connection', you're not
705 >   * connected to a remote server so it doesn't make sense to send them
706 >   * remotely - but the information they contain may be useful, so we
707 >   * remap them up. Weird, but true.  -- Isomer
708 >   */
709 >  if (numeric[0] == '0')
710 >    numeric[0] = '1';
711  
712 <    /* csircd will send out unknown umode flag for +a (admin), drop it here. */
713 <    if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
819 <      return;
820 <    
712 >  if (target_p)
713 >  {
714      /* Fake it for server hiding, if its our client */
715 <    if (ConfigServerHide.hide_servers &&
716 <        MyClient(target_p) && !IsOper(target_p))
717 <      sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
715 >    if (ConfigServerHide.hide_servers && MyClient(target_p) &&
716 >        !HasUMode(target_p, UMODE_OPER))
717 >      sendto_one(target_p, ":%s %s %s %s", me.name, numeric, target_p->name, parv[2]);
718      else
719 <      sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from),
720 <                 numeric, ID_or_name(target_p, target_p->from), buffer);
828 <    return;
719 >      sendto_one(target_p, ":%s %s %s %s", ID_or_name(source_p, target_p->from),
720 >                 numeric, ID_or_name(target_p, target_p->from), parv[2]);
721    }
722 <  else if ((chptr = hash_find_channel(parv[1])) != NULL)
723 <    sendto_channel_local(ALL_MEMBERS, NO, chptr,
724 <                         ":%s %s %s %s",
833 <                         source_p->name,
834 <                         numeric, chptr->chname, buffer);
722 >  else
723 >    sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s %s %s %s",
724 >                         source_p->name, numeric, chptr->chname, parv[2]);
725   }
726  
727   /* m_not_oper()
728 < * inputs       -
728 > * inputs       -
729   * output       -
730   * side effects - just returns a nastyogram to given user
731   */
# Line 844 | Line 734 | m_not_oper(struct Client *client_p, stru
734             int parc, char *parv[])
735   {
736    sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
737 <             me.name, parv[0]);
737 >             me.name, source_p->name);
738   }
739  
740   void
741   m_unregistered(struct Client *client_p, struct Client *source_p,
742                 int parc, char *parv[])
743   {
744 <  /* bit of a hack.
745 <   * I don't =really= want to waste a bit in a flag
856 <   * number_of_nick_changes is only really valid after the client
857 <   * is fully registered..
858 <   */
859 <  if (client_p->localClient->number_of_nick_changes == 0)
860 <  {
861 <    sendto_one(client_p, ":%s %d * %s :Register first.",
862 <               me.name, ERR_NOTREGISTERED, parv[0]);
863 <    client_p->localClient->number_of_nick_changes++;
864 <  }
744 >  sendto_one(source_p, form_str(ERR_NOTREGISTERED), me.name,
745 >             source_p->name[0] ? source_p->name : "*");
746   }
747  
748   void
749   m_registered(struct Client *client_p, struct Client *source_p,
750               int parc, char *parv[])
751   {
752 <  sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),  
753 <             me.name, parv[0]);
752 >  sendto_one(source_p, form_str(ERR_ALREADYREGISTRED),
753 >             me.name, source_p->name);
754   }
755  
756   void
# Line 878 | Line 759 | m_ignore(struct Client *client_p, struct
759   {
760    return;
761   }
881 –

Diff Legend

– Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)