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