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