| 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 |
#include <net-snmp/net-snmp-features.h> |
| 17 |
|
| 18 |
#include <sys/types.h> |
| 19 |
#ifdef HAVE_STDLIB_H |
| 20 |
#include <stdlib.h> |
| 21 |
#endif |
| 22 |
#ifdef HAVE_STRING_H |
| 23 |
#include <string.h> |
| 24 |
#else |
| 25 |
#include <strings.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
/* |
| 29 |
* minimal include directives |
| 30 |
*/ |
| 31 |
#include <net-snmp/net-snmp-includes.h> |
| 32 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 33 |
|
| 34 |
#include "agent_global_vars.h" |
| 35 |
#include "header_complex.h" |
| 36 |
#include "snmpNotifyTable.h" |
| 37 |
#include "snmpNotifyFilterProfileTable.h" |
| 38 |
#include "target/snmpTargetParamsEntry.h" |
| 39 |
#include "target/snmpTargetAddrEntry.h" |
| 40 |
#include "target/target.h" |
| 41 |
#include "snmp-notification-mib/snmpNotifyFilterTable/snmpNotifyFilterTable.h" |
| 42 |
#include <net-snmp/agent/agent_callbacks.h> |
| 43 |
#include <net-snmp/agent/agent_trap.h> |
| 44 |
#include <net-snmp/agent/mib_module_config.h> |
| 45 |
#include "net-snmp/agent/sysORTable.h" |
| 46 |
|
| 47 |
#ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE |
| 48 |
# include "notification-log-mib/notification_log.h" |
| 49 |
#endif |
| 50 |
|
| 51 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 52 |
netsnmp_feature_require(header_complex_find_entry); |
| 53 |
#endif /* NETSNMP_NO_WRITE_SUPPORT */ |
| 54 |
|
| 55 |
/* |
| 56 |
* snmpNotifyTable_variables_oid: |
| 57 |
* this is the top level oid that we want to register under. This |
| 58 |
* is essentially a prefix, with the suffix appearing in the |
| 59 |
* variable below. |
| 60 |
*/ |
| 61 |
|
| 62 |
|
| 63 |
oid snmpNotifyTable_variables_oid[] = |
| 64 |
{ 1, 3, 6, 1, 6, 3, 13, 1, 1 }; |
| 65 |
|
| 66 |
static oid snmpNotifyFullCompliance[] = |
| 67 |
{ SNMP_OID_SNMPMODULES, 13, 3, 1, 3 }; /* SNMP-NOTIFICATION-MIB::snmpNotifyFullCompliance */ |
| 68 |
|
| 69 |
|
| 70 |
/* |
| 71 |
* variable2 snmpNotifyTable_variables: |
| 72 |
* this variable defines function callbacks and type return information |
| 73 |
* for the snmpNotifyTable mib section |
| 74 |
*/ |
| 75 |
|
| 76 |
|
| 77 |
struct variable2 snmpNotifyTable_variables[] = { |
| 78 |
/* |
| 79 |
* magic number , variable type , ro/rw , callback fn , L, oidsuffix |
| 80 |
*/ |
| 81 |
#define SNMPNOTIFYTAG 4 |
| 82 |
{SNMPNOTIFYTAG, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE, |
| 83 |
var_snmpNotifyTable, 2, {1, 2}}, |
| 84 |
#define SNMPNOTIFYTYPE 5 |
| 85 |
{SNMPNOTIFYTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 86 |
var_snmpNotifyTable, 2, {1, 3}}, |
| 87 |
#define SNMPNOTIFYSTORAGETYPE 6 |
| 88 |
{SNMPNOTIFYSTORAGETYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 89 |
var_snmpNotifyTable, 2, {1, 4}}, |
| 90 |
#define SNMPNOTIFYROWSTATUS 7 |
| 91 |
{SNMPNOTIFYROWSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE, |
| 92 |
var_snmpNotifyTable, 2, {1, 5}}, |
| 93 |
|
| 94 |
}; |
| 95 |
/* |
| 96 |
* (L = length of the oidsuffix) |
| 97 |
*/ |
| 98 |
|
| 99 |
|
| 100 |
/* |
| 101 |
* init_snmpNotifyTable(): |
| 102 |
* Initialization routine. This is called when the agent starts up. |
| 103 |
* At a minimum, registration of your variables should take place here. |
| 104 |
*/ |
| 105 |
void |
| 106 |
init_snmpNotifyTable(void) |
| 107 |
{ |
| 108 |
DEBUGMSGTL(("snmpNotifyTable", "initializing... ")); |
| 109 |
|
| 110 |
init_snmpNotifyTable_data(); |
| 111 |
|
| 112 |
/* |
| 113 |
* register ourselves with the agent to handle our mib tree |
| 114 |
*/ |
| 115 |
REGISTER_MIB("snmpNotifyTable", snmpNotifyTable_variables, variable2, |
| 116 |
snmpNotifyTable_variables_oid); |
| 117 |
|
| 118 |
|
| 119 |
/* |
| 120 |
* register our config handler(s) to deal with registrations |
| 121 |
*/ |
| 122 |
snmpd_register_config_handler("snmpNotifyTable", parse_snmpNotifyTable, |
| 123 |
NULL, NULL); |
| 124 |
|
| 125 |
|
| 126 |
/* |
| 127 |
* place any other initialization junk you need here |
| 128 |
*/ |
| 129 |
|
| 130 |
REGISTER_SYSOR_ENTRY(snmpNotifyFullCompliance, |
| 131 |
"The MIB modules for managing SNMP Notification, plus filtering."); |
| 132 |
|
| 133 |
DEBUGMSGTL(("snmpNotifyTable", "done.\n")); |
| 134 |
} |
| 135 |
|
| 136 |
void |
| 137 |
shutdown_snmpNotifyTable(void) |
| 138 |
{ |
| 139 |
DEBUGMSGTL(("snmpNotifyTable", "shutting down ... ")); |
| 140 |
|
| 141 |
shutdown_snmpNotifyTable_data(); |
| 142 |
|
| 143 |
UNREGISTER_SYSOR_ENTRY(snmpNotifyFullCompliance); |
| 144 |
|
| 145 |
DEBUGMSGTL(("snmpNotifyTable", "done.\n")); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
/* |
| 150 |
* parse_snmpNotifyTable(): |
| 151 |
* parses .conf file entries needed to configure the mib. |
| 152 |
*/ |
| 153 |
void |
| 154 |
parse_snmpNotifyTable(const char *token, char *line) |
| 155 |
{ |
| 156 |
size_t tmpint; |
| 157 |
struct snmpNotifyTable_data *StorageTmp = |
| 158 |
SNMP_MALLOC_STRUCT(snmpNotifyTable_data); |
| 159 |
|
| 160 |
|
| 161 |
DEBUGMSGTL(("snmpNotifyTable", "parsing config... ")); |
| 162 |
|
| 163 |
|
| 164 |
if (StorageTmp == NULL) { |
| 165 |
config_perror("malloc failure"); |
| 166 |
return; |
| 167 |
} |
| 168 |
|
| 169 |
line = |
| 170 |
read_config_read_data(ASN_OCTET_STR, line, |
| 171 |
&StorageTmp->snmpNotifyName, |
| 172 |
&StorageTmp->snmpNotifyNameLen); |
| 173 |
if (StorageTmp->snmpNotifyName == NULL) { |
| 174 |
config_perror("invalid specification for snmpNotifyName"); |
| 175 |
SNMP_FREE(StorageTmp); |
| 176 |
return; |
| 177 |
} |
| 178 |
|
| 179 |
line = |
| 180 |
read_config_read_data(ASN_OCTET_STR, line, |
| 181 |
&StorageTmp->snmpNotifyTag, |
| 182 |
&StorageTmp->snmpNotifyTagLen); |
| 183 |
if (StorageTmp->snmpNotifyTag == NULL) { |
| 184 |
config_perror("invalid specification for snmpNotifyTag"); |
| 185 |
SNMP_FREE(StorageTmp); |
| 186 |
return; |
| 187 |
} |
| 188 |
|
| 189 |
line = |
| 190 |
read_config_read_data(ASN_INTEGER, line, |
| 191 |
&StorageTmp->snmpNotifyType, &tmpint); |
| 192 |
|
| 193 |
line = |
| 194 |
read_config_read_data(ASN_INTEGER, line, |
| 195 |
&StorageTmp->snmpNotifyStorageType, &tmpint); |
| 196 |
if (!StorageTmp->snmpNotifyStorageType) |
| 197 |
StorageTmp->snmpNotifyStorageType = ST_READONLY; |
| 198 |
|
| 199 |
line = |
| 200 |
read_config_read_data(ASN_INTEGER, line, |
| 201 |
&StorageTmp->snmpNotifyRowStatus, &tmpint); |
| 202 |
if (!StorageTmp->snmpNotifyRowStatus) |
| 203 |
StorageTmp->snmpNotifyRowStatus = RS_ACTIVE; |
| 204 |
|
| 205 |
|
| 206 |
if (snmpNotifyTable_add(StorageTmp) != SNMPERR_SUCCESS){ |
| 207 |
SNMP_FREE(StorageTmp->snmpNotifyName); |
| 208 |
SNMP_FREE(StorageTmp->snmpNotifyTag); |
| 209 |
SNMP_FREE(StorageTmp); |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
DEBUGMSGTL(("snmpNotifyTable", "done.\n")); |
| 214 |
} |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
/* |
| 220 |
* var_snmpNotifyTable(): |
| 221 |
* Handle this table separately from the scalar value case. |
| 222 |
* The workings of this are basically the same as for var_snmpNotifyTable above. |
| 223 |
*/ |
| 224 |
unsigned char * |
| 225 |
var_snmpNotifyTable(struct variable *vp, |
| 226 |
oid * name, |
| 227 |
size_t * length, |
| 228 |
int exact, |
| 229 |
size_t * var_len, WriteMethod ** write_method) |
| 230 |
{ |
| 231 |
struct snmpNotifyTable_data *StorageTmp = NULL; |
| 232 |
int found = 1; |
| 233 |
|
| 234 |
DEBUGMSGTL(("snmpNotifyTable", |
| 235 |
"var_snmpNotifyTable: Entering... \n")); |
| 236 |
/* |
| 237 |
* this assumes you have registered all your data properly |
| 238 |
*/ |
| 239 |
if ((StorageTmp = find_row_notifyTable(vp, name, length, exact, |
| 240 |
var_len, write_method)) == NULL) { |
| 241 |
found = 0; |
| 242 |
} |
| 243 |
|
| 244 |
switch (vp->magic) { |
| 245 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 246 |
case SNMPNOTIFYTAG: |
| 247 |
*write_method = write_snmpNotifyTag; |
| 248 |
break; |
| 249 |
case SNMPNOTIFYTYPE: |
| 250 |
*write_method = write_snmpNotifyType; |
| 251 |
break; |
| 252 |
case SNMPNOTIFYSTORAGETYPE: |
| 253 |
*write_method = write_snmpNotifyStorageType; |
| 254 |
break; |
| 255 |
case SNMPNOTIFYROWSTATUS: |
| 256 |
*write_method = write_snmpNotifyRowStatus; |
| 257 |
break; |
| 258 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |
| 259 |
default: |
| 260 |
*write_method = NULL; |
| 261 |
} |
| 262 |
|
| 263 |
if (!found) { |
| 264 |
return NULL; |
| 265 |
} |
| 266 |
|
| 267 |
#ifndef NETSNMP_NO_READ_SUPPORT |
| 268 |
switch (vp->magic) { |
| 269 |
case SNMPNOTIFYTAG: |
| 270 |
*var_len = StorageTmp->snmpNotifyTagLen; |
| 271 |
return (u_char *) StorageTmp->snmpNotifyTag; |
| 272 |
|
| 273 |
case SNMPNOTIFYTYPE: |
| 274 |
*var_len = sizeof(StorageTmp->snmpNotifyType); |
| 275 |
return (u_char *) & StorageTmp->snmpNotifyType; |
| 276 |
|
| 277 |
case SNMPNOTIFYSTORAGETYPE: |
| 278 |
*var_len = sizeof(StorageTmp->snmpNotifyStorageType); |
| 279 |
return (u_char *) & StorageTmp->snmpNotifyStorageType; |
| 280 |
|
| 281 |
case SNMPNOTIFYROWSTATUS: |
| 282 |
*var_len = sizeof(StorageTmp->snmpNotifyRowStatus); |
| 283 |
return (u_char *) & StorageTmp->snmpNotifyRowStatus; |
| 284 |
|
| 285 |
default: |
| 286 |
ERROR_MSG(""); |
| 287 |
} |
| 288 |
#endif /* !NETSNMP_NO_READ_SUPPORT */ |
| 289 |
return NULL; |
| 290 |
} |
| 291 |
|
| 292 |
static int |
| 293 |
is_delim(const char c) |
| 294 |
{ |
| 295 |
return (c == 0x020 || c == 0x09 || c == 0x0d || c == 0x0b); |
| 296 |
} |
| 297 |
|
| 298 |
int |
| 299 |
snmpTagValid(const char *tag, const size_t tagLen) |
| 300 |
{ |
| 301 |
size_t i = 0; |
| 302 |
|
| 303 |
|
| 304 |
for (i = 0; i < tagLen; i++) { |
| 305 |
if (is_delim(tag[i])) { |
| 306 |
/* |
| 307 |
* Delimeters aren't allowed. |
| 308 |
*/ |
| 309 |
return 0; |
| 310 |
} |
| 311 |
} |
| 312 |
return 1; |
| 313 |
} |
| 314 |
|
| 315 |
#ifndef NETSNMP_NO_WRITE_SUPPORT |
| 316 |
|
| 317 |
static struct snmpNotifyTable_data *StorageNew; |
| 318 |
|
| 319 |
static const int snmpNotifyTable_offset = |
| 320 |
sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + 3 - 1; |
| 321 |
|
| 322 |
int |
| 323 |
write_snmpNotifyTag(int action, |
| 324 |
u_char * var_val, |
| 325 |
u_char var_val_type, |
| 326 |
size_t var_val_len, |
| 327 |
u_char * statP, oid * name, size_t name_len) |
| 328 |
{ |
| 329 |
static char *tmpvar; |
| 330 |
struct snmpNotifyTable_data *StorageTmp = NULL; |
| 331 |
static size_t tmplen; |
| 332 |
size_t newlen = name_len - snmpNotifyTable_offset; |
| 333 |
|
| 334 |
|
| 335 |
DEBUGMSGTL(("snmpNotifyTable", |
| 336 |
"write_snmpNotifyTag entering action=%d... \n", action)); |
| 337 |
if (action != RESERVE1 && |
| 338 |
(StorageTmp = find_row_notifyTable(NULL, &name[snmpNotifyTable_offset], |
| 339 |
&newlen, 1, NULL, NULL)) == NULL) { |
| 340 |
if ((StorageTmp = StorageNew) == NULL) |
| 341 |
return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
switch (action) { |
| 346 |
case RESERVE1: |
| 347 |
if (var_val_type != ASN_OCTET_STR) { |
| 348 |
return SNMP_ERR_WRONGTYPE; |
| 349 |
} |
| 350 |
if (var_val_len > 255) { |
| 351 |
return SNMP_ERR_WRONGLENGTH; |
| 352 |
} |
| 353 |
if (!snmpTagValid((char *) var_val, var_val_len)) { |
| 354 |
return SNMP_ERR_WRONGVALUE; |
| 355 |
} |
| 356 |
break; |
| 357 |
|
| 358 |
|
| 359 |
case RESERVE2: |
| 360 |
/* |
| 361 |
* memory reseveration, final preparation... |
| 362 |
*/ |
| 363 |
tmpvar = StorageTmp->snmpNotifyTag; |
| 364 |
tmplen = StorageTmp->snmpNotifyTagLen; |
| 365 |
StorageTmp->snmpNotifyTag = (char*)calloc(1, var_val_len + 1); |
| 366 |
if (NULL == StorageTmp->snmpNotifyTag) |
| 367 |
return SNMP_ERR_RESOURCEUNAVAILABLE; |
| 368 |
break; |
| 369 |
|
| 370 |
|
| 371 |
case FREE: |
| 372 |
/* |
| 373 |
* Release any resources that have been allocated |
| 374 |
*/ |
| 375 |
break; |
| 376 |
|
| 377 |
|
| 378 |
case ACTION: |
| 379 |
memcpy(StorageTmp->snmpNotifyTag, var_val, var_val_len); |
| 380 |
StorageTmp->snmpNotifyTagLen = var_val_len; |
| 381 |
break; |
| 382 |
|
| 383 |
|
| 384 |
case UNDO: |
| 385 |
/* |
| 386 |
* Back out any changes made in the ACTION case |
| 387 |
*/ |
| 388 |
SNMP_FREE(StorageTmp->snmpNotifyTag); |
| 389 |
StorageTmp->snmpNotifyTag = tmpvar; |
| 390 |
StorageTmp->snmpNotifyTagLen = tmplen; |
| 391 |
tmpvar = NULL; |
| 392 |
break; |
| 393 |
|
| 394 |
|
| 395 |
case COMMIT: |
| 396 |
/* |
| 397 |
* Things are working well, so it's now safe to make the change |
| 398 |
* permanently. Make sure that anything done here can't fail! |
| 399 |
*/ |
| 400 |
SNMP_FREE(tmpvar); |
| 401 |
snmp_store_needed(NULL); |
| 402 |
break; |
| 403 |
} |
| 404 |
|
| 405 |
return SNMP_ERR_NOERROR; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
int |
| 411 |
write_snmpNotifyType(int action, |
| 412 |
u_char * var_val, |
| 413 |
u_char var_val_type, |
| 414 |
size_t var_val_len, |
| 415 |
u_char * statP, oid * name, size_t name_len) |
| 416 |
{ |
| 417 |
static int tmpvar; |
| 418 |
struct snmpNotifyTable_data *StorageTmp = NULL; |
| 419 |
long value = *((long *) var_val); |
| 420 |
size_t newlen = name_len - snmpNotifyTable_offset; |
| 421 |
|
| 422 |
|
| 423 |
DEBUGMSGTL(("snmpNotifyTable", |
| 424 |
"write_snmpNotifyType entering action=%d... \n", action)); |
| 425 |
if (action != RESERVE1 && |
| 426 |
(StorageTmp = find_row_notifyTable(NULL, &name[snmpNotifyTable_offset], |
| 427 |
&newlen, 1, NULL, NULL)) == NULL) { |
| 428 |
if ((StorageTmp = StorageNew) == NULL) |
| 429 |
return SNMP_ERR_NOSUCHNAME; |
| 430 |
} |
| 431 |
|
| 432 |
switch (action) { |
| 433 |
case RESERVE1: |
| 434 |
if (var_val_type != ASN_INTEGER) { |
| 435 |
return SNMP_ERR_WRONGTYPE; |
| 436 |
} |
| 437 |
if (var_val_len != sizeof(long)) { |
| 438 |
return SNMP_ERR_WRONGLENGTH; |
| 439 |
} |
| 440 |
if (value < 1 || value > 2) { |
| 441 |
return SNMP_ERR_WRONGVALUE; |
| 442 |
} |
| 443 |
break; |
| 444 |
|
| 445 |
case ACTION: |
| 446 |
tmpvar = StorageTmp->snmpNotifyType; |
| 447 |
StorageTmp->snmpNotifyType = value; |
| 448 |
break; |
| 449 |
|
| 450 |
case UNDO: |
| 451 |
/* |
| 452 |
* Back out any changes made in the ACTION case |
| 453 |
*/ |
| 454 |
StorageTmp->snmpNotifyType = tmpvar; |
| 455 |
break; |
| 456 |
} |
| 457 |
|
| 458 |
return SNMP_ERR_NOERROR; |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
int |
| 464 |
write_snmpNotifyStorageType(int action, |
| 465 |
u_char * var_val, |
| 466 |
u_char var_val_type, |
| 467 |
size_t var_val_len, |
| 468 |
u_char * statP, oid * name, size_t name_len) |
| 469 |
{ |
| 470 |
static int tmpvar; |
| 471 |
long value = *((long *) var_val); |
| 472 |
struct snmpNotifyTable_data *StorageTmp = NULL; |
| 473 |
size_t newlen = name_len - snmpNotifyTable_offset; |
| 474 |
|
| 475 |
|
| 476 |
DEBUGMSGTL(("snmpNotifyTable", |
| 477 |
"write_snmpNotifyStorageType entering action=%d... \n", |
| 478 |
action)); |
| 479 |
if (action != RESERVE1 && |
| 480 |
(StorageTmp = find_row_notifyTable(NULL, &name[snmpNotifyTable_offset], |
| 481 |
&newlen, 1, NULL, NULL)) == NULL) { |
| 482 |
if ((StorageTmp = StorageNew) == NULL) |
| 483 |
return SNMP_ERR_NOSUCHNAME; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
switch (action) { |
| 488 |
case RESERVE1: |
| 489 |
if (var_val_type != ASN_INTEGER) { |
| 490 |
return SNMP_ERR_WRONGTYPE; |
| 491 |
} |
| 492 |
if (var_val_len != sizeof(long)) { |
| 493 |
return SNMP_ERR_WRONGLENGTH; |
| 494 |
} |
| 495 |
if (value != SNMP_STORAGE_OTHER && value != SNMP_STORAGE_VOLATILE |
| 496 |
&& value != SNMP_STORAGE_NONVOLATILE) { |
| 497 |
return SNMP_ERR_WRONGVALUE; |
| 498 |
} |
| 499 |
break; |
| 500 |
|
| 501 |
case ACTION: |
| 502 |
tmpvar = StorageTmp->snmpNotifyStorageType; |
| 503 |
StorageTmp->snmpNotifyStorageType = value; |
| 504 |
break; |
| 505 |
|
| 506 |
case UNDO: |
| 507 |
StorageTmp->snmpNotifyStorageType = tmpvar; |
| 508 |
break; |
| 509 |
} |
| 510 |
return SNMP_ERR_NOERROR; |
| 511 |
} |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
int |
| 516 |
write_snmpNotifyRowStatus(int action, |
| 517 |
u_char * var_val, |
| 518 |
u_char var_val_type, |
| 519 |
size_t var_val_len, |
| 520 |
u_char * statP, oid * name, size_t name_len) |
| 521 |
{ |
| 522 |
struct snmpNotifyTable_data *StorageTmp = NULL; |
| 523 |
static struct snmpNotifyTable_data *StorageDel; |
| 524 |
size_t newlen = name_len - snmpNotifyTable_offset; |
| 525 |
static int old_value; |
| 526 |
int set_value = *((long *) var_val); |
| 527 |
static netsnmp_variable_list *vars, *vp; |
| 528 |
|
| 529 |
DEBUGMSGTL(("snmpNotifyTable", |
| 530 |
"write_snmpNotifyRowStatus entering action=%d... \n", |
| 531 |
action)); |
| 532 |
StorageTmp = find_row_notifyTable(NULL, &name[snmpNotifyTable_offset], |
| 533 |
&newlen, 1, NULL, NULL); |
| 534 |
|
| 535 |
switch (action) { |
| 536 |
case RESERVE1: |
| 537 |
if (var_val_type != ASN_INTEGER || var_val == NULL) { |
| 538 |
return SNMP_ERR_WRONGTYPE; |
| 539 |
} |
| 540 |
if (var_val_len != sizeof(long)) { |
| 541 |
return SNMP_ERR_WRONGLENGTH; |
| 542 |
} |
| 543 |
if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) { |
| 544 |
return SNMP_ERR_WRONGVALUE; |
| 545 |
} |
| 546 |
if (StorageTmp == NULL) { |
| 547 |
/* |
| 548 |
* create the row now? |
| 549 |
*/ |
| 550 |
/* |
| 551 |
* ditch illegal values now |
| 552 |
*/ |
| 553 |
if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) { |
| 554 |
return SNMP_ERR_INCONSISTENTVALUE; |
| 555 |
} |
| 556 |
} else { |
| 557 |
/* |
| 558 |
* row exists. Check for a valid state change |
| 559 |
*/ |
| 560 |
if (set_value == RS_CREATEANDGO |
| 561 |
|| set_value == RS_CREATEANDWAIT) { |
| 562 |
/* |
| 563 |
* can't create a row that exists |
| 564 |
*/ |
| 565 |
return SNMP_ERR_INCONSISTENTVALUE; |
| 566 |
} |
| 567 |
/* |
| 568 |
* XXX: interaction with row storage type needed |
| 569 |
*/ |
| 570 |
} |
| 571 |
|
| 572 |
/* |
| 573 |
* memory reseveration, final preparation... |
| 574 |
*/ |
| 575 |
if (StorageTmp == NULL && |
| 576 |
(set_value == RS_CREATEANDGO |
| 577 |
|| set_value == RS_CREATEANDWAIT)) { |
| 578 |
/* |
| 579 |
* creation |
| 580 |
*/ |
| 581 |
vars = NULL; |
| 582 |
|
| 583 |
snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0); /* snmpNotifyName */ |
| 584 |
|
| 585 |
if (header_complex_parse_oid |
| 586 |
(& |
| 587 |
(name |
| 588 |
[sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) + |
| 589 |
2]), newlen, vars) != SNMPERR_SUCCESS) { |
| 590 |
/* |
| 591 |
* XXX: free, zero vars |
| 592 |
*/ |
| 593 |
snmp_free_var(vars); |
| 594 |
return SNMP_ERR_INCONSISTENTNAME; |
| 595 |
} |
| 596 |
vp = vars; |
| 597 |
|
| 598 |
|
| 599 |
StorageNew = SNMP_MALLOC_STRUCT(snmpNotifyTable_data); |
| 600 |
if (StorageNew == NULL) { |
| 601 |
return SNMP_ERR_RESOURCEUNAVAILABLE; |
| 602 |
} |
| 603 |
StorageNew->snmpNotifyName = (char*)calloc( 1, vp->val_len + 1 ); |
| 604 |
if (StorageNew->snmpNotifyName == NULL) { |
| 605 |
return SNMP_ERR_RESOURCEUNAVAILABLE; |
| 606 |
} |
| 607 |
memcpy(StorageNew->snmpNotifyName, vp->val.string, vp->val_len); |
| 608 |
StorageNew->snmpNotifyNameLen = vp->val_len; |
| 609 |
vp = vp->next_variable; |
| 610 |
|
| 611 |
/* |
| 612 |
* default values |
| 613 |
*/ |
| 614 |
StorageNew->snmpNotifyStorageType = ST_NONVOLATILE; |
| 615 |
StorageNew->snmpNotifyType = SNMPNOTIFYTYPE_TRAP; |
| 616 |
StorageNew->snmpNotifyTagLen = 0; |
| 617 |
StorageNew->snmpNotifyTag = (char *) calloc(1, sizeof(char)); |
| 618 |
if (StorageNew->snmpNotifyTag == NULL) { |
| 619 |
return SNMP_ERR_RESOURCEUNAVAILABLE; |
| 620 |
} |
| 621 |
|
| 622 |
StorageNew->snmpNotifyRowStatus = set_value; |
| 623 |
snmp_free_var(vars); |
| 624 |
} |
| 625 |
break; |
| 626 |
|
| 627 |
case RESERVE2: |
| 628 |
break; |
| 629 |
|
| 630 |
case FREE: |
| 631 |
if (StorageNew != NULL) { |
| 632 |
SNMP_FREE(StorageNew->snmpNotifyTag); |
| 633 |
SNMP_FREE(StorageNew->snmpNotifyName); |
| 634 |
free(StorageNew); |
| 635 |
StorageNew = NULL; |
| 636 |
} |
| 637 |
break; |
| 638 |
|
| 639 |
case ACTION: |
| 640 |
if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || |
| 641 |
set_value == RS_CREATEANDWAIT)) { |
| 642 |
/* |
| 643 |
* row creation, so add it |
| 644 |
*/ |
| 645 |
if (StorageNew != NULL) { |
| 646 |
snmpNotifyTable_add(StorageNew); |
| 647 |
} |
| 648 |
} else if (set_value != RS_DESTROY) { |
| 649 |
/* |
| 650 |
* set the flag? |
| 651 |
*/ |
| 652 |
if (StorageTmp == NULL) |
| 653 |
return SNMP_ERR_GENERR; /* should never ever get here */ |
| 654 |
|
| 655 |
old_value = StorageTmp->snmpNotifyRowStatus; |
| 656 |
StorageTmp->snmpNotifyRowStatus = *((long *) var_val); |
| 657 |
} else { |
| 658 |
/* |
| 659 |
* destroy... extract it for now |
| 660 |
*/ |
| 661 |
if (StorageTmp) |
| 662 |
StorageDel = snmpNotifyTable_extract(StorageTmp); |
| 663 |
} |
| 664 |
break; |
| 665 |
|
| 666 |
case UNDO: |
| 667 |
/* |
| 668 |
* Back out any changes made in the ACTION case |
| 669 |
*/ |
| 670 |
if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || |
| 671 |
set_value == RS_CREATEANDWAIT)) { |
| 672 |
/* |
| 673 |
* row creation, so remove it again |
| 674 |
*/ |
| 675 |
StorageDel = snmpNotifyTable_extract(StorageNew); |
| 676 |
/* |
| 677 |
* XXX: free it |
| 678 |
*/ |
| 679 |
} else if (StorageDel != NULL) { |
| 680 |
/* |
| 681 |
* row deletion, so add it again |
| 682 |
*/ |
| 683 |
snmpNotifyTable_add(StorageDel); |
| 684 |
} else if (set_value != RS_DESTROY) { |
| 685 |
if (StorageTmp) |
| 686 |
StorageTmp->snmpNotifyRowStatus = old_value; |
| 687 |
} |
| 688 |
break; |
| 689 |
|
| 690 |
case COMMIT: |
| 691 |
if (StorageDel != NULL) { |
| 692 |
snmpNotifyTable_dispose(StorageDel); |
| 693 |
StorageDel = NULL; |
| 694 |
} |
| 695 |
if (StorageTmp |
| 696 |
&& StorageTmp->snmpNotifyRowStatus == RS_CREATEANDGO) { |
| 697 |
StorageTmp->snmpNotifyRowStatus = RS_ACTIVE; |
| 698 |
StorageNew = NULL; |
| 699 |
} else if (StorageTmp && |
| 700 |
StorageTmp->snmpNotifyRowStatus == RS_CREATEANDWAIT) { |
| 701 |
StorageTmp->snmpNotifyRowStatus = RS_NOTINSERVICE; |
| 702 |
StorageNew = NULL; |
| 703 |
} |
| 704 |
snmp_store_needed(NULL); |
| 705 |
break; |
| 706 |
} |
| 707 |
return SNMP_ERR_NOERROR; |
| 708 |
} |
| 709 |
#endif /* !NETSNMP_NO_WRITE_SUPPORT */ |