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