📄 snmpnotifytable.c
字号:
int exact, size_t *var_len, WriteMethod **write_method){struct snmpNotifyTable_data *StorageTmp = NULL; DEBUGMSGTL(("snmpNotifyTable", "var_snmpNotifyTable: Entering... \n")); /* * this assumes you have registered all your data properly */ if ((StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *)snmpNotifyTableStorage, vp,name,length,exact, var_len,write_method)) == NULL) { DEBUGMSGTL(("snmpNotifyTable", "no row: magic=%d... \n", vp->magic)); if (vp->magic == SNMPNOTIFYROWSTATUS) { DEBUGMSGTL(("snmpNotifyTable", "var_snmpNotifyTable: create?... \n")); *write_method = write_snmpNotifyRowStatus; } return NULL; } /* * this is where we do the value assignments for the mib results. */ switch(vp->magic) { case SNMPNOTIFYTAG: *write_method = write_snmpNotifyTag; *var_len = StorageTmp->snmpNotifyTagLen; return (u_char *) StorageTmp->snmpNotifyTag; case SNMPNOTIFYTYPE: *write_method = write_snmpNotifyType; *var_len = sizeof(StorageTmp->snmpNotifyType); return (u_char *) &StorageTmp->snmpNotifyType; case SNMPNOTIFYSTORAGETYPE: *write_method = write_snmpNotifyStorageType; *var_len = sizeof(StorageTmp->snmpNotifyStorageType); return (u_char *) &StorageTmp->snmpNotifyStorageType; case SNMPNOTIFYROWSTATUS: *write_method = write_snmpNotifyRowStatus; *var_len = sizeof(StorageTmp->snmpNotifyRowStatus); return (u_char *) &StorageTmp->snmpNotifyRowStatus; default: ERROR_MSG(""); } return NULL;}static int is_delim(const char c) { return (c == 0x020 || c == 0x09 || c == 0x0d || c == 0x0b);}intsnmpTagValid(const char *tag, const size_t tagLen){ size_t i = 0; for (i = 0; i < tagLen; i++) { if (is_delim(tag[i])) { /* Delimeters aren't allowed. */ return 0; } } return 1;}intwrite_snmpNotifyTag(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ static char *tmpvar; struct snmpNotifyTable_data *StorageTmp = NULL; static size_t tmplen; size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1); DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyTag entering action=%d... \n", action)); if ((StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *)snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) { return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */ } switch (action) { case RESERVE1: if (var_val_type != ASN_OCTET_STR) { return SNMP_ERR_WRONGTYPE; } if (var_val_len < 0 || var_val_len > 255) { return SNMP_ERR_WRONGLENGTH; } if (!snmpTagValid(var_val, var_val_len)) { return SNMP_ERR_WRONGVALUE; } break; case RESERVE2: /* memory reseveration, final preparation... */ break; case FREE: /* Release any resources that have been allocated */ break; case ACTION: tmpvar = StorageTmp->snmpNotifyTag; tmplen = StorageTmp->snmpNotifyTagLen; memdup((u_char **) &StorageTmp->snmpNotifyTag, var_val, var_val_len); StorageTmp->snmpNotifyTagLen = var_val_len; break; case UNDO: /* Back out any changes made in the ACTION case */ SNMP_FREE(StorageTmp->snmpNotifyTag); StorageTmp->snmpNotifyTag = tmpvar; StorageTmp->snmpNotifyTagLen = tmplen; tmpvar = NULL; break; case COMMIT: /* Things are working well, so it's now safe to make the change permanently. Make sure that anything done here can't fail! */ SNMP_FREE(tmpvar); break; } return SNMP_ERR_NOERROR;}intwrite_snmpNotifyType(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ static int tmpvar; struct snmpNotifyTable_data *StorageTmp = NULL; long value = *((long *)var_val); size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1); DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyType entering action=%d... \n", action)); if ((StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *)snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) { return SNMP_ERR_NOSUCHNAME; } switch (action) { case RESERVE1: if (var_val_type != ASN_INTEGER){ return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long)) { return SNMP_ERR_WRONGLENGTH; } if (value < 1 || value > 2) { return SNMP_ERR_WRONGVALUE; } break; case ACTION: tmpvar = StorageTmp->snmpNotifyType; StorageTmp->snmpNotifyType = value; break; case UNDO: /* Back out any changes made in the ACTION case */ StorageTmp->snmpNotifyType = tmpvar; break; } return SNMP_ERR_NOERROR;}intwrite_snmpNotifyStorageType(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ static int tmpvar; long value = *((long *)var_val); struct snmpNotifyTable_data *StorageTmp = NULL; size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1); DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyStorageType entering action=%d... \n", action)); if ((StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *)snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL)) == NULL) { return SNMP_ERR_NOSUCHNAME; } switch (action) { case RESERVE1: if (var_val_type != ASN_INTEGER) { return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long)) { return SNMP_ERR_WRONGLENGTH; } if (value != SNMP_STORAGE_OTHER && value != SNMP_STORAGE_VOLATILE && value != SNMP_STORAGE_NONVOLATILE) { return SNMP_ERR_WRONGVALUE; } break; case ACTION: tmpvar = StorageTmp->snmpNotifyStorageType; StorageTmp->snmpNotifyStorageType = value; break; case UNDO: StorageTmp->snmpNotifyStorageType = tmpvar; break; } return SNMP_ERR_NOERROR;}intwrite_snmpNotifyRowStatus(int action, u_char *var_val, u_char var_val_type, size_t var_val_len, u_char *statP, oid *name, size_t name_len){ struct snmpNotifyTable_data *StorageTmp = NULL; static struct snmpNotifyTable_data *StorageNew, *StorageDel; size_t newlen=name_len - (sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1); static int old_value; int set_value = *((long *) var_val); static struct variable_list *vars, *vp; struct header_complex_index *hciptr; DEBUGMSGTL(("snmpNotifyTable", "write_snmpNotifyRowStatus entering action=%d... \n", action)); StorageTmp = (struct snmpNotifyTable_data *) header_complex((struct header_complex_index *)snmpNotifyTableStorage, NULL, &name[sizeof(snmpNotifyTable_variables_oid)/sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL); switch (action) { case RESERVE1: if (var_val_type != ASN_INTEGER || var_val == NULL) { return SNMP_ERR_WRONGTYPE; } if (var_val_len != sizeof(long)) { return SNMP_ERR_WRONGLENGTH; } if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) { return SNMP_ERR_WRONGVALUE; } if (StorageTmp == NULL) { /* create the row now? */ /* ditch illegal values now */ if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) { return SNMP_ERR_INCONSISTENTVALUE; } } else { /* row exists. Check for a valid state change */ if (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT) { /* can't create a row that exists */ return SNMP_ERR_INCONSISTENTVALUE; } /* XXX: interaction with row storage type needed */ } break; case RESERVE2: /* memory reseveration, final preparation... */ if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT)) { /* creation */ vars = NULL; snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0); /* snmpNotifyName */ if (header_complex_parse_oid(&(name[sizeof(snmpNotifyTable_variables_oid)/sizeof(oid)+2]), newlen, vars) != SNMPERR_SUCCESS) { /* XXX: free, zero vars */ snmp_free_var(vars); return SNMP_ERR_INCONSISTENTNAME; } vp = vars; StorageNew = SNMP_MALLOC_STRUCT(snmpNotifyTable_data); if (StorageNew == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } memdup((u_char **) &(StorageNew->snmpNotifyName), vp->val.string, vp->val_len); if (StorageNew->snmpNotifyName == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } StorageNew->snmpNotifyNameLen = vp->val_len; vp = vp->next_variable; /* default values */ StorageNew->snmpNotifyStorageType = ST_NONVOLATILE; StorageNew->snmpNotifyType = SNMPNOTIFYTYPE_TRAP; StorageNew->snmpNotifyTagLen = 0; StorageNew->snmpNotifyTag = (char *)calloc(sizeof(char), 1); if (StorageNew->snmpNotifyTag == NULL) { return SNMP_ERR_RESOURCEUNAVAILABLE; } StorageNew->snmpNotifyRowStatus = set_value; snmp_free_var(vars); } break; case FREE: if (StorageNew != NULL) { SNMP_FREE(StorageNew->snmpNotifyTag); SNMP_FREE(StorageNew->snmpNotifyName); free(StorageNew); StorageNew = NULL; } break; case ACTION: if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT)) { /* row creation, so add it */ if (StorageNew != NULL) { snmpNotifyTable_add(StorageNew); } } else if (set_value != RS_DESTROY) { /* set the flag? */ old_value = StorageTmp->snmpNotifyRowStatus; StorageTmp->snmpNotifyRowStatus = *((long *) var_val); } else { /* destroy... extract it for now */ if (StorageTmp) { hciptr = header_complex_find_entry(snmpNotifyTableStorage, StorageTmp); StorageDel = (struct snmpNotifyTable_data *) header_complex_extract_entry((struct header_complex_index **)&snmpNotifyTableStorage, hciptr); } } break; case UNDO: /* Back out any changes made in the ACTION case */ if (StorageTmp == NULL && (set_value == RS_CREATEANDGO || set_value == RS_CREATEANDWAIT)) { /* row creation, so remove it again */ hciptr = header_complex_find_entry(snmpNotifyTableStorage, StorageNew); StorageDel = (struct snmpNotifyTable_data *) header_complex_extract_entry((struct header_complex_index **)&snmpNotifyTableStorage, hciptr); /* XXX: free it */ } else if (StorageDel != NULL) { /* row deletion, so add it again */ snmpNotifyTable_add(StorageDel); } else if (set_value != RS_DESTROY) { StorageTmp->snmpNotifyRowStatus = old_value; } break; case COMMIT: if (StorageDel != NULL) { SNMP_FREE(StorageDel->snmpNotifyTag); SNMP_FREE(StorageDel->snmpNotifyName); free(StorageDel); StorageDel = NULL; } if (StorageTmp && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDGO) { StorageTmp->snmpNotifyRowStatus = RS_ACTIVE; StorageNew = NULL; } else if (StorageTmp && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDWAIT) { StorageTmp->snmpNotifyRowStatus = RS_NOTINSERVICE; StorageNew = NULL; } break; } return SNMP_ERR_NOERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -