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 |
char *host; |
237 |
const char *inpath; |
238 |
static char inpath_ip[HOSTLEN * 2 + USERLEN + 6]; |
239 |
dlink_node *ptr; |
240 |
#if defined(HAVE_LIBCRYPTO) && !defined(OPENSSL_NO_COMP) |
241 |
const COMP_METHOD *compression = NULL, *expansion = NULL; |
242 |
#endif |
243 |
|
244 |
assert(client_p); |
245 |
|
246 |
strlcpy(inpath_ip, get_client_name(client_p, SHOW_IP), sizeof(inpath_ip)); |
247 |
|
248 |
inpath = get_client_name(client_p, MASK_IP); /* "refresh" inpath with host */ |
249 |
host = client_p->name; |
250 |
|
251 |
if ((conf = find_conf_name(&client_p->localClient->confs, host, CONF_SERVER)) |
252 |
== NULL) |
253 |
{ |
254 |
/* This shouldn't happen, better tell the ops... -A1kmm */ |
255 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
256 |
"Warning: Lost connect{} block " |
257 |
"for server %s(this shouldn't happen)!", host); |
258 |
exit_client(client_p, "Lost connect{} block!"); |
259 |
return; |
260 |
} |
261 |
|
262 |
MyFree(client_p->localClient->password); |
263 |
client_p->localClient->password = NULL; |
264 |
|
265 |
/* Its got identd, since it's a server */ |
266 |
SetGotId(client_p); |
267 |
|
268 |
/* If there is something in the serv_list, it might be this |
269 |
* connecting server.. |
270 |
*/ |
271 |
if (!ConfigServerInfo.hub && local_server_list.head) |
272 |
{ |
273 |
if (client_p != local_server_list.head->data || local_server_list.head->next) |
274 |
{ |
275 |
++ServerStats.is_ref; |
276 |
sendto_one(client_p, "ERROR :I'm a leaf not a hub"); |
277 |
exit_client(client_p, "I'm a leaf"); |
278 |
return; |
279 |
} |
280 |
} |
281 |
|
282 |
if (IsUnknown(client_p)) |
283 |
{ |
284 |
sendto_one(client_p, "PASS %s TS %d %s", conf->spasswd, TS_CURRENT, me.id); |
285 |
|
286 |
send_capabilities(client_p, 0); |
287 |
|
288 |
sendto_one(client_p, "SERVER %s 1 :%s%s", |
289 |
me.name, ConfigServerHide.hidden ? "(H) " : "", me.info); |
290 |
} |
291 |
|
292 |
sendto_one(client_p, ":%s SVINFO %d %d 0 :%lu", me.id, TS_CURRENT, TS_MIN, |
293 |
(unsigned long)CurrentTime); |
294 |
|
295 |
/* XXX Does this ever happen? I don't think so -db */ |
296 |
detach_conf(client_p, CONF_OPER); |
297 |
|
298 |
/* *WARNING* |
299 |
** In the following code in place of plain server's |
300 |
** name we send what is returned by get_client_name |
301 |
** which may add the "sockhost" after the name. It's |
302 |
** *very* *important* that there is a SPACE between |
303 |
** the name and sockhost (if present). The receiving |
304 |
** server will start the information field from this |
305 |
** first blank and thus puts the sockhost into info. |
306 |
** ...a bit tricky, but you have been warned, besides |
307 |
** code is more neat this way... --msa |
308 |
*/ |
309 |
client_p->servptr = &me; |
310 |
|
311 |
if (IsClosing(client_p)) |
312 |
return; |
313 |
|
314 |
SetServer(client_p); |
315 |
|
316 |
/* Some day, all these lists will be consolidated *sigh* */ |
317 |
dlinkAdd(client_p, &client_p->lnode, &me.serv->server_list); |
318 |
|
319 |
assert(dlinkFind(&unknown_list, client_p)); |
320 |
|
321 |
dlink_move_node(&client_p->localClient->lclient_node, |
322 |
&unknown_list, &local_server_list); |
323 |
|
324 |
Count.myserver++; |
325 |
|
326 |
dlinkAdd(client_p, &client_p->node, &global_client_list); |
327 |
dlinkAdd(client_p, make_dlink_node(), &global_server_list); |
328 |
hash_add_client(client_p); |
329 |
hash_add_id(client_p); |
330 |
|
331 |
/* doesnt duplicate client_p->serv if allocated this struct already */ |
332 |
make_server(client_p); |
333 |
|
334 |
/* fixing eob timings.. -gnp */ |
335 |
client_p->localClient->firsttime = CurrentTime; |
336 |
|
337 |
if (find_matching_name_conf(CONF_SERVICE, client_p->name, NULL, NULL, 0)) |
338 |
AddFlag(client_p, FLAGS_SERVICE); |
339 |
|
340 |
/* Show the real host/IP to admins */ |
341 |
#ifdef HAVE_LIBCRYPTO |
342 |
if (client_p->localClient->fd.ssl) |
343 |
{ |
344 |
#ifndef OPENSSL_NO_COMP |
345 |
compression = SSL_get_current_compression(client_p->localClient->fd.ssl); |
346 |
expansion = SSL_get_current_expansion(client_p->localClient->fd.ssl); |
347 |
#endif |
348 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
349 |
"Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
350 |
inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl), |
351 |
#ifndef OPENSSL_NO_COMP |
352 |
compression ? SSL_COMP_get_name(compression) : "NONE", |
353 |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
354 |
#else |
355 |
"NONE", "NONE", |
356 |
#endif |
357 |
show_capabilities(client_p)); |
358 |
/* Now show the masked hostname/IP to opers */ |
359 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
360 |
"Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
361 |
inpath, ssl_get_cipher(client_p->localClient->fd.ssl), |
362 |
#ifndef OPENSSL_NO_COMP |
363 |
compression ? SSL_COMP_get_name(compression) : "NONE", |
364 |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
365 |
#else |
366 |
"NONE", "NONE", |
367 |
#endif |
368 |
show_capabilities(client_p)); |
369 |
ilog(LOG_TYPE_IRCD, "Link with %s established: [SSL: %s, Compression/Expansion method: %s/%s] (Capabilities: %s)", |
370 |
inpath_ip, ssl_get_cipher(client_p->localClient->fd.ssl), |
371 |
#ifndef OPENSSL_NO_COMP |
372 |
compression ? SSL_COMP_get_name(compression) : "NONE", |
373 |
expansion ? SSL_COMP_get_name(expansion) : "NONE", |
374 |
#else |
375 |
"NONE", "NONE", |
376 |
#endif |
377 |
show_capabilities(client_p)); |
378 |
} |
379 |
else |
380 |
#endif |
381 |
{ |
382 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
383 |
"Link with %s established: (Capabilities: %s)", |
384 |
inpath_ip, show_capabilities(client_p)); |
385 |
/* Now show the masked hostname/IP to opers */ |
386 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
387 |
"Link with %s established: (Capabilities: %s)", |
388 |
inpath, show_capabilities(client_p)); |
389 |
ilog(LOG_TYPE_IRCD, "Link with %s established: (Capabilities: %s)", |
390 |
inpath_ip, show_capabilities(client_p)); |
391 |
} |
392 |
|
393 |
fd_note(&client_p->localClient->fd, "Server: %s", client_p->name); |
394 |
|
395 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s SID %s 2 %s :%s%s", |
396 |
me.id, client_p->name, client_p->id, |
397 |
IsHidden(client_p) ? "(H) " : "", client_p->info); |
398 |
|
399 |
/* |
400 |
* Pass on my client information to the new server |
401 |
* |
402 |
* First, pass only servers (idea is that if the link gets |
403 |
* cancelled beacause the server was already there, |
404 |
* there are no NICK's to be cancelled...). Of course, |
405 |
* if cancellation occurs, all this info is sent anyway, |
406 |
* and I guess the link dies when a read is attempted...? --msa |
407 |
* |
408 |
* Note: Link cancellation to occur at this point means |
409 |
* that at least two servers from my fragment are building |
410 |
* up connection this other fragment at the same time, it's |
411 |
* a race condition, not the normal way of operation... |
412 |
* |
413 |
* ALSO NOTE: using the get_client_name for server names-- |
414 |
* see previous *WARNING*!!! (Also, original inpath |
415 |
* is destroyed...) |
416 |
*/ |
417 |
DLINK_FOREACH_PREV(ptr, global_server_list.tail) |
418 |
{ |
419 |
struct Client *target_p = ptr->data; |
420 |
|
421 |
/* target_p->from == target_p for target_p == client_p */ |
422 |
if (IsMe(target_p) || target_p->from == client_p) |
423 |
continue; |
424 |
|
425 |
sendto_one(client_p, ":%s SID %s %d %s :%s%s", |
426 |
target_p->servptr->id, target_p->name, target_p->hopcount+1, |
427 |
target_p->id, IsHidden(target_p) ? "(H) " : "", |
428 |
target_p->info); |
429 |
} |
430 |
|
431 |
server_burst(client_p); |
432 |
} |
433 |
|
434 |
/* set_server_gecos() |
435 |
* |
436 |
* input - pointer to client |
437 |
* output - NONE |
438 |
* side effects - servers gecos field is set |
439 |
*/ |
440 |
static void |
441 |
set_server_gecos(struct Client *client_p, const char *info) |
442 |
{ |
443 |
const char *s = info; |
444 |
|
445 |
/* check for (H) which is a hidden server */ |
446 |
if (!strncmp(s, "(H) ", 4)) |
447 |
{ |
448 |
SetHidden(client_p); |
449 |
s = s + 4; |
450 |
} |
451 |
|
452 |
if (!EmptyString(s)) |
453 |
strlcpy(client_p->info, s, sizeof(client_p->info)); |
454 |
else |
455 |
strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); |
456 |
} |
457 |
|
458 |
/* mr_server() |
459 |
* parv[0] = command |
460 |
* parv[1] = servername |
461 |
* parv[2] = hopcount |
462 |
* parv[3] = serverinfo |
463 |
*/ |
464 |
static int |
465 |
mr_server(struct Client *source_p, int parc, char *parv[]) |
466 |
{ |
467 |
char *name = NULL; |
468 |
struct Client *target_p = NULL; |
469 |
|
470 |
if (EmptyString(parv[3])) |
471 |
{ |
472 |
sendto_one(source_p, "ERROR :No servername"); |
473 |
exit_client(source_p, "Wrong number of args"); |
474 |
return 0; |
475 |
} |
476 |
|
477 |
name = parv[1]; |
478 |
|
479 |
/* |
480 |
* Reject a direct nonTS server connection if we're TS_ONLY -orabidoo |
481 |
*/ |
482 |
if (!DoesTS(source_p)) |
483 |
{ |
484 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
485 |
"Unauthorized server connection attempt from %s: Non-TS server " |
486 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
487 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
488 |
"Unauthorized server connection attempt from %s: Non-TS server " |
489 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
490 |
exit_client(source_p, "Non-TS server"); |
491 |
return 0; |
492 |
} |
493 |
|
494 |
if (!valid_servname(name)) |
495 |
{ |
496 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
497 |
"Unauthorized server connection attempt from %s: Bogus server name " |
498 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
499 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
500 |
"Unauthorized server connection attempt from %s: Bogus server name " |
501 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
502 |
exit_client(source_p, "Bogus server name"); |
503 |
return 0; |
504 |
} |
505 |
|
506 |
if (!valid_sid(source_p->id)) |
507 |
{ |
508 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
509 |
"Link %s introduced server with bogus server ID %s", |
510 |
get_client_name(source_p, SHOW_IP), source_p->id); |
511 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
512 |
"Link %s introduced server with bogus server ID %s", |
513 |
get_client_name(source_p, MASK_IP), source_p->id); |
514 |
sendto_one(source_p, "ERROR :Bogus server ID introduced"); |
515 |
exit_client(source_p, "Bogus server ID intoduced"); |
516 |
return 0; |
517 |
} |
518 |
|
519 |
/* Now we just have to call check_server and everything should |
520 |
* be check for us... -A1kmm. |
521 |
*/ |
522 |
switch (check_server(name, source_p)) |
523 |
{ |
524 |
case -1: |
525 |
if (ConfigGeneral.warn_no_connect_block) |
526 |
{ |
527 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
528 |
"Unauthorized server connection attempt from %s: No entry for " |
529 |
"servername %s", get_client_name(source_p, HIDE_IP), name); |
530 |
|
531 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
532 |
"Unauthorized server connection attempt from %s: No entry for " |
533 |
"servername %s", get_client_name(source_p, MASK_IP), name); |
534 |
} |
535 |
|
536 |
exit_client(source_p, "No connect{} block."); |
537 |
return 0; |
538 |
/* NOT REACHED */ |
539 |
break; |
540 |
|
541 |
case -2: |
542 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
543 |
"Unauthorized server connection attempt from %s: Bad password " |
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: Bad password " |
548 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
549 |
|
550 |
exit_client(source_p, "Invalid password."); |
551 |
return 0; |
552 |
/* NOT REACHED */ |
553 |
break; |
554 |
|
555 |
case -3: |
556 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
557 |
"Unauthorized server connection attempt from %s: Invalid host " |
558 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
559 |
|
560 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
561 |
"Unauthorized server connection attempt from %s: Invalid host " |
562 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
563 |
|
564 |
exit_client(source_p, "Invalid host."); |
565 |
return 0; |
566 |
case -4: |
567 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
568 |
"Unauthorized server connection attempt from %s: Invalid certificate fingerprint " |
569 |
"for server %s", get_client_name(source_p, HIDE_IP), name); |
570 |
|
571 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
572 |
"Unauthorized server connection attempt from %s: Invalid certificate fingerprint " |
573 |
"for server %s", get_client_name(source_p, MASK_IP), name); |
574 |
|
575 |
exit_client(source_p, "Invalid certificate fingerprint."); |
576 |
return 0; |
577 |
/* NOT REACHED */ |
578 |
break; |
579 |
} |
580 |
|
581 |
if ((target_p = hash_find_server(name))) |
582 |
{ |
583 |
/* This link is trying feed me a server that I already have |
584 |
* access through another path -- multiple paths not accepted |
585 |
* currently, kill this link immediately!! |
586 |
* |
587 |
* Rather than KILL the link which introduced it, KILL the |
588 |
* youngest of the two links. -avalon |
589 |
* |
590 |
* Definitely don't do that here. This is from an unregistered |
591 |
* connect - A1kmm. |
592 |
*/ |
593 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
594 |
"Attempt to re-introduce server %s from %s", |
595 |
name, get_client_name(source_p, HIDE_IP)); |
596 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
597 |
"Attempt to re-introduce server %s from %s", |
598 |
name, get_client_name(source_p, MASK_IP)); |
599 |
sendto_one(source_p, "ERROR :Server already exists."); |
600 |
exit_client(source_p, "Server already exists"); |
601 |
return 0; |
602 |
} |
603 |
|
604 |
if ((target_p = hash_find_id(source_p->id))) |
605 |
{ |
606 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
607 |
"Attempt to re-introduce server %s SID %s from %s", |
608 |
name, source_p->id, |
609 |
get_client_name(source_p, HIDE_IP)); |
610 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
611 |
"Attempt to re-introduce server %s SID %s from %s", |
612 |
name, source_p->id, |
613 |
get_client_name(source_p, MASK_IP)); |
614 |
sendto_one(source_p, "ERROR :Server ID already exists."); |
615 |
exit_client(source_p, "Server ID already exists"); |
616 |
return 0; |
617 |
} |
618 |
|
619 |
/* XXX If somehow there is a connect in progress and |
620 |
* a connect comes in with same name toss the pending one, |
621 |
* but only if it's not the same client! - Dianora |
622 |
*/ |
623 |
if ((target_p = find_servconn_in_progress(name))) |
624 |
if (target_p != source_p) |
625 |
exit_client(target_p, "Overridden"); |
626 |
|
627 |
/* if we are connecting (Handshake), we already have the name from the |
628 |
* connect{} block in source_p->name |
629 |
*/ |
630 |
strlcpy(source_p->name, name, sizeof(source_p->name)); |
631 |
set_server_gecos(source_p, parv[3]); |
632 |
source_p->hopcount = atoi(parv[2]); |
633 |
server_estab(source_p); |
634 |
return 0; |
635 |
} |
636 |
|
637 |
/* ms_sid() |
638 |
* parv[0] = command |
639 |
* parv[1] = servername |
640 |
* parv[2] = hopcount |
641 |
* parv[3] = sid of new server |
642 |
* parv[4] = serverinfo |
643 |
*/ |
644 |
static int |
645 |
ms_sid(struct Client *source_p, int parc, char *parv[]) |
646 |
{ |
647 |
dlink_node *ptr = NULL; |
648 |
struct Client *target_p = NULL; |
649 |
struct Client *client_p = source_p->from; /* XXX */ |
650 |
const struct MaskItem *conf = NULL; |
651 |
int hlined = 0; |
652 |
int llined = 0; |
653 |
|
654 |
/* Just to be sure -A1kmm. */ |
655 |
if (!IsServer(source_p)) |
656 |
return 0; |
657 |
|
658 |
if (EmptyString(parv[4])) |
659 |
{ |
660 |
sendto_one(client_p, "ERROR :No servername"); |
661 |
return 0; |
662 |
} |
663 |
|
664 |
if (!valid_servname(parv[1])) |
665 |
{ |
666 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
667 |
"Link %s introduced server with bogus server name %s", |
668 |
get_client_name(client_p, SHOW_IP), parv[1]); |
669 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
670 |
"Link %s introduced server with bogus server name %s", |
671 |
get_client_name(client_p, MASK_IP), parv[1]); |
672 |
sendto_one(client_p, "ERROR :Bogus server name introduced"); |
673 |
exit_client(client_p, "Bogus server name intoduced"); |
674 |
return 0; |
675 |
} |
676 |
|
677 |
if (!valid_sid(parv[3])) |
678 |
{ |
679 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
680 |
"Link %s introduced server with bogus server ID %s", |
681 |
get_client_name(client_p, SHOW_IP), parv[3]); |
682 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
683 |
"Link %s introduced server with bogus server ID %s", |
684 |
get_client_name(client_p, MASK_IP), parv[3]); |
685 |
sendto_one(client_p, "ERROR :Bogus server ID introduced"); |
686 |
exit_client(client_p, "Bogus server ID intoduced"); |
687 |
return 0; |
688 |
} |
689 |
|
690 |
/* collision on SID? */ |
691 |
if ((target_p = hash_find_id(parv[3]))) |
692 |
{ |
693 |
sendto_one(client_p, "ERROR :SID %s already exists", parv[3]); |
694 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
695 |
"Link %s cancelled, SID %s already exists", |
696 |
get_client_name(client_p, SHOW_IP), parv[3]); |
697 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
698 |
"Link %s cancelled, SID %s already exists", |
699 |
client_p->name, parv[3]); |
700 |
exit_client(client_p, "SID Exists"); |
701 |
return 0; |
702 |
} |
703 |
|
704 |
/* collision on name? */ |
705 |
if ((target_p = hash_find_server(parv[1]))) |
706 |
{ |
707 |
sendto_one(client_p, "ERROR :Server %s already exists", parv[1]); |
708 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
709 |
"Link %s cancelled, server %s already exists", |
710 |
get_client_name(client_p, SHOW_IP), parv[1]); |
711 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
712 |
"Link %s cancelled, server %s already exists", |
713 |
client_p->name, parv[1]); |
714 |
exit_client(client_p, "Server Exists"); |
715 |
return 0; |
716 |
} |
717 |
|
718 |
/* XXX If somehow there is a connect in progress and |
719 |
* a connect comes in with same name toss the pending one, |
720 |
* but only if it's not the same client! - Dianora |
721 |
*/ |
722 |
if ((target_p = find_servconn_in_progress(parv[1]))) |
723 |
if (target_p != client_p) |
724 |
exit_client(target_p, "Overridden"); |
725 |
|
726 |
conf = client_p->localClient->confs.head->data; |
727 |
|
728 |
/* See if the newly found server is behind a guaranteed |
729 |
* leaf. If so, close the link. |
730 |
*/ |
731 |
DLINK_FOREACH(ptr, conf->leaf_list.head) |
732 |
{ |
733 |
if (!match(ptr->data, parv[1])) |
734 |
{ |
735 |
llined = 1; |
736 |
break; |
737 |
} |
738 |
} |
739 |
|
740 |
DLINK_FOREACH(ptr, conf->hub_list.head) |
741 |
{ |
742 |
if (!match(ptr->data, parv[1])) |
743 |
{ |
744 |
hlined = 1; |
745 |
break; |
746 |
} |
747 |
} |
748 |
|
749 |
/* Ok, this way this works is |
750 |
* |
751 |
* A server can have a CONF_HUB allowing it to introduce servers |
752 |
* behind it. |
753 |
* |
754 |
* connect { |
755 |
* name = "irc.bighub.net"; |
756 |
* hub_mask="*"; |
757 |
* ... |
758 |
* |
759 |
* That would allow "irc.bighub.net" to introduce anything it wanted.. |
760 |
* |
761 |
* However |
762 |
* |
763 |
* connect { |
764 |
* name = "irc.somehub.fi"; |
765 |
* hub_mask="*"; |
766 |
* leaf_mask="*.edu"; |
767 |
*... |
768 |
* Would allow this server in finland to hub anything but |
769 |
* .edu's |
770 |
*/ |
771 |
|
772 |
/* Ok, check client_p can hub the new server, and make sure it's not a LL */ |
773 |
if (!hlined) |
774 |
{ |
775 |
/* OOOPs nope can't HUB */ |
776 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
777 |
"Non-Hub link %s introduced %s.", |
778 |
get_client_name(client_p, SHOW_IP), parv[1]); |
779 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
780 |
"Non-Hub link %s introduced %s.", |
781 |
get_client_name(client_p, MASK_IP), parv[1]); |
782 |
exit_client(source_p, "No matching hub_mask."); |
783 |
return 0; |
784 |
} |
785 |
|
786 |
/* Check for the new server being leafed behind this HUB */ |
787 |
if (llined) |
788 |
{ |
789 |
/* OOOPs nope can't HUB this leaf */ |
790 |
sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE, |
791 |
"Link %s introduced leafed server %s.", |
792 |
get_client_name(client_p, SHOW_IP), parv[1]); |
793 |
sendto_realops_flags(UMODE_ALL, L_OPER, SEND_NOTICE, |
794 |
"Link %s introduced leafed server %s.", |
795 |
get_client_name(client_p, MASK_IP), parv[1]); |
796 |
exit_client(client_p, "Leafed Server."); |
797 |
return 0; |
798 |
} |
799 |
|
800 |
target_p = make_client(client_p); |
801 |
make_server(target_p); |
802 |
target_p->hopcount = atoi(parv[2]); |
803 |
target_p->servptr = source_p; |
804 |
|
805 |
strlcpy(target_p->name, parv[1], sizeof(target_p->name)); |
806 |
strlcpy(target_p->id, parv[3], sizeof(target_p->id)); |
807 |
|
808 |
set_server_gecos(target_p, parv[4]); |
809 |
SetServer(target_p); |
810 |
|
811 |
if (HasFlag(source_p, FLAGS_SERVICE) || find_matching_name_conf(CONF_SERVICE, target_p->name, NULL, NULL, 0)) |
812 |
AddFlag(target_p, FLAGS_SERVICE); |
813 |
|
814 |
dlinkAdd(target_p, &target_p->node, &global_client_list); |
815 |
dlinkAdd(target_p, make_dlink_node(), &global_server_list); |
816 |
dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->server_list); |
817 |
|
818 |
hash_add_client(target_p); |
819 |
hash_add_id(target_p); |
820 |
|
821 |
sendto_server(client_p, NOCAPS, NOCAPS, ":%s SID %s %d %s :%s%s", |
822 |
source_p->id, target_p->name, target_p->hopcount + 1, |
823 |
target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); |
824 |
sendto_realops_flags(UMODE_EXTERNAL, L_ALL, SEND_NOTICE, |
825 |
"Server %s being introduced by %s", |
826 |
target_p->name, source_p->name); |
827 |
return 0; |
828 |
} |
829 |
|
830 |
static struct Message server_msgtab = |
831 |
{ |
832 |
"SERVER", NULL, 0, 0, 4, MAXPARA, MFLG_SLOW, 0, |
833 |
{ mr_server, m_registered, m_ignore, m_ignore, m_registered, m_ignore } |
834 |
}; |
835 |
|
836 |
static struct Message sid_msgtab = |
837 |
{ |
838 |
"SID", NULL, 0, 0, 5, MAXPARA, MFLG_SLOW, 0, |
839 |
{ m_ignore, m_ignore, ms_sid, m_ignore, m_ignore, m_ignore } |
840 |
}; |
841 |
|
842 |
static void |
843 |
module_init(void) |
844 |
{ |
845 |
mod_add_cmd(&sid_msgtab); |
846 |
mod_add_cmd(&server_msgtab); |
847 |
} |
848 |
|
849 |
static void |
850 |
module_exit(void) |
851 |
{ |
852 |
mod_del_cmd(&sid_msgtab); |
853 |
mod_del_cmd(&server_msgtab); |
854 |
} |
855 |
|
856 |
struct module module_entry = |
857 |
{ |
858 |
.node = { NULL, NULL, NULL }, |
859 |
.name = NULL, |
860 |
.version = "$Revision$", |
861 |
.handle = NULL, |
862 |
.modinit = module_init, |
863 |
.modexit = module_exit, |
864 |
.flags = MODULE_FLAG_CORE |
865 |
}; |