ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 2283
Committed: Tue Jun 18 19:13:20 2013 UTC (12 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 59422 byte(s)
Log Message:
- Added generall::cycle_on_host_change configuration option as requested
  by Adam <adam@anope.org>

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

Properties

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