1 |
michael |
5052 |
/* |
2 |
michael |
5351 |
* Copyright (c) 2002 Erik Fears |
3 |
michael |
7927 |
* Copyright (c) 2014-2017 ircd-hybrid development team |
4 |
michael |
5052 |
* |
5 |
michael |
5351 |
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
michael |
5052 |
* |
10 |
michael |
5351 |
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
michael |
5052 |
* |
15 |
michael |
5351 |
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, write to the Free Software |
17 |
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
18 |
|
|
* USA |
19 |
michael |
5052 |
*/ |
20 |
|
|
|
21 |
|
|
#include "setup.h" |
22 |
|
|
|
23 |
|
|
#include <stdio.h> |
24 |
michael |
5254 |
#include <errno.h> |
25 |
michael |
5216 |
#include <string.h> |
26 |
michael |
5335 |
#include <stdlib.h> |
27 |
michael |
5052 |
|
28 |
|
|
#include "config.h" |
29 |
michael |
5270 |
#include "config-parser.h" |
30 |
michael |
7711 |
#include "compat.h" |
31 |
michael |
5333 |
#include "memory.h" |
32 |
michael |
5052 |
#include "log.h" |
33 |
|
|
#include "scan.h" |
34 |
|
|
#include "irc.h" |
35 |
|
|
#include "opercmd.h" |
36 |
|
|
#include "stats.h" |
37 |
|
|
#include "firedns.h" |
38 |
michael |
7711 |
#include "misc.h" |
39 |
michael |
5052 |
|
40 |
|
|
|
41 |
michael |
7711 |
FILE *conf_file; |
42 |
michael |
5052 |
struct OptionsConf *OptionsItem = NULL; |
43 |
|
|
struct IRCConf *IRCItem = NULL; |
44 |
|
|
struct OpmConf *OpmItem = NULL; |
45 |
|
|
struct ExemptConf *ExemptItem = NULL; |
46 |
|
|
list_t *UserItemList = NULL; |
47 |
|
|
list_t *ScannerItemList = NULL; |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
/* Malloc and initialize configuration data to NULL */ |
51 |
michael |
5667 |
static void |
52 |
michael |
5114 |
config_init(void) |
53 |
michael |
5052 |
{ |
54 |
michael |
5114 |
/* Init IRC block */ |
55 |
michael |
6149 |
IRCItem = xcalloc(sizeof(*IRCItem)); |
56 |
michael |
5114 |
IRCItem->channels = list_create(); |
57 |
|
|
IRCItem->performs = list_create(); |
58 |
michael |
5405 |
IRCItem->notices = list_create(); |
59 |
michael |
5052 |
|
60 |
michael |
5114 |
/* Init Options block */ |
61 |
michael |
6149 |
OptionsItem = xcalloc(sizeof(*OptionsItem)); |
62 |
michael |
5052 |
|
63 |
michael |
5114 |
/* Init OPM block */ |
64 |
michael |
6149 |
OpmItem = xcalloc(sizeof(*OpmItem)); |
65 |
michael |
5114 |
OpmItem->blacklists = list_create(); |
66 |
michael |
5052 |
|
67 |
michael |
5114 |
/* Init list of User blocks */ |
68 |
|
|
UserItemList = list_create(); |
69 |
michael |
5052 |
|
70 |
michael |
5114 |
/* Init list of Scanner blocks */ |
71 |
|
|
ScannerItemList = list_create(); |
72 |
michael |
5052 |
|
73 |
michael |
5114 |
/* Init list of Exempts */ |
74 |
michael |
6149 |
ExemptItem = xcalloc(sizeof(*ExemptItem)); |
75 |
michael |
5114 |
ExemptItem->masks = list_create(); |
76 |
michael |
5052 |
} |
77 |
|
|
|
78 |
|
|
/* Setup structs that hold configuration data and then reset default values */ |
79 |
michael |
5667 |
static void |
80 |
michael |
5114 |
config_setup(void) |
81 |
michael |
5052 |
{ |
82 |
michael |
5114 |
/* Setup IRC Block Defaults */ |
83 |
michael |
5148 |
IRCItem->mode = xstrdup("+c"); |
84 |
michael |
5114 |
IRCItem->nick = xstrdup("hopm"); |
85 |
|
|
IRCItem->port = 6667; |
86 |
michael |
5198 |
IRCItem->readtimeout = 900; |
87 |
michael |
6078 |
IRCItem->reconnectinterval = 30; |
88 |
michael |
5114 |
IRCItem->oper = xstrdup("undefined"); |
89 |
|
|
IRCItem->username = xstrdup("hopm"); |
90 |
|
|
IRCItem->realname = xstrdup("Hybrid Open Proxy Monitor"); |
91 |
|
|
IRCItem->server = xstrdup("irc.example.org"); |
92 |
michael |
8135 |
IRCItem->connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9a-fA-F\\.:]+)\\].*"); |
93 |
michael |
5114 |
IRCItem->kline = xstrdup("KLINE %u@%h :Open Proxy found on your host."); |
94 |
michael |
5052 |
|
95 |
michael |
5114 |
/* Setup options block defaults */ |
96 |
michael |
7014 |
OptionsItem->command_queue_size = 64; |
97 |
|
|
OptionsItem->command_interval = 10; |
98 |
|
|
OptionsItem->command_timeout = 180; |
99 |
michael |
5114 |
OptionsItem->negcache = 0; /* 0 disabled negcache */ |
100 |
michael |
5332 |
OptionsItem->negcache_rebuild = 43200; |
101 |
michael |
5114 |
OptionsItem->pidfile = xstrdup("hopm.pid"); |
102 |
|
|
OptionsItem->dns_fdlimit = 50; |
103 |
michael |
6200 |
OptionsItem->dns_timeout = 5; |
104 |
michael |
5114 |
OptionsItem->scanlog = NULL; |
105 |
michael |
5052 |
} |
106 |
|
|
|
107 |
michael |
5726 |
/* Load configuration from filename, via flex/bison parser */ |
108 |
michael |
5114 |
void |
109 |
michael |
5270 |
config_load(const char *filename) |
110 |
|
|
{ |
111 |
|
|
config_init(); |
112 |
|
|
config_setup(); /* Setup/clear current configuration */ |
113 |
|
|
|
114 |
|
|
log_printf("CONFIG -> Loading %s", filename); |
115 |
|
|
|
116 |
michael |
7711 |
strlcpy(conffilebuf, filename, sizeof(conffilebuf)); |
117 |
|
|
|
118 |
|
|
if ((conf_file = fopen(filename, "r")) == NULL) |
119 |
michael |
5270 |
{ |
120 |
|
|
log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno)); |
121 |
|
|
exit(EXIT_FAILURE); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
|
yyparse(); |
125 |
michael |
7711 |
fclose(conf_file); |
126 |
michael |
5270 |
|
127 |
|
|
scan_init(); /* Initialize the scanners once we have the configuration */ |
128 |
|
|
stats_init(); /* Initialize stats (UPTIME) */ |
129 |
|
|
firedns_init(); /* Initialize adns */ |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
void |
133 |
michael |
5114 |
yyerror(const char *str) |
134 |
michael |
5052 |
{ |
135 |
michael |
7728 |
log_printf("CONFIG -> \"%s\", line %u: %s: %s", conffilebuf, lineno, str, stripws(linebuf)); |
136 |
michael |
5114 |
exit(EXIT_FAILURE); |
137 |
michael |
5052 |
} |