Debian Codegraph @

agent/mibgroup/tlstm-mib/snmpTlstmParamsTable/snmpTlstmParamsTable.c

raw
1 /*
2 * Note: this file originally auto-generated by mib2c using
3 * $
4 */
5
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-features.h>
8 #include <net-snmp/net-snmp-includes.h>
9 #include <net-snmp/agent/net-snmp-agent-includes.h>
10
11 #include <openssl/ssl.h>
12 #include <openssl/x509.h>
13 #include <net-snmp/library/cert_util.h>
14 #include "tlstm-mib.h"
15
16 #include "snmpTlstmParamsTable.h"
17
18 netsnmp_feature_require(table_tdata);
19 netsnmp_feature_require(tlstmparams_find);
20 netsnmp_feature_require(tlstmparams_external);
21 netsnmp_feature_require(cert_fingerprints);
22 netsnmp_feature_require(table_tdata_delete_table);
23 netsnmp_feature_require(table_tdata_extract_table);
24 netsnmp_feature_require(table_tdata_remove_row);
25 #ifndef NETSNMP_NO_WRITE_SUPPORT
26 netsnmp_feature_require(check_vb_storagetype);
27 netsnmp_feature_require(check_vb_type_and_max_size);
28 netsnmp_feature_require(check_vb_rowstatus_with_storagetype);
29 netsnmp_feature_require(table_tdata_insert_row);
30 #endif /* NETSNMP_NO_WRITE_SUPPORT */
31
32 /** XXX - move these to table_data header? */
33 #define FATE_NEWLY_CREATED 1
34 #define FATE_NO_CHANGE 0
35 #define FATE_DELETE_ME -1
36
37 /** **************************************************************************
38 *
39 * table structures
40 *
41 */
42 /*
43 * structure for undo storage and other vars for set processing
44 */
45 typedef struct snmpTlstmParamsTable_undo_s {
46 char fate;
47 char copied;
48 signed char is_consistent;
49 netsnmp_request_info *req[SNMPTLSTMPARAMSTABLE_MAX_COLUMN + 1];
50 /* undo Column space */
51 char snmpTlstmParamsClientFingerprint[SNMPTLSTMPARAMSCLIENTFINGERPRINT_MAX_SIZE];
52 size_t snmpTlstmParamsClientFingerprint_len;
53 char snmpTlstmParamsStorageType;
54 char snmpTlstmParamsRowStatus;
55 } snmpTlstmParamsTable_undo;
56
57 /*
58 * Typical data structure for a row entry
59 */
60 typedef struct snmpTlstmParamsTable_entry_s {
61 /* Index values */
62 char snmpTargetParamsName[SNMPTARGETPARAMSNAME_MAX_SIZE];
63 size_t snmpTargetParamsName_len;
64
65 /* Column values */
66 char snmpTlstmParamsClientFingerprint[SNMPTLSTMPARAMSCLIENTFINGERPRINT_MAX_SIZE];
67 size_t snmpTlstmParamsClientFingerprint_len;
68 char snmpTlstmParamsStorageType;
69 char snmpTlstmParamsRowStatus;
70
71 char hashType;
72 char params_flags;
73
74 /* used during set processing */
75 snmpTlstmParamsTable_undo *undo;
76 } snmpTlstmParamsTable_entry;
77
78 static Netsnmp_Node_Handler snmpTlstmParamsTable_handler;
79 static NetsnmpCacheLoad snmpTlstmParamsTable_load;
80 static NetsnmpCacheFree snmpTlstmParamsTable_free;
81
82 static int _tlstmParamsTable_save(int majorID, int minorID,
83 void *serverarg, void *clientarg);
84 static int _count_handler(netsnmp_mib_handler *handler,
85 netsnmp_handler_registration *reginfo,
86 netsnmp_agent_request_info *reqinfo,
87 netsnmp_request_info *requests);
88 static void _tlstmParams_init_persistence(void);
89 static void _params_add(snmpTlstmParamsTable_entry *entry);
90 static void _params_remove(snmpTlstmParamsTable_entry *entry);
91 static void _params_tweak_storage(snmpTlstmParamsTable_entry *entry);
92
93 static netsnmp_handler_registration *params_table_reg;
94 static netsnmp_handler_registration *params_count_reg;
95 static netsnmp_handler_registration *last_changed_reg;
96 static netsnmp_table_registration_info *params_table;
97
98 static uint32_t _last_changed = 0;
99 static netsnmp_tdata *_table_data = NULL;
100
101 /*
102 * Initialize the snmpTlstmParamsTable table by defining its contents
103 * and how it's structured
104 */
105 void
106 init_snmpTlstmParamsTable(void)
107 {
108 oid reg_oid[] = {SNMP_TLS_TM_BASE,2,2,1,6};
109 const size_t reg_oid_len = OID_LENGTH(reg_oid);
110 netsnmp_cache *cache;
111 netsnmp_watcher_info *last_changed_watcher;
112 int rc;
113
114 DEBUGMSGTL(("tlstmParamsTable:init", "initializing table snmpTlstmParamsTable\n"));
115
116 params_table_reg = netsnmp_create_handler_registration
117 ("snmpTlstmParamsTable", snmpTlstmParamsTable_handler, reg_oid,
118 reg_oid_len, HANDLER_CAN_RWRITE);
119 if (!params_table_reg) {
120 snmp_log(LOG_ERR, "snmpTlstmParamsTable registration failed");
121 return;
122 }
123 _table_data = netsnmp_tdata_create_table( "snmpTlstmParamsTable", 0 );
124 if (!_table_data) {
125 snmp_log(LOG_ERR,"error creating tdata table for snmpTlstmParamsTable\n");
126 goto unregister_params_table;
127 }
128 cache = netsnmp_cache_create(SNMPTLSTMPARAMSTABLE_TIMEOUT,
129 snmpTlstmParamsTable_load,
130 snmpTlstmParamsTable_free,
131 reg_oid, reg_oid_len);
132 if (NULL == cache) {
133 snmp_log(LOG_ERR,"error creating cache for snmpTlstmParamsTable\n");
134 goto delete_table_data;
135 }
136 cache->magic = (void *)_table_data;
137 cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
138
139 params_table = SNMP_MALLOC_TYPEDEF( netsnmp_table_registration_info );
140 if (!params_table) {
141 snmp_log(LOG_ERR,"error creating table info for snmpTlstmParamsTable\n");
142 goto free_cache;
143 }
144 /*
145 * populate index types
146 */
147 netsnmp_table_helper_add_indexes(params_table,
148 /* index: snmpTargetParamsName */
149 ASN_PRIV_IMPLIED_OCTET_STR, 0);
150
151 params_table->min_column = SNMPTLSTMPARAMSTABLE_MIN_COLUMN;
152 params_table->max_column = SNMPTLSTMPARAMSTABLE_MAX_COLUMN;
153
154 rc = netsnmp_tdata_register(params_table_reg, _table_data,
155 params_table);
156 if (rc) {
157 snmp_log(LOG_ERR, "%s: netsnmp_tdata_register() returned %d\n",
158 __func__, rc);
159 goto free_params_table;
160 }
161 netsnmp_inject_handler_before(params_table_reg,
162 netsnmp_cache_handler_get(cache),
163 "table_container");
164
165 /*
166 * register scalars
167 */
168 reg_oid[10] = 4;
169 params_count_reg =
170 netsnmp_create_handler_registration("snmpTlstmParamsCount",
171 _count_handler, reg_oid,
172 OID_LENGTH(reg_oid),
173 HANDLER_CAN_RONLY);
174 if (!params_count_reg) {
175 snmp_log(LOG_ERR,
176 "could not create handler for snmpTlstmParamsCount\n");
177 goto free_params_table;
178 }
179 {
180 const int rc = netsnmp_register_scalar(params_count_reg);
181 if (rc) {
182 snmp_log(LOG_ERR, "%s: netsnmp_register_scalar() returned %d\n",
183 __func__, rc);
184 goto unreg_params_count;
185 }
186 netsnmp_inject_handler_before(params_count_reg,
187 netsnmp_cache_handler_get(cache),
188 "snmpTlstmParamsCount");
189 }
190
191 reg_oid[10] = 5;
192 last_changed_reg = netsnmp_create_handler_registration(
193 "snmpTlstmParamsTableLastChanged", NULL, reg_oid,
194 OID_LENGTH(reg_oid), HANDLER_CAN_RONLY);
195 if (!last_changed_reg) {
196 snmp_log(LOG_ERR,
197 "could not create handler for snmpTlstmParamsTableLastChanged\n");
198 goto unreg_params_count;
199 }
200 last_changed_watcher = netsnmp_create_watcher_info((void*)&_last_changed,
201 sizeof(_last_changed),
202 ASN_TIMETICKS,
203 WATCHER_FIXED_SIZE);
204 if (!last_changed_watcher) {
205 snmp_log(LOG_ERR,
206 "could not create handler for snmpTlstmParamsTableLastChanged\n");
207 goto unreg_last_changed;
208 }
209
210 netsnmp_register_watched_scalar2(last_changed_reg, last_changed_watcher);
211
212 /*
213 * Initialise the contents of the table here
214 */
215 _tlstmParams_init_persistence();
216 return;
217
218 unreg_last_changed:
219 netsnmp_tdata_unregister(last_changed_reg);
220
221 unreg_params_count:
222 netsnmp_tdata_unregister(params_count_reg);
223
224 free_params_table:
225 netsnmp_table_registration_info_free(params_table);
226
227 free_cache:
228 netsnmp_cache_free(cache);
229
230 delete_table_data:
231 netsnmp_tdata_delete_table(_table_data);
232 _table_data = NULL;
233
234 unregister_params_table:
235 netsnmp_tdata_unregister(params_table_reg);
236 }
237
238 void
239 shutdown_snmpTlstmParamsTable(void)
240 {
241 snmp_unregister_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
242 _tlstmParamsTable_save, _table_data->container, 1);
243 netsnmp_tdata_unregister(last_changed_reg);
244 netsnmp_tdata_unregister(params_count_reg);
245 netsnmp_tdata_unregister(params_table_reg);
246 netsnmp_table_registration_info_free(params_table);
247 }
248
249 /** **************************************************************************
250 *
251 * utility functions for table structures
252 *
253 */
254 /* create a new row in the table */
255 netsnmp_tdata_row *
256 snmpTlstmParamsTable_createEntry(netsnmp_tdata *table_data,
257 char* snmpTargetParamsName,
258 size_t snmpTargetParamsName_len ) {
259 snmpTlstmParamsTable_entry *entry;
260 netsnmp_tdata_row *row;
261
262 if ((NULL == snmpTargetParamsName) || (snmpTargetParamsName_len >
263 sizeof(entry->snmpTargetParamsName)))
264 return NULL;
265
266 entry = SNMP_MALLOC_TYPEDEF(snmpTlstmParamsTable_entry);
267 if (!entry)
268 return NULL;
269
270 row = netsnmp_tdata_create_row();
271 if (!row) {
272 SNMP_FREE(entry);
273 return NULL;
274 }
275 row->data = entry;
276
277 DEBUGMSGT(("tlstmParamsTable:entry:create", "entry %p / row %p\n",
278 entry, row));
279
280 DEBUGIF("snmpTlstmParamTable:entry:create") {
281 char name[sizeof(entry->snmpTargetParamsName)+1];
282 snprintf(name, sizeof(name), "%s", snmpTargetParamsName);
283 DEBUGMSGT(("tlstmParamsTable:entry:create",
284 "entry %s %p / row %p\n",
285 name, entry, row));
286 }
287
288 /*
289 * populate index
290 */
291 memcpy(entry->snmpTargetParamsName, snmpTargetParamsName,
292 snmpTargetParamsName_len);
293 entry->snmpTargetParamsName_len = snmpTargetParamsName_len;
294 netsnmp_tdata_row_add_index( row, ASN_PRIV_IMPLIED_OCTET_STR,
295 entry->snmpTargetParamsName,
296 snmpTargetParamsName_len);
297
298 entry->snmpTlstmParamsClientFingerprint[0] = '\0';
299 entry->snmpTlstmParamsClientFingerprint_len = 0;
300 entry->snmpTlstmParamsRowStatus = RS_NOTREADY;
301 entry->snmpTlstmParamsStorageType = ST_NONVOLATILE;
302
303 if (table_data) {
304 DEBUGMSGTL(("tlstmParamsTable:row:insert", "row %p\n",
305 row));
306 netsnmp_tdata_add_row( table_data, row );
307 }
308 return row;
309 }
310
311 /* allocate undo resources */
312 static snmpTlstmParamsTable_undo *
313 _allocUndo(snmpTlstmParamsTable_entry *entry)
314 {
315 if (!entry)
316 return NULL;
317
318 entry->undo = SNMP_MALLOC_TYPEDEF(snmpTlstmParamsTable_undo);
319 if (!entry->undo)
320 return NULL;
321
322 entry->undo->is_consistent = -1; /* don't know */
323
324 /* TODO: allocated any other resources needed */
325
326 return entry->undo;
327 }
328
329 /* free undo resources */
330 static void
331 _freeUndo(snmpTlstmParamsTable_entry *entry)
332 {
333 if (!entry || !entry->undo)
334 return;
335
336 /* TODO: release any allocated resources */
337 SNMP_FREE(entry->undo);
338 }
339
340 /* remove a row from the table */
341 void
342 snmpTlstmParamsTable_removeEntry(netsnmp_tdata *table_data,
343 netsnmp_tdata_row *row)
344 {
345 snmpTlstmParamsTable_entry *entry;
346
347 if (!row)
348 return; /* Nothing to remove */
349
350 entry = (snmpTlstmParamsTable_entry *)row->data;
351
352 DEBUGMSGT(("tlstmParamsTable:entry:delete", "entry %p / row %p\n",
353 entry, row));
354
355 if (table_data) {
356 DEBUGMSGTL(("tlstmParamsTable:row:remove", "row %p\n", row));
357 netsnmp_tdata_remove_and_delete_row( table_data, row );
358 }
359 else
360 netsnmp_tdata_delete_row( row );
361
362 if (entry && entry->undo)
363 _freeUndo(entry);
364 SNMP_FREE( entry ); /* TODO - release any other internal resources */
365 }
366
367 /** **************************************************************************
368 *
369 * handle cache / interactions with snmpTlstmParams container in snmplib
370 *
371 */
372 static void
373 _params_add(snmpTlstmParamsTable_entry *entry)
374 {
375 snmpTlstmParams *params;
376
377 if (NULL == entry)
378 return;
379
380 DEBUGMSGTL(("tlstmParamsTable:params:add", "name %s, fp %s\n",
381 entry->snmpTargetParamsName, entry->snmpTlstmParamsClientFingerprint));
382
383 params =
384 netsnmp_tlstmParams_create(entry->snmpTargetParamsName,
385 entry->hashType,
386 entry->snmpTlstmParamsClientFingerprint,
387 entry->snmpTlstmParamsClientFingerprint_len);
388 if (NULL == params)
389 return;
390
391 params->flags = TLSTM_PARAMS_FROM_MIB;
392 if (entry->snmpTlstmParamsStorageType == ST_NONVOLATILE)
393 params->flags |= TLSTM_PARAMS_NONVOLATILE;
394
395 netsnmp_tlstmParams_add(params);
396 }
397
398 static void
399 _params_remove(snmpTlstmParamsTable_entry *entry)
400 {
401 snmpTlstmParams index, *found;
402
403 if (NULL == entry)
404 return;
405
406 DEBUGMSGTL(("tlstmParamsTable:params:remove", "name %s\n",
407 entry->snmpTargetParamsName));
408
409 index.name = entry->snmpTargetParamsName;
410 found = netsnmp_tlstmParams_find(&index);
411 if (found) {
412 netsnmp_tlstmParams_remove(found);
413 netsnmp_tlstmParams_free(found);
414 }
415 entry->params_flags = 0;
416 }
417
418 static void
419 _params_tweak_storage(snmpTlstmParamsTable_entry *entry)
420 {
421 snmpTlstmParams *params, index;
422
423 if (NULL == entry)
424 return;
425
426 DEBUGMSGTL(("tlstmParamsTable:params:tweak", "name %s, st %d\n",
427 entry->snmpTargetParamsName, entry->snmpTlstmParamsStorageType));
428
429 index.name = entry->snmpTargetParamsName;
430 params = netsnmp_tlstmParams_find(&index);
431 if (NULL == params) {
432 DEBUGMSGTL(("tlstmParamsTable:params:tweak",
433 "couldn't find params!\n"));
434 return;
435 }
436
437 if (entry->snmpTlstmParamsStorageType == ST_NONVOLATILE)
438 params->flags |= TLSTM_PARAMS_NONVOLATILE;
439 else
440 params->flags &= ~TLSTM_PARAMS_NONVOLATILE;
441 }
442
443 static netsnmp_tdata_row *
444 _entry_from_params(snmpTlstmParams *params)
445 {
446 netsnmp_tdata_row *row;
447 snmpTlstmParamsTable_entry *entry;
448
449 row = snmpTlstmParamsTable_createEntry(NULL, params->name,
450 strlen(params->name));
451 if (NULL == row) {
452 snmp_log(LOG_ERR, "can create snmpTlstmParams row entry\n");
453 return NULL;
454 }
455 entry = row->data;
456
457 if (params->flags & TLSTM_PARAMS_FROM_CONFIG)
458 entry->snmpTlstmParamsStorageType = ST_PERMANENT;
459 else if (! (params->flags & TLSTM_PARAMS_NONVOLATILE))
460 entry->snmpTlstmParamsStorageType = ST_VOLATILE;
461
462 entry->snmpTlstmParamsRowStatus = RS_ACTIVE;
463
464 if (params->fingerprint) {
465 entry->snmpTlstmParamsClientFingerprint_len =
466 strlen(params->fingerprint);
467 if (entry->snmpTlstmParamsClientFingerprint_len >
468 sizeof(entry->snmpTlstmParamsClientFingerprint))
469 entry->snmpTlstmParamsClientFingerprint_len =
470 sizeof(entry->snmpTlstmParamsClientFingerprint) - 1;
471 memcpy(entry->snmpTlstmParamsClientFingerprint, params->fingerprint,
472 entry->snmpTlstmParamsClientFingerprint_len);
473 entry->snmpTlstmParamsClientFingerprint[sizeof(entry->snmpTlstmParamsClientFingerprint) - 1] = 0;
474 }
475 entry->hashType = params->hashType;
476 entry->params_flags = params->flags;
477
478 return row;
479 }
480
481 static int
482 snmpTlstmParamsTable_load( netsnmp_cache *cache, void *vmagic )
483 {
484 netsnmp_tdata *table = (netsnmp_tdata *)vmagic;
485 netsnmp_tdata_row *row;
486 netsnmp_container *active_params;
487 netsnmp_iterator *itr;
488 snmpTlstmParams *params;
489 int rc = 0;
490
491 active_params = netsnmp_tlstmParams_container();
492 if (NULL == active_params)
493 return 0;
494
495 DEBUGMSGTL(("tlstmParamsTable:cache:load", "snmpTlstmParams %" NETSNMP_PRIz "d rows\n",
496 CONTAINER_SIZE(active_params)));
497 itr = CONTAINER_ITERATOR(active_params);
498 if (NULL == itr) {
499 DEBUGMSGTL(("tlstmParamsTable:cache:load",
500 "cant get iterator\n"));
501 return -1;
502 }
503
504 /*
505 * insert rows for active params into tbl container
506 */
507 params = ITERATOR_FIRST(itr);
508 for( ; params; params = ITERATOR_NEXT(itr)) {
509
510 row = _entry_from_params(params);
511 if (NULL == row) {
512 rc =-1;
513 break;
514 }
515 if (netsnmp_tdata_add_row(table, row) != SNMPERR_SUCCESS) {
516 snmpTlstmParamsTable_removeEntry(NULL, row);
517 rc = -1;
518 break;
519 }
520 }
521 ITERATOR_RELEASE(itr);
522
523 DEBUGMSGTL(("tlstmParamsTable:cache:load", "done, %" NETSNMP_PRIz "d rows\n",
524 CONTAINER_SIZE(table->container)));
525
526 return rc;
527 }
528
529 static void
530 snmpTlstmParamsTable_free( netsnmp_cache *cache, void *vmagic )
531 {
532 netsnmp_tdata *table = (netsnmp_tdata *)vmagic;
533 netsnmp_tdata_row *row;
534 netsnmp_iterator *tbl_itr;
535 snmpTlstmParamsTable_entry *entry;
536
537 DEBUGMSGTL(("tlstmParamsTable:cache:free", "called, %" NETSNMP_PRIz "d rows\n",
538 CONTAINER_SIZE(table->container)));
539
540 tbl_itr = CONTAINER_ITERATOR(table->container);
541 if (NULL == tbl_itr) {
542 DEBUGMSGTL(("tlstmParamsTable:cache:free",
543 "cant get entry iterator\n"));
544 return;
545 }
546
547 row = ITERATOR_FIRST(tbl_itr);
548 for( ; row; row = ITERATOR_NEXT(tbl_itr)) {
549 entry = row->data;
550
551 /*
552 * remove all active rows (they are in the params container kept
553 * by the library). Keep inactive ones for next time.
554 */
555 if (entry->snmpTlstmParamsRowStatus == RS_ACTIVE) {
556 snmpTlstmParamsTable_removeEntry(NULL, row);
557 ITERATOR_REMOVE(tbl_itr);
558 continue;
559 }
560 }
561 ITERATOR_RELEASE(tbl_itr);
562
563 DEBUGMSGTL(("tlstmParamsTable:cache:free", "done, %" NETSNMP_PRIz "d rows\n",
564 CONTAINER_SIZE(table->container)));
565 }
566
567 /** **************************************************************************
568 *
569 * handles requests for the snmpTlstmParamsTable table
570 *
571 */
572 static int
573 snmpTlstmParamsTable_handler(
574 netsnmp_mib_handler *handler,
575 netsnmp_handler_registration *reginfo,
576 netsnmp_agent_request_info *reqinfo,
577 netsnmp_request_info *requests) {
578
579 netsnmp_request_info *request = NULL;
580 netsnmp_table_request_info *table_info;
581 netsnmp_tdata *table_data;
582 snmpTlstmParamsTable_entry *table_entry;
583 int ret = SNMP_ERR_NOERROR;
584
585 DEBUGMSGTL(("tlstmParamsTable:handler", "Processing %s mode (%d) request\n",
586 se_find_label_in_slist("agent_mode", reqinfo->mode),
587 reqinfo->mode));
588
589 switch (reqinfo->mode) {
590 /** ######################################################### GET #####
591 *
592 * Read-support (also covers GetNext requests)
593 */
594 case MODE_GET:
595 for (request=requests; request; request=request->next) {
596 if (request->processed)
597 continue;
598
599 table_entry = (snmpTlstmParamsTable_entry *)
600 netsnmp_tdata_extract_entry(request);
601 table_info = netsnmp_extract_table_info( request);
602 switch (table_info->colnum) {
603 case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT:
604 {
605 u_char bin[42], *ptr = bin;
606 size_t len = sizeof(bin), offset = 1;
607 int rc;
608 bin[0] = table_entry->hashType;
609 netsnmp_assert(table_entry->hashType != 0);
610 rc = netsnmp_hex_to_binary(
611 &ptr, &len, &offset, 0,
612 table_entry->snmpTlstmParamsClientFingerprint, NULL);
613 if (1 != rc)
614 netsnmp_set_request_error(reqinfo, request,
615 SNMP_ERR_GENERR);
616 else
617 snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
618 bin, offset);
619 }
620 break; /* case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT */
621 case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE:
622 snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
623 table_entry->snmpTlstmParamsStorageType);
624 break; /* case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE */
625 case COLUMN_SNMPTLSTMPARAMSROWSTATUS:
626 snmp_set_var_typed_integer( request->requestvb, ASN_INTEGER,
627 table_entry->snmpTlstmParamsRowStatus);
628 break; /* case COLUMN_SNMPTLSTMPARAMSROWSTATUS */
629 default:
630 netsnmp_set_request_error(reqinfo, request,
631 SNMP_NOSUCHOBJECT);
632 break;
633 } /* switch colnum */
634 } /* for requests */
635 break; /* case MODE_GET */
636
637 /*
638 * Write-support
639 */
640 /** #################################################### RESERVE1 #####
641 *
642 * In RESERVE1 we are just checking basic ASN.1 size/type restrictions.
643 * You probably don't need to change any of this code. Don't change any
644 * of the column values here. Save that for the ACTION phase.
645 *
646 * The next phase is RESERVE2 or FREE.
647 */
648 case MODE_SET_RESERVE1:
649 for (request=requests; request; request=request->next) {
650 table_entry = (snmpTlstmParamsTable_entry *)
651 netsnmp_tdata_extract_entry(request);
652 table_info = netsnmp_extract_table_info( request);
653
654 if ((NULL != table_entry) &&
655 (ST_READONLY == table_entry->snmpTlstmParamsStorageType)) {
656 ret = SNMP_ERR_NOTWRITABLE;
657 break;
658 }
659
660 /*
661 * for each column, allocate any additional resources needed
662 * beyond what is in the undo structure.
663 */
664 switch (table_info->colnum) {
665 case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT:
666 ret = netsnmp_check_vb_type_and_max_size(
667 request->requestvb, ASN_OCTET_STR, sizeof(table_entry->snmpTlstmParamsClientFingerprint));
668 /** check len/algorithm MIB requirements */
669 if (SNMP_ERR_NOERROR == ret)
670 ret = netsnmp_cert_check_vb_fingerprint(request->requestvb);
671
672 break; /* case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT */
673
674 case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE:
675 ret = netsnmp_check_vb_storagetype(request->requestvb,
676 (table_entry ? table_entry->snmpTlstmParamsStorageType : ST_NONE ));
677 break; /* case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE */
678
679 case COLUMN_SNMPTLSTMPARAMSROWSTATUS:
680 ret = netsnmp_check_vb_rowstatus_with_storagetype(request->requestvb,
681 (table_entry ? table_entry->snmpTlstmParamsRowStatus : RS_NONEXISTENT ),
682 (table_entry ? table_entry->snmpTlstmParamsStorageType : ST_NONE));
683 break; /* case COLUMN_SNMPTLSTMPARAMSROWSTATUS */
684 default:
685 ret = SNMP_ERR_NOTWRITABLE;
686 } /* switch colnum */
687
688 if ( ret != SNMP_ERR_NOERROR )
689 break;
690 }/* for requests */
691 break; /* case MODE_SET_RESERVE1 */
692
693 /** #################################################### RESERVE2 #####
694 *
695 * RESERVE2 is for checking additional restrictions from the MIB.
696 * Since these restrictions are often in the description of the object,
697 * mib2c can't generate code. It's possible that you need to add
698 * additional checks here. However, don't change any of the column
699 * values here. Save that for the ACTION phase.
700 *
701 * The next phase is ACTION or FREE.
702 */
703 case MODE_SET_RESERVE2:
704 for (request=requests; request; request=request->next) {
705 netsnmp_tdata_row *table_row = NULL;
706
707 table_entry = (snmpTlstmParamsTable_entry *)
708 netsnmp_tdata_extract_entry(request);
709 table_data = netsnmp_tdata_extract_table(request);
710 table_info = netsnmp_extract_table_info( request);
711 /*
712 * if no table_row, create one
713 */
714 if ( !table_entry ) {
715 table_row = snmpTlstmParamsTable_createEntry
716 (table_data, (char*)table_info->indexes->val.string,
717 table_info->indexes->val_len);
718 if (!table_row) {
719 ret = SNMP_ERR_RESOURCEUNAVAILABLE;
720 break;
721 }
722 table_entry = table_row->data;
723 _allocUndo(table_entry);
724 if (table_entry && !table_entry->undo) {
725 snmpTlstmParamsTable_removeEntry(table_data, table_row);
726 table_row = NULL;
727 ret = SNMP_ERR_RESOURCEUNAVAILABLE;
728 break;
729 }
730 table_entry->undo->fate = FATE_NEWLY_CREATED;
731 /** associate row with requests */
732 netsnmp_insert_tdata_row( request, table_row );
733 }
734
735 /** allocate undo structure, if needed */
736 if(!table_entry->undo) {
737 _allocUndo(table_entry);
738 if (!table_entry->undo) {
739 ret = SNMP_ERR_RESOURCEUNAVAILABLE;
740 break;
741 }
742 }
743
744 /** don't allow multiple sets of same column */
745 if (table_entry->undo->req[table_info->colnum]) {
746 DEBUGMSGT(("tlstmParamsTable:reserve2",
747 "multiple sets to col %d in request\n",
748 table_info->colnum));
749 ret = SNMP_ERR_INCONSISTENTNAME;
750 break;
751 }
752 table_entry->undo->req[table_info->colnum] = request;
753
754 if ( ret != SNMP_ERR_NOERROR )
755 break;
756 } /* for requests */
757
758 /** make sure rowstatus is used to create rows */
759 if ( ret == SNMP_ERR_NOERROR ) {
760 for (request = requests; request; request = request->next) {
761 if (request->processed)
762 continue;
763
764 table_entry = (snmpTlstmParamsTable_entry *)
765 netsnmp_tdata_extract_entry(request);
766 if ((table_entry->undo->fate != FATE_NEWLY_CREATED) ||
767 (table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSROWSTATUS]))
768 continue;
769 ret = SNMP_ERR_INCONSISTENTNAME;
770 break;
771 } /* for requests / creation */
772 } /* if no error */
773 break; /* case MODE_SET_RESERVE2 */
774
775 /** ######################################################## FREE #####
776 *
777 * FREE is for cleaning up after a failed request (during either
778 * RESERVE1 or RESERVE2). So any allocated resources need to be
779 * released.
780 *
781 * This the final phase for this path in the state machine.
782 */
783 case MODE_SET_FREE:
784 /*
785 * release undo resources
786 * remove any newly created rows
787 */
788 for (request=requests; request; request=request->next) {
789 netsnmp_tdata_row *table_row = netsnmp_tdata_extract_row(request);
790
791 table_data = netsnmp_tdata_extract_table(request);
792 table_entry = (snmpTlstmParamsTable_entry *)
793 netsnmp_tdata_extract_entry(request);
794
795 if ( !table_entry || !table_entry->undo )
796 continue;
797
798 /** disassociate row with requests */
799 netsnmp_remove_tdata_row( request, table_row );
800
801 if (FATE_NEWLY_CREATED == table_entry->undo->fate )
802 snmpTlstmParamsTable_removeEntry( table_data, table_row );
803 else
804 _freeUndo(table_entry);
805 }
806 break; /* case MODE_SET_FREE */
807
808 /** ###################################################### ACTION #####
809 *
810 * In the ACTION phase, we perform any sets that can be undone.
811 * (Save anything that can't be undone for the COMMIT phase.)
812 *
813 * After individual columns have been done, you should check that the
814 * row as a whole is consistent.
815 *
816 * The next phase is UNDO or COMMIT.
817 */
818 case MODE_SET_ACTION:
819 for (request=requests; request; request=request->next) {
820 table_entry = (snmpTlstmParamsTable_entry *)
821 netsnmp_tdata_extract_entry(request);
822 table_info = netsnmp_extract_table_info( request);
823
824 switch (table_info->colnum) {
825 case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT:
826 {
827 u_char *tmp = (u_char*)table_entry->snmpTlstmParamsClientFingerprint;
828
829 memcpy( table_entry->undo->snmpTlstmParamsClientFingerprint,
830 table_entry->snmpTlstmParamsClientFingerprint,
831 sizeof(table_entry->snmpTlstmParamsClientFingerprint));
832 table_entry->undo->snmpTlstmParamsClientFingerprint_len =
833 table_entry->snmpTlstmParamsClientFingerprint_len;
834
835 table_entry->hashType = request->requestvb->val.string[0];
836 memset( table_entry->snmpTlstmParamsClientFingerprint, 0,
837 sizeof(table_entry->snmpTlstmParamsClientFingerprint));
838 table_entry->snmpTlstmParamsClientFingerprint_len =
839 sizeof(table_entry->snmpTlstmParamsClientFingerprint);
840 table_entry->snmpTlstmParamsClientFingerprint_len =
841 netsnmp_binary_to_hex(&tmp, &table_entry->snmpTlstmParamsClientFingerprint_len,
842 0, &request->requestvb->val.string[1],
843 request->requestvb->val_len - 1);
844 if (0 == table_entry->snmpTlstmParamsClientFingerprint_len)
845 ret = SNMP_ERR_GENERR;
846 }
847 break; /* case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT */
848
849 case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE:
850 /* save snmpTlstmParamsStorageType value */
851 table_entry->undo->snmpTlstmParamsStorageType = table_entry->snmpTlstmParamsStorageType;
852 /* get value from varbind */
853 table_entry->snmpTlstmParamsStorageType = *request->requestvb->val.integer;
854 break; /* case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE */
855
856 case COLUMN_SNMPTLSTMPARAMSROWSTATUS:
857 /* save snmpTlstmParamsRowStatus value */
858 table_entry->undo->snmpTlstmParamsRowStatus = table_entry->snmpTlstmParamsRowStatus;
859 /* get value from varbind */
860 table_entry->snmpTlstmParamsRowStatus = *request->requestvb->val.integer;
861 break; /* case COLUMN_SNMPTLSTMPARAMSROWSTATUS */
862 } /* switch colnum */
863 if ( ret != SNMP_ERR_NOERROR )
864 break;
865 } /* set values for requests */
866
867 if ( ret == SNMP_ERR_NOERROR ) {
868
869 /*
870 * All columns now have their final values set. check the
871 * internal consistency of each row.
872 */
873 for (request=requests; request; request=request->next) {
874 table_entry = (snmpTlstmParamsTable_entry *)
875 netsnmp_tdata_extract_entry(request);
876 table_info = netsnmp_extract_table_info( request);
877
878 if (table_entry->undo->is_consistent != -1)
879 continue; /* already checked */
880
881 /** assume consistency */
882 table_entry->undo->is_consistent = 1;
883
884 if ((RS_IS_ACTIVE(table_entry->snmpTlstmParamsRowStatus)) &&
885 ((!table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSROWSTATUS]) ||
886 (RS_IS_ACTIVE(table_entry->undo->snmpTlstmParamsRowStatus)))) {
887 /*
888 * check mib restrictions on active rows.
889 */
890 if (table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT]) {
891 table_entry->undo->is_consistent = 0;
892 request = table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT];
893 ret = SNMP_ERR_INCONSISTENTVALUE; /* per mib */
894 }
895 } /* active row */
896 else if (RS_IS_GOING_ACTIVE(table_entry->snmpTlstmParamsRowStatus)) {
897 /*
898 * check restrictions for activating a row
899 */
900 /** if going active, inconsistency is fatal */
901 if (!table_entry->undo->is_consistent) {
902 if (FATE_NEWLY_CREATED == table_entry->undo->fate)
903 ret = SNMP_ERR_INCONSISTENTNAME;
904 else
905 ret = SNMP_ERR_INCONSISTENTVALUE;
906 request = table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSROWSTATUS];
907 }
908 } /* going active */
909 else if (RS_DESTROY == table_entry->snmpTlstmParamsRowStatus) {
910 /*
911 * TODO: check restrictions for deleting a row
912 */
913 /** can't delete active row */
914 if (RS_IS_ACTIVE(table_entry->undo->snmpTlstmParamsRowStatus)) {
915 ret = SNMP_ERR_INCONSISTENTVALUE;
916 request = table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSROWSTATUS];
917 }
918 } /* destroy */
919 if ( ret != SNMP_ERR_NOERROR )
920 break;
921 } /* consistency for requests */
922 } /* if no error */
923 break; /* case MODE_SET_ACTION */
924
925 /** ######################################################## UNDO #####
926 *
927 * UNDO is for cleaning up any failed requests that went through the
928 * ACTION phase.
929 *
930 * This the final phase for this path in the state machine.
931 */
932 case MODE_SET_UNDO:
933 for (request=requests; request; request=request->next) {
934 table_entry = (snmpTlstmParamsTable_entry *)
935 netsnmp_tdata_extract_entry(request);
936 table_data = netsnmp_tdata_extract_table(request);
937 table_info = netsnmp_extract_table_info( request);
938
939 switch (table_info->colnum) {
940 case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT:
941 /* restore snmpTlstmParamsClientFingerprint value */
942 memcpy( table_entry->snmpTlstmParamsClientFingerprint,
943 table_entry->undo->snmpTlstmParamsClientFingerprint,
944 sizeof(table_entry->snmpTlstmParamsClientFingerprint));
945 table_entry->snmpTlstmParamsClientFingerprint_len =
946 table_entry->undo->snmpTlstmParamsClientFingerprint_len;
947 break; /* case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT */
948
949 case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE:
950 /* restore snmpTlstmParamsStorageType value */
951 table_entry->snmpTlstmParamsStorageType =
952 table_entry->undo->snmpTlstmParamsStorageType;
953 break; /* case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE */
954
955 case COLUMN_SNMPTLSTMPARAMSROWSTATUS:
956 /* restore snmpTlstmParamsRowStatus value */
957 table_entry->snmpTlstmParamsRowStatus = table_entry->undo->snmpTlstmParamsRowStatus;
958 break; /* case COLUMN_SNMPTLSTMPARAMSROWSTATUS */
959 } /* switch colnum */
960 } /* for requests */
961
962 /*
963 * release undo data
964 * or remove any newly created rows
965 */
966 for (request=requests; request; request=request->next) {
967 netsnmp_tdata_row *table_row = netsnmp_tdata_extract_row(request);
968
969 table_entry = (snmpTlstmParamsTable_entry *)
970 netsnmp_tdata_extract_entry(request);
971
972 if ( !table_entry || !table_entry->undo )
973 continue;
974
975 /** disassociate row with requests */
976 netsnmp_remove_tdata_row( request, table_row );
977
978 if (FATE_NEWLY_CREATED == table_entry->undo->fate )
979 snmpTlstmParamsTable_removeEntry( table_data, table_row );
980 else
981 _freeUndo(table_entry);
982 } /* for requests */
983 break; /* case MODE_SET_UNDO */
984
985 /** ###################################################### COMMIT #####
986 *
987 * COMMIT is the final success state, when all changes are finalized.
988 * There is not recovery state should something faile here.
989 *
990 * This the final phase for this path in the state machine.
991 */
992 case MODE_SET_COMMIT:
993 for (request=requests; request; request=request->next) {
994 netsnmp_tdata_row *table_row = netsnmp_tdata_extract_row(request);
995
996 table_data = netsnmp_tdata_extract_table(request);
997 table_info = netsnmp_extract_table_info( request);
998 table_entry = (snmpTlstmParamsTable_entry *)
999 netsnmp_tdata_extract_entry(request);
1000
1001 if (!table_entry || !table_entry->undo)
1002 continue;
1003
1004 if ((RS_NOTREADY == table_entry->snmpTlstmParamsRowStatus) &&
1005 table_entry->undo->is_consistent)
1006 table_entry->snmpTlstmParamsRowStatus = RS_NOTINSERVICE;
1007 else if ((RS_NOTINSERVICE == table_entry->snmpTlstmParamsRowStatus) &&
1008 (0 == table_entry->undo->is_consistent))
1009 table_entry->snmpTlstmParamsRowStatus = RS_NOTREADY;
1010
1011 /** release undo data for requests with no rowstatus */
1012 if (table_entry->undo &&
1013 table_entry->undo->req[COLUMN_SNMPTLSTMPARAMSROWSTATUS] == NULL) {
1014 _freeUndo(table_entry);
1015
1016 /** update active addrs */
1017 if ((0 == table_entry->params_flags) &&
1018 (table_entry->snmpTlstmParamsRowStatus == RS_ACTIVE))
1019 _params_add(table_entry);
1020 else if ((0 != table_entry->params_flags) &&
1021 (table_entry->snmpTlstmParamsRowStatus == RS_DESTROY))
1022 _params_remove(table_entry);
1023 }
1024
1025 switch (table_info->colnum) {
1026
1027 case COLUMN_SNMPTLSTMPARAMSROWSTATUS:
1028 switch (table_entry->snmpTlstmParamsRowStatus) {
1029 case RS_CREATEANDGO:
1030 /** Fall-through */
1031 case RS_ACTIVE:
1032 table_entry->snmpTlstmParamsRowStatus = RS_ACTIVE;
1033 if (0 == table_entry->params_flags)
1034 _params_add(table_entry);
1035 break;
1036
1037 case RS_CREATEANDWAIT:
1038 /** Fall-through */
1039 case RS_NOTINSERVICE:
1040 /** simply set status based on consistency */
1041 if (table_entry->undo->is_consistent)
1042 table_entry->snmpTlstmParamsRowStatus = RS_NOTINSERVICE;
1043 else
1044 table_entry->snmpTlstmParamsRowStatus = RS_NOTREADY;
1045 if (0 != table_entry->params_flags)
1046 _params_remove(table_entry);
1047 break;
1048
1049 case RS_DESTROY:
1050 if (0 != table_entry->params_flags)
1051 _params_remove(table_entry);
1052 /** disassociate row with requests */
1053 netsnmp_remove_tdata_row( request, table_row );
1054 snmpTlstmParamsTable_removeEntry(table_data, table_row );
1055 table_entry = NULL;
1056 }
1057 /** release undo data */
1058 _freeUndo(table_entry);
1059 break; /* case COLUMN_SNMPTLSTMPARAMSROWSTATUS */
1060
1061 case COLUMN_SNMPTLSTMPARAMSSTORAGETYPE:
1062 if (RS_ACTIVE == table_entry->snmpTlstmParamsRowStatus)
1063 _params_tweak_storage(table_entry);
1064 break;
1065
1066 case COLUMN_SNMPTLSTMPARAMSCLIENTFINGERPRINT:
1067 break;
1068 } /* switch colnum */
1069 } /* for requests */
1070
1071 /** update last changed */
1072 _last_changed = netsnmp_get_agent_uptime();
1073
1074 /** set up to save persistent store */
1075 snmp_store_needed(NULL);
1076
1077 break; /* case MODE_SET_COMMIT */
1078 } /* switch (reqinfo->mode) */
1079
1080 if ( ret != SNMP_ERR_NOERROR )
1081 netsnmp_set_request_error( reqinfo, request, ret);
1082
1083 return SNMP_ERR_NOERROR;
1084 }
1085
1086
1087 static int
1088 _count_handler(netsnmp_mib_handler *handler,
1089 netsnmp_handler_registration *reginfo,
1090 netsnmp_agent_request_info *reqinfo,
1091 netsnmp_request_info *requests)
1092 {
1093 int val;
1094
1095 if (MODE_GET != reqinfo->mode) {
1096 snmp_log(LOG_ERR, "bad mode in RO handler");
1097 return SNMP_ERR_GENERR;
1098 }
1099
1100 if (NULL == _table_data->container)
1101 val = 0;
1102 else
1103 val = CONTAINER_SIZE(_table_data->container);
1104
1105 snmp_set_var_typed_value(requests->requestvb, ASN_GAUGE,
1106 (u_char *) &val, sizeof(val));
1107
1108 if (handler->next && handler->next->access_method)
1109 return netsnmp_call_next_handler(handler, reginfo, reqinfo,
1110 requests);
1111
1112 return SNMP_ERR_NOERROR;
1113 }
1114
1115 /***********************************************************************
1116 *
1117 * PERSISTENCE
1118 *
1119 ***********************************************************************/
1120
1121 static int _save_params(snmpTlstmParams *params, void *app_type);
1122 static int _save_entry(snmpTlstmParamsTable_entry *entry, void *type);
1123 static void _tlstmParamsTable_row_restore_mib(const char *token, char *buf);
1124
1125 static const char mib_token[] = "snmpTlstmParamsEntry";
1126
1127 /************************************************************
1128 * *_init_persistence should be called from the main table
1129 * init routine.
1130 *
1131 * If your table depends on rows in another table,
1132 * you should register your callback after the other table,
1133 * which should ensure the rows on which you depend are saved
1134 * (and re-created) before the dependent rows.
1135 */
1136 void
1137 _tlstmParams_init_persistence(void)
1138 {
1139 int rc;
1140
1141 register_config_handler(NULL, mib_token, _tlstmParamsTable_row_restore_mib,
1142 NULL, NULL);
1143 rc = snmp_register_callback(SNMP_CALLBACK_LIBRARY,
1144 SNMP_CALLBACK_STORE_DATA,
1145 _tlstmParamsTable_save,
1146 _table_data->container);
1147
1148 if (rc != SNMP_ERR_NOERROR)
1149 snmp_log(LOG_ERR, "error registering for STORE_DATA callback "
1150 "in _tlstmParams_init_persistence\n");
1151 }
1152
1153 static int
1154 _tlstmParamsTable_save(int majorID, int minorID, void *serverarg,
1155 void *clientarg)
1156 {
1157 char sep[] =
1158 "##############################################################";
1159 char buf[] = "#\n" "# tlstmParams persistent data\n" "#";
1160 char *type = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
1161 NETSNMP_DS_LIB_APPTYPE);
1162
1163 netsnmp_container *active_params = netsnmp_tlstmParams_container();
1164 netsnmp_tdata_row *row;
1165 netsnmp_iterator *tbl_itr, *params_itr;
1166 snmpTlstmParams *params;
1167 snmpTlstmParamsTable_entry *entry;
1168
1169 if ((CONTAINER_SIZE(active_params) == 0) &&
1170 (CONTAINER_SIZE(_table_data->container) == 0))
1171 return SNMPERR_SUCCESS;
1172
1173 read_config_store((char *) type, sep);
1174 read_config_store((char *) type, buf);
1175
1176 /*
1177 * save active rows from params container
1178 */
1179 if (NULL != active_params) {
1180 params_itr = CONTAINER_ITERATOR(active_params);
1181 if (NULL == params_itr) {
1182 DEBUGMSGTL(("tlstmParamsTable:save",
1183 "cant get params iterator\n"));
1184 params = NULL;
1185 }
1186 else
1187 params = ITERATOR_FIRST(params_itr);
1188
1189 for( ; params; params = ITERATOR_NEXT(params_itr)) {
1190 /** don't store config rows */
1191 if ((params->flags & TLSTM_PARAMS_FROM_CONFIG) ||
1192 ! (params->flags & TLSTM_PARAMS_NONVOLATILE))
1193 continue;
1194 _save_params(params, type);
1195 }
1196 ITERATOR_RELEASE(params_itr);
1197 }
1198
1199 /*
1200 * save inactive rows from mib
1201 */
1202 tbl_itr = CONTAINER_ITERATOR(_table_data->container);
1203 if (NULL == tbl_itr)
1204 DEBUGMSGTL(("tlstmParamsTable:save", "cant get table iterator\n"));
1205 else {
1206 row = ITERATOR_FIRST(tbl_itr);
1207 for( ; row; row = ITERATOR_NEXT(tbl_itr)) {
1208 entry = row->data;
1209
1210 /*
1211 * skip all active rows (should be in active_params and thus saved
1212 * above) and volatile rows.
1213 */
1214 if ((entry->snmpTlstmParamsRowStatus == RS_ACTIVE) ||
1215 (entry->snmpTlstmParamsStorageType != ST_NONVOLATILE))
1216 continue;
1217
1218 _save_entry(entry, type);
1219 }
1220 ITERATOR_RELEASE(tbl_itr);
1221 }
1222
1223 read_config_store((char *) type, sep);
1224 read_config_store((char *) type, "\n");
1225
1226 /*
1227 * never fails
1228 */
1229 return SNMPERR_SUCCESS;
1230 }
1231
1232 /************************************************************
1233 * _tlstmParamsTable_container_row_save
1234 */
1235 static int
1236 _save_entry(snmpTlstmParamsTable_entry *entry, void *type)
1237 {
1238 char buf[SNMP_MAXBUF_SMALL], *hashType;
1239
1240 hashType = se_find_label_in_slist("cert_hash_alg", entry->hashType);
1241 if (NULL == hashType) {
1242 snmp_log(LOG_ERR, "skipping entry unknown hash type %d\n",
1243 entry->hashType);
1244 return SNMP_ERR_GENERR;
1245 }
1246
1247 /*
1248 * build the line
1249 */
1250 netsnmp_assert(0 == entry->snmpTargetParamsName[
1251 entry->snmpTargetParamsName_len]);
1252 netsnmp_assert(0 == entry->snmpTlstmParamsClientFingerprint[
1253 entry->snmpTlstmParamsClientFingerprint_len]);
1254 snprintf(buf, sizeof(buf), "%s %s %s %s %d", mib_token,
1255 entry->snmpTargetParamsName, hashType,
1256 entry->snmpTlstmParamsClientFingerprint,
1257 entry->snmpTlstmParamsRowStatus);
1258 buf[sizeof(buf)-1] = 0;
1259
1260 read_config_store(type, buf);
1261 DEBUGMSGTL(("tlstmParamsTable:row:save", "saving entry '%s'\n", buf));
1262
1263 return SNMP_ERR_NOERROR;
1264 }
1265
1266 static int
1267 _save_params(snmpTlstmParams *params, void *app_type)
1268 {
1269 char buf[SNMP_MAXBUF_SMALL], *hashType;
1270
1271 if (NULL == params)
1272 return SNMP_ERR_GENERR;
1273
1274 hashType = se_find_label_in_slist("cert_hash_alg", params->hashType);
1275 if (NULL == hashType) {
1276 snmp_log(LOG_ERR, "skipping entry unknown hash type %d\n",
1277 params->hashType);
1278 return SNMP_ERR_GENERR;
1279 }
1280 snprintf(buf, sizeof(buf), "%s %s --%s %s %d", mib_token, params->name,
1281 hashType, params->fingerprint, RS_ACTIVE);
1282
1283 DEBUGMSGTL(("tlstmParamsTable:params:save", "saving params '%s'\n",
1284 buf));
1285 read_config_store(app_type, buf);
1286
1287 return SNMP_ERR_NOERROR;
1288 }
1289
1290 static void
1291 _tlstmParamsTable_row_restore_mib(const char *token, char *buf)
1292 {
1293 u_char rowStatus;
1294 snmpTlstmParams *params;
1295
1296 /** need somewhere to save rows */
1297 netsnmp_assert(_table_data && _table_data->container);
1298
1299 params = netsnmp_tlstmParams_restore_common(&buf);
1300 if (NULL == params)
1301 return;
1302
1303 if (NULL == buf) {
1304 config_perror("incomplete line");
1305 return;
1306 }
1307 rowStatus = atoi(buf);
1308
1309 /*
1310 * if row is active, add it to the params container so it is available
1311 * for use. Do not add it to the table, since it will be added
1312 * during cache_load.
1313 */
1314 if (RS_ACTIVE == rowStatus) {
1315 params->flags = TLSTM_PARAMS_FROM_MIB | TLSTM_PARAMS_NONVOLATILE;
1316
1317 netsnmp_tlstmParams_add(params);
1318 } else {
1319 netsnmp_tdata_row *row;
1320 snmpTlstmParamsTable_entry *entry;
1321
1322 row = snmpTlstmParamsTable_createEntry(_table_data, params->name,
1323 strlen(params->name));
1324 if (!row) {
1325 netsnmp_tlstmParams_free(params);
1326 return;
1327 }
1328
1329 entry = row->data;
1330
1331 entry->hashType = params->hashType;
1332 strlcpy(entry->snmpTlstmParamsClientFingerprint, params->fingerprint,
1333 sizeof(entry->snmpTlstmParamsClientFingerprint));
1334 entry->snmpTlstmParamsClientFingerprint_len =
1335 strlen(entry->snmpTlstmParamsClientFingerprint);
1336 entry->snmpTlstmParamsStorageType = ST_NONVOLATILE;
1337 entry->snmpTlstmParamsRowStatus = rowStatus;
1338 netsnmp_tlstmParams_free(params);
1339 }
1340 }