mib_handler.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include "impl.h"
#include "asn1.h"
#include "error.h"
#include "snmp.h"
#include "trap.h"
#include "snmpdx_stub.h"
#include "agent.h"
#include "subtree.h"
#include "res.h"
#include "sh_table.h"
#include "dispatcher.h"
typedef void (*SapDelFunc)(char* t);
typedef char* (*SapAllocFunc)();
typedef char* (*SapFirstEntryFunc)();
typedef int (*SapChkEntryFunc)(char* t);
typedef int (*SapAddEntryFunc)(char *t);
typedef int (*SapIndexOffsetFunc)();
typedef int (*SapIndexOffsetFunc2)();
typedef char* (*SapAdvanceFunc)(char *t);
typedef int (*SapIndexFunc)(char *t);
typedef int (*SapIndexFunc2)(char *t);
typedef char* (*SapCloneFunc)(char *t);
#define SAP_ST_INACTIVE 0
#define SAP_ST_ERR 1
#define SAP_ST_ACTIVE 2
#define DEFAULT_SAP_TBL_INC_SIZE 100
#define SAP_TBL_SUCCESS 1
#define SAP_TBL_FAIL 0
#define SAP_INVALID_INDEX -1
#define SAP_TBL_ENTRY_VALID 1
extern int read_agent_acl (SapResource *);
/** Table **/
/** Current impl, fix array size */
typedef struct _SapTable {
int size;
char *next;
char *first;
} SapTable;
/****** AgentTable private Info *****/
void free_Agent(char *t);
char* alloc_Agent();
char* clone_Agent();
int chk_Agent(char* t);
char* first_entry_Agent();
int index_offset_agent();
int index_offset_2_Agent();
int add_entry_Agent(char* t);
char* advance_entry_Agent(char* t);
int index_agent(char *t);
int index_2_Agent(char *t);
/***** AgentEntry Specific MACRO ****/
#define OFFSET_AGENT_ID 1
#define OFFSET_AGENT_STATUS 2
#define OFFSET_AGENT_TIME_OUT 3
#define OFFSET_AGENT_PORT_NUMBER 4
#define OFFSET_AGENT_PERSONAL_FILE 5
#define OFFSET_AGENT_CONFIG_FILE 6
#define OFFSET_AGENT_EXECUTABLE 7
#define OFFSET_AGENT_VERSION_NUM 8
#define OFFSET_AGENT_PROCESS_ID 9
#define OFFSET_AGENT_AGENT_NAME 10
#define OFFSET_AGENT_SYSTEM_UP_TIME 11
#define OFFSET_AGENT_WATCH_DOG_TIME 12
/***** AgentEntry Specific MACRO ****/
/****** AgentTable private Info *****/
/****** RegTreeTable private Info *****/
void free_Subtree(char *t);
char* alloc_Subtree();
char* clone_Subtree();
int chk_Subtree(char* t);
char* first_entry_Subtree();
int index_offset_Subtree();
int index_offset_2_Subtree();
int add_entry_Subtree(char* t);
char* advance_entry_Subtree(char* t);
int index_Subtree(char *t);
int index_2_Subtree(char *t);
static SapTable reg_tree_tbl = { 0, 0, 0,
/***** RegTreeTable Specific MACRO ****/
#define OFFSET_REGTREE_INDEX 1
#define OFFSET_REGTREE_ID 2
#define OFFSET_REGTREE_OID 3
#define OFFSET_REGTREE_STATUS 4
/***** RegTreeTable Specific MACRO ****/
/****** RegTblTable private Info *****/
void free_Table(char *t);
char* alloc_Table();
char* clone_Table();
int chk_Table(char* t);
char* first_entry_Table();
int index_offset_Table();
int index_offset_2_Table();
int add_entry_Table(char* t);
char* advance_entry_Table(char* t);
int index_Table(char *t);
int index_2_Table(char *t);
static SapTable reg_tbl_tbl = { 0, 0, 0,
/***** RegTblTbl Specific MACRO ****/
#define OFFSET_REG_TBL_INDEX 1
#define OFFSET_REG_TBL_AGENT_ID 2
#define OFFSET_REG_TBL_OID 3
#define OFFSET_REG_TBL_SCOL 4
#define OFFSET_REG_TBL_ECOL 5
#define OFFSET_REG_TBL_SROW 6
#define OFFSET_REG_TBL_EROW 7
#define OFFSET_REG_TBL_STATUS 8
/***** RegTblTbl Specific MACRO ****/
/****** RegTreeTable private Info *****/
/***********/
{
SapResource * rp;
return 0;
}
return 0;
}
/*** string equal ***/
{
int i;
return 0;
}
return 1;
}
return 0;
}
{
return 0;
return 0;
}
return 1;
}
{
return 0;
}
return 1;
}
/************************/
/***** AgentEntry Specific routines ****/
char* first_entry_Agent()
{
return((char*)first_agent);
}
int add_entry_Agent(char* t)
{
if(first_agent == NULL){
}else{
}
first_agent = entry;
return SAP_TBL_SUCCESS;
}
/* a hack: assume the index is integer */
int index_agent(char* t)
{
}
int index_2_Agent(char *t)
{
return 0;
}
{
int res=1;
switch(offset){
case OFFSET_AGENT_PORT_NUMBER:
/* policy: once the port is bind, may not allow it
to bind to another port. If allow, need unbind and
rebind */
/* Bug fix 4145620 - The subagents listen on the loopback driver */
break;
case OFFSET_AGENT_AGENT_NAME:
/* TODO: sync the agent's ACL with the resource list here */
break;
case OFFSET_AGENT_TIME_OUT:
/* for timeout > relay_agent_max_agent_time_out
* we reset it to relay_agent_max_agent_time_out
*/
}else{
}
break;
case OFFSET_AGENT_ID:
/* may not be allowd to change */
case OFFSET_AGENT_STATUS:
/* valid state transistion for user:
* inactive-> any state except inactive
* active-> inactive, destroy except active
*/
if(pass==SECOND_PASS){
}
if(num==SSA_OPER_STATUS_ACTIVE){
if(pass==SECOND_PASS)
}else if(num==SSA_OPER_STATUS_NOT_IN_SERVICE){
}else if(num==SSA_OPER_STATUS_DESTROY){
/* destroy the table before the subtree */
if(pass==FIRST_PASS &&
return(0);
if(pass==SECOND_PASS)
}else return(0);
break;
case OFFSET_AGENT_PROCESS_ID:
break;
case OFFSET_AGENT_CONFIG_FILE:
break;
case OFFSET_AGENT_EXECUTABLE:
break;
case OFFSET_AGENT_VERSION_NUM:
break;
}
return res;
}
void free_Agent(char* t)
{
}
char* alloc_Agent()
{
char* t;
return t;
}
return NULL;
}
char* clone_Agent(char* orig)
{
/* image copy */
char* t;
return t;
}
return NULL;
}
int chk_Agent(char* t)
{
return SAP_TBL_SUCCESS;
}
{
if(chk_Agent(t) == SAP_TBL_SUCCESS)
return SAP_TBL_SUCCESS;
return SAP_TBL_FAIL;
}
{
return SAP_TBL_FAIL;
}
int index_offset_agent()
{
return(OFFSET_AGENT_ID);
}
int index_offset_2_Agent()
{
return(-1);
}
char* advance_entry_Agent(char* t)
{
if(chk_Agent((char*)i) == SAP_TBL_SUCCESS) return((char*)i);
}
return(NULL);
}
/***** AgentEntry Specific routines ****/
/***** RegTreeEntry Specific routines ***/
char* first_entry_Subtree()
{
return((char*)first_subtree);
}
char* advance_entry_Subtree(char* t)
{
if(chk_Subtree((char*)i) == SAP_TBL_SUCCESS) return((char*)i);
}
return(NULL);
}
int add_entry_Subtree(char* t)
{
/* can't register a subtree with agent */
int ret;
/* initialize the agent */
return SAP_TBL_FAIL;
}
/* if name not exist, insert is not allowed */
{
if(ret == 0)
{
/* for duplication registration of oid,
replace the current one */
break;
}
else
if(ret < 0)
{
break;
}
}
}else{
}
return SAP_TBL_SUCCESS;
}
int index_Subtree(char *t)
{
return(entry->regTreeAgentID);
}
int index_2_Subtree(char *t)
{
/* no longer used */
return(entry->regTreeIndex);
}
/*
* If the pass is FIRST_PASS, this function is called when the entry
* exits. It may not be allowed to overwrite some fields.
*/
{
int res = 1;
switch(offset){
case OFFSET_REGTREE_ID: /* need to detach and reattach */
if(pass==SECOND_PASS){
}
}
}
}
case OFFSET_REGTREE_STATUS:
if(pass==FIRST_PASS){
/* don't allow user to destroy tree object which
belongs to table */
return 0;
return 0;
break;
}
/* (mibpatch) if entry->mirrorTag == NULL
create a new mirror_table */
/* if status is not-in-service, we may destroy
this entry */
/* (mibpatch) delete the mirror_table, don't use
delete_table call */
}
}
break;
}
}
/* (mibpatch) if there exists corresponding table,
if(entry->mirrorTag!=NULL) update the table status */
break;
case OFFSET_REGTREE_INDEX:
if(pass==SECOND_PASS){
/* this may not be changed */
}
case OFFSET_REGTREE_OID:
/* don't allow to change any established oid */
return 0;
return 0;
break;
}
return(res);
}
void free_Subtree(char* t)
{
}
char* alloc_Subtree()
{
char* t;
return t;
}
return NULL;
}
{
Subtree *t;
return ((char *)t);
}
return NULL;
}
int chk_Subtree(char* t)
{
return SAP_TBL_SUCCESS;
}
{
if(chk_Subtree(t) == SAP_TBL_SUCCESS)
return SAP_TBL_SUCCESS;
return SAP_TBL_FAIL;
}
{
if(chk_Subtree(t) == SAP_TBL_SUCCESS)
return SAP_TBL_SUCCESS;
return SAP_TBL_FAIL;
}
int index_offset_Subtree()
{
return(OFFSET_REGTREE_ID);
}
int index_offset_2_Subtree()
{
/* no longer used */
return(OFFSET_REGTREE_INDEX);
}
/***** RegTreeEntry Specific routines ***/
/***** RegTblEntry Specific routines ***/
char* first_entry_Table()
{
return((char*)first_table);
}
char* advance_entry_Table(char* t)
{
if(chk_Table((char*)i) == SAP_TBL_SUCCESS) return((char*)i);
}
return(NULL);
}
{
return 0;
return 1;
}
int add_entry_Table(char* t)
{
int ret;
/* initialize the agent */
return SAP_TBL_FAIL;
}
{
if(ret == 0)
{
/* for duplication registration of oid,
replace the current one */
break;
}
}
first_table = entry;
}else{
}
return SAP_TBL_SUCCESS;
}
int index_Table(char *t)
{
return(entry->regTblAgentID);
}
int index_2_Table(char *t)
{
return(entry->regTblIndex);
}
static int table_is_incomplete(Table *t)
{
/* (mibpatch) don't know what to do */
if(t->first_column_subid==0 || t->last_column_subid==0 ||
t->first_index_subid==0 || t->last_index_subid==0)
return TRUE;
return FALSE;
}
/*
* If the pass is FIRST_PASS, this function is called when the entry
* exits. It may not be allowed to overwrite some fields.
*/
{
int res = 1;
switch(offset){
case OFFSET_REG_TBL_INDEX:
/* this may not be changed */
if(pass==SECOND_PASS){
}
case OFFSET_REG_TBL_AGENT_ID: /* need to detach and reattach */
if(pass==SECOND_PASS){
}
}
case OFFSET_REG_TBL_OID:
/* this oid can be set up once, no replacement */
if(pass==FIRST_PASS){
/* if table is complete, user can't change the table */
return 0;
}
if(pass==SECOND_PASS){
}
break;
case OFFSET_REG_TBL_SCOL:
if(table_is_incomplete(entry)){
}else
return(0);
break;
case OFFSET_REG_TBL_ECOL:
if(table_is_incomplete(entry)){
}else
return(0);
break;
case OFFSET_REG_TBL_SROW:
if(table_is_incomplete(entry)){
}else
return(0);
break;
case OFFSET_REG_TBL_EROW:
if(table_is_incomplete(entry)){
}else
return(0);
break;
case OFFSET_REG_TBL_STATUS:
/* destroy the table or add the table */
if(pass==FIRST_PASS){
num==SSA_OPER_STATUS_ACTIVE ) return 0;
return(res);
return(res);
return 0;
}
/* second pass */
if(num==SSA_OPER_STATUS_ACTIVE){
{
/* (mibpatch) if table is mirror, set the
subtree status to active */
}
}else if(num==SSA_OPER_STATUS_NOT_IN_SERVICE){
/* destroy the table */
else
}
}
return(res);
}
void free_Table(char* t)
{
}
char* alloc_Table()
{
char* t;
return t;
}
return NULL;
}
char* clone_Table(char* table)
{
char* t;
return t;
}
return NULL;
}
int chk_Table(char* t)
{
return SAP_TBL_SUCCESS;
}
{
if(chk_Table(t) == SAP_TBL_SUCCESS)
return SAP_TBL_SUCCESS;
return SAP_TBL_FAIL;
}
{
if(chk_Table(t) == SAP_TBL_SUCCESS)
return SAP_TBL_SUCCESS;
return SAP_TBL_FAIL;
}
int index_offset_Table()
{
return(OFFSET_REG_TBL_AGENT_ID);
}
int index_offset_2_Table()
{
return(OFFSET_REG_TBL_INDEX);
}
/***** RegTblEntry Specific routines ***/
/***********************************************************/
{
/* point to the first of the list */
}
{
/* free out the list */
}
{
/* add entry to the list */
}
{
char* t;
return t;
t = (*this->advance_entry)(t);
}
return(NULL);
/* call the search */
}
{
char* t;
return t;
t = (*this->advance_entry)(t);
}
return(NULL);
/* call the search2 */
}
{
return -1;
/* not required */
}
{
char* t;
return((*this->advance_entry)(t));
}
t = (*this->advance_entry)(t);
}
return(NULL);
/* call the next_entry */
}
{
char* t;
return((*this->advance_entry)(t));
}
t = (*this->advance_entry)(t);
}
return(NULL);
/* call the next_entry */
}
{
char *t;
return( (*this->advance_entry)(t) );
/* head of the list */
}
{
switch(search_type)
{
case FIRST_ENTRY:
== NULL)
/* update the index */
break;
case NEXT_ENTRY:
if((entry =
== NULL)
/* update the index */
break;
case EXACT_ENTRY:
if( (entry =
== NULL)
break;
}
return entry;
}
char* get_tbl_entry_2(SapTable *this, int search_type, int *snmp_error, Integer *AgentID, Integer *index2)
{
switch(search_type)
{
case FIRST_ENTRY:
== NULL)
/* update the index */
break;
case NEXT_ENTRY:
if((entry =
== NULL)
/* update the index */
break;
case EXACT_ENTRY:
if( (entry =
== NULL)
break;
}
return entry;
}
/* Assumption: second phase comes after successful first phase
in second phase cleanup the clone created in first phase,
if first phase fails, the clone is cleanup before return */
/* side effect, if index doesn't exist, add a new row */
{
static char* first_pass_entry=NULL;
{
}
/* here, if first_pass_entry is not NULL => it points to the desired
entry */
return SNMP_ERR_NOSUCHNAME;
if(pass==FIRST_PASS)
return SNMP_ERR_GENERR;
}
if(pass==SECOND_PASS){
return SNMP_ERR_GENERR;
}
}
}else{
/* entry exists, may need to do some clean up */
/* made a duplication */
if(pass==FIRST_PASS){
if(first_pass_entry == NULL){
return SNMP_ERR_GENERR;
}
}
if(pass==FIRST_PASS)
return SNMP_ERR_GENERR;
}
}
return SNMP_ERR_NOERROR;
}
{
static char* first_pass_entry=NULL;
{
}
/* here, if first_pass_entry is not NULL => it points to the desired
entry */
if( first_pass_entry==NULL &&
return SNMP_ERR_NOSUCHNAME;
if(pass==FIRST_PASS)
NULL)==0 ||
return SNMP_ERR_GENERR;
}
if(pass==SECOND_PASS){
return SNMP_ERR_GENERR;
}
}
}else{
/* entry exists, may need to do some clean up */
if(pass==FIRST_PASS){
/* clone the entry */
if(first_pass_entry == NULL){
return SNMP_ERR_GENERR;
}
}
if(pass==FIRST_PASS)
return SNMP_ERR_GENERR;
}
}
return SNMP_ERR_NOERROR;
}
/***********************************************************/
{
int snmp_error;
return(snmp_error);
}
/***** AgentStatus ********************************/
{
/* set agent status, remember to set all the subtree belongs to it */
int offset = OFFSET_AGENT_STATUS;
}
/***** AgentTimeOut ********************************/
{
int offset = OFFSET_AGENT_TIME_OUT;
}
/***** AgentPortNumber ********************************/
{
int offset = OFFSET_AGENT_PORT_NUMBER;
}
/***** AgentPersonalFile ********************************/
{
int offset = OFFSET_AGENT_PERSONAL_FILE;
}
/***** AgentConfigFile ********************************/
{
int offset = OFFSET_AGENT_CONFIG_FILE;
}
/***** AgentExecutable ********************************/
{
int offset = OFFSET_AGENT_EXECUTABLE;
}
/***** AgentVersionNum ********************************/
{
int offset = OFFSET_AGENT_VERSION_NUM;
}
/***** AgentProcessID ********************************/
{
int ret;
int offset = OFFSET_AGENT_PROCESS_ID;
return ret;
}
/***** AgentName ********************************/
{
int offset = OFFSET_AGENT_AGENT_NAME;
}
/***** agentSystemUpTime ********************************/
}
}
{
/* next available index to be used */
return SNMP_ERR_NOERROR;
}
{
switch(pass)
{
case FIRST_PASS:
return SNMP_ERR_GENERR;
break;
case SECOND_PASS:
sap_agent_id++;
}
return SNMP_ERR_NOERROR;
}
/***** Subtree ********************************/
/***** regTreeEntry ********************************/
{
int snmp_error;
return(snmp_error);
}
/***** regTreeOID ********************************/
{
int offset = OFFSET_REGTREE_OID;
}
/***** regTreeStatus ********************************/
{
int offset = OFFSET_REGTREE_STATUS;
return(set_table_entry_field_2(tbl,regTreeAgentID,regTreeIndex,pass,regTreeStatus,NULL,NULL,offset));
}
{
/* it may overflow */
return SNMP_ERR_NOERROR;
}
/*********************************************************/
/***** relayProcessIDFile ********************************/
{
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
/***** regTblEntry ********************************/
{
int snmp_error;
return(snmp_error);
}
/***** regTblOID ********************************/
{
int offset = OFFSET_REG_TBL_OID;
}
/***** regTblStartColumn ********************************/
{
int offset = OFFSET_REG_TBL_SCOL;
return(set_table_entry_field_2(tbl,regTblAgentID,regTblIndex,pass,regTblStartColumn,NULL,NULL,offset));
}
/***** regTblEndColumn ********************************/
{
int offset = OFFSET_REG_TBL_ECOL;
return(set_table_entry_field_2(tbl,regTblAgentID,regTblIndex,pass,regTblEndColumn,NULL,NULL,offset));
}
/***** regTblStartRow ********************************/
{
int offset = OFFSET_REG_TBL_SROW;
return(set_table_entry_field_2(tbl,regTblAgentID,regTblIndex,pass,regTblStartRow,NULL,NULL,offset));
}
/***** regTblEndRow ********************************/
{
int offset = OFFSET_REG_TBL_EROW;
}
/***** regTblStatus ********************************/
{
int offset = OFFSET_REG_TBL_STATUS;
}
{
*regTblTableIndex = 0;
return SNMP_ERR_NOERROR;
}
/***** relayResourceFile ********************************/
{
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
/***** relayPersonalFileDir ********************************/
{
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
/***** relayLogFile ********************************/
{
if (relayLogFile == NULL)
return SNMP_ERR_BADVALUE;
else
relayLogFile->len=0;
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
/***** relayOperationStatus ********************************/
{
if (relayOperationStatus == NULL)
return SNMP_ERR_BADVALUE;
else
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
/***** relayCheckPoint ********************************/
{
if (relayCheckPoint == NULL)
return SNMP_ERR_BADVALUE;
else
relayCheckPoint->len=0;
return SNMP_ERR_NOERROR;
}
{
/* check for dup. agent name */
char *buffer;
return SNMP_ERR_NOERROR; /* No alternative */
switch(pass)
{
case FIRST_PASS:
case SECOND_PASS:
}
return SNMP_ERR_NOERROR;
}
{
return NOT_IMPLEMENTED;
}
{
return NOT_IMPLEMENTED;
}
{
return SNMP_ERR_NOERROR;
}
{
return SNMP_ERR_NOERROR;
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}
{
}