personal.y 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 1998 Sun Microsystems, Inc. All Rights Reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
%}
/* support SNMP security(5-13-96) */
%{
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include "impl.h"
#include "error.h"
#include "trace.h"
#include "pdu.h"
#include "pagent.h"
#include "subtree.h"
/** SNMP security (5-13-96) */
#include "trap.h"
#include "agent_msg.h"
#include "access.h"
#include "snmpd.h"
/***** DEFINE *****/
/*
#define DEBUG_YACC(string) printf("\t\tYACC: %s: %s at line %d\n", string, yytext, yylineno);
*/
#define DEBUG_YACC(string)
#define SNMPRELAY_SUFFIX ".snmprelay"
/***** TYPEDEF *****/
typedef struct _Macro {
struct _Macro *next_macro;
char *label;
} Macro;
#include "table.h"
static int table_index=0;
/*
typedef struct _Table {
struct _Table *next_table;
Agent *agent;
Oid name;
Subid regTblStartColumn;
Subid regTblEndColumn;
Subid regTblStartRow;
Subid regTblEndRow;
} Table;
*/
/***** STATIC VARIABLES AND FUNCTIONS *****/
/* access control(6-20-96) */
/* trap filter (6-25-96) */
static int static_trap_low=-1;
static int static_trap_high=-1;
/* snmp security(5-13-96) */
static int community_type = 0;
static char *current_filename = NULL;
/* lexinput points to the current focus point in the config file */
static char *lexinput;
/* first_macro is the begining of the list */
/* of the user defined macros */
/* first_table is the begining of the list */
/* of tables supported by the agents */
/* the boolean parsing_oid is used to */
/* know if we are parsing an */
/* object identifier or not. */
static int parsing_oid = False;
/* here are the values of the predifined macros */
/* that can be used in the configuration file */
static int mib2_len = 6;
static int enterprise_len = 6;
static int sun_len = 7;
/* the 2 static variables static_subids and */
/* static_len are used when parsing an */
/* object identifier. Then the boolean */
/* parsing_oid should be true. When a new sub- */
/* identifier (or a list of sub-identifiers) */
/* is found, we use the function */
/* subids_cat to append it to the static_subids.*/
static int static_len = 0;
/* macro_add() is used to append a macro to */
/* the macro list. macro_find is used to find */
/* a macro in the macro list */
static void macro_list_delete();
static void table_list_delete();
extern int SSARegSubagent(Agent *);
extern int SSASubagentOpen(int, char *);
extern int SSARegSubtable(SSA_Table *);
/* static_label is used when parsing a macro */
static char *static_label = NULL;
/* static_agent is used when parsing an agent */
/* static_table is used when parsing n table */
/* static_inf_value and static_max_value are */
/* used when parsing a range */
static int static_inf_value = -1;
static int static_sup_value = -1;
static int count;
%}
%%
{
DEBUG_YACC("configuration")
}
/******************* SNMP security (5-13-96) *********/
{
DEBUG_YACC("security configuration")
}
/***************/
/* accesscontrol */
/***************/
{
DEBUG_YACC("acls_list")
}
{
if(static_access_policy != NULL){
}
}
{
DEBUG_YACC("acls_list")
}
{
if(static_access_policy == NULL)
{
error("calloc() failed");
}
{
if(static_access_policy!=NULL)
{
/* create AccessServer */
/* put the AccessPolicy into AccessServer */
/* put AccessServer into corresponding manager */
community_type = 0;
}
{
DEBUG_YACC("communities_stmt");
}
{
DEBUG_YACC("communities_set");
}
{
if(static_access_policy==NULL){
error("acl statement error");
}
/* add community into AccessPolicy */
if(static_community == NULL)
{
error("calloc() failed");
}
}
{
DEBUG_YACC("acl_access")
}
{
DEBUG_YACC("acl_access_type")
}
{
DEBUG_YACC("hosts")
}
{
DEBUG_YACC("hosts_list");
}
{
/* add the host item to manager list */
/* it should return the pointer if exists */
DEBUG_YACC("manager_item")
error("error in %s at line %d: %s",
"???",
}
if(static_access_server == NULL)
{
error("malloc() failed");
}
if(static_access_policy!=NULL)
}
/************/
/* managers */
/************/
/*
managers : t_managers t_equal t_openbracket managers_list t_closebracket
{
DEBUG_YACC("agents")
}
managers_list : | managers_list list_separator manager_item
{
DEBUG_YACC("managers_list")
}
manager_item : ct_identifier
{
Manager *res;
DEBUG_YACC("manager_item")
res = manager_add(yytext, error_label);
if(res==NULL){
error("error in %s at line %d: %s",
current_filename? current_filename:
"???",
yylineno, error_label);
}
}
*/
/*** trap hanlding (6-25-96) */
{
DEBUG_YACC("trap_block")
}
{
/* clean up */
if(static_sub_member != NULL){
}
}
{
DEBUG_YACC("trap_list")
}
{
/* create submember */
if(static_sub_member == NULL)
{
error("malloc() failed");
}
{
/* attach submember to subgroup */
{
}
{
/* set the community field in submember */
if(static_sub_member != NULL)
{
if(static_sub_member == NULL)
{
}
}else{
error("BUG: missing trap community name");
}
}
{
DEBUG_YACC("trap_interest_hosts")
}
{
DEBUG_YACC("trap_interest_hosts_list")
}
{
DEBUG_YACC("trap_interest_host_item")
/* attach host to the submember */
if(static_sub_member==NULL){
error("trap statement error");
}else{
if(static_host == NULL)
{
error("malloc() failed");
}
}
}
}
{
DEBUG_YACC("enterprise_list")
}
{
DEBUG_YACC("enterprise_item")
}
{
/* currently, it supports single enterprise */
DEBUG_YACC("enterprise_stmt")
/* add or find the enterprise */
if(static_filter==NULL){
error("error in %s at line %d: %s",
}
}
{
DEBUG_YACC("trap_number_stmt")
}
{
DEBUG_YACC("trap_number_list")
}
{
DEBUG_YACC("trap_number_list")
}
{
DEBUG_YACC("trap_number_item")
enterprise, and add_tailthe subgroup
to each trap */
if(static_filter!=NULL){
/* expand the trap */
}else{
error("error in enterprise statement");
}
}
{
/* starting trap num */
}
{
/* ending trap num */
}
| NUMBER
{
/* start & end num the same */
DEBUG_YACC("trap_range")
}
/*
trapcommunity : t_trapcommunity t_equal ct_identifier
{
DEBUG_YACC("trap_community")
if(trap_community)
{
error("BUG: trap_community not NULL in trap_community");
}
trap_community = strdup(yytext);
if(trap_community == NULL)
{
error(ERR_MSG_ALLOC);
YYERROR;
}
}
*/
/*******************/
/* trapdestinators */
/*******************/
/*
trapdestinators : t_trapdestinators t_equal t_openbracket trapdestinators_list t_closebracket
{
DEBUG_YACC("trapdestinators")
}
trapdestinators_list : | trapdestinators_list list_separator trapdestinator_item
{
DEBUG_YACC("trapdestinators_list")
}
trapdestinator_item : ct_identifier
{
int res;
DEBUG_YACC("trapdestinator_item")
res = trap_destinator_add(yytext, error_label);
switch(res)
{
case 0:
break;
case 1:
error("error in %s at line %d: %s",
current_filename? current_filename:
"???",
yylineno, error_label);
break;
default:
error("fatal error in %s at line %d: %s",
current_filename? current_filename:
"???",
yylineno, error_label);
YYERROR;
}
}
*/
/******************* SNMP security (5-13-96) *********/
/**********/
/* macros */
/**********/
{
DEBUG_YACC("macros")
}
{
DEBUG_YACC("macros_list")
}
{
if(parsing_oid != False)
{
}
parsing_oid = True;
if(static_subids != NULL)
{
}
if(static_len != 0)
{
}
}
{
DEBUG_YACC("macro_item")
{
}
parsing_oid = False;
static_label = NULL;
static_len = 0;
}
{
DEBUG_YACC("label")
if(static_label != NULL)
{
}
if(static_label == NULL)
{
error("malloc() failed");
}
}
/**********/
/* agents */
/**********/
{
DEBUG_YACC("agents")
}
{
DEBUG_YACC("agents_list")
}
{
if(static_agent != NULL)
{
}
if(static_agent == NULL)
{
error("malloc() failed");
}
/* LINTED */
}
{
DEBUG_YACC("agent_item");
/* add the agent id to agent, currently, agent_id is pid */
if(first_agent == NULL)
{
}
else
{
}
/* if port is 0, assigned a non-reserved available port */
if (agent_port_number == -1)
/* the registration is for confirmation and
fill in extra value */
if(SSARegSubagent(static_agent) == 0)
{
error("subagent registration failed");
}
static_agent = NULL;
}
{
DEBUG_YACC("name")
{
}
{
error("malloc() failed");
}
/*
* Increased the num. of retries for SSASubagentOpen in order to insure success
* typically for boot time race condition between the master and subagent
* Initial sleep is introduced to increase the probability of success the very
* first time. This could be removed at a later time, after modifying the timeout
* parameters for the subagent
*/
(void)sleep(15);
count=1;
while(count) {
if( (static_agent->agent_id =
{
if (count == 5) {
error_exit("subagent registration failed");
}
}
if (static_agent->agent_id ) break;
count++;
}
if(SSARegSubagent(static_agent) == 0)
{
error("subagent registration failed");
}
/* LINTED */
}
{
DEBUG_YACC("subtrees_tables")
}
{
if(parsing_oid != False)
{
}
parsing_oid = True;
if(static_subids != NULL)
{
}
if(static_len != 0)
{
}
}
{
DEBUG_YACC("subtrees")
if(parsing_oid != True)
{
}
parsing_oid = False;
}
{
DEBUG_YACC("subtrees_list")
}
{
DEBUG_YACC("subtrees_list_coma_separated")
}
{
DEBUG_YACC("subtree_item")
if(parsing_oid != True)
{
}
{
}
static_len = 0;
}
{
DEBUG_YACC("tables")
}
{
DEBUG_YACC("tables_list")
}
{
if(static_agent == NULL)
{
}
if(static_table)
{
}
if(static_table == NULL)
{
error("malloc() failed");
}
if(static_agent!=NULL)
static_table->regTblEndColumn = 0;
/*
static_table->indexs.subids = NULL;
static_table->indexs.len = 0;
*/
}
{
DEBUG_YACC("table_item")
if(static_table == NULL)
{
}
/* register the table, if register fails, delete
the table */
if(SSARegSubtable(static_table)==0){
/* unregister the table */
error_exit("TABLE CONFIG");
}
if(last_table)
{
}
else
{
}
static_table = NULL;
}
{
if(parsing_oid != False)
{
}
parsing_oid = True;
}
{
DEBUG_YACC("table")
if(parsing_oid != True)
{
}
parsing_oid = False;
if(static_table == NULL)
{
}
static_len = 0;
}
{
DEBUG_YACC("columns")
if(static_table == NULL)
{
}
static_inf_value = -1;
static_sup_value = -1;
}
/*
indexs : t_indexs t_equal
{
if(parsing_oid != False)
{
error("BUG at line %d: parsing_oid is not False in indexs", yylineno);
}
parsing_oid = True;
}
subids_list
{
DEBUG_YACC("indexs")
if(parsing_oid != True)
{
error("BUG at line %d: parsing_oid is not True in indexs", yylineno);
}
parsing_oid = False;
if(static_table == NULL)
{
error_exit("BUG at line %d: static_table is NULL in indexs", yylineno);
}
static_table->indexs.subids = static_subids;
static_subids = NULL;
static_table->indexs.len = static_len;
static_len = 0;
}
*/
{
DEBUG_YACC("indexs")
if(static_inf_value == -1)
{
}
if(static_sup_value == -1)
{
}
static_inf_value = -1;
static_sup_value = -1;
}
{
if(static_inf_value != -1)
{
error("BUG at line %d: static_inf_value (%d) is not -1 in range",
}
}
{
if(static_sup_value != -1)
{
error("BUG at line %d: static_sup_value (%d) is not -1 in range",
}
}
{
DEBUG_YACC("range")
}
| t_number
{
if(static_inf_value != -1)
{
error("BUG at line %d: static_inf_value (%d) is not -1 in range",
}
if(static_sup_value != -1)
{
error("BUG at line %d: static_sup_value (%d) is not -1 in range",
}
}
{
DEBUG_YACC("subtree")
}
{
DEBUG_YACC("optional_watch_dog_time")
}
{
DEBUG_YACC("optional_port")
}
{
DEBUG_YACC("port")
if(token_value > 0xFFFF)
{
error("error at line %d: the port number (%d) should not be greater than %d", yylineno, token_value, 0xFFFF);
}
/* LINTED */
{
error("error at line %d: the port number %d is already used by another agent", yylineno, token_value);
}
}
/***************/
/* subids_list */
/***************/
{
DEBUG_YACC("subids_list")
}
{
DEBUG_YACC("subid")
}
/*******************/
/* terminal tokens */
/*******************/
/**************** SNMP security (5-13-96) ***/
{
DEBUG_YACC("ct_indentifier")
}
{
DEBUG_YACC("t_communities")
}
{
DEBUG_YACC("t_hosts")
}
{
DEBUG_YACC("t_acls")
}
{
DEBUG_YACC("t_access")
}
{
DEBUG_YACC("t_readonly")
}
{
DEBUG_YACC("t_readwrite")
}
{
DEBUG_YACC("t_managers")
}
{
DEBUG_YACC("t_trap")
}
{
DEBUG_YACC("t_trap_num")
}
{
DEBUG_YACC("t_trapcommunity")
}
/*
t_trapdestinators : TRAPDESTINATORS
{
DEBUG_YACC("t_trapdestinators")
}
list_separator : | t_coma
{
DEBUG_YACC("list_separator")
}
*/
/**************** SNMP security (5-13-96) ***/
{
DEBUG_YACC("t_number")
if(parsing_oid == True)
{
{
}
}
}
{
DEBUG_YACC("t_macros")
}
{
DEBUG_YACC("t_equal")
}
{
DEBUG_YACC("t_minus")
}
{
DEBUG_YACC("t_openbracket")
}
{
DEBUG_YACC("t_closebracket")
}
{
DEBUG_YACC("t_opensquarebracket")
}
{
DEBUG_YACC("t_closesquarebracket")
}
{
DEBUG_YACC("t_identifier")
if(parsing_oid == True)
{
{
}
{
}
}
}
{
DEBUG_YACC("t_mib2")
if(parsing_oid == False)
{
}
{
}
}
{
DEBUG_YACC("t_sun")
if(parsing_oid == False)
{
}
{
}
}
{
DEBUG_YACC("t_enterprise")
if(parsing_oid == False)
{
}
{
}
}
{
DEBUG_YACC("t_dot")
}
{
DEBUG_YACC("t_agents")
}
{
DEBUG_YACC("t_name")
}
{
DEBUG_YACC("t_subtrees")
}
{
DEBUG_YACC("t_tables")
}
{
DEBUG_YACC("t_table")
}
{
DEBUG_YACC("t_columns")
}
{
DEBUG_YACC("t_indexs")
}
{
DEBUG_YACC("t_timeout")
}
{
DEBUG_YACC("t_watch_dog_time")
}
{
DEBUG_YACC("t_port")
}
{
DEBUG_YACC("t_quotedstring\n")
}
{
DEBUG_YACC("t_coma")
}
%%
#include "personal.lex.c"
/****************************************************************/
{
int new_len;
/* LINTED */
if(new_subids == NULL)
{
error("malloc() failed");
if(static_subids)
{
}
static_len = 0;
return -1;
}
/* LINTED */
/* LINTED */
if(static_subids)
{
}
return 0;
}
/****************************************************************/
{
{
return NULL;
}
{
error("malloc() failed");
return NULL;
}
{
error("malloc() failed");
return NULL;
}
/* LINTED */
{
error("malloc() failed");
return NULL;
}
/* LINTED */
first_macro = new;
return new;
}
/****************************************************************/
{
{
{
return mp;
}
}
return NULL;
}
/****************************************************************/
{
{
return;
}
{
}
{
}
return;
}
/****************************************************************/
static void macro_list_delete()
{
while(mp)
{
macro_free(mp);
}
first_macro = NULL;
return;
}
/****************************************************************/
int yyerror(char *s)
{
return (0);
}
/****************************************************************/
/* If we have a serious problem, this function will */
/* terminate (<==> exit) the program */
void config_init(char *filename)
{
char *fileaddr;
int fd;
yylineno = 1;
{
filename, errno_string());
}
/*
* get the size of the file
*/
{
filename, errno_string());
}
{
}
/*
* and map it into my address space
*/
{
read the last + 1 byte to decide EOF */
/* LINTED */
MAP_PRIVATE, fd, 0)) <= (char *) 0)
{
filename, errno_string());
}
/*
* set current lex focus on the file
*/
/*
* and parse the file
*/
if(yyparse() == 1)
{
}
/*
* Parsing is finished
*
* unmap the file and close it
*/
/* LINTED */
{
}
}
else
{
/* empty file, ignore it */
}
{
}
if(first_agent == NULL)
{
error_exit("No SNMP agent configured");
}
if(trace_level > 0)
{
trace_agents();
}
}
/****************************************************************/
static void table_list_delete()
{
while(first_table)
{
first_table = next;
}
first_table = NULL;
last_table = NULL;
}
/****************************************************************/
{
{
return;
}
{
}
/*
if(tp->indexs.subids)
{
free(tp->indexs.subids);
}
*/
}
/****************************************************************/
/*********** SNMP security (5-13-96) ******/
/* If we have a serious problem, this function will */
/* terminate (<==> exit) the program */
void sec_config_init(char *filename)
{
char *fileaddr;
int fd;
if(trap_community)
{
}
yylineno = 1;
{
filename, errno_string());
}
/*
* get the size of the file
*/
{
filename, errno_string());
}
{
}
/*
* and map it into my address space
*/
{
read the last + 1 byte to decide EOF */
/* LINTED */
MAP_PRIVATE, fd, 0)) <= (char *) 0)
{
filename, errno_string());
}
/*
* set current lex focus on the file
*/
/*
* and parse the file
*/
if(yyparse() == 1)
{
}
/*
* Parsing is finished
*
* unmap the file and close it
*/
/* LINTED */
{
errno_string());
}
}
else
{
/* empty file, ignore it */
}
{
}
if(trace_level > 0)
{
trace("\n");
trace_filter();
}
}
/*********** SNMP security (5-13-96) ******/
int yywrap()
{
return 1;
}
static int get_a_non_reserved_port()
{
struct sockaddr_in me;
int cnt=0;
int sd;
if(sd<0) return 0;
}
return 0;
}