23 |
|
*/ |
24 |
|
|
25 |
|
#include "stdinc.h" |
26 |
+ |
#include "list.h" |
27 |
|
#include "ircd_defs.h" |
28 |
< |
#include "tools.h" |
28 |
> |
#include "balloc.h" |
29 |
|
#include "s_conf.h" |
30 |
|
#include "s_serv.h" |
31 |
|
#include "resv.h" |
40 |
|
#include "s_bsd.h" |
41 |
|
#include "irc_getaddrinfo.h" |
42 |
|
#include "ircd.h" |
42 |
– |
#include "list.h" |
43 |
|
#include "listener.h" |
44 |
|
#include "hostmask.h" |
45 |
|
#include "modules.h" |
85 |
|
extern char conffilebuf[IRCD_BUFSIZE]; |
86 |
|
extern char yytext[]; |
87 |
|
extern int yyparse(); /* defined in y.tab.c */ |
88 |
< |
int ypass = 1; /* used by yyparse() */ |
88 |
> |
|
89 |
> |
struct conf_parser_context conf_parser_ctx = { 0, 0, NULL }; |
90 |
|
|
91 |
|
/* internally defined functions */ |
92 |
|
static void lookup_confhost(struct ConfItem *); |
115 |
|
|
116 |
|
static void flags_to_ascii(unsigned int, const unsigned int[], char *, int); |
117 |
|
|
117 |
– |
FBFILE *conf_fbfile_in = NULL; |
118 |
– |
|
118 |
|
/* address of default class conf */ |
119 |
|
static struct ConfItem *class_default; |
120 |
|
|
137 |
|
static int ip_entries_count = 0; |
138 |
|
|
139 |
|
|
140 |
< |
inline void * |
140 |
> |
void * |
141 |
|
map_to_conf(struct ConfItem *aconf) |
142 |
|
{ |
143 |
|
void *conf; |
144 |
< |
conf = (void *)((unsigned long)aconf + |
145 |
< |
(unsigned long)sizeof(struct ConfItem)); |
144 |
> |
conf = (void *)((uintptr_t)aconf + |
145 |
> |
(uintptr_t)sizeof(struct ConfItem)); |
146 |
|
return(conf); |
147 |
|
} |
148 |
|
|
149 |
< |
inline struct ConfItem * |
149 |
> |
struct ConfItem * |
150 |
|
unmap_conf_item(void *aconf) |
151 |
|
{ |
152 |
|
struct ConfItem *conf; |
153 |
|
|
154 |
< |
conf = (struct ConfItem *)((unsigned long)aconf - |
155 |
< |
(unsigned long)sizeof(struct ConfItem)); |
154 |
> |
conf = (struct ConfItem *)((uintptr_t)aconf - |
155 |
> |
(uintptr_t)sizeof(struct ConfItem)); |
156 |
|
return(conf); |
157 |
|
} |
158 |
|
|
167 |
|
* if successful save hp in the conf item it was called with |
168 |
|
*/ |
169 |
|
static void |
170 |
< |
conf_dns_callback(void *vptr, struct DNSReply *reply) |
170 |
> |
conf_dns_callback(void *vptr, const struct irc_ssaddr *addr, const char *name) |
171 |
|
{ |
172 |
< |
struct AccessItem *aconf = (struct AccessItem *)vptr; |
174 |
< |
struct ConfItem *conf; |
172 |
> |
struct AccessItem *aconf = vptr; |
173 |
|
|
174 |
< |
MyFree(aconf->dns_query); |
177 |
< |
aconf->dns_query = NULL; |
174 |
> |
aconf->dns_pending = 0; |
175 |
|
|
176 |
< |
if (reply != NULL) |
177 |
< |
memcpy(&aconf->ipnum, &reply->addr, sizeof(reply->addr)); |
178 |
< |
else { |
179 |
< |
ilog(L_NOTICE, "Host not found: %s, ignoring connect{} block", |
183 |
< |
aconf->host); |
184 |
< |
conf = unmap_conf_item(aconf); |
185 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, |
186 |
< |
"Ignoring connect{} block for %s - host not found", |
187 |
< |
conf->name); |
188 |
< |
delete_conf_item(conf); |
189 |
< |
} |
176 |
> |
if (addr != NULL) |
177 |
> |
memcpy(&aconf->ipnum, addr, sizeof(aconf->ipnum)); |
178 |
> |
else |
179 |
> |
aconf->dns_failed = 1; |
180 |
|
} |
181 |
|
|
182 |
|
/* conf_dns_lookup() |
188 |
|
static void |
189 |
|
conf_dns_lookup(struct AccessItem *aconf) |
190 |
|
{ |
191 |
< |
if (aconf->dns_query == NULL) |
191 |
> |
if (!aconf->dns_pending) |
192 |
|
{ |
193 |
< |
aconf->dns_query = MyMalloc(sizeof(struct DNSQuery)); |
194 |
< |
aconf->dns_query->ptr = aconf; |
205 |
< |
aconf->dns_query->callback = conf_dns_callback; |
206 |
< |
gethost_byname(aconf->host, aconf->dns_query); |
193 |
> |
aconf->dns_pending = 1; |
194 |
> |
gethost_byname(conf_dns_callback, aconf, aconf->host); |
195 |
|
} |
196 |
|
} |
197 |
|
|
291 |
|
sizeof(struct MatchItem)); |
292 |
|
dlinkAdd(conf, &conf->node, &xconf_items); |
293 |
|
break; |
294 |
< |
|
294 |
> |
#ifdef HAVE_LIBPCRE |
295 |
|
case RXLINE_TYPE: |
296 |
|
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem) + |
297 |
|
sizeof(struct MatchItem)); |
305 |
|
aconf->status = CONF_KLINE; |
306 |
|
dlinkAdd(conf, &conf->node, &rkconf_items); |
307 |
|
break; |
308 |
< |
|
308 |
> |
#endif |
309 |
|
case CLUSTER_TYPE: |
310 |
|
conf = (struct ConfItem *)MyMalloc(sizeof(struct ConfItem)); |
311 |
|
dlinkAdd(conf, &conf->node, &cluster_items); |
369 |
|
case SERVER_TYPE: |
370 |
|
aconf = map_to_conf(conf); |
371 |
|
|
372 |
< |
if (aconf->dns_query != NULL) |
373 |
< |
{ |
386 |
< |
delete_resolver_queries(aconf->dns_query); |
387 |
< |
MyFree(aconf->dns_query); |
388 |
< |
} |
372 |
> |
if (aconf->dns_pending) |
373 |
> |
delete_resolver_queries(aconf); |
374 |
|
if (aconf->passwd != NULL) |
375 |
|
memset(aconf->passwd, 0, strlen(aconf->passwd)); |
376 |
|
if (aconf->spasswd != NULL) |
383 |
|
MyFree(aconf->oper_reason); |
384 |
|
MyFree(aconf->user); |
385 |
|
MyFree(aconf->host); |
401 |
– |
MyFree(aconf->fakename); |
386 |
|
#ifdef HAVE_LIBCRYPTO |
387 |
|
if (aconf->rsa_public_key) |
388 |
|
RSA_free(aconf->rsa_public_key); |
462 |
|
dlinkDelete(&conf->node, &xconf_items); |
463 |
|
MyFree(conf); |
464 |
|
break; |
465 |
< |
|
465 |
> |
#ifdef HAVE_LIBPCRE |
466 |
|
case RKLINE_TYPE: |
467 |
|
aconf = map_to_conf(conf); |
468 |
|
MyFree(aconf->regexuser); |
485 |
|
dlinkDelete(&conf->node, &rxconf_items); |
486 |
|
MyFree(conf); |
487 |
|
break; |
488 |
< |
|
488 |
> |
#endif |
489 |
|
case NRESV_TYPE: |
490 |
|
match_item = map_to_conf(conf); |
491 |
|
MyFree(match_item->user); |
612 |
|
} |
613 |
|
break; |
614 |
|
|
615 |
+ |
#ifdef HAVE_LIBPCRE |
616 |
|
case RXLINE_TYPE: |
617 |
|
DLINK_FOREACH(ptr, rxconf_items.head) |
618 |
|
{ |
641 |
|
aconf->reason, aconf->oper_reason ? aconf->oper_reason : ""); |
642 |
|
} |
643 |
|
break; |
644 |
+ |
#endif |
645 |
|
|
646 |
|
case ULINE_TYPE: |
647 |
|
DLINK_FOREACH(ptr, uconf_items.head) |
732 |
|
*p++ = 'A'; |
733 |
|
if (IsConfCryptLink(aconf)) |
734 |
|
*p++ = 'C'; |
749 |
– |
if (aconf->fakename) |
750 |
– |
*p++ = 'M'; |
735 |
|
if (IsConfTopicBurst(aconf)) |
736 |
|
*p++ = 'T'; |
737 |
|
if (IsConfCompressed(aconf)) |
784 |
|
case CRESV_TYPE: |
785 |
|
case NRESV_TYPE: |
786 |
|
case CLUSTER_TYPE: |
787 |
+ |
default: |
788 |
|
break; |
789 |
|
} |
790 |
|
} |
1176 |
|
{ |
1177 |
|
struct sockaddr_in *v4 = (struct sockaddr_in *)addr; |
1178 |
|
int hash; |
1179 |
< |
u_int32_t ip; |
1179 |
> |
uint32_t ip; |
1180 |
|
|
1181 |
|
ip = ntohl(v4->sin_addr.s_addr); |
1182 |
|
hash = ((ip >> 12) + ip) & (IP_HASH_SIZE-1); |
1187 |
|
{ |
1188 |
|
int hash; |
1189 |
|
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
1190 |
< |
u_int32_t *ip = (u_int32_t *)&v6->sin6_addr.s6_addr; |
1190 |
> |
uint32_t *ip = (uint32_t *)&v6->sin6_addr.s6_addr; |
1191 |
|
|
1192 |
|
hash = ip[0] ^ ip[3]; |
1193 |
|
hash ^= hash >> 16; |
1572 |
|
|
1573 |
|
switch (type) |
1574 |
|
{ |
1575 |
< |
case RXLINE_TYPE: |
1575 |
> |
#ifdef HAVE_LIBPCRE |
1576 |
> |
case RXLINE_TYPE: |
1577 |
|
DLINK_FOREACH(ptr, list_p->head) |
1578 |
|
{ |
1579 |
|
conf = ptr->data; |
1583 |
|
return conf; |
1584 |
|
} |
1585 |
|
break; |
1586 |
< |
|
1586 |
> |
#endif |
1587 |
|
case XLINE_TYPE: |
1588 |
|
case ULINE_TYPE: |
1589 |
|
case NRESV_TYPE: |
1747 |
|
sendto_realops_flags(UMODE_ALL, L_ALL, |
1748 |
|
"Got signal SIGHUP, reloading ircd.conf file"); |
1749 |
|
|
1764 |
– |
#ifndef _WIN32 |
1750 |
|
restart_resolver(); |
1751 |
< |
#endif |
1751 |
> |
|
1752 |
|
/* don't close listeners until we know we can go ahead with the rehash */ |
1753 |
|
|
1754 |
|
/* Check to see if we magically got(or lost) IPv6 support */ |
1807 |
|
ServerInfo.specific_ipv6_vhost = 0; |
1808 |
|
|
1809 |
|
ServerInfo.max_clients = MAXCLIENTS_MAX; |
1810 |
< |
/* Don't reset hub, as that will break lazylinks */ |
1811 |
< |
/* ServerInfo.hub = NO; */ |
1810 |
> |
|
1811 |
> |
ServerInfo.hub = 0; |
1812 |
> |
delete_capability("HUB"); |
1813 |
|
ServerInfo.dns_host.sin_addr.s_addr = 0; |
1814 |
|
ServerInfo.dns_host.sin_port = 0; |
1815 |
|
AdminInfo.name = NULL; |
1868 |
|
ConfigFileEntry.default_floodcount = 8; /* XXX */ |
1869 |
|
ConfigFileEntry.failed_oper_notice = YES; |
1870 |
|
ConfigFileEntry.dots_in_ident = 0; /* XXX */ |
1885 |
– |
ConfigFileEntry.dot_in_ip6_addr = YES; |
1871 |
|
ConfigFileEntry.min_nonwildcard = 4; |
1872 |
|
ConfigFileEntry.min_nonwildcard_simple = 3; |
1873 |
|
ConfigFileEntry.max_accept = 20; |
1933 |
|
lineno = 0; |
1934 |
|
|
1935 |
|
set_default_conf(); /* Set default values prior to conf parsing */ |
1936 |
< |
ypass = 1; |
1936 |
> |
conf_parser_ctx.pass = 1; |
1937 |
|
yyparse(); /* pick up the classes first */ |
1938 |
|
|
1939 |
|
fbrewind(file); |
1940 |
|
|
1941 |
< |
ypass = 2; |
1941 |
> |
conf_parser_ctx.pass = 2; |
1942 |
|
yyparse(); /* Load the values from the conf */ |
1943 |
|
validate_conf(); /* Check to make sure some values are still okay. */ |
1944 |
|
/* Some global values are also loaded here. */ |
2056 |
|
static struct AccessItem * |
2057 |
|
find_regexp_kline(const char *uhi[]) |
2058 |
|
{ |
2059 |
+ |
#ifdef HAVE_LIBPCRE |
2060 |
|
const dlink_node *ptr = NULL; |
2061 |
|
|
2062 |
|
DLINK_FOREACH(ptr, rkconf_items.head) |
2071 |
|
!ircd_pcre_exec(aptr->regexhost, uhi[2]))) |
2072 |
|
return aptr; |
2073 |
|
} |
2074 |
< |
|
2074 |
> |
#endif |
2075 |
|
return NULL; |
2076 |
|
} |
2077 |
|
|
2411 |
|
char chanmodes[32]; |
2412 |
|
char chanlimit[32]; |
2413 |
|
|
2414 |
+ |
conf_parser_ctx.boot = cold; |
2415 |
|
filename = get_conf_name(CONF_TYPE); |
2416 |
|
|
2417 |
|
/* We need to know the initial filename for the yyerror() to report |
2422 |
|
*/ |
2423 |
|
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
2424 |
|
|
2425 |
< |
if ((conf_fbfile_in = fbopen(filename, "r")) == NULL) |
2425 |
> |
if ((conf_parser_ctx.conf_file = fbopen(filename, "r")) == NULL) |
2426 |
|
{ |
2427 |
|
if (cold) |
2428 |
|
{ |
2442 |
|
if (!cold) |
2443 |
|
clear_out_old_conf(); |
2444 |
|
|
2445 |
< |
read_conf(conf_fbfile_in); |
2446 |
< |
fbclose(conf_fbfile_in); |
2445 |
> |
read_conf(conf_parser_ctx.conf_file); |
2446 |
> |
fbclose(conf_parser_ctx.conf_file); |
2447 |
|
|
2448 |
|
add_isupport("NETWORK", ServerInfo.network_name, -1); |
2449 |
|
ircsprintf(chanmodes, "b%s%s:%d", ConfigChannel.use_except ? "e" : "", |
2472 |
|
*/ |
2473 |
|
rebuild_isupport_message_line(); |
2474 |
|
|
2475 |
< |
parse_conf_file(KLINE_TYPE, cold); |
2475 |
> |
#ifdef HAVE_LIBPCRE |
2476 |
|
parse_conf_file(RKLINE_TYPE, cold); |
2477 |
+ |
parse_conf_file(RXLINE_TYPE, cold); |
2478 |
+ |
#endif |
2479 |
+ |
parse_conf_file(KLINE_TYPE, cold); |
2480 |
|
parse_conf_file(DLINE_TYPE, cold); |
2481 |
|
parse_conf_file(XLINE_TYPE, cold); |
2492 |
– |
parse_conf_file(RXLINE_TYPE, cold); |
2482 |
|
parse_conf_file(NRESV_TYPE, cold); |
2483 |
|
parse_conf_file(CRESV_TYPE, cold); |
2484 |
|
} |
3068 |
|
return 0; |
3069 |
|
} |
3070 |
|
|
3082 |
– |
/* conf_add_d_conf() |
3083 |
– |
* |
3084 |
– |
* inputs - pointer to config item |
3085 |
– |
* output - NONE |
3086 |
– |
* side effects - Add a d/D line |
3087 |
– |
*/ |
3088 |
– |
void |
3089 |
– |
conf_add_d_conf(struct AccessItem *aconf) |
3090 |
– |
{ |
3091 |
– |
if (aconf->host == NULL) |
3092 |
– |
return; |
3093 |
– |
|
3094 |
– |
aconf->user = NULL; |
3095 |
– |
|
3096 |
– |
/* XXX - Should 'd' ever be in the old conf? For new conf we don't |
3097 |
– |
* need this anyway, so I will disable it for now... -A1kmm |
3098 |
– |
*/ |
3099 |
– |
if (parse_netmask(aconf->host, NULL, NULL) == HM_HOST) |
3100 |
– |
{ |
3101 |
– |
ilog(L_WARN, "Invalid Dline %s ignored", aconf->host); |
3102 |
– |
free_access_item(aconf); |
3103 |
– |
} |
3104 |
– |
else |
3105 |
– |
{ |
3106 |
– |
/* XXX ensure user is NULL */ |
3107 |
– |
MyFree(aconf->user); |
3108 |
– |
aconf->user = NULL; |
3109 |
– |
add_conf_by_address(CONF_DLINE, aconf); |
3110 |
– |
} |
3111 |
– |
} |
3112 |
– |
|
3071 |
|
/* yyerror() |
3072 |
|
* |
3073 |
|
* inputs - message from parser |
3079 |
|
{ |
3080 |
|
char newlinebuf[IRCD_BUFSIZE]; |
3081 |
|
|
3082 |
< |
if (ypass != 1) |
3082 |
> |
if (conf_parser_ctx.pass != 1) |
3083 |
|
return; |
3084 |
|
|
3085 |
|
strip_tabs(newlinebuf, linebuf, sizeof(newlinebuf)); |