]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_server.c: Introduces a server. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: m_server.c 3291 2007-03-28 14:30:10Z jilles $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "client.h" /* client struct */ | |
29 | #include "common.h" /* TRUE bleah */ | |
30 | #include "hash.h" /* add_to_client_hash */ | |
31 | #include "match.h" | |
32 | #include "ircd.h" /* me */ | |
33 | #include "numeric.h" /* ERR_xxx */ | |
34 | #include "s_conf.h" /* struct ConfItem */ | |
35 | #include "s_newconf.h" | |
36 | #include "logger.h" /* log level defines */ | |
37 | #include "s_serv.h" /* server_estab, check_server */ | |
38 | #include "s_stats.h" /* ServerStats */ | |
39 | #include "scache.h" | |
40 | #include "send.h" /* sendto_one */ | |
41 | #include "msg.h" | |
42 | #include "parse.h" | |
43 | #include "modules.h" | |
44 | ||
45 | static int mr_server(struct Client *, struct Client *, int, const char **); | |
46 | static int ms_server(struct Client *, struct Client *, int, const char **); | |
47 | static int ms_sid(struct Client *, struct Client *, int, const char **); | |
48 | ||
49 | struct Message server_msgtab = { | |
50 | "SERVER", 0, 0, 0, MFLG_SLOW | MFLG_UNREG, | |
51 | {{mr_server, 4}, mg_reg, mg_ignore, {ms_server, 4}, mg_ignore, mg_reg} | |
52 | }; | |
53 | struct Message sid_msgtab = { | |
54 | "SID", 0, 0, 0, MFLG_SLOW, | |
55 | {mg_ignore, mg_reg, mg_ignore, {ms_sid, 5}, mg_ignore, mg_reg} | |
56 | }; | |
57 | ||
58 | mapi_clist_av1 server_clist[] = { &server_msgtab, &sid_msgtab, NULL }; | |
59 | ||
60 | DECLARE_MODULE_AV1(server, NULL, NULL, server_clist, NULL, NULL, "$Revision: 3291 $"); | |
61 | ||
62 | int bogus_host(const char *host); | |
63 | static int set_server_gecos(struct Client *, const char *); | |
64 | ||
65 | /* | |
66 | * mr_server - SERVER message handler | |
67 | * parv[1] = servername | |
68 | * parv[2] = serverinfo/hopcount | |
69 | * parv[3] = serverinfo | |
70 | */ | |
71 | static int | |
72 | mr_server(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
73 | { | |
74 | char info[REALLEN + 1]; | |
75 | const char *name; | |
76 | struct Client *target_p; | |
77 | int hop; | |
78 | unsigned int required_mask; | |
79 | const char *missing; | |
80 | ||
81 | name = parv[1]; | |
82 | hop = atoi(parv[2]); | |
83 | rb_strlcpy(info, parv[3], sizeof(info)); | |
84 | ||
85 | if (IsHandshake(client_p) && irccmp(client_p->name, name)) | |
86 | { | |
87 | sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, | |
88 | "Server %s has unexpected name %s", | |
89 | client_p->name, name); | |
90 | ilog(L_SERVER, "Server %s has unexpected name %s", | |
91 | log_client_name(client_p, SHOW_IP), name); | |
92 | exit_client(client_p, client_p, client_p, "Server name mismatch"); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | /* | |
97 | * Reject a direct nonTS server connection if we're TS_ONLY -orabidoo | |
98 | */ | |
99 | if(!DoesTS(client_p)) | |
100 | { | |
101 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Link %s dropped, non-TS server", | |
102 | client_p->name); | |
103 | exit_client(client_p, client_p, client_p, "Non-TS server"); | |
104 | return 0; | |
105 | } | |
106 | ||
107 | if(bogus_host(name)) | |
108 | { | |
109 | exit_client(client_p, client_p, client_p, "Bogus server name"); | |
110 | return 0; | |
111 | } | |
112 | ||
113 | /* Now we just have to call check_server and everything should be | |
114 | * check for us... -A1kmm. */ | |
115 | switch (check_server(name, client_p)) | |
116 | { | |
117 | case -1: | |
118 | if(ConfigFileEntry.warn_no_nline) | |
119 | { | |
120 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
121 | "Unauthorised server connection attempt from %s: " | |
122 | "No entry for servername %s", | |
123 | "[@255.255.255.255]", name); | |
124 | ||
125 | ilog(L_SERVER, "Access denied, no connect block for server %s%s", | |
126 | EmptyString(client_p->name) ? name : "", | |
127 | log_client_name(client_p, SHOW_IP)); | |
128 | } | |
129 | ||
130 | exit_client(client_p, client_p, client_p, "Invalid servername."); | |
131 | return 0; | |
132 | /* NOT REACHED */ | |
133 | break; | |
134 | ||
135 | case -2: | |
136 | sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, | |
137 | "Unauthorised server connection attempt from %s: " | |
138 | "Bad credentials for server %s", | |
139 | "[@255.255.255.255]", name); | |
140 | ||
141 | ilog(L_SERVER, "Access denied, invalid credentials for server %s%s", | |
142 | EmptyString(client_p->name) ? name : "", | |
143 | log_client_name(client_p, SHOW_IP)); | |
144 | ||
145 | exit_client(client_p, client_p, client_p, "Invalid credentials."); | |
146 | return 0; | |
147 | /* NOT REACHED */ | |
148 | break; | |
149 | ||
150 | case -3: | |
151 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
152 | "Unauthorised server connection attempt from %s: " | |
153 | "Invalid host for server %s", | |
154 | "[@255.255.255.255]", name); | |
155 | ||
156 | ilog(L_SERVER, "Access denied, invalid host for server %s%s", | |
157 | EmptyString(client_p->name) ? name : "", | |
158 | log_client_name(client_p, SHOW_IP)); | |
159 | ||
160 | exit_client(client_p, client_p, client_p, "Invalid host."); | |
161 | return 0; | |
162 | /* NOT REACHED */ | |
163 | break; | |
164 | ||
165 | /* servername is > HOSTLEN */ | |
166 | case -4: | |
167 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
168 | "Invalid servername %s from %s", | |
169 | name, "[@255.255.255.255]"); | |
170 | ilog(L_SERVER, "Access denied, invalid servername from %s", | |
171 | log_client_name(client_p, SHOW_IP)); | |
172 | ||
173 | exit_client(client_p, client_p, client_p, "Invalid servername."); | |
174 | return 0; | |
175 | /* NOT REACHED */ | |
176 | break; | |
177 | case -5: | |
178 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
179 | "Connection from servername %s requires SSL/TLS but is plaintext", | |
180 | name); | |
181 | ilog(L_SERVER, "Access denied, requires SSL/TLS but is plaintext from %s", | |
182 | log_client_name(client_p, SHOW_IP)); | |
183 | ||
184 | exit_client(client_p, client_p, client_p, "Access denied, requires SSL/TLS but is plaintext"); | |
185 | return 0; | |
186 | } | |
187 | ||
188 | /* require TS6 for direct links */ | |
189 | if(!IsCapable(client_p, CAP_TS6)) | |
190 | { | |
191 | sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, | |
192 | "Link %s dropped, TS6 protocol is required", name); | |
193 | exit_client(client_p, client_p, client_p, "Incompatible TS version"); | |
194 | return 0; | |
195 | } | |
196 | ||
197 | /* check to ensure any "required" caps are set. --nenolod */ | |
198 | required_mask = capability_index_get_required(serv_capindex); | |
199 | if (!IsCapable(client_p, required_mask)) | |
200 | { | |
201 | missing = capability_index_list(serv_capindex, required_mask & | |
202 | ~client_p->localClient->caps); | |
203 | sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, | |
204 | "Link %s dropped, required CAPABs [%s] are missing", | |
205 | name, missing); | |
206 | ilog(L_SERVER, "Link %s%s dropped, required CAPABs [%s] are missing", | |
207 | EmptyString(client_p->name) ? name : "", | |
208 | log_client_name(client_p, SHOW_IP), missing); | |
209 | /* Do not use '[' in the below message because it would cause | |
210 | * it to be considered potentially unsafe (might disclose IP | |
211 | * addresses) | |
212 | */ | |
213 | sendto_one(client_p, "ERROR :Missing required CAPABs (%s)", missing); | |
214 | exit_client(client_p, client_p, client_p, "Missing required CAPABs"); | |
215 | ||
216 | return 0; | |
217 | } | |
218 | ||
219 | if((target_p = find_server(NULL, name))) | |
220 | { | |
221 | /* | |
222 | * This link is trying feed me a server that I already have | |
223 | * access through another path -- multiple paths not accepted | |
224 | * currently, kill this link immediately!! | |
225 | * | |
226 | * Rather than KILL the link which introduced it, KILL the | |
227 | * youngest of the two links. -avalon | |
228 | * | |
229 | * Definitely don't do that here. This is from an unregistered | |
230 | * connect - A1kmm. | |
231 | */ | |
232 | if (target_p->servptr->flags & FLAGS_SERVICE) | |
233 | { | |
234 | /* Assume any servers introduced by services | |
235 | * are jupes. | |
236 | * -- jilles | |
237 | */ | |
238 | sendto_one(client_p, "ERROR :Server juped."); | |
239 | } | |
240 | else | |
241 | { | |
242 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
243 | "Attempt to re-introduce server %s from %s", | |
244 | name, "[@255.255.255.255]"); | |
245 | ilog(L_SERVER, "Attempt to re-introduce server %s from %s", | |
246 | name, log_client_name(client_p, SHOW_IP)); | |
247 | ||
248 | sendto_one(client_p, "ERROR :Server already exists."); | |
249 | } | |
250 | exit_client(client_p, client_p, client_p, "Server Exists"); | |
251 | return 0; | |
252 | } | |
253 | ||
254 | if(has_id(client_p) && (target_p = find_id(client_p->id)) != NULL) | |
255 | { | |
256 | sendto_realops_snomask(SNO_GENERAL, is_remote_connect(client_p) ? L_NETWIDE : L_ALL, | |
257 | "Attempt to re-introduce SID %s from %s%s (already in use by %s)", | |
258 | client_p->id, | |
259 | EmptyString(client_p->name) ? name : "", | |
260 | client_p->name, target_p->name); | |
261 | ilog(L_SERVER, "Attempt to re-introduce SID %s from %s%s (already in use by %s)", | |
262 | client_p->id, | |
263 | EmptyString(client_p->name) ? name : "", | |
264 | log_client_name(client_p, SHOW_IP), | |
265 | target_p->name); | |
266 | ||
267 | sendto_one(client_p, "ERROR :SID already exists."); | |
268 | exit_client(client_p, client_p, client_p, "SID Exists"); | |
269 | return 0; | |
270 | } | |
271 | ||
272 | /* | |
273 | * if we are connecting (Handshake), we already have the name from the | |
274 | * C:line in client_p->name | |
275 | */ | |
276 | ||
277 | rb_strlcpy(client_p->name, name, sizeof(client_p->name)); | |
278 | set_server_gecos(client_p, info); | |
279 | client_p->hopcount = hop; | |
280 | server_estab(client_p); | |
281 | ||
282 | return 0; | |
283 | } | |
284 | ||
285 | /* | |
286 | * ms_server - SERVER message handler | |
287 | * parv[1] = servername | |
288 | * parv[2] = serverinfo/hopcount | |
289 | * parv[3] = serverinfo | |
290 | */ | |
291 | static int | |
292 | ms_server(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
293 | { | |
294 | char info[REALLEN + 1]; | |
295 | /* same size as in s_misc.c */ | |
296 | const char *name; | |
297 | struct Client *target_p; | |
298 | struct remote_conf *hub_p; | |
299 | hook_data_client hdata; | |
300 | int hop; | |
301 | int hlined = 0; | |
302 | int llined = 0; | |
303 | rb_dlink_node *ptr; | |
304 | char squitreason[160]; | |
305 | ||
306 | name = parv[1]; | |
307 | hop = atoi(parv[2]); | |
308 | rb_strlcpy(info, parv[3], sizeof(info)); | |
309 | ||
310 | if(find_server(NULL, name)) | |
311 | { | |
312 | /* | |
313 | * This link is trying feed me a server that I already have | |
314 | * access through another path -- multiple paths not accepted | |
315 | * currently, kill this link immediately!! | |
316 | * | |
317 | * Rather than KILL the link which introduced it, KILL the | |
318 | * youngest of the two links. -avalon | |
319 | * | |
320 | * I think that we should exit the link itself, not the introducer, | |
321 | * and we should always exit the most recently received(i.e. the | |
322 | * one we are receiving this SERVER for. -A1kmm | |
323 | * | |
324 | * You *cant* do this, if you link somewhere, it bursts you a server | |
325 | * that already exists, then sends you a client burst, you squit the | |
326 | * server, but you keep getting the burst of clients on a server that | |
327 | * doesnt exist, although ircd can handle it, its not a realistic | |
328 | * solution.. --fl_ | |
329 | */ | |
330 | ilog(L_SERVER, "Link %s cancelled, server %s already exists", | |
331 | client_p->name, name); | |
332 | ||
333 | rb_snprintf(squitreason, sizeof squitreason, | |
334 | "Server %s already exists", | |
335 | name); | |
336 | exit_client(client_p, client_p, &me, squitreason); | |
337 | return 0; | |
338 | } | |
339 | ||
340 | /* | |
341 | * User nicks never have '.' in them and server names | |
342 | * must always have '.' in them. | |
343 | */ | |
344 | if(strchr(name, '.') == NULL) | |
345 | { | |
346 | /* | |
347 | * Server trying to use the same name as a person. Would | |
348 | * cause a fair bit of confusion. Enough to make it hellish | |
349 | * for a while and servers to send stuff to the wrong place. | |
350 | */ | |
351 | sendto_one(client_p, "ERROR :Nickname %s already exists!", name); | |
352 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
353 | "Link %s cancelled: Server/nick collision on %s", | |
354 | client_p->name, name); | |
355 | ilog(L_SERVER, "Link %s cancelled: Server/nick collision on %s", | |
356 | client_p->name, name); | |
357 | ||
358 | exit_client(client_p, client_p, client_p, "Nick as Server"); | |
359 | return 0; | |
360 | } | |
361 | ||
362 | /* | |
363 | * Server is informing about a new server behind | |
364 | * this link. Create REMOTE server structure, | |
365 | * add it to list and propagate word to my other | |
366 | * server links... | |
367 | */ | |
368 | ||
369 | /* | |
370 | * See if the newly found server is behind a guaranteed | |
371 | * leaf. If so, close the link. | |
372 | * | |
373 | */ | |
374 | RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) | |
375 | { | |
376 | hub_p = ptr->data; | |
377 | ||
378 | if(match(hub_p->server, client_p->name) && match(hub_p->host, name)) | |
379 | { | |
380 | if(hub_p->flags & CONF_HUB) | |
381 | hlined++; | |
382 | else | |
383 | llined++; | |
384 | } | |
385 | } | |
386 | ||
387 | /* Ok, this way this works is | |
388 | * | |
389 | * A server can have a CONF_HUB allowing it to introduce servers | |
390 | * behind it. | |
391 | * | |
392 | * connect { | |
393 | * name = "irc.bighub.net"; | |
394 | * hub_mask="*"; | |
395 | * ... | |
396 | * | |
397 | * That would allow "irc.bighub.net" to introduce anything it wanted.. | |
398 | * | |
399 | * However | |
400 | * | |
401 | * connect { | |
402 | * name = "irc.somehub.fi"; | |
403 | * hub_mask="*"; | |
404 | * leaf_mask="*.edu"; | |
405 | *... | |
406 | * Would allow this server in finland to hub anything but | |
407 | * .edu's | |
408 | */ | |
409 | ||
410 | /* Ok, check client_p can hub the new server */ | |
411 | if(!hlined) | |
412 | { | |
413 | /* OOOPs nope can't HUB */ | |
414 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "Non-Hub link %s introduced %s.", | |
415 | client_p->name, name); | |
416 | ilog(L_SERVER, "Non-Hub link %s introduced %s.", | |
417 | client_p->name, name); | |
418 | ||
419 | rb_snprintf(squitreason, sizeof squitreason, | |
420 | "No matching hub_mask for %s", | |
421 | name); | |
422 | exit_client(NULL, client_p, &me, squitreason); | |
423 | return 0; | |
424 | } | |
425 | ||
426 | /* Check for the new server being leafed behind this HUB */ | |
427 | if(llined) | |
428 | { | |
429 | /* OOOPs nope can't HUB this leaf */ | |
430 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
431 | "Link %s introduced leafed server %s.", | |
432 | client_p->name, name); | |
433 | ilog(L_SERVER, "Link %s introduced leafed server %s.", | |
434 | client_p->name, name); | |
435 | ||
436 | rb_snprintf(squitreason, sizeof squitreason, | |
437 | "Matching leaf_mask for %s", | |
438 | name); | |
439 | exit_client(NULL, client_p, &me, squitreason); | |
440 | return 0; | |
441 | } | |
442 | ||
443 | ||
444 | ||
445 | if(strlen(name) > HOSTLEN) | |
446 | { | |
447 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
448 | "Link %s introduced server with invalid servername %s", | |
449 | client_p->name, name); | |
450 | ilog(L_SERVER, "Link %s introduced server with invalid servername %s", | |
451 | client_p->name, name); | |
452 | ||
453 | exit_client(NULL, client_p, &me, "Invalid servername introduced."); | |
454 | return 0; | |
455 | } | |
456 | ||
457 | target_p = make_client(client_p); | |
458 | make_server(target_p); | |
459 | target_p->hopcount = hop; | |
460 | ||
461 | rb_strlcpy(target_p->name, name, sizeof(target_p->name)); | |
462 | ||
463 | set_server_gecos(target_p, info); | |
464 | ||
465 | target_p->servptr = source_p; | |
466 | ||
467 | SetServer(target_p); | |
468 | ||
469 | rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); | |
470 | rb_dlinkAddTailAlloc(target_p, &global_serv_list); | |
471 | add_to_client_hash(target_p->name, target_p); | |
472 | rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); | |
473 | ||
474 | target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); | |
475 | ||
476 | sendto_server(client_p, NULL, NOCAPS, NOCAPS, | |
477 | ":%s SERVER %s %d :%s%s", | |
478 | source_p->name, target_p->name, target_p->hopcount + 1, | |
479 | IsHidden(target_p) ? "(H) " : "", target_p->info); | |
480 | ||
481 | sendto_realops_snomask(SNO_EXTERNAL, L_ALL, | |
482 | "Server %s being introduced by %s", target_p->name, source_p->name); | |
483 | ||
484 | /* quick, dirty EOB. you know you love it. */ | |
485 | sendto_one(target_p, ":%s PING %s %s", get_id(&me, target_p), me.name, target_p->name); | |
486 | ||
487 | hdata.client = source_p; | |
488 | hdata.target = target_p; | |
489 | call_hook(h_server_introduced, &hdata); | |
490 | ||
491 | return 0; | |
492 | } | |
493 | ||
494 | static int | |
495 | ms_sid(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
496 | { | |
497 | struct Client *target_p; | |
498 | struct remote_conf *hub_p; | |
499 | hook_data_client hdata; | |
500 | rb_dlink_node *ptr; | |
501 | int hlined = 0; | |
502 | int llined = 0; | |
503 | char squitreason[160]; | |
504 | ||
505 | /* collision on the name? */ | |
506 | if(find_server(NULL, parv[1]) != NULL) | |
507 | { | |
508 | ilog(L_SERVER, "Link %s cancelled, server %s already exists", | |
509 | client_p->name, parv[1]); | |
510 | ||
511 | rb_snprintf(squitreason, sizeof squitreason, | |
512 | "Server %s already exists", | |
513 | parv[1]); | |
514 | exit_client(NULL, client_p, &me, squitreason); | |
515 | return 0; | |
516 | } | |
517 | ||
518 | /* collision on the SID? */ | |
519 | if((target_p = find_id(parv[3])) != NULL) | |
520 | { | |
521 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
522 | "Link %s cancelled, SID %s for server %s already in use by %s", | |
523 | client_p->name, parv[3], parv[1], target_p->name); | |
524 | sendto_server(NULL, NULL, CAP_TS6, NOCAPS, | |
525 | ":%s WALLOPS :Link %s cancelled, SID %s for server %s already in use by %s", | |
526 | me.id, client_p->name, parv[3], parv[1], target_p->name); | |
527 | ilog(L_SERVER, "Link %s cancelled, SID %s for server %s already in use by %s", | |
528 | client_p->name, parv[3], parv[1], target_p->name); | |
529 | ||
530 | rb_snprintf(squitreason, sizeof squitreason, | |
531 | "SID %s for %s already in use by %s", | |
532 | parv[3], parv[1], target_p->name); | |
533 | exit_client(NULL, client_p, &me, squitreason); | |
534 | return 0; | |
535 | } | |
536 | ||
537 | if(bogus_host(parv[1]) || strlen(parv[1]) > HOSTLEN) | |
538 | { | |
539 | sendto_one(client_p, "ERROR :Invalid servername"); | |
540 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
541 | "Link %s cancelled, servername %s invalid", | |
542 | client_p->name, parv[1]); | |
543 | ilog(L_SERVER, "Link %s cancelled, servername %s invalid", | |
544 | client_p->name, parv[1]); | |
545 | ||
546 | exit_client(NULL, client_p, &me, "Bogus server name"); | |
547 | return 0; | |
548 | } | |
549 | ||
550 | if(!IsDigit(parv[3][0]) || !IsIdChar(parv[3][1]) || | |
551 | !IsIdChar(parv[3][2]) || parv[3][3] != '\0') | |
552 | { | |
553 | sendto_one(client_p, "ERROR :Invalid SID"); | |
554 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
555 | "Link %s cancelled, SID %s invalid", | |
556 | client_p->name, parv[3]); | |
557 | ilog(L_SERVER, "Link %s cancelled, SID %s invalid", | |
558 | client_p->name, parv[3]); | |
559 | ||
560 | exit_client(NULL, client_p, &me, "Bogus SID"); | |
561 | return 0; | |
562 | } | |
563 | ||
564 | /* for the directly connected server: | |
565 | * H: allows it to introduce a server matching that mask | |
566 | * L: disallows it introducing a server matching that mask | |
567 | */ | |
568 | RB_DLINK_FOREACH(ptr, hubleaf_conf_list.head) | |
569 | { | |
570 | hub_p = ptr->data; | |
571 | ||
572 | if(match(hub_p->server, client_p->name) && match(hub_p->host, parv[1])) | |
573 | { | |
574 | if(hub_p->flags & CONF_HUB) | |
575 | hlined++; | |
576 | else | |
577 | llined++; | |
578 | } | |
579 | } | |
580 | ||
581 | /* no matching hub_mask */ | |
582 | if(!hlined) | |
583 | { | |
584 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
585 | "Non-Hub link %s introduced %s.", | |
586 | client_p->name, parv[1]); | |
587 | ilog(L_SERVER, "Non-Hub link %s introduced %s.", | |
588 | client_p->name, parv[1]); | |
589 | ||
590 | rb_snprintf(squitreason, sizeof squitreason, | |
591 | "No matching hub_mask for %s", | |
592 | parv[1]); | |
593 | exit_client(NULL, client_p, &me, squitreason); | |
594 | return 0; | |
595 | } | |
596 | ||
597 | /* matching leaf_mask */ | |
598 | if(llined) | |
599 | { | |
600 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
601 | "Link %s introduced leafed server %s.", | |
602 | client_p->name, parv[1]); | |
603 | ilog(L_SERVER, "Link %s introduced leafed server %s.", | |
604 | client_p->name, parv[1]); | |
605 | ||
606 | rb_snprintf(squitreason, sizeof squitreason, | |
607 | "Matching leaf_mask for %s", | |
608 | parv[1]); | |
609 | exit_client(NULL, client_p, &me, squitreason); | |
610 | return 0; | |
611 | } | |
612 | ||
613 | /* ok, alls good */ | |
614 | target_p = make_client(client_p); | |
615 | make_server(target_p); | |
616 | ||
617 | rb_strlcpy(target_p->name, parv[1], sizeof(target_p->name)); | |
618 | target_p->hopcount = atoi(parv[2]); | |
619 | strcpy(target_p->id, parv[3]); | |
620 | set_server_gecos(target_p, parv[4]); | |
621 | ||
622 | target_p->servptr = source_p; | |
623 | SetServer(target_p); | |
624 | ||
625 | rb_dlinkAddTail(target_p, &target_p->node, &global_client_list); | |
626 | rb_dlinkAddTailAlloc(target_p, &global_serv_list); | |
627 | add_to_client_hash(target_p->name, target_p); | |
628 | add_to_id_hash(target_p->id, target_p); | |
629 | rb_dlinkAdd(target_p, &target_p->lnode, &target_p->servptr->serv->servers); | |
630 | ||
631 | target_p->serv->nameinfo = scache_connect(target_p->name, target_p->info, IsHidden(target_p)); | |
632 | ||
633 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, | |
634 | ":%s SID %s %d %s :%s%s", | |
635 | source_p->id, target_p->name, target_p->hopcount + 1, | |
636 | target_p->id, IsHidden(target_p) ? "(H) " : "", target_p->info); | |
637 | ||
638 | sendto_realops_snomask(SNO_EXTERNAL, L_ALL, | |
639 | "Server %s being introduced by %s", target_p->name, source_p->name); | |
640 | ||
641 | /* quick, dirty EOB. you know you love it. */ | |
642 | sendto_one(target_p, ":%s PING %s %s", | |
643 | get_id(&me, target_p), me.name, get_id(target_p, target_p)); | |
644 | ||
645 | hdata.client = source_p; | |
646 | hdata.target = target_p; | |
647 | call_hook(h_server_introduced, &hdata); | |
648 | ||
649 | return 0; | |
650 | } | |
651 | ||
652 | /* set_server_gecos() | |
653 | * | |
654 | * input - pointer to client | |
655 | * output - none | |
656 | * side effects - servers gecos field is set | |
657 | */ | |
658 | static int | |
659 | set_server_gecos(struct Client *client_p, const char *info) | |
660 | { | |
661 | /* check the info for [IP] */ | |
662 | if(info[0]) | |
663 | { | |
664 | char *p; | |
665 | char *s; | |
666 | ||
667 | s = LOCAL_COPY(info); | |
668 | ||
669 | /* we should only check the first word for an ip */ | |
670 | if((p = strchr(s, ' '))) | |
671 | *p = '\0'; | |
672 | ||
673 | /* check for a ] which would symbolise an [IP] */ | |
674 | if(strchr(s, ']')) | |
675 | { | |
676 | /* set s to after the first space */ | |
677 | if(p) | |
678 | s = ++p; | |
679 | else | |
680 | s = NULL; | |
681 | } | |
682 | /* no ], put the space back */ | |
683 | else if(p) | |
684 | *p = ' '; | |
685 | ||
686 | /* p may have been set to a trailing space, so check s exists and that | |
687 | * it isnt \0 */ | |
688 | if(s && (*s != '\0')) | |
689 | { | |
690 | /* a space? if not (H) could be the last part of info.. */ | |
691 | if((p = strchr(s, ' '))) | |
692 | *p = '\0'; | |
693 | ||
694 | /* check for (H) which is a hidden server */ | |
695 | if(!strcmp(s, "(H)")) | |
696 | { | |
697 | SetHidden(client_p); | |
698 | ||
699 | /* if there was no space.. theres nothing to set info to */ | |
700 | if(p) | |
701 | s = ++p; | |
702 | else | |
703 | s = NULL; | |
704 | } | |
705 | else if(p) | |
706 | *p = ' '; | |
707 | ||
708 | /* if there was a trailing space, s could point to \0, so check */ | |
709 | if(s && (*s != '\0')) | |
710 | { | |
711 | rb_strlcpy(client_p->info, s, sizeof(client_p->info)); | |
712 | return 1; | |
713 | } | |
714 | } | |
715 | } | |
716 | ||
717 | rb_strlcpy(client_p->info, "(Unknown Location)", sizeof(client_p->info)); | |
718 | ||
719 | return 1; | |
720 | } | |
721 | ||
722 | /* | |
723 | * bogus_host | |
724 | * | |
725 | * inputs - hostname | |
726 | * output - 1 if a bogus hostname input, 0 if its valid | |
727 | * side effects - none | |
728 | */ | |
729 | int | |
730 | bogus_host(const char *host) | |
731 | { | |
732 | int bogus_server = 0; | |
733 | const char *s; | |
734 | int dots = 0; | |
735 | ||
736 | for(s = host; *s; s++) | |
737 | { | |
738 | if(!IsServChar(*s)) | |
739 | { | |
740 | bogus_server = 1; | |
741 | break; | |
742 | } | |
743 | if('.' == *s) | |
744 | ++dots; | |
745 | } | |
746 | ||
747 | if(!dots || bogus_server) | |
748 | return 1; | |
749 | ||
750 | return 0; | |
751 | } |