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