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