ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/conf.c
Revision: 1922
Committed: Tue Apr 30 15:08:42 2013 UTC (10 years, 11 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/src/conf.c
File size: 57739 byte(s)
Log Message:
- Moved report_confitem_types() to m_stats.c

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * conf.c: Configuration file functions.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h"
27 #include "ircd_defs.h"
28 #include "conf.h"
29 #include "s_serv.h"
30 #include "resv.h"
31 #include "channel.h"
32 #include "client.h"
33 #include "event.h"
34 #include "hook.h"
35 #include "irc_string.h"
36 #include "s_bsd.h"
37 #include "ircd.h"
38 #include "listener.h"
39 #include "hostmask.h"
40 #include "modules.h"
41 #include "numeric.h"
42 #include "fdlist.h"
43 #include "log.h"
44 #include "send.h"
45 #include "s_gline.h"
46 #include "memory.h"
47 #include "mempool.h"
48 #include "irc_res.h"
49 #include "userhost.h"
50 #include "s_user.h"
51 #include "channel_mode.h"
52 #include "parse.h"
53 #include "s_misc.h"
54 #include "conf_db.h"
55 #include "conf_class.h"
56
57 struct config_server_hide ConfigServerHide;
58
59 /* general conf items link list root, other than k lines etc. */
60 dlink_list service_items = { NULL, NULL, 0 };
61 dlink_list server_items = { NULL, NULL, 0 };
62 dlink_list cluster_items = { NULL, NULL, 0 };
63 dlink_list oconf_items = { NULL, NULL, 0 };
64 dlink_list uconf_items = { NULL, NULL, 0 };
65 dlink_list xconf_items = { NULL, NULL, 0 };
66 dlink_list nresv_items = { NULL, NULL, 0 };
67 dlink_list temporary_resv = { NULL, NULL, 0 };
68
69 extern unsigned int lineno;
70 extern char linebuf[];
71 extern char conffilebuf[IRCD_BUFSIZE];
72 extern int yyparse(); /* defined in y.tab.c */
73
74 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
75
76 /* internally defined functions */
77 static void read_conf(FILE *);
78 static void clear_out_old_conf(void);
79 static void expire_tklines(dlink_list *);
80 static void garbage_collect_ip_entries(void);
81 static int hash_ip(struct irc_ssaddr *);
82 static int verify_access(struct Client *);
83 static int attach_iline(struct Client *, struct MaskItem *);
84 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
85 static dlink_list *map_to_list(enum maskitem_type);
86 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
87
88
89 /* usually, with hash tables, you use a prime number...
90 * but in this case I am dealing with ip addresses,
91 * not ascii strings.
92 */
93 #define IP_HASH_SIZE 0x1000
94
95 struct ip_entry
96 {
97 struct irc_ssaddr ip;
98 unsigned int count;
99 time_t last_attempt;
100 struct ip_entry *next;
101 };
102
103 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
104 static mp_pool_t *ip_entry_pool = NULL;
105 static int ip_entries_count = 0;
106
107
108 /* conf_dns_callback()
109 *
110 * inputs - pointer to struct MaskItem
111 * - pointer to DNSReply reply
112 * output - none
113 * side effects - called when resolver query finishes
114 * if the query resulted in a successful search, hp will contain
115 * a non-null pointer, otherwise hp will be null.
116 * if successful save hp in the conf item it was called with
117 */
118 static void
119 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
120 {
121 struct MaskItem *conf = vptr;
122
123 conf->dns_pending = 0;
124
125 if (addr != NULL)
126 memcpy(&conf->addr, addr, sizeof(conf->addr));
127 else
128 conf->dns_failed = 1;
129 }
130
131 /* conf_dns_lookup()
132 *
133 * do a nameserver lookup of the conf host
134 * if the conf entry is currently doing a ns lookup do nothing, otherwise
135 * allocate a dns_query and start ns lookup.
136 */
137 static void
138 conf_dns_lookup(struct MaskItem *conf)
139 {
140 if (!conf->dns_pending)
141 {
142 conf->dns_pending = 1;
143 gethost_byname(conf_dns_callback, conf, conf->host);
144 }
145 }
146
147 struct MaskItem *
148 conf_make(enum maskitem_type type)
149 {
150 struct MaskItem *conf = MyMalloc(sizeof(*conf));
151 dlink_list *list = NULL;
152
153 conf->type = type;
154 conf->active = 1;
155 conf->aftype = AF_INET;
156
157 if ((list = map_to_list(type)))
158 dlinkAdd(conf, &conf->node, list);
159 return conf;
160 }
161
162 void
163 conf_free(struct MaskItem *conf)
164 {
165 dlink_node *ptr = NULL, *ptr_next = NULL;
166 dlink_list *list = NULL;
167
168 if (conf->node.next)
169 if ((list = map_to_list(conf->type)))
170 dlinkDelete(&conf->node, list);
171
172 MyFree(conf->name);
173
174 if (conf->dns_pending)
175 delete_resolver_queries(conf);
176 if (conf->passwd != NULL)
177 memset(conf->passwd, 0, strlen(conf->passwd));
178 if (conf->spasswd != NULL)
179 memset(conf->spasswd, 0, strlen(conf->spasswd));
180
181 conf->class = NULL;
182
183 MyFree(conf->passwd);
184 MyFree(conf->spasswd);
185 MyFree(conf->reason);
186 MyFree(conf->user);
187 MyFree(conf->host);
188 #ifdef HAVE_LIBCRYPTO
189 MyFree(conf->cipher_list);
190
191 if (conf->rsa_public_key)
192 RSA_free(conf->rsa_public_key);
193 #endif
194 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
195 {
196 MyFree(ptr->data);
197 free_dlink_node(ptr);
198 }
199
200 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
201 {
202 MyFree(ptr->data);
203 free_dlink_node(ptr);
204 }
205
206 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
207 {
208 struct exempt *exptr = ptr->data;
209
210 MyFree(exptr->name);
211 MyFree(exptr->user);
212 MyFree(exptr->host);
213 MyFree(exptr);
214 }
215
216 MyFree(conf);
217 }
218
219 /* check_client()
220 *
221 * inputs - pointer to client
222 * output - 0 = Success
223 * NOT_AUTHORIZED (-1) = Access denied (no I line match)
224 * IRCD_SOCKET_ERROR (-2) = Bad socket.
225 * I_LINE_FULL (-3) = I-line is full
226 * TOO_MANY (-4) = Too many connections from hostname
227 * BANNED_CLIENT (-5) = K-lined
228 * side effects - Ordinary client access check.
229 * Look for conf lines which have the same
230 * status as the flags passed.
231 */
232 int
233 check_client(struct Client *source_p)
234 {
235 int i;
236
237 if ((i = verify_access(source_p)))
238 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
239 source_p->name, source_p->sockhost);
240
241 switch (i)
242 {
243 case TOO_MANY:
244 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
245 "Too many on IP for %s (%s).",
246 get_client_name(source_p, SHOW_IP),
247 source_p->sockhost);
248 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
249 get_client_name(source_p, SHOW_IP));
250 ++ServerStats.is_ref;
251 exit_client(source_p, &me, "No more connections allowed on that IP");
252 break;
253
254 case I_LINE_FULL:
255 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
256 "auth{} block is full for %s (%s).",
257 get_client_name(source_p, SHOW_IP),
258 source_p->sockhost);
259 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
260 get_client_name(source_p, SHOW_IP));
261 ++ServerStats.is_ref;
262 exit_client(source_p, &me,
263 "No more connections allowed in your connection class");
264 break;
265
266 case NOT_AUTHORIZED:
267 ++ServerStats.is_ref;
268 /* jdc - lists server name & port connections are on */
269 /* a purely cosmetical change */
270 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
271 "Unauthorized client connection from %s [%s] on [%s/%u].",
272 get_client_name(source_p, SHOW_IP),
273 source_p->sockhost,
274 source_p->localClient->listener->name,
275 source_p->localClient->listener->port);
276 ilog(LOG_TYPE_IRCD,
277 "Unauthorized client connection from %s on [%s/%u].",
278 get_client_name(source_p, SHOW_IP),
279 source_p->localClient->listener->name,
280 source_p->localClient->listener->port);
281
282 exit_client(source_p, &me, "You are not authorized to use this server");
283 break;
284
285 case BANNED_CLIENT:
286 exit_client(source_p, &me, "Banned");
287 ++ServerStats.is_ref;
288 break;
289
290 case 0:
291 default:
292 break;
293 }
294
295 return (i < 0 ? 0 : 1);
296 }
297
298 /* verify_access()
299 *
300 * inputs - pointer to client to verify
301 * output - 0 if success -'ve if not
302 * side effect - find the first (best) I line to attach.
303 */
304 static int
305 verify_access(struct Client *client_p)
306 {
307 struct MaskItem *conf = NULL, *rkconf = NULL;
308 char non_ident[USERLEN + 1] = { '~', '\0' };
309
310 if (IsGotId(client_p))
311 {
312 conf = find_address_conf(client_p->host, client_p->username,
313 &client_p->localClient->ip,
314 client_p->localClient->aftype,
315 client_p->localClient->passwd);
316 }
317 else
318 {
319 strlcpy(non_ident+1, client_p->username, sizeof(non_ident)-1);
320 conf = find_address_conf(client_p->host,non_ident,
321 &client_p->localClient->ip,
322 client_p->localClient->aftype,
323 client_p->localClient->passwd);
324 }
325
326 if (conf != NULL)
327 {
328 if (IsConfClient(conf))
329 {
330 if (IsConfRedir(conf))
331 {
332 sendto_one(client_p, form_str(RPL_REDIR),
333 me.name, client_p->name,
334 conf->name ? conf->name : "",
335 conf->port);
336 return(NOT_AUTHORIZED);
337 }
338
339 if (IsConfDoIdentd(conf))
340 SetNeedId(client_p);
341
342 /* Thanks for spoof idea amm */
343 if (IsConfDoSpoofIp(conf))
344 {
345 if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
346 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
347 "%s spoofing: %s as %s",
348 client_p->name, client_p->host, conf->name);
349 strlcpy(client_p->host, conf->name, sizeof(client_p->host));
350 SetIPSpoof(client_p);
351 }
352
353 return(attach_iline(client_p, conf));
354 }
355 else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
356 {
357 if (IsConfGline(conf))
358 sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
359 client_p->name);
360 sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
361 me.name, client_p->name, conf->reason);
362 return(BANNED_CLIENT);
363 }
364 }
365
366 return(NOT_AUTHORIZED);
367 }
368
369 /* attach_iline()
370 *
371 * inputs - client pointer
372 * - conf pointer
373 * output -
374 * side effects - do actual attach
375 */
376 static int
377 attach_iline(struct Client *client_p, struct MaskItem *conf)
378 {
379 struct ClassItem *class = NULL;
380 struct ip_entry *ip_found;
381 int a_limit_reached = 0;
382 unsigned int local = 0, global = 0, ident = 0;
383
384 ip_found = find_or_add_ip(&client_p->localClient->ip);
385 ip_found->count++;
386 SetIpHash(client_p);
387
388 if (conf->class == NULL)
389 return NOT_AUTHORIZED; /* If class is missing, this is best */
390
391 class = conf->class;
392
393 count_user_host(client_p->username, client_p->host,
394 &global, &local, &ident);
395
396 /* XXX blah. go down checking the various silly limits
397 * setting a_limit_reached if any limit is reached.
398 * - Dianora
399 */
400 if (class->max_total != 0 && class->ref_count >= class->max_total)
401 a_limit_reached = 1;
402 else if (class->max_perip != 0 && ip_found->count > class->max_perip)
403 a_limit_reached = 1;
404 else if (class->max_local != 0 && local >= class->max_local)
405 a_limit_reached = 1;
406 else if (class->max_global != 0 && global >= class->max_global)
407 a_limit_reached = 1;
408 else if (class->max_ident != 0 && ident >= class->max_ident &&
409 client_p->username[0] != '~')
410 a_limit_reached = 1;
411
412 if (a_limit_reached)
413 {
414 if (!IsConfExemptLimits(conf))
415 return TOO_MANY; /* Already at maximum allowed */
416
417 sendto_one(client_p,
418 ":%s NOTICE %s :*** Your connection class is full, "
419 "but you have exceed_limit = yes;", me.name, client_p->name);
420 }
421
422 return attach_conf(client_p, conf);
423 }
424
425 /* init_ip_hash_table()
426 *
427 * inputs - NONE
428 * output - NONE
429 * side effects - allocate memory for ip_entry(s)
430 * - clear the ip hash table
431 */
432 void
433 init_ip_hash_table(void)
434 {
435 ip_entry_pool = mp_pool_new(sizeof(struct ip_entry),
436 2 * hard_fdlimit);
437 memset(ip_hash_table, 0, sizeof(ip_hash_table));
438 }
439
440 /* find_or_add_ip()
441 *
442 * inputs - pointer to struct irc_ssaddr
443 * output - pointer to a struct ip_entry
444 * side effects -
445 *
446 * If the ip # was not found, a new struct ip_entry is created, and the ip
447 * count set to 0.
448 */
449 static struct ip_entry *
450 find_or_add_ip(struct irc_ssaddr *ip_in)
451 {
452 struct ip_entry *ptr, *newptr;
453 int hash_index = hash_ip(ip_in), res;
454 struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
455 #ifdef IPV6
456 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
457 #endif
458
459 for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
460 {
461 #ifdef IPV6
462 if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
463 continue;
464 if (ip_in->ss.ss_family == AF_INET6)
465 {
466 ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
467 res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
468 }
469 else
470 #endif
471 {
472 ptr_v4 = (struct sockaddr_in *)&ptr->ip;
473 res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
474 }
475 if (res == 0)
476 {
477 /* Found entry already in hash, return it. */
478 return ptr;
479 }
480 }
481
482 if (ip_entries_count >= 2 * hard_fdlimit)
483 garbage_collect_ip_entries();
484
485 newptr = mp_pool_get(ip_entry_pool);
486 memset(newptr, 0, sizeof(*newptr));
487 ip_entries_count++;
488 memcpy(&newptr->ip, ip_in, sizeof(struct irc_ssaddr));
489
490 newptr->next = ip_hash_table[hash_index];
491 ip_hash_table[hash_index] = newptr;
492
493 return newptr;
494 }
495
496 /* remove_one_ip()
497 *
498 * inputs - unsigned long IP address value
499 * output - NONE
500 * side effects - The ip address given, is looked up in ip hash table
501 * and number of ip#'s for that ip decremented.
502 * If ip # count reaches 0 and has expired,
503 * the struct ip_entry is returned to the ip_entry_heap
504 */
505 void
506 remove_one_ip(struct irc_ssaddr *ip_in)
507 {
508 struct ip_entry *ptr;
509 struct ip_entry *last_ptr = NULL;
510 int hash_index = hash_ip(ip_in), res;
511 struct sockaddr_in *v4 = (struct sockaddr_in *)ip_in, *ptr_v4;
512 #ifdef IPV6
513 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)ip_in, *ptr_v6;
514 #endif
515
516 for (ptr = ip_hash_table[hash_index]; ptr; ptr = ptr->next)
517 {
518 #ifdef IPV6
519 if (ptr->ip.ss.ss_family != ip_in->ss.ss_family)
520 continue;
521 if (ip_in->ss.ss_family == AF_INET6)
522 {
523 ptr_v6 = (struct sockaddr_in6 *)&ptr->ip;
524 res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr));
525 }
526 else
527 #endif
528 {
529 ptr_v4 = (struct sockaddr_in *)&ptr->ip;
530 res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr));
531 }
532 if (res)
533 continue;
534 if (ptr->count > 0)
535 ptr->count--;
536 if (ptr->count == 0 &&
537 (CurrentTime-ptr->last_attempt) >= ConfigFileEntry.throttle_time)
538 {
539 if (last_ptr != NULL)
540 last_ptr->next = ptr->next;
541 else
542 ip_hash_table[hash_index] = ptr->next;
543
544 mp_pool_release(ptr);
545 ip_entries_count--;
546 return;
547 }
548 last_ptr = ptr;
549 }
550 }
551
552 /* hash_ip()
553 *
554 * input - pointer to an irc_inaddr
555 * output - integer value used as index into hash table
556 * side effects - hopefully, none
557 */
558 static int
559 hash_ip(struct irc_ssaddr *addr)
560 {
561 if (addr->ss.ss_family == AF_INET)
562 {
563 struct sockaddr_in *v4 = (struct sockaddr_in *)addr;
564 int hash;
565 uint32_t ip;
566
567 ip = ntohl(v4->sin_addr.s_addr);
568 hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1);
569 return hash;
570 }
571 #ifdef IPV6
572 else
573 {
574 int hash;
575 struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr;
576 uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr;
577
578 hash = ip[0] ^ ip[3];
579 hash ^= hash >> 16;
580 hash ^= hash >> 8;
581 hash = hash & (IP_HASH_SIZE - 1);
582 return hash;
583 }
584 #else
585 return 0;
586 #endif
587 }
588
589 /* count_ip_hash()
590 *
591 * inputs - pointer to counter of number of ips hashed
592 * - pointer to memory used for ip hash
593 * output - returned via pointers input
594 * side effects - NONE
595 *
596 * number of hashed ip #'s is counted up, plus the amount of memory
597 * used in the hash.
598 */
599 void
600 count_ip_hash(unsigned int *number_ips_stored, uint64_t *mem_ips_stored)
601 {
602 struct ip_entry *ptr;
603 int i;
604
605 *number_ips_stored = 0;
606 *mem_ips_stored = 0;
607
608 for (i = 0; i < IP_HASH_SIZE; i++)
609 {
610 for (ptr = ip_hash_table[i]; ptr; ptr = ptr->next)
611 {
612 *number_ips_stored += 1;
613 *mem_ips_stored += sizeof(struct ip_entry);
614 }
615 }
616 }
617
618 /* garbage_collect_ip_entries()
619 *
620 * input - NONE
621 * output - NONE
622 * side effects - free up all ip entries with no connections
623 */
624 static void
625 garbage_collect_ip_entries(void)
626 {
627 struct ip_entry *ptr;
628 struct ip_entry *last_ptr;
629 struct ip_entry *next_ptr;
630 int i;
631
632 for (i = 0; i < IP_HASH_SIZE; i++)
633 {
634 last_ptr = NULL;
635
636 for (ptr = ip_hash_table[i]; ptr; ptr = next_ptr)
637 {
638 next_ptr = ptr->next;
639
640 if (ptr->count == 0 &&
641 (CurrentTime - ptr->last_attempt) >= ConfigFileEntry.throttle_time)
642 {
643 if (last_ptr != NULL)
644 last_ptr->next = ptr->next;
645 else
646 ip_hash_table[i] = ptr->next;
647 mp_pool_release(ptr);
648 ip_entries_count--;
649 }
650 else
651 last_ptr = ptr;
652 }
653 }
654 }
655
656 /* detach_conf()
657 *
658 * inputs - pointer to client to detach
659 * - type of conf to detach
660 * output - 0 for success, -1 for failure
661 * side effects - Disassociate configuration from the client.
662 * Also removes a class from the list if marked for deleting.
663 */
664 void
665 detach_conf(struct Client *client_p, enum maskitem_type type)
666 {
667 dlink_node *ptr = NULL, *next_ptr = NULL;
668
669 DLINK_FOREACH_SAFE(ptr, next_ptr, client_p->localClient->confs.head)
670 {
671 struct MaskItem *conf = ptr->data;
672
673 assert(conf->type & (CONF_CLIENT | CONF_OPER | CONF_SERVER));
674 assert(conf->ref_count > 0);
675 assert(conf->class->ref_count > 0);
676
677 if (!(conf->type & type))
678 continue;
679
680 dlinkDelete(ptr, &client_p->localClient->confs);
681 free_dlink_node(ptr);
682
683 if (conf->type == CONF_CLIENT)
684 remove_from_cidr_check(&client_p->localClient->ip, conf->class);
685
686 if (--conf->class->ref_count == 0 && conf->class->active == 0)
687 {
688 class_free(conf->class);
689 conf->class = NULL;
690 }
691
692 if (--conf->ref_count == 0 && conf->active == 0)
693 conf_free(conf);
694 }
695 }
696
697 /* attach_conf()
698 *
699 * inputs - client pointer
700 * - conf pointer
701 * output -
702 * side effects - Associate a specific configuration entry to a *local*
703 * client (this is the one which used in accepting the
704 * connection). Note, that this automatically changes the
705 * attachment if there was an old one...
706 */
707 int
708 attach_conf(struct Client *client_p, struct MaskItem *conf)
709 {
710 if (dlinkFind(&client_p->localClient->confs, conf) != NULL)
711 return 1;
712
713 if (conf->type == CONF_CLIENT)
714 if (cidr_limit_reached(IsConfExemptLimits(conf),
715 &client_p->localClient->ip, conf->class))
716 return TOO_MANY; /* Already at maximum allowed */
717
718 conf->class->ref_count++;
719 conf->ref_count++;
720
721 dlinkAdd(conf, make_dlink_node(), &client_p->localClient->confs);
722
723 return 0;
724 }
725
726 /* attach_connect_block()
727 *
728 * inputs - pointer to server to attach
729 * - name of server
730 * - hostname of server
731 * output - true (1) if both are found, otherwise return false (0)
732 * side effects - find connect block and attach them to connecting client
733 */
734 int
735 attach_connect_block(struct Client *client_p, const char *name,
736 const char *host)
737 {
738 dlink_node *ptr;
739 struct MaskItem *conf = NULL;
740
741 assert(client_p != NULL);
742 assert(host != NULL);
743
744 if (client_p == NULL || host == NULL)
745 return 0;
746
747 DLINK_FOREACH(ptr, server_items.head)
748 {
749 conf = ptr->data;
750
751 if (match(conf->name, name) || match(conf->host, host))
752 continue;
753
754 attach_conf(client_p, conf);
755 return -1;
756 }
757
758 return 0;
759 }
760
761 /* find_conf_name()
762 *
763 * inputs - pointer to conf link list to search
764 * - pointer to name to find
765 * - int mask of type of conf to find
766 * output - NULL or pointer to conf found
767 * side effects - find a conf entry which matches the name
768 * and has the given mask.
769 */
770 struct MaskItem *
771 find_conf_name(dlink_list *list, const char *name, enum maskitem_type type)
772 {
773 dlink_node *ptr;
774 struct MaskItem* conf;
775
776 DLINK_FOREACH(ptr, list->head)
777 {
778 conf = ptr->data;
779
780 if (conf->type == type)
781 {
782 if (conf->name && (irccmp(conf->name, name) == 0 ||
783 !match(conf->name, name)))
784 return conf;
785 }
786 }
787
788 return NULL;
789 }
790
791 /* map_to_list()
792 *
793 * inputs - ConfType conf
794 * output - pointer to dlink_list to use
795 * side effects - none
796 */
797 static dlink_list *
798 map_to_list(enum maskitem_type type)
799 {
800 switch(type)
801 {
802 case CONF_XLINE:
803 return(&xconf_items);
804 break;
805 case CONF_ULINE:
806 return(&uconf_items);
807 break;
808 case CONF_NRESV:
809 return(&nresv_items);
810 break;
811 case CONF_CRESV:
812 return(&resv_channel_list);
813 case CONF_OPER:
814 return(&oconf_items);
815 break;
816 case CONF_SERVER:
817 return(&server_items);
818 break;
819 case CONF_SERVICE:
820 return(&service_items);
821 break;
822 case CONF_CLUSTER:
823 return(&cluster_items);
824 break;
825 default:
826 return NULL;
827 }
828 }
829
830 /* find_matching_name_conf()
831 *
832 * inputs - type of link list to look in
833 * - pointer to name string to find
834 * - pointer to user
835 * - pointer to host
836 * - optional flags to match on as well
837 * output - NULL or pointer to found struct MaskItem
838 * side effects - looks for a match on name field
839 */
840 struct MaskItem *
841 find_matching_name_conf(enum maskitem_type type, const char *name, const char *user,
842 const char *host, unsigned int flags)
843 {
844 dlink_node *ptr=NULL;
845 struct MaskItem *conf=NULL;
846 dlink_list *list_p = map_to_list(type);
847
848 switch (type)
849 {
850 case CONF_SERVICE:
851 DLINK_FOREACH(ptr, list_p->head)
852 {
853 conf = ptr->data;
854
855 if (EmptyString(conf->name))
856 continue;
857 if ((name != NULL) && !irccmp(name, conf->name))
858 return conf;
859 }
860 break;
861
862 case CONF_XLINE:
863 case CONF_ULINE:
864 case CONF_NRESV:
865 case CONF_CRESV:
866 DLINK_FOREACH(ptr, list_p->head)
867 {
868 conf = ptr->data;
869
870 if (EmptyString(conf->name))
871 continue;
872 if ((name != NULL) && !match(conf->name, name))
873 {
874 if ((user == NULL && (host == NULL)))
875 return conf;
876 if ((conf->flags & flags) != flags)
877 continue;
878 if (EmptyString(conf->user) || EmptyString(conf->host))
879 return conf;
880 if (!match(conf->user, user) && !match(conf->host, host))
881 return conf;
882 }
883 }
884 break;
885
886 case CONF_SERVER:
887 DLINK_FOREACH(ptr, list_p->head)
888 {
889 conf = ptr->data;
890
891 if ((name != NULL) && !match(name, conf->name))
892 return conf;
893 else if ((host != NULL) && !match(host, conf->host))
894 return conf;
895 }
896 break;
897
898 default:
899 break;
900 }
901 return NULL;
902 }
903
904 /* find_exact_name_conf()
905 *
906 * inputs - type of link list to look in
907 * - pointer to name string to find
908 * - pointer to user
909 * - pointer to host
910 * output - NULL or pointer to found struct MaskItem
911 * side effects - looks for an exact match on name field
912 */
913 struct MaskItem *
914 find_exact_name_conf(enum maskitem_type type, const struct Client *who, const char *name,
915 const char *user, const char *host)
916 {
917 dlink_node *ptr = NULL;
918 struct MaskItem *conf;
919 dlink_list *list_p = map_to_list(type);
920
921 switch(type)
922 {
923 case CONF_XLINE:
924 case CONF_ULINE:
925 case CONF_NRESV:
926 case CONF_CRESV:
927
928 DLINK_FOREACH(ptr, list_p->head)
929 {
930 conf = ptr->data;
931
932 if (EmptyString(conf->name))
933 continue;
934
935 if (irccmp(conf->name, name) == 0)
936 {
937 if ((user == NULL && (host == NULL)))
938 return (conf);
939 if (EmptyString(conf->user) || EmptyString(conf->host))
940 return (conf);
941 if (!match(conf->user, user) && !match(conf->host, host))
942 return (conf);
943 }
944 }
945 break;
946
947 case CONF_OPER:
948 DLINK_FOREACH(ptr, list_p->head)
949 {
950 conf = ptr->data;
951
952 if (EmptyString(conf->name))
953 continue;
954
955 if (!irccmp(conf->name, name))
956 {
957 if (!who)
958 return conf;
959 if (EmptyString(conf->user) || EmptyString(conf->host))
960 return NULL;
961 if (!match(conf->user, who->username))
962 {
963 switch (conf->htype)
964 {
965 case HM_HOST:
966 if (!match(conf->host, who->host) || !match(conf->host, who->sockhost))
967 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
968 return conf;
969 break;
970 case HM_IPV4:
971 if (who->localClient->aftype == AF_INET)
972 if (match_ipv4(&who->localClient->ip, &conf->addr, conf->bits))
973 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
974 return conf;
975 break;
976 #ifdef IPV6
977 case HM_IPV6:
978 if (who->localClient->aftype == AF_INET6)
979 if (match_ipv6(&who->localClient->ip, &conf->addr, conf->bits))
980 if (!conf->class->max_total || conf->class->ref_count < conf->class->max_total)
981 return conf;
982 break;
983 #endif
984 default:
985 assert(0);
986 }
987 }
988 }
989 }
990
991 break;
992
993 case CONF_SERVER:
994 DLINK_FOREACH(ptr, list_p->head)
995 {
996 conf = ptr->data;
997
998 if (EmptyString(conf->name))
999 continue;
1000
1001 if (name == NULL)
1002 {
1003 if (EmptyString(conf->host))
1004 continue;
1005 if (irccmp(conf->host, host) == 0)
1006 return(conf);
1007 }
1008 else if (irccmp(conf->name, name) == 0)
1009 {
1010 return (conf);
1011 }
1012 }
1013 break;
1014
1015 default:
1016 break;
1017 }
1018 return(NULL);
1019 }
1020
1021 /* rehash()
1022 *
1023 * Actual REHASH service routine. Called with sig == 0 if it has been called
1024 * as a result of an operator issuing this command, else assume it has been
1025 * called as a result of the server receiving a HUP signal.
1026 */
1027 int
1028 rehash(int sig)
1029 {
1030 if (sig != 0)
1031 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1032 "Got signal SIGHUP, reloading ircd.conf file");
1033
1034 restart_resolver();
1035
1036 /* don't close listeners until we know we can go ahead with the rehash */
1037
1038 /* Check to see if we magically got(or lost) IPv6 support */
1039 check_can_use_v6();
1040
1041 read_conf_files(0);
1042
1043 if (ServerInfo.description != NULL)
1044 strlcpy(me.info, ServerInfo.description, sizeof(me.info));
1045
1046 load_conf_modules();
1047
1048 rehashed_klines = 1;
1049
1050 return 0;
1051 }
1052
1053 /* set_default_conf()
1054 *
1055 * inputs - NONE
1056 * output - NONE
1057 * side effects - Set default values here.
1058 * This is called **PRIOR** to parsing the
1059 * configuration file. If you want to do some validation
1060 * of values later, put them in validate_conf().
1061 */
1062 static void
1063 set_default_conf(void)
1064 {
1065 /* verify init_class() ran, this should be an unnecessary check
1066 * but its not much work.
1067 */
1068 assert(class_default == class_get_list()->tail->data);
1069
1070 #ifdef HAVE_LIBCRYPTO
1071 ServerInfo.rsa_private_key = NULL;
1072 ServerInfo.rsa_private_key_file = NULL;
1073 #endif
1074
1075 /* ServerInfo.name is not rehashable */
1076 /* ServerInfo.name = ServerInfo.name; */
1077 ServerInfo.description = NULL;
1078 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1079 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1080
1081 memset(&ServerInfo.ip, 0, sizeof(ServerInfo.ip));
1082 ServerInfo.specific_ipv4_vhost = 0;
1083 memset(&ServerInfo.ip6, 0, sizeof(ServerInfo.ip6));
1084 ServerInfo.specific_ipv6_vhost = 0;
1085
1086 ServerInfo.max_clients = MAXCLIENTS_MAX;
1087 ServerInfo.max_nick_length = 9;
1088 ServerInfo.max_topic_length = 80;
1089
1090 ServerInfo.hub = 0;
1091 ServerInfo.dns_host.sin_addr.s_addr = 0;
1092 ServerInfo.dns_host.sin_port = 0;
1093 AdminInfo.name = NULL;
1094 AdminInfo.email = NULL;
1095 AdminInfo.description = NULL;
1096
1097 log_del_all();
1098
1099 ConfigLoggingEntry.use_logging = 1;
1100
1101 ConfigChannel.disable_fake_channels = 0;
1102 ConfigChannel.knock_delay = 300;
1103 ConfigChannel.knock_delay_channel = 60;
1104 ConfigChannel.max_chans_per_user = 25;
1105 ConfigChannel.max_chans_per_oper = 50;
1106 ConfigChannel.quiet_on_ban = 1;
1107 ConfigChannel.max_bans = 25;
1108 ConfigChannel.default_split_user_count = 0;
1109 ConfigChannel.default_split_server_count = 0;
1110 ConfigChannel.no_join_on_split = 0;
1111 ConfigChannel.no_create_on_split = 0;
1112
1113 ConfigServerHide.flatten_links = 0;
1114 ConfigServerHide.links_delay = 300;
1115 ConfigServerHide.hidden = 0;
1116 ConfigServerHide.hide_servers = 0;
1117 ConfigServerHide.hide_services = 0;
1118 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1119 ConfigServerHide.hide_server_ips = 0;
1120
1121
1122 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1123 ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1124 ConfigFileEntry.glines = 0;
1125 ConfigFileEntry.gline_time = 12 * 3600;
1126 ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1127 ConfigFileEntry.gline_min_cidr = 16;
1128 ConfigFileEntry.gline_min_cidr6 = 48;
1129 ConfigFileEntry.invisible_on_connect = 1;
1130 ConfigFileEntry.tkline_expire_notices = 1;
1131 ConfigFileEntry.hide_spoof_ips = 1;
1132 ConfigFileEntry.ignore_bogus_ts = 0;
1133 ConfigFileEntry.disable_auth = 0;
1134 ConfigFileEntry.disable_remote = 0;
1135 ConfigFileEntry.kill_chase_time_limit = 90;
1136 ConfigFileEntry.default_floodcount = 8;
1137 ConfigFileEntry.failed_oper_notice = 1;
1138 ConfigFileEntry.dots_in_ident = 0;
1139 ConfigFileEntry.min_nonwildcard = 4;
1140 ConfigFileEntry.min_nonwildcard_simple = 3;
1141 ConfigFileEntry.max_accept = 20;
1142 ConfigFileEntry.anti_nick_flood = 0;
1143 ConfigFileEntry.max_nick_time = 20;
1144 ConfigFileEntry.max_nick_changes = 5;
1145 ConfigFileEntry.anti_spam_exit_message_time = 0;
1146 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1147 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1148 ConfigFileEntry.warn_no_nline = 1;
1149 ConfigFileEntry.stats_o_oper_only = 0;
1150 ConfigFileEntry.stats_k_oper_only = 1; /* masked */
1151 ConfigFileEntry.stats_i_oper_only = 1; /* masked */
1152 ConfigFileEntry.stats_P_oper_only = 0;
1153 ConfigFileEntry.caller_id_wait = 60;
1154 ConfigFileEntry.opers_bypass_callerid = 0;
1155 ConfigFileEntry.pace_wait = 10;
1156 ConfigFileEntry.pace_wait_simple = 1;
1157 ConfigFileEntry.short_motd = 0;
1158 ConfigFileEntry.ping_cookie = 0;
1159 ConfigFileEntry.no_oper_flood = 0;
1160 ConfigFileEntry.true_no_oper_flood = 0;
1161 ConfigFileEntry.oper_pass_resv = 1;
1162 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1163 ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1164 ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1165 UMODE_OPERWALL | UMODE_WALLOP;
1166 ConfigFileEntry.use_egd = 0;
1167 ConfigFileEntry.egdpool_path = NULL;
1168 ConfigFileEntry.throttle_time = 10;
1169 }
1170
1171 static void
1172 validate_conf(void)
1173 {
1174 if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1175 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1176
1177 if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1178 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1179
1180 if (ServerInfo.network_name == NULL)
1181 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1182
1183 if (ServerInfo.network_desc == NULL)
1184 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1185
1186 if (ConfigFileEntry.service_name == NULL)
1187 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1188
1189 ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1190 }
1191
1192 /* read_conf()
1193 *
1194 * inputs - file descriptor pointing to config file to use
1195 * output - None
1196 * side effects - Read configuration file.
1197 */
1198 static void
1199 read_conf(FILE *file)
1200 {
1201 lineno = 0;
1202
1203 set_default_conf(); /* Set default values prior to conf parsing */
1204 conf_parser_ctx.pass = 1;
1205 yyparse(); /* pick up the classes first */
1206
1207 rewind(file);
1208
1209 conf_parser_ctx.pass = 2;
1210 yyparse(); /* Load the values from the conf */
1211 validate_conf(); /* Check to make sure some values are still okay. */
1212 /* Some global values are also loaded here. */
1213 class_delete_marked(); /* Make sure classes are valid */
1214 }
1215
1216 /* lookup_confhost()
1217 *
1218 * start DNS lookups of all hostnames in the conf
1219 * line and convert an IP addresses in a.b.c.d number for to IP#s.
1220 */
1221 void
1222 lookup_confhost(struct MaskItem *conf)
1223 {
1224 struct addrinfo hints, *res;
1225
1226 /* Do name lookup now on hostnames given and store the
1227 * ip numbers in conf structure.
1228 */
1229 memset(&hints, 0, sizeof(hints));
1230
1231 hints.ai_family = AF_UNSPEC;
1232 hints.ai_socktype = SOCK_STREAM;
1233
1234 /* Get us ready for a bind() and don't bother doing dns lookup */
1235 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1236
1237 if (getaddrinfo(conf->host, NULL, &hints, &res))
1238 {
1239 conf_dns_lookup(conf);
1240 return;
1241 }
1242
1243 assert(res != NULL);
1244
1245 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1246 conf->addr.ss_len = res->ai_addrlen;
1247 conf->addr.ss.ss_family = res->ai_family;
1248
1249 freeaddrinfo(res);
1250 }
1251
1252 /* conf_connect_allowed()
1253 *
1254 * inputs - pointer to inaddr
1255 * - int type ipv4 or ipv6
1256 * output - BANNED or accepted
1257 * side effects - none
1258 */
1259 int
1260 conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1261 {
1262 struct ip_entry *ip_found;
1263 struct MaskItem *conf = find_dline_conf(addr, aftype);
1264
1265 /* DLINE exempt also gets you out of static limits/pacing... */
1266 if (conf && (conf->type == CONF_EXEMPT))
1267 return 0;
1268
1269 if (conf != NULL)
1270 return BANNED_CLIENT;
1271
1272 ip_found = find_or_add_ip(addr);
1273
1274 if ((CurrentTime - ip_found->last_attempt) <
1275 ConfigFileEntry.throttle_time)
1276 {
1277 ip_found->last_attempt = CurrentTime;
1278 return TOO_FAST;
1279 }
1280
1281 ip_found->last_attempt = CurrentTime;
1282 return 0;
1283 }
1284
1285 /* find_kill()
1286 *
1287 * inputs - pointer to client structure
1288 * output - pointer to struct MaskItem if found
1289 * side effects - See if this user is klined already,
1290 * and if so, return struct MaskItem pointer
1291 */
1292 struct MaskItem *
1293 find_kill(struct Client *client_p)
1294 {
1295 struct MaskItem *conf = NULL;
1296
1297 assert(client_p != NULL);
1298
1299 conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1300 CONF_KLINE, client_p->localClient->aftype,
1301 client_p->username, NULL, 1);
1302 return conf;
1303 }
1304
1305 struct MaskItem *
1306 find_gline(struct Client *client_p)
1307 {
1308 struct MaskItem *conf;
1309
1310 assert(client_p != NULL);
1311
1312 conf = find_conf_by_address(client_p->host, &client_p->localClient->ip,
1313 CONF_GLINE, client_p->localClient->aftype,
1314 client_p->username, NULL, 1);
1315 return conf;
1316 }
1317
1318 /* cleanup_tklines()
1319 *
1320 * inputs - NONE
1321 * output - NONE
1322 * side effects - call function to expire temporary k/d lines
1323 * This is an event started off in ircd.c
1324 */
1325 void
1326 cleanup_tklines(void *notused)
1327 {
1328 hostmask_expire_temporary();
1329 expire_tklines(&xconf_items);
1330 expire_tklines(&nresv_items);
1331 expire_tklines(&resv_channel_list);
1332 }
1333
1334 /* expire_tklines()
1335 *
1336 * inputs - tkline list pointer
1337 * output - NONE
1338 * side effects - expire tklines
1339 */
1340 static void
1341 expire_tklines(dlink_list *tklist)
1342 {
1343 dlink_node *ptr;
1344 dlink_node *next_ptr;
1345 struct MaskItem *conf;
1346
1347 DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1348 {
1349 conf = ptr->data;
1350
1351 if (!conf->until || conf->until > CurrentTime)
1352 continue;
1353
1354 if (conf->type == CONF_XLINE)
1355 {
1356 if (ConfigFileEntry.tkline_expire_notices)
1357 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1358 "Temporary X-line for [%s] expired", conf->name);
1359 conf_free(conf);
1360 }
1361 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1362 {
1363 if (ConfigFileEntry.tkline_expire_notices)
1364 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1365 "Temporary RESV for [%s] expired", conf->name);
1366 conf_free(conf);
1367 }
1368 }
1369 }
1370
1371 /* oper_privs_as_string()
1372 *
1373 * inputs - pointer to client_p
1374 * output - pointer to static string showing oper privs
1375 * side effects - return as string, the oper privs as derived from port
1376 */
1377 static const struct oper_privs
1378 {
1379 const unsigned int flag;
1380 const unsigned char c;
1381 } flag_list[] = {
1382 { OPER_FLAG_ADMIN, 'A' },
1383 { OPER_FLAG_REMOTEBAN, 'B' },
1384 { OPER_FLAG_DIE, 'D' },
1385 { OPER_FLAG_GLINE, 'G' },
1386 { OPER_FLAG_REHASH, 'H' },
1387 { OPER_FLAG_K, 'K' },
1388 { OPER_FLAG_OPERWALL, 'L' },
1389 { OPER_FLAG_GLOBAL_KILL, 'O' },
1390 { OPER_FLAG_REMOTE, 'R' },
1391 { OPER_FLAG_OPER_SPY, 'S' },
1392 { OPER_FLAG_UNKLINE, 'U' },
1393 { OPER_FLAG_X, 'X' },
1394 { 0, '\0' }
1395 };
1396
1397 char *
1398 oper_privs_as_string(const unsigned int port)
1399 {
1400 static char privs_out[16];
1401 char *privs_ptr = privs_out;
1402 const struct oper_privs *opriv = flag_list;
1403
1404 for (; opriv->flag; ++opriv)
1405 {
1406 if (port & opriv->flag)
1407 *privs_ptr++ = opriv->c;
1408 else
1409 *privs_ptr++ = ToLower(opriv->c);
1410 }
1411
1412 *privs_ptr = '\0';
1413
1414 return privs_out;
1415 }
1416
1417 /*
1418 * Input: A client to find the active oper{} name for.
1419 * Output: The nick!user@host{oper} of the oper.
1420 * "oper" is server name for remote opers
1421 * Side effects: None.
1422 */
1423 const char *
1424 get_oper_name(const struct Client *client_p)
1425 {
1426 dlink_node *cnode = NULL;
1427 /* +5 for !,@,{,} and null */
1428 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1429
1430 if (MyConnect(client_p))
1431 {
1432 if ((cnode = client_p->localClient->confs.head))
1433 {
1434 struct MaskItem *conf = cnode->data;
1435
1436 if (IsConfOperator(conf))
1437 {
1438 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1439 client_p->username, client_p->host, conf->name);
1440 return buffer;
1441 }
1442 }
1443
1444 /* Probably should assert here for now. If there is an oper out there
1445 * with no oper{} conf attached, it would be good for us to know...
1446 */
1447 assert(0); /* Oper without oper conf! */
1448 }
1449
1450 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1451 client_p->username, client_p->host, client_p->servptr->name);
1452 return buffer;
1453 }
1454
1455 /* read_conf_files()
1456 *
1457 * inputs - cold start YES or NO
1458 * output - none
1459 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1460 */
1461 void
1462 read_conf_files(int cold)
1463 {
1464 const char *filename;
1465 char chanmodes[32];
1466 char chanlimit[32];
1467
1468 conf_parser_ctx.boot = cold;
1469 filename = ConfigFileEntry.configfile;
1470
1471 /* We need to know the initial filename for the yyerror() to report
1472 FIXME: The full path is in conffilenamebuf first time since we
1473 dont know anything else
1474
1475 - Gozem 2002-07-21
1476 */
1477 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1478
1479 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1480 {
1481 if (cold)
1482 {
1483 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1484 filename, strerror(errno));
1485 exit(-1);
1486 }
1487 else
1488 {
1489 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1490 "Unable to read configuration file '%s': %s",
1491 filename, strerror(errno));
1492 return;
1493 }
1494 }
1495
1496 if (!cold)
1497 clear_out_old_conf();
1498
1499 read_conf(conf_parser_ctx.conf_file);
1500 fclose(conf_parser_ctx.conf_file);
1501
1502 log_reopen_all();
1503
1504 add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1505 add_isupport("NETWORK", ServerInfo.network_name, -1);
1506
1507 snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1508 add_isupport("MAXLIST", chanmodes, -1);
1509 add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1510 add_isupport("CHANTYPES", "#", -1);
1511
1512 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1513 ConfigChannel.max_chans_per_user);
1514 add_isupport("CHANLIMIT", chanlimit, -1);
1515 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1516 add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1517 add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1518 add_isupport("EXCEPTS", "e", -1);
1519 add_isupport("INVEX", "I", -1);
1520 add_isupport("CHANMODES", chanmodes, -1);
1521
1522 /*
1523 * message_locale may have changed. rebuild isupport since it relies
1524 * on strlen(form_str(RPL_ISUPPORT))
1525 */
1526 rebuild_isupport_message_line();
1527 }
1528
1529 /* clear_out_old_conf()
1530 *
1531 * inputs - none
1532 * output - none
1533 * side effects - Clear out the old configuration
1534 */
1535 static void
1536 clear_out_old_conf(void)
1537 {
1538 dlink_node *ptr = NULL, *next_ptr = NULL;
1539 struct MaskItem *conf;
1540 dlink_list *free_items [] = {
1541 &server_items, &oconf_items,
1542 &uconf_items, &xconf_items,
1543 &nresv_items, &cluster_items, &service_items, &resv_channel_list, NULL
1544 };
1545
1546 dlink_list ** iterator = free_items; /* C is dumb */
1547
1548 /* We only need to free anything allocated by yyparse() here.
1549 * Resetting structs, etc, is taken care of by set_default_conf().
1550 */
1551
1552 for (; *iterator != NULL; iterator++)
1553 {
1554 DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1555 {
1556 conf = ptr->data;
1557
1558 dlinkDelete(&conf->node, map_to_list(conf->type));
1559
1560 /* XXX This is less than pretty */
1561 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1562 {
1563 if (!conf->ref_count)
1564 conf_free(conf);
1565 }
1566 else if (conf->type == CONF_XLINE)
1567 {
1568 if (!conf->until)
1569 conf_free(conf);
1570 }
1571 else
1572 conf_free(conf);
1573 }
1574 }
1575
1576 /*
1577 * don't delete the class table, rather mark all entries
1578 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1579 */
1580 class_mark_for_deletion();
1581
1582 clear_out_address_conf();
1583
1584 /* clean out module paths */
1585 mod_clear_paths();
1586
1587 /* clean out ServerInfo */
1588 MyFree(ServerInfo.description);
1589 ServerInfo.description = NULL;
1590 MyFree(ServerInfo.network_name);
1591 ServerInfo.network_name = NULL;
1592 MyFree(ServerInfo.network_desc);
1593 ServerInfo.network_desc = NULL;
1594 MyFree(ConfigFileEntry.egdpool_path);
1595 ConfigFileEntry.egdpool_path = NULL;
1596 #ifdef HAVE_LIBCRYPTO
1597 if (ServerInfo.rsa_private_key != NULL)
1598 {
1599 RSA_free(ServerInfo.rsa_private_key);
1600 ServerInfo.rsa_private_key = NULL;
1601 }
1602
1603 MyFree(ServerInfo.rsa_private_key_file);
1604 ServerInfo.rsa_private_key_file = NULL;
1605
1606 if (ServerInfo.server_ctx)
1607 SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1608 SSL_OP_NO_SSLv3|
1609 SSL_OP_NO_TLSv1);
1610 if (ServerInfo.client_ctx)
1611 SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1612 SSL_OP_NO_SSLv3|
1613 SSL_OP_NO_TLSv1);
1614 #endif
1615
1616 /* clean out AdminInfo */
1617 MyFree(AdminInfo.name);
1618 AdminInfo.name = NULL;
1619 MyFree(AdminInfo.email);
1620 AdminInfo.email = NULL;
1621 MyFree(AdminInfo.description);
1622 AdminInfo.description = NULL;
1623
1624 /* clean out listeners */
1625 close_listeners();
1626
1627 /* clean out general */
1628 MyFree(ConfigFileEntry.service_name);
1629 ConfigFileEntry.service_name = NULL;
1630
1631 delete_isupport("INVEX");
1632 delete_isupport("EXCEPTS");
1633 }
1634
1635 /* conf_add_class_to_conf()
1636 *
1637 * inputs - pointer to config item
1638 * output - NONE
1639 * side effects - Add a class pointer to a conf
1640 */
1641 void
1642 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1643 {
1644 if (class_name == NULL)
1645 {
1646 conf->class = class_default;
1647
1648 if (conf->type == CONF_CLIENT)
1649 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1650 "Warning *** Defaulting to default class for %s@%s",
1651 conf->user, conf->host);
1652 else
1653 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1654 "Warning *** Defaulting to default class for %s",
1655 conf->name);
1656 }
1657 else
1658 conf->class = class_find(class_name, 1);
1659
1660 if (conf->class == NULL)
1661 {
1662 if (conf->type == CONF_CLIENT)
1663 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1664 "Warning *** Defaulting to default class for %s@%s",
1665 conf->user, conf->host);
1666 else
1667 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1668 "Warning *** Defaulting to default class for %s",
1669 conf->name);
1670 conf->class = class_default;
1671 }
1672 }
1673
1674 /* yyerror()
1675 *
1676 * inputs - message from parser
1677 * output - NONE
1678 * side effects - message to opers and log file entry is made
1679 */
1680 void
1681 yyerror(const char *msg)
1682 {
1683 char newlinebuf[IRCD_BUFSIZE];
1684
1685 if (conf_parser_ctx.pass != 1)
1686 return;
1687
1688 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1689 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1690 "\"%s\", line %u: %s: %s",
1691 conffilebuf, lineno + 1, msg, newlinebuf);
1692 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1693 conffilebuf, lineno + 1, msg, newlinebuf);
1694 }
1695
1696 void
1697 conf_error_report(const char *msg)
1698 {
1699 char newlinebuf[IRCD_BUFSIZE];
1700
1701 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1702 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1703 "\"%s\", line %u: %s: %s",
1704 conffilebuf, lineno + 1, msg, newlinebuf);
1705 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1706 conffilebuf, lineno + 1, msg, newlinebuf);
1707 }
1708
1709 /*
1710 * valid_tkline()
1711 *
1712 * inputs - pointer to ascii string to check
1713 * - whether the specified time is in seconds or minutes
1714 * output - -1 not enough parameters
1715 * - 0 if not an integer number, else the number
1716 * side effects - none
1717 * Originally written by Dianora (Diane, db@db.net)
1718 */
1719 time_t
1720 valid_tkline(const char *p, int minutes)
1721 {
1722 time_t result = 0;
1723
1724 for (; *p; ++p)
1725 {
1726 if (!IsDigit(*p))
1727 return 0;
1728
1729 result *= 10;
1730 result += ((*p) & 0xF);
1731 }
1732
1733 /*
1734 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1735 * i.e. they specifically use 0, I am going to return 1 instead
1736 * as a return value of non-zero is used to flag it as a temporary kline
1737 */
1738 if (result == 0)
1739 result = 1;
1740
1741 /*
1742 * If the incoming time is in seconds convert it to minutes for the purpose
1743 * of this calculation
1744 */
1745 if (!minutes)
1746 result = result / (time_t)60;
1747
1748 if (result > MAX_TDKLINE_TIME)
1749 result = MAX_TDKLINE_TIME;
1750
1751 result = result * (time_t)60; /* turn it into seconds */
1752
1753 return result;
1754 }
1755
1756 /* valid_wild_card()
1757 *
1758 * input - pointer to client
1759 * - int flag, 0 for no warning oper 1 for warning oper
1760 * - count of following varargs to check
1761 * output - 0 if not valid, 1 if valid
1762 * side effects - NOTICE is given to source_p if warn is 1
1763 */
1764 int
1765 valid_wild_card(struct Client *source_p, int warn, int count, ...)
1766 {
1767 char *p;
1768 char tmpch;
1769 int nonwild = 0;
1770 va_list args;
1771
1772 /*
1773 * Now we must check the user and host to make sure there
1774 * are at least NONWILDCHARS non-wildcard characters in
1775 * them, otherwise assume they are attempting to kline
1776 * *@* or some variant of that. This code will also catch
1777 * people attempting to kline *@*.tld, as long as NONWILDCHARS
1778 * is greater than 3. In that case, there are only 3 non-wild
1779 * characters (tld), so if NONWILDCHARS is 4, the kline will
1780 * be disallowed.
1781 * -wnder
1782 */
1783
1784 va_start(args, count);
1785
1786 while (count--)
1787 {
1788 p = va_arg(args, char *);
1789 if (p == NULL)
1790 continue;
1791
1792 while ((tmpch = *p++))
1793 {
1794 if (!IsKWildChar(tmpch))
1795 {
1796 /*
1797 * If we find enough non-wild characters, we can
1798 * break - no point in searching further.
1799 */
1800 if (++nonwild >= ConfigFileEntry.min_nonwildcard)
1801 return 1;
1802 }
1803 }
1804 }
1805
1806 if (warn)
1807 sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1808 me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1809 return 0;
1810 }
1811
1812 /* XXX should this go into a separate file ? -Dianora */
1813 /* parse_aline
1814 *
1815 * input - pointer to cmd name being used
1816 * - pointer to client using cmd
1817 * - parc parameter count
1818 * - parv[] list of parameters to parse
1819 * - parse_flags bit map of things to test
1820 * - pointer to user or string to parse into
1821 * - pointer to host or NULL to parse into if non NULL
1822 * - pointer to optional tkline time or NULL
1823 * - pointer to target_server to parse into if non NULL
1824 * - pointer to reason to parse into
1825 *
1826 * output - 1 if valid, -1 if not valid
1827 * side effects - A generalised k/d/x etc. line parser,
1828 * "ALINE [time] user@host|string [ON] target :reason"
1829 * will parse returning a parsed user, host if
1830 * h_p pointer is non NULL, string otherwise.
1831 * if tkline_time pointer is non NULL a tk line will be set
1832 * to non zero if found.
1833 * if tkline_time pointer is NULL and tk line is found,
1834 * error is reported.
1835 * if target_server is NULL and an "ON" is found error
1836 * is reported.
1837 * if reason pointer is NULL ignore pointer,
1838 * this allows use of parse_a_line in unkline etc.
1839 *
1840 * - Dianora
1841 */
1842 int
1843 parse_aline(const char *cmd, struct Client *source_p,
1844 int parc, char **parv,
1845 int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1846 char **target_server, char **reason)
1847 {
1848 int found_tkline_time=0;
1849 static char def_reason[] = "No Reason";
1850 static char user[USERLEN*4+1];
1851 static char host[HOSTLEN*4+1];
1852
1853 parv++;
1854 parc--;
1855
1856 found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1857
1858 if (found_tkline_time != 0)
1859 {
1860 parv++;
1861 parc--;
1862
1863 if (tkline_time != NULL)
1864 *tkline_time = found_tkline_time;
1865 else
1866 {
1867 sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1868 me.name, source_p->name, cmd);
1869 return -1;
1870 }
1871 }
1872
1873 if (parc == 0)
1874 {
1875 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1876 me.name, source_p->name, cmd);
1877 return -1;
1878 }
1879
1880 if (h_p == NULL)
1881 *up_p = *parv;
1882 else
1883 {
1884 if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1885 return -1;
1886
1887 *up_p = user;
1888 *h_p = host;
1889 }
1890
1891 parc--;
1892 parv++;
1893
1894 if (parc != 0)
1895 {
1896 if (irccmp(*parv, "ON") == 0)
1897 {
1898 parc--;
1899 parv++;
1900
1901 if (target_server == NULL)
1902 {
1903 sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1904 me.name, source_p->name, cmd);
1905 return -1;
1906 }
1907
1908 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1909 {
1910 sendto_one(source_p, form_str(ERR_NOPRIVS),
1911 me.name, source_p->name, "remoteban");
1912 return -1;
1913 }
1914
1915 if (parc == 0 || EmptyString(*parv))
1916 {
1917 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1918 me.name, source_p->name, cmd);
1919 return -1;
1920 }
1921
1922 *target_server = *parv;
1923 parc--;
1924 parv++;
1925 }
1926 else
1927 {
1928 /* Make sure target_server *is* NULL if no ON server found
1929 * caller probably NULL'd it first, but no harm to do it again -db
1930 */
1931 if (target_server != NULL)
1932 *target_server = NULL;
1933 }
1934 }
1935
1936 if (h_p != NULL)
1937 {
1938 if (strchr(user, '!') != NULL)
1939 {
1940 sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1941 me.name, source_p->name);
1942 return -1;
1943 }
1944
1945 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1946 return -1;
1947 }
1948 else
1949 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1950 return -1;
1951
1952 if (reason != NULL)
1953 {
1954 if (parc != 0 && !EmptyString(*parv))
1955 {
1956 *reason = *parv;
1957 if (!valid_comment(source_p, *reason, 1))
1958 return -1;
1959 }
1960 else
1961 *reason = def_reason;
1962 }
1963
1964 return 1;
1965 }
1966
1967 /* find_user_host()
1968 *
1969 * inputs - pointer to client placing kline
1970 * - pointer to user_host_or_nick
1971 * - pointer to user buffer
1972 * - pointer to host buffer
1973 * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1974 * side effects -
1975 */
1976 static int
1977 find_user_host(struct Client *source_p, char *user_host_or_nick,
1978 char *luser, char *lhost, unsigned int flags)
1979 {
1980 struct Client *target_p = NULL;
1981 char *hostp = NULL;
1982
1983 if (lhost == NULL)
1984 {
1985 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1986 return 1;
1987 }
1988
1989 if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1990 {
1991 /* Explicit user@host mask given */
1992
1993 if (hostp != NULL) /* I'm a little user@host */
1994 {
1995 *(hostp++) = '\0'; /* short and squat */
1996 if (*user_host_or_nick)
1997 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
1998 else
1999 strcpy(luser, "*");
2000 if (*hostp)
2001 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
2002 else
2003 strcpy(lhost, "*");
2004 }
2005 else
2006 {
2007 luser[0] = '*'; /* no @ found, assume its *@somehost */
2008 luser[1] = '\0';
2009 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2010 }
2011
2012 return 1;
2013 }
2014 else
2015 {
2016 /* Try to find user@host mask from nick */
2017 /* Okay to use source_p as the first param, because source_p == client_p */
2018 if ((target_p =
2019 find_chasing(source_p, source_p, user_host_or_nick, NULL)) == NULL)
2020 return 0;
2021
2022 if (IsExemptKline(target_p))
2023 {
2024 if (!IsServer(source_p))
2025 sendto_one(source_p,
2026 ":%s NOTICE %s :%s is E-lined",
2027 me.name, source_p->name, target_p->name);
2028 return 0;
2029 }
2030
2031 /*
2032 * turn the "user" bit into "*user", blow away '~'
2033 * if found in original user name (non-idented)
2034 */
2035 strlcpy(luser, target_p->username, USERLEN*4 + 1);
2036
2037 if (target_p->username[0] == '~')
2038 luser[0] = '*';
2039
2040 if (target_p->sockhost[0] == '\0' ||
2041 (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2042 strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2043 else
2044 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2045 return 1;
2046 }
2047
2048 return 0;
2049 }
2050
2051 /* valid_comment()
2052 *
2053 * inputs - pointer to client
2054 * - pointer to comment
2055 * output - 0 if no valid comment,
2056 * - 1 if valid
2057 * side effects - truncates reason where necessary
2058 */
2059 int
2060 valid_comment(struct Client *source_p, char *comment, int warn)
2061 {
2062 if (strlen(comment) > REASONLEN)
2063 comment[REASONLEN-1] = '\0';
2064
2065 return 1;
2066 }
2067
2068 /* match_conf_password()
2069 *
2070 * inputs - pointer to given password
2071 * - pointer to Conf
2072 * output - 1 or 0 if match
2073 * side effects - none
2074 */
2075 int
2076 match_conf_password(const char *password, const struct MaskItem *conf)
2077 {
2078 const char *encr = NULL;
2079
2080 if (EmptyString(password) || EmptyString(conf->passwd))
2081 return 0;
2082
2083 if (conf->flags & CONF_FLAGS_ENCRYPTED)
2084 encr = crypt(password, conf->passwd);
2085 else
2086 encr = password;
2087
2088 return !strcmp(encr, conf->passwd);
2089 }
2090
2091 /*
2092 * cluster_a_line
2093 *
2094 * inputs - client sending the cluster
2095 * - command name "KLINE" "XLINE" etc.
2096 * - capab -- CAP_KLN etc. from s_serv.h
2097 * - cluster type -- CLUSTER_KLINE etc. from conf.h
2098 * - pattern and args to send along
2099 * output - none
2100 * side effects - Take source_p send the pattern with args given
2101 * along to all servers that match capab and cluster type
2102 */
2103 void
2104 cluster_a_line(struct Client *source_p, const char *command,
2105 int capab, int cluster_type, const char *pattern, ...)
2106 {
2107 va_list args;
2108 char buffer[IRCD_BUFSIZE];
2109 const dlink_node *ptr = NULL;
2110
2111 va_start(args, pattern);
2112 vsnprintf(buffer, sizeof(buffer), pattern, args);
2113 va_end(args);
2114
2115 DLINK_FOREACH(ptr, cluster_items.head)
2116 {
2117 const struct MaskItem *conf = ptr->data;
2118
2119 if (conf->flags & cluster_type)
2120 sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2121 "%s %s %s", command, conf->name, buffer);
2122 }
2123 }
2124
2125 /*
2126 * split_nuh
2127 *
2128 * inputs - pointer to original mask (modified in place)
2129 * - pointer to pointer where nick should go
2130 * - pointer to pointer where user should go
2131 * - pointer to pointer where host should go
2132 * output - NONE
2133 * side effects - mask is modified in place
2134 * If nick pointer is NULL, ignore writing to it
2135 * this allows us to use this function elsewhere.
2136 *
2137 * mask nick user host
2138 * ---------------------- ------- ------- ------
2139 * Dianora!db@db.net Dianora db db.net
2140 * Dianora Dianora * *
2141 * db.net * * db.net
2142 * OR if nick pointer is NULL
2143 * Dianora - * Dianora
2144 * Dianora! Dianora * *
2145 * Dianora!@ Dianora * *
2146 * Dianora!db Dianora db *
2147 * Dianora!@db.net Dianora * db.net
2148 * db@db.net * db db.net
2149 * !@ * * *
2150 * @ * * *
2151 * ! * * *
2152 */
2153 void
2154 split_nuh(struct split_nuh_item *const iptr)
2155 {
2156 char *p = NULL, *q = NULL;
2157
2158 if (iptr->nickptr)
2159 strlcpy(iptr->nickptr, "*", iptr->nicksize);
2160 if (iptr->userptr)
2161 strlcpy(iptr->userptr, "*", iptr->usersize);
2162 if (iptr->hostptr)
2163 strlcpy(iptr->hostptr, "*", iptr->hostsize);
2164
2165 if ((p = strchr(iptr->nuhmask, '!')))
2166 {
2167 *p = '\0';
2168
2169 if (iptr->nickptr && *iptr->nuhmask != '\0')
2170 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2171
2172 if ((q = strchr(++p, '@'))) {
2173 *q++ = '\0';
2174
2175 if (*p != '\0')
2176 strlcpy(iptr->userptr, p, iptr->usersize);
2177
2178 if (*q != '\0')
2179 strlcpy(iptr->hostptr, q, iptr->hostsize);
2180 }
2181 else
2182 {
2183 if (*p != '\0')
2184 strlcpy(iptr->userptr, p, iptr->usersize);
2185 }
2186 }
2187 else
2188 {
2189 /* No ! found so lets look for a user@host */
2190 if ((p = strchr(iptr->nuhmask, '@')))
2191 {
2192 /* if found a @ */
2193 *p++ = '\0';
2194
2195 if (*iptr->nuhmask != '\0')
2196 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
2197
2198 if (*p != '\0')
2199 strlcpy(iptr->hostptr, p, iptr->hostsize);
2200 }
2201 else
2202 {
2203 /* no @ found */
2204 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
2205 strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
2206 else
2207 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2208 }
2209 }
2210 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision