blob: 0129217478c40b0de22a8d5230872b97858791f8 [file] [log] [blame]
Dave Shielde42fbdf2000-05-12 15:15:37 +00001/*
2 * agent_index.c
3 *
4 * Maintain a registry of index allocations
Wes Hardaker6d1f6022002-04-20 07:08:20 +00005 * (Primarily required for AgentX support,
6 * but it could be more widely useable).
Dave Shielde42fbdf2000-05-12 15:15:37 +00007 */
8
9
Wes Hardakereb6d4fc2002-01-04 21:00:48 +000010#include <net-snmp/net-snmp-config.h>
Wes Hardaker3b14c592011-02-23 00:01:18 +000011#include <net-snmp/net-snmp-features.h>
Dave Shielde42fbdf2000-05-12 15:15:37 +000012#include <signal.h>
13#if HAVE_STRING_H
14#include <string.h>
15#endif
16#if HAVE_STDLIB_H
17#include <stdlib.h>
18#endif
19#include <sys/types.h>
20#include <stdio.h>
21#include <fcntl.h>
Dave Shielde42fbdf2000-05-12 15:15:37 +000022#if TIME_WITH_SYS_TIME
Bart Van Assche337360e2010-01-24 11:41:03 +000023# include <sys/time.h>
Dave Shielde42fbdf2000-05-12 15:15:37 +000024# include <time.h>
25#else
26# if HAVE_SYS_TIME_H
27# include <sys/time.h>
28# else
29# include <time.h>
30# endif
31#endif
Wes Hardaker9743e9f2001-10-11 21:01:50 +000032#if HAVE_NETINET_IN_H
33#include <netinet/in.h>
34#endif
Dave Shielde42fbdf2000-05-12 15:15:37 +000035
Dave Shield1f17c992002-02-08 15:45:13 +000036#include <net-snmp/net-snmp-includes.h>
37#include <net-snmp/agent/net-snmp-agent-includes.h>
Wes Hardaker40342b72002-01-14 16:05:52 +000038#include <net-snmp/agent/agent_callbacks.h>
39#include <net-snmp/agent/agent_index.h>
Dave Shielde42fbdf2000-05-12 15:15:37 +000040
41#include "snmpd.h"
42#include "mibgroup/struct.h"
Dave Shield1f17c992002-02-08 15:45:13 +000043#include <net-snmp/agent/table.h>
44#include <net-snmp/agent/table_iterator.h>
Dave Shielde42fbdf2000-05-12 15:15:37 +000045
46#ifdef USING_AGENTX_SUBAGENT_MODULE
47#include "agentx/subagent.h"
48#include "agentx/client.h"
49#endif
50
Wes Hardakera8b13912011-02-26 01:22:21 +000051netsnmp_feature_child_of(agent_index_all, libnetsnmpagent)
52
53netsnmp_feature_child_of(remove_index, agent_index_all)
Wes Hardaker3b14c592011-02-23 00:01:18 +000054
Wes Hardaker6d1f6022002-04-20 07:08:20 +000055 /*
56 * Initial support for index allocation
57 */
Dave Shielde42fbdf2000-05-12 15:15:37 +000058
59struct snmp_index {
Wes Hardaker6d1f6022002-04-20 07:08:20 +000060 netsnmp_variable_list *varbind; /* or pointer to var_list ? */
61 int allocated;
62 netsnmp_session *session;
63 struct snmp_index *next_oid;
64 struct snmp_index *prev_oid;
65 struct snmp_index *next_idx;
66} *snmp_index_head = NULL;
Dave Shielde42fbdf2000-05-12 15:15:37 +000067
Wes Hardaker73925b82002-03-09 00:28:07 +000068extern netsnmp_session *main_session;
Dave Shielde42fbdf2000-05-12 15:15:37 +000069
Wes Hardaker6d1f6022002-04-20 07:08:20 +000070/*
71 * The caller is responsible for free()ing the memory returned by
72 * this function.
73 */
John Naylona5bf3312001-06-06 14:37:08 +000074
Wes Hardaker6d1f6022002-04-20 07:08:20 +000075char *
76register_string_index(oid * name, size_t name_len, char *cp)
Dave Shielde42fbdf2000-05-12 15:15:37 +000077{
Wes Hardaker73925b82002-03-09 00:28:07 +000078 netsnmp_variable_list varbind, *res;
Wes Hardaker6d1f6022002-04-20 07:08:20 +000079
80 memset(&varbind, 0, sizeof(netsnmp_variable_list));
Dave Shielde42fbdf2000-05-12 15:15:37 +000081 varbind.type = ASN_OCTET_STR;
Wes Hardaker6d1f6022002-04-20 07:08:20 +000082 snmp_set_var_objid(&varbind, name, name_len);
83 if (cp != ANY_STRING_INDEX) {
84 snmp_set_var_value(&varbind, (u_char *) cp, strlen(cp));
85 res = register_index(&varbind, ALLOCATE_THIS_INDEX, main_session);
John Naylona5bf3312001-06-06 14:37:08 +000086 } else {
Wes Hardaker6d1f6022002-04-20 07:08:20 +000087 res = register_index(&varbind, ALLOCATE_ANY_INDEX, main_session);
Dave Shielde42fbdf2000-05-12 15:15:37 +000088 }
Dave Shielde42fbdf2000-05-12 15:15:37 +000089
John Naylona5bf3312001-06-06 14:37:08 +000090 if (res == NULL) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +000091 return NULL;
John Naylona5bf3312001-06-06 14:37:08 +000092 } else {
Dave Shield30878de2010-06-12 10:26:13 +000093 char *rv = (char *)malloc(res->val_len + 1);
Bart Van Assche90a14752009-12-28 18:03:23 +000094 if (rv) {
95 memcpy(rv, res->val.string, res->val_len);
96 rv[res->val_len] = 0;
97 }
Wes Hardaker6d1f6022002-04-20 07:08:20 +000098 free(res);
99 return rv;
John Naylona5bf3312001-06-06 14:37:08 +0000100 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000101}
102
103int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000104register_int_index(oid * name, size_t name_len, int val)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000105{
Wes Hardaker73925b82002-03-09 00:28:07 +0000106 netsnmp_variable_list varbind, *res;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000107
108 memset(&varbind, 0, sizeof(netsnmp_variable_list));
Dave Shielde42fbdf2000-05-12 15:15:37 +0000109 varbind.type = ASN_INTEGER;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000110 snmp_set_var_objid(&varbind, name, name_len);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000111 varbind.val.string = varbind.buf;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000112 if (val != ANY_INTEGER_INDEX) {
Dave Shielde42fbdf2000-05-12 15:15:37 +0000113 varbind.val_len = sizeof(long);
114 *varbind.val.integer = val;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000115 res = register_index(&varbind, ALLOCATE_THIS_INDEX, main_session);
John Naylona5bf3312001-06-06 14:37:08 +0000116 } else {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000117 res = register_index(&varbind, ALLOCATE_ANY_INDEX, main_session);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000118 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000119
John Naylona5bf3312001-06-06 14:37:08 +0000120 if (res == NULL) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000121 return -1;
John Naylona5bf3312001-06-06 14:37:08 +0000122 } else {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000123 int rv = *(res->val.integer);
124 free(res);
125 return rv;
John Naylona5bf3312001-06-06 14:37:08 +0000126 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000127}
128
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000129/*
130 * The caller is responsible for free()ing the memory returned by
131 * this function.
132 */
John Naylona5bf3312001-06-06 14:37:08 +0000133
Wes Hardaker73925b82002-03-09 00:28:07 +0000134netsnmp_variable_list *
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000135register_oid_index(oid * name, size_t name_len,
136 oid * value, size_t value_len)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000137{
Wes Hardaker73925b82002-03-09 00:28:07 +0000138 netsnmp_variable_list varbind;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000139
140 memset(&varbind, 0, sizeof(netsnmp_variable_list));
Dave Shielde42fbdf2000-05-12 15:15:37 +0000141 varbind.type = ASN_OBJECT_ID;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000142 snmp_set_var_objid(&varbind, name, name_len);
John Naylona5bf3312001-06-06 14:37:08 +0000143 if (value != ANY_OID_INDEX) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000144 snmp_set_var_value(&varbind, (u_char *) value,
145 value_len * sizeof(oid));
146 return register_index(&varbind, ALLOCATE_THIS_INDEX, main_session);
John Naylona5bf3312001-06-06 14:37:08 +0000147 } else {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000148 return register_index(&varbind, ALLOCATE_ANY_INDEX, main_session);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000149 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000150}
151
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000152/*
153 * The caller is responsible for free()ing the memory returned by
154 * this function.
155 */
John Naylona5bf3312001-06-06 14:37:08 +0000156
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000157netsnmp_variable_list *
158register_index(netsnmp_variable_list * varbind, int flags,
159 netsnmp_session * ss)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000160{
Wes Hardaker73925b82002-03-09 00:28:07 +0000161 netsnmp_variable_list *rv = NULL;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000162 struct snmp_index *new_index, *idxptr, *idxptr2;
163 struct snmp_index *prev_oid_ptr, *prev_idx_ptr;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000164 int res, res2, i;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000165
John Naylondb64aeb2002-03-05 16:48:42 +0000166 DEBUGMSGTL(("register_index", "register "));
167 DEBUGMSGVAR(("register_index", varbind));
Magnus Fromreide759220f2008-05-10 09:55:02 +0000168 DEBUGMSG(("register_index", "for session %8p\n", ss));
John Naylon9a60b412001-06-05 10:10:45 +0000169
Dave Shielde42fbdf2000-05-12 15:15:37 +0000170#if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(TESTING)
John Naylonbb401c12002-05-15 12:53:01 +0000171 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
172 NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000173 return (agentx_register_index(ss, varbind, flags));
John Naylonbb401c12002-05-15 12:53:01 +0000174 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000175#endif
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000176 /*
177 * Look for the requested OID entry
178 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000179 prev_oid_ptr = NULL;
180 prev_idx_ptr = NULL;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000181 res = 1;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000182 res2 = 1;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000183 for (idxptr = snmp_index_head; idxptr != NULL;
184 prev_oid_ptr = idxptr, idxptr = idxptr->next_oid) {
185 if ((res = snmp_oid_compare(varbind->name, varbind->name_length,
186 idxptr->varbind->name,
187 idxptr->varbind->name_length)) <= 0)
188 break;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000189 }
190
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000191 /*
192 * Found the OID - now look at the registered indices
193 */
194 if (res == 0 && idxptr) {
195 if (varbind->type != idxptr->varbind->type)
196 return NULL; /* wrong type */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000197
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000198 /*
199 * If we've been asked for an arbitrary new value,
200 * then find the end of the list.
201 * If we've been asked for any arbitrary value,
202 * then look for an unused entry, and use that.
203 * If there aren't any, continue as for new.
204 * Otherwise, locate the given value in the (sorted)
205 * list of already allocated values
206 */
207 if (flags & ALLOCATE_ANY_INDEX) {
208 for (idxptr2 = idxptr; idxptr2 != NULL;
209 prev_idx_ptr = idxptr2, idxptr2 = idxptr2->next_idx) {
John Naylon496ba562001-06-19 16:44:38 +0000210
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000211 if (flags == ALLOCATE_ANY_INDEX && !(idxptr2->allocated)) {
212 if ((rv =
213 snmp_clone_varbind(idxptr2->varbind)) != NULL) {
214 idxptr2->session = ss;
215 idxptr2->allocated = 1;
216 }
217 return rv;
218 }
219 }
220 } else {
221 for (idxptr2 = idxptr; idxptr2 != NULL;
222 prev_idx_ptr = idxptr2, idxptr2 = idxptr2->next_idx) {
223 switch (varbind->type) {
224 case ASN_INTEGER:
225 res2 =
226 (*varbind->val.integer -
227 *idxptr2->varbind->val.integer);
228 break;
229 case ASN_OCTET_STR:
230 i = SNMP_MIN(varbind->val_len,
231 idxptr2->varbind->val_len);
232 res2 =
233 memcmp(varbind->val.string,
234 idxptr2->varbind->val.string, i);
235 break;
236 case ASN_OBJECT_ID:
237 res2 =
238 snmp_oid_compare(varbind->val.objid,
239 varbind->val_len / sizeof(oid),
240 idxptr2->varbind->val.objid,
241 idxptr2->varbind->val_len /
242 sizeof(oid));
243 break;
244 default:
245 return NULL; /* wrong type */
246 }
247 if (res2 <= 0)
248 break;
249 }
250 if (res2 == 0) {
251 if (idxptr2->allocated) {
252 /*
253 * No good: the index is in use.
254 */
255 return NULL;
256 } else {
257 /*
258 * Okay, it's unallocated, we can just claim ownership
259 * here.
260 */
261 if ((rv =
262 snmp_clone_varbind(idxptr2->varbind)) != NULL) {
263 idxptr2->session = ss;
264 idxptr2->allocated = 1;
265 }
266 return rv;
267 }
268 }
269 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000270 }
271
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000272 /*
273 * OK - we've now located where the new entry needs to
274 * be fitted into the index registry tree
275 * To recap:
276 * 'prev_oid_ptr' points to the head of the OID index
277 * list prior to this one. If this is null, then
278 * it means that this is the first OID in the list.
279 * 'idxptr' points either to the head of this OID list,
280 * or the next OID (if this is a new OID request)
281 * These can be distinguished by the value of 'res'.
282 *
283 * 'prev_idx_ptr' points to the index entry that sorts
284 * immediately prior to the requested value (if any).
285 * If an arbitrary value is required, then this will
286 * point to the last allocated index.
287 * If this pointer is null, then either this is a new
288 * OID request, or the requested value is the first
289 * in the list.
290 * 'idxptr2' points to the next sorted index (if any)
291 * but is not actually needed any more.
292 *
293 * Clear? Good!
294 * I hope you've been paying attention.
295 * There'll be a test later :-)
296 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000297
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000298 /*
299 * We proceed by creating the new entry
300 * (by copying the entry provided)
301 */
302 new_index = (struct snmp_index *) calloc(1, sizeof(struct snmp_index));
303 if (new_index == NULL)
304 return NULL;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000305
Magnus Fromreide465e8e62008-05-09 21:35:32 +0000306 if (NULL == snmp_varlist_add_variable(&new_index->varbind,
307 varbind->name,
308 varbind->name_length,
309 varbind->type,
310 varbind->val.string,
311 varbind->val_len)) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000312 /*
313 * if (snmp_clone_var( varbind, new_index->varbind ) != 0 )
314 */
315 free(new_index);
316 return NULL;
317 }
318 new_index->session = ss;
319 new_index->allocated = 1;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000320
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000321 if (varbind->type == ASN_OCTET_STR && flags == ALLOCATE_THIS_INDEX)
322 new_index->varbind->val.string[new_index->varbind->val_len] = 0;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000323
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000324 /*
325 * If we've been given a value, then we can use that, but
326 * otherwise, we need to create a new value for this entry.
327 * Note that ANY_INDEX and NEW_INDEX are both covered by this
328 * test (since NEW_INDEX & ANY_INDEX = ANY_INDEX, remember?)
329 */
330 if (flags & ALLOCATE_ANY_INDEX) {
331 if (prev_idx_ptr) {
332 if (snmp_clone_var(prev_idx_ptr->varbind, new_index->varbind)
333 != 0) {
334 free(new_index);
335 return NULL;
336 }
337 } else
338 new_index->varbind->val.string = new_index->varbind->buf;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000339
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000340 switch (varbind->type) {
341 case ASN_INTEGER:
342 if (prev_idx_ptr) {
343 (*new_index->varbind->val.integer)++;
344 } else
345 *(new_index->varbind->val.integer) = 1;
346 new_index->varbind->val_len = sizeof(long);
347 break;
348 case ASN_OCTET_STR:
349 if (prev_idx_ptr) {
350 i = new_index->varbind->val_len - 1;
351 while (new_index->varbind->buf[i] == 'z') {
352 new_index->varbind->buf[i] = 'a';
353 i--;
354 if (i < 0) {
355 i = new_index->varbind->val_len;
356 new_index->varbind->buf[i] = 'a';
357 new_index->varbind->buf[i + 1] = 0;
358 }
359 }
360 new_index->varbind->buf[i]++;
361 } else
362 strcpy((char *) new_index->varbind->buf, "aaaa");
363 new_index->varbind->val_len =
364 strlen((char *) new_index->varbind->buf);
365 break;
366 case ASN_OBJECT_ID:
367 if (prev_idx_ptr) {
368 i = prev_idx_ptr->varbind->val_len / sizeof(oid) - 1;
369 while (new_index->varbind->val.objid[i] == 255) {
370 new_index->varbind->val.objid[i] = 1;
371 i--;
372 if (i == 0 && new_index->varbind->val.objid[0] == 2) {
373 new_index->varbind->val.objid[0] = 1;
374 i = new_index->varbind->val_len / sizeof(oid);
375 new_index->varbind->val.objid[i] = 0;
376 new_index->varbind->val_len += sizeof(oid);
377 }
378 }
379 new_index->varbind->val.objid[i]++;
380 } else {
381 /*
382 * If the requested OID name is small enough,
383 * * append another OID (1) and use this as the
384 * * default starting value for new indexes.
385 */
386 if ((varbind->name_length + 1) * sizeof(oid) <= 40) {
387 for (i = 0; i < (int) varbind->name_length; i++)
388 new_index->varbind->val.objid[i] =
389 varbind->name[i];
390 new_index->varbind->val.objid[varbind->name_length] =
391 1;
392 new_index->varbind->val_len =
393 (varbind->name_length + 1) * sizeof(oid);
394 } else {
395 /*
396 * Otherwise use '.1.1.1.1...'
397 */
398 i = 40 / sizeof(oid);
399 if (i > 4)
400 i = 4;
401 new_index->varbind->val_len = i * (sizeof(oid));
402 for (i--; i >= 0; i--)
403 new_index->varbind->val.objid[i] = 1;
404 }
405 }
406 break;
407 default:
408 snmp_free_var(new_index->varbind);
409 free(new_index);
410 return NULL; /* Index type not supported */
411 }
412 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000413
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000414 /*
415 * Try to duplicate the new varbind for return.
416 */
John Naylona5bf3312001-06-06 14:37:08 +0000417
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000418 if ((rv = snmp_clone_varbind(new_index->varbind)) == NULL) {
419 snmp_free_var(new_index->varbind);
420 free(new_index);
421 return NULL;
422 }
John Naylona5bf3312001-06-06 14:37:08 +0000423
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000424 /*
425 * Right - we've set up the new entry.
426 * All that remains is to link it into the tree.
427 * There are a number of possible cases here,
428 * so watch carefully.
429 */
430 if (prev_idx_ptr) {
431 new_index->next_idx = prev_idx_ptr->next_idx;
432 new_index->next_oid = prev_idx_ptr->next_oid;
433 prev_idx_ptr->next_idx = new_index;
434 } else {
435 if (res == 0 && idxptr) {
436 new_index->next_idx = idxptr;
437 new_index->next_oid = idxptr->next_oid;
438 } else {
439 new_index->next_idx = NULL;
440 new_index->next_oid = idxptr;
441 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000442
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000443 if (prev_oid_ptr) {
444 while (prev_oid_ptr) {
445 prev_oid_ptr->next_oid = new_index;
446 prev_oid_ptr = prev_oid_ptr->next_idx;
447 }
448 } else
449 snmp_index_head = new_index;
450 }
John Naylona5bf3312001-06-06 14:37:08 +0000451 return rv;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000452}
453
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000454 /*
455 * Release an allocated index,
456 * to allow it to be used elsewhere
457 */
Wes Hardaker3b14c592011-02-23 00:01:18 +0000458netsnmp_feature_child_of(release_index,netsnmp_unused)
459#ifndef NETSNMP_FEATURE_REMOVE_RELEASE_INDEX
Dave Shielde42fbdf2000-05-12 15:15:37 +0000460int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000461release_index(netsnmp_variable_list * varbind)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000462{
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000463 return (unregister_index(varbind, TRUE, NULL));
Dave Shielde42fbdf2000-05-12 15:15:37 +0000464}
Wes Hardaker3b14c592011-02-23 00:01:18 +0000465#endif /* NETSNMP_FEATURE_REMOVE_RELEASE_INDEX */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000466
Wes Hardaker3b14c592011-02-23 00:01:18 +0000467#ifndef NETSNMP_FEATURE_REMOVE_REMOVE_INDEX
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000468 /*
469 * Completely remove an allocated index,
470 * due to errors in the registration process.
471 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000472int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000473remove_index(netsnmp_variable_list * varbind, netsnmp_session * ss)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000474{
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000475 return (unregister_index(varbind, FALSE, ss));
Dave Shielde42fbdf2000-05-12 15:15:37 +0000476}
Wes Hardaker3b14c592011-02-23 00:01:18 +0000477#endif /* NETSNMP_FEATURE_REMOVE_REMOVE_INDEX */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000478
479void
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000480unregister_index_by_session(netsnmp_session * ss)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000481{
482 struct snmp_index *idxptr, *idxptr2;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000483 for (idxptr = snmp_index_head; idxptr != NULL;
484 idxptr = idxptr->next_oid)
485 for (idxptr2 = idxptr; idxptr2 != NULL;
486 idxptr2 = idxptr2->next_idx)
487 if (idxptr2->session == ss) {
488 idxptr2->allocated = 0;
489 idxptr2->session = NULL;
490 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000491}
492
493
494int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000495unregister_index(netsnmp_variable_list * varbind, int remember,
496 netsnmp_session * ss)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000497{
498 struct snmp_index *idxptr, *idxptr2;
499 struct snmp_index *prev_oid_ptr, *prev_idx_ptr;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000500 int res, res2, i;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000501
502#if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(TESTING)
John Naylonbb401c12002-05-15 12:53:01 +0000503 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
504 NETSNMP_DS_AGENT_ROLE) == SUB_AGENT) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000505 return (agentx_unregister_index(ss, varbind));
John Naylonbb401c12002-05-15 12:53:01 +0000506 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000507#endif
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000508 /*
509 * Look for the requested OID entry
510 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000511 prev_oid_ptr = NULL;
512 prev_idx_ptr = NULL;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000513 res = 1;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000514 res2 = 1;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000515 for (idxptr = snmp_index_head; idxptr != NULL;
516 prev_oid_ptr = idxptr, idxptr = idxptr->next_oid) {
517 if ((res = snmp_oid_compare(varbind->name, varbind->name_length,
518 idxptr->varbind->name,
519 idxptr->varbind->name_length)) <= 0)
520 break;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000521 }
522
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000523 if (res != 0)
524 return INDEX_ERR_NOT_ALLOCATED;
525 if (varbind->type != idxptr->varbind->type)
526 return INDEX_ERR_WRONG_TYPE;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000527
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000528 for (idxptr2 = idxptr; idxptr2 != NULL;
529 prev_idx_ptr = idxptr2, idxptr2 = idxptr2->next_idx) {
Dave Shielda32ca932013-01-08 16:42:54 +0000530 switch (varbind->type) {
531 case ASN_INTEGER:
532 res2 =
533 (*varbind->val.integer -
534 *idxptr2->varbind->val.integer);
535 break;
536 case ASN_OCTET_STR:
537 i = SNMP_MIN(varbind->val_len,
538 idxptr2->varbind->val_len);
539 res2 =
540 memcmp(varbind->val.string,
541 idxptr2->varbind->val.string, i);
542 break;
543 case ASN_OBJECT_ID:
544 res2 =
545 snmp_oid_compare(varbind->val.objid,
546 varbind->val_len / sizeof(oid),
547 idxptr2->varbind->val.objid,
548 idxptr2->varbind->val_len /
549 sizeof(oid));
550 break;
551 default:
552 return INDEX_ERR_WRONG_TYPE; /* wrong type */
553 }
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000554 if (res2 <= 0)
555 break;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000556 }
John Naylon496ba562001-06-19 16:44:38 +0000557 if (res2 != 0 || (res2 == 0 && !idxptr2->allocated)) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000558 return INDEX_ERR_NOT_ALLOCATED;
John Naylon496ba562001-06-19 16:44:38 +0000559 }
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000560 if (ss != idxptr2->session)
561 return INDEX_ERR_WRONG_SESSION;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000562
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000563 /*
564 * If this is a "normal" index unregistration,
565 * mark the index entry as unused, but leave
566 * it in situ. This allows differentiation
567 * between ANY_INDEX and NEW_INDEX
568 */
569 if (remember) {
570 idxptr2->allocated = 0; /* Unused index */
571 idxptr2->session = NULL;
572 return SNMP_ERR_NOERROR;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000573 }
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000574 /*
575 * If this is a failed attempt to register a
576 * number of indexes, the successful ones
577 * must be removed completely.
578 */
579 if (prev_idx_ptr) {
580 prev_idx_ptr->next_idx = idxptr2->next_idx;
581 } else if (prev_oid_ptr) {
582 if (idxptr2->next_idx) /* Use p_idx_ptr as a temp variable */
583 prev_idx_ptr = idxptr2->next_idx;
584 else
585 prev_idx_ptr = idxptr2->next_oid;
586 while (prev_oid_ptr) {
587 prev_oid_ptr->next_oid = prev_idx_ptr;
588 prev_oid_ptr = prev_oid_ptr->next_idx;
589 }
590 } else {
591 if (idxptr2->next_idx)
592 snmp_index_head = idxptr2->next_idx;
593 else
594 snmp_index_head = idxptr2->next_oid;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000595 }
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000596 snmp_free_var(idxptr2->varbind);
597 free(idxptr2);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000598 return SNMP_ERR_NOERROR;
599}
600
Wes Hardaker3b14c592011-02-23 00:01:18 +0000601netsnmp_feature_child_of(unregister_indexes,netsnmp_unused)
602#ifndef NETSNMP_FEATURE_REMOVE_UNREGISTER_INDEXES
John Naylon481a3092001-11-20 16:29:41 +0000603int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000604unregister_string_index(oid * name, size_t name_len, char *cp)
John Naylon481a3092001-11-20 16:29:41 +0000605{
Wes Hardaker73925b82002-03-09 00:28:07 +0000606 netsnmp_variable_list varbind;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000607
608 memset(&varbind, 0, sizeof(netsnmp_variable_list));
John Naylon481a3092001-11-20 16:29:41 +0000609 varbind.type = ASN_OCTET_STR;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000610 snmp_set_var_objid(&varbind, name, name_len);
611 snmp_set_var_value(&varbind, (u_char *) cp, strlen(cp));
John Naylon481a3092001-11-20 16:29:41 +0000612 return (unregister_index(&varbind, FALSE, main_session));
613}
614
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000615int
616unregister_int_index(oid * name, size_t name_len, int val)
John Naylon481a3092001-11-20 16:29:41 +0000617{
Wes Hardaker73925b82002-03-09 00:28:07 +0000618 netsnmp_variable_list varbind;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000619
Wes Hardaker73925b82002-03-09 00:28:07 +0000620 memset(&varbind, 0, sizeof(netsnmp_variable_list));
John Naylon481a3092001-11-20 16:29:41 +0000621 varbind.type = ASN_INTEGER;
622 snmp_set_var_objid(&varbind, name, name_len);
623 varbind.val.string = varbind.buf;
624 varbind.val_len = sizeof(long);
625 *varbind.val.integer = val;
626 return (unregister_index(&varbind, FALSE, main_session));
627}
628
629int
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000630unregister_oid_index(oid * name, size_t name_len,
631 oid * value, size_t value_len)
John Naylon481a3092001-11-20 16:29:41 +0000632{
Wes Hardaker73925b82002-03-09 00:28:07 +0000633 netsnmp_variable_list varbind;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000634
635 memset(&varbind, 0, sizeof(netsnmp_variable_list));
John Naylon481a3092001-11-20 16:29:41 +0000636 varbind.type = ASN_OBJECT_ID;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000637 snmp_set_var_objid(&varbind, name, name_len);
638 snmp_set_var_value(&varbind, (u_char *) value,
639 value_len * sizeof(oid));
John Naylon481a3092001-11-20 16:29:41 +0000640 return (unregister_index(&varbind, FALSE, main_session));
641}
Wes Hardaker3b14c592011-02-23 00:01:18 +0000642#endif /* NETSNMP_FEATURE_REMOVE_UNREGISTER_INDEXES */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000643
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000644void
645dump_idx_registry(void)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000646{
647 struct snmp_index *idxptr, *idxptr2;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000648 u_char *sbuf = NULL, *ebuf = NULL;
649 size_t sbuf_len = 0, sout_len = 0, ebuf_len = 0, eout_len = 0;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000650
John Naylon3bee5ee2002-02-27 12:35:42 +0000651 if (snmp_index_head != NULL) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000652 printf("\nIndex Allocations:\n");
John Naylon3bee5ee2002-02-27 12:35:42 +0000653 }
654
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000655 for (idxptr = snmp_index_head; idxptr != NULL;
656 idxptr = idxptr->next_oid) {
657 sout_len = 0;
658 if (sprint_realloc_objid(&sbuf, &sbuf_len, &sout_len, 1,
659 idxptr->varbind->name,
660 idxptr->varbind->name_length)) {
661 printf("%s indexes:\n", sbuf);
662 } else {
663 printf("%s [TRUNCATED] indexes:\n", sbuf);
664 }
John Naylon3bee5ee2002-02-27 12:35:42 +0000665
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000666 for (idxptr2 = idxptr; idxptr2 != NULL;
667 idxptr2 = idxptr2->next_idx) {
668 switch (idxptr2->varbind->type) {
669 case ASN_INTEGER:
John Naylona1a4a842002-07-10 09:35:38 +0000670 printf(" %ld for session %8p, allocated %d\n",
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000671 *idxptr2->varbind->val.integer, idxptr2->session,
672 idxptr2->allocated);
673 break;
674 case ASN_OCTET_STR:
John Naylona1a4a842002-07-10 09:35:38 +0000675 printf(" \"%s\" for session %8p, allocated %d\n",
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000676 idxptr2->varbind->val.string, idxptr2->session,
677 idxptr2->allocated);
678 break;
679 case ASN_OBJECT_ID:
680 eout_len = 0;
681 if (sprint_realloc_objid(&ebuf, &ebuf_len, &eout_len, 1,
682 idxptr2->varbind->val.objid,
683 idxptr2->varbind->val_len /
684 sizeof(oid))) {
John Naylona1a4a842002-07-10 09:35:38 +0000685 printf(" %s for session %8p, allocated %d\n", ebuf,
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000686 idxptr2->session, idxptr2->allocated);
687 } else {
688 printf
John Naylona1a4a842002-07-10 09:35:38 +0000689 (" %s [TRUNCATED] for sess %8p, allocated %d\n",
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000690 ebuf, idxptr2->session, idxptr2->allocated);
691 }
692 break;
693 default:
694 printf("unsupported type (%d/0x%02x)\n",
695 idxptr2->varbind->type, idxptr2->varbind->type);
696 }
697 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000698 }
John Naylon3bee5ee2002-02-27 12:35:42 +0000699
700 if (sbuf != NULL) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000701 free(sbuf);
John Naylon3bee5ee2002-02-27 12:35:42 +0000702 }
703 if (ebuf != NULL) {
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000704 free(ebuf);
John Naylon3bee5ee2002-02-27 12:35:42 +0000705 }
Dave Shielde42fbdf2000-05-12 15:15:37 +0000706}
707
Wes Hardaker3b14c592011-02-23 00:01:18 +0000708netsnmp_feature_child_of(count_indexes, netsnmp_unused)
709#ifndef NETSNMP_FEATURE_REMOVE_UNUSED
John Naylona5f53ae2001-06-20 13:44:18 +0000710unsigned long
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000711count_indexes(oid * name, size_t namelen, int include_unallocated)
John Naylona5f53ae2001-06-20 13:44:18 +0000712{
713 struct snmp_index *i = NULL, *j = NULL;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000714 unsigned long n = 0;
John Naylona5f53ae2001-06-20 13:44:18 +0000715
716 for (i = snmp_index_head; i != NULL; i = i->next_oid) {
Wes Hardakerbb4d05c2002-08-15 15:14:22 +0000717 if (netsnmp_oid_equals(name, namelen,
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000718 i->varbind->name,
719 i->varbind->name_length) == 0) {
720 for (j = i; j != NULL; j = j->next_idx) {
721 if (j->allocated || include_unallocated) {
722 n++;
723 }
724 }
725 }
John Naylona5f53ae2001-06-20 13:44:18 +0000726 }
727 return n;
728}
Wes Hardaker3b14c592011-02-23 00:01:18 +0000729#endif /* NETSNMP_FEATURE_REMOVE_UNUSED */
John Naylona5f53ae2001-06-20 13:44:18 +0000730
Dave Shielde42fbdf2000-05-12 15:15:37 +0000731#ifdef TESTING
Wes Hardaker73925b82002-03-09 00:28:07 +0000732netsnmp_variable_list varbind;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000733netsnmp_session main_sess, *main_session = &main_sess;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000734
735void
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000736test_string_register(int n, char *cp)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000737{
738 varbind->name[4] = n;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000739 if (register_string_index(varbind->name, varbind.name_length, cp) ==
740 NULL)
741 printf("allocating %s failed\n", cp);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000742}
743
744void
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000745test_int_register(int n, int val)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000746{
747 varbind->name[4] = n;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000748 if (register_int_index(varbind->name, varbind.name_length, val) == -1)
749 printf("allocating %d/%d failed\n", n, val);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000750}
751
752void
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000753test_oid_register(int n, int subid)
Dave Shielde42fbdf2000-05-12 15:15:37 +0000754{
Wes Hardaker73925b82002-03-09 00:28:07 +0000755 netsnmp_variable_list *res;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000756
757 varbind->name[4] = n;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000758 if (subid != -1) {
Dave Shielde42fbdf2000-05-12 15:15:37 +0000759 varbind->val.objid[5] = subid;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000760 res = register_oid_index(varbind->name, varbind.name_length,
761 varbind->val.objid,
762 varbind->val_len / sizeof(oid));
763 } else
764 res =
765 register_oid_index(varbind->name, varbind.name_length, NULL,
766 0);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000767
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000768 if (res == NULL)
769 printf("allocating %d/%d failed\n", n, subid);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000770}
771
772void
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000773main(int argc, char argv[])
Dave Shielde42fbdf2000-05-12 15:15:37 +0000774{
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000775 oid name[] = { 1, 2, 3, 4, 0 };
776 int i;
777
778 memset(&varbind, 0, sizeof(netsnmp_variable_list));
779 snmp_set_var_objid(&varbind, name, 5);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000780 varbind->type = ASN_OCTET_STR;
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000781 /*
782 * Test index structure linking:
783 * a) sorted by OID
784 */
785 test_string_register(20, "empty OID");
786 test_string_register(10, "first OID");
787 test_string_register(40, "last OID");
788 test_string_register(30, "middle OID");
Dave Shielde42fbdf2000-05-12 15:15:37 +0000789
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000790 /*
791 * b) sorted by index value
792 */
793 test_string_register(25, "eee: empty IDX");
794 test_string_register(25, "aaa: first IDX");
795 test_string_register(25, "zzz: last IDX");
796 test_string_register(25, "mmm: middle IDX");
Dave Shielde42fbdf2000-05-12 15:15:37 +0000797 printf("This next one should fail....\n");
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000798 test_string_register(25, "eee: empty IDX"); /* duplicate */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000799 printf("done\n");
800
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000801 /*
802 * c) test initial index linking
803 */
804 test_string_register(5, "eee: empty initial IDX");
805 test_string_register(5, "aaa: replace initial IDX");
Dave Shielde42fbdf2000-05-12 15:15:37 +0000806
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000807 /*
808 * Did it all work?
809 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000810 dump_idx_registry();
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000811 unregister_index_by_session(main_session);
812 /*
813 * Now test index allocation
814 * a) integer values
815 */
816 test_int_register(110, -1); /* empty */
817 test_int_register(110, -1); /* append */
818 test_int_register(110, 10); /* append exact */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000819 printf("This next one should fail....\n");
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000820 test_int_register(110, 10); /* exact duplicate */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000821 printf("done\n");
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000822 test_int_register(110, -1); /* append */
823 test_int_register(110, 5); /* insert exact */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000824
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000825 /*
826 * b) string values
827 */
828 test_string_register(120, NULL); /* empty */
829 test_string_register(120, NULL); /* append */
830 test_string_register(120, "aaaz");
831 test_string_register(120, NULL); /* minor rollover */
832 test_string_register(120, "zzzz");
833 test_string_register(120, NULL); /* major rollover */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000834
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000835 /*
836 * c) OID values
837 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000838
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000839 test_oid_register(130, -1); /* empty */
840 test_oid_register(130, -1); /* append */
841
842 varbind->val_len = varbind.name_length * sizeof(oid);
843 memcpy(varbind->buf, varbind.name, varbind.val_len);
844 varbind->val.objid = (oid *) varbind.buf;
Dave Shielde42fbdf2000-05-12 15:15:37 +0000845 varbind->val_len += sizeof(oid);
846
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000847 test_oid_register(130, 255); /* append exact */
848 test_oid_register(130, -1); /* minor rollover */
849 test_oid_register(130, 100); /* insert exact */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000850 printf("This next one should fail....\n");
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000851 test_oid_register(130, 100); /* exact duplicate */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000852 printf("done\n");
853
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000854 varbind->val.objid = (oid *) varbind.buf;
855 for (i = 0; i < 6; i++)
856 varbind->val.objid[i] = 255;
857 varbind->val.objid[0] = 1;
858 test_oid_register(130, 255); /* set up rollover */
859 test_oid_register(130, -1); /* medium rollover */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000860
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000861 for (i = 0; i < 6; i++)
862 varbind->val.objid[i] = 255;
863 varbind->val.objid[0] = 2;
864 test_oid_register(130, 255); /* set up rollover */
865 test_oid_register(130, -1); /* major rollover */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000866
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000867 /*
868 * Did it all work?
869 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000870 dump_idx_registry();
871
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000872 /*
873 * Test the various "invalid" requests
874 * (unsupported types, mis-matched types, etc)
875 */
Dave Shielde42fbdf2000-05-12 15:15:37 +0000876 printf("The rest of these should fail....\n");
Wes Hardaker6d1f6022002-04-20 07:08:20 +0000877 test_oid_register(110, -1);
878 test_oid_register(110, 100);
879 test_oid_register(120, -1);
880 test_oid_register(120, 100);
881 test_string_register(110, NULL);
882 test_string_register(110, "aaaa");
883 test_string_register(130, NULL);
884 test_string_register(130, "aaaa");
885 test_int_register(120, -1);
886 test_int_register(120, 1);
887 test_int_register(130, -1);
888 test_int_register(130, 1);
Dave Shielde42fbdf2000-05-12 15:15:37 +0000889 printf("done - this dump should be the same as before\n");
890 dump_idx_registry();
891}
892#endif