| 1 |
/* |
| 2 |
* This file was generated by mib2c and is intended for use as |
| 3 |
* a mib module for the ucd-snmp snmpd agent. |
| 4 |
* |
| 5 |
* Portions of this file are copyrighted by: |
| 6 |
* Copyright (c) 2016 VMware, Inc. All rights reserved. |
| 7 |
* Use is subject to license terms specified in the COPYING file |
| 8 |
* distributed with the Net-SNMP package. |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
/* |
| 13 |
* This should always be included first before anything else |
| 14 |
*/ |
| 15 |
#include <net-snmp/net-snmp-config.h> |
| 16 |
|
| 17 |
#include <sys/types.h> |
| 18 |
#ifdef HAVE_STDLIB_H |
| 19 |
#include <stdlib.h> |
| 20 |
#endif |
| 21 |
#ifdef HAVE_STRING_H |
| 22 |
#include <string.h> |
| 23 |
#else |
| 24 |
#include <strings.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
|
| 28 |
/* |
| 29 |
* minimal include directives |
| 30 |
*/ |
| 31 |
#include <net-snmp/net-snmp-features.h> |
| 32 |
#include <net-snmp/net-snmp-includes.h> |
| 33 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 34 |
|
| 35 |
#include "header_complex.h" |
| 36 |
#include "snmpNotifyTable_data.h" |
| 37 |
#include "snmpNotifyFilterProfileTable_data.h" |
| 38 |
|
| 39 |
|
| 40 |
/* |
| 41 |
* global storage of our data, saved in and configured by header_complex() |
| 42 |
*/ |
| 43 |
static struct header_complex_index *snmpNotifyFilterProfileTableStorage = |
| 44 |
NULL; |
| 45 |
static int _active = 0; |
| 46 |
|
| 47 |
void parse_snmpNotifyFilterProfileTable(const char *token, char *line); |
| 48 |
int store_snmpNotifyFilterProfileTable(int majorID, int minorID, |
| 49 |
void *serverarg, void *clientarg); |
| 50 |
|
| 51 |
/* |
| 52 |
* init_snmpNotifyFilterProfileTable(): |
| 53 |
* Initialization routine. This is called when the agent starts up. |
| 54 |
* At a minimum, registration of your variables should take place here. |
| 55 |
*/ |
| 56 |
void |
| 57 |
init_snmpNotifyFilterProfileTable_data(void) |
| 58 |
{ |
| 59 |
int done = 0; |
| 60 |
|
| 61 |
if (++done != 1) |
| 62 |
return; |
| 63 |
|
| 64 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "initializing... ")); |
| 65 |
|
| 66 |
/* |
| 67 |
* register our config handler(s) to deal with registrations |
| 68 |
*/ |
| 69 |
snmpd_register_config_handler("snmpNotifyFilterProfileTable", |
| 70 |
parse_snmpNotifyFilterProfileTable, NULL, |
| 71 |
NULL); |
| 72 |
|
| 73 |
/* |
| 74 |
* we need to be called back later to store our data |
| 75 |
*/ |
| 76 |
snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, |
| 77 |
store_snmpNotifyFilterProfileTable, NULL); |
| 78 |
} |
| 79 |
|
| 80 |
void |
| 81 |
shutdown_snmpNotifyFilterProfileTable_data(void) |
| 82 |
{ |
| 83 |
struct header_complex_index *hptr, *nhptr; |
| 84 |
|
| 85 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "shutdown... ")); |
| 86 |
|
| 87 |
for (hptr = snmpNotifyFilterProfileTableStorage; hptr; hptr = nhptr) { |
| 88 |
struct snmpNotifyFilterProfileTable_data *nptr = hptr->data; |
| 89 |
nhptr = hptr->next; |
| 90 |
if (nptr->snmpNotifyFilterProfileStorType == ST_READONLY) { |
| 91 |
header_complex_extract_entry(&snmpNotifyFilterProfileTableStorage, |
| 92 |
hptr); |
| 93 |
snmpNotifyFilterProfileTable_free(nptr); |
| 94 |
} |
| 95 |
} |
| 96 |
snmpNotifyFilterProfileTableStorage = NULL; |
| 97 |
|
| 98 |
DEBUGMSGTL(("trap:notifyFilterProfile:shutdown", |
| 99 |
"active count %d\n", _active)); |
| 100 |
if (_active != 0) { |
| 101 |
DEBUGMSGTL(("trap:notifyFilterProfile:shutdown", |
| 102 |
"unexpected count %d after cleanup!\n", _active)); |
| 103 |
snmp_log(LOG_WARNING, |
| 104 |
"notifyFilterProfile count %d, not 0, after shutdown.\n", |
| 105 |
_active); |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
void |
| 111 |
snmpNotifyFilterProfileTable_free(struct snmpNotifyFilterProfileTable_data |
| 112 |
*data) |
| 113 |
{ |
| 114 |
if (NULL == data) |
| 115 |
return; |
| 116 |
|
| 117 |
SNMP_FREE(data->snmpTargetParamsName); |
| 118 |
SNMP_FREE(data->snmpNotifyFilterProfileName); |
| 119 |
free(data); |
| 120 |
--_active; |
| 121 |
} |
| 122 |
|
| 123 |
/* |
| 124 |
* |
| 125 |
*/ |
| 126 |
struct snmpNotifyFilterProfileTable_data * |
| 127 |
snmpNotifyFilterProfileTable_create(const char *paramsName, |
| 128 |
size_t paramsName_len, |
| 129 |
const char *profileName, |
| 130 |
size_t profileName_len) |
| 131 |
{ |
| 132 |
struct snmpNotifyFilterProfileTable_data *profile = NULL; |
| 133 |
|
| 134 |
if ((paramsName_len > NOTIFY_NAME_MAX) || (0 == paramsName_len) || |
| 135 |
(profileName_len > NOTIFY_NAME_MAX)|| (0 == profileName_len)) { |
| 136 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", |
| 137 |
"bad params or profile name\n")); |
| 138 |
return NULL; |
| 139 |
} |
| 140 |
|
| 141 |
profile = SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data); |
| 142 |
if (NULL == profile) { |
| 143 |
snmp_log(LOG_ERR, |
| 144 |
"could not allocate snmpNotifyFilterProfileTable_data\n"); |
| 145 |
return NULL; |
| 146 |
} |
| 147 |
++_active; |
| 148 |
|
| 149 |
profile->snmpTargetParamsName = malloc(paramsName_len+1); |
| 150 |
profile->snmpNotifyFilterProfileName = malloc(profileName_len+1); |
| 151 |
if (NULL == profile->snmpTargetParamsName || |
| 152 |
NULL == profile->snmpNotifyFilterProfileName) { |
| 153 |
snmp_log(LOG_ERR, |
| 154 |
"could not allocate snmpNotifyFilterProfileTable_data data\n"); |
| 155 |
snmpNotifyFilterProfileTable_free(profile); |
| 156 |
return NULL; |
| 157 |
} |
| 158 |
|
| 159 |
memcpy(profile->snmpTargetParamsName, paramsName, paramsName_len); |
| 160 |
profile->snmpTargetParamsNameLen = paramsName_len; |
| 161 |
profile->snmpTargetParamsName[paramsName_len] = 0; |
| 162 |
|
| 163 |
memcpy(profile->snmpNotifyFilterProfileName, profileName, profileName_len); |
| 164 |
profile->snmpNotifyFilterProfileNameLen = profileName_len; |
| 165 |
profile->snmpNotifyFilterProfileName[profileName_len] = 0; |
| 166 |
|
| 167 |
profile->snmpNotifyFilterProfileRowStatus = RS_NOTREADY; |
| 168 |
profile->snmpNotifyFilterProfileStorType = ST_READONLY; |
| 169 |
|
| 170 |
return profile; |
| 171 |
} |
| 172 |
|
| 173 |
/* |
| 174 |
* snmpNotifyFilterProfileTable_add(): adds a structure node to our data set |
| 175 |
*/ |
| 176 |
int |
| 177 |
snmpNotifyFilterProfileTable_add(struct snmpNotifyFilterProfileTable_data |
| 178 |
*thedata) |
| 179 |
{ |
| 180 |
netsnmp_variable_list *vars = NULL; |
| 181 |
int retVal; |
| 182 |
|
| 183 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "adding data... ")); |
| 184 |
/* |
| 185 |
* add the index variables to the varbind list, which is |
| 186 |
* used by header_complex to index the data |
| 187 |
*/ |
| 188 |
|
| 189 |
snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, |
| 190 |
(u_char *) thedata->snmpTargetParamsName, |
| 191 |
thedata->snmpTargetParamsNameLen); |
| 192 |
|
| 193 |
if (header_complex_maybe_add_data(&snmpNotifyFilterProfileTableStorage, vars, |
| 194 |
thedata, 1) != NULL){ |
| 195 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "registered an entry\n")); |
| 196 |
retVal = SNMPERR_SUCCESS; |
| 197 |
}else{ |
| 198 |
retVal = SNMPERR_GENERR; |
| 199 |
} |
| 200 |
|
| 201 |
|
| 202 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "done.\n")); |
| 203 |
return retVal; |
| 204 |
} |
| 205 |
|
| 206 |
struct snmpNotifyFilterProfileTable_data * |
| 207 |
snmpNotifyFilterProfileTable_extract(struct snmpNotifyFilterProfileTable_data * |
| 208 |
thedata) |
| 209 |
{ |
| 210 |
struct header_complex_index *hptr; |
| 211 |
|
| 212 |
for (hptr = snmpNotifyFilterProfileTableStorage; hptr; hptr = hptr->next) { |
| 213 |
if (hptr->data == thedata) |
| 214 |
break; |
| 215 |
} |
| 216 |
if (NULL != hptr) { |
| 217 |
struct snmpNotifyFilterProfileTable_data *nptr = hptr->data; |
| 218 |
header_complex_extract_entry(&snmpNotifyFilterProfileTableStorage, |
| 219 |
hptr); |
| 220 |
return nptr; |
| 221 |
} |
| 222 |
return NULL; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
int |
| 227 |
snmpNotifyFilterProfileTable_remove(struct snmpNotifyFilterProfileTable_data * |
| 228 |
thedata) |
| 229 |
{ |
| 230 |
struct snmpNotifyFilterProfileTable_data * found = |
| 231 |
snmpNotifyFilterProfileTable_extract(thedata); |
| 232 |
if (NULL != found) { |
| 233 |
snmpNotifyFilterProfileTable_free(found); |
| 234 |
return 1; |
| 235 |
} |
| 236 |
return 0; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
struct snmpNotifyFilterProfileTable_data * |
| 241 |
snmpNotifyFilterProfileTable_find(const char *name, size_t len) |
| 242 |
{ |
| 243 |
netsnmp_variable_list *vars = NULL; |
| 244 |
struct snmpNotifyFilterProfileTable_data *data; |
| 245 |
|
| 246 |
/* |
| 247 |
* put requested info into var structure |
| 248 |
*/ |
| 249 |
snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, |
| 250 |
(const u_char *) name, len); |
| 251 |
|
| 252 |
/* |
| 253 |
* get the data from the header_complex storage |
| 254 |
*/ |
| 255 |
data = (struct snmpNotifyFilterProfileTable_data *) |
| 256 |
header_complex_get(snmpNotifyFilterProfileTableStorage, vars); |
| 257 |
|
| 258 |
/* |
| 259 |
* free search index |
| 260 |
*/ |
| 261 |
snmp_free_var(vars); |
| 262 |
|
| 263 |
return data; |
| 264 |
} |
| 265 |
|
| 266 |
struct snmpNotifyFilterProfileTable_data * |
| 267 |
snmpNotifyFilterProfileTable_oldapi_find(struct variable *vp, |
| 268 |
oid *name, size_t *nameLen, int exact, |
| 269 |
size_t *var_len, |
| 270 |
WriteMethod ** write_method) |
| 271 |
{ |
| 272 |
return header_complex((struct header_complex_index *) |
| 273 |
snmpNotifyFilterProfileTableStorage, vp, name, |
| 274 |
nameLen, exact, var_len, write_method); |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
char * |
| 279 |
get_FilterProfileName(const char *paramName, size_t paramName_len, |
| 280 |
size_t * profileName_len) |
| 281 |
{ |
| 282 |
struct snmpNotifyFilterProfileTable_data *data = |
| 283 |
snmpNotifyFilterProfileTable_find(paramName, paramName_len); |
| 284 |
|
| 285 |
/* |
| 286 |
* return the requested information (if this row is active) |
| 287 |
*/ |
| 288 |
if (data && data->snmpNotifyFilterProfileRowStatus == RS_ACTIVE) { |
| 289 |
*profileName_len = data->snmpNotifyFilterProfileNameLen; |
| 290 |
return data->snmpNotifyFilterProfileName; |
| 291 |
} |
| 292 |
|
| 293 |
*profileName_len = 0; |
| 294 |
return NULL; |
| 295 |
} |
| 296 |
|
| 297 |
/* |
| 298 |
* parse_snmpNotifyFilterProfileTable(): |
| 299 |
* parses .conf file entries needed to configure the mib. |
| 300 |
*/ |
| 301 |
void |
| 302 |
parse_snmpNotifyFilterProfileTable(const char *token, char *line) |
| 303 |
{ |
| 304 |
size_t tmpint; |
| 305 |
struct snmpNotifyFilterProfileTable_data *StorageTmp = |
| 306 |
SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data); |
| 307 |
|
| 308 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "parsing config... ")); |
| 309 |
|
| 310 |
if (StorageTmp == NULL) { |
| 311 |
config_perror("malloc failure"); |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
line = |
| 316 |
read_config_read_data(ASN_OCTET_STR, line, |
| 317 |
&StorageTmp->snmpTargetParamsName, |
| 318 |
&StorageTmp->snmpTargetParamsNameLen); |
| 319 |
if (StorageTmp->snmpTargetParamsName == NULL) { |
| 320 |
config_perror("invalid specification for snmpTargetParamsName"); |
| 321 |
free(StorageTmp); |
| 322 |
return; |
| 323 |
} |
| 324 |
|
| 325 |
line = |
| 326 |
read_config_read_data(ASN_OCTET_STR, line, |
| 327 |
&StorageTmp->snmpNotifyFilterProfileName, |
| 328 |
&StorageTmp->snmpNotifyFilterProfileNameLen); |
| 329 |
if (StorageTmp->snmpNotifyFilterProfileName == NULL) { |
| 330 |
config_perror("invalid specification for snmpNotifyFilterProfileName"); |
| 331 |
snmpNotifyFilterProfileTable_free(StorageTmp); |
| 332 |
return; |
| 333 |
} |
| 334 |
|
| 335 |
line = |
| 336 |
read_config_read_data(ASN_INTEGER, line, |
| 337 |
&StorageTmp->snmpNotifyFilterProfileStorType, |
| 338 |
&tmpint); |
| 339 |
|
| 340 |
line = |
| 341 |
read_config_read_data(ASN_INTEGER, line, |
| 342 |
&StorageTmp-> |
| 343 |
snmpNotifyFilterProfileRowStatus, &tmpint); |
| 344 |
|
| 345 |
if (snmpNotifyFilterProfileTable_add(StorageTmp) != SNMPERR_SUCCESS){ |
| 346 |
snmpNotifyFilterProfileTable_free(StorageTmp); |
| 347 |
StorageTmp = NULL; |
| 348 |
} |
| 349 |
|
| 350 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "done.\n")); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
/* |
| 357 |
* store_snmpNotifyFilterProfileTable(): |
| 358 |
* stores .conf file entries needed to configure the mib. |
| 359 |
*/ |
| 360 |
int |
| 361 |
store_snmpNotifyFilterProfileTable(int majorID, int minorID, |
| 362 |
void *serverarg, void *clientarg) |
| 363 |
{ |
| 364 |
char line[SNMP_MAXBUF]; |
| 365 |
char *cptr; |
| 366 |
struct snmpNotifyFilterProfileTable_data *StorageTmp; |
| 367 |
struct header_complex_index *hcindex; |
| 368 |
|
| 369 |
|
| 370 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "storing data... ")); |
| 371 |
|
| 372 |
for (hcindex = snmpNotifyFilterProfileTableStorage; hcindex != NULL; |
| 373 |
hcindex = hcindex->next) { |
| 374 |
StorageTmp = |
| 375 |
(struct snmpNotifyFilterProfileTable_data *) hcindex->data; |
| 376 |
|
| 377 |
if ((StorageTmp->snmpNotifyFilterProfileStorType == ST_NONVOLATILE) || |
| 378 |
(StorageTmp->snmpNotifyFilterProfileStorType == ST_PERMANENT)) { |
| 379 |
|
| 380 |
memset(line, 0, sizeof(line)); |
| 381 |
strcat(line, "snmpNotifyFilterProfileTable "); |
| 382 |
cptr = line + strlen(line); |
| 383 |
|
| 384 |
cptr = |
| 385 |
read_config_store_data(ASN_OCTET_STR, cptr, |
| 386 |
&StorageTmp->snmpTargetParamsName, |
| 387 |
&StorageTmp-> |
| 388 |
snmpTargetParamsNameLen); |
| 389 |
cptr = |
| 390 |
read_config_store_data(ASN_OCTET_STR, cptr, |
| 391 |
&StorageTmp-> |
| 392 |
snmpNotifyFilterProfileName, |
| 393 |
&StorageTmp-> |
| 394 |
snmpNotifyFilterProfileNameLen); |
| 395 |
cptr = |
| 396 |
read_config_store_data(ASN_INTEGER, cptr, |
| 397 |
&StorageTmp-> |
| 398 |
snmpNotifyFilterProfileStorType, |
| 399 |
NULL); |
| 400 |
cptr = |
| 401 |
read_config_store_data(ASN_INTEGER, cptr, |
| 402 |
&StorageTmp-> |
| 403 |
snmpNotifyFilterProfileRowStatus, |
| 404 |
NULL); |
| 405 |
|
| 406 |
snmpd_store_config(line); |
| 407 |
} |
| 408 |
} |
| 409 |
DEBUGMSGTL(("snmpNotifyFilterProfileTable", "done.\n")); |
| 410 |
return 0; |
| 411 |
} |