From a953f3ad4ad0be324b3bf76eaff6d5c5fb783257 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Wed, 21 May 2014 15:06:12 +0200 Subject: [PATCH] starter: Remove old parser --- src/starter/.gitignore | 6 +- src/starter/Android.mk | 3 +- src/starter/Makefile.am | 5 +- src/starter/ipsec-parser.h | 48 ------- src/starter/lexer.l | 215 ----------------------------- src/starter/parser.y | 272 ------------------------------------- 6 files changed, 4 insertions(+), 545 deletions(-) delete mode 100644 src/starter/ipsec-parser.h delete mode 100644 src/starter/lexer.l delete mode 100644 src/starter/parser.y diff --git a/src/starter/.gitignore b/src/starter/.gitignore index 9382cb9ca..a370ee554 100644 --- a/src/starter/.gitignore +++ b/src/starter/.gitignore @@ -1,8 +1,4 @@ starter parser/lexer.c parser/parser.[ch] -parser/parser.output -lexer.c -parser.h -parser.c -parser.output +parser/parser.output \ No newline at end of file diff --git a/src/starter/Android.mk b/src/starter/Android.mk index de27af759..c37fc1aa6 100644 --- a/src/starter/Android.mk +++ b/src/starter/Android.mk @@ -5,8 +5,7 @@ include $(CLEAR_VARS) starter_SOURCES := \ starter.c files.h \ parser/parser.c parser/lexer.c parser/conf_parser.c parser/conf_parser.h \ -parser.c lexer.c ipsec-parser.h args.c args.h \ -confread.c confread.h keywords.c keywords.h cmp.c cmp.h \ +args.c args.h confread.c confread.h keywords.c keywords.h cmp.c cmp.h \ invokecharon.c invokecharon.h starterstroke.c starterstroke.h \ netkey.c netkey.h klips.c klips.h diff --git a/src/starter/Makefile.am b/src/starter/Makefile.am index 32aa9d2c2..1eb834e92 100644 --- a/src/starter/Makefile.am +++ b/src/starter/Makefile.am @@ -4,8 +4,7 @@ ipsec_PROGRAMS = starter starter_SOURCES = \ starter.c files.h \ parser/parser.y parser/lexer.l parser/conf_parser.c parser/conf_parser.h \ -parser.y lexer.l ipsec-parser.h args.c args.h \ -confread.c confread.h keywords.c keywords.h cmp.c cmp.h \ +args.c args.h confread.c confread.h keywords.c keywords.h cmp.c cmp.h \ invokecharon.c invokecharon.h starterstroke.c starterstroke.h \ netkey.c netkey.h klips.c klips.h @@ -34,7 +33,7 @@ starter_LDADD = \ EXTRA_DIST = keywords.txt ipsec.conf Android.mk MAINTAINERCLEANFILES = keywords.c -BUILT_SOURCES = keywords.c parser.h parser/parser.h +BUILT_SOURCES = keywords.c parser/parser.h if USE_CHARON AM_CPPFLAGS += -DSTART_CHARON diff --git a/src/starter/ipsec-parser.h b/src/starter/ipsec-parser.h deleted file mode 100644 index fb64bfa2a..000000000 --- a/src/starter/ipsec-parser.h +++ /dev/null @@ -1,48 +0,0 @@ -/* strongSwan config file parser - * Copyright (C) 2001-2002 Mathieu Lafon - Arkoon Network Security - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#ifndef _IPSEC_PARSER_H_ -#define _IPSEC_PARSER_H_ - -#include "keywords.h" - -typedef struct kw_list kw_list_t; - -struct kw_list { - kw_entry_t *entry; - char *value; - kw_list_t *next; -}; - -typedef struct section_list section_list_t; - -struct section_list { - char *name; - kw_list_t *kw; - section_list_t *next; -}; - -typedef struct config_parsed config_parsed_t; - -struct config_parsed { - kw_list_t *config_setup; - section_list_t *conn_first, *conn_last; - section_list_t *ca_first, *ca_last; -}; - -config_parsed_t *parser_load_conf (const char *file); -void parser_free_conf (config_parsed_t *cfg); - -#endif /* _IPSEC_PARSER_H_ */ - diff --git a/src/starter/lexer.l b/src/starter/lexer.l deleted file mode 100644 index 734776a74..000000000 --- a/src/starter/lexer.l +++ /dev/null @@ -1,215 +0,0 @@ -%option noinput -%option nounput -%{ -/* FreeS/WAN config file parser (parser.l) - * Copyright (C) 2001 Mathieu Lafon - Arkoon Network Security - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#include -#include - -#ifdef HAVE_GLOB_H -#include -#endif - -#include "parser.h" - -#define MAX_INCLUDE_DEPTH 20 - -extern void yyerror(const char *); -extern int yylex(void); -extern int yylex_destroy(void); - -static struct { - int stack_ptr; - YY_BUFFER_STATE stack[MAX_INCLUDE_DEPTH]; - FILE *file[MAX_INCLUDE_DEPTH]; - unsigned int line[MAX_INCLUDE_DEPTH]; - char *filename[MAX_INCLUDE_DEPTH]; -} __parser_y_private; - -void _parser_y_error(char *b, int size, const char *s); -void _parser_y_init (const char *f); -void _parser_y_fini (void); -int _parser_y_include (const char *filename); - -void _parser_y_error(char *b, int size, const char *s) -{ - extern char *yytext; // was: char yytext[]; - - snprintf(b, size, "%s:%d: %s [%s]", - __parser_y_private.filename[__parser_y_private.stack_ptr], - __parser_y_private.line[__parser_y_private.stack_ptr], - s, yytext); -} - -void _parser_y_init (const char *f) -{ - memset(&__parser_y_private, 0, sizeof(__parser_y_private)); - __parser_y_private.line[0] = 1; - __parser_y_private.filename[0] = strdup(f); -} - -void _parser_y_fini (void) -{ - unsigned int i; - - for (i = 0; i < MAX_INCLUDE_DEPTH; i++) - { - if (__parser_y_private.filename[i]) - free(__parser_y_private.filename[i]); - if (__parser_y_private.file[i]) - fclose(__parser_y_private.file[i]); - } - memset(&__parser_y_private, 0, sizeof(__parser_y_private)); - yylex_destroy(); -} - -/** - * parse the file located at filename - */ -int include_file(char *filename) -{ - unsigned int p = __parser_y_private.stack_ptr + 1; - FILE *f; - - if (p >= MAX_INCLUDE_DEPTH) - { - yyerror("max inclusion depth reached"); - return 1; - } - - f = fopen(filename, "r"); - if (!f) - { - yyerror("can't open include filename"); - return 0; /* ignore this error */ - } - - __parser_y_private.stack_ptr++; - __parser_y_private.file[p] = f; - __parser_y_private.stack[p] = YY_CURRENT_BUFFER; - __parser_y_private.line[p] = 1; - __parser_y_private.filename[p] = strdup(filename); - - yy_switch_to_buffer(yy_create_buffer(f, YY_BUF_SIZE)); - return 0; -} - -int _parser_y_include (const char *filename) -{ - int ret = 0; -#ifdef HAVE_GLOB_H - { - glob_t files; - int i; - - ret = glob(filename, GLOB_ERR, NULL, &files); - if (ret) - { - const char *err; - - switch (ret) - { - case GLOB_NOSPACE: - err = "include files ran out of memory"; - break; - case GLOB_ABORTED: - err = "include files aborted due to read error"; - break; - case GLOB_NOMATCH: - err = "include files found no matches"; - break; - default: - err = "unknown include files error"; - } - globfree(&files); - yyerror(err); - return 1; - } - - for (i = 0; i < files.gl_pathc; i++) - { - if ((ret = include_file(files.gl_pathv[i]))) - { - break; - } - } - globfree(&files); - } -#else /* HAVE_GLOB_H */ - /* if glob(3) is not available, try to load pattern directly */ - ret = include_file(filename); -#endif /* HAVE_GLOB_H */ - return ret; -} - -%} - -%% - -<> { - if (__parser_y_private.filename[__parser_y_private.stack_ptr]) { - free(__parser_y_private.filename[__parser_y_private.stack_ptr]); - __parser_y_private.filename[__parser_y_private.stack_ptr] = NULL; - } - if (__parser_y_private.file[__parser_y_private.stack_ptr]) { - fclose(__parser_y_private.file[__parser_y_private.stack_ptr]); - __parser_y_private.file[__parser_y_private.stack_ptr] = NULL; - yy_delete_buffer (YY_CURRENT_BUFFER); - yy_switch_to_buffer - (__parser_y_private.stack[__parser_y_private.stack_ptr]); - } - if (--__parser_y_private.stack_ptr < 0) { - yyterminate(); - } -} - -^[\t ]+ return FIRST_SPACES; - -[\t ]+ /* ignore spaces in line */ ; - -= return EQUAL; - -\n|#.*\n { - __parser_y_private.line[__parser_y_private.stack_ptr]++; - return EOL; - } - -config return CONFIG; -setup return SETUP; -conn return CONN; -ca return CA; -include return INCLUDE; -version return FILE_VERSION; - -[^\"= \t\n]+ { - yylval.s = strdup(yytext); - return STRING; - } - -\"[^\"\n]*\" { - yylval.s = strdup(yytext+1); - if (yylval.s) yylval.s[strlen(yylval.s)-1]='\0'; - return STRING; - } - -. yyerror(yytext); - -%% - -int yywrap(void) -{ - return 1; -} - diff --git a/src/starter/parser.y b/src/starter/parser.y deleted file mode 100644 index 2cf0501f4..000000000 --- a/src/starter/parser.y +++ /dev/null @@ -1,272 +0,0 @@ -%{ -/* strongSwan config file parser (parser.y) - * Copyright (C) 2001 Mathieu Lafon - Arkoon Network Security - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. See . - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * for more details. - */ - -#include -#include -#include - -#include -#include - -#include "ipsec-parser.h" - -#define YYERROR_VERBOSE -#define ERRSTRING_LEN 256 - -/** - * Bison - */ -static char parser_errstring[ERRSTRING_LEN+1]; - -extern void yyerror(const char *s); -extern int yylex (void); -extern void _parser_y_error(char *b, int size, const char *s); - -/** - * Static Globals - */ -static int _save_errors_; -static config_parsed_t *_parser_cfg; -static kw_list_t **_parser_kw, *_parser_kw_last; -static char errbuf[ERRSTRING_LEN+1]; - -/** - * Gperf - */ -extern kw_entry_t *in_word_set (char *str, unsigned int len); - -%} - -%union { char *s; }; -%token EQUAL FIRST_SPACES EOL CONFIG SETUP CONN CA INCLUDE FILE_VERSION -%token STRING - -%% - -/* - * Config file - */ - -config_file: - config_file section_or_include - | /* NULL */ - ; - -section_or_include: - FILE_VERSION STRING EOL - { - free($2); - } - | CONFIG SETUP EOL - { - _parser_kw = &(_parser_cfg->config_setup); - _parser_kw_last = NULL; - } kw_section - | CONN STRING EOL - { - section_list_t *section = malloc_thing(section_list_t); - - section->name = strdupnull($2); - section->kw = NULL; - section->next = NULL; - _parser_kw = &(section->kw); - if (!_parser_cfg->conn_first) - _parser_cfg->conn_first = section; - if (_parser_cfg->conn_last) - _parser_cfg->conn_last->next = section; - _parser_cfg->conn_last = section; - _parser_kw_last = NULL; - free($2); - } kw_section - | CA STRING EOL - { - section_list_t *section = malloc_thing(section_list_t); - section->name = strdupnull($2); - section->kw = NULL; - section->next = NULL; - _parser_kw = &(section->kw); - if (!_parser_cfg->ca_first) - _parser_cfg->ca_first = section; - if (_parser_cfg->ca_last) - _parser_cfg->ca_last->next = section; - _parser_cfg->ca_last = section; - _parser_kw_last = NULL; - free($2); - } kw_section - | INCLUDE STRING - { - extern void _parser_y_include (const char *f); - _parser_y_include($2); - free($2); - } EOL - | EOL - ; - -kw_section: - FIRST_SPACES statement_kw EOL kw_section - | - ; - -statement_kw: - STRING EQUAL STRING - { - kw_list_t *new; - kw_entry_t *entry = in_word_set($1, strlen($1)); - - if (entry == NULL) - { - snprintf(errbuf, ERRSTRING_LEN, "unknown keyword '%s'", $1); - yyerror(errbuf); - } - else if (_parser_kw) - { - new = (kw_list_t *)malloc_thing(kw_list_t); - new->entry = entry; - new->value = strdupnull($3); - new->next = NULL; - if (_parser_kw_last) - _parser_kw_last->next = new; - _parser_kw_last = new; - if (!*_parser_kw) - *_parser_kw = new; - } - free($1); - free($3); - } - | STRING EQUAL - { - free($1); - } - | - ; - -%% - -void yyerror(const char *s) -{ - if (_save_errors_) - _parser_y_error(parser_errstring, ERRSTRING_LEN, s); -} - -config_parsed_t *parser_load_conf(const char *file) -{ - config_parsed_t *cfg = NULL; - int err = 0; - FILE *f; - - extern void _parser_y_init(const char *f); - extern void _parser_y_fini(void); - extern FILE *yyin; - - memset(parser_errstring, 0, ERRSTRING_LEN+1); - - cfg = (config_parsed_t *)malloc_thing(config_parsed_t); - if (cfg) - { - memset(cfg, 0, sizeof(config_parsed_t)); - f = fopen(file, "r"); - if (f) - { - yyin = f; - _parser_y_init(file); - _save_errors_ = 1; - _parser_cfg = cfg; - - if (yyparse() !=0 ) - { - if (parser_errstring[0] == '\0') - { - snprintf(parser_errstring, ERRSTRING_LEN, "Unknown error..."); - } - _save_errors_ = 0; - while (yyparse() != 0); - err++; - } - else if (parser_errstring[0] != '\0') - { - err++; - } - else - { - /** - * Config valid - */ - } - - fclose(f); - } - else - { - snprintf(parser_errstring, ERRSTRING_LEN, "can't load file '%s'", file); - err++; - } - } - else - { - snprintf(parser_errstring, ERRSTRING_LEN, "can't allocate memory"); - err++; - } - - if (err) - { - DBG1(DBG_APP, "%s", parser_errstring); - - if (cfg) - parser_free_conf(cfg); - cfg = NULL; - } - - _parser_y_fini(); - return cfg; -} - -static void parser_free_kwlist(kw_list_t *list) -{ - kw_list_t *elt; - - while (list) - { - elt = list; - list = list->next; - free(elt->value); - free(elt); - } -} - -void parser_free_conf(config_parsed_t *cfg) -{ - section_list_t *sec; - if (cfg) - { - parser_free_kwlist(cfg->config_setup); - while (cfg->conn_first) - { - sec = cfg->conn_first; - cfg->conn_first = cfg->conn_first->next; - free(sec->name); - parser_free_kwlist(sec->kw); - free(sec); - } - while (cfg->ca_first) - { - sec = cfg->ca_first; - cfg->ca_first = cfg->ca_first->next; - free(sec->name); - parser_free_kwlist(sec->kw); - free(sec); - } - free(cfg); - } -}