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