ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf.c
Revision: 3022
Committed: Mon Feb 24 20:41:16 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 58963 byte(s)
Log Message:
- Moved "struct config_channel_entry ConfigChannel" from channel.c to conf.c

File Contents

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

Properties

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