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 there is something in the serv_list, it might be this |
258 |
* connecting server.. |
259 |
*/ |
260 |
if (!ConfigServerInfo.hub && local_server_list.head) |
261 |
{ |
262 |
if (client_p != local_server_list.head->data || local_server_list.head->next) |
263 |
{ |
264 |
++ServerStats.is_ref; |
265 |
exit_client(client_p, "I'm a leaf not a hub"); |
266 |
return; |
267 |
} |
268 |
} |
269 |
|
270 |
if (IsUnknown(client_p)) |
271 |
{ |
272 |
sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id); |
273 |
|
274 |
send_capabilities(client_p, 0); |
275 |
|
276 |
sendto_one(client_p, "SERVER %s 1 :%s%s", |
277 |
me.name, ConfigServerHide.hidden ? "(H) " : "", me.info); |
278 |
} |
279 |
|
280 |
sendto_one(client_p, ":%s SVINFO %d %d 0 :%lu", me.id, TS_CURRENT, TS_MIN, |
281 |
(unsigned long)CurrentTime); |
282 |
|
283 |
/* XXX Does this ever happen? I don't think so -db */ |
284 |
detach_conf(client_p, CONF_OPER); |
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_ALL, 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_ALL, 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_ALL, 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_ALL, 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, NOCAPS, NOCAPS, ":%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(ptr, global_server_list.tail) |
406 |
{ |
407 |
struct Client *target_p = ptr->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 %d %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 |
|
422 |
/* set_server_gecos() |
423 |
* |
424 |
* input - pointer to client |
425 |
* output - NONE |
426 |
* side effects - servers gecos field is set |
427 |
*/ |
428 |
static void |
429 |
set_server_gecos(struct Client *client_p, const char *info) |
430 |
{ |
431 |
const char *s = info; |
432 |
|
433 |
/* check for (H) which is a hidden server */ |
434 |
if (!strncmp(s, "(H) ", 4)) |
435 |
{ |
436 |
SetHidden(client_p); |
437 |
s = s + 4; |
438 |
} |
439 |
|
440 |
if (!EmptyString(s)) |
441 |
strlcpy(client_p->info, s, sizeof(client_p->info)); |
442 |
else |
443 |
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
444 |
} |
445 |
|
446 |
/* mr_server() |
447 |
* parv[0] = command |
448 |
* parv[1] = servername |
449 |
* parv[2] = hopcount |
450 |
* parv[3] = serverinfo |
451 |
*/ |
452 |
static int |
453 |
mr_server(struct Client *source_p, int parc, char *parv[]) |
454 |
{ |
455 |
char *name = NULL; |
456 |
struct Client *target_p = NULL; |
457 |
|
458 |
if (EmptyString(parv[3])) |
459 |
{ |
460 |
exit_client(source_p, "No server description supplied"); |
461 |
return 0; |
462 |
} |
463 |
|
464 |
name = parv[1]; |
465 |
|
466 |
/* |
467 |
* Reject a direct nonTS server connection if we're TS_ONLY -orabidoo |
468 |
*/ |
469 |
if (!DoesTS(source_p)) |
470 |
{ |
471 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
472 |
"Unauthorized server connection attempt from %s: Non-TS server " |
473 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
474 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
475 |
"Unauthorized server connection attempt from %s: Non-TS server " |
476 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
477 |
exit_client(source_p, "Non-TS server"); |
478 |
return 0; |
479 |
} |
480 |
|
481 |
if (!valid_servname(name)) |
482 |
{ |
483 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
484 |
"Unauthorized server connection attempt from %s: Bogus server name " |
485 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
486 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
487 |
"Unauthorized server connection attempt from %s: Bogus server name " |
488 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
489 |
exit_client(source_p, "Bogus server name"); |
490 |
return 0; |
491 |
} |
492 |
|
493 |
if (!valid_sid(source_p->id)) |
494 |
{ |
495 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
496 |
"Link %s introduced server with bogus server ID %s", |
497 |
get_client_name(source_p, SHOW_IP), source_p->id); |
498 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
499 |
"Link %s introduced server with bogus server ID %s", |
500 |
get_client_name(source_p, MASK_IP), source_p->id); |
501 |
exit_client(source_p, "Bogus server ID introduced"); |
502 |
return 0; |
503 |
} |
504 |
|
505 |
/* Now we just have to call check_server and everything should |
506 |
* be check for us... -A1kmm. |
507 |
*/ |
508 |
switch (check_server(name, source_p)) |
509 |
{ |
510 |
case -1: |
511 |
if (ConfigGeneral.warn_no_connect_block) |
512 |
{ |
513 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
514 |
"Unauthorized server connection attempt from %s: No entry for " |
515 |
"servername %s", get_client_name(source_p, HIDE_IP), name); |
516 |
|
517 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
518 |
"Unauthorized server connection attempt from %s: No entry for " |
519 |
"servername %s", get_client_name(source_p, MASK_IP), name); |
520 |
} |
521 |
|
522 |
exit_client(source_p, "No connect {} block."); |
523 |
return 0; |
524 |
/* NOT REACHED */ |
525 |
break; |
526 |
|
527 |
case -2: |
528 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
529 |
"Unauthorized server connection attempt from %s: Bad password " |
530 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
531 |
|
532 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
533 |
"Unauthorized server connection attempt from %s: Bad password " |
534 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
535 |
|
536 |
exit_client(source_p, "Invalid password."); |
537 |
return 0; |
538 |
/* NOT REACHED */ |
539 |
break; |
540 |
|
541 |
case -3: |
542 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
543 |
"Unauthorized server connection attempt from %s: Invalid host " |
544 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
545 |
|
546 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
547 |
"Unauthorized server connection attempt from %s: Invalid host " |
548 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
549 |
|
550 |
exit_client(source_p, "Invalid host."); |
551 |
return 0; |
552 |
case -4: |
553 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
554 |
"Unauthorized server connection attempt from %s: Invalid certificate fingerprint " |
555 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
556 |
|
557 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
558 |
"Unauthorized server connection attempt from %s: Invalid certificate fingerprint " |
559 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
560 |
|
561 |
exit_client(source_p, "Invalid certificate fingerprint."); |
562 |
return 0; |
563 |
/* NOT REACHED */ |
564 |
break; |
565 |
} |
566 |
|
567 |
if ((target_p = hash_find_server(name))) |
568 |
{ |
569 |
/* This link is trying feed me a server that I already have |
570 |
* access through another path -- multiple paths not accepted |
571 |
* currently, kill this link immediately!! |
572 |
* |
573 |
* Rather than KILL the link which introduced it, KILL the |
574 |
* youngest of the two links. -avalon |
575 |
* |
576 |
* Definitely don't do that here. This is from an unregistered |
577 |
* connect - A1kmm. |
578 |
*/ |
579 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
580 |
"Attempt to re-introduce server %s from %s", |
581 |
name, get_client_name(source_p, HIDE_IP)); |
582 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
583 |
"Attempt to re-introduce server %s from %s", |
584 |
name, get_client_name(source_p, MASK_IP)); |
585 |
exit_client(source_p, "Server already exists"); |
586 |
return 0; |
587 |
} |
588 |
|
589 |
if ((target_p = hash_find_id(source_p->id))) |
590 |
{ |
591 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
592 |
"Attempt to re-introduce server %s SID %s from %s", |
593 |
name, source_p->id, |
594 |
get_client_name(source_p, HIDE_IP)); |
595 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
596 |
"Attempt to re-introduce server %s SID %s from %s", |
597 |
name, source_p->id, |
598 |
get_client_name(source_p, MASK_IP)); |
599 |
exit_client(source_p, "Server ID already exists"); |
600 |
return 0; |
601 |
} |
602 |
|
603 |
/* XXX If somehow there is a connect in progress and |
604 |
* a connect comes in with same name toss the pending one, |
605 |
* but only if it's not the same client! - Dianora |
606 |
*/ |
607 |
if ((target_p = find_servconn_in_progress(name))) |
608 |
if (target_p != source_p) |
609 |
exit_client(target_p, "Overridden"); |
610 |
|
611 |
/* if we are connecting (Handshake), we already have the name from the |
612 |
* connect{} block in source_p->name |
613 |
*/ |
614 |
strlcpy(source_p->name, name, sizeof(source_p->name)); |
615 |
set_server_gecos(source_p, parv[3]); |
616 |
source_p->hopcount = atoi(parv[2]); |
617 |
server_estab(source_p); |
618 |
return 0; |
619 |
} |
620 |
|
621 |
/* ms_sid() |
622 |
* parv[0] = command |
623 |
* parv[1] = servername |
624 |
* parv[2] = hopcount |
625 |
* parv[3] = sid of new server |
626 |
* parv[4] = serverinfo |
627 |
*/ |
628 |
static int |
629 |
ms_sid(struct Client *source_p, int parc, char *parv[]) |
630 |
{ |
631 |
dlink_node *ptr = NULL; |
632 |
struct Client *target_p = NULL; |
633 |
struct Client *client_p = source_p->from; /* XXX */ |
634 |
const struct MaskItem *conf = NULL; |
635 |
int hlined = 0; |
636 |
int llined = 0; |
637 |
|
638 |
/* Just to be sure -A1kmm. */ |
639 |
if (!IsServer(source_p)) |
640 |
return 0; |
641 |
|
642 |
if (EmptyString(parv[4])) |
643 |
{ |
644 |
exit_client(client_p, "No server description supplied"); |
645 |
return 0; |
646 |
} |
647 |
|
648 |
if (!valid_servname(parv[1])) |
649 |
{ |
650 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
651 |
"Link %s introduced server with bogus server name %s", |
652 |
get_client_name(client_p, SHOW_IP), parv[1]); |
653 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
654 |
"Link %s introduced server with bogus server name %s", |
655 |
get_client_name(client_p, MASK_IP), parv[1]); |
656 |
exit_client(client_p, "Bogus server name introduced"); |
657 |
return 0; |
658 |
} |
659 |
|
660 |
if (!valid_sid(parv[3])) |
661 |
{ |
662 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
663 |
"Link %s introduced server with bogus server ID %s", |
664 |
get_client_name(client_p, SHOW_IP), parv[3]); |
665 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
666 |
"Link %s introduced server with bogus server ID %s", |
667 |
get_client_name(client_p, MASK_IP), parv[3]); |
668 |
exit_client(client_p, "Bogus server ID introduced"); |
669 |
return 0; |
670 |
} |
671 |
|
672 |
/* collision on SID? */ |
673 |
if ((target_p = hash_find_id(parv[3]))) |
674 |
{ |
675 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
676 |
"Link %s cancelled, server ID %s already exists", |
677 |
get_client_name(client_p, SHOW_IP), parv[3]); |
678 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
679 |
"Link %s cancelled, server ID %s already exists", |
680 |
client_p->name, parv[3]); |
681 |
exit_client(client_p, "Link cancelled, server ID already exists"); |
682 |
return 0; |
683 |
} |
684 |
|
685 |
/* collision on name? */ |
686 |
if ((target_p = hash_find_server(parv[1]))) |
687 |
{ |
688 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
689 |
"Link %s cancelled, server %s already exists", |
690 |
get_client_name(client_p, SHOW_IP), parv[1]); |
691 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
692 |
"Link %s cancelled, server %s already exists", |
693 |
client_p->name, parv[1]); |
694 |
exit_client(client_p, "Server exists"); |
695 |
return 0; |
696 |
} |
697 |
|
698 |
/* XXX If somehow there is a connect in progress and |
699 |
* a connect comes in with same name toss the pending one, |
700 |
* but only if it's not the same client! - Dianora |
701 |
*/ |
702 |
if ((target_p = find_servconn_in_progress(parv[1]))) |
703 |
if (target_p != client_p) |
704 |
exit_client(target_p, "Overridden"); |
705 |
|
706 |
conf = client_p->connection->confs.head->data; |
707 |
|
708 |
/* See if the newly found server is behind a guaranteed |
709 |
* leaf. If so, close the link. |
710 |
*/ |
711 |
DLINK_FOREACH(ptr, conf->leaf_list.head) |
712 |
{ |
713 |
if (!match(ptr->data, parv[1])) |
714 |
{ |
715 |
llined = 1; |
716 |
break; |
717 |
} |
718 |
} |
719 |
|
720 |
DLINK_FOREACH(ptr, conf->hub_list.head) |
721 |
{ |
722 |
if (!match(ptr->data, parv[1])) |
723 |
{ |
724 |
hlined = 1; |
725 |
break; |
726 |
} |
727 |
} |
728 |
|
729 |
/* Ok, this way this works is |
730 |
* |
731 |
* A server can have a CONF_HUB allowing it to introduce servers |
732 |
* behind it. |
733 |
* |
734 |
* connect { |
735 |
* name = "irc.bighub.net"; |
736 |
* hub_mask="*"; |
737 |
* ... |
738 |
* |
739 |
* That would allow "irc.bighub.net" to introduce anything it wanted.. |
740 |
* |
741 |
* However |
742 |
* |
743 |
* connect { |
744 |
* name = "irc.somehub.fi"; |
745 |
* hub_mask="*"; |
746 |
* leaf_mask="*.edu"; |
747 |
*... |
748 |
* Would allow this server in finland to hub anything but |
749 |
* .edu's |
750 |
*/ |
751 |
|
752 |
/* Ok, check client_p can hub the new server, and make sure it's not a LL */ |
753 |
if (!hlined) |
754 |
{ |
755 |
/* OOOPs nope can't HUB */ |
756 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
757 |
"Non-Hub link %s introduced %s.", |
758 |
get_client_name(client_p, SHOW_IP), parv[1]); |
759 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
760 |
"Non-Hub link %s introduced %s.", |
761 |
get_client_name(client_p, MASK_IP), parv[1]); |
762 |
exit_client(source_p, "No matching hub_mask."); |
763 |
return 0; |
764 |
} |
765 |
|
766 |
/* Check for the new server being leafed behind this HUB */ |
767 |
if (llined) |
768 |
{ |
769 |
/* OOOPs nope can't HUB this leaf */ |
770 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
771 |
"Link %s introduced leafed server %s.", |
772 |
get_client_name(client_p, SHOW_IP), parv[1]); |
773 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
774 |
"Link %s introduced leafed server %s.", |
775 |
get_client_name(client_p, MASK_IP), parv[1]); |
776 |
exit_client(client_p, "Leafed server."); |
777 |
return 0; |
778 |
} |
779 |
|
780 |
target_p = make_client(client_p); |
781 |
make_server(target_p); |
782 |
target_p->hopcount = atoi(parv[2]); |
783 |
target_p->servptr = source_p; |
784 |
|
785 |
strlcpy(target_p->name, parv[1], sizeof(target_p->name)); |
786 |
strlcpy(target_p->id, parv[3], sizeof(target_p->id)); |
787 |
|
788 |
set_server_gecos(target_p, parv[4]); |
789 |
SetServer(target_p); |
790 |
|
791 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_SERVICE, target_p->name, NULL, NULL, 0)) |
792 |
AddFlag(target_p, FLAGS_SERVICE); |
793 |
|
794 |
dlinkAdd(target_p, &target_p->node, &global_client_list); |
795 |
dlinkAdd(target_p, make_dlink_node(), &global_server_list); |
796 |
dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list); |
797 |
|
798 |
hash_add_client(target_p); |
799 |
hash_add_id(target_p); |
800 |
|
801 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s SID %s %d %s :%s%s", |
802 |
source_p->id, target_p->name, target_p->hopcount + 1, |
803 |
target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); |
804 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE, |
805 |
"Server %s being introduced by %s", |
806 |
target_p->name, source_p->name); |
807 |
return 0; |
808 |
} |
809 |
|
810 |
static struct Message server_msgtab = |
811 |
{ |
812 |
"SERVER", NULL, 0, 0, 4, MAXPARA, MFLG_SLOW, 0, |
813 |
{ mr_server, m_registered, m_ignore, m_ignore, m_registered, m_ignore } |
814 |
}; |
815 |
|
816 |
static struct Message sid_msgtab = |
817 |
{ |
818 |
"SID", NULL, 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
819 |
{ m_ignore, m_ignore, ms_sid, m_ignore, m_ignore, m_ignore } |
820 |
}; |
821 |
|
822 |
static void |
823 |
module_init(void) |
824 |
{ |
825 |
mod_add_cmd(&sid_msgtab); |
826 |
mod_add_cmd(&server_msgtab); |
827 |
} |
828 |
|
829 |
static void |
830 |
module_exit(void) |
831 |
{ |
832 |
mod_del_cmd(&sid_msgtab); |
833 |
mod_del_cmd(&server_msgtab); |
834 |
} |
835 |
|
836 |
struct module module_entry = |
837 |
{ |
838 |
.node = { NULL, NULL, NULL }, |
839 |
.name = NULL, |
840 |
.version = "$Revision$", |
841 |
.handle = NULL, |
842 |
.modinit = module_init, |
843 |
.modexit = module_exit, |
844 |
.flags = MODULE_FLAG_CORE |
845 |
}; |