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