PageRenderTime 8ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 3ms app.codeStats 0ms

/usr/src/cmd/agents/snmp/snmprelayd/config.y

https://bitbucket.org/osunix/osunix-gate
Happy | 2736 lines | 2237 code | 499 blank | 0 comment | 0 complexity | 604036c698476a8570c99b3ef90fa426 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1%{
   2/*
   3 * CDDL HEADER START
   4 *
   5 * The contents of this file are subject to the terms of the
   6 * Common Development and Distribution License (the "License").
   7 * You may not use this file except in compliance with the License.
   8 *
   9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 * or http://www.opensolaris.org/os/licensing.
  11 * See the License for the specific language governing permissions
  12 * and limitations under the License.
  13 *
  14 * When distributing Covered Code, include this CDDL HEADER in each
  15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 * If applicable, add the following below this CDDL HEADER, with the 
  17 * fields enclosed by brackets "[]" replaced with your own identifying
  18 * information: Portions Copyright [yyyy] [name of copyright owner]
  19 *
  20 * CDDL HEADER END
  21 */
  22
  23/*
  24 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  25 * Use is subject to license terms.
  26 */
  27
  28#pragma ident	"%Z%%M%	%I%	%E% SMI"
  29
  30/*
  31 * HISTORY
  32 * 5-13-96	Jerry Yeung		parse security config. file
  33 * 6-25-96      Jerry Yeung             parse trap info.
  34 * 6-27-96 	Jerry Yeung		optional port stmt
  35 * 6-28-96	Jerry Yeung		add setuid support
  36 * 7-03-96	Jerry Yeung		add watchdog, maxAgentTimeOut
  37 *					    pollInterval
  38 * 7-13-96	Jerry Yeung		remove resource_name
  39 * 7-17-96	Jerry Yeung		change reg file suffix
  40 * 7-17-96	Jerry Yeung		change personal to registration_file
  41 */
  42%}
  43
  44%start configuration
  45
  46%token NUMBER
  47%token MACROS
  48%token EQUAL
  49%token OPENBRACKET
  50%token CLOSEBRACKET
  51%token IDENTIFIER
  52%token MIB2
  53%token SUN
  54%token ENTERPRISE
  55%token DOT
  56%token AGENTS
  57%token NAME
  58%token SUBTREES
  59%token TABLES
  60%token TABLE
  61%token COLUMNS
  62%token INDEXS
  63%token TIMEOUT
  64%token PORT
  65%token QUOTEDSTRING
  66%token COMMA
  67%token MINUS
  68%token OPENSQUAREBRACKET
  69%token CLOSESQUAREBRACKET
  70%token WATCHDOGTIME
  71%token MAXAGENTTIMEOUT
  72%token POLLINTERVAL
  73%token ENVIRONMENT
  74
  75/* support SNMP security(5-13-96) */
  76%token COMMUNITIES
  77%token READONLY
  78%token READWRITE
  79%token MANAGERS
  80%token TRAPCOMMUNITY
  81%token TRAPDESTINATORS
  82%token ACL
  83%token ACCESS
  84%token TRAPNUM
  85%token HOSTS
  86%token TRAP
  87
  88/* support resource */
  89%token RESOURCE
  90%token REGISTRATION_FILE
  91%token SECURITY
  92%token POLICY
  93%token TYPE
  94%token COMMAND
  95%token DIRECTORY
  96%token USER
  97
  98%{
  99#include <unistd.h>
 100#include <stdio.h>
 101#include <sys/types.h>
 102#include <sys/stat.h>
 103#include <sys/mman.h>
 104#include <netinet/in.h>
 105#include <fcntl.h>
 106#include <dirent.h>
 107#include <string.h>
 108
 109#include "impl.h"
 110#include "error.h"
 111#include "trace.h"
 112#include "pdu.h"
 113
 114#include "snmprelay_msg.h"
 115#include "agent.h"
 116#include "subtree.h"
 117#include "session.h"
 118#include "dispatcher.h"
 119
 120/** SNMP security (5-13-96) */
 121#include "trap.h"
 122#include "access.h"
 123
 124#include "res.h"
 125#include "sh_table.h"
 126
 127
 128/***** DEFINE *****/
 129
 130/*
 131 #define DEBUG_YACC(string) printf("\t\tYACC: %s: %s at line %d\n", string, yytext, yylineno);
 132*/
 133
 134#define DEBUG_YACC(string) 
 135
 136/*
 137#define SNMPRELAY_SUFFIX	".snmprelay" 
 138*/
 139#define SNMPRELAY_SUFFIX	".reg"
 140#define SNMPRESOURCE_SUFFIX	".rsrc"
 141#define SNMPRELAY_REG_FILE	"snmpdx.reg"
 142#define SNMPACL_SUFFIX		".acl"
 143
 144
 145/***** TYPEDEF *****/
 146
 147typedef struct _Macro {
 148	struct _Macro *next_macro;
 149	char *label;
 150	Oid name;
 151} Macro;
 152
 153
 154/***** GLOBAL VARIABLES *****/
 155
 156char config_file_4_res[300] = "";
 157
 158
 159/***** STATIC VARIABLES AND FUNCTIONS *****/
 160/*(6-18) reconfig */
 161#define RES_PARSING_STATE_FROM_SCRATCH 0
 162#define RES_PARSING_STATE_RE_READ 1
 163static time_t last_res_modify_time=0;
 164static int res_parsing_state =0; /* 0:init */
 165
 166/* access control(6-20-96) */
 167static AccessServer *static_access_server=NULL;
 168static AccessPolicy *static_access_policy=NULL;
 169static Community *static_community=NULL;
 170
 171/* trap filter (6-25-96) */
 172static SubMember *static_sub_member=NULL;
 173static Manager *static_host=NULL;
 174static EFilter *static_filter=NULL;
 175static int static_trap_low=-1;
 176static int static_trap_high=-1;
 177
 178/* snmp security(5-13-96) */
 179static int community_type = 0;
 180static char *current_filename = NULL;
 181
 182/* lexinput points to the current focus point in the config file */
 183static char *lexinput;
 184
 185/* first_macro is the begining of the list	*/
 186/* of the user defined macros			*/
 187
 188static Macro *first_macro = NULL;
 189
 190
 191/* the boolean parsing_oid is used to		*/
 192/* know if we are parsing an			*/
 193/* object identifier or not.			*/
 194
 195static int parsing_oid = False;
 196
 197
 198/* here are the values of the predifined macros	*/
 199/* that can be used in the configuration file	*/
 200
 201static Subid subids_mib2[] = { 1, 3, 6, 1, 2, 1 };
 202static int mib2_len = 6;
 203static Subid subids_enterprise[] = { 1, 3, 6, 1, 4, 1 };
 204static int enterprise_len = 6;
 205static Subid subids_sun[] = { 1, 3, 6, 1, 4, 1, 42 };
 206static int sun_len = 7;
 207
 208/* the 2 static variables static_subids and	*/
 209/* static_len are used when parsing an	*/
 210/* object identifier. Then the boolean		*/
 211/* parsing_oid should be true. When a new sub-	*/
 212/* identifier (or a list of sub-identifiers)	*/
 213/* is found, we use the function		*/
 214/* subids_cat to append it to the static_subids.*/
 215
 216static Subid *static_subids = NULL;
 217static int static_len = 0;
 218static int subids_cat(Subid *subids, int len);
 219
 220
 221/* macro_add() is used to append a macro to	*/
 222/* the macro list. macro_find is used to find	*/
 223/* a macro in the macro list			*/
 224
 225static Macro *macro_add(char *label, Subid *subids, int len);
 226static Macro *macro_find(char *label);
 227static void macro_free(Macro *mp);
 228static void macro_list_delete();
 229static void trace_macros();
 230
 231
 232/* static_label is used when parsing a macro	*/
 233static char *static_label = NULL;
 234
 235/* static_agent is used when parsing an agent	*/
 236static Agent *static_agent = NULL;
 237
 238/* resource support */
 239static SapResource *static_res = NULL;
 240
 241/* static_table is used when parsing n table	*/
 242static Table *static_table = NULL;
 243Table *tmp_table;
 244
 245/* static_inf_value and static_max_value are	*/
 246/* used when parsing a range			*/
 247static int static_inf_value = -1;
 248static int static_sup_value = -1;
 249
 250char *save_string = NULL;
 251char *com_string = NULL;
 252char *host_string = NULL;
 253int found_dot=FALSE;
 254int found_comma=FALSE;
 255
 256
 257%}
 258
 259%%
 260
 261
 262configuration :	agents | macros agents | snmp_security | environment resources
 263		{
 264			DEBUG_YACC("configuration")
 265		}
 266
 267/******************* SNMP security (5-13-96) *********/
 268snmp_security : acls trap_block /*trapcommunity trapdestinators*/
 269                {
 270                        DEBUG_YACC("security configuration")
 271                }
 272
 273/***************/
 274/* accesscontrol */
 275/***************/
 276
 277acls :	/*empty*/ |t_acls t_equal t_openbracket acls_list t_closebracket
 278	{
 279		DEBUG_YACC("acls_list1")
 280	}
 281	| t_acls t_equal t_openbracket error t_closebracket
 282	{
 283	          DEBUG_YACC("acls_listError")	
 284		  error("BUG: acl stmt parsing error at line %d",yylineno);
 285                  if(static_access_policy != NULL){
 286                        access_policy_list_free(static_access_policy);
 287                        static_access_policy = NULL;
 288		  }
 289	}
 290
 291acls_list : /*empty*/ | acls_list acl_item 
 292	{
 293		DEBUG_YACC("acls_list2")
 294	}
 295
 296acl_item : t_openbracket 
 297	{
 298		static_access_policy = calloc(1,sizeof(AccessPolicy));
 299		if(static_access_policy == NULL)
 300		{
 301			error("malloc() failed");
 302			YYERROR;
 303		}
 304	} communities_stmt acl_access
 305	{
 306		if(static_access_policy!=NULL)
 307			static_access_policy->access_type = community_type;	
 308	} hosts t_closebracket
 309	{
 310		/* create AccessServer */
 311		/* put the AccessPolicy into AccessServer */
 312		/* put AccessServer into corresponding manager */
 313
 314                {
 315                        /* Hack to send last community string which is a dot string */
 316
 317                        if (com_string != NULL)
 318                        {                  /* add community into AccessPolicy */
 319                           static_community = calloc(1,sizeof(Community));
 320                           if(static_community == NULL)
 321                           {
 322                              error("malloc() failed");
 323                              YYERROR;
 324                           }
 325                           static_community->name = strdup(com_string);
 326                           community_attach(static_access_policy,static_community);
 327                           static_community = NULL;
 328                           free(com_string);
 329			   com_string=NULL;
 330                           found_comma = FALSE;
 331                        }
 332                        /* Hack to send last manager host string which is a dot string */
 333
 334                        if (host_string != NULL)
 335                        {
 336                            Manager *res;
 337
 338                           res = manager_add(host_string, error_label);
 339                           if(res==NULL){
 340                               error("error in %s at line %d: %s",
 341                                     current_filename? current_filename:
 342"???",
 343                                     yylineno, error_label);
 344                           }
 345                           static_access_server = calloc(1,sizeof(AccessServer));
 346                           if(static_access_server == NULL)
 347                           {
 348                              error("malloc() failed");
 349                              if(static_access_policy)
 350                              access_policy_list_free(static_access_policy);
 351                              YYERROR;
 352                           }
 353                              if(static_access_policy!=NULL)
 354                              	static_access_policy->count++;
 355                              static_access_server->first_acc_policy = static_access_policy;
 356                              access_server_add_tail(res,static_access_server);
 357                              static_access_server = NULL;
 358			      free(host_string);
 359		              host_string=NULL;	
 360                   	      found_comma = FALSE;
 361                        }
 362                }
 363                static_access_server = NULL;
 364                static_access_policy = NULL;
 365                static_community = NULL;
 366                community_type = 0;
 367	}
 368
 369communities_stmt :    t_communities t_equal communities_set
 370	{
 371		DEBUG_YACC("communities_stmt");
 372	}
 373
 374communities_set : communities_set  t_comma community_elem | community_elem
 375	{
 376                DEBUG_YACC("communities_set");
 377	}
 378
 379community_elem : community_elem  t_dot community_item | t_dot community_elem | community_item
 380        {
 381               DEBUG_YACC("community_elem")
 382        }
 383
 384community_item : ct_identifier
 385 	{
 386		DEBUG_YACC("community_item")
 387		if(static_access_policy==NULL){
 388			error("acl statement error");
 389			YYERROR;
 390		}
 391
 392                if (found_comma && (com_string != NULL))
 393                {
 394		     static_community = calloc(1,sizeof(Community));
 395                     if(static_community == NULL)
 396                     {
 397                        error("malloc() failed");
 398                        YYERROR;
 399                     }
 400
 401	             static_community->name = strdup(com_string);
 402                     community_attach(static_access_policy,static_community);
 403                     static_community = NULL;
 404	             free(com_string);
 405	             com_string=NULL;	
 406                     found_comma=FALSE;
 407                }
 408                if (com_string == NULL && found_dot == FALSE)
 409	        {
 410                    /* com_string= strdup(save_string);*/
 411                    /* first part of community string */
 412                    com_string=malloc(50);
 413                    if(com_string == NULL){
 414                        error("malloc() failed");
 415                        YYERROR;
 416                    }
 417                    strcpy(com_string,save_string);
 418                    free(save_string);
 419                }
 420
 421                 
 422		if (found_dot )
 423		{
 424			if (com_string == NULL)
 425				com_string = malloc(50);
 426			strcat(com_string,".");
 427					/* allow a dot in community string */
 428			strcat(com_string,save_string);
 429					/* add part after the dot    */
 430			free(save_string);
 431			found_dot=FALSE;
 432		}
 433	}
 434
 435acl_access :	t_access t_equal acl_access_type
 436	{
 437		DEBUG_YACC("acl_access")
 438        }
 439
 440acl_access_type : t_readonly | t_readwrite
 441		{
 442			DEBUG_YACC("acl_access_type")      
 443		}
 444
 445hosts : t_managers t_equal hosts_list
 446	{
 447		DEBUG_YACC("hosts")
 448	}
 449
 450hosts_list : hosts_list t_comma host_elem | host_elem 
 451	{
 452		DEBUG_YACC("hosts_list");
 453	}
 454
 455host_elem : host_elem t_dot host_item | host_item
 456        {
 457                DEBUG_YACC("host_elem");
 458	}
 459
 460host_item :  ct_identifier 
 461	{
 462		/* add the host item to manager list */
 463		/* it should return the pointer if exists */
 464                Manager *res;
 465 
 466                DEBUG_YACC("manager_item")
 467
 468		if (found_comma && (host_string != NULL))
 469		{
 470                	res = manager_add(host_string, error_label);
 471                	if(res==NULL)
 472			{
 473                                error("error in %s at line %d: %s",
 474                                        current_filename? current_filename:
 475"???",
 476                                        yylineno, error_label);
 477                	} 
 478                	static_access_server = calloc(1,sizeof(AccessServer));
 479                	if(static_access_server == NULL)
 480                	{
 481                        	error("malloc() failed");
 482                        	if(static_access_policy)
 483                          	access_policy_list_free(static_access_policy);
 484                        	YYERROR;
 485                	}
 486                	if(static_access_policy!=NULL)
 487                        	static_access_policy->count++;
 488                	static_access_server->first_acc_policy = static_access_policy;
 489			access_server_add_tail(res,static_access_server);
 490			static_access_server = NULL;
 491                        free(host_string);
 492			host_string=NULL;
 493			found_comma = FALSE;
 494		}
 495		if (host_string == NULL)
 496                {
 497		    /* host_string= strdup(save_string);*/
 498                    /* first part of host string */
 499                    host_string=malloc(50);
 500                    if(host_string == NULL){
 501                        error("malloc() failed");
 502                        YYERROR;
 503	            }	
 504                    strcpy(host_string,save_string);
 505                    free(save_string);
 506                }
 507                    
 508
 509                if (found_dot )
 510                {
 511                     strcat(host_string,".");           /* allow a dot in hoststring */
 512                     strcat(host_string,save_string);   /* add part after the dot    */
 513                     free(save_string);
 514                     found_dot=FALSE;
 515                }
 516
 517	}
 518
 519/***************/
 520/* communities */
 521/***************/
 522
 523/*
 524
 525communities :	t_communities t_equal t_openbracket communities_list t_closebracket
 526		{
 527			DEBUG_YACC("communities")
 528		}
 529		| t_communities t_equal t_openbracket error t_closebracket
 530		{
 531		  error("BUG: community stmt parsing error at line %d",yylineno);
 532		  if(community_name != NULL) free(community_name);
 533		}
 534
 535
 536communities_list :  | communities_list community_item
 537		{
 538			DEBUG_YACC("communities_list")
 539		}
 540
 541
 542community_item : ct_identifier
 543		{
 544			DEBUG_YACC("community_item 1")
 545
 546			if(community_name)
 547			{
 548				error("BUG: community_name is not NULL in community_item");
 549			}
 550
 551			community_name = strdup(yytext);
 552			if(community_name == NULL)
 553			{
 554				error(ERR_MSG_ALLOC);
 555				YYERROR;
 556			}
 557		}
 558		communitytype
 559		{
 560			int res;
 561
 562			DEBUG_YACC("community_item 2")
 563
 564			if(community_name == NULL)
 565			{
 566				error("BUG: community_name is NULL in community_item");
 567			}
 568
 569			res = community_add(community_name, community_type, error_label);
 570			switch(res)
 571			{
 572				case 0:
 573					break;
 574
 575				case 1:
 576					error("error in %s at line %d: %s",
 577						current_filename? current_filename: "???",
 578						yylineno, error_label);
 579					break;
 580
 581				default:
 582					error("fatal error in %s at line %d: %s",
 583						current_filename? current_filename: "???",
 584						yylineno, error_label);
 585					YYERROR;
 586			}
 587
 588			free(community_name);
 589			community_name = NULL;
 590		}
 591
 592communitytype : t_readonly | t_readwrite
 593		{
 594			DEBUG_YACC("community_type")
 595		}
 596*/
 597
 598/************/
 599/* managers */
 600/************/
 601 
 602/*
 603managers :      t_managers t_equal t_openbracket managers_list t_closebracket
 604                {
 605                        DEBUG_YACC("agents")
 606                }
 607	 	| t_managers t_equal t_openbracket error t_closebracket
 608		{
 609		  error("BUG: managers stmt parsing error at line %d",yylineno);
 610		} 
 611 
 612managers_list :  | managers_list list_separator manager_item
 613                {
 614                        DEBUG_YACC("managers_list")
 615                }
 616 
 617manager_item :  ct_identifier
 618                {
 619                        Manager *res;
 620 
 621                        DEBUG_YACC("manager_item")
 622 
 623                        res = manager_add(yytext, error_label);
 624                        if(res==NULL){
 625                                        error("error in %s at line %d: %s",
 626                                                current_filename? current_filename:
 627"???",
 628                                                yylineno, error_label);
 629                        } 
 630                }
 631*/
 632
 633/*** trap hanlding (6-25-96) */
 634trap_block :    t_trap t_equal t_openbracket trap_list t_closebracket
 635                {
 636                        DEBUG_YACC("trap_block")
 637			found_comma = FALSE;
 638                }
 639                | t_trap t_equal t_openbracket error t_closebracket
 640                {
 641                        /* clean up */
 642                        if(static_sub_member != NULL){
 643                          sub_member_free(static_sub_member);
 644                          static_sub_member=NULL;
 645                        }
 646                }
 647
 648trap_list : /*empty*/ | trap_list trap_item
 649        {
 650                DEBUG_YACC("trap_list")
 651        }
 652
 653trap_item : t_openbracket
 654        {
 655                /* create submember */
 656                static_sub_member = calloc(1,sizeof(SubMember));
 657                if(static_sub_member == NULL)
 658                {
 659                        error("malloc() failed");
 660                        YYERROR;
 661                }
 662        } trap_community_string trap_interest_hosts
 663        {
 664                /* attach submember to subgroup */
 665        } enterprise_list t_closebracket
 666        {
 667                static_sub_member = NULL;
 668        }
 669 
 670trap_community_string : t_trapcommunity t_equal ct_identifier
 671        {
 672                /* set the community field in submember */
 673                if(static_sub_member != NULL)
 674                {
 675                        static_sub_member->community_string = strdup(yytext);
 676                        if(static_sub_member == NULL)
 677                        {
 678                                error(ERR_MSG_ALLOC);
 679                                YYERROR;
 680                        }
 681                }else{
 682                        error("BUG: missing trap community name");
 683                }
 684        }
 685 
 686trap_interest_hosts : t_hosts t_equal trap_interest_hosts_list
 687        {
 688                DEBUG_YACC("trap_interest_hosts")
 689        }
 690 
 691trap_interest_hosts_list : trap_interest_hosts_list t_comma
 692                 trap_interest_host_item | trap_interest_host_item
 693        {
 694                DEBUG_YACC("trap_interest_hosts_list")
 695        }
 696 
 697trap_interest_host_item : ct_identifier
 698        {
 699                DEBUG_YACC("trap_interest_host_item")
 700                /* attach host to the submember */
 701                if(static_sub_member==NULL){
 702                        error("trap statement error");
 703                        YYERROR;
 704                }else{
 705                  static_host = calloc(1,sizeof(Manager));
 706                  if(static_host == NULL)
 707                  {
 708                        error("malloc() failed");
 709                        YYERROR;
 710                  }
 711                  static_host->name = strdup(yytext);
 712                  if(name_to_ip_address(static_host->name,
 713                        &static_host->ip_address,error_label)){
 714                        error("unknown host %s",static_host->name);
 715                        free(static_host);
 716                        static_host=NULL;
 717                        YYERROR;
 718                  }
 719                  static_host->next_manager = static_sub_member->first_manager;
 720                  static_sub_member->first_manager=static_host;
 721                  static_host=NULL;
 722                }
 723        }
 724 
 725enterprise_list : /* empty */ | enterprise_list enterprise_item
 726        {
 727                DEBUG_YACC("enterprise_list")
 728        }
 729
 730enterprise_item : t_openbracket enterprise_stmt trap_number_stmt
 731                  t_closebracket
 732                {
 733                        DEBUG_YACC("enterprise_item")
 734                }
 735 
 736enterprise_stmt : ENTERPRISE t_equal t_quotedstring
 737                {
 738                        /* currently, it supports single enterprise */
 739 
 740                        DEBUG_YACC("enterprise_stmt")
 741                        /* add or find the enterprise */
 742                        static_filter = efilter_add(quoted_string,error_label);
 743                        if(static_filter==NULL){
 744                          error("error in %s at line %d: %s",
 745                                current_filename?current_filename:"???",
 746                                yylineno,error_label);
 747                        }
 748                }
 749 
 750trap_number_stmt : t_trap_num t_equal trap_number_list
 751                {
 752                        DEBUG_YACC("trap_number_stmt")
 753                }
 754
 755trap_number_list : trap_number_item
 756                {
 757                        DEBUG_YACC("trap_number_list")
 758                }
 759                | trap_number_list t_comma trap_number_item
 760                {
 761                        DEBUG_YACC("trap_number_list")
 762                }
 763
 764trap_number_item : trap_range
 765	{
 766			DEBUG_YACC("trap_number_item")
 767                        /* for each trap, find/add to the
 768                           enterprise, and add_tailthe subgroup
 769                           to each trap */
 770 
 771                        if(static_filter!=NULL){
 772                                /* expand the trap */
 773                                mem_filter_join(static_trap_low,
 774                                        static_trap_high,static_sub_member,
 775                                        static_filter);
 776                        }else{
 777                                error("error in enterprise statement");
 778                                YYERROR;
 779                        }
 780	
 781	}
 782
 783trap_range :    NUMBER
 784                {
 785                        /* starting trap num */
 786                        static_trap_low = token_value;
 787                }
 788                t_minus  NUMBER
 789                {
 790                        /* ending trap num */
 791                        static_trap_high = token_value;
 792                }
 793                | NUMBER
 794                {
 795                        /* start & end num the same */
 796                        DEBUG_YACC("trap_range")
 797                        static_trap_low=static_trap_high=token_value;
 798                }
 799 
 800/* 
 801trapcommunity : t_trapcommunity t_equal ct_identifier
 802                {
 803                        DEBUG_YACC("trap_community")
 804
 805                        if(trap_community)
 806                        {
 807                                error("BUG: trap_community not NULL in trap_community");
 808                        }
 809
 810                        trap_community = strdup(yytext);
 811                        if(trap_community == NULL)
 812                        {
 813                                error(ERR_MSG_ALLOC);
 814                                YYERROR;
 815                        }
 816                }
 817*/
 818
 819/*******************/
 820/* trapdestinators */
 821/*******************/
 822
 823/*
 824trapdestinators : t_trapdestinators t_equal t_openbracket trapdestinators_list t_closebracket
 825                {
 826                        DEBUG_YACC("trapdestinators")
 827                }
 828		| t_trapdestinators t_equal t_openbracket error t_closebracket
 829		{
 830		  error("BUG: trapdestinators stmt parsing error at line %d",yylineno);
 831		}
 832
 833
 834trapdestinators_list :  | trapdestinators_list list_separator trapdestinator_item
 835                {
 836                        DEBUG_YACC("trapdestinators_list")
 837                }
 838
 839
 840trapdestinator_item : ct_identifier
 841                {
 842                        int res; 
 843
 844                        DEBUG_YACC("trapdestinator_item")
 845 
 846                        res = trap_destinator_add(yytext, error_label);
 847                        switch(res)
 848                        {
 849                                case 0:
 850                                        break;
 851 
 852                                case 1:
 853                                        error("error in %s at line %d: %s",
 854                                                current_filename? current_filename:
 855"???",
 856                                                yylineno, error_label);
 857                                        break;
 858 
 859                                default:
 860                                        error("fatal error in %s at line %d: %s",
 861                                                current_filename? current_filename:
 862"???",
 863                                                yylineno, error_label);
 864                                        YYERROR;
 865                        }
 866                }
 867
 868*/
 869
 870/******************* SNMP security (5-13-96) *********/
 871
 872
 873
 874
 875/**********/
 876/* macros */
 877/**********/
 878
 879macros :	t_macros t_equal t_openbracket macros_list t_closebracket
 880		{
 881			DEBUG_YACC("macros")
 882		}
 883		| t_macros t_equal t_openbracket error t_closebracket
 884		{ error("BUG at line %d: macro-parsing error", yylineno); 
 885			parsing_oid = False;
 886			if(static_label != NULL) free(static_label);
 887			static_label = NULL;
 888			if(static_subids != NULL) free(static_subids);
 889			static_subids = NULL;
 890			static_len = 0;
 891		}
 892
 893
 894macros_list :	/* empty */ | macros_list macro_item
 895		{
 896			DEBUG_YACC("macros_list")
 897		}
 898
 899
 900macro_item :	label t_equal
 901		{
 902			if(parsing_oid != False)
 903			{
 904				error("BUG at line %d: parsing_oid not False in macro_item", yylineno);
 905			}
 906			parsing_oid = True;
 907
 908			if(static_subids != NULL)
 909			{
 910				error("BUG at line %d: static_subids not NULL in macro_item", yylineno);
 911			}
 912			if(static_len != 0)
 913			{
 914				error("BUG at line %d: static_len not 0 in macro_item", yylineno);
 915			}
 916		}
 917		subids_list
 918		{
 919			DEBUG_YACC("macro_item")
 920	
 921			if(macro_add(static_label, static_subids, static_len) == NULL)
 922			{
 923				error("error at line %d", yylineno);
 924				YYERROR;
 925			}
 926
 927			parsing_oid = False;
 928			free(static_label);
 929			static_label = NULL;
 930			free(static_subids);
 931			static_subids = NULL;
 932			static_len = 0;
 933		}
 934
 935
 936label :		t_identifier
 937		{
 938			DEBUG_YACC("label")
 939
 940			if(static_label != NULL)
 941			{
 942				error("BUG at line %d: static_label not NULL in label", yylineno);
 943			}
 944			static_label = strdup(yytext);
 945			if(static_label == NULL)
 946			{
 947				error("malloc() failed");
 948				YYERROR;
 949			}
 950		}
 951
 952/************/
 953/* environment */
 954/************/
 955
 956environment:	/*empty*/ | t_environment t_equal t_openbracket environment_list 
 957		t_closebracket
 958		{
 959			DEBUG_YACC("environment")
 960		}
 961
 962environment_list: /* empty */ | environment_list environment_item
 963		{
 964			DEBUG_YACC("environment_list")
 965		}
 966
 967environment_item: 	poll_interval | max_agent_time_out
 968		{
 969			DEBUG_YACC("environment_item")
 970		}
 971
 972poll_interval:	t_poll_interval t_equal NUMBER
 973		{
 974			DEBUG_YACC("poll_interval")
 975			relay_agent_poll_interval = token_value;
 976		}
 977
 978max_agent_time_out:	t_max_agent_time_out t_equal NUMBER
 979		{
 980			DEBUG_YACC("max_agent_time_out")
 981			relay_agent_max_agent_time_out = token_value;
 982		}
 983			
 984
 985/***********/
 986/* resouces */
 987/************/
 988
 989resources:	/*empty*/ | t_resource t_equal t_openbracket resources_list t_closebracket
 990		{
 991			DEBUG_YACC("resources")
 992		}
 993
 994resources_list:	/*empty*/ | resources_list resource_item
 995			{
 996				DEBUG_YACC("resources_list")
 997			}
 998resource_item:	t_openbracket
 999		{
1000		  if(static_res != NULL)
1001			error("BUG at line%d: static_res not NULL",yylineno);
1002		  static_res = malloc(sizeof(SapResource));
1003		  if(static_res == NULL)
1004		  {
1005			error("malloc() failed");
1006			YYERROR;
1007		  }
1008		  memset(static_res,0,sizeof(SapResource));
1009		}
1010		fileslist policy res_type user start_cmd t_closebracket
1011		{
1012			DEBUG_YACC("agent_item")
1013		   if(res_parsing_state == RES_PARSING_STATE_RE_READ){
1014			if(reconfig_first_res == NULL)
1015			{
1016				static_res->next_res = NULL;
1017			}
1018			else
1019			{
1020				static_res->next_res = reconfig_first_res;
1021			}
1022			reconfig_first_res = static_res;
1023		   }else{
1024			if(first_res == NULL)
1025			{
1026				static_res->next_res = NULL;
1027			}
1028			else
1029			{
1030				static_res->next_res = first_res;
1031			}
1032			first_res = static_res;
1033		  }
1034		  static_res = NULL;
1035		}
1036		| t_openbracket error t_closebracket
1037		{ 
1038			error("BUG at line %d: resource stmt error",yylineno);
1039		   if(static_res != NULL){
1040			if(static_res->dir_file != NULL)
1041				free(static_res->dir_file);
1042			if(static_res->personal_file != NULL)
1043				free(static_res->personal_file);
1044			if(static_res->sec_file != NULL)
1045				free(static_res->sec_file);
1046			if(static_res->policy != NULL)
1047				free(static_res->policy);
1048			if(static_res->type != NULL)
1049				free(static_res->type);
1050			if(static_res->start_cmd != NULL)
1051				free(static_res->start_cmd);
1052			free(static_res);
1053		   }
1054			static_res = NULL;
1055		}
1056	
1057
1058fileslist:	file_item | fileslist file_item
1059		{
1060			DEBUG_YACC("fileslist");
1061		}
1062file_item:	personal_file | sec_file | directory_file
1063		{
1064			DEBUG_YACC("file_item");
1065		}
1066
1067personal_file:	t_registration_file t_equal t_quotedstring
1068		{
1069		  DEBUG_YACC("personal_file")
1070		  if(static_res->personal_file != NULL) 
1071			error("BUG at line %d: static_res->personal_file not NULL ",yylineno);
1072		  static_res->personal_file = strdup(quoted_string);
1073		  if(static_res->personal_file == NULL){
1074			error("malloc() failed");
1075			YYERROR;
1076		  }			
1077		}
1078sec_file:	t_sec_fname t_equal t_quotedstring
1079		{
1080		  DEBUG_YACC("sec_file")
1081		  if(static_res->sec_file != NULL) 
1082			error("BUG at line %d: static_res->sec_file not NULL ",yylineno);
1083		  static_res->sec_file = strdup(quoted_string);
1084		  if(static_res->sec_file == NULL){
1085			error("malloc() failed");
1086			YYERROR;
1087		  }			
1088		}
1089
1090directory_file:	t_dir_fname t_equal t_quotedstring
1091		{
1092		  DEBUG_YACC("directory_file")
1093		  if(static_res->dir_file != NULL) 
1094			error("BUG at line %d: static_res->dir_file not NULL ",yylineno);
1095		  static_res->dir_file = strdup(quoted_string);
1096		  if(static_res->dir_file == NULL){
1097			error("malloc() failed");
1098			YYERROR;
1099		  }			
1100		}
1101
1102policy: 	/*empty*/ | t_policy t_equal t_quotedstring
1103		{
1104		  DEBUG_YACC("policy")
1105		  if(static_res->policy != NULL) 
1106			error("BUG at line %d: static_res->policy not NULL ",yylineno);
1107		  static_res->policy = strdup(quoted_string);
1108		  if(static_res->policy == NULL){
1109			error("malloc() failed");
1110			YYERROR;
1111		  }
1112		}
1113
1114
1115user: 	/*empty*/ | t_user t_equal t_quotedstring
1116		{
1117		  DEBUG_YACC("user")
1118		  if(static_res->user != NULL) 
1119			error("BUG at line %d: static_res->user not NULL ",yylineno);
1120		  static_res->user = strdup(quoted_string);
1121		  if(static_res->user == NULL){
1122			error("malloc() failed");
1123			YYERROR;
1124		  }
1125		}
1126
1127res_type: 	/*empty*/ | t_res_type t_equal t_quotedstring
1128		{
1129		  DEBUG_YACC("res_type")
1130		  if(static_res->type != NULL) 
1131			error("BUG at line %d: static_res->type not NULL ",yylineno);
1132		  static_res->type = strdup(quoted_string);
1133		  if(static_res->type == NULL){
1134			error("malloc() failed");
1135			YYERROR;
1136		  }
1137		}
1138
1139
1140
1141start_cmd:	t_command t_equal t_quotedstring
1142		{
1143		  DEBUG_YACC("start_cmd")
1144		  if(static_res->start_cmd != NULL) 
1145			error("BUG at line %d: static_res->start_cmd not NULL ",yylineno);
1146		  static_res->start_cmd = strdup(quoted_string);
1147		  if(static_res->start_cmd == NULL){
1148			error("malloc() failed");
1149			YYERROR;
1150		  }			
1151		}
1152
1153t_resource:	RESOURCE
1154		{
1155			DEBUG_YACC("t_resource");
1156		}
1157
1158t_registration_file:	REGISTRATION_FILE
1159		{
1160			DEBUG_YACC("t_registration_file");
1161		}
1162
1163t_sec_fname:	SECURITY
1164		{
1165			DEBUG_YACC("t_sec_file");
1166		}
1167
1168t_dir_fname:	DIRECTORY
1169		{
1170			DEBUG_YACC("t_dir_fname");
1171		}
1172
1173t_policy:	POLICY
1174		{
1175			DEBUG_YACC("t_policy");
1176		}
1177
1178t_res_type:	TYPE
1179		{
1180			DEBUG_YACC("t_res_type");
1181		}
1182
1183t_user:		USER
1184		{
1185			DEBUG_YACC("t_user");
1186		}
1187
1188t_command:	COMMAND
1189		{
1190			DEBUG_YACC("t_command");
1191		}
1192
1193/**********/
1194/* agents */
1195/**********/
1196
1197agents :	t_agents t_equal t_openbracket agents_list t_closebracket
1198		{
1199			DEBUG_YACC("agents")
1200		}
1201
1202
1203agents_list :	/*empty */ | agents_list agent_item
1204		{
1205			DEBUG_YACC("agents_list")
1206		}
1207
1208
1209agent_item :		t_openbracket
1210		{
1211			if(static_agent != NULL)
1212			{
1213				error("BUG at line %d: static_agent not NULL in agent", yylineno);
1214			}
1215			static_agent = malloc(sizeof(Agent));
1216			if(static_agent == NULL)
1217			{
1218				error("malloc() failed");
1219				YYERROR;
1220			}
1221			memset(static_agent, 0, sizeof(Agent));
1222			static_agent->agentID = sap_agent_id++;
1223			/* Bug fix 4145620 - The subagents listen on the loopback driver */
1224			static_agent->address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
1225			static_agent->agentStatus = SSA_OPER_STATUS_INIT;
1226		}
1227		name subtrees_tables timeout optional_watch_dog_time optional_port t_closebracket
1228		{
1229			DEBUG_YACC("agent_item");
1230
1231			if(first_agent == NULL)
1232			{
1233				static_agent->next_agent = NULL;
1234			}
1235			else
1236			{
1237				static_agent->next_agent = first_agent;
1238			}
1239			first_agent = static_agent;
1240			static_agent = NULL;
1241		}
1242		| t_openbracket error t_closebracket
1243		{ 
1244			error("BUG at line %d: agent statement error",yylineno);
1245			if(static_agent != NULL){ 
1246				delete_all_subtree_from_agent(static_agent);
1247				delete_all_tables_for_agent(static_agent);
1248				if(static_agent->agentName.chars != NULL){
1249				  free(static_agent->agentName.chars);
1250				  static_agent->agentName.chars = NULL;
1251				}
1252				static_agent->agentName.len = 0;
1253				if(static_agent->name != NULL){
1254					free(static_agent->name);
1255					static_agent->name = NULL;
1256				}
1257				free(static_agent);
1258				static_agent = NULL;
1259			}
1260			/* clean up */
1261		}
1262
1263
1264name :		t_name t_equal t_quotedstring
1265		{
1266			DEBUG_YACC("name")
1267
1268			if(static_agent->name != NULL)
1269			{
1270				error("BUG at line %d: static_agent->name not NULL in name", yylineno);
1271			}
1272			static_agent->name = strdup(quoted_string);
1273			(static_agent->agentName).chars = 
1274				(u_char*)strdup(static_agent->name);
1275			(static_agent->agentName).len = strlen(static_agent->name);
1276
1277			if(static_agent->name == NULL)
1278			{
1279				error("malloc() failed");
1280				YYERROR;
1281			}
1282		}
1283
1284
1285subtrees_tables :  subtrees tables | subtrees | tables
1286		{
1287			DEBUG_YACC("subtrees_tables")
1288		}
1289
1290
1291subtrees :	t_subtrees t_equal t_openbracket
1292		{
1293			if(parsing_oid != False)
1294			{
1295				error("BUG at line %d: parsing_oid is not False in subtrees", yylineno);
1296			}
1297			parsing_oid = True;
1298
1299			if(static_subids != NULL)
1300			{
1301				error("BUG at line %d: static_subids not NULL in subtrees", yylineno);
1302			}
1303			if(static_len != 0)
1304			{
1305				error("BUG at line %d: static_len not 0 in subtrees", yylineno);
1306			}
1307		}
1308		subtrees_list t_closebracket
1309		{
1310			DEBUG_YACC("subtrees")
1311
1312			if(parsing_oid != True)
1313			{
1314				error("BUG at line %d: parsing_oid is not True in subtrees", yylineno);
1315			}
1316			parsing_oid = False;
1317		}
1318
1319
1320subtrees_list : /* empty */ | subtrees_list_comma_separated
1321		{
1322			DEBUG_YACC("subtrees_list")
1323		}
1324
1325
1326subtrees_list_comma_separated : subtree_item | subtrees_list_comma_separated t_comma subtree_item
1327		{
1328			DEBUG_YACC("subtrees_list_comma_separated")
1329		}
1330
1331
1332subtree_item : subids_list
1333		{
1334			Subtree *sp;
1335
1336
1337			DEBUG_YACC("subtree_item")
1338
1339			if(parsing_oid != True)
1340			{
1341				error("BUG at line %d: parsing_oid is not True in subtree_item", yylineno);
1342			}
1343
1344			if(subtree_add(static_agent, static_subids, static_len,NULL) == -1)
1345			{
1346				error("error at line %d", yylineno);
1347				YYERROR;
1348			}
1349	
1350			/* add the mirror table(mibpatch) */
1351			/* assume that the subtree is the first agent
1352			   subtree */
1353			sp = static_agent->first_agent_subtree;
1354			create_mirror_table_from_subtree(sp);
1355
1356			free(static_subids);
1357			static_subids = NULL;
1358			static_len = 0;
1359			found_comma = FALSE;
1360		}
1361
1362
1363tables :	t_tables t_equal t_openbracket tables_list t_closebracket
1364		{
1365			DEBUG_YACC("tables")
1366		}
1367
1368
1369tables_list :	/* empty */ | tables_list table_item
1370		{
1371			DEBUG_YACC("tables_list")
1372		}
1373
1374
1375table_item :	t_openbracket
1376		{
1377			if(static_agent == NULL)
1378			{
1379				error("BUG at line %d: static_agent is NULL in table_item", yylineno);
1380			}
1381
1382			if(static_table)
1383			{
1384				error("BUG at line %d: static_table not NULL in table_item", yylineno);
1385			}
1386
1387			static_table = calloc(1,sizeof(Table));
1388			if(static_table == NULL)
1389			{
1390				error("malloc() failed");
1391				YYERROR;
1392			}
1393			static_table->regTblStatus = SSA_OPER_STATUS_ACTIVE;
1394			static_table->next_table = NULL;
1395			static_table->agent = static_agent;
1396			static_table->regTblAgentID = static_agent->agentID;
1397			static_table->regTblIndex = ++static_agent->agentTblIndex;
1398			static_table->name.subids = NULL;
1399			static_table->name.len = 0;
1400			static_table->first_column_subid = 0;
1401			static_table->last_column_subid = 0;
1402/*
1403			static_table->indexs.subids = NULL;
1404			static_table->indexs.len = 0;
1405*/
1406		}
1407		table columns indexs t_closebracket
1408		{
1409			DEBUG_YACC("table_item")
1410
1411			if(static_table == NULL)
1412			{
1413				error("BUG at line %d: static_table is NULL in table_item", yylineno);
1414			}else{
1415			  /* check for the validation of the table,
1416		  	   * if insertion is ok, then put it into the 
1417			   * table lists
1418			   */
1419			
1420			  if(single_table_to_subtrees(TABLE_TO_OID_TRY,
1421			    static_table,error_label) == -1){
1422				/* may need more elaboration in error */
1423				error("Table %d insertion failed",
1424				(static_table->name.subids)?
1425				SSAOidString(&(static_table->name)):"");
1426				table_free(static_table);
1427			  }
1428			  if(single_table_to_subtrees(TABLE_TO_OID_GO,
1429			    static_table,error_label) != -1){
1430
1431				if(first_table==NULL){
1432				  first_table =static_table;
1433				}else{
1434				  for(tmp_table=first_table;tmp_table;
1435				      tmp_table=tmp_table->next_table)
1436					last_table = tmp_table;
1437				  last_table->next_table = static_table;
1438				}
1439			  }
1440			}
1441			static_table = NULL;
1442		}
1443
1444
1445table :		t_table t_equal
1446		{
1447			if(parsing_oid != False)
1448			{
1449				error("BUG at line %d: parsing_oid is not False in tables", yylineno);
1450			}
1451
1452			parsing_oid = True;
1453		}
1454		subids_list
1455		{
1456			DEBUG_YACC("table")
1457
1458			if(parsing_oid != True)
1459			{
1460				error("BUG at line %d: parsing_oid is not True in tables", yylineno);
1461			}
1462			parsing_oid = False;
1463
1464			if(static_table == NULL)
1465			{
1466				error_exit("BUG at line %d: static_table is NULL in table", yylineno);
1467			}
1468
1469			static_table->name.subids = static_subids;
1470			static_subids = NULL;
1471			static_table->name.len = static_len;
1472			static_len = 0;
1473		}
1474
1475
1476columns :	t_columns t_equal range
1477		{
1478			DEBUG_YACC("columns")
1479
1480			if(static_table == NULL)
1481			{
1482				error_exit("BUG at line %d: static_table is NULL in columns", yylineno);
1483			}
1484
1485			static_table->first_column_subid = static_inf_value;
1486			static_inf_value = -1;
1487			static_table->last_column_subid = static_sup_value;
1488			static_sup_value = -1;
1489		}
1490
1491
1492/*
1493indexs :	t_indexs t_equal
1494		{
1495			if(parsing_oid != False)
1496			{
1497				error("BUG at line %d: parsing_oid is not False in indexs", yylineno);
1498			}
1499
1500			parsing_oid = True;
1501		}
1502		subids_list
1503		{
1504			DEBUG_YACC("indexs")
1505
1506			if(parsing_oid != True)
1507			{
1508				error("BUG at line %d: parsing_oid is not True in indexs", yylineno);
1509			}
1510			parsing_oid = False;
1511
1512			if(static_table == NULL)
1513			{
1514				error_exit("BUG at line %d: static_table is NULL in indexs", yylineno);
1515			}
1516
1517			static_table->indexs.subids = static_subids;
1518			static_subids = NULL;
1519			static_table->indexs.len = static_len;
1520			static_len = 0;
1521		}
1522*/
1523
1524indexs :	t_indexs t_equal range
1525		{
1526			DEBUG_YACC("indexs")
1527
1528			if(static_inf_value == -1)
1529			{
1530				error("BUG at line %d: static_inf_value is -1", yylineno);
1531			}
1532			if(static_sup_value == -1)
1533			{
1534				error("BUG at line %d: static_sup_value is -1", yylineno);
1535			}
1536			static_table->first_index_subid = static_inf_value;
1537			static_table->last_index_subid = static_sup_value;
1538			static_inf_value = -1;
1539			static_sup_value = -1;
1540		}
1541
1542
1543range :		t_opensquarebracket t_number
1544		{
1545			if(static_inf_value != -1)
1546			{
1547				error("BUG at line %d: static_inf_value (%d) is not -1 in range",
1548					yylineno,
1549					static_inf_value);
1550			}
1551
1552			static_inf_value = token_value;
1553		}
1554		t_minus t_number
1555		{
1556			if(static_sup_value != -1)
1557			{
1558				error("BUG at line %d: static_sup_value (%d) is not -1 in range",
1559					yylineno,
1560					static_inf_value);
1561			}
1562
1563			static_sup_value = token_value;
1564		}
1565		t_closesquarebracket
1566		{
1567			DEBUG_YACC("range")
1568		}
1569		| t_number
1570		{
1571			if(static_inf_value != -1)
1572			{
1573				error("BUG at line %d: static_inf_value (%d) is not -1 in range",
1574					yylineno,
1575					static_inf_value);
1576			}
1577			if(static_sup_value != -1)
1578			{
1579				error("BUG at line %d: static_sup_value (%d) is not -1 in range",
1580					yylineno,
1581					static_sup_value);
1582			}
1583
1584			static_inf_value = token_value;
1585			static_sup_value = token_value;
1586		}
1587
1588
1589timeout :	t_timeout t_equal t_number
1590		{
1591			DEBUG_YACC("subtree")
1592
1593			static_agent->agentTimeOut =static_agent->timeout = token_value;
1594		}
1595
1596optional_watch_dog_time : /*empty*/ |	t_watch_dog_time t_equal NUMBER
1597		{
1598			DEBUG_YACC("optional_watch_dog_time")
1599			static_agent->agentWatchDogTime = token_value;
1600		}
1601
1602
1603optional_port : /*empty*/ | port
1604	{
1605		DEBUG_YACC("optional_port")
1606	}
1607
1608port :		t_port t_equal t_number
1609		{
1610			DEBUG_YACC("port")
1611
1612			if(token_value > 0xFFFF)
1613			{
1614				error("error at line %d: the port number (%d) should not be greater than %d", yylineno, token_value, 0xFFFF);
1615				YYERROR;
1616			}
1617
1618			static_agent->address.sin_port = (short) token_value;
1619			static_agent->agentPortNumber = 
1620				static_agent->address.sin_port;
1621
1622			if(agent_find(&(static_agent->address)))
1623			{
1624				error("error at line %d: the port number %d is already used by another agent", yylineno, token_value);
1625				YYERROR;
1626			}
1627		}
1628
1629
1630
1631/***************/
1632/* subids_list */
1633/***************/
1634
1635subids_list :	subid | subids_list t_dot subid
1636		{
1637			DEBUG_YACC("subids_list")
1638                        found_dot = FALSE;
1639		}
1640
1641
1642subid :		t_mib2 | t_sun | t_enterprise | t_identifier | t_number
1643		{
1644			DEBUG_YACC("subid")
1645		}
1646
1647
1648
1649/*******************/
1650/* terminal tokens */
1651/*******************/
1652
1653/**************** SNMP security (5-13-96) ***/
1654ct_identifier : IDENTIFIER
1655		{
1656			DEBUG_YACC("ct_indentifier")
1657/*             
1658                        if(save_string == NULL)
1659                        {
1660                           error("malloc() failed");
1661                           YYERROR;
1662                        }
1663*/
1664                        save_string = strdup(yytext);
1665
1666
1667		}
1668
1669t_communities : COMMUNITIES
1670                {
1671                        DEBUG_YACC("t_communities")
1672                }
1673
1674t_hosts : HOSTS
1675        {
1676                DEBUG_YACC("t_hosts")
1677        }
1678
1679t_acls	: ACL
1680	{
1681		DEBUG_YACC("t_acls")
1682	}
1683
1684t_access : ACCESS 
1685        {
1686                DEBUG_YACC("t_access") 
1687        } 
1688
1689
1690t_readonly :    READONLY
1691                {
1692                        DEBUG_YACC("t_readonly")
1693
1694                        community_type = READ_ONLY;
1695                }
1696
1697t_readwrite :   READWRITE
1698                {
1699                        DEBUG_YACC("t_readwrite")
1700
1701                        community_type = READ_WRITE;
1702                }
1703
1704t_managers :    MANAGERS
1705                {
1706                        DEBUG_YACC("t_managers")
1707                }
1708
1709t_trap :        TRAP
1710                {
1711                        DEBUG_YACC("t_trap")
1712                }
1713 
1714t_trap_num:     TRAPNUM
1715                {
1716                        DEBUG_YACC("t_trap_num")
1717                }
1718
1719t_trapcommunity : TRAPCOMMUNITY
1720                {
1721                        DEBUG_YACC("t_trapcommunity")
1722                }
1723
1724
1725/*
1726t_trapdestinators : TRAPDESTINATORS
1727                {
1728                        DEBUG_YACC("t_trapdestinators")
1729                }
1730
1731list_separator :  | t_comma
1732                {
1733                        DEBUG_YACC("list_separator")
1734                }
1735*/
1736
1737
1738/**************** SNMP security (5-13-96) ***/
1739
1740
1741t_number :	NUMBER
1742		{
1743			DEBUG_YACC("t_number")
1744
1745			if(parsing_oid == True)
1746			{
1747				if(subids_cat((Subid *) &token_value, 1) == -1)
1748				{
1749					YYERROR;
1750				}
1751			}
1752		}
1753
1754
1755t_macros :	MACROS
1756		{
1757			DEBUG_YACC("t_macros")
1758		}
1759
1760
1761t_equal :	EQUAL
1762		{
1763			DEBUG_YACC("t_equal")
1764		}
1765
1766
1767t_minus :	MINUS
1768		{
1769			DEBUG_YACC("t_minus")
1770		}
1771
1772
1773t_openbracket :	OPENBRACKET
1774		{
1775			DEBUG_YACC("t_openbracket")
1776		}
1777
1778
1779t_closebracket : CLOSEBRACKET
1780		{
1781			DEBUG_YACC("t_closebracket")
1782		}
1783
1784
1785t_opensquarebracket : OPENSQUAREBRACKET
1786		{
1787			DEBUG_YACC("t_opensquarebracket")
1788		}
1789
1790
1791t_closesquarebracket : CLOSESQUAREBRACKET
1792		{
1793			DEBUG_YACC("t_closesquarebracket")
1794		}
1795
1796
1797t_identifier :	IDENTIFIER
1798		{
1799			DEBUG_YACC("t_identifier")
1800
1801			if(parsing_oid == True)
1802			{
1803				Macro *mp;
1804
1805
1806				mp = macro_find(yytext);
1807				if(mp == NULL)
1808				{
1809					error("error at line %d: %s is not a macro", yylineno, yytext);
1810					YYERROR;
1811				}
1812
1813				if(subids_cat(mp->name.subids, mp->name.len) == -1)
1814				{
1815					YYERROR;	
1816				}
1817			}
1818		}
1819
1820
1821t_mib2 :	MIB2
1822		{
1823			DEBUG_YACC("t_mib2")
1824
1825			if(parsing_oid == False)
1826			{
1827				error("BUG at line %d: parsing_oid not True in t_mib2", yylineno);
1828			}
1829			if(subids_cat(subids_mib2, mib2_len) == -1)
1830			{
1831				YYERROR;
1832			}
1833		}
1834
1835
1836t_sun :		SUN
1837		{
1838			DEBUG_YACC("t_sun")
1839
1840			if(parsing_oid == False)
1841			{
1842				error("BUG at line %d: parsing_oid not True in t_sun", yylineno);
1843			}
1844			if(subids_cat(subids_sun, sun_len) == -1)
1845			{
1846				YYERROR;
1847			}
1848		}
1849
1850
1851t_enterprise :	ENTERPRISE
1852		{
1853			DEBUG_YACC("t_enterprise")
1854
1855			if(parsing_oid == False)
1856			{
1857				error("BUG at line %d: parsing_oid not True in t_enterprise", yylineno);
1858			}
1859			if(subids_cat(subids_enterprise, enterprise_len) == -1)
1860			{
1861				YYERROR;
1862			}
1863		}
1864
1865t_dot :		DOT
1866		{
1867			DEBUG_YACC("t_dot")
1868                        found_dot=TRUE;
1869		}
1870
1871
1872t_agents :	AGENTS
1873		{
1874			DEBUG_YACC("t_agents")
1875		}
1876
1877
1878t_name :	NAME
1879		{
1880			DEBUG_YACC("t_name")
1881		}
1882
1883
1884t_subtrees :	SUBTREES
1885		{
1886			DEBUG_YACC("t_subtrees")
1887		}
1888
1889
1890t_tables :	TABLES
1891		{
1892			DEBUG_YACC("t_tables")
1893		}
1894
1895
1896t_table :	TABLE
1897		{
1898			DEBUG_YACC("t_table")
1899		}
1900
1901
1902t_columns :	COLUMNS
1903		{
1904			DEBUG_YACC("t_columns")
1905		}
1906
1907
1908t_indexs :	INDEXS
1909		{
1910			DEBUG_YACC("t_indexs")
1911		}
1912
1913
1914t_timeout :	TIMEOUT
1915		{
1916			DEBUG_YACC("t_timeout")
1917		}
1918
1919t_environment:	ENVIRONMENT
1920		{
1921			DEBUG_YACC("t_environment")
1922		}
1923
1924t_watch_dog_time :	WATCHDOGTIME
1925		{
1926			DEBUG_YACC("t_watch_dog_time")
1927		}
1928
1929t_poll_interval: 	POLLINTERVAL
1930		{
1931			DEBUG_YACC("t_poll_interval")
1932		}
1933
1934t_max_agent_time_out:	MAXAGENTTIMEOUT
1935		{
1936			DEBUG_YACC("t_max_agent_time_out")
1937		}
1938
1939
1940t_port :	PORT
1941		{
1942			DEBUG_YACC("t_port")
1943		}
1944
1945
1946t_quotedstring : QUOTEDSTRING
1947		{
1948			DEBUG_YACC("t_quotedstring\n")
1949		}
1950
1951
1952t_comma :	COMMA
1953		{
1954			DEBUG_YACC("t_comma")
1955                        found_comma=TRUE;
1956		}
1957%%
1958
1959#include "config.lex.c"
1960
1961/****************************************************************/
1962
1963static int subids_cat(Subid *subids, int len)
1964{
1965	Subid *new_subids;
1966	int new_len;
1967
1968
1969	new_len = static_len + len;
1970	new_subids = (Subid *) malloc(new_len * sizeof(Subid));
1971	if(new_subids == NULL)
1972	{
1973		error("malloc() failed");
1974		if(static_subids)
1975		{
1976			free(static_subids);
1977		}
1978		static_subids = NULL;
1979		static_len = 0;
1980		return -1;
1981	}
1982	memcpy(new_subids, static_subids, static_len * sizeof(Subid));
1983	memcpy(&(new_subids[static_len]), subids, len * sizeof(Subid));
1984
1985
1986	if(static_subids)
1987	{
1988		free(static_subids);
1989	}
1990	static_subids = new_subids;
1991	static_len = new_len;
1992
1993	return 0;
1994}
1995
1996
1997/****************************************************************/
1998
1999static Macro *macro_add(char *label, Subid *subids, int len)
2000{
2001	Macro *new;
2002
2003
2004	if(macro_find(label) != NULL)
2005	{
2006		error("%s is already a macro", label);
2007		return NULL;
2008	}
2009
2010	new = (Macro *) malloc(sizeof(Macro));
2011	if(new == NULL)
2012	{
2013		error("malloc() failed");
2014		return NULL;
2015	}
2016	new->label = NULL;
2017	new->name.subids = NULL;
2018
2019	new->label = strdup(label);
2020	if(new->label == NULL)
2021	{
2022		error("malloc() failed");
2023		macro_free(new);
2024		return NULL;
2025	}
2026	new->name.subids = (Subid *) malloc(len * sizeof(Subid));
2027	if(new->name.subids == NULL)
2028	{
2029		error("malloc() failed");
2030		macro_free(new);
2031		return NULL;
2032	}
2033	memcpy(new->name.subids, subids, len * sizeof(Subid));
2034	new->name.len = len;
2035	new->next_macro = first_macro;
2036	first_macro = new;
2037
2038	return new;
2039}
2040
2041
2042/****************************************************************/
2043
2044static Macro *macro_find(char *label)
2045{
2046	Macro *mp;
2047
2048
2049	for(mp = first_macro; mp; mp = mp->next_macro)
2050	{
2051		if(strcmp(mp->label, label) == 0)
2052		{
2053			return mp;
2054		}
2055	}
2056
2057	return NULL;
2058}
2059
2060
2061/****************************************************************/
2062
2063static void macro_free(Macro *mp)
2064{
2065	if(mp == NULL)
2066	{
2067		return;
2068	}
2069
2070	if(mp->label)
2071	{
2072		free(mp->label);
2073	}
2074
2075	if(mp->name.subids)
2076	{
2077		free(mp->name.subids);
2078	}
2079
2080	free(mp);
2081
2082	return;
2083}
2084
2085
2086/****************************************************************/
2087
2088static void macro_list_delete()
2089{
2090	Macro *mp = first_macro;
2091	Macro *next;
2092
2093
2094	while(mp)
2095	{
2096		next = mp->next_macro;
2097
2098		macro_free(mp);
2099
2100		mp = next;
2101	}
2102
2103	first_macro = NULL;
2104
2105	return;
2106}
2107
2108
2109/****************************************************************/
2110
2111static void trace_macros()
2112{
2113	Macro *mp;
2114
2115
2116	trace("MACROS:\n");
2117	for(mp = first_macro; mp; mp = mp->next_macro)
2118	{
2119		trace("\t%-30s %-30s\n",
2120			mp->label,
2121			SSAOidString(&(mp->name)));
2122	}
2123	trace("\n");
2124}
2125
2126
2127/****************************************************************/
2128
2129int yyerror(char *s)
2130{
2131	error("%s at line %d: %s", s, yylineno, yytext);
2132	return (0);
2133}
2134
2135
2136/****************************************************************/
2137
2138/*
2139 * filename is the file to be read
2140 * file_time is the modified time of the file, this argument can be NULL
2141 */
2142int parsing_file(char* filename,time_t *file_time)
2143{
2144  struct stat statb;
2145  int fd;
2146  char *fileaddr;
2147  int error_free = TRUE;
2148
2149  yylineno = 1;
2150  if((fd = open(filename, O_RDONLY)) < 0)
2151  {
2152	error(ERR_MSG_OPEN, filename, errno_string());
2153	error_free = FALSE;
2154	return (error_free);
2155  }
2156
2157  /* 
2158   * get the size of the file
2159   */
2160  if(fstat(fd, &statb) < 0 )
2161  {
2162	error(ERR_MSG_FSTAT, filename, errno_string());
2163	error_free = FALSE;
2164	return(error_free);
2165   }
2166
2167  if(S_ISREG(statb.st_mode)==0)
2168  {
2169	error(" parsing file error: %s is not a file\n",filename);
2170	error_free = FALSE;
2171	return(error_free);
2172   }
2173
2174   /* file time stamp */
2175   if(file_time) *file_time = statb.st_mtime;
2176
2177   /* 
2178    * and map it into my address spa…

Large files files are truncated, but you can click here to view the full file