PageRenderTime 58ms CodeModel.GetById 29ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause-No-Nuclear-License-2014, MPL-2.0-no-copyleft-exception, BSD-3-Clause, BSD-2-Clause, LGPL-3.0, 0BSD, GPL-2.0, LGPL-2.0, AGPL-1.0, AGPL-3.0, GPL-3.0, LGPL-2.1

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

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