ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/core/m_server.c
Revision: 1474
Committed: Sun Jul 22 14:44:07 2012 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 21378 byte(s)
Log Message:
- removed &localchannels

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_server.c: Introduces a server.
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 "list.h"
27 #include "client.h" /* client struct */
28 #include "event.h"
29 #include "hash.h" /* add_to_client_hash_table */
30 #include "irc_string.h"
31 #include "ircd.h" /* me */
32 #include "numeric.h" /* ERR_xxx */
33 #include "conf.h" /* struct AccessItem */
34 #include "log.h" /* log level defines */
35 #include "s_serv.h" /* server_estab, check_server */
36 #include "s_user.h"
37 #include "send.h" /* sendto_one */
38 #include "parse.h"
39 #include "modules.h"
40
41
42 static void set_server_gecos(struct Client *, char *);
43
44 /* mr_server()
45 * parv[0] = sender prefix
46 * parv[1] = servername
47 * parv[2] = serverinfo/hopcount
48 * parv[3] = serverinfo
49 */
50 static void
51 mr_server(struct Client *client_p, struct Client *source_p,
52 int parc, char *parv[])
53 {
54 char info[REALLEN + 1];
55 char *name;
56 struct Client *target_p;
57 int hop;
58
59 if (EmptyString(parv[3]))
60 {
61 sendto_one(client_p, "ERROR :No servername");
62 exit_client(client_p, client_p, "Wrong number of args");
63 return;
64 }
65
66 name = parv[1];
67 hop = atoi(parv[2]);
68 strlcpy(info, parv[3], sizeof(info));
69
70 /*
71 * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo
72 */
73 if (!DoesTS(client_p))
74 {
75 sendto_realops_flags(UMODE_ALL, L_ADMIN,
76 "Unauthorized server connection attempt from %s: Non-TS server "
77 "for server %s", get_client_name(client_p, HIDE_IP), name);
78 sendto_realops_flags(UMODE_ALL, L_OPER,
79 "Unauthorized server connection attempt from %s: Non-TS server "
80 "for server %s", get_client_name(client_p, MASK_IP), name);
81 exit_client(client_p, client_p, "Non-TS server");
82 return;
83 }
84
85 if (!valid_servname(name))
86 {
87 sendto_realops_flags(UMODE_ALL, L_ADMIN,
88 "Unauthorized server connection attempt from %s: Bogus server name "
89 "for server %s", get_client_name(client_p, HIDE_IP), name);
90 sendto_realops_flags(UMODE_ALL, L_OPER,
91 "Unauthorized server connection attempt from %s: Bogus server name "
92 "for server %s", get_client_name(client_p, MASK_IP), name);
93 exit_client(client_p, client_p, "Bogus server name");
94 return;
95 }
96
97 /* Now we just have to call check_server and everything should
98 * be check for us... -A1kmm.
99 */
100 switch (check_server(name, client_p))
101 {
102 case -1:
103 if (ConfigFileEntry.warn_no_nline)
104 {
105 sendto_realops_flags(UMODE_ALL, L_ADMIN,
106 "Unauthorized server connection attempt from %s: No entry for "
107 "servername %s", get_client_name(client_p, HIDE_IP), name);
108
109 sendto_realops_flags(UMODE_ALL, L_OPER,
110 "Unauthorized server connection attempt from %s: No entry for "
111 "servername %s", get_client_name(client_p, MASK_IP), name);
112 }
113
114 exit_client(client_p, client_p, "Invalid servername.");
115 return;
116 /* NOT REACHED */
117 break;
118
119 case -2:
120 sendto_realops_flags(UMODE_ALL, L_ADMIN,
121 "Unauthorized server connection attempt from %s: Bad password "
122 "for server %s", get_client_name(client_p, HIDE_IP), name);
123
124 sendto_realops_flags(UMODE_ALL, L_OPER,
125 "Unauthorized server connection attempt from %s: Bad password "
126 "for server %s", get_client_name(client_p, MASK_IP), name);
127
128 exit_client(client_p, client_p, "Invalid password.");
129 return;
130 /* NOT REACHED */
131 break;
132
133 case -3:
134 sendto_realops_flags(UMODE_ALL, L_ADMIN,
135 "Unauthorized server connection attempt from %s: Invalid host "
136 "for server %s", get_client_name(client_p, HIDE_IP), name);
137
138 sendto_realops_flags(UMODE_ALL, L_OPER,
139 "Unauthorized server connection attempt from %s: Invalid host "
140 "for server %s", get_client_name(client_p, MASK_IP), name);
141
142 exit_client(client_p, client_p, "Invalid host.");
143 return;
144 /* NOT REACHED */
145 break;
146 }
147
148 if ((client_p->id[0] && (target_p = hash_find_id(client_p->id)))
149 || (target_p = hash_find_server(name)))
150 {
151 /* This link is trying feed me a server that I already have
152 * access through another path -- multiple paths not accepted
153 * currently, kill this link immediately!!
154 *
155 * Rather than KILL the link which introduced it, KILL the
156 * youngest of the two links. -avalon
157 *
158 * Definitely don't do that here. This is from an unregistered
159 * connect - A1kmm.
160 */
161 sendto_realops_flags(UMODE_ALL, L_ADMIN,
162 "Attempt to re-introduce server %s SID %s from %s",
163 name, client_p->id,
164 get_client_name(client_p, HIDE_IP));
165 sendto_realops_flags(UMODE_ALL, L_OPER,
166 "Attempt to re-introduce server %s SID %s from %s",
167 name, client_p->id,
168 get_client_name(client_p, MASK_IP));
169 sendto_one(client_p, "ERROR :Server ID already exists.");
170 exit_client(client_p, client_p, "Server ID Exists");
171 return;
172 }
173
174 /* XXX If somehow there is a connect in progress and
175 * a connect comes in with same name toss the pending one,
176 * but only if it's not the same client! - Dianora
177 */
178 if ((target_p = find_servconn_in_progress(name)))
179 if (target_p != client_p)
180 exit_client(target_p, &me, "Overridden");
181
182 /* if we are connecting (Handshake), we already have the name from the
183 * connect{} block in client_p->name
184 */
185 strlcpy(client_p->name, name, sizeof(client_p->name));
186 set_server_gecos(client_p, info);
187 client_p->hopcount = hop;
188 server_estab(client_p);
189 }
190
191 /* ms_server()
192 * parv[0] = sender prefix
193 * parv[1] = servername
194 * parv[2] = serverinfo/hopcount
195 * parv[3] = serverinfo
196 */
197 static void
198 ms_server(struct Client *client_p, struct Client *source_p,
199 int parc, char *parv[])
200 {
201 char info[REALLEN + 1];
202 char *name;
203 struct Client *target_p;
204 struct AccessItem *aconf;
205 int hop;
206 int hlined = 0;
207 int llined = 0;
208 dlink_node *ptr = NULL;
209
210 /* Just to be sure -A1kmm. */
211 if (!IsServer(source_p))
212 return;
213
214 if (EmptyString(parv[3]))
215 {
216 sendto_one(client_p, "ERROR :No servername");
217 return;
218 }
219
220 name = parv[1];
221 hop = atoi(parv[2]);
222 strlcpy(info, parv[3], sizeof(info));
223
224 if (!valid_servname(name))
225 {
226 sendto_realops_flags(UMODE_ALL, L_ADMIN,
227 "Link %s introduced server with bogus server name %s",
228 get_client_name(client_p, SHOW_IP), name);
229 sendto_realops_flags(UMODE_ALL, L_OPER,
230 "Link %s introduced server with bogus server name %s",
231 get_client_name(client_p, MASK_IP), name);
232 sendto_one(client_p, "ERROR :Bogus server name introduced");
233 exit_client(client_p, &me, "Bogus server name intoduced");
234 return;
235 }
236
237 if ((target_p = hash_find_server(name)))
238 {
239 /* This link is trying feed me a server that I already have
240 * access through another path -- multiple paths not accepted
241 * currently, kill this link immediately!!
242 *
243 * Rather than KILL the link which introduced it, KILL the
244 * youngest of the two links. -avalon
245 *
246 * I think that we should exit the link itself, not the introducer,
247 * and we should always exit the most recently received(i.e. the
248 * one we are receiving this SERVER for. -A1kmm
249 *
250 * You *cant* do this, if you link somewhere, it bursts you a server
251 * that already exists, then sends you a client burst, you squit the
252 * server, but you keep getting the burst of clients on a server that
253 * doesnt exist, although ircd can handle it, its not a realistic
254 * solution.. --fl_
255 */
256 /* It is behind a host-masked server. Completely ignore the
257 * server message(don't propagate or we will delink from whoever
258 * we propagate to). -A1kmm
259 */
260 if (irccmp(target_p->name, name) && target_p->from == client_p)
261 return;
262
263 sendto_one(client_p, "ERROR :Server %s already exists", name);
264 sendto_realops_flags(UMODE_ALL, L_ADMIN,
265 "Link %s cancelled, server %s already exists",
266 get_client_name(client_p, SHOW_IP), name);
267 sendto_realops_flags(UMODE_ALL, L_OPER,
268 "Link %s cancelled, server %s already exists",
269 client_p->name, name);
270 exit_client(client_p, &me, "Server Exists");
271 return;
272 }
273
274 /* XXX If somehow there is a connect in progress and
275 * a connect comes in with same name toss the pending one,
276 * but only if it's not the same client! - Dianora
277 */
278 if ((target_p = find_servconn_in_progress(name)))
279 if (target_p != client_p)
280 exit_client(target_p, &me, "Overridden");
281
282 aconf = map_to_conf(client_p->localClient->confs.head->data);
283
284 /* See if the newly found server is behind a guaranteed
285 * leaf. If so, close the link.
286 */
287 DLINK_FOREACH(ptr, aconf->leaf_list.head)
288 if (match(ptr->data, name))
289 ++llined;
290
291 DLINK_FOREACH(ptr, aconf->hub_list.head)
292 if (match(ptr->data, name))
293 ++hlined;
294
295 /* Ok, this way this works is
296 *
297 * A server can have a CONF_HUB allowing it to introduce servers
298 * behind it.
299 *
300 * connect {
301 * name = "irc.bighub.net";
302 * hub_mask="*";
303 * ...
304 *
305 * That would allow "irc.bighub.net" to introduce anything it wanted..
306 *
307 * However
308 *
309 * connect {
310 * name = "irc.somehub.fi";
311 * hub_mask="*";
312 * leaf_mask="*.edu";
313 *...
314 * Would allow this server in finland to hub anything but
315 * .edu's
316 */
317
318 /* Ok, check client_p can hub the new server */
319 if (!hlined)
320 {
321 /* OOOPs nope can't HUB */
322 sendto_realops_flags(UMODE_ALL, L_ADMIN, "Non-Hub link %s introduced %s.",
323 get_client_name(client_p, HIDE_IP), name);
324 sendto_realops_flags(UMODE_ALL, L_OPER, "Non-Hub link %s introduced %s.",
325 get_client_name(client_p, MASK_IP), name);
326 exit_client(source_p, &me, "No matching hub_mask.");
327 return;
328 }
329
330 /* Check for the new server being leafed behind this HUB */
331 if (llined)
332 {
333 /* OOOPs nope can't HUB this leaf */
334 sendto_realops_flags(UMODE_ALL, L_ADMIN,
335 "Link %s introduced leafed server %s.",
336 get_client_name(client_p, HIDE_IP), name);
337 sendto_realops_flags(UMODE_ALL, L_OPER,
338 "Link %s introduced leafed server %s.",
339 get_client_name(client_p, MASK_IP), name);
340 /* If it is new, we are probably misconfigured, so split the
341 * non-hub server introducing this. Otherwise, split the new
342 * server. -A1kmm.
343 */
344 /* wastes too much bandwidth, generates too many errors on
345 * larger networks, dont bother. --fl_
346 */
347 exit_client(client_p, &me, "Leafed Server.");
348 return;
349 }
350
351 target_p = make_client(client_p);
352 make_server(target_p);
353 target_p->hopcount = hop;
354 target_p->servptr = source_p;
355
356 strlcpy(target_p->name, name, sizeof(target_p->name));
357
358 set_server_gecos(target_p, info);
359 SetServer(target_p);
360
361 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(SERVICE_TYPE, target_p->name, NULL, NULL, 0))
362 AddFlag(target_p, FLAGS_SERVICE);
363
364 dlinkAdd(target_p, &target_p->node, &global_client_list);
365 dlinkAdd(target_p, make_dlink_node(), &global_serv_list);
366 dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list);
367
368 hash_add_client(target_p);
369
370 sendto_server(client_p, NOCAPS, NOCAPS, ":%s SERVER %s %d :%s%s",
371 source_p->name, target_p->name, hop + 1,
372 IsHidden(target_p) ? "(H) " : "", target_p->info);
373
374 sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
375 "Server %s being introduced by %s",
376 target_p->name, source_p->name);
377 }
378
379 /* ms_sid()
380 * parv[0] = sender prefix
381 * parv[1] = servername
382 * parv[2] = serverinfo/hopcount
383 * parv[3] = sid of new server
384 * parv[4] = serverinfo
385 */
386 static void
387 ms_sid(struct Client *client_p, struct Client *source_p,
388 int parc, char *parv[])
389 {
390 char info[REALLEN + 1];
391 struct Client *target_p;
392 struct AccessItem *aconf = NULL;
393 int hlined = 0;
394 int llined = 0;
395 dlink_node *ptr = NULL;
396 int hop;
397
398 /* Just to be sure -A1kmm. */
399 if (!IsServer(source_p))
400 return;
401
402 if (EmptyString(parv[4]))
403 {
404 sendto_one(client_p, "ERROR :No servername");
405 return;
406 }
407
408 hop = atoi(parv[2]);
409 strlcpy(info, parv[4], sizeof(info));
410
411 if (!valid_servname(parv[1]))
412 {
413 sendto_realops_flags(UMODE_ALL, L_ADMIN,
414 "Link %s introduced server with bogus server name %s",
415 get_client_name(client_p, SHOW_IP), parv[1]);
416 sendto_realops_flags(UMODE_ALL, L_OPER,
417 "Link %s introduced server with bogus server name %s",
418 get_client_name(client_p, MASK_IP), parv[1]);
419 sendto_one(client_p, "ERROR :Bogus server name introduced");
420 exit_client(client_p, &me, "Bogus server name intoduced");
421 return;
422 }
423
424 if (!valid_sid(parv[3]))
425 {
426 sendto_realops_flags(UMODE_ALL, L_ADMIN,
427 "Link %s introduced server with bogus server ID %s",
428 get_client_name(client_p, SHOW_IP), parv[3]);
429 sendto_realops_flags(UMODE_ALL, L_OPER,
430 "Link %s introduced server with bogus server ID %s",
431 get_client_name(client_p, MASK_IP), parv[3]);
432 sendto_one(client_p, "ERROR :Bogus server ID introduced");
433 exit_client(client_p, &me, "Bogus server ID intoduced");
434 return;
435 }
436
437 /* collision on SID? */
438 if ((target_p = hash_find_id(parv[3])))
439 {
440 sendto_one(client_p, "ERROR :SID %s already exists", parv[3]);
441 sendto_realops_flags(UMODE_ALL, L_ADMIN,
442 "Link %s cancelled, SID %s already exists",
443 get_client_name(client_p, SHOW_IP), parv[3]);
444 sendto_realops_flags(UMODE_ALL, L_OPER,
445 "Link %s cancelled, SID %s already exists",
446 client_p->name, parv[3]);
447 exit_client(client_p, &me, "Server Exists");
448 return;
449 }
450
451 /* collision on name? */
452 if ((target_p = hash_find_server(parv[1])))
453 {
454 sendto_one(client_p, "ERROR :Server %s already exists", parv[1]);
455 sendto_realops_flags(UMODE_ALL, L_ADMIN,
456 "Link %s cancelled, server %s already exists",
457 get_client_name(client_p, SHOW_IP), parv[1]);
458 sendto_realops_flags(UMODE_ALL, L_OPER,
459 "Link %s cancelled, server %s already exists",
460 client_p->name, parv[1]);
461 exit_client(client_p, &me, "Server Exists");
462 return;
463 }
464
465 /* XXX If somehow there is a connect in progress and
466 * a connect comes in with same name toss the pending one,
467 * but only if it's not the same client! - Dianora
468 */
469 if ((target_p = find_servconn_in_progress(parv[1])))
470 if (target_p != client_p)
471 exit_client(target_p, &me, "Overridden");
472
473 aconf = map_to_conf(client_p->localClient->confs.head->data);
474
475 /* See if the newly found server is behind a guaranteed
476 * leaf. If so, close the link.
477 */
478 DLINK_FOREACH(ptr, aconf->leaf_list.head)
479 if (match(ptr->data, parv[1]))
480 ++llined;
481
482 DLINK_FOREACH(ptr, aconf->hub_list.head)
483 if (match(ptr->data, parv[1]))
484 ++hlined;
485
486
487 /* Ok, this way this works is
488 *
489 * A server can have a CONF_HUB allowing it to introduce servers
490 * behind it.
491 *
492 * connect {
493 * name = "irc.bighub.net";
494 * hub_mask="*";
495 * ...
496 *
497 * That would allow "irc.bighub.net" to introduce anything it wanted..
498 *
499 * However
500 *
501 * connect {
502 * name = "irc.somehub.fi";
503 * hub_mask="*";
504 * leaf_mask="*.edu";
505 *...
506 * Would allow this server in finland to hub anything but
507 * .edu's
508 */
509
510 /* Ok, check client_p can hub the new server, and make sure it's not a LL */
511 if (!hlined)
512 {
513 /* OOOPs nope can't HUB */
514 sendto_realops_flags(UMODE_ALL, L_ADMIN, "Non-Hub link %s introduced %s.",
515 get_client_name(client_p, SHOW_IP), parv[1]);
516 sendto_realops_flags(UMODE_ALL, L_OPER, "Non-Hub link %s introduced %s.",
517 get_client_name(client_p, MASK_IP), parv[1]);
518 exit_client(source_p, &me, "No matching hub_mask.");
519 return;
520 }
521
522 /* Check for the new server being leafed behind this HUB */
523 if (llined)
524 {
525 /* OOOPs nope can't HUB this leaf */
526 sendto_realops_flags(UMODE_ALL, L_ADMIN,
527 "Link %s introduced leafed server %s.",
528 get_client_name(client_p, SHOW_IP), parv[1]);
529 sendto_realops_flags(UMODE_ALL, L_OPER,
530 "Link %s introduced leafed server %s.",
531 get_client_name(client_p, MASK_IP), parv[1]);
532 exit_client(client_p, &me, "Leafed Server.");
533 return;
534 }
535
536 target_p = make_client(client_p);
537 make_server(target_p);
538 target_p->hopcount = hop;
539 target_p->servptr = source_p;
540
541 strlcpy(target_p->name, parv[1], sizeof(target_p->name));
542 strlcpy(target_p->id, parv[3], sizeof(target_p->id));
543
544 set_server_gecos(target_p, info);
545 SetServer(target_p);
546
547 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(SERVICE_TYPE, target_p->name, NULL, NULL, 0))
548 AddFlag(target_p, FLAGS_SERVICE);
549
550 dlinkAdd(target_p, &target_p->node, &global_client_list);
551 dlinkAdd(target_p, make_dlink_node(), &global_serv_list);
552 dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list);
553
554 hash_add_client(target_p);
555 hash_add_id(target_p);
556
557 sendto_server(client_p, CAP_TS6, NOCAPS, ":%s SID %s %d %s :%s%s",
558 ID_or_name(source_p, client_p), target_p->name, hop + 1,
559 IsHidden(target_p) ? "(H) " : "", target_p->info);
560 sendto_server(client_p, NOCAPS, CAP_TS6, ":%s SERVER %s %d :%s%s",
561 source_p->name, target_p->name, hop + 1,
562 IsHidden(target_p) ? "(H) " : "", target_p->info);
563
564 sendto_realops_flags(UMODE_EXTERNAL, L_ALL,
565 "Server %s being introduced by %s",
566 target_p->name, source_p->name);
567 }
568
569 /* set_server_gecos()
570 *
571 * input - pointer to client
572 * output - NONE
573 * side effects - servers gecos field is set
574 */
575 static void
576 set_server_gecos(struct Client *client_p, char *info)
577 {
578 /* check the info for [IP] */
579 if (info[0])
580 {
581 char *p;
582 char *s;
583 char *t;
584
585 s = info;
586
587 /* we should only check the first word for an ip */
588 if ((p = strchr(s, ' ')) != NULL)
589 *p = '\0';
590
591 /* check for a ] which would symbolise an [IP] */
592 if ((t = strchr(s, ']')) != NULL)
593 {
594 /* set s to after the first space */
595 if (p)
596 s = ++p;
597 else
598 s = NULL;
599 }
600 /* no ], put the space back */
601 else if (p)
602 *p = ' ';
603
604 /* p may have been set to a trailing space, so check s exists and that
605 * it isnt \0 */
606 if (s && (*s != '\0'))
607 {
608 /* a space? if not (H) could be the last part of info.. */
609 if ((p = strchr(s, ' ')))
610 *p = '\0';
611
612 /* check for (H) which is a hidden server */
613 if (!strcmp(s, "(H)"))
614 {
615 SetHidden(client_p);
616
617 /* if there was no space.. theres nothing to set info to */
618 if (p)
619 s = ++p;
620 else
621 s = NULL;
622 }
623 else if (p)
624 *p = ' ';
625
626 /* if there was a trailing space, s could point to \0, so check */
627 if (s && (*s != '\0'))
628 strlcpy(client_p->info, s, sizeof(client_p->info));
629 else
630 strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info));
631 }
632 else
633 strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info));
634 }
635 else
636 strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info));
637 }
638
639 static struct Message server_msgtab = {
640 "SERVER", 0, 0, 4, MAXPARA, MFLG_SLOW | MFLG_UNREG, 0,
641 {mr_server, m_registered, ms_server, m_ignore, m_registered, m_ignore}
642 };
643
644 static struct Message sid_msgtab = {
645 "SID", 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
646 {rfc1459_command_send_error, m_ignore, ms_sid, m_ignore, m_ignore, m_ignore}
647 };
648
649 static void
650 module_init(void)
651 {
652 mod_add_cmd(&sid_msgtab);
653 mod_add_cmd(&server_msgtab);
654 }
655
656 static void
657 module_exit(void)
658 {
659 mod_del_cmd(&sid_msgtab);
660 mod_del_cmd(&server_msgtab);
661 }
662
663 struct module module_entry = {
664 .node = { NULL, NULL, NULL },
665 .name = NULL,
666 .version = "$Revision$",
667 .handle = NULL,
668 .modinit = module_init,
669 .modexit = module_exit,
670 .flags = MODULE_FLAG_CORE
671 };

Properties

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