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