ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_server.c
Revision: 7105
Committed: Sat Jan 23 20:11:27 2016 UTC (10 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 27693 byte(s)
Error occurred while calculating annotation data.
Log Message:
- Incorporate gnutls support by Adam & Attila

File Contents

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

Properties

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