snmpTargetAddrEntry.c
资源名称:snmp.src.rar [点击查看]
上传用户:cxs890
上传日期:2021-05-22
资源大小:347k
文件大小:48k
源码类别:
SNMP编程
开发平台:
C/C++
- /* snmpTargetAddrEntry 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 <ip/socket.h>
- #endif
- #include "mibincl.h"
- #include "snmpTargetAddrEntry.h"
- #include "read_config.h"
- #include "callback.h"
- #include "util_funcs.h"
- #define snmpTargetAddrOIDLen 11 /*This is base+column,
- i.e. everything but index*/
- oid snmpTargetAddrOID[snmpTargetAddrOIDLen] = {1,3,6,1,6,3,12,1,2,1,0};
- static struct targetAddrTable_struct *aAddrTable=0;
- static unsigned int snmpTargetSpinLock = 420420;
- /* Utility routines */
- extern char *snmp_ntoa (long );
- extern char *strdup (const char*);
- /* TargetAddrTable_create creates and returns a pointer
- to a targetAddrTable_struct with default values set */
- /* Convert Internet address in ascii dotted-decimal format (44.0.0.1) to
- * binary IP address
- */
- int32
- aton(char *s)
- {
- int32 n;
- register int i;
- n = 0;
- if(s == NULLCHAR)
- return 0;
- for(i=24;i>=0;i -= 8){
- /* Skip any leading stuff (e.g., spaces, '[') */
- while(*s != ' ' && !isdigit(*s))
- s++;
- if(*s == ' ')
- break;
- n |= (int32)atoi(s) << i;
- if((s = strchr(s,'.')) == NULLCHAR)
- break;
- s++;
- }
- return n;
- }
- struct targetAddrTable_struct
- *snmpTargetAddrTable_create(void)
- {
- struct targetAddrTable_struct *newEntry;
- newEntry = (struct targetAddrTable_struct *)
- malloc(sizeof(struct targetAddrTable_struct));
- if (newEntry) {
- newEntry->name = 0;
- newEntry->tDomainLen = 0;
- newEntry->tAddress = 0;
- newEntry->timeout = 1500;
- newEntry->retryCount = 3;
- newEntry->tagList = strdup("");
- if (newEntry->tagList == NULL)
- {
- free (newEntry);
- return NULL;
- }
- newEntry->params = 0;
- newEntry->spinLock = 0;
- newEntry->storageType = SNMP_STORAGE_NONVOLATILE;
- newEntry->rowStatus = SNMP_ROW_NONEXISTENT;
- newEntry->next = 0;
- }
- return newEntry;
- } /* snmpTargetAddrTable_create */
- /* TargetAddrTable_dispose frees the space allocated to a
- targetAddrTable_struct */
- void snmpTargetAddrTable_dispose(struct targetAddrTable_struct *reaped)
- {
- free(reaped->name);
- free(reaped->tAddress);
- free(reaped->tagList);
- free(reaped->params);
- free(reaped);
- } /* snmpTargetAddrTable_dispose */
- /* snmpTargetAddrTable_addToList adds a targetAddrTable_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 name. A new equal value
- overwrites a current one. */
- void snmpTargetAddrTable_addToList(
- struct targetAddrTable_struct *newEntry,
- struct targetAddrTable_struct **listPtr)
- {
- static struct targetAddrTable_struct *curr_struct, *prev_struct;
- int i;
- int newOIDLen, currOIDLen;
- 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->name);
- for(i=0; i < (int)newOIDLen ;i++) {
- newOID[i] = newEntry->name[i];
- }
- /* search through the list for an equal or greater OID value */
- while (curr_struct != 0) {
- currOIDLen = strlen(curr_struct->name);
- for(i=0; i < (int)currOIDLen ;i++) {
- currOID[i] = curr_struct->name[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;
- snmpTargetAddrTable_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;
- } /* snmpTargeAddrTable_addToList */
- /* snmpTargetAddrTable_remFromList removes a targetAddrTable_struct
- from the list passed in */
- void snmpTargetAddrTable_remFromList(
- struct targetAddrTable_struct *oldEntry,
- struct targetAddrTable_struct **listPtr)
- {
- struct targetAddrTable_struct *tptr;
- if ( (tptr = *listPtr) == 0 ) return;
- else if (tptr == oldEntry) {
- *listPtr = (*listPtr)->next;
- snmpTargetAddrTable_dispose(tptr);
- return;
- }
- else {
- while (tptr->next != 0) {
- if (tptr->next == oldEntry) {
- tptr->next = tptr->next->next;
- snmpTargetAddrTable_dispose(oldEntry);
- return;
- }
- tptr = tptr->next;
- }
- }
- } /* snmpTargetAddrTable_remFromList */
- /* lookup OID in the link list of Addr Table Entries */
- struct targetAddrTable_struct *
- search_snmpTargetAddrTable(
- oid *baseName,
- int baseNameLen,
- oid *name,
- int *length,
- int exact)
- {
- static struct targetAddrTable_struct *temp_struct;
- int i;
- int myOIDLen;
- oid newNum[128];
- /* lookup entry in addrTable linked list, Get Current MIB ID */
- memcpy(newNum, baseName, baseNameLen*sizeof(oid));
- for( temp_struct = aAddrTable; temp_struct != 0; temp_struct = temp_struct->next) {
- for(i=0; i < (int)strlen(temp_struct->name) ;i++) {
- newNum[baseNameLen+i] = temp_struct->name[i];
- }
- myOIDLen = baseNameLen+strlen(temp_struct->name);
- 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_snmpTargetAddrTable */
- /* snmpTargetAddr_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 snmpTargetAddr_rowStatusCheck(struct targetAddrTable_struct *entry)
- {
- if ( (entry->tDomainLen == 0) || (entry->tAddress == 0) ||
- (entry->params == 0) )
- return 0;
- else
- return 1;
- } /* snmtpTargetAddrTable_rowStatusCheck */
- /* Init routines */
- /* this variable defines function callbacks and type return information
- for the snmpTargetAddrEntry mib */
- struct variable2 snmpTargetAddrEntry_variables[] = {
- { SNMPTARGETADDRTDOMAIN, ASN_OBJECT_ID , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTDOMAINCOLUMN } },
- { SNMPTARGETADDRTADDRESS, ASN_OCTET_STR , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTADDRESSCOLUMN } },
- { SNMPTARGETADDRTIMEOUT, ASN_INTEGER , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRTIMEOUTCOLUMN } },
- { SNMPTARGETADDRRETRYCOUNT, ASN_INTEGER , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRRETRYCOUNTCOLUMN } },
- { SNMPTARGETADDRTAGLIST, ASN_OCTET_STR , RWRITE,
- var_snmpTargetAddrEntry, 1, {SNMPTARGETADDRTAGLISTCOLUMN } },
- { SNMPTARGETADDRPARAMS, ASN_OCTET_STR , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRPARAMSCOLUMN } },
- { SNMPTARGETADDRSTORAGETYPE, ASN_INTEGER , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRSTORAGETYPECOLUMN } },
- { SNMPTARGETADDRROWSTATUS, ASN_INTEGER , RWRITE,
- var_snmpTargetAddrEntry, 1, { SNMPTARGETADDRROWSTATUSCOLUMN } },
- };
- struct variable2 snmpTargetSpinLock_variables[] = {
- {SNMPTARGETSPINLOCK, ASN_INTEGER, RWRITE, var_snmpTargetSpinLock, 1, {1}},
- };
- /*
- struct variable2 snmpTargetContexts_variables[] = {
- {SNMPUNAVAILABLECONTEXTS , ASN_INTEGER, RWRITE, var_snmpTargetContexts, 1, {4}},
- {SNMPUNKNOWNCONTEXTS , ASN_INTEGER, RWRITE, var_snmpTargetContexts, 1, {5}},
- };
- */
- /* now load this mib into the agents mib table */
- oid snmpTargetAddrEntry_variables_oid[] = { 1,3,6,1,6,3,12,1,2,1 };
- oid snmpTargetSpinLock_variables_oid[] = {1,3,6,1,6,3,12,1};
- static oid snmpTargetAddrEntry_TDomain_oid[] = {1,3,6,1,6,1,1};
- static int snmpTargetAddrEntry_TDomain_oid_len = 7;
- void init_snmpTargetAddrEntry(void) {
- aAddrTable = 0;
- DEBUGMSGTL(("snmpTargetAddrEntry","initn"));
- REGISTER_MIB("target/snmpTargetAddrEntry", snmpTargetAddrEntry_variables,
- variable2, snmpTargetAddrEntry_variables_oid);
- REGISTER_MIB("target/snmpTargetSpinLock", snmpTargetSpinLock_variables,
- variable2, snmpTargetSpinLock_variables_oid);
- snmpd_register_config_handler("targetAddr", snmpd_parse_config_targetAddr,
- 0, "");
- /* we need to be called back later */
- snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
- store_snmpTargetAddrEntry, NULL);
- } /* init_snmpTargetAddrEntry */
- int snmpTargetAddr_addName(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- int len;
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no name in config stringn"));
- return(0);
- }
- else {
- len = strlen(cptr);
- /* spec check for string 1-32 */
- if (len < 1 || len > 32) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: name out of range in config stringn"));
- return(0);
- }
- entry->name = (char *)malloc(len + 1);
- if (entry->name == NULL)
- return 0;
- strncpy(entry->name, cptr, len);
- entry->name[len] = ' ';
- }
- return(1);
- } /* addName */
- int snmpTargetAddr_addTDomain(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- int len=128;
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tDomain in config stringn"));
- return(0);
- }
- if ( !read_objid(cptr, entry->tDomain, (size_t *)&len) ) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tDomain unreadable in config stringn"));
- return(0);
- }
- /* spec check for oid 1-128 */
- if (len < 1 || len > 128) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tDomain out of range in config stringn"));
- return(0);
- }
- entry->tDomainLen = len;
- return(1);
- } /* snmpTargetAddr_addTDomain */
- int snmpTargetAddr_addTAddress(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- int len;
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tAddress in config stringn"));
- return(0);
- }
- else {
- len = strlen(cptr);
- /* spec check for string 1-32 */
- /* if (len < 1 || len > 32) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: name out of range in config stringn"));
- return(0);
- } */
- free(entry->tAddress);
- entry->tAddress = (char *)malloc(len + 1);
- if (entry->tAddress == NULL)
- return 0;
- strncpy(entry->tAddress, cptr, len);
- entry->tAddress[len] = ' ';
- }
- return(1);
- } /* snmpTargetAddr_addTAddress */
- int snmpTargetAddr_addTimeout(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetParamsEntry: no Timeout in config stringn"));
- return(0);
- }
- else if (!(isdigit(*cptr))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Timeout is not a digit in config stringn"));
- return(0);
- }
- /* check Timeout >= 0 */
- else if ( (entry->timeout = (int)strtol(cptr, (char **)NULL, 0)) < 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Timeout out of range in config stringn"));
- return(0);
- }
- return(1);
- } /* snmpTargetAddr_addTimeout */
- int snmpTargetAddr_addRetryCount(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetParamsEntry: no Retry Count in config stringn"));
- return(0);
- }
- else if (!(isdigit(*cptr))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Retry Count is not a digit in config stringn"));
- return(0);
- }
- /* spec check 0..255 */
- else {
- entry->retryCount = (int)strtol(cptr, (char **)NULL, 0);
- if ( (entry->retryCount < 0) ||
- (entry->retryCount > 255) ) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargeParamsEntry: Retry Count is out of range in config stringn"));
- return(0);
- }
- }
- return(1);
- } /* snmpTargetAddr_addRetryCount */
- int snmpTargetAddr_addTagList(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- int len;
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no tag list in config stringn"));
- return(0);
- }
- else {
- len = strlen(cptr);
- /* spec check for string 0-255 */
- if (len < 0 || len > 255) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: tag list out of range in config stringn"));
- return(0);
- }
- free(entry->tagList);
- entry->tagList = (char *)malloc(len + 1);
- if (entry->tagList == NULL)
- return 0;
- strncpy(entry->tagList, cptr, len);
- entry->tagList[len] = ' ';
- }
- return(1);
- } /* snmpTargetAddr_addTagList */
- int snmpTargetAddr_addParams(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- int len;
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no params in config stringn"));
- return(0);
- }
- else {
- len = strlen(cptr);
- /* spec check for string 1-32 */
- if (len < 1 || len > 32) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: params out of range in config stringn"));
- return(0);
- }
- entry->params = (char *)malloc(len + 1);
- if (entry->params == NULL)
- return 0;
- strncpy(entry->params, cptr, len);
- entry->params[len] = ' ';
- }
- return(1);
- } /* snmpTargetAddr_addParams */
- int snmpTargetAddr_addStorageType(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- char buff[1024];
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no storage type in config stringn"));
- return(0);
- }
- else if (!(isdigit(*cptr))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: storage type is not a digit in config stringn"));
- return(0);
- }
- /* check that storage type is a possible value */
- else if ( ((entry->storageType = (int)strtol(cptr, (char **)NULL, 0))
- != SNMP_STORAGE_OTHER) &&
- (entry->storageType != SNMP_STORAGE_VOLATILE) &&
- (entry->storageType != SNMP_STORAGE_NONVOLATILE) &&
- (entry->storageType != SNMP_STORAGE_PERMANENT) &&
- (entry->storageType != SNMP_STORAGE_READONLY) ) {
- sprintf(buff,"ERROR snmpTargetAddrEntry: storage type not a valid value of other(%d), volatile(%d), nonvolatile(%d), permanent(%d), or readonly(%d) in config string.n", SNMP_STORAGE_OTHER, SNMP_STORAGE_VOLATILE, SNMP_STORAGE_NONVOLATILE, SNMP_STORAGE_PERMANENT, SNMP_STORAGE_READONLY);
- DEBUGMSGTL(("snmpTargetAddrEntry", buff));
- return(0);
- }
- return(1);
- } /* snmpTargetAddr_addStorageType */
- int snmpTargetAddr_addRowStatus(
- struct targetAddrTable_struct *entry,
- char *cptr)
- {
- char buff[1024];
- if (cptr == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: no Row Status in config stringn"));
- return(0);
- }
- else if (!(isdigit(*cptr))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","ERROR snmpTargetAddrEntry: Row Status is not a digit in config stringn"));
- return(0);
- }
- /* check that row status is a valid value */
- else if ( ((entry->rowStatus = (int)strtol(cptr, (char **)NULL, 0))
- != SNMP_ROW_ACTIVE) &&
- (entry->rowStatus != SNMP_ROW_NOTINSERVICE) &&
- (entry->rowStatus != SNMP_ROW_NOTREADY) ) {
- sprintf(buff, "ERROR snmpTargetAddrEntry: Row Status is not a valid value of active(%d), notinservice(%d), or notready(%d) in config string.n", SNMP_ROW_ACTIVE, SNMP_ROW_NOTINSERVICE, SNMP_ROW_NOTREADY);
- DEBUGMSGTL(("snmpTargetAddrEntry", buff));
- return(0);
- }
- return(1);
- } /* snmpTargetAddr_addRowStatus */
- /**************************************************
- *Delete a target address entry
- *IN: host_name -- ip address in string format
- *IN: community -- community string
- * --sxf 2k-12-26
- *******************************************************/
- void snmp_delete_targetAddr (char *host_name, char *community)
- {
- struct targetAddrTable_struct *temp_struct, *temp_struct_next;
- char buf[256];
- if (host_name == NULL || community == NULL)
- {
- snmp_trace("SNMP In add target entry: community or host_name not provided!n");
- return;
- }
- if (strlen (community) + strlen (host_name) > 200)
- {
- snmp_trace("SNMP In add target entry: community or host_name length to long!n");
- return;
- }
- sprintf (buf, "traphost.%s.%s",community,host_name);
- for( temp_struct = aAddrTable; temp_struct != NULL; )
- {
- temp_struct_next = temp_struct->next;
- if (strcmp (buf,temp_struct->name) == 0)
- {
- snmpTargetAddrTable_remFromList(temp_struct, &aAddrTable);
- }
- temp_struct = temp_struct_next;
- }
- }
- /*
- *Create target address entry. Called when create a new host to send trap.
- *IN: host_name -- ip address in string format
- *IN: community -- community of trapd application in manager entity
- *IN: timeout -- default value is 1500 (defined in target mib)
- *IN: retry -- default value is 3 (defined in target mib)
- * --sxf 2k-12-26
- */
- void snmp_add_targetAddr (char *host_name, char *community, int timeout, int retry)
- {
- struct targetAddrTable_struct *newEntry;
- char buf[256];
- long ipAddr;
- if (host_name == NULL || community == NULL)
- {
- snmp_trace("SNMP In add target entry: community or host_name not provided!n");
- return;
- }
- if (strlen (community) + strlen (host_name) > 200)
- {
- snmp_trace("SNMP In add target entry: community or host_name length to long!n");
- return;
- }
- snmp_delete_targetAddr (host_name, community);
- newEntry = snmpTargetAddrTable_create();
- if (newEntry == NULL)
- return;
- sprintf (buf, "traphost.%s.%s",community,host_name);
- newEntry->name = strdup (buf);
- memcpy (newEntry->tDomain, snmpTargetAddrEntry_TDomain_oid,snmpTargetAddrEntry_TDomain_oid_len*sizeof(oid));
- newEntry->tDomainLen = snmpTargetAddrEntry_TDomain_oid_len;
- newEntry->tAddress = (char *)malloc (7*sizeof(char));
- /*ip addr*/
- ipAddr = aton(host_name);
- if (newEntry->tAddress != NULL)
- {
- memcpy (newEntry->tAddress, &ipAddr, 4);
- /*udp port*/
- (newEntry->tAddress)[4] = 0;
- (newEntry->tAddress)[5] = 0xA2;
- (newEntry->tAddress)[6] = ' ';
- }
- newEntry->timeout = timeout;
- newEntry->retryCount = retry;
- newEntry->tagList = strdup ("trap");
- newEntry->params = strdup (buf);
- newEntry->storageType = SNMP_STORAGE_NONVOLATILE;
- newEntry->rowStatus = SNMP_ROW_ACTIVE;
- if (newEntry->name == NULL||newEntry->tAddress == NULL
- ||newEntry->tagList == NULL||newEntry->params == NULL)
- {
- snmp_trace("SNMP In add target entry:Insufficient memoryn");
- if (newEntry->name)
- free(newEntry->name);
- if (newEntry->tAddress)
- free (newEntry->tAddress);
- if (newEntry->tagList)
- free (newEntry->tagList);
- if (newEntry->params)
- free (newEntry->params);
- free (newEntry);
- return;
- }
- snmpTargetAddrTable_addToList(newEntry, &aAddrTable);
- }
- void snmpd_parse_config_targetAddr(const char *token, char *char_ptr)
- {
- char *cptr = char_ptr, buff[1024];
- struct targetAddrTable_struct *newEntry;
- int i;
- newEntry = snmpTargetAddrTable_create();
- if (newEntry == NULL)
- return;
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addName(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addTDomain(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addTAddress(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addTimeout(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addRetryCount(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addTagList(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addParams(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addStorageType(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- cptr = copy_word(cptr, buff);
- if (snmpTargetAddr_addRowStatus(newEntry, buff) == 0) {
- snmpTargetAddrTable_dispose(newEntry);
- return;
- }
- sprintf(buff, "snmp_parse_config_targetAddr, read: %sn",
- newEntry->name);
- for(i=0;i<newEntry->tDomainLen;i++) {
- sprintf(&buff[strlen(buff)], ".%d", (int)newEntry->tDomain[i]);
- }
- sprintf(&buff[strlen(buff)], " %s %d %d %s %s %d %dn",
- snmp_ntoa(*((long*)(newEntry->tAddress))), newEntry->timeout, newEntry->retryCount,
- newEntry->tagList, newEntry->params, newEntry->storageType,
- newEntry->rowStatus);
- DEBUGMSGTL(("snmpTargetAddrEntry", buff));
- snmpTargetAddrTable_addToList(newEntry, &aAddrTable);
- } /* snmpd_parse_config_target */
- /* Shutdown routines */
- /* store_snmpTargetAddrEntry handles the persistent storage proccess
- for this MIB table. It writes out all the non-volatile rows
- to permanent storage on a shutdown */
- int
- store_snmpTargetAddrEntry(int majorID, int minorID, void *serverarg,
- void *clientarg)
- {
- struct targetAddrTable_struct *curr_struct;
- char line[1024];
- int i;
- if ( (curr_struct = aAddrTable) != 0) {
- while (curr_struct != 0) {
- if ( (curr_struct->storageType == SNMP_STORAGE_NONVOLATILE ||
- curr_struct->storageType == SNMP_STORAGE_PERMANENT)
- &&
- (curr_struct->rowStatus == SNMP_ROW_ACTIVE ||
- curr_struct->rowStatus == SNMP_ROW_NOTINSERVICE) ) {
- sprintf(line, "targetAddr %s ", curr_struct->name);
- for(i=0; i < curr_struct->tDomainLen; i++) {
- sprintf(&line[strlen(line)], ".%i", (int)curr_struct->tDomain[i]);
- }
- sprintf(&line[strlen(line)], " %s %i %i "%s" %s %i %i",
- snmp_ntoa(*((long*)(curr_struct->tAddress))), curr_struct->timeout,
- curr_struct->retryCount, curr_struct->tagList,
- curr_struct->params, curr_struct->storageType,
- curr_struct->rowStatus);
- /* store to file */
- snmpd_store_config(line);
- }
- curr_struct = curr_struct->next;
- }
- }
- return SNMPERR_SUCCESS;
- } /* store_snmpTargetAddrEntry */
- /*MIB table access routines */
- u_char *
- var_snmpTargetAddrEntry(
- struct variable *vp,
- oid *name,
- int *length,
- int exact,
- int *var_len,
- WriteMethod **write_method)
- {
- /* variables we may use later */
- static long long_ret;
- static char string[1500];
- static oid objid[128];
- struct targetAddrTable_struct *temp_struct;
- int i;
- *write_method = 0; /* assume it isnt writable for the time being */
- *var_len = sizeof(long_ret); /* assume an integer and change later if not */
- /* look for OID in current table */
- if ( (temp_struct = search_snmpTargetAddrTable(vp->name, vp->namelen,
- name, length, exact)) == 0 ) {
- /* for creation of new rows */
- if (vp->magic == SNMPTARGETADDRROWSTATUS) {
- *write_method = write_snmpTargetAddrRowStatus;
- }
- return(0);
- }
- /* We found what we were looking for, either the next OID or the exact OID */
- /* this is where we do the value assignments for the mib results. */
- switch(vp->magic) {
- case SNMPTARGETADDRTDOMAIN:
- *write_method = write_snmpTargetAddrTDomain;
- if (temp_struct->tDomainLen <= 0) {
- return(0);
- }
- else {
- for (i=0;i<temp_struct->tDomainLen;i++) {
- objid[i] = temp_struct->tDomain[i];
- }
- *var_len = temp_struct->tDomainLen * sizeof(oid);
- }
- return (unsigned char *) objid;
- case SNMPTARGETADDRTADDRESS:
- *write_method = write_snmpTargetAddrTAddress;
- if (temp_struct->tAddress == 0) return(0);
- memcpy(string, temp_struct->tAddress, 7);
- *var_len = 6;
- return (unsigned char *) string;
- case SNMPTARGETADDRTIMEOUT:
- *write_method = write_snmpTargetAddrTimeout;
- long_ret = temp_struct->timeout;
- return (unsigned char *) &long_ret;
- case SNMPTARGETADDRRETRYCOUNT:
- *write_method = write_snmpTargetAddrRetryCount;
- long_ret = temp_struct->retryCount;
- return (unsigned char *) &long_ret;
- case SNMPTARGETADDRTAGLIST:
- *write_method = write_snmpTargetAddrTagList;
- strcpy(string, temp_struct->tagList);
- *var_len = strlen(string);
- return (unsigned char *) string;
- case SNMPTARGETADDRPARAMS:
- *write_method = write_snmpTargetAddrParams;
- if (temp_struct->params == 0) return(0);
- strcpy(string, temp_struct->params);
- *var_len = strlen(string);
- return (unsigned char *) string;
- case SNMPTARGETADDRSTORAGETYPE:
- *write_method = write_snmpTargetAddrStorageType;
- long_ret = temp_struct->storageType;
- return (unsigned char *) &long_ret;
- case SNMPTARGETADDRROWSTATUS:
- *write_method = write_snmpTargetAddrRowStatus;
- long_ret = temp_struct->rowStatus;
- return (unsigned char *) &long_ret;
- default:
- DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_snmpTargetAddrEntryn", vp->magic));
- }
- return 0;
- } /* var_snmpTargetAddrEntry */
- int
- write_snmpTargetAddrTDomain(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- int objSize;
- int i;
- struct targetAddrTable_struct *temp_struct;
- static oid objid[MAX_OID_LEN];
- if (var_val_type != ASN_OBJECT_ID) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTDomain not ASN_OBJECT_IDn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > 128) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTDomain: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- /* spec check, ??? */
- objSize = var_val_len/sizeof(oid);
- memcpy(objid, var_val, var_val_len);
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRTDOMAINCOLUMN;
- if ( (temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTDomain : BAD OID!n"));
- return SNMP_ERR_NOSUCHNAME;
- }
- /* row exists, check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTDomain : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* check if row active */
- if (temp_struct->rowStatus == SNMP_ROW_ACTIVE) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTDomains : This change not allowed in active row.n"));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- /* Finally, we're golden, check if we should save value */
- if (action == COMMIT) {
- for (i=0;i < (int)objSize; i++)
- temp_struct->tDomain[i] = objid[i];
- temp_struct->tDomainLen = objSize;
- /* If row is new, check if its status can be updated */
- if ( (temp_struct->rowStatus == SNMP_ROW_NOTREADY) &&
- (snmpTargetAddr_rowStatusCheck(temp_struct) != 0) )
- temp_struct->rowStatus = SNMP_ROW_NOTINSERVICE;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrTDomain */
- int
- write_snmpTargetAddrTAddress(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- static unsigned char string[1500];
- int size;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_OCTET_STR) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTAddress not ASN_OCTET_STRn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(string))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTAddress: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- /* spec check, ??? */
- size = var_val_len;
- memcpy(string, var_val, var_val_len);
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRTADDRESSCOLUMN;
- if ( (temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTAddress : BAD OID!n"));
- return SNMP_ERR_NOSUCHNAME;
- }
- /* row exists, check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTAddress : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* check if row active */
- if (temp_struct->rowStatus == SNMP_ROW_ACTIVE) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTAddress : This change not allowed in active row.n"));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- /* Finally, we're golden, check if we should save value */
- if (action == COMMIT) {
- free(temp_struct->tAddress);
- temp_struct->tAddress = (char *)malloc(size + 1);
- if (temp_struct->tAddress == NULL)
- return SNMP_ERR_COMMITFAILED;
- memcpy(temp_struct->tAddress, string, size);
- temp_struct->tAddress[size] = ' ';
- /* If row is new, check if its status can be updated */
- if ( (temp_struct->rowStatus == SNMP_ROW_NOTREADY) &&
- (snmpTargetAddr_rowStatusCheck(temp_struct) != 0) )
- temp_struct->rowStatus = SNMP_ROW_NOTINSERVICE;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrTAddress */
- int
- write_snmpTargetAddrTimeout(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- /* variables we may use later */
- static long long_ret;
- /* int size;*/
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_INTEGER) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTimeout not ASN_INTEGERn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(long_ret))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTimeout: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- long_ret = *((long *) var_val);
- /* spec check range, no spec check */
- /* Find row in linked list and check pertinent status... */
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRTIMEOUTCOLUMN;
- if ((temp_struct = search_snmpTargetAddrTable
- (snmpTargetAddrOID, snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0 ) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTimeout : BAD OIDn"));
- return SNMP_ERR_NOSUCHNAME;
- }
- /* row exists, check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTimeout : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* Finally, we're golden, should we save value? */
- if (action == COMMIT) {
- temp_struct->timeout = long_ret;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrTimeout */
- int
- write_snmpTargetAddrRetryCount(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- /* variables we may use later */
- static long long_ret;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_INTEGER) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRetryCount not ASN_INTEGERn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(long_ret))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRetryCount: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- long_ret = *((long *) var_val);
- /* spec check range, no spec check */
- /* Find row in linked list and check pertinent status... */
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRRETRYCOUNTCOLUMN;
- if ((temp_struct = search_snmpTargetAddrTable
- (snmpTargetAddrOID, snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0 ) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTimeout : BAD OIDn"));
- return SNMP_ERR_NOSUCHNAME;
- }
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRetryCount : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* Finally, we're golden, should we save value? */
- if (action == COMMIT) {
- temp_struct->retryCount = long_ret;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrRetryCount */
- int
- write_snmpTargetAddrTagList(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- /* variables we may use later */
- static unsigned char string[1500];
- int size;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_OCTET_STR) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTagList not ASN_OCTET_STRn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(string))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTagList: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- /* spec check, ??? */
- size = var_val_len;
- memcpy(string, var_val, var_val_len);
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRTAGLISTCOLUMN;
- if ( (temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTagList : BAD OID!n"));
- return SNMP_ERR_NOSUCHNAME;
- }
- /* row exists, check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrTagList : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* Finally, we're golden, check if we should save value */
- if (action == COMMIT) {
- free(temp_struct->tagList);
- temp_struct->tagList = (char *)malloc(size + 1);
- if (temp_struct->tagList == NULL)
- return SNMP_ERR_COMMITFAILED;
- memcpy(temp_struct->tagList, string, size);
- temp_struct->tagList[size] = ' ';
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrTagList */
- int
- write_snmpTargetAddrParams(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- static unsigned char string[1500];
- int size;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_OCTET_STR) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrParams not ASN_OCTET_STRn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(string))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrParams: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- /* spec check, ??? */
- size = var_val_len;
- memcpy(string, var_val, var_val_len);
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRPARAMSCOLUMN;
- if ( (temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrParams : BAD OID!n"));
- return SNMP_ERR_NOSUCHNAME;
- }
- /* row exists, check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrParams : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* Finally, we're golden, check if we should save value */
- if (action == COMMIT) {
- free(temp_struct->params);
- temp_struct->params = (char *)malloc(size + 1);
- if (temp_struct->params == NULL)
- return SNMP_ERR_COMMITFAILED;
- memcpy(temp_struct->params, string, size);
- temp_struct->params[size] = ' ';
- /* If row is new, check if its status can be updated */
- if ( (temp_struct->rowStatus == SNMP_ROW_NOTREADY) &&
- (snmpTargetAddr_rowStatusCheck(temp_struct) != 0) )
- temp_struct->rowStatus = SNMP_ROW_NOTINSERVICE;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrParams */
- int
- write_snmpTargetAddrStorageType(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- static long long_ret;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_INTEGER) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrStorageType not ASN_INTEGERn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(long_ret))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrStorageType: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- long_ret = *((long *) var_val);
- if ( (long_ret != SNMP_STORAGE_OTHER) && (long_ret != SNMP_STORAGE_VOLATILE) &&
- (long_ret != SNMP_STORAGE_NONVOLATILE) ) {
- DEBUGMSGTL(("snmpTargetAddrEntry", "write to snmpTargetAddrStorageType : attempted storage type not a valid"));
- DEBUGMSG(("snmpTargetAddrEntry", " value of other(%d), volatile(%d), or nonvolatile(%d)n",
- SNMP_STORAGE_OTHER, SNMP_STORAGE_VOLATILE, SNMP_STORAGE_NONVOLATILE));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- /* Find the struct in the linked list and check status */
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRSTORAGETYPECOLUMN;
- if ((temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0 ) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrStorageType : BAD OIDn"));
- return SNMP_ERR_NOSUCHNAME;
- }
- if ( (temp_struct->storageType == SNMP_STORAGE_PERMANENT) ||
- (temp_struct->storageType == SNMP_STORAGE_READONLY) ) {
- DEBUGMSGTL(("snmpTargetAddrEntry", "write to snmpTargetAddrStorageType : row has unchangeable storage status: %dn",
- temp_struct->storageType));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- /* Finally, we're golden, check if we should save new value */
- if (action == COMMIT) {
- temp_struct->storageType = long_ret;
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrStorageType */
- /* snmpTargeAddr_createNewRow is called from write_snmpTargetAddrRowStatus
- when a new row is required. It creates a new row with
- the index of the passed in 'name' (i.e. full index OID) and
- adds it to the linked list. 'name' should be the full OID of the new index.
- It passes back 0 if unsuccessfull.*/
- int snmpTargetAddr_createNewRow(
- oid *name,
- int name_len)
- {
- int newNameLen;
- int i;
- struct targetAddrTable_struct *temp_struct;
- /* setup a new snmpTargetAddrTable structure and add it to the list */
- newNameLen = name_len - snmpTargetAddrOIDLen;
- if (newNameLen > 0) {
- temp_struct = snmpTargetAddrTable_create();
- if (temp_struct == NULL)
- return 0;
- temp_struct->name = (char *)malloc(newNameLen + 1);
- if (temp_struct->name == NULL) {
- free(temp_struct);
- return 0;
- }
- for (i = 0; i < (int)newNameLen; i++) {
- temp_struct->name[i] = (char)name[i+snmpTargetAddrOIDLen];
- }
- temp_struct->name[newNameLen] = ' ';
- temp_struct->rowStatus = SNMP_ROW_NOTREADY;
- snmpTargetAddrTable_addToList(temp_struct, &aAddrTable);
- return 1;
- }
- return 0;
- } /* snmpTargetAddr_createNewRow */
- /* Assign a value to the Row Status variable */
- int
- write_snmpTargetAddrRowStatus(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- enum commit_action_enum {NOTHING, DESTROY, CREATE, CHANGE};
- enum commit_action_enum onCommitDo;
- static long long_ret;
- struct targetAddrTable_struct *temp_struct;
- if (var_val_type != ASN_INTEGER) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRowStatus not ASN_INTEGERn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > (sizeof(long_ret))) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRowStatus: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- long_ret = *((long *) var_val);
- /* search for struct in linked list */
- snmpTargetAddrOID[snmpTargetAddrOIDLen-1] = SNMPTARGETADDRROWSTATUSCOLUMN;
- if ((temp_struct = search_snmpTargetAddrTable(snmpTargetAddrOID,
- snmpTargetAddrOIDLen,
- name, &name_len, 1)) == 0) {
- /* row doesn't exist, check valid possibilities */
- if (long_ret == SNMP_ROW_DESTROY)
- /* re: RFC 1903, destroying a non-existent row is noError, whatever */
- onCommitDo = NOTHING;
- /* check if this is for a new row creation */
- else if (long_ret == SNMP_ROW_CREATEANDGO || long_ret == SNMP_ROW_CREATEANDWAIT)
- onCommitDo = CREATE;
- else /* no valid sets for no row being found so... */
- return SNMP_ERR_NOSUCHNAME;
- }
- else { /* row exists */
- /* check if it is changeable */
- if (temp_struct->storageType == SNMP_STORAGE_READONLY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRowStatus : row is read onlyn"));
- return SNMP_ERR_READONLY;
- }
- /* check if row is to be destroyed (note: it is ok to destroy notReady row!) */
- else if (long_ret == SNMP_ROW_DESTROY) {
- if (temp_struct->storageType == SNMP_STORAGE_PERMANENT) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRowStatus : unable to destroy permanent rown"));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- else {
- onCommitDo = DESTROY;
- }
- }
- /* check if row is new and can be changed from notready yet */
- else if (temp_struct->rowStatus == SNMP_ROW_NOTREADY) {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargeAddrRowStatus : unable to change from NOTREADYn"));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- /* we now know the row status can be set, check for the two valid settings left*/
- else if ( (long_ret == SNMP_ROW_ACTIVE) ||
- (long_ret == SNMP_ROW_NOTINSERVICE) ) {
- onCommitDo = CHANGE;
- }
- /* not a valid setting */
- else {
- DEBUGMSGTL(("snmpTargetAddrEntry","write to snmpTargetAddrRowStatus : Bad value for setn"));
- return SNMP_ERR_INCONSISTENTVALUE;
- }
- } /* if row exist */
- /* if this is a commit, do expected action */
- if (action == COMMIT) {
- switch(onCommitDo) {
- case CREATE :
- if (snmpTargetAddr_createNewRow(name, name_len) == 0) {
- DEBUGMSGTL(("snmpTargetAddrEntry", "write to snmpTargetAddrRowStatus : "));
- DEBUGMSG(("snmpTargetAddrEntry","failed new row creation, bad OID/index value n"));
- return SNMP_ERR_GENERR;
- }
- break;
- case DESTROY:
- snmpTargetAddrTable_remFromList(temp_struct, &aAddrTable);
- break;
- case CHANGE:
- if ((temp_struct->rowStatus != SNMP_ROW_ACTIVE) && (long_ret == SNMP_ROW_ACTIVE))
- {
- temp_struct->rowStatus = long_ret;
- snmpTargetTryToAddTrap (temp_struct->name);
- }
- else if ((temp_struct->rowStatus == SNMP_ROW_ACTIVE) && (long_ret != SNMP_ROW_ACTIVE))
- {
- snmpTargetTryToDelTrap (temp_struct->name);
- }
- temp_struct->rowStatus = long_ret;
- break;
- case NOTHING:
- default:
- break;
- }
- }
- return SNMP_ERR_NOERROR;
- } /* write_snmpTargetAddrRowStatus */
- u_char *
- var_snmpTargetSpinLock(
- struct variable *vp,
- oid *name,
- int *length,
- int exact,
- int *var_len,
- WriteMethod **write_method)
- {
- static long long_ret;
- *write_method = NULL;
- if (header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED)
- return NULL;
- switch(vp->magic) {
- case SNMPTARGETSPINLOCK:
- *write_method = write_snmpTargetSpinLock;
- long_ret = snmpTargetSpinLock;
- *var_len = sizeof (long);
- return (unsigned char *) &long_ret;
- default:
- snmp_trace ("SNMP in var_snmpTargetSpinLock: unknown suboidn");
- }
- return NULL;
- }
- int write_snmpTargetSpinLock(
- int action,
- u_char *var_val,
- u_char var_val_type,
- int var_val_len,
- u_char *statP,
- oid *name,
- int name_len)
- {
- /* variables we may use later */
- static long long_ret;
- if (var_val_type != ASN_INTEGER){
- DEBUGMSGTL(("usmUser","write to usmUserSpinLock not ASN_INTEGERn"));
- return SNMP_ERR_WRONGTYPE;
- }
- if (var_val_len > sizeof(long_ret)){
- DEBUGMSGTL(("usmUser","write to usmUserSpinLock: bad lengthn"));
- return SNMP_ERR_WRONGLENGTH;
- }
- long_ret = *((long *) var_val);
- if (long_ret != (long)snmpTargetSpinLock)
- return SNMP_ERR_INCONSISTENTVALUE;
- if (action == COMMIT) {
- if (snmpTargetSpinLock == 2147483647)
- snmpTargetSpinLock = 0;
- else
- snmpTargetSpinLock++;
- }
- return SNMP_ERR_NOERROR;
- } /* end write_usmUserSpinLock() */
- int snmpTargetGetAddrFromIndex(char *name, char *buf, int *pRetry)
- {
- struct targetAddrTable_struct *temp_struct;
- long ipAddr;
- for( temp_struct = aAddrTable; temp_struct != NULL; temp_struct = temp_struct->next)
- {
- if (strcmp (name,temp_struct->name) == 0 && temp_struct->rowStatus == SNMP_ROW_ACTIVE)
- {
- ipAddr = *((long *)(temp_struct->tAddress));
- strncpy (buf, snmp_ntoa(ipAddr), 256);
- *pRetry = temp_struct->retryCount;
- return 1;
- }
- }
- return 0;
- }
- /************************************************
- *When rowStatus set to active, add to trap sink.
- *--sxf 2k-12-27
- ************************************************/
- extern int deleteTrapSessionNoRem (char *peer, char *community, int version, int pdutype);
- extern int createTrapSessionNoAdd (char *sink,char * com,int timeout,int queuelen,unsigned short trapflags, int version, int pdutype);
- extern int snmpTargetGetCommFromIndex (char*, char*);
- void snmpTargetTryToAddTrap (char *name)
- {
- char host_name[256];
- char community[256];
- int retry;
- if (snmpTargetGetAddrFromIndex (name, host_name, &retry))
- {
- if (snmpTargetGetCommFromIndex(name, community))
- {
- createTrapSessionNoAdd (host_name, community, 30, retry, 0xffff, SNMP_VERSION_1, SNMP_MSG_TRAP);
- }
- }
- }
- /***************************************************
- *When rowStatus set from active, del from trap sink
- *--sxf 2k-12-27
- ***************************************************/
- void snmpTargetTryToDelTrap (char *name)
- {
- char host_name[256];
- char community[256];
- int retry;
- if (snmpTargetGetAddrFromIndex (name, host_name, &retry))
- {
- if (snmpTargetGetCommFromIndex(name, community))
- {
- deleteTrapSessionNoRem (host_name, community, SNMP_VERSION_1, SNMP_MSG_TRAP);
- }
- }
- }
- u_char *
- var_snmpTargetContexts(
- struct variable *vp,
- oid *name,
- int *length,
- int exact,
- int *var_len,
- WriteMethod **write_method)
- {
- static long long_ret;
- *write_method = NULL;
- if (header_generic(vp,name,length,exact,var_len,write_method) == MATCH_FAILED)
- return NULL;
- switch(vp->magic) {
- case SNMPUNAVAILABLECONTEXTS:
- case SNMPUNKNOWNCONTEXTS:
- long_ret = 0;
- *var_len = sizeof (long);
- return (unsigned char *) &long_ret;
- default:
- snmp_trace ("SNMP in var_snmpTargetSpinLock: unknown suboidn");
- }
- return NULL;
- }