ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/parse.c
Revision: 753
Committed: Wed Jul 26 15:58:16 2006 UTC (17 years, 8 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/parse.c
File size: 25282 byte(s)
Log Message:
+ fixed an old bug that affected our numeric delivery:

Spotted by: stu

Imagine we have a scenario like this:
[origin A on server 0] --> [OUR IRCD] --> [TS6 server] --> [TS5 server and target Z]

We'd try to address Z by its null ID only because the next server on the way
is TS6.  That led to delivery failure in cases like
ts6(origin)->ts6->ts6->ts5(target).

File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * parse.c: The message parser.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "parse.h"
27     #include "client.h"
28     #include "channel.h"
29     #include "handlers.h"
30     #include "common.h"
31     #include "hash.h"
32     #include "irc_string.h"
33     #include "sprintf_irc.h"
34     #include "ircd.h"
35     #include "numeric.h"
36     #include "s_log.h"
37     #include "s_stats.h"
38     #include "send.h"
39     #include "ircd_handler.h"
40     #include "msg.h"
41     #include "s_conf.h"
42     #include "memory.h"
43     #include "s_user.h"
44     #include "s_serv.h"
45    
46     /*
47     * (based on orabidoo's parser code)
48     *
49     * This has always just been a trie. Look at volume III of Knuth ACP
50     *
51     *
52     * ok, you start out with an array of pointers, each one corresponds
53     * to a letter at the current position in the command being examined.
54     *
55     * so roughly you have this for matching 'trie' or 'tie'
56     *
57     * 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i'
58     * -> [MessageTree *] -> [MessageTree *] -> 'e' and matches
59     *
60     * 'i' -> [MessageTree *] -> 'e' and matches
61     *
62     * BUGS (Limitations!)
63     *
64     * I designed this trie to parse ircd commands. Hence it currently
65     * casefolds. This is trivial to fix by increasing MAXPTRLEN.
66     * This trie also "folds" '{' etc. down. This means, the input to this
67     * trie must be alpha tokens only. This again, is a limitation that
68     * can be overcome by increasing MAXPTRLEN to include upper/lower case
69     * at the expense of more memory. At the extreme end, you could make
70     * MAXPTRLEN 128.
71     *
72     * This is also not a patricia trie. On short ircd tokens, this is
73     * not likely going to matter.
74     *
75     * Diane Bruce (Dianora), June 6 2003
76     */
77    
78     #define MAXPTRLEN 32
79     /* Must be a power of 2, and
80     * larger than 26 [a-z]|[A-Z]
81     * its used to allocate the set
82     * of pointers at each node of the tree
83     * There are MAXPTRLEN pointers at each node.
84     * Obviously, there have to be more pointers
85     * Than ASCII letters. 32 is a nice number
86     * since there is then no need to shift
87     * 'A'/'a' to base 0 index, at the expense
88     * of a few never used pointers. For a small
89     * parser like this, this is a good compromise
90     * and does make it somewhat faster.
91     *
92     * - Dianora
93     */
94    
95     struct MessageTree
96     {
97     int links; /* Count of all pointers (including msg) at this node
98     * used as reference count for deletion of _this_ node.
99     */
100     struct Message *msg;
101     struct MessageTree *pointers[MAXPTRLEN];
102     };
103    
104     static struct MessageTree msg_tree;
105    
106     /*
107     * NOTE: parse() should not be called recursively by other functions!
108     */
109     static char *sender;
110     static char *para[MAXPARA + 1];
111     static char buffer[1024];
112    
113     static int cancel_clients(struct Client *, struct Client *, char *);
114     static void remove_unknown(struct Client *, char *, char *);
115     static void do_numeric(char[], struct Client *, struct Client *, int, char **);
116     static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char **);
117     static void recurse_report_messages(struct Client *source_p, struct MessageTree *mtree);
118     static void add_msg_element(struct MessageTree *mtree_p, struct Message *msg_p, const char *cmd);
119     static void del_msg_element(struct MessageTree *mtree_p, const char *cmd);
120    
121     /* turn a string into a parc/parv pair */
122     static inline int
123     string_to_array(char *string, char *parv[MAXPARA])
124     {
125     char *p;
126     char *buf = string;
127     int x = 1;
128    
129     parv[x] = NULL;
130    
131     while (*buf == ' ') /* skip leading spaces */
132     buf++;
133    
134     if (*buf == '\0') /* ignore all-space args */
135     return(x);
136    
137     do
138     {
139     if (*buf == ':') /* Last parameter */
140     {
141     buf++;
142     parv[x++] = buf;
143     parv[x] = NULL;
144     return(x);
145     }
146     else
147     {
148     parv[x++] = buf;
149     parv[x] = NULL;
150    
151     if ((p = strchr(buf, ' ')) != NULL)
152     {
153     *p++ = '\0';
154     buf = p;
155     }
156     else
157     return(x);
158     }
159    
160     while (*buf == ' ')
161     buf++;
162    
163     if (*buf == '\0')
164     return(x);
165     } while (x < MAXPARA - 1);
166    
167     if (*p == ':')
168     p++;
169    
170     parv[x++] = p;
171     parv[x] = NULL;
172     return(x);
173     }
174    
175     /*
176     * parse a buffer.
177     *
178     * NOTE: parse() should not be called recusively by any other functions!
179     */
180     void
181     parse(struct Client *client_p, char *pbuffer, char *bufend)
182     {
183     struct Client *from = client_p;
184     char *ch;
185     char *s;
186     char *numeric = 0;
187     unsigned int i = 0;
188     int paramcount;
189     int mpara = 0;
190     struct Message *mptr = NULL;
191    
192     if (IsDefunct(client_p))
193     return;
194    
195     assert(client_p->localClient->fd.flags.open);
196     assert((bufend - pbuffer) < 512);
197    
198     for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
199     /* null statement */ ;
200    
201     para[0] = from->name;
202    
203     if (*ch == ':')
204     {
205     ch++;
206    
207     /* Copy the prefix to 'sender' assuming it terminates
208     * with SPACE (or NULL, which is an error, though).
209     */
210     sender = ch;
211    
212     if ((s = strchr(ch, ' ')) != NULL)
213     {
214     *s = '\0';
215     s++;
216     ch = s;
217     }
218    
219     if (*sender && IsServer(client_p))
220     {
221     /*
222     * XXX it could be useful to know which of these occurs most frequently.
223     * the ID check should always come first, though, since it is so easy.
224     */
225     if ((from = find_person(client_p, sender)) == NULL)
226     {
227     from = find_server(sender);
228    
229     if (from == NULL && IsCapable(client_p, CAP_TS6) &&
230     client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
231     {
232     /* Dirty hack to allow messages from masked SIDs (i.e. the ones
233     * hidden by fakename="..."). It shouldn't break anything, since
234     * unknown SIDs don't happen during normal ircd work --adx
235     */
236     from = client_p;
237     }
238     }
239    
240     /* Hmm! If the client corresponding to the
241     * prefix is not found--what is the correct
242     * action??? Now, I will ignore the message
243     * (old IRC just let it through as if the
244     * prefix just wasn't there...) --msa
245     */
246     if (from == NULL)
247     {
248     ServerStats->is_unpf++;
249     remove_unknown(client_p, sender, pbuffer);
250     return;
251     }
252    
253     para[0] = from->name;
254    
255     if (from->from != client_p)
256     {
257     ServerStats->is_wrdi++;
258     cancel_clients(client_p, from, pbuffer);
259     return;
260     }
261     }
262    
263     while (*ch == ' ')
264     ch++;
265     }
266    
267     if (*ch == '\0')
268     {
269     ServerStats->is_empt++;
270     return;
271     }
272    
273     /* Extract the command code from the packet. Point s to the end
274     * of the command code and calculate the length using pointer
275     * arithmetic. Note: only need length for numerics and *all*
276     * numerics must have parameters and thus a space after the command
277     * code. -avalon
278     */
279    
280     /* EOB is 3 chars long but is not a numeric */
281     if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
282     IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
283     {
284     mptr = NULL;
285     numeric = ch;
286     paramcount = MAXPARA;
287     ServerStats->is_num++;
288     s = ch + 3; /* I know this is ' ' from above if */
289     *s++ = '\0'; /* blow away the ' ', and point s to next part */
290     }
291     else
292     {
293     int ii = 0;
294    
295     if ((s = strchr(ch, ' ')) != NULL)
296     *s++ = '\0';
297    
298     if ((mptr = find_command(ch)) == NULL)
299     {
300     /* Note: Give error message *only* to recognized
301     * persons. It's a nightmare situation to have
302     * two programs sending "Unknown command"'s or
303     * equivalent to each other at full blast....
304     * If it has got to person state, it at least
305     * seems to be well behaving. Perhaps this message
306     * should never be generated, though... --msa
307     * Hm, when is the buffer empty -- if a command
308     * code has been found ?? -Armin
309     */
310     if (pbuffer[0] != '\0')
311     {
312     if (IsClient(from))
313     sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
314     me.name, from->name, ch);
315     }
316    
317     ServerStats->is_unco++;
318     return;
319     }
320    
321     assert(mptr->cmd != NULL);
322    
323     paramcount = mptr->parameters;
324     mpara = mptr->maxpara;
325    
326     ii = bufend - ((s) ? s : ch);
327     mptr->bytes += ii;
328     }
329    
330     if (s != NULL)
331     i = string_to_array(s, para);
332     else
333     {
334     i = 0;
335     para[1] = NULL;
336     }
337    
338     if (mptr == NULL)
339     do_numeric(numeric, client_p, from, i, para);
340     else
341     handle_command(mptr, client_p, from, i, para);
342     }
343    
344     /* handle_command()
345     *
346     * inputs - pointer to message block
347     * - pointer to client
348     * - pointer to client message is from
349     * - count of number of args
350     * - pointer to argv[] array
351     * output - -1 if error from server
352     * side effects -
353     */
354     static void
355     handle_command(struct Message *mptr, struct Client *client_p,
356     struct Client *from, unsigned int i, char *hpara[MAXPARA])
357     {
358     MessageHandler handler = 0;
359    
360     if (IsServer(client_p))
361     mptr->rcount++;
362    
363     mptr->count++;
364    
365     /* New patch to avoid server flooding from unregistered connects
366     * - Pie-Man 07/27/2000 */
367     if (!IsRegistered(client_p))
368     {
369     /* if its from a possible server connection
370     * ignore it.. more than likely its a header thats sneaked through
371     */
372     if ((IsHandshake(client_p) || IsConnecting(client_p) ||
373     IsServer(client_p)) && !(mptr->flags & MFLG_UNREG))
374     return;
375     }
376    
377     handler = mptr->handlers[client_p->handler];
378    
379     /* check right amount of params is passed... --is */
380     if (i < mptr->parameters)
381     {
382     if (!IsServer(client_p))
383     {
384     sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
385     me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
386     }
387     else
388     {
389     sendto_realops_flags(UMODE_ALL, L_ALL,
390     "Dropping server %s due to (invalid) command '%s' "
391     "with only %d arguments (expecting %d).",
392     client_p->name, mptr->cmd, i, mptr->parameters);
393     ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
394     i, mptr->cmd, client_p->name);
395     exit_client(client_p, client_p,
396     "Not enough arguments to server command.");
397     }
398     }
399     else
400     (*handler)(client_p, from, i, hpara);
401     }
402    
403     /* clear_tree_parse()
404     *
405     * inputs - NONE
406     * output - NONE
407     * side effects - MUST MUST be called at startup ONCE before
408     * any other keyword routine is used.
409     */
410     void
411     clear_tree_parse(void)
412     {
413     memset(&msg_tree, 0, sizeof(msg_tree));
414     }
415    
416     /* add_msg_element()
417     *
418     * inputs - pointer to MessageTree
419     * - pointer to Message to add for given command
420     * - pointer to current portion of command being added
421     * output - NONE
422     * side effects - recursively build the Message Tree ;-)
423     */
424     /*
425     * How this works.
426     *
427     * The code first checks to see if its reached the end of the command
428     * If so, that struct MessageTree has a msg pointer updated and the links
429     * count incremented, since a msg pointer is a reference.
430     * Then the code descends recursively, building the trie.
431     * If a pointer index inside the struct MessageTree is NULL a new
432     * child struct MessageTree has to be allocated.
433     * The links (reference count) is incremented as they are created
434     * in the parent.
435     */
436     static void
437     add_msg_element(struct MessageTree *mtree_p,
438     struct Message *msg_p, const char *cmd)
439     {
440     struct MessageTree *ntree_p;
441    
442     if (*cmd == '\0')
443     {
444     mtree_p->msg = msg_p;
445     mtree_p->links++; /* Have msg pointer, so up ref count */
446     }
447     else
448     {
449     /* *cmd & (MAXPTRLEN-1)
450     * convert the char pointed to at *cmd from ASCII to an integer
451     * between 0 and MAXPTRLEN.
452     * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
453     */
454    
455     if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
456     {
457     ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
458     mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;
459    
460     mtree_p->links++; /* Have new pointer, so up ref count */
461     }
462     add_msg_element(ntree_p, msg_p, cmd+1);
463     }
464     }
465    
466     /* del_msg_element()
467     *
468     * inputs - Pointer to MessageTree to delete from
469     * - pointer to command name to delete
470     * output - NONE
471     * side effects - recursively deletes a token from the Message Tree ;-)
472     */
473     /*
474     * How this works.
475     *
476     * Well, first off, the code recursively descends into the trie
477     * until it finds the terminating letter of the command being removed.
478     * Once it has done that, it marks the msg pointer as NULL then
479     * reduces the reference count on that allocated struct MessageTree
480     * since a command counts as a reference.
481     *
482     * Then it pops up the recurse stack. As it comes back up the recurse
483     * The code checks to see if the child now has no pointers or msg
484     * i.e. the links count has gone to zero. If its no longer used, the
485     * child struct MessageTree can be deleted. The parent reference
486     * to this child is then removed and the parents link count goes down.
487     * Thus, we continue to go back up removing all unused MessageTree(s)
488     */
489     static void
490     del_msg_element(struct MessageTree *mtree_p, const char *cmd)
491     {
492     struct MessageTree *ntree_p;
493    
494     /* In case this is called for a nonexistent command
495     * check that there is a msg pointer here, else links-- goes -ve
496     * -db
497     */
498    
499     if ((*cmd == '\0') && (mtree_p->msg != NULL))
500     {
501     mtree_p->msg = NULL;
502     mtree_p->links--;
503     }
504     else
505     {
506     if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) != NULL)
507     {
508     del_msg_element(ntree_p, cmd+1);
509     if (ntree_p->links == 0)
510     {
511     mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL;
512     mtree_p->links--;
513     MyFree(ntree_p);
514     }
515     }
516     }
517     }
518    
519     /* msg_tree_parse()
520     *
521     * inputs - Pointer to command to find
522     * - Pointer to MessageTree root
523     * output - Find given command returning Message * if found NULL if not
524     * side effects - none
525     */
526     static struct Message *
527     msg_tree_parse(const char *cmd, struct MessageTree *root)
528     {
529 michael 522 struct MessageTree *mtree = root;
530 adx 30 assert(cmd && *cmd);
531    
532 michael 522 while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
533     if (*++cmd == '\0')
534     return mtree->msg;
535 adx 30
536 michael 522 return NULL;
537 adx 30 }
538    
539     /* mod_add_cmd()
540     *
541     * inputs - pointer to struct Message
542     * output - none
543     * side effects - load this one command name
544     * msg->count msg->bytes is modified in place, in
545     * modules address space. Might not want to do that...
546     */
547     void
548     mod_add_cmd(struct Message *msg)
549     {
550     struct Message *found_msg;
551    
552     if (msg == NULL)
553     return;
554    
555     /* someone loaded a module with a bad messagetab */
556     assert(msg->cmd != NULL);
557    
558     /* command already added? */
559     if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
560     return;
561    
562     add_msg_element(&msg_tree, msg, msg->cmd);
563     msg->count = msg->rcount = msg->bytes = 0;
564     }
565    
566     /* mod_del_cmd()
567     *
568     * inputs - pointer to struct Message
569     * output - none
570     * side effects - unload this one command name
571     */
572     void
573     mod_del_cmd(struct Message *msg)
574     {
575     assert(msg != NULL);
576    
577     if (msg == NULL)
578     return;
579    
580     del_msg_element(&msg_tree, msg->cmd);
581     }
582    
583     /* find_command()
584     *
585     * inputs - command name
586     * output - pointer to struct Message
587     * side effects - none
588     */
589     struct Message *
590     find_command(const char *cmd)
591     {
592     return(msg_tree_parse(cmd, &msg_tree));
593     }
594    
595     /* report_messages()
596     *
597     * inputs - pointer to client to report to
598     * output - NONE
599     * side effects - client is shown list of commands
600     */
601     void
602     report_messages(struct Client *source_p)
603     {
604     struct MessageTree *mtree = &msg_tree;
605     int i;
606    
607     for (i = 0; i < MAXPTRLEN; i++)
608     {
609     if (mtree->pointers[i] != NULL)
610     recurse_report_messages(source_p, mtree->pointers[i]);
611     }
612     }
613    
614     static void
615     recurse_report_messages(struct Client *source_p, struct MessageTree *mtree)
616     {
617     int i;
618    
619     if (mtree->msg != NULL)
620     {
621     sendto_one(source_p, form_str(RPL_STATSCOMMANDS),
622     me.name, source_p->name, mtree->msg->cmd,
623     mtree->msg->count, mtree->msg->bytes,
624     mtree->msg->rcount);
625     }
626    
627     for (i = 0; i < MAXPTRLEN; i++)
628     {
629     if (mtree->pointers[i] != NULL)
630     recurse_report_messages(source_p, mtree->pointers[i]);
631     }
632     }
633    
634     /* cancel_clients()
635     *
636     * inputs -
637     * output -
638     * side effects -
639     */
640     static int
641     cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
642     {
643     /* kill all possible points that are causing confusion here,
644     * I'm not sure I've got this all right...
645     * - avalon
646     *
647     * knowing avalon, probably not.
648     */
649    
650     /* with TS, fake prefixes are a common thing, during the
651     * connect burst when there's a nick collision, and they
652     * must be ignored rather than killed because one of the
653     * two is surviving.. so we don't bother sending them to
654     * all ops everytime, as this could send 'private' stuff
655     * from lagged clients. we do send the ones that cause
656     * servers to be dropped though, as well as the ones from
657     * non-TS servers -orabidoo
658     */
659     /* Incorrect prefix for a server from some connection. If it is a
660     * client trying to be annoying, just QUIT them, if it is a server
661     * then the same deal.
662     */
663     if (IsServer(source_p) || IsMe(source_p))
664     {
665     sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
666     source_p->name, source_p->from->name,
667     get_client_name(client_p, SHOW_IP));
668     sendto_realops_flags(UMODE_DEBUG, L_OPER, "Message for %s[%s] from %s",
669     source_p->name, source_p->from->name,
670     get_client_name(client_p, MASK_IP));
671     sendto_realops_flags(UMODE_DEBUG, L_ALL,
672     "Not dropping server %s (%s) for Fake Direction",
673     client_p->name, source_p->name);
674     return(-1);
675     /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
676     }
677    
678     /* Ok, someone is trying to impose as a client and things are
679     * confused. If we got the wrong prefix from a server, send out a
680     * kill, else just exit the lame client.
681     */
682     /* If the fake prefix is coming from a TS server, discard it
683     * silently -orabidoo
684     *
685     * all servers must be TS these days --is
686     */
687     sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
688     "Message for %s[%s@%s!%s] from %s (TS, ignored)",
689     source_p->name, source_p->username, source_p->host,
690     source_p->from->name, get_client_name(client_p, SHOW_IP));
691     sendto_realops_flags(UMODE_DEBUG, L_OPER,
692     "Message for %s[%s@%s!%s] from %s (TS, ignored)",
693     source_p->name, source_p->username, source_p->host,
694     source_p->from->name, get_client_name(client_p, MASK_IP));
695    
696     return(0);
697     }
698    
699     /* remove_unknown()
700     *
701     * inputs -
702     * output -
703     * side effects -
704     */
705     static void
706     remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
707     {
708     /* Do kill if it came from a server because it means there is a ghost
709     * user on the other server which needs to be removed. -avalon
710     * Tell opers about this. -Taner
711     */
712     /* '[0-9]something' is an ID (KILL/SQUIT depending on its length)
713     * 'nodots' is a nickname (KILL)
714     * 'no.dot.at.start' is a server (SQUIT)
715     */
716     if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
717     strchr(lsender, '.') != NULL)
718     {
719     sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
720     "Unknown prefix (%s) from %s, Squitting %s",
721     lbuffer, get_client_name(client_p, SHOW_IP), lsender);
722     sendto_realops_flags(UMODE_DEBUG, L_OPER,
723     "Unknown prefix (%s) from %s, Squitting %s",
724     lbuffer, client_p->name, lsender);
725     sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
726     me.name, lsender, lbuffer, client_p->name);
727     }
728     else
729     sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
730     me.name, lsender, me.name);
731     }
732    
733     /*
734     *
735     * parc number of arguments ('sender' counted as one!)
736     * parv[0] pointer to 'sender' (may point to empty string) (not used)
737     * parv[1]..parv[parc-1]
738     * pointers to additional parameters, this is a NULL
739     * terminated list (parv[parc] == NULL).
740     *
741     * *WARNING*
742     * Numerics are mostly error reports. If there is something
743     * wrong with the message, just *DROP* it! Don't even think of
744     * sending back a neat error message -- big danger of creating
745     * a ping pong error message...
746     */
747     static void
748     do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
749     int parc, char *parv[])
750     {
751     struct Client *target_p;
752     struct Channel *chptr;
753     char *t; /* current position within the buffer */
754     int i, tl; /* current length of presently being built string in t */
755    
756     if (parc < 2 || !IsServer(source_p))
757     return;
758    
759     /* Remap low number numerics. */
760     if (numeric[0] == '0')
761     numeric[0] = '1';
762    
763     /* Prepare the parameter portion of the message into 'buffer'.
764     * (Because the buffer is twice as large as the message buffer
765     * for the socket, no overflow can occur here... ...on current
766     * assumptions--bets are off, if these are changed --msa)
767     */
768     t = buffer;
769     for (i = 2; i < (parc - 1); i++)
770     {
771     tl = ircsprintf(t, " %s", parv[i]);
772     t += tl;
773     }
774    
775     ircsprintf(t," :%s", parv[parc-1]);
776    
777     if (((target_p = find_person(client_p, parv[1])) != NULL) ||
778     ((target_p = find_server(parv[1])) != NULL))
779     {
780     if (IsMe(target_p))
781     {
782     int num;
783    
784     /*
785     * We shouldn't get numerics sent to us,
786     * any numerics we do get indicate a bug somewhere..
787     */
788     /* ugh. this is here because of nick collisions. when two servers
789     * relink, they burst each other their nicks, then perform collides.
790     * if there is a nick collision, BOTH servers will kill their own
791     * nicks, and BOTH will kill the other servers nick, which wont exist,
792     * because it will have been already killed by the local server.
793     *
794     * unfortunately, as we cant guarantee other servers will do the
795     * "right thing" on a nick collision, we have to keep both kills.
796     * ergo we need to ignore ERR_NOSUCHNICK. --fl_
797     */
798     /* quick comment. This _was_ tried. i.e. assume the other servers
799     * will do the "right thing" and kill a nick that is colliding.
800     * unfortunately, it did not work. --Dianora
801     */
802    
803     /* Yes, a good compiler would have optimised this, but
804     * this is probably easier to read. -db
805     */
806     num = atoi(numeric);
807    
808     if ((num != ERR_NOSUCHNICK))
809     sendto_realops_flags(UMODE_ALL, L_ADMIN,
810     "*** %s(via %s) sent a %s numeric to me: %s",
811     source_p->name, client_p->name, numeric, buffer);
812     return;
813     }
814     else if (target_p->from == client_p)
815     {
816     /* This message changed direction (nick collision?)
817     * ignore it.
818     */
819     return;
820     }
821    
822     /* csircd will send out unknown umode flag for +a (admin), drop it here. */
823     if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
824     return;
825    
826     /* Fake it for server hiding, if its our client */
827     if (ConfigServerHide.hide_servers &&
828     MyClient(target_p) && !IsOper(target_p))
829     sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
830 adx 753 else
831     sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from),
832     numeric, ID_or_name(target_p, target_p->from), buffer);
833 adx 30 return;
834     }
835     else if ((chptr = hash_find_channel(parv[1])) != NULL)
836     sendto_channel_local(ALL_MEMBERS, NO, chptr,
837     ":%s %s %s %s",
838     source_p->name,
839     numeric, chptr->chname, buffer);
840     }
841    
842     /* m_not_oper()
843     * inputs -
844     * output -
845     * side effects - just returns a nastyogram to given user
846     */
847     void
848     m_not_oper(struct Client *client_p, struct Client *source_p,
849     int parc, char *parv[])
850     {
851     sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
852     me.name, parv[0]);
853     }
854    
855     void
856     m_unregistered(struct Client *client_p, struct Client *source_p,
857     int parc, char *parv[])
858     {
859     /* bit of a hack.
860     * I don't =really= want to waste a bit in a flag
861     * number_of_nick_changes is only really valid after the client
862     * is fully registered..
863     */
864     if (client_p->localClient->number_of_nick_changes == 0)
865     {
866     sendto_one(client_p, ":%s %d * %s :Register first.",
867     me.name, ERR_NOTREGISTERED, parv[0]);
868     client_p->localClient->number_of_nick_changes++;
869     }
870     }
871    
872     void
873     m_registered(struct Client *client_p, struct Client *source_p,
874     int parc, char *parv[])
875     {
876     sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),
877     me.name, parv[0]);
878     }
879    
880     void
881     m_ignore(struct Client *client_p, struct Client *source_p,
882     int parc, char *parv[])
883     {
884     return;
885     }
886    

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision