ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config.c
Revision: 5254
Committed: Thu Jan 1 13:57:07 2015 UTC (11 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 3859 byte(s)
Log Message:
- config.c:config_load(): improved error reporting if fopen() fails

File Contents

# User Rev Content
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 michael 5254
27 michael 5052 #include <stdio.h>
28 michael 5254 #include <errno.h>
29 michael 5216 #include <string.h>
30 michael 5052
31     #include "config.h"
32     #include "malloc.h"
33     #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     extern int yyparse(void);
42    
43     void config_setup(void);
44     void config_init(void);
45    
46    
47    
48     struct OptionsConf *OptionsItem = NULL;
49     struct IRCConf *IRCItem = NULL;
50     struct OpmConf *OpmItem = NULL;
51     struct ExemptConf *ExemptItem = NULL;
52     list_t *UserItemList = NULL;
53     list_t *ScannerItemList = NULL;
54    
55    
56     /* Rehash or load new configuration from filename, via flex/bison parser */
57 michael 5114 void
58     config_load(const char *filename)
59 michael 5052 {
60 michael 5114 config_init();
61     config_setup(); /* Setup/clear current configuration */
62 michael 5052
63 michael 5114 log_printf("CONFIG -> Loading %s", filename);
64 michael 5052
65 michael 5114 if ((yyin = fopen(filename, "r")) == NULL)
66     {
67 michael 5254 log_printf("CONFIG -> Error opening %s: %s", filename, strerror(errno));
68 michael 5151 exit(EXIT_FAILURE);
69 michael 5114 }
70 michael 5052
71 michael 5114 yyparse();
72 michael 5052
73 michael 5114 scan_init(); /* Initialize the scanners once we have the configuration */
74     command_init(); /* Initialize the command queue */
75     stats_init(); /* Initialize stats (UPTIME) */
76     firedns_init(); /* Initialize adns */
77 michael 5052
78 michael 5114 fclose(yyin);
79 michael 5052 }
80    
81     /* Malloc and initialize configuration data to NULL */
82 michael 5114 void
83     config_init(void)
84 michael 5052 {
85 michael 5114 /* Init IRC block */
86     IRCItem = MyMalloc(sizeof *IRCItem);
87     IRCItem->channels = list_create();
88     IRCItem->performs = list_create();
89 michael 5052
90 michael 5114 /* Init Options block */
91     OptionsItem = MyMalloc(sizeof *OptionsItem);
92 michael 5052
93 michael 5114 /* Init OPM block */
94     OpmItem = MyMalloc(sizeof *OpmItem);
95     OpmItem->blacklists = list_create();
96 michael 5052
97 michael 5114 /* Init list of User blocks */
98     UserItemList = list_create();
99 michael 5052
100 michael 5114 /* Init list of Scanner blocks */
101     ScannerItemList = list_create();
102 michael 5052
103 michael 5114 /* Init list of Exempts */
104     ExemptItem = MyMalloc(sizeof *ExemptItem);
105     ExemptItem->masks = list_create();
106 michael 5052 }
107    
108     /* Setup structs that hold configuration data and then reset default values */
109 michael 5114 void
110     config_setup(void)
111 michael 5052 {
112 michael 5114 /* Setup IRC Block Defaults */
113 michael 5148 IRCItem->mode = xstrdup("+c");
114 michael 5114 IRCItem->nick = xstrdup("hopm");
115     IRCItem->nickserv = xstrdup("");
116     IRCItem->password = xstrdup("");
117     IRCItem->port = 6667;
118 michael 5198 IRCItem->readtimeout = 900;
119 michael 5114 IRCItem->oper = xstrdup("undefined");
120     IRCItem->username = xstrdup("hopm");
121     IRCItem->realname = xstrdup("Hybrid Open Proxy Monitor");
122     IRCItem->server = xstrdup("irc.example.org");
123     IRCItem->vhost = xstrdup("");
124     IRCItem->connregex = xstrdup("\\*\\*\\* Notice -- Client connecting: ([^ ]+) \\(([^@]+)@([^\\)]+)\\) \\[([0-9\\.]+)\\].*");
125     IRCItem->kline = xstrdup("KLINE %u@%h :Open Proxy found on your host.");
126 michael 5052
127    
128 michael 5114 /* Setup options block defaults */
129     OptionsItem->negcache = 0; /* 0 disabled negcache */
130     OptionsItem->pidfile = xstrdup("hopm.pid");
131     OptionsItem->dns_fdlimit = 50;
132     OptionsItem->scanlog = NULL;
133 michael 5052
134 michael 5114 /* Setup OPM block defaults */
135     OpmItem->sendmail = xstrdup("/usr/sbin/sendmail");
136     OpmItem->dnsbl_from = xstrdup("");
137     OpmItem->dnsbl_to = xstrdup("");
138 michael 5052 }
139    
140 michael 5114 void
141     yyerror(const char *str)
142 michael 5052 {
143 michael 5114 log_printf("CONFIG -> %s: line %d", str, linenum);
144     exit(EXIT_FAILURE);
145 michael 5052 }

Properties

Name Value
svn:eol-style native
svn:keywords Id