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