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 "client.h" |
27 |
#include "parse.h" |
28 |
#include "channel.h" |
29 |
#include "hash.h" |
30 |
#include "irc_string.h" |
31 |
#include "sprintf_irc.h" |
32 |
#include "ircd.h" |
33 |
#include "numeric.h" |
34 |
#include "log.h" |
35 |
#include "send.h" |
36 |
#include "conf.h" |
37 |
#include "memory.h" |
38 |
#include "s_user.h" |
39 |
#include "s_serv.h" |
40 |
|
41 |
/* |
42 |
* (based on orabidoo's parser code) |
43 |
* |
44 |
* This has always just been a trie. Look at volume III of Knuth ACP |
45 |
* |
46 |
* |
47 |
* ok, you start out with an array of pointers, each one corresponds |
48 |
* to a letter at the current position in the command being examined. |
49 |
* |
50 |
* so roughly you have this for matching 'trie' or 'tie' |
51 |
* |
52 |
* 't' points -> [MessageTree *] 'r' -> [MessageTree *] -> 'i' |
53 |
* -> [MessageTree *] -> [MessageTree *] -> 'e' and matches |
54 |
* |
55 |
* 'i' -> [MessageTree *] -> 'e' and matches |
56 |
* |
57 |
* BUGS (Limitations!) |
58 |
* |
59 |
* I designed this trie to parse ircd commands. Hence it currently |
60 |
* casefolds. This is trivial to fix by increasing MAXPTRLEN. |
61 |
* This trie also "folds" '{' etc. down. This means, the input to this |
62 |
* trie must be alpha tokens only. This again, is a limitation that |
63 |
* can be overcome by increasing MAXPTRLEN to include upper/lower case |
64 |
* at the expense of more memory. At the extreme end, you could make |
65 |
* MAXPTRLEN 128. |
66 |
* |
67 |
* This is also not a patricia trie. On short ircd tokens, this is |
68 |
* not likely going to matter. |
69 |
* |
70 |
* Diane Bruce (Dianora), June 6 2003 |
71 |
*/ |
72 |
|
73 |
#define MAXPTRLEN 32 |
74 |
/* Must be a power of 2, and |
75 |
* larger than 26 [a-z]|[A-Z] |
76 |
* its used to allocate the set |
77 |
* of pointers at each node of the tree |
78 |
* There are MAXPTRLEN pointers at each node. |
79 |
* Obviously, there have to be more pointers |
80 |
* Than ASCII letters. 32 is a nice number |
81 |
* since there is then no need to shift |
82 |
* 'A'/'a' to base 0 index, at the expense |
83 |
* of a few never used pointers. For a small |
84 |
* parser like this, this is a good compromise |
85 |
* and does make it somewhat faster. |
86 |
* |
87 |
* - Dianora |
88 |
*/ |
89 |
|
90 |
struct MessageTree |
91 |
{ |
92 |
int links; /* Count of all pointers (including msg) at this node |
93 |
* used as reference count for deletion of _this_ node. |
94 |
*/ |
95 |
struct Message *msg; |
96 |
struct MessageTree *pointers[MAXPTRLEN]; |
97 |
}; |
98 |
|
99 |
static struct MessageTree msg_tree; |
100 |
|
101 |
/* |
102 |
* NOTE: parse() should not be called recursively by other functions! |
103 |
*/ |
104 |
static char *sender; |
105 |
static char *para[MAXPARA + 2]; /* <prefix> + <params> + NULL */ |
106 |
|
107 |
static int cancel_clients(struct Client *, struct Client *, char *); |
108 |
static void remove_unknown(struct Client *, char *, char *); |
109 |
static void handle_numeric(char[], struct Client *, struct Client *, int, char *[]); |
110 |
static void handle_command(struct Message *, struct Client *, struct Client *, unsigned int, char *[]); |
111 |
|
112 |
|
113 |
/* |
114 |
* parse a buffer. |
115 |
* |
116 |
* NOTE: parse() should not be called recusively by any other functions! |
117 |
*/ |
118 |
void |
119 |
parse(struct Client *client_p, char *pbuffer, char *bufend) |
120 |
{ |
121 |
struct Client *from = client_p; |
122 |
struct Message *msg_ptr = NULL; |
123 |
char *ch = NULL; |
124 |
char *s = NULL; |
125 |
char *numeric = NULL; |
126 |
unsigned int parc = 0; |
127 |
unsigned int paramcount; |
128 |
|
129 |
if (IsDefunct(client_p)) |
130 |
return; |
131 |
|
132 |
assert(client_p->localClient->fd.flags.open); |
133 |
assert((bufend - pbuffer) < 512); |
134 |
|
135 |
for (ch = pbuffer; *ch == ' '; ++ch) /* skip spaces */ |
136 |
/* null statement */ ; |
137 |
|
138 |
if (*ch == ':') |
139 |
{ |
140 |
/* |
141 |
* Copy the prefix to 'sender' assuming it terminates |
142 |
* with SPACE (or NULL, which is an error, though). |
143 |
*/ |
144 |
sender = ++ch; |
145 |
|
146 |
if ((s = strchr(ch, ' ')) != NULL) |
147 |
{ |
148 |
*s = '\0'; |
149 |
ch = ++s; |
150 |
} |
151 |
|
152 |
if (*sender && IsServer(client_p)) |
153 |
{ |
154 |
if ((from = find_person(client_p, sender)) == NULL) |
155 |
from = hash_find_server(sender); |
156 |
|
157 |
/* Hmm! If the client corresponding to the |
158 |
* prefix is not found--what is the correct |
159 |
* action??? Now, I will ignore the message |
160 |
* (old IRC just let it through as if the |
161 |
* prefix just wasn't there...) --msa |
162 |
*/ |
163 |
if (from == NULL) |
164 |
{ |
165 |
++ServerStats.is_unpf; |
166 |
remove_unknown(client_p, sender, pbuffer); |
167 |
return; |
168 |
} |
169 |
|
170 |
if (from->from != client_p) |
171 |
{ |
172 |
++ServerStats.is_wrdi; |
173 |
cancel_clients(client_p, from, pbuffer); |
174 |
return; |
175 |
} |
176 |
} |
177 |
|
178 |
while (*ch == ' ') |
179 |
++ch; |
180 |
} |
181 |
|
182 |
if (*ch == '\0') |
183 |
{ |
184 |
++ServerStats.is_empt; |
185 |
return; |
186 |
} |
187 |
|
188 |
/* Extract the command code from the packet. Point s to the end |
189 |
* of the command code and calculate the length using pointer |
190 |
* arithmetic. Note: only need length for numerics and *all* |
191 |
* numerics must have parameters and thus a space after the command |
192 |
* code. -avalon |
193 |
*/ |
194 |
|
195 |
/* EOB is 3 chars long but is not a numeric */ |
196 |
if (*(ch + 3) == ' ' && /* ok, lets see if its a possible numeric.. */ |
197 |
IsDigit(*ch) && IsDigit(*(ch + 1)) && IsDigit(*(ch + 2))) |
198 |
{ |
199 |
numeric = ch; |
200 |
paramcount = 2; /* destination, and the rest of it */ |
201 |
++ServerStats.is_num; |
202 |
s = ch + 3; /* I know this is ' ' from above if */ |
203 |
*s++ = '\0'; /* blow away the ' ', and point s to next part */ |
204 |
} |
205 |
else |
206 |
{ |
207 |
unsigned int ii = 0; |
208 |
|
209 |
if ((s = strchr(ch, ' ')) != NULL) |
210 |
*s++ = '\0'; |
211 |
|
212 |
if ((msg_ptr = find_command(ch)) == NULL) |
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.... |
218 |
* If it has got to person state, it at least |
219 |
* seems to be well behaving. Perhaps this message |
220 |
* should never be generated, though... --msa |
221 |
* Hm, when is the buffer empty -- if a command |
222 |
* code has been found ?? -Armin |
223 |
*/ |
224 |
if (*pbuffer != '\0') |
225 |
{ |
226 |
if (IsClient(from)) |
227 |
sendto_one(from, form_str(ERR_UNKNOWNCOMMAND), |
228 |
me.name, from->name, ch); |
229 |
} |
230 |
|
231 |
++ServerStats.is_unco; |
232 |
return; |
233 |
} |
234 |
|
235 |
assert(msg_ptr->cmd != NULL); |
236 |
|
237 |
paramcount = msg_ptr->args_max; |
238 |
ii = bufend - ((s) ? s : ch); |
239 |
msg_ptr->bytes += ii; |
240 |
} |
241 |
|
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 |
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 |
para[++parc] = NULL; |
284 |
|
285 |
if (msg_ptr != NULL) |
286 |
handle_command(msg_ptr, client_p, from, parc, para); |
287 |
else |
288 |
handle_numeric(numeric, client_p, from, parc, para); |
289 |
} |
290 |
|
291 |
/* handle_command() |
292 |
* |
293 |
* inputs - pointer to message block |
294 |
* - pointer to client |
295 |
* - pointer to client message is from |
296 |
* - count of number of args |
297 |
* - pointer to argv[] array |
298 |
* output - -1 if error from server |
299 |
* side effects - |
300 |
*/ |
301 |
static void |
302 |
handle_command(struct Message *mptr, struct Client *client_p, |
303 |
struct Client *from, unsigned int i, char *hpara[]) |
304 |
{ |
305 |
MessageHandler handler = 0; |
306 |
|
307 |
if (IsServer(client_p)) |
308 |
mptr->rcount++; |
309 |
|
310 |
mptr->count++; |
311 |
|
312 |
handler = mptr->handlers[client_p->handler]; |
313 |
|
314 |
/* check right amount of params is passed... --is */ |
315 |
if (i < mptr->args_min) |
316 |
{ |
317 |
if (!IsServer(client_p)) |
318 |
{ |
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, 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->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."); |
332 |
} |
333 |
} |
334 |
else |
335 |
(*handler)(client_p, from, i, hpara); |
336 |
} |
337 |
|
338 |
/* add_msg_element() |
339 |
* |
340 |
* inputs - pointer to MessageTree |
341 |
* - pointer to Message to add for given command |
342 |
* - pointer to current portion of command being added |
343 |
* output - NONE |
344 |
* side effects - recursively build the Message Tree ;-) |
345 |
*/ |
346 |
/* |
347 |
* How this works. |
348 |
* |
349 |
* The code first checks to see if its reached the end of the command |
350 |
* If so, that struct MessageTree has a msg pointer updated and the links |
351 |
* count incremented, since a msg pointer is a reference. |
352 |
* Then the code descends recursively, building the trie. |
353 |
* If a pointer index inside the struct MessageTree is NULL a new |
354 |
* child struct MessageTree has to be allocated. |
355 |
* The links (reference count) is incremented as they are created |
356 |
* in the parent. |
357 |
*/ |
358 |
static void |
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 */ |
368 |
} |
369 |
else |
370 |
{ |
371 |
/* *cmd & (MAXPTRLEN-1) |
372 |
* convert the char pointed to at *cmd from ASCII to an integer |
373 |
* between 0 and MAXPTRLEN. |
374 |
* Thus 'A' -> 0x1 'B' -> 0x2 'c' -> 0x3 etc. |
375 |
*/ |
376 |
|
377 |
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) == NULL) |
378 |
{ |
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 */ |
383 |
} |
384 |
|
385 |
add_msg_element(ntree_p, msg_p, cmd + 1); |
386 |
} |
387 |
} |
388 |
|
389 |
/* del_msg_element() |
390 |
* |
391 |
* inputs - Pointer to MessageTree to delete from |
392 |
* - pointer to command name to delete |
393 |
* output - NONE |
394 |
* side effects - recursively deletes a token from the Message Tree ;-) |
395 |
*/ |
396 |
/* |
397 |
* How this works. |
398 |
* |
399 |
* Well, first off, the code recursively descends into the trie |
400 |
* until it finds the terminating letter of the command being removed. |
401 |
* Once it has done that, it marks the msg pointer as NULL then |
402 |
* reduces the reference count on that allocated struct MessageTree |
403 |
* since a command counts as a reference. |
404 |
* |
405 |
* Then it pops up the recurse stack. As it comes back up the recurse |
406 |
* The code checks to see if the child now has no pointers or msg |
407 |
* i.e. the links count has gone to zero. If its no longer used, the |
408 |
* child struct MessageTree can be deleted. The parent reference |
409 |
* to this child is then removed and the parents link count goes down. |
410 |
* Thus, we continue to go back up removing all unused MessageTree(s) |
411 |
*/ |
412 |
static void |
413 |
del_msg_element(struct MessageTree *mtree_p, const char *cmd) |
414 |
{ |
415 |
struct MessageTree *ntree_p; |
416 |
|
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 |
*/ |
422 |
if ((*cmd == '\0') && (mtree_p->msg != NULL)) |
423 |
{ |
424 |
mtree_p->msg = NULL; |
425 |
mtree_p->links--; |
426 |
} |
427 |
else |
428 |
{ |
429 |
if ((ntree_p = mtree_p->pointers[*cmd & (MAXPTRLEN - 1)]) != NULL) |
430 |
{ |
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); |
438 |
} |
439 |
} |
440 |
} |
441 |
} |
442 |
|
443 |
/* msg_tree_parse() |
444 |
* |
445 |
* inputs - Pointer to command to find |
446 |
* - Pointer to MessageTree root |
447 |
* output - Find given command returning Message * if found NULL if not |
448 |
* side effects - none |
449 |
*/ |
450 |
static struct Message * |
451 |
msg_tree_parse(const char *cmd) |
452 |
{ |
453 |
struct MessageTree *mtree = &msg_tree; |
454 |
assert(cmd && *cmd); |
455 |
|
456 |
while (IsAlpha(*cmd) && (mtree = mtree->pointers[*cmd & (MAXPTRLEN - 1)])) |
457 |
if (*++cmd == '\0') |
458 |
return mtree->msg; |
459 |
|
460 |
return NULL; |
461 |
} |
462 |
|
463 |
/* mod_add_cmd() |
464 |
* |
465 |
* inputs - pointer to struct Message |
466 |
* output - none |
467 |
* side effects - load this one command name |
468 |
* msg->count msg->bytes is modified in place, in |
469 |
* modules address space. Might not want to do that... |
470 |
*/ |
471 |
void |
472 |
mod_add_cmd(struct Message *msg) |
473 |
{ |
474 |
assert(msg && msg->cmd); |
475 |
|
476 |
/* command already added? */ |
477 |
if (msg_tree_parse(msg->cmd)) |
478 |
return; |
479 |
|
480 |
add_msg_element(&msg_tree, msg, msg->cmd); |
481 |
msg->count = msg->rcount = msg->bytes = 0; |
482 |
} |
483 |
|
484 |
/* mod_del_cmd() |
485 |
* |
486 |
* inputs - pointer to struct Message |
487 |
* output - none |
488 |
* side effects - unload this one command name |
489 |
*/ |
490 |
void |
491 |
mod_del_cmd(struct Message *msg) |
492 |
{ |
493 |
assert(msg && msg->cmd); |
494 |
|
495 |
del_msg_element(&msg_tree, msg->cmd); |
496 |
} |
497 |
|
498 |
/* find_command() |
499 |
* |
500 |
* inputs - command name |
501 |
* output - pointer to struct Message |
502 |
* side effects - none |
503 |
*/ |
504 |
struct Message * |
505 |
find_command(const char *cmd) |
506 |
{ |
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() |
527 |
* |
528 |
* inputs - pointer to client to report to |
529 |
* output - NONE |
530 |
* side effects - client is shown list of commands |
531 |
*/ |
532 |
void |
533 |
report_messages(struct Client *source_p) |
534 |
{ |
535 |
const struct MessageTree *mtree = &msg_tree; |
536 |
unsigned int i; |
537 |
|
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 - |
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, |
553 |
* I'm not sure I've got this all right... |
554 |
* - avalon |
555 |
* |
556 |
* knowing avalon, probably not. |
557 |
*/ |
558 |
|
559 |
/* with TS, fake prefixes are a common thing, during the |
560 |
* connect burst when there's a nick collision, and they |
561 |
* must be ignored rather than killed because one of the |
562 |
* two is surviving.. so we don't bother sending them to |
563 |
* all ops everytime, as this could send 'private' stuff |
564 |
* from lagged clients. we do send the ones that cause |
565 |
* servers to be dropped though, as well as the ones from |
566 |
* non-TS servers -orabidoo |
567 |
*/ |
568 |
/* Incorrect prefix for a server from some connection. If it is a |
569 |
* client trying to be annoying, just QUIT them, if it is a server |
570 |
* then the same deal. |
571 |
*/ |
572 |
if (IsServer(source_p) || IsMe(source_p)) |
573 |
{ |
574 |
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
575 |
"Message for %s[%s] from %s", |
576 |
source_p->name, source_p->from->name, |
577 |
get_client_name(client_p, SHOW_IP)); |
578 |
sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE, |
579 |
"Message for %s[%s] from %s", |
580 |
source_p->name, source_p->from->name, |
581 |
get_client_name(client_p, MASK_IP)); |
582 |
sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE, |
583 |
"Not dropping server %s (%s) for Fake Direction", |
584 |
client_p->name, source_p->name); |
585 |
return -1; |
586 |
/* return exit_client(client_p, client_p, &me, "Fake Direction");*/ |
587 |
} |
588 |
|
589 |
/* Ok, someone is trying to impose as a client and things are |
590 |
* confused. If we got the wrong prefix from a server, send out a |
591 |
* kill, else just exit the lame client. |
592 |
*/ |
593 |
/* If the fake prefix is coming from a TS server, discard it |
594 |
* silently -orabidoo |
595 |
* |
596 |
* all servers must be TS these days --is |
597 |
*/ |
598 |
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
599 |
"Message for %s[%s@%s!%s] from %s (TS, ignored)", |
600 |
source_p->name, source_p->username, source_p->host, |
601 |
source_p->from->name, get_client_name(client_p, SHOW_IP)); |
602 |
sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE, |
603 |
"Message for %s[%s@%s!%s] from %s (TS, ignored)", |
604 |
source_p->name, source_p->username, source_p->host, |
605 |
source_p->from->name, get_client_name(client_p, MASK_IP)); |
606 |
|
607 |
return 0; |
608 |
} |
609 |
|
610 |
/* remove_unknown() |
611 |
* |
612 |
* inputs - |
613 |
* output - |
614 |
* side effects - |
615 |
*/ |
616 |
static void |
617 |
remove_unknown(struct Client *client_p, char *lsender, char *lbuffer) |
618 |
{ |
619 |
/* Do kill if it came from a server because it means there is a ghost |
620 |
* user on the other server which needs to be removed. -avalon |
621 |
* Tell opers about this. -Taner |
622 |
*/ |
623 |
/* '[0-9]something' is an ID (KILL/SQUIT depending on its length) |
624 |
* 'nodots' is a nickname (KILL) |
625 |
* 'no.dot.at.start' is a server (SQUIT) |
626 |
*/ |
627 |
if ((IsDigit(*lsender) && strlen(lsender) <= IRC_MAXSID) || |
628 |
strchr(lsender, '.') != NULL) |
629 |
{ |
630 |
sendto_realops_flags(UMODE_DEBUG, L_ADMIN, SEND_NOTICE, |
631 |
"Unknown prefix (%s) from %s, Squitting %s", |
632 |
lbuffer, get_client_name(client_p, SHOW_IP), lsender); |
633 |
sendto_realops_flags(UMODE_DEBUG, L_OPER, SEND_NOTICE, |
634 |
"Unknown prefix (%s) from %s, Squitting %s", |
635 |
lbuffer, client_p->name, lsender); |
636 |
sendto_one(client_p, ":%s SQUIT %s :(Unknown prefix (%s) from %s)", |
637 |
me.name, lsender, lbuffer, client_p->name); |
638 |
} |
639 |
else |
640 |
sendto_one(client_p, ":%s KILL %s :%s (Unknown Client)", |
641 |
me.name, lsender, me.name); |
642 |
} |
643 |
|
644 |
/* |
645 |
* |
646 |
* parc number of arguments ('sender' counted as one!) |
647 |
* parv[0] pointer to 'sender' (may point to empty string) (not used) |
648 |
* parv[1]..parv[parc-1] |
649 |
* pointers to additional parameters, this is a NULL |
650 |
* terminated list (parv[parc] == NULL). |
651 |
* |
652 |
* *WARNING* |
653 |
* Numerics are mostly error reports. If there is something |
654 |
* wrong with the message, just *DROP* it! Don't even think of |
655 |
* sending back a neat error message -- big danger of creating |
656 |
* a ping pong error message... |
657 |
* |
658 |
* Rewritten by Nemesi, Jan 1999, to support numeric nicks in parv[1] |
659 |
* |
660 |
* Called when we get a numeric message from a remote _server_ and we are |
661 |
* supposed to forward it somewhere. Note that we always ignore numerics sent |
662 |
* to 'me' and simply drop the message if we can't handle with this properly: |
663 |
* the savvy approach is NEVER generate an error in response to an... error :) |
664 |
*/ |
665 |
static void |
666 |
handle_numeric(char numeric[], struct Client *client_p, struct Client *source_p, |
667 |
int parc, char *parv[]) |
668 |
{ |
669 |
struct Client *target_p = NULL; |
670 |
struct Channel *chptr = NULL; |
671 |
|
672 |
/* Avoid trash, we need it to come from a server and have a target */ |
673 |
if (parc < 2 || !IsServer(source_p)) |
674 |
return; |
675 |
|
676 |
/* |
677 |
* Who should receive this message ? Will we do something with it ? |
678 |
* Note that we use findUser functions, so the target can't be neither |
679 |
* a server, nor a channel (?) nor a list of targets (?) .. u2.10 |
680 |
* should never generate numeric replies to non-users anyway |
681 |
* Ahem... it can be a channel actually, csc bots use it :\ --Nem |
682 |
*/ |
683 |
if (IsChanPrefix(*parv[1])) |
684 |
chptr = hash_find_channel(parv[1]); |
685 |
else |
686 |
target_p = find_person(client_p, parv[1]); |
687 |
|
688 |
if (((!target_p) || (target_p->from == client_p)) && !chptr) |
689 |
return; |
690 |
|
691 |
/* |
692 |
* Remap low number numerics, not that I understand WHY.. --Nemesi |
693 |
*/ |
694 |
/* |
695 |
* numerics below 100 talk about the current 'connection', you're not |
696 |
* connected to a remote server so it doesn't make sense to send them |
697 |
* remotely - but the information they contain may be useful, so we |
698 |
* remap them up. Weird, but true. -- Isomer |
699 |
*/ |
700 |
if (numeric[0] == '0') |
701 |
numeric[0] = '1'; |
702 |
|
703 |
if (target_p) |
704 |
{ |
705 |
/* Fake it for server hiding, if its our client */ |
706 |
if (ConfigServerHide.hide_servers && MyClient(target_p) && |
707 |
!HasUMode(target_p, UMODE_OPER)) |
708 |
sendto_one(target_p, ":%s %s %s %s", me.name, numeric, target_p->name, parv[2]); |
709 |
else |
710 |
sendto_one(target_p, ":%s %s %s%s", ID_or_name(source_p, target_p->from), |
711 |
numeric, ID_or_name(target_p, target_p->from), parv[2]); |
712 |
} |
713 |
else |
714 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s %s %s %s", |
715 |
source_p->name, numeric, chptr->chname, parv[2]); |
716 |
} |
717 |
|
718 |
/* m_not_oper() |
719 |
* inputs - |
720 |
* output - |
721 |
* side effects - just returns a nastyogram to given user |
722 |
*/ |
723 |
void |
724 |
m_not_oper(struct Client *client_p, struct Client *source_p, |
725 |
int parc, char *parv[]) |
726 |
{ |
727 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
728 |
me.name, source_p->name); |
729 |
} |
730 |
|
731 |
void |
732 |
m_unregistered(struct Client *client_p, struct Client *source_p, |
733 |
int parc, char *parv[]) |
734 |
{ |
735 |
sendto_one(source_p, form_str(ERR_NOTREGISTERED), me.name, |
736 |
source_p->name[0] ? source_p->name : "*"); |
737 |
} |
738 |
|
739 |
void |
740 |
m_registered(struct Client *client_p, struct Client *source_p, |
741 |
int parc, char *parv[]) |
742 |
{ |
743 |
sendto_one(source_p, form_str(ERR_ALREADYREGISTRED), |
744 |
me.name, source_p->name); |
745 |
} |
746 |
|
747 |
void |
748 |
m_ignore(struct Client *client_p, struct Client *source_p, |
749 |
int parc, char *parv[]) |
750 |
{ |
751 |
return; |
752 |
} |
753 |
|
754 |
void |
755 |
rfc1459_command_send_error(struct Client *client_p, struct Client *source_p, |
756 |
int parc, char *parv[]) |
757 |
{ |
758 |
const char *in_para; |
759 |
|
760 |
in_para = (parc > 1 && *parv[1] != '\0') ? parv[1] : "<>"; |
761 |
|
762 |
ilog(LOG_TYPE_IRCD, "Received ERROR message from %s: %s", |
763 |
source_p->name, in_para); |
764 |
|
765 |
if (client_p == source_p) |
766 |
{ |
767 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
768 |
"ERROR :from %s -- %s", |
769 |
get_client_name(client_p, HIDE_IP), in_para); |
770 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
771 |
"ERROR :from %s -- %s", |
772 |
get_client_name(client_p, MASK_IP), in_para); |
773 |
} |
774 |
else |
775 |
{ |
776 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
777 |
"ERROR :from %s via %s -- %s", |
778 |
source_p->name, get_client_name(client_p, HIDE_IP), in_para); |
779 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
780 |
"ERROR :from %s via %s -- %s", |
781 |
source_p->name, get_client_name(client_p, MASK_IP), in_para); |
782 |
} |
783 |
|
784 |
if (MyClient(source_p)) |
785 |
exit_client(source_p, source_p, "ERROR"); |
786 |
} |