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