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