1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// ./lib/current/src/default_store.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 Red Hat, 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 version.
|
15 |
|
|
//
|
16 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
17 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
18 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
19 |
|
|
// for more details.
|
20 |
|
|
//
|
21 |
|
|
// You should have received a copy of the GNU General Public License along
|
22 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
23 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
24 |
|
|
//
|
25 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
26 |
|
|
// or inline functions from this file, or you compile this file and link it
|
27 |
|
|
// with other works to produce a work based on this file, this file does not
|
28 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
29 |
|
|
// License. However the source code for this file must still be made available
|
30 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
31 |
|
|
//
|
32 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
33 |
|
|
// this file might be covered by the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
36 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//####UCDSNMPCOPYRIGHTBEGIN####
|
40 |
|
|
//
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//
|
43 |
|
|
// Portions of this software may have been derived from the UCD-SNMP
|
44 |
|
|
// project, <http://ucd-snmp.ucdavis.edu/> from the University of
|
45 |
|
|
// California at Davis, which was originally based on the Carnegie Mellon
|
46 |
|
|
// University SNMP implementation. Portions of this software are therefore
|
47 |
|
|
// covered by the appropriate copyright disclaimers included herein.
|
48 |
|
|
//
|
49 |
|
|
// The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
|
50 |
|
|
// -------------------------------------------
|
51 |
|
|
//
|
52 |
|
|
//####UCDSNMPCOPYRIGHTEND####
|
53 |
|
|
//==========================================================================
|
54 |
|
|
//#####DESCRIPTIONBEGIN####
|
55 |
|
|
//
|
56 |
|
|
// Author(s): hmt
|
57 |
|
|
// Contributors: hmt
|
58 |
|
|
// Date: 2000-05-30
|
59 |
|
|
// Purpose: Port of UCD-SNMP distribution to eCos.
|
60 |
|
|
// Description:
|
61 |
|
|
//
|
62 |
|
|
//
|
63 |
|
|
//####DESCRIPTIONEND####
|
64 |
|
|
//
|
65 |
|
|
//==========================================================================
|
66 |
|
|
/********************************************************************
|
67 |
|
|
Copyright 1989, 1991, 1992 by Carnegie Mellon University
|
68 |
|
|
|
69 |
|
|
Derivative Work -
|
70 |
|
|
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
|
71 |
|
|
|
72 |
|
|
All Rights Reserved
|
73 |
|
|
|
74 |
|
|
Permission to use, copy, modify and distribute this software and its
|
75 |
|
|
documentation for any purpose and without fee is hereby granted,
|
76 |
|
|
provided that the above copyright notice appears in all copies and
|
77 |
|
|
that both that copyright notice and this permission notice appear in
|
78 |
|
|
supporting documentation, and that the name of CMU and The Regents of
|
79 |
|
|
the University of California not be used in advertising or publicity
|
80 |
|
|
pertaining to distribution of the software without specific written
|
81 |
|
|
permission.
|
82 |
|
|
|
83 |
|
|
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
|
84 |
|
|
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
85 |
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
|
86 |
|
|
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
|
87 |
|
|
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
88 |
|
|
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
89 |
|
|
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
90 |
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
91 |
|
|
*********************************************************************/
|
92 |
|
|
/* default_store.h: storage space for defaults */
|
93 |
|
|
|
94 |
|
|
#include <config.h>
|
95 |
|
|
#include <sys/types.h>
|
96 |
|
|
#if HAVE_STDLIB_H
|
97 |
|
|
#include <stdlib.h>
|
98 |
|
|
#endif
|
99 |
|
|
#if HAVE_NETINET_IN_H
|
100 |
|
|
#include <netinet/in.h>
|
101 |
|
|
#endif
|
102 |
|
|
#if HAVE_STDLIB_H
|
103 |
|
|
#include <stdlib.h>
|
104 |
|
|
#endif
|
105 |
|
|
#if HAVE_STRING_H
|
106 |
|
|
#include <string.h>
|
107 |
|
|
#else
|
108 |
|
|
#include <strings.h>
|
109 |
|
|
#endif
|
110 |
|
|
#if HAVE_WINSOCK_H
|
111 |
|
|
#include <winsock.h>
|
112 |
|
|
#endif
|
113 |
|
|
|
114 |
|
|
#if HAVE_DMALLOC_H
|
115 |
|
|
#include <dmalloc.h>
|
116 |
|
|
#endif
|
117 |
|
|
|
118 |
|
|
#include "asn1.h"
|
119 |
|
|
#include "snmp_api.h"
|
120 |
|
|
#include "snmp_debug.h"
|
121 |
|
|
#include "snmp_logging.h"
|
122 |
|
|
#include "tools.h"
|
123 |
|
|
#include "read_config.h"
|
124 |
|
|
#include "default_store.h"
|
125 |
|
|
#include "read_config.h"
|
126 |
|
|
#include "system.h"
|
127 |
|
|
|
128 |
|
|
struct ds_read_config *ds_configs = NULL;
|
129 |
|
|
|
130 |
|
|
int ds_integers[DS_MAX_IDS][DS_MAX_SUBIDS];
|
131 |
|
|
char ds_booleans[DS_MAX_IDS][DS_MAX_SUBIDS/8]; /* bit vector storage. */
|
132 |
|
|
char *ds_strings[DS_MAX_IDS][DS_MAX_SUBIDS]; /* bit vector storage. */
|
133 |
|
|
|
134 |
|
|
int
|
135 |
|
|
ds_set_boolean(int storeid, int which, int value) {
|
136 |
|
|
|
137 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
138 |
|
|
storeid < 0 || which < 0)
|
139 |
|
|
return SNMPERR_GENERR;
|
140 |
|
|
|
141 |
|
|
DEBUGMSGTL(("ds_set_boolean","Setting %d:%d = %d/%s\n", storeid, which,
|
142 |
|
|
value, ((value)?"True":"False")));
|
143 |
|
|
|
144 |
|
|
if (value > 0)
|
145 |
|
|
ds_booleans[storeid][which/8] |= (1 << (which%8));
|
146 |
|
|
else
|
147 |
|
|
ds_booleans[storeid][which/8] &= (0xff7f >> (7-(which%8)));
|
148 |
|
|
|
149 |
|
|
return SNMPERR_SUCCESS;
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
int
|
153 |
|
|
ds_toggle_boolean(int storeid, int which) {
|
154 |
|
|
|
155 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
156 |
|
|
storeid < 0 || which < 0)
|
157 |
|
|
return SNMPERR_GENERR;
|
158 |
|
|
|
159 |
|
|
if ((ds_booleans[storeid][which/8] & (1 << (which % 8))) == 0)
|
160 |
|
|
ds_booleans[storeid][which/8] |= (1 << (which%8));
|
161 |
|
|
else
|
162 |
|
|
ds_booleans[storeid][which/8] &= (0xff7f >> (7-(which%8)));
|
163 |
|
|
|
164 |
|
|
DEBUGMSGTL(("ds_toggle_boolean","Setting %d:%d = %d/%s\n", storeid, which,
|
165 |
|
|
ds_booleans[storeid][which/8],
|
166 |
|
|
((ds_booleans[storeid][which/8])?"True":"False")));
|
167 |
|
|
|
168 |
|
|
return SNMPERR_SUCCESS;
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
int
|
172 |
|
|
ds_get_boolean(int storeid, int which) {
|
173 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
174 |
|
|
storeid < 0 || which < 0)
|
175 |
|
|
return SNMPERR_GENERR;
|
176 |
|
|
|
177 |
|
|
return ((ds_booleans[storeid][which/8] & (1 << (which%8))) ? 1 : 0);
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
int
|
181 |
|
|
ds_set_int(int storeid, int which, int value) {
|
182 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
183 |
|
|
storeid < 0 || which < 0)
|
184 |
|
|
return SNMPERR_GENERR;
|
185 |
|
|
|
186 |
|
|
DEBUGMSGTL(("ds_set_int","Setting %d:%d = %d\n", storeid, which, value));
|
187 |
|
|
|
188 |
|
|
ds_integers[storeid][which] = value;
|
189 |
|
|
return SNMPERR_SUCCESS;
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
int
|
193 |
|
|
ds_get_int(int storeid, int which) {
|
194 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
195 |
|
|
storeid < 0 || which < 0)
|
196 |
|
|
return SNMPERR_GENERR;
|
197 |
|
|
|
198 |
|
|
return (ds_integers[storeid][which]);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
int
|
202 |
|
|
ds_set_string(int storeid, int which, const char *value) {
|
203 |
|
|
|
204 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
205 |
|
|
storeid < 0 || which < 0)
|
206 |
|
|
return SNMPERR_GENERR;
|
207 |
|
|
|
208 |
|
|
DEBUGMSGTL(("ds_set_string","Setting %d:%d = %s\n", storeid, which,
|
209 |
|
|
value));
|
210 |
|
|
|
211 |
|
|
if (ds_strings[storeid][which] != NULL)
|
212 |
|
|
free(ds_strings[storeid][which]);
|
213 |
|
|
|
214 |
|
|
if (value)
|
215 |
|
|
ds_strings[storeid][which] = strdup(value);
|
216 |
|
|
else
|
217 |
|
|
ds_strings[storeid][which] = NULL;
|
218 |
|
|
|
219 |
|
|
return SNMPERR_SUCCESS;
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
char *
|
223 |
|
|
ds_get_string(int storeid, int which) {
|
224 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
225 |
|
|
storeid < 0 || which < 0)
|
226 |
|
|
return NULL;
|
227 |
|
|
|
228 |
|
|
return (ds_strings[storeid][which]);
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
void
|
232 |
|
|
ds_handle_config(const char *token, char *line) {
|
233 |
|
|
struct ds_read_config *drsp;
|
234 |
|
|
char buf[SNMP_MAXBUF];
|
235 |
|
|
int itmp;
|
236 |
|
|
|
237 |
|
|
DEBUGMSGTL(("ds_handle_config", "handling %s\n", token));
|
238 |
|
|
for(drsp = ds_configs; drsp != NULL && strcasecmp(token, drsp->token) != 0;
|
239 |
|
|
drsp = drsp->next);
|
240 |
|
|
if (drsp != NULL) {
|
241 |
|
|
DEBUGMSGTL(("ds_handle_config",
|
242 |
|
|
"setting: token=%s, type=%d, id=%d, which=%d\n",
|
243 |
|
|
drsp->token, drsp->type, drsp->storeid, drsp->which));
|
244 |
|
|
switch (drsp->type) {
|
245 |
|
|
case ASN_BOOLEAN:
|
246 |
|
|
if (strncasecmp(line,"yes",3) == 0 || strncasecmp(line,"true",4) == 0) {
|
247 |
|
|
itmp = 1;
|
248 |
|
|
} else if (strncasecmp(line,"no",3) == 0 ||
|
249 |
|
|
strncasecmp(line,"false",5) == 0) {
|
250 |
|
|
itmp = 0;
|
251 |
|
|
} else if (atoi(line) > 0) {
|
252 |
|
|
itmp = 1;
|
253 |
|
|
} else {
|
254 |
|
|
itmp = 0;
|
255 |
|
|
}
|
256 |
|
|
ds_set_boolean(drsp->storeid, drsp->which, itmp);
|
257 |
|
|
DEBUGMSGTL(("ds_handle_config", "bool: %d\n", itmp));
|
258 |
|
|
break;
|
259 |
|
|
|
260 |
|
|
case ASN_INTEGER:
|
261 |
|
|
ds_set_int(drsp->storeid, drsp->which, atoi(line));
|
262 |
|
|
DEBUGMSGTL(("ds_handle_config", "int: %d\n", atoi(line)));
|
263 |
|
|
break;
|
264 |
|
|
|
265 |
|
|
case ASN_OCTET_STR:
|
266 |
|
|
if (*line == '"') {
|
267 |
|
|
copy_word(line, buf);
|
268 |
|
|
ds_set_string(drsp->storeid, drsp->which, buf);
|
269 |
|
|
} else {
|
270 |
|
|
ds_set_string(drsp->storeid, drsp->which, line);
|
271 |
|
|
}
|
272 |
|
|
DEBUGMSGTL(("ds_handle_config", "string: %s\n", line));
|
273 |
|
|
break;
|
274 |
|
|
|
275 |
|
|
default:
|
276 |
|
|
snmp_log(LOG_CRIT,"ds_handle_config *** unknown type %d\n", drsp->type);
|
277 |
|
|
break;
|
278 |
|
|
}
|
279 |
|
|
} else {
|
280 |
|
|
snmp_log(LOG_CRIT, "ds_handle_config *** no registration for %s\n", token);
|
281 |
|
|
}
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
int
|
286 |
|
|
ds_register_config(u_char type, const char *ftype, const char *token,
|
287 |
|
|
int storeid, int which) {
|
288 |
|
|
struct ds_read_config *drsp;
|
289 |
|
|
|
290 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
291 |
|
|
storeid < 0 || which < 0 || token == NULL)
|
292 |
|
|
return SNMPERR_GENERR;
|
293 |
|
|
|
294 |
|
|
if (ds_configs == NULL) {
|
295 |
|
|
ds_configs = SNMP_MALLOC_STRUCT(ds_read_config);
|
296 |
|
|
drsp = ds_configs;
|
297 |
|
|
} else {
|
298 |
|
|
for(drsp = ds_configs; drsp->next != NULL; drsp = drsp->next);
|
299 |
|
|
drsp->next = SNMP_MALLOC_STRUCT(ds_read_config);
|
300 |
|
|
drsp = drsp->next;
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
drsp->type = type;
|
304 |
|
|
drsp->token = strdup(token);
|
305 |
|
|
drsp->storeid = storeid;
|
306 |
|
|
drsp->which = which;
|
307 |
|
|
|
308 |
|
|
switch (type) {
|
309 |
|
|
case ASN_BOOLEAN:
|
310 |
|
|
register_config_handler(ftype, token, ds_handle_config, NULL,"(1|yes|true|0|no|false)");
|
311 |
|
|
break;
|
312 |
|
|
|
313 |
|
|
case ASN_INTEGER:
|
314 |
|
|
register_config_handler(ftype, token, ds_handle_config, NULL,"integerValue");
|
315 |
|
|
break;
|
316 |
|
|
|
317 |
|
|
case ASN_OCTET_STR:
|
318 |
|
|
register_config_handler(ftype, token, ds_handle_config, NULL,"string");
|
319 |
|
|
break;
|
320 |
|
|
|
321 |
|
|
}
|
322 |
|
|
return SNMPERR_SUCCESS;
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
int
|
326 |
|
|
ds_register_premib(u_char type, const char *ftype, const char *token,
|
327 |
|
|
int storeid, int which) {
|
328 |
|
|
struct ds_read_config *drsp;
|
329 |
|
|
|
330 |
|
|
if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
|
331 |
|
|
storeid < 0 || which < 0 || token == NULL)
|
332 |
|
|
return SNMPERR_GENERR;
|
333 |
|
|
|
334 |
|
|
if (ds_configs == NULL) {
|
335 |
|
|
ds_configs = SNMP_MALLOC_STRUCT(ds_read_config);
|
336 |
|
|
drsp = ds_configs;
|
337 |
|
|
} else {
|
338 |
|
|
for(drsp = ds_configs; drsp->next != NULL; drsp = drsp->next);
|
339 |
|
|
drsp->next = SNMP_MALLOC_STRUCT(ds_read_config);
|
340 |
|
|
drsp = drsp->next;
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
drsp->type = type;
|
344 |
|
|
drsp->token = strdup(token);
|
345 |
|
|
drsp->storeid = storeid;
|
346 |
|
|
drsp->which = which;
|
347 |
|
|
|
348 |
|
|
switch (type) {
|
349 |
|
|
case ASN_BOOLEAN:
|
350 |
|
|
register_premib_handler(ftype, token, ds_handle_config, NULL,"(1|yes|true|0|no|false)");
|
351 |
|
|
break;
|
352 |
|
|
|
353 |
|
|
case ASN_INTEGER:
|
354 |
|
|
register_premib_handler(ftype, token, ds_handle_config, NULL,"integerValue");
|
355 |
|
|
break;
|
356 |
|
|
|
357 |
|
|
case ASN_OCTET_STR:
|
358 |
|
|
register_premib_handler(ftype, token, ds_handle_config, NULL,"string");
|
359 |
|
|
break;
|
360 |
|
|
|
361 |
|
|
}
|
362 |
|
|
return SNMPERR_SUCCESS;
|
363 |
|
|
}
|
364 |
|
|
|