ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2659
Committed: Thu Dec 12 19:36:08 2013 UTC (11 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 58606 byte(s)
Log Message:
- conf.c:valid_wild_card(): add missing va_end()

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 #include "motd.h"
57
58 struct config_server_hide ConfigServerHide;
59
60 /* general conf items link list root, other than k lines etc. */
61 dlink_list service_items = { NULL, NULL, 0 };
62 dlink_list server_items = { NULL, NULL, 0 };
63 dlink_list cluster_items = { NULL, NULL, 0 };
64 dlink_list oconf_items = { NULL, NULL, 0 };
65 dlink_list uconf_items = { NULL, NULL, 0 };
66 dlink_list xconf_items = { NULL, NULL, 0 };
67 dlink_list nresv_items = { NULL, NULL, 0 };
68 dlink_list cresv_items = { NULL, NULL, 0 };
69
70 extern unsigned int lineno;
71 extern char linebuf[];
72 extern char conffilebuf[IRCD_BUFSIZE];
73 extern int yyparse(); /* defined in y.tab.c */
74
75 struct conf_parser_context conf_parser_ctx = { 0, 0, NULL };
76
77 /* internally defined functions */
78 static void read_conf(FILE *);
79 static void clear_out_old_conf(void);
80 static void expire_tklines(dlink_list *);
81 static void garbage_collect_ip_entries(void);
82 static int hash_ip(struct irc_ssaddr *);
83 static int verify_access(struct Client *);
84 static int attach_iline(struct Client *, struct MaskItem *);
85 static struct ip_entry *find_or_add_ip(struct irc_ssaddr *);
86 static dlink_list *map_to_list(enum maskitem_type);
87 static int find_user_host(struct Client *, char *, char *, char *, unsigned int);
88
89
90 /* usually, with hash tables, you use a prime number...
91 * but in this case I am dealing with ip addresses,
92 * not ascii strings.
93 */
94 #define IP_HASH_SIZE 0x1000
95
96 struct ip_entry
97 {
98 struct irc_ssaddr ip;
99 unsigned int count;
100 time_t last_attempt;
101 struct ip_entry *next;
102 };
103
104 static struct ip_entry *ip_hash_table[IP_HASH_SIZE];
105 static mp_pool_t *ip_entry_pool = NULL;
106 static int ip_entries_count = 0;
107
108
109 /* conf_dns_callback()
110 *
111 * inputs - pointer to struct MaskItem
112 * - pointer to DNSReply reply
113 * output - none
114 * side effects - called when resolver query finishes
115 * if the query resulted in a successful search, hp will contain
116 * a non-null pointer, otherwise hp will be null.
117 * if successful save hp in the conf item it was called with
118 */
119 static void
120 conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name)
121 {
122 struct MaskItem *conf = vptr;
123
124 conf->dns_pending = 0;
125
126 if (addr != NULL)
127 memcpy(&conf->addr, addr, sizeof(conf->addr));
128 else
129 conf->dns_failed = 1;
130 }
131
132 /* conf_dns_lookup()
133 *
134 * do a nameserver lookup of the conf host
135 * if the conf entry is currently doing a ns lookup do nothing, otherwise
136 * allocate a dns_query and start ns lookup.
137 */
138 static void
139 conf_dns_lookup(struct MaskItem *conf)
140 {
141 if (!conf->dns_pending)
142 {
143 conf->dns_pending = 1;
144 gethost_byname(conf_dns_callback, conf, conf->host);
145 }
146 }
147
148 struct MaskItem *
149 conf_make(enum maskitem_type type)
150 {
151 struct MaskItem *conf = MyMalloc(sizeof(*conf));
152 dlink_list *list = NULL;
153
154 conf->type = type;
155 conf->active = 1;
156 conf->aftype = AF_INET;
157
158 if ((list = map_to_list(type)))
159 dlinkAdd(conf, &conf->node, list);
160 return conf;
161 }
162
163 void
164 conf_free(struct MaskItem *conf)
165 {
166 dlink_node *ptr = NULL, *ptr_next = NULL;
167 dlink_list *list = NULL;
168
169 if (conf->node.next)
170 if ((list = map_to_list(conf->type)))
171 dlinkDelete(&conf->node, list);
172
173 MyFree(conf->name);
174
175 if (conf->dns_pending)
176 delete_resolver_queries(conf);
177 if (conf->passwd != NULL)
178 memset(conf->passwd, 0, strlen(conf->passwd));
179 if (conf->spasswd != NULL)
180 memset(conf->spasswd, 0, strlen(conf->spasswd));
181
182 conf->class = NULL;
183
184 MyFree(conf->passwd);
185 MyFree(conf->spasswd);
186 MyFree(conf->reason);
187 MyFree(conf->certfp);
188 MyFree(conf->user);
189 MyFree(conf->host);
190 #ifdef HAVE_LIBCRYPTO
191 MyFree(conf->cipher_list);
192
193 if (conf->rsa_public_key)
194 RSA_free(conf->rsa_public_key);
195 #endif
196 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->hub_list.head)
197 {
198 MyFree(ptr->data);
199 free_dlink_node(ptr);
200 }
201
202 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->leaf_list.head)
203 {
204 MyFree(ptr->data);
205 free_dlink_node(ptr);
206 }
207
208 DLINK_FOREACH_SAFE(ptr, ptr_next, conf->exempt_list.head)
209 {
210 struct exempt *exptr = ptr->data;
211
212 MyFree(exptr->name);
213 MyFree(exptr->user);
214 MyFree(exptr->host);
215 MyFree(exptr);
216 }
217
218 MyFree(conf);
219 }
220
221 /* check_client()
222 *
223 * inputs - pointer to client
224 * output - 0 = Success
225 * NOT_AUTHORIZED (-1) = Access denied (no I line match)
226 * IRCD_SOCKET_ERROR (-2) = Bad socket.
227 * I_LINE_FULL (-3) = I-line is full
228 * TOO_MANY (-4) = Too many connections from hostname
229 * BANNED_CLIENT (-5) = K-lined
230 * side effects - Ordinary client access check.
231 * Look for conf lines which have the same
232 * status as the flags passed.
233 */
234 int
235 check_client(struct Client *source_p)
236 {
237 int i;
238
239 if ((i = verify_access(source_p)))
240 ilog(LOG_TYPE_IRCD, "Access denied: %s[%s]",
241 source_p->name, source_p->sockhost);
242
243 switch (i)
244 {
245 case TOO_MANY:
246 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
247 "Too many on IP for %s (%s).",
248 get_client_name(source_p, SHOW_IP),
249 source_p->sockhost);
250 ilog(LOG_TYPE_IRCD, "Too many connections on IP from %s.",
251 get_client_name(source_p, SHOW_IP));
252 ++ServerStats.is_ref;
253 exit_client(source_p, &me, "No more connections allowed on that IP");
254 break;
255
256 case I_LINE_FULL:
257 sendto_realops_flags(UMODE_FULL, L_ALL, SEND_NOTICE,
258 "auth{} block is full for %s (%s).",
259 get_client_name(source_p, SHOW_IP),
260 source_p->sockhost);
261 ilog(LOG_TYPE_IRCD, "Too many connections from %s.",
262 get_client_name(source_p, SHOW_IP));
263 ++ServerStats.is_ref;
264 exit_client(source_p, &me,
265 "No more connections allowed in your connection class");
266 break;
267
268 case NOT_AUTHORIZED:
269 ++ServerStats.is_ref;
270 /* jdc - lists server name & port connections are on */
271 /* a purely cosmetical change */
272 sendto_realops_flags(UMODE_UNAUTH, L_ALL, SEND_NOTICE,
273 "Unauthorized client connection from %s [%s] on [%s/%u].",
274 get_client_name(source_p, SHOW_IP),
275 source_p->sockhost,
276 source_p->localClient->listener->name,
277 source_p->localClient->listener->port);
278 ilog(LOG_TYPE_IRCD,
279 "Unauthorized client connection from %s on [%s/%u].",
280 get_client_name(source_p, SHOW_IP),
281 source_p->localClient->listener->name,
282 source_p->localClient->listener->port);
283
284 exit_client(source_p, &me, "You are not authorized to use this server");
285 break;
286
287 case BANNED_CLIENT:
288 exit_client(source_p, &me, "Banned");
289 ++ServerStats.is_ref;
290 break;
291
292 case 0:
293 default:
294 break;
295 }
296
297 return (i < 0 ? 0 : 1);
298 }
299
300 /* verify_access()
301 *
302 * inputs - pointer to client to verify
303 * output - 0 if success -'ve if not
304 * side effect - find the first (best) I line to attach.
305 */
306 static int
307 verify_access(struct Client *client_p)
308 {
309 struct MaskItem *conf = NULL;
310 char non_ident[USERLEN + 1] = { '~', '\0' };
311
312 if (IsGotId(client_p))
313 {
314 conf = find_address_conf(client_p->host, client_p->username,
315 &client_p->localClient->ip,
316 client_p->localClient->aftype,
317 client_p->localClient->passwd);
318 }
319 else
320 {
321 strlcpy(non_ident + 1, client_p->username, sizeof(non_ident) - 1);
322 conf = find_address_conf(client_p->host,non_ident,
323 &client_p->localClient->ip,
324 client_p->localClient->aftype,
325 client_p->localClient->passwd);
326 }
327
328 if (conf != NULL)
329 {
330 if (IsConfClient(conf))
331 {
332 if (IsConfRedir(conf))
333 {
334 sendto_one(client_p, form_str(RPL_REDIR),
335 me.name, client_p->name,
336 conf->name ? conf->name : "",
337 conf->port);
338 return NOT_AUTHORIZED;
339 }
340
341 if (IsConfDoIdentd(conf))
342 SetNeedId(client_p);
343
344 /* Thanks for spoof idea amm */
345 if (IsConfDoSpoofIp(conf))
346 {
347 if (!ConfigFileEntry.hide_spoof_ips && IsConfSpoofNotice(conf))
348 sendto_realops_flags(UMODE_ALL, L_ADMIN, SEND_NOTICE,
349 "%s spoofing: %s as %s",
350 client_p->name, client_p->host, conf->name);
351 strlcpy(client_p->host, conf->name, sizeof(client_p->host));
352 AddFlag(client_p, FLAGS_IP_SPOOFING | FLAGS_AUTH_SPOOF);
353 }
354
355 return attach_iline(client_p, conf);
356 }
357 else if (IsConfKill(conf) || (ConfigFileEntry.glines && IsConfGline(conf)))
358 {
359 if (IsConfGline(conf))
360 sendto_one(client_p, ":%s NOTICE %s :*** G-lined", me.name,
361 client_p->name);
362 sendto_one(client_p, ":%s NOTICE %s :*** Banned: %s",
363 me.name, client_p->name, conf->reason);
364 return BANNED_CLIENT;
365 }
366 }
367
368 return NOT_AUTHORIZED;
369 }
370
371 /* attach_iline()
372 *
373 * inputs - client pointer
374 * - conf pointer
375 * output -
376 * side effects - do actual attach
377 */
378 static int
379 attach_iline(struct Client *client_p, struct MaskItem *conf)
380 {
381 struct ClassItem *class = NULL;
382 struct ip_entry *ip_found;
383 int a_limit_reached = 0;
384 unsigned int local = 0, global = 0, ident = 0;
385
386 assert(conf->class);
387
388 ip_found = find_or_add_ip(&client_p->localClient->ip);
389 ip_found->count++;
390 SetIpHash(client_p);
391
392 class = conf->class;
393
394 count_user_host(client_p->username, client_p->host,
395 &global, &local, &ident);
396
397 /* XXX blah. go down checking the various silly limits
398 * setting a_limit_reached if any limit is reached.
399 * - Dianora
400 */
401 if (class->max_total != 0 && class->ref_count >= class->max_total)
402 a_limit_reached = 1;
403 else if (class->max_perip != 0 && ip_found->count > class->max_perip)
404 a_limit_reached = 1;
405 else if (class->max_local != 0 && local >= class->max_local)
406 a_limit_reached = 1;
407 else if (class->max_global != 0 && global >= class->max_global)
408 a_limit_reached = 1;
409 else if (class->max_ident != 0 && ident >= class->max_ident &&
410 client_p->username[0] != '~')
411 a_limit_reached = 1;
412
413 if (a_limit_reached)
414 {
415 if (!IsConfExemptLimits(conf))
416 return TOO_MANY; /* Already at maximum allowed */
417
418 sendto_one(client_p,
419 ":%s NOTICE %s :*** Your connection class is full, "
420 "but you have exceed_limit = yes;", me.name, client_p->name);
421 }
422
423 return attach_conf(client_p, conf);
424 }
425
426 /* init_ip_hash_table()
427 *
428 * inputs - NONE
429 * output - NONE
430 * side effects - allocate memory for ip_entry(s)
431 * - clear the ip hash table
432 */
433 void
434 init_ip_hash_table(void)
435 {
436 ip_entry_pool = mp_pool_new(sizeof(struct ip_entry), MP_CHUNK_SIZE_IP_ENTRY);
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(&cresv_items);
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 return conf;
1010 }
1011
1012 break;
1013
1014 default:
1015 break;
1016 }
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.max_bans = 25;
1107 ConfigChannel.default_split_user_count = 0;
1108 ConfigChannel.default_split_server_count = 0;
1109 ConfigChannel.no_join_on_split = 0;
1110 ConfigChannel.no_create_on_split = 0;
1111
1112 ConfigServerHide.flatten_links = 0;
1113 ConfigServerHide.links_delay = 300;
1114 ConfigServerHide.hidden = 0;
1115 ConfigServerHide.hide_servers = 0;
1116 ConfigServerHide.hide_services = 0;
1117 ConfigServerHide.hidden_name = xstrdup(NETWORK_NAME_DEFAULT);
1118 ConfigServerHide.hide_server_ips = 0;
1119 ConfigServerHide.disable_remote_commands = 0;
1120
1121
1122 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1123 ConfigFileEntry.max_watch = WATCHSIZE_DEFAULT;
1124 ConfigFileEntry.cycle_on_host_change = 1;
1125 ConfigFileEntry.glines = 0;
1126 ConfigFileEntry.gline_time = 12 * 3600;
1127 ConfigFileEntry.gline_request_time = GLINE_REQUEST_EXPIRE_DEFAULT;
1128 ConfigFileEntry.gline_min_cidr = 16;
1129 ConfigFileEntry.gline_min_cidr6 = 48;
1130 ConfigFileEntry.invisible_on_connect = 1;
1131 ConfigFileEntry.tkline_expire_notices = 1;
1132 ConfigFileEntry.hide_spoof_ips = 1;
1133 ConfigFileEntry.ignore_bogus_ts = 0;
1134 ConfigFileEntry.disable_auth = 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.stats_u_oper_only = 0;
1154 ConfigFileEntry.caller_id_wait = 60;
1155 ConfigFileEntry.opers_bypass_callerid = 0;
1156 ConfigFileEntry.pace_wait = 10;
1157 ConfigFileEntry.pace_wait_simple = 1;
1158 ConfigFileEntry.short_motd = 0;
1159 ConfigFileEntry.ping_cookie = 0;
1160 ConfigFileEntry.no_oper_flood = 0;
1161 ConfigFileEntry.true_no_oper_flood = 0;
1162 ConfigFileEntry.oper_pass_resv = 1;
1163 ConfigFileEntry.max_targets = MAX_TARGETS_DEFAULT;
1164 ConfigFileEntry.oper_only_umodes = UMODE_DEBUG;
1165 ConfigFileEntry.oper_umodes = UMODE_BOTS | UMODE_LOCOPS | UMODE_SERVNOTICE |
1166 UMODE_OPERWALL | UMODE_WALLOP;
1167 ConfigFileEntry.use_egd = 0;
1168 ConfigFileEntry.egdpool_path = NULL;
1169 ConfigFileEntry.throttle_time = 10;
1170 }
1171
1172 static void
1173 validate_conf(void)
1174 {
1175 if (ConfigFileEntry.ts_warn_delta < TS_WARN_DELTA_MIN)
1176 ConfigFileEntry.ts_warn_delta = TS_WARN_DELTA_DEFAULT;
1177
1178 if (ConfigFileEntry.ts_max_delta < TS_MAX_DELTA_MIN)
1179 ConfigFileEntry.ts_max_delta = TS_MAX_DELTA_DEFAULT;
1180
1181 if (ServerInfo.network_name == NULL)
1182 ServerInfo.network_name = xstrdup(NETWORK_NAME_DEFAULT);
1183
1184 if (ServerInfo.network_desc == NULL)
1185 ServerInfo.network_desc = xstrdup(NETWORK_DESC_DEFAULT);
1186
1187 if (ConfigFileEntry.service_name == NULL)
1188 ConfigFileEntry.service_name = xstrdup(SERVICE_NAME_DEFAULT);
1189
1190 ConfigFileEntry.max_watch = IRCD_MAX(ConfigFileEntry.max_watch, WATCHSIZE_MIN);
1191 }
1192
1193 /* read_conf()
1194 *
1195 * inputs - file descriptor pointing to config file to use
1196 * output - None
1197 * side effects - Read configuration file.
1198 */
1199 static void
1200 read_conf(FILE *file)
1201 {
1202 lineno = 0;
1203
1204 set_default_conf(); /* Set default values prior to conf parsing */
1205 conf_parser_ctx.pass = 1;
1206 yyparse(); /* pick up the classes first */
1207
1208 rewind(file);
1209
1210 conf_parser_ctx.pass = 2;
1211 yyparse(); /* Load the values from the conf */
1212 validate_conf(); /* Check to make sure some values are still okay. */
1213 /* Some global values are also loaded here. */
1214 class_delete_marked(); /* Make sure classes are valid */
1215 }
1216
1217 /* lookup_confhost()
1218 *
1219 * start DNS lookups of all hostnames in the conf
1220 * line and convert an IP addresses in a.b.c.d number for to IP#s.
1221 */
1222 void
1223 lookup_confhost(struct MaskItem *conf)
1224 {
1225 struct addrinfo hints, *res;
1226
1227 /* Do name lookup now on hostnames given and store the
1228 * ip numbers in conf structure.
1229 */
1230 memset(&hints, 0, sizeof(hints));
1231
1232 hints.ai_family = AF_UNSPEC;
1233 hints.ai_socktype = SOCK_STREAM;
1234
1235 /* Get us ready for a bind() and don't bother doing dns lookup */
1236 hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST;
1237
1238 if (getaddrinfo(conf->host, NULL, &hints, &res))
1239 {
1240 conf_dns_lookup(conf);
1241 return;
1242 }
1243
1244 assert(res != NULL);
1245
1246 memcpy(&conf->addr, res->ai_addr, res->ai_addrlen);
1247 conf->addr.ss_len = res->ai_addrlen;
1248 conf->addr.ss.ss_family = res->ai_family;
1249
1250 freeaddrinfo(res);
1251 }
1252
1253 /* conf_connect_allowed()
1254 *
1255 * inputs - pointer to inaddr
1256 * - int type ipv4 or ipv6
1257 * output - BANNED or accepted
1258 * side effects - none
1259 */
1260 int
1261 conf_connect_allowed(struct irc_ssaddr *addr, int aftype)
1262 {
1263 struct ip_entry *ip_found;
1264 struct MaskItem *conf = find_dline_conf(addr, aftype);
1265
1266 /* DLINE exempt also gets you out of static limits/pacing... */
1267 if (conf && (conf->type == CONF_EXEMPT))
1268 return 0;
1269
1270 if (conf != NULL)
1271 return BANNED_CLIENT;
1272
1273 ip_found = find_or_add_ip(addr);
1274
1275 if ((CurrentTime - ip_found->last_attempt) <
1276 ConfigFileEntry.throttle_time)
1277 {
1278 ip_found->last_attempt = CurrentTime;
1279 return TOO_FAST;
1280 }
1281
1282 ip_found->last_attempt = CurrentTime;
1283 return 0;
1284 }
1285
1286 /* cleanup_tklines()
1287 *
1288 * inputs - NONE
1289 * output - NONE
1290 * side effects - call function to expire temporary k/d lines
1291 * This is an event started off in ircd.c
1292 */
1293 void
1294 cleanup_tklines(void *notused)
1295 {
1296 hostmask_expire_temporary();
1297 expire_tklines(&xconf_items);
1298 expire_tklines(&nresv_items);
1299 expire_tklines(&cresv_items);
1300 }
1301
1302 /* expire_tklines()
1303 *
1304 * inputs - tkline list pointer
1305 * output - NONE
1306 * side effects - expire tklines
1307 */
1308 static void
1309 expire_tklines(dlink_list *tklist)
1310 {
1311 dlink_node *ptr;
1312 dlink_node *next_ptr;
1313 struct MaskItem *conf;
1314
1315 DLINK_FOREACH_SAFE(ptr, next_ptr, tklist->head)
1316 {
1317 conf = ptr->data;
1318
1319 if (!conf->until || conf->until > CurrentTime)
1320 continue;
1321
1322 if (conf->type == CONF_XLINE)
1323 {
1324 if (ConfigFileEntry.tkline_expire_notices)
1325 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1326 "Temporary X-line for [%s] expired", conf->name);
1327 conf_free(conf);
1328 }
1329 else if (conf->type == CONF_NRESV || conf->type == CONF_CRESV)
1330 {
1331 if (ConfigFileEntry.tkline_expire_notices)
1332 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1333 "Temporary RESV for [%s] expired", conf->name);
1334 conf_free(conf);
1335 }
1336 }
1337 }
1338
1339 /* oper_privs_as_string()
1340 *
1341 * inputs - pointer to client_p
1342 * output - pointer to static string showing oper privs
1343 * side effects - return as string, the oper privs as derived from port
1344 */
1345 static const struct oper_privs
1346 {
1347 const unsigned int flag;
1348 const unsigned char c;
1349 } flag_list[] = {
1350 { OPER_FLAG_ADMIN, 'A' },
1351 { OPER_FLAG_REMOTEBAN, 'B' },
1352 { OPER_FLAG_DIE, 'D' },
1353 { OPER_FLAG_GLINE, 'G' },
1354 { OPER_FLAG_REHASH, 'H' },
1355 { OPER_FLAG_K, 'K' },
1356 { OPER_FLAG_OPERWALL, 'L' },
1357 { OPER_FLAG_KILL, 'N' },
1358 { OPER_FLAG_KILL_REMOTE, 'O' },
1359 { OPER_FLAG_CONNECT, 'P' },
1360 { OPER_FLAG_CONNECT_REMOTE, 'Q' },
1361 { OPER_FLAG_SQUIT, 'R' },
1362 { OPER_FLAG_SQUIT_REMOTE, 'S' },
1363 { OPER_FLAG_UNKLINE, 'U' },
1364 { OPER_FLAG_X, 'X' },
1365 { 0, '\0' }
1366 };
1367
1368 char *
1369 oper_privs_as_string(const unsigned int port)
1370 {
1371 static char privs_out[16];
1372 char *privs_ptr = privs_out;
1373 const struct oper_privs *opriv = flag_list;
1374
1375 for (; opriv->flag; ++opriv)
1376 {
1377 if (port & opriv->flag)
1378 *privs_ptr++ = opriv->c;
1379 else
1380 *privs_ptr++ = ToLower(opriv->c);
1381 }
1382
1383 *privs_ptr = '\0';
1384
1385 return privs_out;
1386 }
1387
1388 /*
1389 * Input: A client to find the active oper{} name for.
1390 * Output: The nick!user@host{oper} of the oper.
1391 * "oper" is server name for remote opers
1392 * Side effects: None.
1393 */
1394 const char *
1395 get_oper_name(const struct Client *client_p)
1396 {
1397 dlink_node *cnode = NULL;
1398 /* +5 for !,@,{,} and null */
1399 static char buffer[NICKLEN + USERLEN + HOSTLEN + HOSTLEN + 5];
1400
1401 if (MyConnect(client_p))
1402 {
1403 if ((cnode = client_p->localClient->confs.head))
1404 {
1405 struct MaskItem *conf = cnode->data;
1406
1407 if (IsConfOperator(conf))
1408 {
1409 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1410 client_p->username, client_p->host, conf->name);
1411 return buffer;
1412 }
1413 }
1414
1415 /* Probably should assert here for now. If there is an oper out there
1416 * with no oper{} conf attached, it would be good for us to know...
1417 */
1418 assert(0); /* Oper without oper conf! */
1419 }
1420
1421 snprintf(buffer, sizeof(buffer), "%s!%s@%s{%s}", client_p->name,
1422 client_p->username, client_p->host, client_p->servptr->name);
1423 return buffer;
1424 }
1425
1426 /* read_conf_files()
1427 *
1428 * inputs - cold start YES or NO
1429 * output - none
1430 * side effects - read all conf files needed, ircd.conf kline.conf etc.
1431 */
1432 void
1433 read_conf_files(int cold)
1434 {
1435 const char *filename;
1436 char chanmodes[32];
1437 char chanlimit[32];
1438
1439 conf_parser_ctx.boot = cold;
1440 filename = ConfigFileEntry.configfile;
1441
1442 /* We need to know the initial filename for the yyerror() to report
1443 FIXME: The full path is in conffilenamebuf first time since we
1444 dont know anything else
1445
1446 - Gozem 2002-07-21
1447 */
1448 strlcpy(conffilebuf, filename, sizeof(conffilebuf));
1449
1450 if ((conf_parser_ctx.conf_file = fopen(filename, "r")) == NULL)
1451 {
1452 if (cold)
1453 {
1454 ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s",
1455 filename, strerror(errno));
1456 exit(-1);
1457 }
1458 else
1459 {
1460 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1461 "Unable to read configuration file '%s': %s",
1462 filename, strerror(errno));
1463 return;
1464 }
1465 }
1466
1467 if (!cold)
1468 clear_out_old_conf();
1469
1470 read_conf(conf_parser_ctx.conf_file);
1471 fclose(conf_parser_ctx.conf_file);
1472
1473 log_reopen_all();
1474
1475 add_isupport("NICKLEN", NULL, ServerInfo.max_nick_length);
1476 add_isupport("NETWORK", ServerInfo.network_name, -1);
1477
1478 snprintf(chanmodes, sizeof(chanmodes), "beI:%d", ConfigChannel.max_bans);
1479 add_isupport("MAXLIST", chanmodes, -1);
1480 add_isupport("MAXTARGETS", NULL, ConfigFileEntry.max_targets);
1481 add_isupport("CHANTYPES", "#", -1);
1482
1483 snprintf(chanlimit, sizeof(chanlimit), "#:%d",
1484 ConfigChannel.max_chans_per_user);
1485 add_isupport("CHANLIMIT", chanlimit, -1);
1486 snprintf(chanmodes, sizeof(chanmodes), "%s", "beI,k,l,imnprstORS");
1487 add_isupport("CHANNELLEN", NULL, LOCAL_CHANNELLEN);
1488 add_isupport("TOPICLEN", NULL, ServerInfo.max_topic_length);
1489 add_isupport("CHANMODES", chanmodes, -1);
1490
1491 /*
1492 * message_locale may have changed. rebuild isupport since it relies
1493 * on strlen(form_str(RPL_ISUPPORT))
1494 */
1495 rebuild_isupport_message_line();
1496 }
1497
1498 /* clear_out_old_conf()
1499 *
1500 * inputs - none
1501 * output - none
1502 * side effects - Clear out the old configuration
1503 */
1504 static void
1505 clear_out_old_conf(void)
1506 {
1507 dlink_node *ptr = NULL, *next_ptr = NULL;
1508 struct MaskItem *conf;
1509 dlink_list *free_items [] = {
1510 &server_items, &oconf_items,
1511 &uconf_items, &xconf_items,
1512 &nresv_items, &cluster_items, &service_items, &cresv_items, NULL
1513 };
1514
1515 dlink_list ** iterator = free_items; /* C is dumb */
1516
1517 /* We only need to free anything allocated by yyparse() here.
1518 * Resetting structs, etc, is taken care of by set_default_conf().
1519 */
1520
1521 for (; *iterator != NULL; iterator++)
1522 {
1523 DLINK_FOREACH_SAFE(ptr, next_ptr, (*iterator)->head)
1524 {
1525 conf = ptr->data;
1526
1527 dlinkDelete(&conf->node, map_to_list(conf->type));
1528
1529 /* XXX This is less than pretty */
1530 if (conf->type == CONF_SERVER || conf->type == CONF_OPER)
1531 {
1532 if (!conf->ref_count)
1533 conf_free(conf);
1534 }
1535 else if (conf->type == CONF_XLINE)
1536 {
1537 if (!conf->until)
1538 conf_free(conf);
1539 }
1540 else
1541 conf_free(conf);
1542 }
1543 }
1544
1545 motd_clear();
1546
1547 /*
1548 * don't delete the class table, rather mark all entries
1549 * for deletion. The table is cleaned up by class_delete_marked. - avalon
1550 */
1551 class_mark_for_deletion();
1552
1553 clear_out_address_conf();
1554
1555 /* clean out module paths */
1556 mod_clear_paths();
1557
1558 /* clean out ServerInfo */
1559 MyFree(ServerInfo.description);
1560 ServerInfo.description = NULL;
1561 MyFree(ServerInfo.network_name);
1562 ServerInfo.network_name = NULL;
1563 MyFree(ServerInfo.network_desc);
1564 ServerInfo.network_desc = NULL;
1565 MyFree(ConfigFileEntry.egdpool_path);
1566 ConfigFileEntry.egdpool_path = NULL;
1567 #ifdef HAVE_LIBCRYPTO
1568 if (ServerInfo.rsa_private_key != NULL)
1569 {
1570 RSA_free(ServerInfo.rsa_private_key);
1571 ServerInfo.rsa_private_key = NULL;
1572 }
1573
1574 MyFree(ServerInfo.rsa_private_key_file);
1575 ServerInfo.rsa_private_key_file = NULL;
1576
1577 if (ServerInfo.server_ctx)
1578 SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|
1579 SSL_OP_NO_SSLv3|
1580 SSL_OP_NO_TLSv1);
1581 if (ServerInfo.client_ctx)
1582 SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|
1583 SSL_OP_NO_SSLv3|
1584 SSL_OP_NO_TLSv1);
1585 #endif
1586
1587 /* clean out AdminInfo */
1588 MyFree(AdminInfo.name);
1589 AdminInfo.name = NULL;
1590 MyFree(AdminInfo.email);
1591 AdminInfo.email = NULL;
1592 MyFree(AdminInfo.description);
1593 AdminInfo.description = NULL;
1594
1595 /* clean out listeners */
1596 close_listeners();
1597
1598 /* clean out general */
1599 MyFree(ConfigFileEntry.service_name);
1600 ConfigFileEntry.service_name = NULL;
1601 }
1602
1603 /* conf_add_class_to_conf()
1604 *
1605 * inputs - pointer to config item
1606 * output - NONE
1607 * side effects - Add a class pointer to a conf
1608 */
1609 void
1610 conf_add_class_to_conf(struct MaskItem *conf, const char *class_name)
1611 {
1612 if (class_name == NULL)
1613 {
1614 conf->class = class_default;
1615
1616 if (conf->type == CONF_CLIENT)
1617 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1618 "Warning *** Defaulting to default class for %s@%s",
1619 conf->user, conf->host);
1620 else
1621 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1622 "Warning *** Defaulting to default class for %s",
1623 conf->name);
1624 }
1625 else
1626 conf->class = class_find(class_name, 1);
1627
1628 if (conf->class == NULL)
1629 {
1630 if (conf->type == CONF_CLIENT)
1631 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1632 "Warning *** Defaulting to default class for %s@%s",
1633 conf->user, conf->host);
1634 else
1635 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1636 "Warning *** Defaulting to default class for %s",
1637 conf->name);
1638 conf->class = class_default;
1639 }
1640 }
1641
1642 /* yyerror()
1643 *
1644 * inputs - message from parser
1645 * output - NONE
1646 * side effects - message to opers and log file entry is made
1647 */
1648 void
1649 yyerror(const char *msg)
1650 {
1651 char newlinebuf[IRCD_BUFSIZE];
1652
1653 if (conf_parser_ctx.pass != 1)
1654 return;
1655
1656 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1657 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1658 "\"%s\", line %u: %s: %s",
1659 conffilebuf, lineno + 1, msg, newlinebuf);
1660 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1661 conffilebuf, lineno + 1, msg, newlinebuf);
1662 }
1663
1664 void
1665 conf_error_report(const char *msg)
1666 {
1667 char newlinebuf[IRCD_BUFSIZE];
1668
1669 strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf));
1670 sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
1671 "\"%s\", line %u: %s: %s",
1672 conffilebuf, lineno + 1, msg, newlinebuf);
1673 ilog(LOG_TYPE_IRCD, "\"%s\", line %u: %s: %s",
1674 conffilebuf, lineno + 1, msg, newlinebuf);
1675 }
1676
1677 /*
1678 * valid_tkline()
1679 *
1680 * inputs - pointer to ascii string to check
1681 * - whether the specified time is in seconds or minutes
1682 * output - -1 not enough parameters
1683 * - 0 if not an integer number, else the number
1684 * side effects - none
1685 * Originally written by Dianora (Diane, db@db.net)
1686 */
1687 time_t
1688 valid_tkline(const char *data, const int minutes)
1689 {
1690 const unsigned char *p = (const unsigned char *)data;
1691 unsigned char tmpch = '\0';
1692 time_t result = 0;
1693
1694 while ((tmpch = *p++))
1695 {
1696 if (!IsDigit(tmpch))
1697 return 0;
1698
1699 result *= 10;
1700 result += (tmpch & 0xF);
1701 }
1702
1703 /*
1704 * In the degenerate case where oper does a /quote kline 0 user@host :reason
1705 * i.e. they specifically use 0, I am going to return 1 instead
1706 * as a return value of non-zero is used to flag it as a temporary kline
1707 */
1708 if (result == 0)
1709 result = 1;
1710
1711 /*
1712 * If the incoming time is in seconds convert it to minutes for the purpose
1713 * of this calculation
1714 */
1715 if (!minutes)
1716 result = result / 60;
1717
1718 if (result > MAX_TDKLINE_TIME)
1719 result = MAX_TDKLINE_TIME;
1720
1721 result = result * 60; /* turn it into seconds */
1722
1723 return result;
1724 }
1725
1726 /* valid_wild_card_simple()
1727 *
1728 * inputs - data to check for sufficient non-wildcard characters
1729 * outputs - 1 if valid, else 0
1730 * side effects - none
1731 */
1732 int
1733 valid_wild_card_simple(const char *data)
1734 {
1735 const unsigned char *p = (const unsigned char *)data;
1736 unsigned char tmpch = '\0';
1737 int nonwild = 0;
1738
1739 while ((tmpch = *p++))
1740 {
1741 if (tmpch == '\\')
1742 {
1743 ++p;
1744 if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1745 return 1;
1746 }
1747 else if (!IsMWildChar(tmpch))
1748 {
1749 if (++nonwild >= ConfigFileEntry.min_nonwildcard_simple)
1750 return 1;
1751 }
1752 }
1753
1754 return 0;
1755 }
1756
1757 /* valid_wild_card()
1758 *
1759 * input - pointer to client
1760 * - int flag, 0 for no warning oper 1 for warning oper
1761 * - count of following varargs to check
1762 * output - 0 if not valid, 1 if valid
1763 * side effects - NOTICE is given to source_p if warn is 1
1764 */
1765 int
1766 valid_wild_card(struct Client *source_p, int warn, int count, ...)
1767 {
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 const char *p = va_arg(args, const 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 {
1802 va_end(args);
1803 return 1;
1804 }
1805 }
1806 }
1807 }
1808
1809 if (warn)
1810 sendto_one(source_p, ":%s NOTICE %s :Please include at least %d non-wildcard characters with the mask",
1811 me.name, source_p->name, ConfigFileEntry.min_nonwildcard);
1812 va_end(args);
1813 return 0;
1814 }
1815
1816 /* XXX should this go into a separate file ? -Dianora */
1817 /* parse_aline
1818 *
1819 * input - pointer to cmd name being used
1820 * - pointer to client using cmd
1821 * - parc parameter count
1822 * - parv[] list of parameters to parse
1823 * - parse_flags bit map of things to test
1824 * - pointer to user or string to parse into
1825 * - pointer to host or NULL to parse into if non NULL
1826 * - pointer to optional tkline time or NULL
1827 * - pointer to target_server to parse into if non NULL
1828 * - pointer to reason to parse into
1829 *
1830 * output - 1 if valid, -1 if not valid
1831 * side effects - A generalised k/d/x etc. line parser,
1832 * "ALINE [time] user@host|string [ON] target :reason"
1833 * will parse returning a parsed user, host if
1834 * h_p pointer is non NULL, string otherwise.
1835 * if tkline_time pointer is non NULL a tk line will be set
1836 * to non zero if found.
1837 * if tkline_time pointer is NULL and tk line is found,
1838 * error is reported.
1839 * if target_server is NULL and an "ON" is found error
1840 * is reported.
1841 * if reason pointer is NULL ignore pointer,
1842 * this allows use of parse_a_line in unkline etc.
1843 *
1844 * - Dianora
1845 */
1846 int
1847 parse_aline(const char *cmd, struct Client *source_p,
1848 int parc, char **parv,
1849 int parse_flags, char **up_p, char **h_p, time_t *tkline_time,
1850 char **target_server, char **reason)
1851 {
1852 int found_tkline_time=0;
1853 static char def_reason[] = "No Reason";
1854 static char user[USERLEN*4+1];
1855 static char host[HOSTLEN*4+1];
1856
1857 parv++;
1858 parc--;
1859
1860 found_tkline_time = valid_tkline(*parv, TK_MINUTES);
1861
1862 if (found_tkline_time != 0)
1863 {
1864 parv++;
1865 parc--;
1866
1867 if (tkline_time != NULL)
1868 *tkline_time = found_tkline_time;
1869 else
1870 {
1871 sendto_one(source_p, ":%s NOTICE %s :temp_line not supported by %s",
1872 me.name, source_p->name, cmd);
1873 return -1;
1874 }
1875 }
1876
1877 if (parc == 0)
1878 {
1879 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1880 me.name, source_p->name, cmd);
1881 return -1;
1882 }
1883
1884 if (h_p == NULL)
1885 *up_p = *parv;
1886 else
1887 {
1888 if (find_user_host(source_p, *parv, user, host, parse_flags) == 0)
1889 return -1;
1890
1891 *up_p = user;
1892 *h_p = host;
1893 }
1894
1895 parc--;
1896 parv++;
1897
1898 if (parc != 0)
1899 {
1900 if (irccmp(*parv, "ON") == 0)
1901 {
1902 parc--;
1903 parv++;
1904
1905 if (target_server == NULL)
1906 {
1907 sendto_one(source_p, ":%s NOTICE %s :ON server not supported by %s",
1908 me.name, source_p->name, cmd);
1909 return -1;
1910 }
1911
1912 if (!HasOFlag(source_p, OPER_FLAG_REMOTEBAN))
1913 {
1914 sendto_one(source_p, form_str(ERR_NOPRIVS),
1915 me.name, source_p->name, "remoteban");
1916 return -1;
1917 }
1918
1919 if (parc == 0 || EmptyString(*parv))
1920 {
1921 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1922 me.name, source_p->name, cmd);
1923 return -1;
1924 }
1925
1926 *target_server = *parv;
1927 parc--;
1928 parv++;
1929 }
1930 else
1931 {
1932 /* Make sure target_server *is* NULL if no ON server found
1933 * caller probably NULL'd it first, but no harm to do it again -db
1934 */
1935 if (target_server != NULL)
1936 *target_server = NULL;
1937 }
1938 }
1939
1940 if (h_p != NULL)
1941 {
1942 if (strchr(user, '!') != NULL)
1943 {
1944 sendto_one(source_p, ":%s NOTICE %s :Invalid character '!' in kline",
1945 me.name, source_p->name);
1946 return -1;
1947 }
1948
1949 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 2, *up_p, *h_p))
1950 return -1;
1951 }
1952 else
1953 if ((parse_flags & AWILD) && !valid_wild_card(source_p, 1, 1, *up_p))
1954 return -1;
1955
1956 if (reason != NULL)
1957 {
1958 if (parc != 0 && !EmptyString(*parv))
1959 {
1960 *reason = *parv;
1961 if (!valid_comment(source_p, *reason, 1))
1962 return -1;
1963 }
1964 else
1965 *reason = def_reason;
1966 }
1967
1968 return 1;
1969 }
1970
1971 /* find_user_host()
1972 *
1973 * inputs - pointer to client placing kline
1974 * - pointer to user_host_or_nick
1975 * - pointer to user buffer
1976 * - pointer to host buffer
1977 * output - 0 if not ok to kline, 1 to kline i.e. if valid user host
1978 * side effects -
1979 */
1980 static int
1981 find_user_host(struct Client *source_p, char *user_host_or_nick,
1982 char *luser, char *lhost, unsigned int flags)
1983 {
1984 struct Client *target_p = NULL;
1985 char *hostp = NULL;
1986
1987 if (lhost == NULL)
1988 {
1989 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1);
1990 return 1;
1991 }
1992
1993 if ((hostp = strchr(user_host_or_nick, '@')) || *user_host_or_nick == '*')
1994 {
1995 /* Explicit user@host mask given */
1996
1997 if (hostp != NULL) /* I'm a little user@host */
1998 {
1999 *(hostp++) = '\0'; /* short and squat */
2000 if (*user_host_or_nick)
2001 strlcpy(luser, user_host_or_nick, USERLEN*4 + 1); /* here is my user */
2002 else
2003 strcpy(luser, "*");
2004
2005 if (*hostp)
2006 strlcpy(lhost, hostp, HOSTLEN + 1); /* here is my host */
2007 else
2008 strcpy(lhost, "*");
2009 }
2010 else
2011 {
2012 luser[0] = '*'; /* no @ found, assume its *@somehost */
2013 luser[1] = '\0';
2014 strlcpy(lhost, user_host_or_nick, HOSTLEN*4 + 1);
2015 }
2016
2017 return 1;
2018 }
2019 else
2020 {
2021 /* Try to find user@host mask from nick */
2022 /* Okay to use source_p as the first param, because source_p == client_p */
2023 if ((target_p =
2024 find_chasing(source_p, user_host_or_nick, NULL)) == NULL)
2025 return 0;
2026
2027 if (IsExemptKline(target_p))
2028 {
2029 if (!IsServer(source_p))
2030 sendto_one(source_p,
2031 ":%s NOTICE %s :%s is E-lined",
2032 me.name, source_p->name, target_p->name);
2033 return 0;
2034 }
2035
2036 /*
2037 * turn the "user" bit into "*user", blow away '~'
2038 * if found in original user name (non-idented)
2039 */
2040 strlcpy(luser, target_p->username, USERLEN*4 + 1);
2041
2042 if (target_p->username[0] == '~')
2043 luser[0] = '*';
2044
2045 if (target_p->sockhost[0] == '\0' ||
2046 (target_p->sockhost[0] == '0' && target_p->sockhost[1] == '\0'))
2047 strlcpy(lhost, target_p->host, HOSTLEN*4 + 1);
2048 else
2049 strlcpy(lhost, target_p->sockhost, HOSTLEN*4 + 1);
2050 return 1;
2051 }
2052
2053 return 0;
2054 }
2055
2056 /* valid_comment()
2057 *
2058 * inputs - pointer to client
2059 * - pointer to comment
2060 * output - 0 if no valid comment,
2061 * - 1 if valid
2062 * side effects - truncates reason where necessary
2063 */
2064 int
2065 valid_comment(struct Client *source_p, char *comment, int warn)
2066 {
2067 if (strlen(comment) > REASONLEN)
2068 comment[REASONLEN-1] = '\0';
2069
2070 return 1;
2071 }
2072
2073 /* match_conf_password()
2074 *
2075 * inputs - pointer to given password
2076 * - pointer to Conf
2077 * output - 1 or 0 if match
2078 * side effects - none
2079 */
2080 int
2081 match_conf_password(const char *password, const struct MaskItem *conf)
2082 {
2083 const char *encr = NULL;
2084
2085 if (EmptyString(password) || EmptyString(conf->passwd))
2086 return 0;
2087
2088 if (conf->flags & CONF_FLAGS_ENCRYPTED)
2089 encr = crypt(password, conf->passwd);
2090 else
2091 encr = password;
2092
2093 return !strcmp(encr, conf->passwd);
2094 }
2095
2096 /*
2097 * cluster_a_line
2098 *
2099 * inputs - client sending the cluster
2100 * - command name "KLINE" "XLINE" etc.
2101 * - capab -- CAP_KLN etc. from s_serv.h
2102 * - cluster type -- CLUSTER_KLINE etc. from conf.h
2103 * - pattern and args to send along
2104 * output - none
2105 * side effects - Take source_p send the pattern with args given
2106 * along to all servers that match capab and cluster type
2107 */
2108 void
2109 cluster_a_line(struct Client *source_p, const char *command,
2110 int capab, int cluster_type, const char *pattern, ...)
2111 {
2112 va_list args;
2113 char buffer[IRCD_BUFSIZE];
2114 const dlink_node *ptr = NULL;
2115
2116 va_start(args, pattern);
2117 vsnprintf(buffer, sizeof(buffer), pattern, args);
2118 va_end(args);
2119
2120 DLINK_FOREACH(ptr, cluster_items.head)
2121 {
2122 const struct MaskItem *conf = ptr->data;
2123
2124 if (conf->flags & cluster_type)
2125 sendto_match_servs(source_p, conf->name, CAP_CLUSTER|capab,
2126 "%s %s %s", command, conf->name, buffer);
2127 }
2128 }
2129
2130 /*
2131 * split_nuh
2132 *
2133 * inputs - pointer to original mask (modified in place)
2134 * - pointer to pointer where nick should go
2135 * - pointer to pointer where user should go
2136 * - pointer to pointer where host should go
2137 * output - NONE
2138 * side effects - mask is modified in place
2139 * If nick pointer is NULL, ignore writing to it
2140 * this allows us to use this function elsewhere.
2141 *
2142 * mask nick user host
2143 * ---------------------- ------- ------- ------
2144 * Dianora!db@db.net Dianora db db.net
2145 * Dianora Dianora * *
2146 * db.net * * db.net
2147 * OR if nick pointer is NULL
2148 * Dianora - * Dianora
2149 * Dianora! Dianora * *
2150 * Dianora!@ Dianora * *
2151 * Dianora!db Dianora db *
2152 * Dianora!@db.net Dianora * db.net
2153 * db@db.net * db db.net
2154 * !@ * * *
2155 * @ * * *
2156 * ! * * *
2157 */
2158 void
2159 split_nuh(struct split_nuh_item *const iptr)
2160 {
2161 char *p = NULL, *q = NULL;
2162
2163 if (iptr->nickptr)
2164 strlcpy(iptr->nickptr, "*", iptr->nicksize);
2165 if (iptr->userptr)
2166 strlcpy(iptr->userptr, "*", iptr->usersize);
2167 if (iptr->hostptr)
2168 strlcpy(iptr->hostptr, "*", iptr->hostsize);
2169
2170 if ((p = strchr(iptr->nuhmask, '!')))
2171 {
2172 *p = '\0';
2173
2174 if (iptr->nickptr && *iptr->nuhmask != '\0')
2175 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2176
2177 if ((q = strchr(++p, '@')))
2178 {
2179 *q++ = '\0';
2180
2181 if (*p != '\0')
2182 strlcpy(iptr->userptr, p, iptr->usersize);
2183
2184 if (*q != '\0')
2185 strlcpy(iptr->hostptr, q, iptr->hostsize);
2186 }
2187 else
2188 {
2189 if (*p != '\0')
2190 strlcpy(iptr->userptr, p, iptr->usersize);
2191 }
2192 }
2193 else
2194 {
2195 /* No ! found so lets look for a user@host */
2196 if ((p = strchr(iptr->nuhmask, '@')))
2197 {
2198 /* if found a @ */
2199 *p++ = '\0';
2200
2201 if (*iptr->nuhmask != '\0')
2202 strlcpy(iptr->userptr, iptr->nuhmask, iptr->usersize);
2203
2204 if (*p != '\0')
2205 strlcpy(iptr->hostptr, p, iptr->hostsize);
2206 }
2207 else
2208 {
2209 /* no @ found */
2210 if (!iptr->nickptr || strpbrk(iptr->nuhmask, ".:"))
2211 strlcpy(iptr->hostptr, iptr->nuhmask, iptr->hostsize);
2212 else
2213 strlcpy(iptr->nickptr, iptr->nuhmask, iptr->nicksize);
2214 }
2215 }
2216 }

Properties

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