1 |
/* |
2 |
* Copyright (c) 2002 Erik Fears |
3 |
* Copyright (c) 2014-2015 ircd-hybrid development team |
4 |
* |
5 |
* 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 |
* |
10 |
* 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 |
* |
15 |
* 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 |
*/ |
20 |
|
21 |
#include "setup.h" |
22 |
|
23 |
#include <stdio.h> |
24 |
#include <errno.h> |
25 |
#include <string.h> |
26 |
#include <stdlib.h> |
27 |
|
28 |
#include "config.h" |
29 |
#include "config-parser.h" |
30 |
#include "memory.h" |
31 |
#include "log.h" |
32 |
#include "scan.h" |
33 |
#include "irc.h" |
34 |
#include "opercmd.h" |
35 |
#include "stats.h" |
36 |
#include "firedns.h" |
37 |
|
38 |
extern FILE *yyin; |
39 |
|
40 |
struct OptionsConf *OptionsItem = NULL; |
41 |
struct IRCConf *IRCItem = NULL; |
42 |
struct OpmConf *OpmItem = NULL; |
43 |
struct ExemptConf *ExemptItem = NULL; |
44 |
list_t *UserItemList = NULL; |
45 |
list_t *ScannerItemList = NULL; |
46 |
|
47 |
|
48 |
/* Malloc and initialize configuration data to NULL */ |
49 |
void |
50 |
config_init(void) |
51 |
{ |
52 |
/* Init IRC block */ |
53 |
IRCItem = xcalloc(sizeof *IRCItem); |
54 |
IRCItem->channels = list_create(); |
55 |
IRCItem->performs = list_create(); |
56 |
IRCItem->notices = list_create(); |
57 |
|
58 |
/* Init Options block */ |
59 |
OptionsItem = xcalloc(sizeof *OptionsItem); |
60 |
|
61 |
/* Init OPM block */ |
62 |
OpmItem = xcalloc(sizeof *OpmItem); |
63 |
OpmItem->blacklists = list_create(); |
64 |
|
65 |
/* Init list of User blocks */ |
66 |
UserItemList = list_create(); |
67 |
|
68 |
/* Init list of Scanner blocks */ |
69 |
ScannerItemList = list_create(); |
70 |
|
71 |
/* Init list of Exempts */ |
72 |
ExemptItem = xcalloc(sizeof *ExemptItem); |
73 |
ExemptItem->masks = list_create(); |
74 |
} |
75 |
|
76 |
/* Setup structs that hold configuration data and then reset default values */ |
77 |
void |
78 |
config_setup(void) |
79 |
{ |
80 |
/* Setup IRC Block Defaults */ |
81 |
IRCItem->mode = xstrdup("+c"); |
82 |
IRCItem->nick = xstrdup("hopm"); |
83 |
IRCItem->port = 6667; |
84 |
IRCItem->readtimeout = 900; |
85 |
IRCItem->oper = xstrdup("undefined"); |
86 |
IRCItem->username = xstrdup("hopm"); |
87 |
IRCItem->realname = xstrdup("Hybrid Open Proxy Monitor"); |
88 |
IRCItem->server = xstrdup("irc.example.org"); |
89 |
IRCItem->connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9\\.]+)\\].*"); |
90 |
IRCItem->kline = xstrdup("KLINE %u@%h :Open Proxy found on your host."); |
91 |
|
92 |
/* Setup options block defaults */ |
93 |
OptionsItem->negcache = 0; /* 0 disabled negcache */ |
94 |
OptionsItem->negcache_rebuild = 43200; |
95 |
OptionsItem->pidfile = xstrdup("hopm.pid"); |
96 |
OptionsItem->dns_fdlimit = 50; |
97 |
OptionsItem->scanlog = NULL; |
98 |
} |
99 |
|
100 |
/* Rehash or load new configuration from filename, via flex/bison parser */ |
101 |
void |
102 |
config_load(const char *filename) |
103 |
{ |
104 |
config_init(); |
105 |
config_setup(); /* Setup/clear current configuration */ |
106 |
|
107 |
log_printf("CONFIG -> Loading %s", filename); |
108 |
|
109 |
if ((yyin = fopen(filename, "r")) == NULL) |
110 |
{ |
111 |
log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno)); |
112 |
exit(EXIT_FAILURE); |
113 |
} |
114 |
|
115 |
yyparse(); |
116 |
|
117 |
scan_init(); /* Initialize the scanners once we have the configuration */ |
118 |
command_init(); /* Initialize the command queue */ |
119 |
stats_init(); /* Initialize stats (UPTIME) */ |
120 |
firedns_init(); /* Initialize adns */ |
121 |
|
122 |
fclose(yyin); |
123 |
} |
124 |
|
125 |
void |
126 |
yyerror(const char *str) |
127 |
{ |
128 |
log_printf("CONFIG -> %s: line %d", str, linenum); |
129 |
exit(EXIT_FAILURE); |
130 |
} |