| 1 |
/* |
| 2 |
* Copyright (c) 2002 Erik Fears |
| 3 |
* Copyright (c) 2014-2016 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 |
static 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 |
static 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->reconnectinterval = 30; |
| 86 |
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 |
|
| 93 |
/* Setup options block defaults */ |
| 94 |
OptionsItem->negcache = 0; /* 0 disabled negcache */ |
| 95 |
OptionsItem->negcache_rebuild = 43200; |
| 96 |
OptionsItem->pidfile = xstrdup("hopm.pid"); |
| 97 |
OptionsItem->dns_fdlimit = 50; |
| 98 |
OptionsItem->dns_timeout = 5; |
| 99 |
OptionsItem->scanlog = NULL; |
| 100 |
} |
| 101 |
|
| 102 |
/* Load configuration from filename, via flex/bison parser */ |
| 103 |
void |
| 104 |
config_load(const char *filename) |
| 105 |
{ |
| 106 |
config_init(); |
| 107 |
config_setup(); /* Setup/clear current configuration */ |
| 108 |
|
| 109 |
log_printf("CONFIG -> Loading %s", filename); |
| 110 |
|
| 111 |
if ((yyin = fopen(filename, "r")) == NULL) |
| 112 |
{ |
| 113 |
log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno)); |
| 114 |
exit(EXIT_FAILURE); |
| 115 |
} |
| 116 |
|
| 117 |
yyparse(); |
| 118 |
fclose(yyin); |
| 119 |
|
| 120 |
scan_init(); /* Initialize the scanners once we have the configuration */ |
| 121 |
stats_init(); /* Initialize stats (UPTIME) */ |
| 122 |
firedns_init(); /* Initialize adns */ |
| 123 |
} |
| 124 |
|
| 125 |
void |
| 126 |
yyerror(const char *str) |
| 127 |
{ |
| 128 |
log_printf("CONFIG -> %s: line %u", str, linenum); |
| 129 |
exit(EXIT_FAILURE); |
| 130 |
} |