ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/hopm/trunk/src/config.c
Revision: 5135
Committed: Thu Dec 25 18:51:51 2014 UTC (9 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 3828 byte(s)
Log Message:
- propset svn:eol-style native

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

Properties

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