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