1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// ./agent/current/src/agent_read_config.c
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//==========================================================================
|
7 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
8 |
|
|
// -------------------------------------------
|
9 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
10 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
11 |
|
|
//
|
12 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
13 |
|
|
// the terms of the GNU General Public License as published by the Free
|
14 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
15 |
|
|
// version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
18 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License
|
23 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use
|
27 |
|
|
// macros or inline functions from this file, or you compile this file
|
28 |
|
|
// and link it with other works to produce a work based on this file,
|
29 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
30 |
|
|
// the GNU General Public License. However the source code for this file
|
31 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
32 |
|
|
// General Public License v2.
|
33 |
|
|
//
|
34 |
|
|
// This exception does not invalidate any other reasons why a work based
|
35 |
|
|
// on this file might be covered by the GNU General Public License.
|
36 |
|
|
// -------------------------------------------
|
37 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
38 |
|
|
//####UCDSNMPCOPYRIGHTBEGIN####
|
39 |
|
|
//
|
40 |
|
|
// -------------------------------------------
|
41 |
|
|
//
|
42 |
|
|
// Portions of this software may have been derived from the UCD-SNMP
|
43 |
|
|
// project, <http://ucd-snmp.ucdavis.edu/> from the University of
|
44 |
|
|
// California at Davis, which was originally based on the Carnegie Mellon
|
45 |
|
|
// University SNMP implementation. Portions of this software are therefore
|
46 |
|
|
// covered by the appropriate copyright disclaimers included herein.
|
47 |
|
|
//
|
48 |
|
|
// The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
|
49 |
|
|
// -------------------------------------------
|
50 |
|
|
//
|
51 |
|
|
//####UCDSNMPCOPYRIGHTEND####
|
52 |
|
|
//==========================================================================
|
53 |
|
|
//#####DESCRIPTIONBEGIN####
|
54 |
|
|
//
|
55 |
|
|
// Author(s): hmt
|
56 |
|
|
// Contributors: hmt
|
57 |
|
|
// Date: 2000-05-30
|
58 |
|
|
// Purpose: Port of UCD-SNMP distribution to eCos.
|
59 |
|
|
// Description:
|
60 |
|
|
//
|
61 |
|
|
//
|
62 |
|
|
//####DESCRIPTIONEND####
|
63 |
|
|
//
|
64 |
|
|
//==========================================================================
|
65 |
|
|
/********************************************************************
|
66 |
|
|
Copyright 1989, 1991, 1992 by Carnegie Mellon University
|
67 |
|
|
|
68 |
|
|
Derivative Work -
|
69 |
|
|
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
|
70 |
|
|
|
71 |
|
|
All Rights Reserved
|
72 |
|
|
|
73 |
|
|
Permission to use, copy, modify and distribute this software and its
|
74 |
|
|
documentation for any purpose and without fee is hereby granted,
|
75 |
|
|
provided that the above copyright notice appears in all copies and
|
76 |
|
|
that both that copyright notice and this permission notice appear in
|
77 |
|
|
supporting documentation, and that the name of CMU and The Regents of
|
78 |
|
|
the University of California not be used in advertising or publicity
|
79 |
|
|
pertaining to distribution of the software without specific written
|
80 |
|
|
permission.
|
81 |
|
|
|
82 |
|
|
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
|
83 |
|
|
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
84 |
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
|
85 |
|
|
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
|
86 |
|
|
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
87 |
|
|
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
88 |
|
|
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
89 |
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
90 |
|
|
*********************************************************************/
|
91 |
|
|
/*
|
92 |
|
|
* agent_read_config.c
|
93 |
|
|
*/
|
94 |
|
|
|
95 |
|
|
#include <config.h>
|
96 |
|
|
|
97 |
|
|
#include <sys/types.h>
|
98 |
|
|
#if HAVE_STDLIB_H
|
99 |
|
|
#include <stdlib.h>
|
100 |
|
|
#endif
|
101 |
|
|
#if HAVE_STRING_H
|
102 |
|
|
#include <string.h>
|
103 |
|
|
#else
|
104 |
|
|
#include <strings.h>
|
105 |
|
|
#endif
|
106 |
|
|
#include <stdio.h>
|
107 |
|
|
#include <ctype.h>
|
108 |
|
|
#include <errno.h>
|
109 |
|
|
|
110 |
|
|
#if TIME_WITH_SYS_TIME
|
111 |
|
|
# ifdef WIN32
|
112 |
|
|
# include <sys/timeb.h>
|
113 |
|
|
# else
|
114 |
|
|
# include <sys/time.h>
|
115 |
|
|
# endif
|
116 |
|
|
# include <time.h>
|
117 |
|
|
#else
|
118 |
|
|
# if HAVE_SYS_TIME_H
|
119 |
|
|
# include <sys/time.h>
|
120 |
|
|
# else
|
121 |
|
|
# include <time.h>
|
122 |
|
|
# endif
|
123 |
|
|
#endif
|
124 |
|
|
#if HAVE_NETINET_IN_H
|
125 |
|
|
#include <netinet/in.h>
|
126 |
|
|
#endif
|
127 |
|
|
#if HAVE_NETINET_IN_SYSTM_H
|
128 |
|
|
#include <netinet/in_systm.h>
|
129 |
|
|
#endif
|
130 |
|
|
#if HAVE_NETINET_IP_H
|
131 |
|
|
#include <netinet/ip.h>
|
132 |
|
|
#endif
|
133 |
|
|
#ifdef INET6
|
134 |
|
|
#if HAVE_NETINET_IP6_H
|
135 |
|
|
#include <netinet/ip6.h>
|
136 |
|
|
#endif
|
137 |
|
|
#endif
|
138 |
|
|
#if HAVE_SYS_QUEUE_H
|
139 |
|
|
#include <sys/queue.h>
|
140 |
|
|
#endif
|
141 |
|
|
#if HAVE_SYS_SOCKET_H
|
142 |
|
|
#include <sys/socket.h>
|
143 |
|
|
#elif HAVE_WINSOCK_H
|
144 |
|
|
#include <winsock.h>
|
145 |
|
|
#endif
|
146 |
|
|
#if HAVE_SYS_STREAM_H
|
147 |
|
|
#include <sys/stream.h>
|
148 |
|
|
#endif
|
149 |
|
|
#if HAVE_NET_ROUTE_H
|
150 |
|
|
#include <net/route.h>
|
151 |
|
|
#endif
|
152 |
|
|
#if HAVE_NETINET_IP_VAR_H
|
153 |
|
|
#include <netinet/ip_var.h>
|
154 |
|
|
#endif
|
155 |
|
|
#ifdef INET6
|
156 |
|
|
#if HAVE_NETINET6_IP6_VAR_H
|
157 |
|
|
#include <netinet6/ip6_var.h>
|
158 |
|
|
#endif
|
159 |
|
|
#endif
|
160 |
|
|
#if HAVE_NETINET_IN_PCB_H
|
161 |
|
|
#include <netinet/in_pcb.h>
|
162 |
|
|
#endif
|
163 |
|
|
#if HAVE_INET_MIB2_H
|
164 |
|
|
#include <inet/mib2.h>
|
165 |
|
|
#endif
|
166 |
|
|
|
167 |
|
|
#if HAVE_DMALLOC_H
|
168 |
|
|
#include <dmalloc.h>
|
169 |
|
|
#endif
|
170 |
|
|
|
171 |
|
|
#include "mibincl.h"
|
172 |
|
|
#include "snmpusm.h"
|
173 |
|
|
|
174 |
|
|
#include "mibgroup/struct.h"
|
175 |
|
|
#include "read_config.h"
|
176 |
|
|
#include "agent_read_config.h"
|
177 |
|
|
#include "callback.h"
|
178 |
|
|
#include "snmp_agent.h"
|
179 |
|
|
#include "agent_trap.h"
|
180 |
|
|
#include "snmpd.h"
|
181 |
|
|
#include "system.h"
|
182 |
|
|
#include "snmp_debug.h"
|
183 |
|
|
#include "snmp_alarm.h"
|
184 |
|
|
#include "default_store.h"
|
185 |
|
|
#include "ds_agent.h"
|
186 |
|
|
#include "mib_module_includes.h"
|
187 |
|
|
|
188 |
|
|
char dontReadConfigFiles;
|
189 |
|
|
char *optconfigfile;
|
190 |
|
|
|
191 |
|
|
void init_agent_read_config (const char *app)
|
192 |
|
|
{
|
193 |
|
|
if ( app != NULL )
|
194 |
|
|
ds_set_string(DS_LIBRARY_ID, DS_LIB_APPTYPE, app);
|
195 |
|
|
|
196 |
|
|
register_app_config_handler("authtrapenable",
|
197 |
|
|
snmpd_parse_config_authtrap, NULL,
|
198 |
|
|
"1 | 2\t\t(1 = enable, 2 = disable)");
|
199 |
|
|
|
200 |
|
|
if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) == MASTER_AGENT ) {
|
201 |
|
|
register_app_config_handler("trapsink",
|
202 |
|
|
snmpd_parse_config_trapsink, snmpd_free_trapsinks,
|
203 |
|
|
"host [community]");
|
204 |
|
|
register_app_config_handler("trap2sink",
|
205 |
|
|
snmpd_parse_config_trap2sink, NULL,
|
206 |
|
|
"host [community]");
|
207 |
|
|
register_app_config_handler("informsink",
|
208 |
|
|
snmpd_parse_config_informsink, NULL,
|
209 |
|
|
"host [community]");
|
210 |
|
|
}
|
211 |
|
|
register_app_config_handler("trapcommunity",
|
212 |
|
|
snmpd_parse_config_trapcommunity,
|
213 |
|
|
snmpd_free_trapcommunity,
|
214 |
|
|
"community-string");
|
215 |
|
|
#include "mib_module_dot_conf.h"
|
216 |
|
|
#ifdef TESTING
|
217 |
|
|
print_config_handlers();
|
218 |
|
|
#endif
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
void update_config(void)
|
222 |
|
|
{
|
223 |
|
|
free_config();
|
224 |
|
|
read_configs();
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
|
228 |
|
|
void
|
229 |
|
|
snmpd_register_config_handler(const char *token,
|
230 |
|
|
void (*parser) (const char *, char *),
|
231 |
|
|
void (*releaser) (void),
|
232 |
|
|
const char *help)
|
233 |
|
|
{
|
234 |
|
|
DEBUGMSGTL(("snmpd_register_app_config_handler",
|
235 |
|
|
"registering .conf token for \"%s\"\n", token));
|
236 |
|
|
register_app_config_handler(token, parser, releaser, help);
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
void
|
240 |
|
|
snmpd_unregister_config_handler(const char *token)
|
241 |
|
|
{
|
242 |
|
|
unregister_app_config_handler(token);
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
/* this function is intended for use by mib-modules to store permenant
|
246 |
|
|
configuration information generated by sets or persistent counters */
|
247 |
|
|
void
|
248 |
|
|
snmpd_store_config(const char *line)
|
249 |
|
|
{
|
250 |
|
|
read_app_config_store(line);
|
251 |
|
|
}
|