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