/[svn]/ircd-hybrid/trunk/modules/core/m_server.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/modules/core/m_server.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4612 - (show annotations)
Tue Sep 2 08:55:13 2014 UTC (7 years, 11 months ago) by michael
File MIME type: text/x-chdr
File size: 27390 byte(s)
- m_server.c:server_estab(): since we no longer put connecting/unknown servers on the local_server_list,
  we can simplify that "I'm no hub, I'm not allowed to link" test.

1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 * USA
20 */
21
22 /*! \file m_server.c
23 * \brief Includes required functions for processing the SERVER/SID command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "client.h"
30 #include "event.h"
31 #include "hash.h"
32 #include "irc_string.h"
33 #include "ircd.h"
34 #include "numeric.h"
35 #include "conf.h"
36 #include "log.h"
37 #include "misc.h"
38 #include "server.h"
39 #include "user.h"
40 #include "send.h"
41 #include "parse.h"
42 #include "memory.h"
43 #include "modules.h"
44
45
46 /*
47 * send_tb
48 *
49 * inputs - pointer to Client
50 * - pointer to channel
51 * output - NONE
52 * side effects - Called on a server burst when
53 * server is CAP_TBURST capable
54 */
55 static void
56 send_tb(struct Client *client_p, struct Channel *chptr)
57 {
58 /*
59 * We may also send an empty topic here, but only if topic_time isn't 0,
60 * i.e. if we had a topic that got unset. This is required for syncing
61 * topics properly.
62 *
63 * Imagine the following scenario: Our downlink introduces a channel
64 * to us with a TS that is equal to ours, but the channel topic on
65 * their side got unset while the servers were in splitmode, which means
66 * their 'topic' is newer. They simply wanted to unset it, so we have to
67 * deal with it in a more sophisticated fashion instead of just resetting
68 * it to their old topic they had before. Read m_tburst.c:ms_tburst
69 * for further information -Michael
70 */
71 if (chptr->topic_time)
72 sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s", me.id,
73 (unsigned long)chptr->channelts, chptr->chname,
74 (unsigned long)chptr->topic_time,
75 chptr->topic_info,
76 chptr->topic);
77 }
78
79 /* sendnick_TS()
80 *
81 * inputs - client (server) to send nick towards
82 * - client to send nick for
83 * output - NONE
84 * side effects - NICK message is sent towards given client_p
85 */
86 static void
87 sendnick_TS(struct Client *client_p, struct Client *target_p)
88 {
89 char ubuf[IRCD_BUFSIZE] = "";
90
91 if (!IsClient(target_p))
92 return;
93
94 send_umode(NULL, target_p, 0, ubuf);
95
96 if (ubuf[0] == '\0')
97 {
98 ubuf[0] = '+';
99 ubuf[1] = '\0';
100 }
101
102 if (IsCapable(client_p, CAP_SVS))
103 sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s %s :%s",
104 target_p->servptr->id,
105 target_p->name, target_p->hopcount + 1,
106 (unsigned long) target_p->tsinfo,
107 ubuf, target_p->username, target_p->host,
108 (MyClient(target_p) && IsIPSpoof(target_p)) ?
109 "0" : target_p->sockhost, target_p->id,
110 target_p->svid, target_p->info);
111 else
112 sendto_one(client_p, ":%s UID %s %d %lu %s %s %s %s %s :%s",
113 target_p->servptr->id,
114 target_p->name, target_p->hopcount + 1,
115 (unsigned long) target_p->tsinfo,
116 ubuf, target_p->username, target_p->host,
117 (MyClient(target_p) && IsIPSpoof(target_p)) ?
118 "0" : target_p->sockhost, target_p->id, target_p->info);
119
120 if (!EmptyString(target_p->certfp))
121 sendto_one(client_p, ":%s CERTFP %s", target_p->id, target_p->certfp);
122
123 if (target_p->away[0])
124 sendto_one(client_p, ":%s AWAY :%s", target_p->id, target_p->away);
125
126 }
127
128 /* burst_members()
129 *
130 * inputs - pointer to server to send members to
131 * - dlink_list pointer to membership list to send
132 * output - NONE
133 * side effects -
134 */
135 static void
136 burst_members(struct Client *client_p, struct Channel *chptr)
137 {
138 struct Client *target_p;
139 struct Membership *ms;
140 dlink_node *ptr;
141
142 DLINK_FOREACH(ptr, chptr->members.head)
143 {
144 ms = ptr->data;
145 target_p = ms->client_p;
146
147 if (!HasFlag(target_p, FLAGS_BURSTED))
148 {
149 AddFlag(target_p, FLAGS_BURSTED);
150
151 if (target_p->from != client_p)
152 sendnick_TS(client_p, target_p);
153 }
154 }
155 }
156
157 /* burst_all()
158 *
159 * inputs - pointer to server to send burst to
160 * output - NONE
161 * side effects - complete burst of channels/nicks is sent to client_p
162 */
163 static void
164 burst_all(struct Client *client_p)
165 {
166 dlink_node *ptr = NULL;
167
168 DLINK_FOREACH(ptr, channel_list.head)
169 {
170 struct Channel *chptr = ptr->data;
171
172 if (dlink_list_length(&chptr->members))
173 {
174 burst_members(client_p, chptr);
175 send_channel_modes(client_p, chptr);
176
177 if (IsCapable(client_p, CAP_TBURST))
178 send_tb(client_p, chptr);
179 }
180 }
181
182 /* also send out those that are not on any channel
183 */
184 DLINK_FOREACH(ptr, global_client_list.head)
185 {
186 struct Client *target_p = ptr->data;
187
188 if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
189 sendnick_TS(client_p, target_p);
190
191 DelFlag(target_p, FLAGS_BURSTED);
192 }
193
194 if (IsCapable(client_p, CAP_EOB))
195 sendto_one(client_p, ":%s EOB", me.id);
196 }
197
198 /* server_burst()
199 *
200 * inputs - struct Client pointer server
201 * -
202 * output - none
203 * side effects - send a server burst
204 * bugs - still too long
205 */
206 static void
207 server_burst(struct Client *client_p)
208 {
209 /* Send it in the shortened format with the TS, if
210 ** it's a TS server; walk the list of channels, sending
211 ** all the nicks that haven't been sent yet for each
212 ** channel, then send the channel itself -- it's less
213 ** obvious than sending all nicks first, but on the
214 ** receiving side memory will be allocated more nicely
215 ** saving a few seconds in the handling of a split
216 ** -orabidoo
217 */
218
219 burst_all(client_p);
220
221 /* EOB stuff is now in burst_all */
222 /* Always send a PING after connect burst is done */
223 sendto_one(client_p, "PING :%s", me.id);
224 }
225
226 /* server_estab()
227 *
228 * inputs - pointer to a struct Client
229 * output -
230 * side effects -
231 */
232 static void
233 server_estab(struct Client *client_p)
234 {
235 struct MaskItem *conf = NULL;
236 dlink_node *ptr;
237 #if defined(HAVE_LIBCRYPTO) && !defined(OPENSSL_NO_COMP)
238 const COMP_METHOD *compression = NULL, *expansion = NULL;
239 #endif
240
241 assert(client_p);
242
243 if ((conf = find_conf_name(&client_p->connection->confs, client_p->name, CONF_SERVER))
244 == NULL)
245 {
246 /* This shouldn't happen, better tell the ops... -A1kmm */
247 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
248 "Warning: Lost connect{} block "
249 "for server %s(this shouldn't happen)!", client_p->name);
250 exit_client(client_p, "Lost connect{} block!");
251 return;
252 }
253
254 MyFree(client_p->connection->password);
255 client_p->connection->password = NULL;
256
257 if (!ConfigServerInfo.hub && dlink_list_length(&local_server_list))
258 {
259 ++ServerStats.is_ref;
260 exit_client(client_p, "I'm a leaf not a hub");
261 return;
262 }
263
264 if (IsUnknown(client_p))
265 {
266 sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
267
268 send_capabilities(client_p, 0);
269
270 sendto_one(client_p, "SERVER %s 1 :%s%s",
271 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
272 }
273
274 sendto_one(client_p, ":%s SVINFO %d %d 0 :%lu", me.id, TS_CURRENT, TS_MIN,
275 (unsigned long)CurrentTime);
276
277 /* XXX Does this ever happen? I don't think so -db */
278 detach_conf(client_p, CONF_OPER);
279
280 /* *WARNING*
281 ** In the following code in place of plain server's
282 ** name we send what is returned by get_client_name
283 ** which may add the "sockhost" after the name. It's
284 ** *very* *important* that there is a SPACE between
285 ** the name and sockhost (if present). The receiving
286 ** server will start the information field from this
287 ** first blank and thus puts the sockhost into info.
288 ** ...a bit tricky, but you have been warned, besides
289 ** code is more neat this way... --msa
290 */
291 client_p->servptr = &me;
292
293 if (IsClosing(client_p))
294 return;
295
296 SetServer(client_p);
297
298 /* Some day, all these lists will be consolidated *sigh* */
299 dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list);
300
301 assert(dlinkFind(&unknown_list, client_p));
302
303 dlink_move_node(&client_p->connection->lclient_node,
304 &unknown_list, &local_server_list);
305
306 Count.myserver++;
307
308 dlinkAdd(client_p, &client_p->node, &global_client_list);
309 dlinkAdd(client_p, make_dlink_node(), &global_server_list);
310 hash_add_client(client_p);
311 hash_add_id(client_p);
312
313 /* Doesn't duplicate client_p->serv if allocated this struct already */
314 make_server(client_p);
315
316 /* Fixing eob timings.. -gnp */
317 client_p->connection->firsttime = CurrentTime;
318
319 if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
320 AddFlag(client_p, FLAGS_SERVICE);
321
322 /* Show the real host/IP to admins */
323 #ifdef HAVE_LIBCRYPTO
324 if (client_p->connection->fd.ssl)
325 {
326 #ifndef OPENSSL_NO_COMP
327 compression = SSL_get_current_compression(client_p->connection->fd.ssl);
328 expansion = SSL_get_current_expansion(client_p->connection->fd.ssl);
329 #endif
330 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
331 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
332 get_client_name(client_p, SHOW_IP), ssl_get_cipher(client_p->connection->fd.ssl),
333 #ifndef OPENSSL_NO_COMP
334 compression ? SSL_COMP_get_name(compression) : "NONE",
335 expansion ? SSL_COMP_get_name(expansion) : "NONE",
336 #else
337 "NONE", "NONE",
338 #endif
339 show_capabilities(client_p));
340 /* Now show the masked hostname/IP to opers */
341 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
342 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
343 get_client_name(client_p, MASK_IP), ssl_get_cipher(client_p->connection->fd.ssl),
344 #ifndef OPENSSL_NO_COMP
345 compression ? SSL_COMP_get_name(compression) : "NONE",
346 expansion ? SSL_COMP_get_name(expansion) : "NONE",
347 #else
348 "NONE", "NONE",
349 #endif
350 show_capabilities(client_p));
351 ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
352 get_client_name(client_p, SHOW_IP), ssl_get_cipher(client_p->connection->fd.ssl),
353 #ifndef OPENSSL_NO_COMP
354 compression ? SSL_COMP_get_name(compression) : "NONE",
355 expansion ? SSL_COMP_get_name(expansion) : "NONE",
356 #else
357 "NONE", "NONE",
358 #endif
359 show_capabilities(client_p));
360 }
361 else
362 #endif
363 {
364 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
365 "Link with %s established: (Capabilities: %s)",
366 get_client_name(client_p, SHOW_IP), show_capabilities(client_p));
367 /* Now show the masked hostname/IP to opers */
368 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
369 "Link with %s established: (Capabilities: %s)",
370 get_client_name(client_p, MASK_IP), show_capabilities(client_p));
371 ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)",
372 get_client_name(client_p, SHOW_IP), show_capabilities(client_p));
373 }
374
375 fd_note(&client_p->connection->fd, "Server: %s", client_p->name);
376
377 sendto_server(client_p, NOCAPS, NOCAPS, ":%s SID %s 2 %s :%s%s",
378 me.id, client_p->name, client_p->id,
379 IsHidden(client_p) ? "(H) " : "", client_p->info);
380
381 /*
382 * Pass on my client information to the new server
383 *
384 * First, pass only servers (idea is that if the link gets
385 * cancelled beacause the server was already there,
386 * there are no NICK's to be cancelled...). Of course,
387 * if cancellation occurs, all this info is sent anyway,
388 * and I guess the link dies when a read is attempted...? --msa
389 *
390 * Note: Link cancellation to occur at this point means
391 * that at least two servers from my fragment are building
392 * up connection this other fragment at the same time, it's
393 * a race condition, not the normal way of operation...
394 *
395 * ALSO NOTE: using the get_client_name for server names--
396 * see previous *WARNING*!!! (Also, original inpath
397 * is destroyed...)
398 */
399 DLINK_FOREACH_PREV(ptr, global_server_list.tail)
400 {
401 struct Client *target_p = ptr->data;
402
403 /* target_p->from == target_p for target_p == client_p */
404 if (IsMe(target_p) || target_p->from == client_p)
405 continue;
406
407 sendto_one(client_p, ":%s SID %s %d %s :%s%s",
408 target_p->servptr->id, target_p->name, target_p->hopcount+1,
409 target_p->id, IsHidden(target_p) ? "(H) " : "",
410 target_p->info);
411 }
412
413 server_burst(client_p);
414 }
415
416 /* set_server_gecos()
417 *
418 * input - pointer to client
419 * output - NONE
420 * side effects - servers gecos field is set
421 */
422 static void
423 set_server_gecos(struct Client *client_p, const char *info)
424 {
425 const char *s = info;
426
427 /* check for (H) which is a hidden server */
428 if (!strncmp(s, "(H) ", 4))
429 {
430 SetHidden(client_p);
431 s = s + 4;
432 }
433
434 if (!EmptyString(s))
435 strlcpy(client_p->info, s, sizeof(client_p->info));
436 else
437 strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info));
438 }
439
440 /* mr_server()
441 * parv[0] = command
442 * parv[1] = servername
443 * parv[2] = hopcount
444 * parv[3] = serverinfo
445 */
446 static int
447 mr_server(struct Client *source_p, int parc, char *parv[])
448 {
449 char *name = NULL;
450 struct Client *target_p = NULL;
451
452 if (EmptyString(parv[3]))
453 {
454 exit_client(source_p, "No server description supplied");
455 return 0;
456 }
457
458 name = parv[1];
459
460 /*
461 * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo
462 */
463 if (!DoesTS(source_p))
464 {
465 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
466 "Unauthorized server connection attempt from %s: Non-TS server "
467 "for server %s", get_client_name(source_p, HIDE_IP), name);
468 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
469 "Unauthorized server connection attempt from %s: Non-TS server "
470 "for server %s", get_client_name(source_p, MASK_IP), name);
471 exit_client(source_p, "Non-TS server");
472 return 0;
473 }
474
475 if (!valid_servname(name))
476 {
477 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
478 "Unauthorized server connection attempt from %s: Bogus server name "
479 "for server %s", get_client_name(source_p, HIDE_IP), name);
480 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
481 "Unauthorized server connection attempt from %s: Bogus server name "
482 "for server %s", get_client_name(source_p, MASK_IP), name);
483 exit_client(source_p, "Bogus server name");
484 return 0;
485 }
486
487 if (!valid_sid(source_p->id))
488 {
489 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
490 "Link %s introduced server with bogus server ID %s",
491 get_client_name(source_p, SHOW_IP), source_p->id);
492 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
493 "Link %s introduced server with bogus server ID %s",
494 get_client_name(source_p, MASK_IP), source_p->id);
495 exit_client(source_p, "Bogus server ID introduced");
496 return 0;
497 }
498
499 /* Now we just have to call check_server and everything should
500 * be check for us... -A1kmm.
501 */
502 switch (check_server(name, source_p))
503 {
504 case -1:
505 if (ConfigGeneral.warn_no_connect_block)
506 {
507 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
508 "Unauthorized server connection attempt from %s: No entry for "
509 "servername %s", get_client_name(source_p, HIDE_IP), name);
510
511 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
512 "Unauthorized server connection attempt from %s: No entry for "
513 "servername %s", get_client_name(source_p, MASK_IP), name);
514 }
515
516 exit_client(source_p, "No connect {} block.");
517 return 0;
518 /* NOT REACHED */
519 break;
520
521 case -2:
522 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
523 "Unauthorized server connection attempt from %s: Bad password "
524 "for server %s", get_client_name(source_p, HIDE_IP), name);
525
526 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
527 "Unauthorized server connection attempt from %s: Bad password "
528 "for server %s", get_client_name(source_p, MASK_IP), name);
529
530 exit_client(source_p, "Invalid password.");
531 return 0;
532 /* NOT REACHED */
533 break;
534
535 case -3:
536 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
537 "Unauthorized server connection attempt from %s: Invalid host "
538 "for server %s", get_client_name(source_p, HIDE_IP), name);
539
540 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
541 "Unauthorized server connection attempt from %s: Invalid host "
542 "for server %s", get_client_name(source_p, MASK_IP), name);
543
544 exit_client(source_p, "Invalid host.");
545 return 0;
546 case -4:
547 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
548 "Unauthorized server connection attempt from %s: Invalid certificate fingerprint "
549 "for server %s", get_client_name(source_p, HIDE_IP), name);
550
551 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
552 "Unauthorized server connection attempt from %s: Invalid certificate fingerprint "
553 "for server %s", get_client_name(source_p, MASK_IP), name);
554
555 exit_client(source_p, "Invalid certificate fingerprint.");
556 return 0;
557 /* NOT REACHED */
558 break;
559 }
560
561 if ((target_p = hash_find_server(name)))
562 {
563 /* This link is trying feed me a server that I already have
564 * access through another path -- multiple paths not accepted
565 * currently, kill this link immediately!!
566 *
567 * Rather than KILL the link which introduced it, KILL the
568 * youngest of the two links. -avalon
569 *
570 * Definitely don't do that here. This is from an unregistered
571 * connect - A1kmm.
572 */
573 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
574 "Attempt to re-introduce server %s from %s",
575 name, get_client_name(source_p, HIDE_IP));
576 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
577 "Attempt to re-introduce server %s from %s",
578 name, get_client_name(source_p, MASK_IP));
579 exit_client(source_p, "Server already exists");
580 return 0;
581 }
582
583 if ((target_p = hash_find_id(source_p->id)))
584 {
585 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
586 "Attempt to re-introduce server %s SID %s from %s",
587 name, source_p->id,
588 get_client_name(source_p, HIDE_IP));
589 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
590 "Attempt to re-introduce server %s SID %s from %s",
591 name, source_p->id,
592 get_client_name(source_p, MASK_IP));
593 exit_client(source_p, "Server ID already exists");
594 return 0;
595 }
596
597 /* XXX If somehow there is a connect in progress and
598 * a connect comes in with same name toss the pending one,
599 * but only if it's not the same client! - Dianora
600 */
601 if ((target_p = find_servconn_in_progress(name)))
602 if (target_p != source_p)
603 exit_client(target_p, "Overridden");
604
605 /* if we are connecting (Handshake), we already have the name from the
606 * connect{} block in source_p->name
607 */
608 strlcpy(source_p->name, name, sizeof(source_p->name));
609 set_server_gecos(source_p, parv[3]);
610 source_p->hopcount = atoi(parv[2]);
611 server_estab(source_p);
612 return 0;
613 }
614
615 /* ms_sid()
616 * parv[0] = command
617 * parv[1] = servername
618 * parv[2] = hopcount
619 * parv[3] = sid of new server
620 * parv[4] = serverinfo
621 */
622 static int
623 ms_sid(struct Client *source_p, int parc, char *parv[])
624 {
625 dlink_node *ptr = NULL;
626 struct Client *target_p = NULL;
627 struct Client *client_p = source_p->from; /* XXX */
628 const struct MaskItem *conf = NULL;
629 int hlined = 0;
630 int llined = 0;
631
632 /* Just to be sure -A1kmm. */
633 if (!IsServer(source_p))
634 return 0;
635
636 if (EmptyString(parv[4]))
637 {
638 exit_client(client_p, "No server description supplied");
639 return 0;
640 }
641
642 if (!valid_servname(parv[1]))
643 {
644 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
645 "Link %s introduced server with bogus server name %s",
646 get_client_name(client_p, SHOW_IP), parv[1]);
647 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
648 "Link %s introduced server with bogus server name %s",
649 get_client_name(client_p, MASK_IP), parv[1]);
650 exit_client(client_p, "Bogus server name introduced");
651 return 0;
652 }
653
654 if (!valid_sid(parv[3]))
655 {
656 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
657 "Link %s introduced server with bogus server ID %s",
658 get_client_name(client_p, SHOW_IP), parv[3]);
659 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
660 "Link %s introduced server with bogus server ID %s",
661 get_client_name(client_p, MASK_IP), parv[3]);
662 exit_client(client_p, "Bogus server ID introduced");
663 return 0;
664 }
665
666 /* collision on SID? */
667 if ((target_p = hash_find_id(parv[3])))
668 {
669 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
670 "Link %s cancelled, server ID %s already exists",
671 get_client_name(client_p, SHOW_IP), parv[3]);
672 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
673 "Link %s cancelled, server ID %s already exists",
674 client_p->name, parv[3]);
675 exit_client(client_p, "Link cancelled, server ID already exists");
676 return 0;
677 }
678
679 /* collision on name? */
680 if ((target_p = hash_find_server(parv[1])))
681 {
682 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
683 "Link %s cancelled, server %s already exists",
684 get_client_name(client_p, SHOW_IP), parv[1]);
685 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
686 "Link %s cancelled, server %s already exists",
687 client_p->name, parv[1]);
688 exit_client(client_p, "Server exists");
689 return 0;
690 }
691
692 /* XXX If somehow there is a connect in progress and
693 * a connect comes in with same name toss the pending one,
694 * but only if it's not the same client! - Dianora
695 */
696 if ((target_p = find_servconn_in_progress(parv[1])))
697 if (target_p != client_p)
698 exit_client(target_p, "Overridden");
699
700 conf = client_p->connection->confs.head->data;
701
702 /* See if the newly found server is behind a guaranteed
703 * leaf. If so, close the link.
704 */
705 DLINK_FOREACH(ptr, conf->leaf_list.head)
706 {
707 if (!match(ptr->data, parv[1]))
708 {
709 llined = 1;
710 break;
711 }
712 }
713
714 DLINK_FOREACH(ptr, conf->hub_list.head)
715 {
716 if (!match(ptr->data, parv[1]))
717 {
718 hlined = 1;
719 break;
720 }
721 }
722
723 /* Ok, this way this works is
724 *
725 * A server can have a CONF_HUB allowing it to introduce servers
726 * behind it.
727 *
728 * connect {
729 * name = "irc.bighub.net";
730 * hub_mask="*";
731 * ...
732 *
733 * That would allow "irc.bighub.net" to introduce anything it wanted..
734 *
735 * However
736 *
737 * connect {
738 * name = "irc.somehub.fi";
739 * hub_mask="*";
740 * leaf_mask="*.edu";
741 *...
742 * Would allow this server in finland to hub anything but
743 * .edu's
744 */
745
746 /* Ok, check client_p can hub the new server, and make sure it's not a LL */
747 if (!hlined)
748 {
749 /* OOOPs nope can't HUB */
750 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
751 "Non-Hub link %s introduced %s.",
752 get_client_name(client_p, SHOW_IP), parv[1]);
753 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
754 "Non-Hub link %s introduced %s.",
755 get_client_name(client_p, MASK_IP), parv[1]);
756 exit_client(source_p, "No matching hub_mask.");
757 return 0;
758 }
759
760 /* Check for the new server being leafed behind this HUB */
761 if (llined)
762 {
763 /* OOOPs nope can't HUB this leaf */
764 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
765 "Link %s introduced leafed server %s.",
766 get_client_name(client_p, SHOW_IP), parv[1]);
767 sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE,
768 "Link %s introduced leafed server %s.",
769 get_client_name(client_p, MASK_IP), parv[1]);
770 exit_client(client_p, "Leafed server.");
771 return 0;
772 }
773
774 target_p = make_client(client_p);
775 make_server(target_p);
776 target_p->hopcount = atoi(parv[2]);
777 target_p->servptr = source_p;
778
779 strlcpy(target_p->name, parv[1], sizeof(target_p->name));
780 strlcpy(target_p->id, parv[3], sizeof(target_p->id));
781
782 set_server_gecos(target_p, parv[4]);
783 SetServer(target_p);
784
785 if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_SERVICE, target_p->name, NULL, NULL, 0))
786 AddFlag(target_p, FLAGS_SERVICE);
787
788 dlinkAdd(target_p, &target_p->node, &global_client_list);
789 dlinkAdd(target_p, make_dlink_node(), &global_server_list);
790 dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list);
791
792 hash_add_client(target_p);
793 hash_add_id(target_p);
794
795 sendto_server(client_p, NOCAPS, NOCAPS, ":%s SID %s %d %s :%s%s",
796 source_p->id, target_p->name, target_p->hopcount + 1,
797 target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info);
798 sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
799 "Server %s being introduced by %s",
800 target_p->name, source_p->name);
801 return 0;
802 }
803
804 static struct Message server_msgtab =
805 {
806 "SERVER", NULL, 0, 0, 4, MAXPARA, MFLG_SLOW, 0,
807 { mr_server, m_registered, m_ignore, m_ignore, m_registered, m_ignore }
808 };
809
810 static struct Message sid_msgtab =
811 {
812 "SID", NULL, 0, 0, 5, MAXPARA, MFLG_SLOW, 0,
813 { m_ignore, m_ignore, ms_sid, m_ignore, m_ignore, m_ignore }
814 };
815
816 static void
817 module_init(void)
818 {
819 mod_add_cmd(&sid_msgtab);
820 mod_add_cmd(&server_msgtab);
821 }
822
823 static void
824 module_exit(void)
825 {
826 mod_del_cmd(&sid_msgtab);
827 mod_del_cmd(&server_msgtab);
828 }
829
830 struct module module_entry =
831 {
832 .node = { NULL, NULL, NULL },
833 .name = NULL,
834 .version = "$Revision$",
835 .handle = NULL,
836 .modinit = module_init,
837 .modexit = module_exit,
838 .flags = MODULE_FLAG_CORE
839 };

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28