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