ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/core/m_server.c
Revision: 6318
Committed: Wed Aug 5 16:04:43 2015 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 27737 byte(s)
Error occurred while calculating annotation data.
Log Message:
- Get rid of UMODE_ALL

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2015 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 /*
48 * send_tb
49 *
50 * inputs - pointer to Client
51 * - pointer to channel
52 * output - NONE
53 * side effects - Called on a server burst when
54 * server is CAP_TBURST capable
55 */
56 static void
57 send_tb(struct Client *client_p, const struct Channel *chptr)
58 {
59 /*
60 * We may also send an empty topic here, but only if topic_time isn't 0,
61 * i.e. if we had a topic that got unset. This is required for syncing
62 * topics properly.
63 *
64 * Imagine the following scenario: Our downlink introduces a channel
65 * to us with a TS that is equal to ours, but the channel topic on
66 * their side got unset while the servers were in splitmode, which means
67 * their 'topic' is newer. They simply wanted to unset it, so we have to
68 * deal with it in a more sophisticated fashion instead of just resetting
69 * it to their old topic they had before. Read m_tburst.c:ms_tburst
70 * for further information -Michael
71 */
72 if (chptr->topic_time)
73 sendto_one(client_p, ":%s TBURST %lu %s %lu %s :%s", me.id,
74 (unsigned long)chptr->creationtime, chptr->name,
75 (unsigned long)chptr->topic_time,
76 chptr->topic_info,
77 chptr->topic);
78 }
79
80 /* sendnick_TS()
81 *
82 * inputs - client (server) to send nick towards
83 * - client to send nick for
84 * output - NONE
85 * side effects - NICK message is sent towards given client_p
86 */
87 static void
88 sendnick_TS(struct Client *client_p, struct Client *target_p)
89 {
90 dlink_node *node = NULL;
91 char ubuf[IRCD_BUFSIZE] = "";
92
93 if (!IsClient(target_p))
94 return;
95
96 send_umode(NULL, target_p, 0, ubuf);
97
98 if (ubuf[0] == '\0')
99 {
100 ubuf[0] = '+';
101 ubuf[1] = '\0';
102 }
103
104 if (IsCapable(client_p, CAP_SVS))
105 sendto_one(client_p, ":%s UID %s %u %lu %s %s %s %s %s %s :%s",
106 target_p->servptr->id,
107 target_p->name, target_p->hopcount + 1,
108 (unsigned long) target_p->tsinfo,
109 ubuf, target_p->username, target_p->host,
110 target_p->sockhost, target_p->id,
111 target_p->account, target_p->info);
112 else
113 sendto_one(client_p, ":%s UID %s %u %lu %s %s %s %s %s :%s",
114 target_p->servptr->id,
115 target_p->name, target_p->hopcount + 1,
116 (unsigned long) target_p->tsinfo,
117 ubuf, target_p->username, target_p->host,
118 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 DLINK_FOREACH(node, target_p->svstags.head)
128 {
129 const struct ServicesTag *svstag = node->data;
130 char *m = ubuf;
131
132 for (const struct user_modes *tab = umode_tab; tab->c; ++tab)
133 if (svstag->umodes & tab->flag)
134 *m++ = tab->c;
135 *m = '\0';
136
137 sendto_one(client_p, ":%s SVSTAG %s %lu %u +%s :%s", me.id, target_p->id,
138 target_p->tsinfo, svstag->numeric, ubuf, svstag->tag);
139 }
140 }
141
142 /* burst_members()
143 *
144 * inputs - pointer to server to send members to
145 * - dlink_list pointer to membership list to send
146 * output - NONE
147 * side effects -
148 */
149 static void
150 burst_members(struct Client *client_p, struct Channel *chptr)
151 {
152 struct Client *target_p;
153 struct Membership *member;
154 dlink_node *node = NULL;
155
156 DLINK_FOREACH(node, chptr->members.head)
157 {
158 member = node->data;
159 target_p = member->client_p;
160
161 if (!HasFlag(target_p, FLAGS_BURSTED))
162 {
163 AddFlag(target_p, FLAGS_BURSTED);
164
165 if (target_p->from != client_p)
166 sendnick_TS(client_p, target_p);
167 }
168 }
169 }
170
171 /* burst_all()
172 *
173 * inputs - pointer to server to send burst to
174 * output - NONE
175 * side effects - complete burst of channels/nicks is sent to client_p
176 */
177 static void
178 burst_all(struct Client *client_p)
179 {
180 dlink_node *node = NULL;
181
182 DLINK_FOREACH(node, channel_list.head)
183 {
184 struct Channel *chptr = node->data;
185
186 if (dlink_list_length(&chptr->members))
187 {
188 burst_members(client_p, chptr);
189 send_channel_modes(client_p, chptr);
190
191 if (IsCapable(client_p, CAP_TBURST))
192 send_tb(client_p, chptr);
193 }
194 }
195
196 /* also send out those that are not on any channel
197 */
198 DLINK_FOREACH(node, global_client_list.head)
199 {
200 struct Client *target_p = node->data;
201
202 if (!HasFlag(target_p, FLAGS_BURSTED) && target_p->from != client_p)
203 sendnick_TS(client_p, target_p);
204
205 DelFlag(target_p, FLAGS_BURSTED);
206 }
207 }
208
209 /* server_burst()
210 *
211 * inputs - struct Client pointer server
212 * -
213 * output - none
214 * side effects - send a server burst
215 * bugs - still too long
216 */
217 static void
218 server_burst(struct Client *client_p)
219 {
220 /* Send it in the shortened format with the TS, if
221 ** it's a TS server; walk the list of channels, sending
222 ** all the nicks that haven't been sent yet for each
223 ** channel, then send the channel itself -- it's less
224 ** obvious than sending all nicks first, but on the
225 ** receiving side memory will be allocated more nicely
226 ** saving a few seconds in the handling of a split
227 ** -orabidoo
228 */
229
230 burst_all(client_p);
231
232 /* EOB stuff is now in burst_all */
233 /* Always send a PING after connect burst is done */
234 sendto_one(client_p, "PING :%s", me.id);
235 }
236
237 /* server_estab()
238 *
239 * inputs - pointer to a struct Client
240 * output -
241 * side effects -
242 */
243 static void
244 server_estab(struct Client *client_p)
245 {
246 struct MaskItem *conf = NULL;
247 dlink_node *node = NULL;
248 #if defined(HAVE_LIBCRYPTO) && !defined(OPENSSL_NO_COMP)
249 const COMP_METHOD *compression = NULL, *expansion = NULL;
250 #endif
251
252 if ((conf = find_conf_name(&client_p->connection->confs, client_p->name, CONF_SERVER))
253 == NULL)
254 {
255 /* This shouldn't happen, better tell the ops... -A1kmm */
256 sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
257 "Warning: Lost connect{} block "
258 "for server %s(this shouldn't happen)!", client_p->name);
259 exit_client(client_p, "Lost connect{} block!");
260 return;
261 }
262
263 MyFree(client_p->connection->password);
264 client_p->connection->password = NULL;
265
266 if (!ConfigServerInfo.hub && dlink_list_length(&local_server_list))
267 {
268 ++ServerStats.is_ref;
269 exit_client(client_p, "I'm a leaf not a hub");
270 return;
271 }
272
273 if (IsUnknown(client_p))
274 {
275 sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id);
276
277 send_capabilities(client_p);
278
279 sendto_one(client_p, "SERVER %s 1 :%s%s",
280 me.name, ConfigServerHide.hidden ? "(H) " : "", me.info);
281 }
282
283 sendto_one(client_p, ":%s SVINFO %d %d 0 :%lu", me.id, TS_CURRENT, TS_MIN,
284 (unsigned long)CurrentTime);
285
286 /* *WARNING*
287 ** In the following code in place of plain server's
288 ** name we send what is returned by get_client_name
289 ** which may add the "sockhost" after the name. It's
290 ** *very* *important* that there is a SPACE between
291 ** the name and sockhost (if present). The receiving
292 ** server will start the information field from this
293 ** first blank and thus puts the sockhost into info.
294 ** ...a bit tricky, but you have been warned, besides
295 ** code is more neat this way... --msa
296 */
297 client_p->servptr = &me;
298
299 if (IsClosing(client_p))
300 return;
301
302 SetServer(client_p);
303
304 /* Some day, all these lists will be consolidated *sigh* */
305 dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list);
306
307 assert(dlinkFind(&unknown_list, client_p));
308
309 dlink_move_node(&client_p->connection->lclient_node,
310 &unknown_list, &local_server_list);
311
312 Count.myserver++;
313
314 dlinkAdd(client_p, &client_p->node, &global_client_list);
315 dlinkAdd(client_p, make_dlink_node(), &global_server_list);
316 hash_add_client(client_p);
317 hash_add_id(client_p);
318
319 /* Doesn't duplicate client_p->serv if allocated this struct already */
320 make_server(client_p);
321
322 /* Fixing eob timings.. -gnp */
323 client_p->connection->firsttime = CurrentTime;
324
325 if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0))
326 AddFlag(client_p, FLAGS_SERVICE);
327
328 /* Show the real host/IP to admins */
329 #ifdef HAVE_LIBCRYPTO
330 if (client_p->connection->fd.ssl)
331 {
332 #ifndef OPENSSL_NO_COMP
333 compression = SSL_get_current_compression(client_p->connection->fd.ssl);
334 expansion = SSL_get_current_expansion(client_p->connection->fd.ssl);
335 #endif
336 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
337 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
338 get_client_name(client_p, SHOW_IP), ssl_get_cipher(client_p->connection->fd.ssl),
339 #ifndef OPENSSL_NO_COMP
340 compression ? SSL_COMP_get_name(compression) : "NONE",
341 expansion ? SSL_COMP_get_name(expansion) : "NONE",
342 #else
343 "NONE", "NONE",
344 #endif
345 show_capabilities(client_p));
346 /* Now show the masked hostname/IP to opers */
347 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
348 "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
349 get_client_name(client_p, MASK_IP), ssl_get_cipher(client_p->connection->fd.ssl),
350 #ifndef OPENSSL_NO_COMP
351 compression ? SSL_COMP_get_name(compression) : "NONE",
352 expansion ? SSL_COMP_get_name(expansion) : "NONE",
353 #else
354 "NONE", "NONE",
355 #endif
356 show_capabilities(client_p));
357 ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)",
358 get_client_name(client_p, SHOW_IP), ssl_get_cipher(client_p->connection->fd.ssl),
359 #ifndef OPENSSL_NO_COMP
360 compression ? SSL_COMP_get_name(compression) : "NONE",
361 expansion ? SSL_COMP_get_name(expansion) : "NONE",
362 #else
363 "NONE", "NONE",
364 #endif
365 show_capabilities(client_p));
366 }
367 else
368 #endif
369 {
370 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
371 "Link with %s established: (Capabilities: %s)",
372 get_client_name(client_p, SHOW_IP), show_capabilities(client_p));
373 /* Now show the masked hostname/IP to opers */
374 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
375 "Link with %s established: (Capabilities: %s)",
376 get_client_name(client_p, MASK_IP), show_capabilities(client_p));
377 ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)",
378 get_client_name(client_p, SHOW_IP), show_capabilities(client_p));
379 }
380
381 fd_note(&client_p->connection->fd, "Server: %s", client_p->name);
382
383 sendto_server(client_p, 0, 0, ":%s SID %s 2 %s :%s%s",
384 me.id, client_p->name, client_p->id,
385 IsHidden(client_p) ? "(H) " : "", client_p->info);
386
387 /*
388 * Pass on my client information to the new server
389 *
390 * First, pass only servers (idea is that if the link gets
391 * cancelled beacause the server was already there,
392 * there are no NICK's to be cancelled...). Of course,
393 * if cancellation occurs, all this info is sent anyway,
394 * and I guess the link dies when a read is attempted...? --msa
395 *
396 * Note: Link cancellation to occur at this point means
397 * that at least two servers from my fragment are building
398 * up connection this other fragment at the same time, it's
399 * a race condition, not the normal way of operation...
400 *
401 * ALSO NOTE: using the get_client_name for server names--
402 * see previous *WARNING*!!! (Also, original inpath
403 * is destroyed...)
404 */
405 DLINK_FOREACH_PREV(node, global_server_list.tail)
406 {
407 struct Client *target_p = node->data;
408
409 /* target_p->from == target_p for target_p == client_p */
410 if (IsMe(target_p) || target_p->from == client_p)
411 continue;
412
413 sendto_one(client_p, ":%s SID %s %u %s :%s%s",
414 target_p->servptr->id, target_p->name, target_p->hopcount+1,
415 target_p->id, IsHidden(target_p) ? "(H) " : "",
416 target_p->info);
417 }
418
419 server_burst(client_p);
420
421 if (IsCapable(client_p, CAP_EOB))
422 {
423 DLINK_FOREACH_PREV(node, global_server_list.tail)
424 {
425 struct Client *target_p = node->data;
426
427 if (target_p->from == client_p)
428 continue;
429
430 if (IsMe(target_p) || HasFlag(target_p, FLAGS_EOB))
431 sendto_one(client_p, ":%s EOB", target_p->id);
432 }
433 }
434 }
435
436 /* set_server_gecos()
437 *
438 * input - pointer to client
439 * output - NONE
440 * side effects - servers gecos field is set
441 */
442 static void
443 set_server_gecos(struct Client *client_p, const char *info)
444 {
445 const char *s = info;
446
447 /* check for (H) which is a hidden server */
448 if (!strncmp(s, "(H) ", 4))
449 {
450 AddFlag(client_p, FLAGS_HIDDEN);
451 s = s + 4;
452 }
453
454 if (!EmptyString(s))
455 strlcpy(client_p->info, s, sizeof(client_p->info));
456 else
457 strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info));
458 }
459
460 /* mr_server()
461 * parv[0] = command
462 * parv[1] = servername
463 * parv[2] = hopcount
464 * parv[3] = serverinfo
465 */
466 static int
467 mr_server(struct Client *source_p, int parc, char *parv[])
468 {
469 const char *name = parv[1];
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, HIDE_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(source_p->id))
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), source_p->id);
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), source_p->id);
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, HIDE_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, HIDE_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, HIDE_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, HIDE_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, HIDE_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, HIDE_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 set_server_gecos(source_p, parv[parc - 1]);
613 source_p->hopcount = atoi(parv[2]);
614 server_estab(source_p);
615 return 0;
616 }
617
618 /* ms_sid()
619 * parv[0] = command
620 * parv[1] = servername
621 * parv[2] = hopcount
622 * parv[3] = sid of new server
623 * parv[4] = serverinfo
624 */
625 static int
626 ms_sid(struct Client *source_p, int parc, char *parv[])
627 {
628 dlink_node *node = NULL;
629 struct Client *target_p = NULL;
630 struct Client *client_p = source_p->from; /* XXX */
631 const struct MaskItem *conf = NULL;
632 int hlined = 0;
633 int llined = 0;
634
635 /* Just to be sure -A1kmm. */
636 if (!IsServer(source_p))
637 return 0;
638
639 if (EmptyString(parv[parc - 1]))
640 {
641 exit_client(client_p, "No server description supplied");
642 return 0;
643 }
644
645 if (!valid_servname(parv[1]))
646 {
647 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
648 "Link %s introduced server with bogus server name %s",
649 get_client_name(client_p, SHOW_IP), parv[1]);
650 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
651 "Link %s introduced server with bogus server name %s",
652 get_client_name(client_p, MASK_IP), parv[1]);
653 exit_client(client_p, "Bogus server name introduced");
654 return 0;
655 }
656
657 if (!valid_sid(parv[3]))
658 {
659 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
660 "Link %s introduced server with bogus server ID %s",
661 get_client_name(client_p, SHOW_IP), parv[3]);
662 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
663 "Link %s introduced server with bogus server ID %s",
664 get_client_name(client_p, MASK_IP), parv[3]);
665 exit_client(client_p, "Bogus server ID introduced");
666 return 0;
667 }
668
669 /* collision on SID? */
670 if ((target_p = hash_find_id(parv[3])))
671 {
672 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
673 "Link %s cancelled, server ID %s already exists",
674 get_client_name(client_p, SHOW_IP), parv[3]);
675 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
676 "Link %s cancelled, server ID %s already exists",
677 client_p->name, parv[3]);
678 exit_client(client_p, "Link cancelled, server ID already exists");
679 return 0;
680 }
681
682 /* collision on name? */
683 if ((target_p = hash_find_server(parv[1])))
684 {
685 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
686 "Link %s cancelled, server %s already exists",
687 get_client_name(client_p, SHOW_IP), parv[1]);
688 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
689 "Link %s cancelled, server %s already exists",
690 client_p->name, parv[1]);
691 exit_client(client_p, "Server exists");
692 return 0;
693 }
694
695 /* XXX If somehow there is a connect in progress and
696 * a connect comes in with same name toss the pending one,
697 * but only if it's not the same client! - Dianora
698 */
699 if ((target_p = find_servconn_in_progress(parv[1])))
700 if (target_p != client_p)
701 exit_client(target_p, "Overridden");
702
703 conf = client_p->connection->confs.head->data;
704
705 /* See if the newly found server is behind a guaranteed
706 * leaf. If so, close the link.
707 */
708 DLINK_FOREACH(node, conf->leaf_list.head)
709 {
710 if (!match(node->data, parv[1]))
711 {
712 llined = 1;
713 break;
714 }
715 }
716
717 DLINK_FOREACH(node, conf->hub_list.head)
718 {
719 if (!match(node->data, parv[1]))
720 {
721 hlined = 1;
722 break;
723 }
724 }
725
726 /* Ok, this way this works is
727 *
728 * A server can have a CONF_HUB allowing it to introduce servers
729 * behind it.
730 *
731 * connect {
732 * name = "irc.bighub.net";
733 * hub_mask="*";
734 * ...
735 *
736 * That would allow "irc.bighub.net" to introduce anything it wanted..
737 *
738 * However
739 *
740 * connect {
741 * name = "irc.somehub.fi";
742 * hub_mask="*";
743 * leaf_mask="*.edu";
744 *...
745 * Would allow this server in finland to hub anything but
746 * .edu's
747 */
748
749 /* Ok, check client_p can hub the new server, and make sure it's not a LL */
750 if (!hlined)
751 {
752 /* OOOPs nope can't HUB */
753 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
754 "Non-Hub link %s introduced %s.",
755 get_client_name(client_p, SHOW_IP), parv[1]);
756 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
757 "Non-Hub link %s introduced %s.",
758 get_client_name(client_p, MASK_IP), parv[1]);
759 exit_client(source_p, "No matching hub_mask.");
760 return 0;
761 }
762
763 /* Check for the new server being leafed behind this HUB */
764 if (llined)
765 {
766 /* OOOPs nope can't HUB this leaf */
767 sendto_realops_flags(UMODE_SERVNOTICE, L_ADMIN, SEND_NOTICE,
768 "Link %s introduced leafed server %s.",
769 get_client_name(client_p, SHOW_IP), parv[1]);
770 sendto_realops_flags(UMODE_SERVNOTICE, L_OPER, SEND_NOTICE,
771 "Link %s introduced leafed server %s.",
772 get_client_name(client_p, MASK_IP), parv[1]);
773 exit_client(client_p, "Leafed server.");
774 return 0;
775 }
776
777 target_p = make_client(client_p);
778 make_server(target_p);
779 target_p->hopcount = atoi(parv[2]);
780 target_p->servptr = source_p;
781
782 strlcpy(target_p->name, parv[1], sizeof(target_p->name));
783 strlcpy(target_p->id, parv[3], sizeof(target_p->id));
784
785 set_server_gecos(target_p, parv[parc - 1]);
786 SetServer(target_p);
787
788 if (find_matching_name_conf(CONF_SERVICE, target_p->name, NULL, NULL, 0))
789 AddFlag(target_p, FLAGS_SERVICE);
790
791 dlinkAdd(target_p, &target_p->node, &global_client_list);
792 dlinkAdd(target_p, make_dlink_node(), &global_server_list);
793 dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list);
794
795 hash_add_client(target_p);
796 hash_add_id(target_p);
797
798 sendto_server(client_p, 0, 0, ":%s SID %s %u %s :%s%s",
799 source_p->id, target_p->name, target_p->hopcount + 1,
800 target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info);
801 sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE,
802 "Server %s being introduced by %s",
803 target_p->name, source_p->name);
804 return 0;
805 }
806
807 static struct Message server_msgtab =
808 {
809 .cmd = "SERVER",
810 .args_min = 4,
811 .args_max = MAXPARA,
812 .handlers[UNREGISTERED_HANDLER] = mr_server,
813 .handlers[CLIENT_HANDLER] = m_registered,
814 .handlers[SERVER_HANDLER] = m_ignore,
815 .handlers[ENCAP_HANDLER] = m_ignore,
816 .handlers[OPER_HANDLER] = m_registered
817 };
818
819 static struct Message sid_msgtab =
820 {
821 .cmd = "SID",
822 .args_min = 5,
823 .args_max = MAXPARA,
824 .handlers[UNREGISTERED_HANDLER] = m_ignore,
825 .handlers[CLIENT_HANDLER] = m_ignore,
826 .handlers[SERVER_HANDLER] = ms_sid,
827 .handlers[ENCAP_HANDLER] = m_ignore,
828 .handlers[OPER_HANDLER] = m_ignore
829 };
830
831 static void
832 module_init(void)
833 {
834 mod_add_cmd(&sid_msgtab);
835 mod_add_cmd(&server_msgtab);
836 }
837
838 static void
839 module_exit(void)
840 {
841 mod_del_cmd(&sid_msgtab);
842 mod_del_cmd(&server_msgtab);
843 }
844
845 struct module module_entry =
846 {
847 .version = "$Revision$",
848 .modinit = module_init,
849 .modexit = module_exit,
850 .flags = MODULE_FLAG_CORE
851 };

Properties

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