ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/parse.c
Revision: 1178
Committed: Mon Aug 15 08:11:31 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/src/parse.c
File size: 26421 byte(s)
Log Message:
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

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

Properties

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