📄 snmptargetparamsentry.c
字号:
/* TargetParamTable MIB This file was generated by mib2c and is intended for use as a mib module for the ucd-snmp snmpd agent. Edited by Michael Baer last changed 2/2/99.*/#include <config.h>#if HAVE_STRING_H#include <string.h>#else#include <strings.h>#endif#include <stdlib.h>#include <ctype.h>#if HAVE_WINSOCK_H#include <winsock.h>#endif#include "mibincl.h"#include "snmpTargetParamsEntry.h"#include "read_config.h"#include "callback.h"#define snmpTargetParamsOIDLen 11 /*This is base+column, i.e. everything but index*/oid snmpTargetParamsOID[snmpTargetParamsOIDLen] = {1,3,6,1,6,3,15,1,3,1,0};static struct targetParamTable_struct *aPTable=0;/* Utility routines *//* TargetParamTable_create creates and returns a pointer to a targetParamTable_struct with default values set */struct targetParamTable_struct *snmpTargetParamTable_create(void){ struct targetParamTable_struct *newEntry; newEntry = (struct targetParamTable_struct *) malloc(sizeof(struct targetParamTable_struct)); newEntry->paramName = 0; newEntry->mpModel = -1; newEntry->secModel = -1; newEntry->secName = 0; newEntry->secLevel = -1; newEntry->storageType = SNMP_STORAGE_NONVOLATILE; newEntry->rowStatus = SNMP_ROW_NONEXISTENT; newEntry->next = 0; return newEntry;}/* TargetParamTable_dispose frees the space allocated to a targetParamTable_struct */void snmpTargetParamTable_dispose( struct targetParamTable_struct *reaped){ free(reaped->paramName); free(reaped->secName); free(reaped);} /* snmpTargetParamTable_dispose *//* snmpTargetParamTable_addToList adds a targetParamTable_struct to a list passed in. The list is assumed to be in a sorted order, low to high and this procedure inserts a new struct in the proper location. Sorting uses OID values based on paramName. A new equal value overwrites a current one. */void snmpTargetParamTable_addToList( struct targetParamTable_struct *newEntry, struct targetParamTable_struct **listPtr){ static struct targetParamTable_struct *curr_struct, *prev_struct; int i; size_t newOIDLen = 0, currOIDLen = 0; oid newOID[128], currOID[128]; /* if the list is empty, add the new entry to the top */ if ( (prev_struct = curr_struct = *listPtr) == 0 ) { *listPtr = newEntry; return; } else { /* get the 'OID' value of the new entry */ newOIDLen = strlen(newEntry->paramName); for(i=0; i < (int)newOIDLen ;i++) { newOID[i] = newEntry->paramName[i]; } /* search through the list for an equal or greater OID value */ while (curr_struct != 0) { currOIDLen = strlen(curr_struct->paramName); for(i=0; i < (int)currOIDLen ;i++) { currOID[i] = curr_struct->paramName[i]; } i=snmp_oid_compare(newOID, newOIDLen, currOID, currOIDLen); if (i==0) { /* Exact match, overwrite with new struct */ newEntry->next = curr_struct->next; /* if curr_struct is the top of the list */ if (*listPtr == curr_struct) *listPtr = newEntry; else prev_struct->next = newEntry; snmpTargetParamTable_dispose(curr_struct); return; } else if (i < 0) { /* Found a greater OID, insert struct in front of it.*/ newEntry->next = curr_struct; /* if curr_struct is the top of the list */ if (*listPtr == curr_struct) *listPtr = newEntry; else prev_struct->next = newEntry; return; } prev_struct = curr_struct; curr_struct = curr_struct->next; } } /* if we're here, no larger OID was ever found, insert on end of list */ prev_struct->next = newEntry;} /* snmpTargeParamTable_addToList *//* snmpTargetParamTable_remFromList removes a targetParamTable_struct from the list passed in */void snmpTargetParamTable_remFromList( struct targetParamTable_struct *oldEntry, struct targetParamTable_struct **listPtr){ struct targetParamTable_struct *tptr; if ( (tptr = *listPtr) == 0 ) return; else if (tptr == oldEntry) { *listPtr = (*listPtr)->next; snmpTargetParamTable_dispose(tptr); return; } else { while (tptr->next != 0) { if (tptr->next == oldEntry) { tptr->next = tptr->next->next; snmpTargetParamTable_dispose(oldEntry); return; } tptr = tptr->next; } } } /* snmpTargetParamTable_remFromList *//* lookup OID in the link list of Table Entries */struct targetParamTable_struct *search_snmpTargetParamsTable( oid *baseName, size_t baseNameLen, oid *name, size_t *length, int exact){ static struct targetParamTable_struct *temp_struct; int i; size_t myOIDLen = 0; oid newNum[128]; /* lookup entry in p / * Get Current MIB ID */ memcpy(newNum, baseName, baseNameLen*sizeof(oid)); for( temp_struct = aPTable; temp_struct != 0; temp_struct = temp_struct->next) { for(i=0; i < (int)strlen(temp_struct->paramName) ;i++) { newNum[baseNameLen+i] = temp_struct->paramName[i]; } myOIDLen = baseNameLen+strlen(temp_struct->paramName); i=snmp_oid_compare(name, *length, newNum, myOIDLen); /* Assumes that the linked list sorted by OID, low to high */ if ( (i==0 && exact!=0) || (i<0 && exact==0) ) { if (exact == 0) { memcpy(name, newNum, myOIDLen*sizeof(oid)); *length = myOIDLen; } return temp_struct; } } return(0);} /* search_snmpTargetParamsTable *//* snmpTargetParams_rowStatusCheck is boolean funciton that checks the status of a row's values in order to determine whether the row should be notReady or notInService */int snmpTargetParams_rowStatusCheck( struct targetParamTable_struct *entry){ if ( (entry->mpModel < 0) || (entry->secModel < 0) || (entry->secLevel < 0) || (entry->secName == 0) ) return 0; else return 1;} /* snmtpTargetParamTable_rowStatusCheck *//* initialization routines *//* this variable defines function callbacks and type return information for the snmpTargetAddrEntry mib */struct variable2 snmpTargetParamsEntry_variables[] = { { SNMPTARGETPARAMSMPMODEL, ASN_INTEGER, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSMPMODELCOLUMN } }, { SNMPTARGETPARAMSSECURITYMODEL, ASN_INTEGER, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSSECURITYMODELCOLUMN } }, { SNMPTARGETPARAMSSECURITYNAME, ASN_OCTET_STR, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSSECURITYNAMECOLUMN } }, { SNMPTARGETPARAMSSECURITYLEVEL, ASN_INTEGER, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSSECURITYLEVELCOLUMN } }, { SNMPTARGETPARAMSSTORAGETYPE, ASN_INTEGER, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSSTORAGETYPECOLUMN } }, { SNMPTARGETPARAMSROWSTATUS, ASN_INTEGER, RWRITE, var_snmpTargetParamsEntry, 1, { SNMPTARGETPARAMSROWSTATUSCOLUMN } }};/* now load this mib into the agents mib table */oid snmpTargetParamsEntry_variables_oid[] = { 1,3,6,1,6,3,12,1,3,1 };void init_snmpTargetParamsEntry(void){ aPTable = 0; REGISTER_MIB("target/snmpTargetParamsEntry", snmpTargetParamsEntry_variables, variable2, snmpTargetParamsEntry_variables_oid); snmpd_register_config_handler("targetParams", snmpd_parse_config_targetParams,0,""); /* we need to be called back later */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, store_snmpTargetParamsEntry, NULL);} /* init_snmpTargetParmsEntry */int snmpTargetParams_addParamName( struct targetParamTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: no param name in config string\n")); return(0); } else { len = strlen(cptr); /* spec check for string 1-32 */ if (len < 1 || len > 32) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: param name out of range in config string\n")); return(0); } entry->paramName = (char *)malloc(len + 1); strncpy(entry->paramName, cptr, len); entry->paramName[len] = '\0'; } return(1);} int snmpTargetParams_addMPModel( struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: no mp model in config string\n")); return(0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargeParamsEntry: mp model is not digit in config string\n")); return(0); } /* spec check MP Model >= 0 */ else if ( (entry->mpModel = (int)strtol(cptr, (char **)NULL, 0)) < 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargeParamsEntry: mp model out of range in config string\n")); return(0); } return(1);} /* snmpTargetParams_addMPModel */ int snmpTargetParams_addSecModel( struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: no sec model in config string\n")); return(0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargeParamsEntry: security model is not digit in config string\n")); return(0); } /* spec check Sec. Model > 0 */ else if ( (entry->secModel = (int)strtol(cptr, (char **)NULL, 0)) <= 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: security model out of range in config string\n")); return(0); } return(1);} /* snmpTargetParams_addSecModel */int snmpTargetParams_addSecName( struct targetParamTable_struct *entry, char *cptr){ size_t len; if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: no security name in config string\n")); return(0); } else { len = strlen(cptr); entry->secName = (char *)malloc(len + 1); strncpy(entry->secName, cptr, len); entry->secName[len] = '\0'; } return(1);} /* snmpTargetParams_addSecName */int snmpTargetParams_addSecLevel( struct targetParamTable_struct *entry, char *cptr){ if (cptr == 0) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargetParamsEntry: no security level in config string\n")); return(0); } else if (!(isdigit(*cptr))) { DEBUGMSGTL(("snmpTargetParamsEntry","ERROR snmpTargeParamsEntry: security level is not digit in config string\n")); return(0); } /* no spec range check, but noAuthNoPriv is 1 so... */ else if ( (entry->secLevel = (int)strtol(cptr, (char **)NULL, 0)) <= 0 ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -