ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/src/parse.c
Revision: 948
Committed: Tue Jul 21 17:34:06 2009 UTC (14 years, 8 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/parse.c
File size: 26287 byte(s)
Log Message:
- lp64\llp64\ilp32 portability fixes

File Contents

# Content
1 /*
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 * $Id$
23 */
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 "send.h"
38 #include "ircd_handler.h"
39 #include "msg.h"
40 #include "s_conf.h"
41 #include "memory.h"
42 #include "s_user.h"
43 #include "s_serv.h"
44
45 /*
46 * (based on orabidoo's parser code)
47 *
48 * This has always just been a trie. Look at volume III of Knuth ACP
49 *
50 *
51 * ok, you start out with an array of pointers, each one corresponds
52 * to a letter at the current position in the command being examined.
53 *
54 * so roughly you have this for matching 'trie' or 'tie'
55 *
56 * 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i'
57 * -> [MessageTree *] -> [MessageTree *] -> 'e' and matches
58 *
59 * 'i' -> [MessageTree *] -> 'e' and matches
60 *
61 * BUGS (Limitations!)
62 *
63 * I designed this trie to parse ircd commands. Hence it currently
64 * casefolds. This is trivial to fix by increasing MAXPTRLEN.
65 * This trie also "folds" '{' etc. down. This means, the input to this
66 * trie must be alpha tokens only. This again, is a limitation that
67 * can be overcome by increasing MAXPTRLEN to include upper/lower case
68 * at the expense of more memory. At the extreme end, you could make
69 * MAXPTRLEN 128.
70 *
71 * This is also not a patricia trie. On short ircd tokens, this is
72 * not likely going to matter.
73 *
74 * Diane Bruce (Dianora), June 6 2003
75 */
76
77 #define MAXPTRLEN 32
78 /* Must be a power of 2, and
79 * larger than 26 [a-z]|[A-Z]
80 * its used to allocate the set
81 * of pointers at each node of the tree
82 * There are MAXPTRLEN pointers at each node.
83 * Obviously, there have to be more pointers
84 * Than ASCII letters. 32 is a nice number
85 * since there is then no need to shift
86 * 'A'/'a' to base 0 index, at the expense
87 * of a few never used pointers. For a small
88 * parser like this, this is a good compromise
89 * and does make it somewhat faster.
90 *
91 * - Dianora
92 */
93
94 struct MessageTree
95 {
96 int links; /* Count of all pointers (including msg) at this node
97 * used as reference count for deletion of _this_ node.
98 */
99 struct Message *msg;
100 struct MessageTree *pointers[MAXPTRLEN];
101 };
102
103 static struct MessageTree msg_tree;
104
105 /*
106 * NOTE: parse() should not be called recursively by other functions!
107 */
108 static char *sender;
109 static char *para[MAXPARA + 1];
110 static char buffer[1024];
111
112 static int cancel_clients(struct Client *, struct Client *, char *);
113 static void remove_unknown(struct Client *, char *, char *);
114 static void do_numeric(char[], struct Client *, struct Client *, int, char **);
115 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;
127
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 }
173
174 /*
175 * parse a buffer.
176 *
177 * NOTE: parse() should not be called recusively by any other functions!
178 */
179 void
180 parse(struct Client *client_p, char *pbuffer, char *bufend)
181 {
182 struct Client *from = client_p;
183 char *ch;
184 char *s;
185 char *numeric = 0;
186 unsigned int i = 0;
187 int paramcount;
188 int mpara = 0;
189 struct Message *mptr = NULL;
190
191 if (IsDefunct(client_p))
192 return;
193
194 assert(client_p->localClient->fd.flags.open);
195 assert((bufend - pbuffer) < 512);
196
197 for (ch = pbuffer; *ch == ' '; ch++) /* skip spaces */
198 /* null statement */ ;
199
200 para[0] = from->name;
201
202 if (*ch == ':')
203 {
204 ch++;
205
206 /* Copy the prefix to 'sender' assuming it terminates
207 * with SPACE (or NULL, which is an error, though).
208 */
209 sender = ch;
210
211 if ((s = strchr(ch, ' ')) != NULL)
212 {
213 *s = '\0';
214 s++;
215 ch = s;
216 }
217
218 if (*sender && IsServer(client_p))
219 {
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 */
224 if ((from = find_person(client_p, sender)) == NULL)
225 {
226 from = find_server(sender);
227
228 if (from == NULL && IsCapable(client_p, CAP_TS6) &&
229 client_p->name[0] == '*' && IsDigit(*sender) && strlen(sender) == 3)
230 {
231 /* 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
244 */
245 if (from == NULL)
246 {
247 ++ServerStats.is_unpf;
248 remove_unknown(client_p, sender, pbuffer);
249 return;
250 }
251
252 para[0] = from->name;
253
254 if (from->from != client_p)
255 {
256 ++ServerStats.is_wrdi;
257 cancel_clients(client_p, from, pbuffer);
258 return;
259 }
260 }
261
262 while (*ch == ' ')
263 ch++;
264 }
265
266 if (*ch == '\0')
267 {
268 ++ServerStats.is_empt;
269 return;
270 }
271
272 /* Extract the command code from the packet. Point s to the end
273 * of the command code and calculate the length using pointer
274 * arithmetic. Note: only need length for numerics and *all*
275 * numerics must have parameters and thus a space after the command
276 * code. -avalon
277 */
278
279 /* EOB is 3 chars long but is not a numeric */
280 if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */
281 IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2)))
282 {
283 mptr = NULL;
284 numeric = ch;
285 paramcount = MAXPARA;
286 ++ServerStats.is_num;
287 s = ch + 3; /* I know this is ' ' from above if */
288 *s++ = '\0'; /* blow away the ' ', and point s to next part */
289 }
290 else
291 {
292 unsigned int ii = 0;
293
294 if ((s = strchr(ch, ' ')) != NULL)
295 *s++ = '\0';
296
297 if ((mptr = find_command(ch)) == NULL)
298 {
299 /* Note: Give error message *only* to recognized
300 * persons. It's a nightmare situation to have
301 * two programs sending "Unknown command"'s or
302 * equivalent to each other at full blast....
303 * If it has got to person state, it at least
304 * seems to be well behaving. Perhaps this message
305 * should never be generated, though... --msa
306 * Hm, when is the buffer empty -- if a command
307 * code has been found ?? -Armin
308 */
309 if (pbuffer[0] != '\0')
310 {
311 if (IsClient(from))
312 sendto_one(from, form_str(ERR_UNKNOWNCOMMAND),
313 me.name, from->name, ch);
314 }
315
316 ++ServerStats.is_unco;
317 return;
318 }
319
320 assert(mptr->cmd != NULL);
321
322 paramcount = mptr->parameters;
323 mpara = mptr->maxpara;
324
325 ii = bufend - ((s) ? s : ch);
326 mptr->bytes += ii;
327 }
328
329 if (s != NULL)
330 i = string_to_array(s, para);
331 else
332 {
333 i = 0;
334 para[1] = NULL;
335 }
336
337 if (mptr == NULL)
338 do_numeric(numeric, client_p, from, i, para);
339 else
340 handle_command(mptr, client_p, from, i, para);
341 }
342
343 /* handle_command()
344 *
345 * inputs - pointer to message block
346 * - pointer to client
347 * - pointer to client message is from
348 * - count of number of args
349 * - pointer to argv[] array
350 * output - -1 if error from server
351 * side effects -
352 */
353 static void
354 handle_command(struct Message *mptr, struct Client *client_p,
355 struct Client *from, unsigned int i, char *hpara[MAXPARA])
356 {
357 MessageHandler handler = 0;
358
359 if (IsServer(client_p))
360 mptr->rcount++;
361
362 mptr->count++;
363
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
376 handler = mptr->handlers[client_p->handler];
377
378 /* check right amount of params is passed... --is */
379 if (i < mptr->parameters)
380 {
381 if (!IsServer(client_p))
382 {
383 sendto_one(client_p, form_str(ERR_NEEDMOREPARAMS),
384 me.name, EmptyString(hpara[0]) ? "*" : hpara[0], mptr->cmd);
385 }
386 else
387 {
388 sendto_realops_flags(UMODE_ALL, L_ALL,
389 "Dropping server %s due to (invalid) command '%s' "
390 "with only %d arguments (expecting %d).",
391 client_p->name, mptr->cmd, i, mptr->parameters);
392 ilog(L_CRIT, "Insufficient parameters (%d) for command '%s' from %s.",
393 i, mptr->cmd, client_p->name);
394 exit_client(client_p, client_p,
395 "Not enough arguments to server command.");
396 }
397 }
398 else
399 (*handler)(client_p, from, i, hpara);
400 }
401
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
415 /* add_msg_element()
416 *
417 * inputs - pointer to MessageTree
418 * - pointer to Message to add for given command
419 * - pointer to current portion of command being added
420 * output - NONE
421 * side effects - recursively build the Message Tree ;-)
422 */
423 /*
424 * How this works.
425 *
426 * The code first checks to see if its reached the end of the command
427 * If so, that struct MessageTree has a msg pointer updated and the links
428 * count incremented, since a msg pointer is a reference.
429 * Then the code descends recursively, building the trie.
430 * If a pointer index inside the struct MessageTree is NULL a new
431 * child struct MessageTree has to be allocated.
432 * The links (reference count) is incremented as they are created
433 * in the parent.
434 */
435 static void
436 add_msg_element(struct MessageTree *mtree_p,
437 struct Message *msg_p, const char *cmd)
438 {
439 struct MessageTree *ntree_p;
440
441 if (*cmd == '\0')
442 {
443 mtree_p->msg = msg_p;
444 mtree_p->links++; /* Have msg pointer, so up ref count */
445 }
446 else
447 {
448 /* *cmd & (MAXPTRLEN-1)
449 * convert the char pointed to at *cmd from ASCII to an integer
450 * between 0 and MAXPTRLEN.
451 * Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc.
452 */
453
454 if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN-1)]) == NULL)
455 {
456 ntree_p = (struct MessageTree *)MyMalloc(sizeof(struct MessageTree));
457 mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = ntree_p;
458
459 mtree_p->links++; /* Have new pointer, so up ref count */
460 }
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
510 if (ntree_p->links == 0)
511 {
512 mtree_p->pointers[*cmd & (MAXPTRLEN-1)] = NULL;
513 mtree_p->links--;
514 MyFree(ntree_p);
515 }
516 }
517 }
518 }
519
520 /* msg_tree_parse()
521 *
522 * inputs - Pointer to command to find
523 * - Pointer to MessageTree root
524 * output - Find given command returning Message * if found NULL if not
525 * side effects - none
526 */
527 static struct Message *
528 msg_tree_parse(const char *cmd, struct MessageTree *root)
529 {
530 struct MessageTree *mtree = root;
531 assert(cmd && *cmd);
532
533 while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)]))
534 if (*++cmd == '\0')
535 return mtree->msg;
536
537 return NULL;
538 }
539
540 /* mod_add_cmd()
541 *
542 * inputs - pointer to struct Message
543 * output - none
544 * side effects - load this one command name
545 * msg->count msg->bytes is modified in place, in
546 * modules address space. Might not want to do that...
547 */
548 void
549 mod_add_cmd(struct Message *msg)
550 {
551 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);
558
559 /* command already added? */
560 if ((found_msg = msg_tree_parse(msg->cmd, &msg_tree)) != NULL)
561 return;
562
563 add_msg_element(&msg_tree, msg, msg->cmd);
564 msg->count = msg->rcount = msg->bytes = 0;
565 }
566
567 /* mod_del_cmd()
568 *
569 * inputs - pointer to struct Message
570 * output - none
571 * side effects - unload this one command name
572 */
573 void
574 mod_del_cmd(struct Message *msg)
575 {
576 assert(msg != NULL);
577
578 if (msg == NULL)
579 return;
580
581 del_msg_element(&msg_tree, msg->cmd);
582 }
583
584 /* find_command()
585 *
586 * inputs - command name
587 * output - pointer to struct Message
588 * side effects - none
589 */
590 struct Message *
591 find_command(const char *cmd)
592 {
593 return msg_tree_parse(cmd, &msg_tree);
594 }
595
596 /* report_messages()
597 *
598 * inputs - pointer to client to report to
599 * output - NONE
600 * side effects - client is shown list of commands
601 */
602 void
603 report_messages(struct Client *source_p)
604 {
605 struct MessageTree *mtree = &msg_tree;
606 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;
617
618 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++)
625 if (mtree->pointers[i] != NULL)
626 recurse_report_messages(source_p, mtree->pointers[i]);
627 }
628
629 /* cancel_clients()
630 *
631 * inputs -
632 * output -
633 * side effects -
634 */
635 static int
636 cancel_clients(struct Client *client_p, struct Client *source_p, char *cmd)
637 {
638 /* kill all possible points that are causing confusion here,
639 * I'm not sure I've got this all right...
640 * - avalon
641 *
642 * knowing avalon, probably not.
643 */
644
645 /* with TS, fake prefixes are a common thing, during the
646 * connect burst when there's a nick collision, and they
647 * must be ignored rather than killed because one of the
648 * two is surviving.. so we don't bother sending them to
649 * all ops everytime, as this could send 'private' stuff
650 * from lagged clients. we do send the ones that cause
651 * servers to be dropped though, as well as the ones from
652 * non-TS servers -orabidoo
653 */
654 /* Incorrect prefix for a server from some connection. If it is a
655 * client trying to be annoying, just QUIT them, if it is a server
656 * then the same deal.
657 */
658 if (IsServer(source_p) || IsMe(source_p))
659 {
660 sendto_realops_flags(UMODE_DEBUG, L_ADMIN, "Message for %s[%s] from %s",
661 source_p->name, source_p->from->name,
662 get_client_name(client_p, SHOW_IP));
663 sendto_realops_flags(UMODE_DEBUG, L_OPER, "Message for %s[%s] from %s",
664 source_p->name, source_p->from->name,
665 get_client_name(client_p, MASK_IP));
666 sendto_realops_flags(UMODE_DEBUG, L_ALL,
667 "Not dropping server %s (%s) for Fake Direction",
668 client_p->name, source_p->name);
669 return -1;
670 /* return exit_client(client_p, client_p, &me, "Fake Direction");*/
671 }
672
673 /* Ok, someone is trying to impose as a client and things are
674 * confused. If we got the wrong prefix from a server, send out a
675 * kill, else just exit the lame client.
676 */
677 /* If the fake prefix is coming from a TS server, discard it
678 * silently -orabidoo
679 *
680 * all servers must be TS these days --is
681 */
682 sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
683 "Message for %s[%s@%s!%s] from %s (TS, ignored)",
684 source_p->name, source_p->username, source_p->host,
685 source_p->from->name, get_client_name(client_p, SHOW_IP));
686 sendto_realops_flags(UMODE_DEBUG, L_OPER,
687 "Message for %s[%s@%s!%s] from %s (TS, ignored)",
688 source_p->name, source_p->username, source_p->host,
689 source_p->from->name, get_client_name(client_p, MASK_IP));
690
691 return 0;
692 }
693
694 /* remove_unknown()
695 *
696 * inputs -
697 * output -
698 * side effects -
699 */
700 static void
701 remove_unknown(struct Client *client_p, char *lsender, char *lbuffer)
702 {
703 /* Do kill if it came from a server because it means there is a ghost
704 * user on the other server which needs to be removed. -avalon
705 * Tell opers about this. -Taner
706 */
707 /* '[0-9]something' is an ID (KILL/SQUIT depending on its length)
708 * 'nodots' is a nickname (KILL)
709 * 'no.dot.at.start' is a server (SQUIT)
710 */
711 if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) ||
712 strchr(lsender, '.') != NULL)
713 {
714 sendto_realops_flags(UMODE_DEBUG, L_ADMIN,
715 "Unknown prefix (%s) from %s, Squitting %s",
716 lbuffer, get_client_name(client_p, SHOW_IP), lsender);
717 sendto_realops_flags(UMODE_DEBUG, L_OPER,
718 "Unknown prefix (%s) from %s, Squitting %s",
719 lbuffer, client_p->name, lsender);
720 sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)",
721 me.name, lsender, lbuffer, client_p->name);
722 }
723 else
724 sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)",
725 me.name, lsender, me.name);
726 }
727
728 /*
729 *
730 * parc number of arguments ('sender' counted as one!)
731 * parv[0] pointer to 'sender' (may point to empty string) (not used)
732 * parv[1]..parv[parc-1]
733 * pointers to additional parameters, this is a NULL
734 * terminated list (parv[parc] == NULL).
735 *
736 * *WARNING*
737 * Numerics are mostly error reports. If there is something
738 * wrong with the message, just *DROP* it! Don't even think of
739 * sending back a neat error message -- big danger of creating
740 * a ping pong error message...
741 */
742 static void
743 do_numeric(char numeric[], struct Client *client_p, struct Client *source_p,
744 int parc, char *parv[])
745 {
746 struct Client *target_p;
747 struct Channel *chptr;
748 char *t; /* current position within the buffer */
749 int i, tl; /* current length of presently being built string in t */
750
751 if (parc < 2 || !IsServer(source_p))
752 return;
753
754 /* Remap low number numerics. */
755 if (numeric[0] == '0')
756 numeric[0] = '1';
757
758 /* Prepare the parameter portion of the message into 'buffer'.
759 * (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)
762 */
763 t = buffer;
764 for (i = 2; i < (parc - 1); i++)
765 {
766 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 */
797
798 /* Yes, a good compiler would have optimised this, but
799 * this is probably easier to read. -db
800 */
801 num = atoi(numeric);
802
803 if ((num != ERR_NOSUCHNICK))
804 sendto_realops_flags(UMODE_ALL, L_ADMIN,
805 "*** %s(via %s) sent a %s numeric to me: %s",
806 source_p->name, client_p->name, numeric, buffer);
807 return;
808 }
809 else if (target_p->from == client_p)
810 {
811 /* This message changed direction (nick collision?)
812 * ignore it.
813 */
814 return;
815 }
816
817 /* csircd will send out unknown umode flag for +a (admin), drop it here. */
818 if ((atoi(numeric) == ERR_UMODEUNKNOWNFLAG) && MyClient(target_p))
819 return;
820
821 /* Fake it for server hiding, if its our client */
822 if (ConfigServerHide.hide_servers &&
823 MyClient(target_p) && !IsOper(target_p))
824 sendto_one(target_p, ":%s %s %s%s", me.name, numeric, target_p->name, buffer);
825 else
826 sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from),
827 numeric, ID_or_name(target_p, target_p->from), buffer);
828 return;
829 }
830 else if ((chptr = hash_find_channel(parv[1])) != NULL)
831 sendto_channel_local(ALL_MEMBERS, NO, chptr,
832 ":%s %s %s %s",
833 source_p->name,
834 numeric, chptr->chname, buffer);
835 }
836
837 /* m_not_oper()
838 * inputs -
839 * output -
840 * side effects - just returns a nastyogram to given user
841 */
842 void
843 m_not_oper(struct Client *client_p, struct Client *source_p,
844 int parc, char *parv[])
845 {
846 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
847 me.name, source_p->name);
848 }
849
850 void
851 m_unregistered(struct Client *client_p, struct Client *source_p,
852 int parc, char *parv[])
853 {
854 /* bit of a hack.
855 * 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 }
865 }
866
867 void
868 m_registered(struct Client *client_p, struct Client *source_p,
869 int parc, char *parv[])
870 {
871 sendto_one(client_p, form_str(ERR_ALREADYREGISTRED),
872 me.name, parv[0]);
873 }
874
875 void
876 m_ignore(struct Client *client_p, struct Client *source_p,
877 int parc, char *parv[])
878 {
879 return;
880 }
881
882 void
883 rfc1459_command_send_error(struct Client *client_p, struct Client *source_p,
884 int parc, char *parv[])
885 {
886 const char *in_para;
887
888 in_para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>";
889
890 ilog(L_ERROR, "Received ERROR message from %s: %s",
891 source_p->name, in_para);
892
893 if (client_p == source_p)
894 {
895 sendto_realops_flags(UMODE_ALL, L_ADMIN, "ERROR :from %s -- %s",
896 get_client_name(client_p, HIDE_IP), in_para);
897 sendto_realops_flags(UMODE_ALL, L_OPER, "ERROR :from %s -- %s",
898 get_client_name(client_p, MASK_IP), in_para);
899 }
900 else
901 {
902 sendto_realops_flags(UMODE_ALL, L_OPER, "ERROR :from %s via %s -- %s",
903 source_p->name, get_client_name(client_p, MASK_IP), in_para);
904 sendto_realops_flags(UMODE_ALL, L_ADMIN, "ERROR :from %s via %s -- %s",
905 source_p->name, get_client_name(client_p, HIDE_IP), in_para);
906 }
907
908 if (MyClient(source_p))
909 exit_client(source_p, source_p, "ERROR");
910 }

Properties

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