|
|
738028 |
diff -Naur libreswan-3.15-orig/include/ipsecconf/confread.h libreswan-3.15/include/ipsecconf/confread.h
|
|
|
738028 |
--- libreswan-3.15-orig/include/ipsecconf/confread.h 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/include/ipsecconf/confread.h 2015-09-03 11:43:09.630000000 -0400
|
|
|
738028 |
@@ -132,7 +132,7 @@
|
|
|
738028 |
extern struct starter_config *confread_load(const char *file,
|
|
|
738028 |
err_t *perr,
|
|
|
738028 |
bool resolvip,
|
|
|
738028 |
- char *ctlbase,
|
|
|
738028 |
+ const char *ctlbase,
|
|
|
738028 |
bool setuponly);
|
|
|
738028 |
extern struct starter_conn *alloc_add_conn(struct starter_config *cfg,
|
|
|
738028 |
char *name);
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/include/ipsecconf/keywords.h libreswan-3.15/include/ipsecconf/keywords.h
|
|
|
738028 |
--- libreswan-3.15-orig/include/ipsecconf/keywords.h 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/include/ipsecconf/keywords.h 2015-09-03 11:43:10.538000000 -0400
|
|
|
738028 |
@@ -305,8 +305,7 @@
|
|
|
738028 |
struct kw_list {
|
|
|
738028 |
struct kw_list *next;
|
|
|
738028 |
struct keyword keyword;
|
|
|
738028 |
- char *string;
|
|
|
738028 |
- double decimal;
|
|
|
738028 |
+ char *string;
|
|
|
738028 |
unsigned int number;
|
|
|
738028 |
};
|
|
|
738028 |
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/lib/libipsecconf/confread.c libreswan-3.15/lib/libipsecconf/confread.c
|
|
|
738028 |
--- libreswan-3.15-orig/lib/libipsecconf/confread.c 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/lib/libipsecconf/confread.c 2015-09-03 11:42:22.941000000 -0400
|
|
|
738028 |
@@ -1418,7 +1418,7 @@
|
|
|
738028 |
struct starter_config *confread_load(const char *file,
|
|
|
738028 |
err_t *perr,
|
|
|
738028 |
bool resolvip,
|
|
|
738028 |
- char *ctlbase,
|
|
|
738028 |
+ const char *ctlbase,
|
|
|
738028 |
bool setuponly)
|
|
|
738028 |
{
|
|
|
738028 |
struct starter_config *cfg = NULL;
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/lib/libipsecconf/confwrite.c libreswan-3.15/lib/libipsecconf/confwrite.c
|
|
|
738028 |
--- libreswan-3.15-orig/lib/libipsecconf/confwrite.c 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/lib/libipsecconf/confwrite.c 2015-09-03 11:42:22.941000000 -0400
|
|
|
738028 |
@@ -412,9 +412,9 @@
|
|
|
738028 |
|
|
|
738028 |
int alsoplace = 0;
|
|
|
738028 |
|
|
|
738028 |
- fprintf(out, "\t#also = ");
|
|
|
738028 |
+ fprintf(out, "\t#also =");
|
|
|
738028 |
while (conn->alsos[alsoplace] != NULL) {
|
|
|
738028 |
- fprintf(out, "%s ", conn->alsos[alsoplace]);
|
|
|
738028 |
+ fprintf(out, " %s", conn->alsos[alsoplace]);
|
|
|
738028 |
alsoplace++;
|
|
|
738028 |
}
|
|
|
738028 |
fprintf(out, "\n");
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/lib/libipsecconf/Makefile libreswan-3.15/lib/libipsecconf/Makefile
|
|
|
738028 |
--- libreswan-3.15-orig/lib/libipsecconf/Makefile 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/lib/libipsecconf/Makefile 2015-09-03 11:42:22.941000000 -0400
|
|
|
738028 |
@@ -38,21 +38,45 @@
|
|
|
738028 |
# since all the $(OBJS) indirectly depend on the header anyway.
|
|
|
738028 |
$(OBJS): parser.tab.h
|
|
|
738028 |
|
|
|
738028 |
-# Use UNIX basename to strip off the directory. Use grep to workaround flex < 2.5.35
|
|
|
738028 |
+# Use UNIX basename to strip off the directory.
|
|
|
738028 |
+# Use sed to work around two bugs:
|
|
|
738028 |
+#
|
|
|
738028 |
+# - flex < 2.5.35 generates an extern that isn't good
|
|
|
738028 |
+#
|
|
|
738028 |
+# - flex on RHEL 7 generates code that provokes GCC to warn
|
|
|
738028 |
+# about comparing a signed value with an unsigned value
|
|
|
738028 |
+# (Combination of a new GCC and an old flex).
|
|
|
738028 |
+# Adding one cast makes RHEL 6's GCC unhappy, so we add two.
|
|
|
738028 |
+# On RHEL 6, i is int and _yybytes_len is int.
|
|
|
738028 |
+# On RHEL 7, i is int and _yybytes_len is yy_size_t
|
|
|
738028 |
+# On Fedora 21, i is yy_size_t and _yybytes_len is yy_size_t
|
|
|
738028 |
+# On some architectures, yy_size_t is wider than int;
|
|
|
738028 |
+# which makes a mixed comparison OK.
|
|
|
738028 |
+#
|
|
|
738028 |
+# Avoid sed -i which somehow causes unwritable files
|
|
|
738028 |
+# on fedora 20 with 9p filesystem mount.
|
|
|
738028 |
+# Avoid creating the target file until it is done.
|
|
|
738028 |
lex.yy.c: parser.l
|
|
|
738028 |
- cd $(builddir) && $(LEX) -t $(srcdir)/$$(basename $<) | grep -v '^extern int isatty' > $@
|
|
|
738028 |
+ cd $(builddir) && \
|
|
|
738028 |
+ $(LEX) -o $@.$$$$ $(srcdir)/$$(basename $<) && \
|
|
|
738028 |
+ sed -e 's/for ( i = 0; i < _yybytes_len; ++i )$$/for ( i = 0; (yy_size_t)i < (yy_size_t)_yybytes_len; ++i )/' \
|
|
|
738028 |
+ -e '/^extern int isatty.*$$/d' $@.$$$$ >SEDTMP$$$$ && \
|
|
|
738028 |
+ rm $@.$$$$ && \
|
|
|
738028 |
+ mv SEDTMP$$$$ $@
|
|
|
738028 |
|
|
|
738028 |
# Use wild card rule so that GNU Make knows that both are output from
|
|
|
738028 |
# a single recipe.
|
|
|
738028 |
# - sed command for workaround for older bison vs GCC warning
|
|
|
738028 |
# - avoid sed -i which somehow causes unwritable files
|
|
|
738028 |
# on fedora 20 with 9p filesystem mount
|
|
|
738028 |
+# - avoid creating the target file until it is done
|
|
|
738028 |
%.tab.h %.tab.c: %.y
|
|
|
738028 |
cd $(builddir) && \
|
|
|
738028 |
- $(BISON) ${BISONOSFLAGS} -v -d $(srcdir)/$$(basename $<) && \
|
|
|
738028 |
+ $(BISON) ${BISONOSFLAGS} -v --defines=$$(basename $< .y).tab.h -o $$(basename $< .y).tab.c$$$$ $(srcdir)/$$(basename $<) && \
|
|
|
738028 |
sed -e '/^ *#/s/if YYENABLE_NLS/if defined(YYENABLE_NLS) \&\& YYENABLE_NLS/' \
|
|
|
738028 |
-e '/^ *#/s/if YYLTYPE_IS_TRIVIAL/if defined(YYLTYPE_IS_TRIVIAL) \&\& YYLTYPE_IS_TRIVIAL/' \
|
|
|
738028 |
- $$(basename $< .y).tab.c >SEDTMP$$$$ && \
|
|
|
738028 |
+ $$(basename $< .y).tab.c$$$$ >SEDTMP$$$$ && \
|
|
|
738028 |
+ rm $$(basename $< .y).tab.c$$$$ && \
|
|
|
738028 |
mv SEDTMP$$$$ $$(basename $< .y).tab.c
|
|
|
738028 |
|
|
|
738028 |
clean: parser-clean
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/lib/libipsecconf/parser.l libreswan-3.15/lib/libipsecconf/parser.l
|
|
|
738028 |
--- libreswan-3.15-orig/lib/libipsecconf/parser.l 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/lib/libipsecconf/parser.l 2015-09-03 11:42:22.942000000 -0400
|
|
|
738028 |
@@ -373,7 +373,17 @@
|
|
|
738028 |
|
|
|
738028 |
<INITIAL,USERDEF>[0-9]+ {
|
|
|
738028 |
/* process a number */
|
|
|
738028 |
- yylval.num = strtoul(yytext, NULL, 10);
|
|
|
738028 |
+ unsigned long val = (errno = 0, strtoul(yytext, NULL, 10));
|
|
|
738028 |
+
|
|
|
738028 |
+ if (errno != 0 || val > UINT_MAX) {
|
|
|
738028 |
+ char ebuf[128];
|
|
|
738028 |
+
|
|
|
738028 |
+ snprintf(ebuf, sizeof(ebuf),
|
|
|
738028 |
+ "number too large: %s",
|
|
|
738028 |
+ yytext);
|
|
|
738028 |
+ yyerror(ebuf);
|
|
|
738028 |
+ }
|
|
|
738028 |
+ yylval.num = val;
|
|
|
738028 |
BEGIN INITIAL;
|
|
|
738028 |
return INTEGER;
|
|
|
738028 |
}
|
|
|
738028 |
diff -Naur libreswan-3.15-orig/lib/libipsecconf/parser.y libreswan-3.15/lib/libipsecconf/parser.y
|
|
|
738028 |
--- libreswan-3.15-orig/lib/libipsecconf/parser.y 2015-08-24 16:52:43.000000000 -0400
|
|
|
738028 |
+++ libreswan-3.15/lib/libipsecconf/parser.y 2015-09-03 11:42:22.942000000 -0400
|
|
|
738028 |
@@ -26,7 +26,7 @@
|
|
|
738028 |
#include <assert.h>
|
|
|
738028 |
#include <limits.h>
|
|
|
738028 |
#include <unistd.h>
|
|
|
738028 |
-
|
|
|
738028 |
+#include <errno.h>
|
|
|
738028 |
#define YYDEBUG 1
|
|
|
738028 |
|
|
|
738028 |
#include "ipsecconf/keywords.h"
|
|
|
738028 |
@@ -41,16 +41,15 @@
|
|
|
738028 |
* Bison
|
|
|
738028 |
*/
|
|
|
738028 |
static char parser_errstring[ERRSTRING_LEN+1];
|
|
|
738028 |
-static struct kw_list *alloc_kwlist(void);
|
|
|
738028 |
-static struct starter_comments *alloc_comment(void);
|
|
|
738028 |
|
|
|
738028 |
/**
|
|
|
738028 |
* Static Globals
|
|
|
738028 |
*/
|
|
|
738028 |
-static int _save_errors_;
|
|
|
738028 |
-static struct config_parsed *_parser_cfg;
|
|
|
738028 |
-static struct kw_list **_parser_kw, *_parser_kw_last;
|
|
|
738028 |
-static struct starter_comments_list *_parser_comments;
|
|
|
738028 |
+static bool save_errors;
|
|
|
738028 |
+static struct config_parsed *parser_cfg;
|
|
|
738028 |
+static struct kw_list **parser_kw, *parser_kw_last;
|
|
|
738028 |
+static void new_parser_kw(struct keyword *keyword, char *string, unsigned int number); /* forward */
|
|
|
738028 |
+static struct starter_comments_list *parser_comments;
|
|
|
738028 |
|
|
|
738028 |
/**
|
|
|
738028 |
* Functions
|
|
|
738028 |
@@ -60,7 +59,7 @@
|
|
|
738028 |
|
|
|
738028 |
%union {
|
|
|
738028 |
char *s;
|
|
|
738028 |
- unsigned int num;
|
|
|
738028 |
+ unsigned int num;
|
|
|
738028 |
struct keyword k;
|
|
|
738028 |
}
|
|
|
738028 |
%token EQUAL FIRST_SPACES EOL CONFIG SETUP CONN INCLUDE VERSION
|
|
|
738028 |
@@ -72,6 +71,8 @@
|
|
|
738028 |
%token <k> BOOLWORD
|
|
|
738028 |
%token <k> PERCENTWORD
|
|
|
738028 |
%token <k> COMMENT
|
|
|
738028 |
+
|
|
|
738028 |
+%type <num> duration
|
|
|
738028 |
%%
|
|
|
738028 |
|
|
|
738028 |
/*
|
|
|
738028 |
@@ -84,8 +85,8 @@
|
|
|
738028 |
/* we have configs shipped with version 2 (INTEGER) and with version 2.0 (STRING, now NUMBER/float was removed */
|
|
|
738028 |
|
|
|
738028 |
versionstmt: /* NULL */
|
|
|
738028 |
- | VERSION STRING EOL blanklines
|
|
|
738028 |
- | VERSION INTEGER EOL blanklines
|
|
|
738028 |
+ | VERSION STRING EOL blanklines
|
|
|
738028 |
+ | VERSION INTEGER EOL blanklines
|
|
|
738028 |
;
|
|
|
738028 |
|
|
|
738028 |
blanklines: /* NULL */
|
|
|
738028 |
@@ -98,40 +99,40 @@
|
|
|
738028 |
|
|
|
738028 |
section_or_include:
|
|
|
738028 |
CONFIG SETUP EOL {
|
|
|
738028 |
- _parser_kw = &(_parser_cfg->config_setup);
|
|
|
738028 |
- _parser_kw_last = NULL;
|
|
|
738028 |
- _parser_comments = &_parser_cfg->comments;
|
|
|
738028 |
+ parser_kw = &parser_cfg->config_setup;
|
|
|
738028 |
+ parser_kw_last = NULL;
|
|
|
738028 |
+ parser_comments = &parser_cfg->comments;
|
|
|
738028 |
if (yydebug)
|
|
|
738028 |
fprintf(stderr, "\nconfig setup read\n");
|
|
|
738028 |
|
|
|
738028 |
} kw_sections
|
|
|
738028 |
| CONN STRING EOL {
|
|
|
738028 |
- struct section_list *section;
|
|
|
738028 |
- section = (struct section_list *)malloc(sizeof(struct section_list));
|
|
|
738028 |
- if (section != NULL) {
|
|
|
738028 |
+ struct section_list *section = malloc(sizeof(struct section_list));
|
|
|
738028 |
+
|
|
|
738028 |
+ if (section == NULL) {
|
|
|
738028 |
+ parser_kw = NULL;
|
|
|
738028 |
+ parser_kw_last = NULL;
|
|
|
738028 |
+ yyerror("can't allocate memory in section_or_include/conn");
|
|
|
738028 |
+ } else {
|
|
|
738028 |
section->name = $2;
|
|
|
738028 |
section->kw = NULL;
|
|
|
738028 |
|
|
|
738028 |
- TAILQ_INSERT_TAIL(&_parser_cfg->sections, section, link);
|
|
|
738028 |
+ TAILQ_INSERT_TAIL(&parser_cfg->sections, section, link);
|
|
|
738028 |
|
|
|
738028 |
- /* setup keyword section to record values */
|
|
|
738028 |
- _parser_kw = &(section->kw);
|
|
|
738028 |
- _parser_kw_last = NULL;
|
|
|
738028 |
+ /* setup keyword section to record values */
|
|
|
738028 |
+ parser_kw = §ion->kw;
|
|
|
738028 |
+ parser_kw_last = NULL;
|
|
|
738028 |
|
|
|
738028 |
/* and comments */
|
|
|
738028 |
TAILQ_INIT(§ion->comments);
|
|
|
738028 |
- _parser_comments = §ion->comments;
|
|
|
738028 |
+ parser_comments = §ion->comments;
|
|
|
738028 |
|
|
|
738028 |
- if(yydebug)
|
|
|
738028 |
+ if (yydebug)
|
|
|
738028 |
fprintf(stderr, "\nread conn %s\n", section->name);
|
|
|
738028 |
- } else {
|
|
|
738028 |
- _parser_kw = NULL;
|
|
|
738028 |
- _parser_kw_last = NULL;
|
|
|
738028 |
- yyerror("can't allocate memory in section_or_include/conn");
|
|
|
738028 |
}
|
|
|
738028 |
} kw_sections
|
|
|
738028 |
| INCLUDE STRING EOL {
|
|
|
738028 |
- parser_y_include($2);
|
|
|
738028 |
+ parser_y_include($2);
|
|
|
738028 |
}
|
|
|
738028 |
;
|
|
|
738028 |
|
|
|
738028 |
@@ -144,198 +145,174 @@
|
|
|
738028 |
|
|
|
738028 |
statement_kw:
|
|
|
738028 |
KEYWORD EQUAL KEYWORD {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
+ struct keyword kw = $1;
|
|
|
738028 |
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- struct keyword kw;
|
|
|
738028 |
- /* because the third argument was also a keyword, we dig up the string representation. */
|
|
|
738028 |
- const char *value = $3.keydef->keyname;
|
|
|
738028 |
-
|
|
|
738028 |
- kw = $1;
|
|
|
738028 |
- new->keyword = kw;
|
|
|
738028 |
-
|
|
|
738028 |
- switch(kw.keydef->type) {
|
|
|
738028 |
- case kt_list:
|
|
|
738028 |
- new->number = parser_enum_list(kw.keydef, value, TRUE);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_enum:
|
|
|
738028 |
- new->number = parser_enum_list(kw.keydef, value, FALSE);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_rsakey:
|
|
|
738028 |
- case kt_loose_enum:
|
|
|
738028 |
- new->number = parser_loose_enum(&new->keyword, value);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_string:
|
|
|
738028 |
- case kt_appendstring:
|
|
|
738028 |
- case kt_appendlist:
|
|
|
738028 |
- case kt_filename:
|
|
|
738028 |
- case kt_dirname:
|
|
|
738028 |
- case kt_ipaddr:
|
|
|
738028 |
- case kt_bitstring:
|
|
|
738028 |
- case kt_idtype:
|
|
|
738028 |
- case kt_range:
|
|
|
738028 |
- case kt_subnet:
|
|
|
738028 |
- new->string = strdup(value);
|
|
|
738028 |
- break;
|
|
|
738028 |
-
|
|
|
738028 |
- case kt_bool:
|
|
|
738028 |
- case kt_invertbool:
|
|
|
738028 |
- case kt_number:
|
|
|
738028 |
- case kt_time:
|
|
|
738028 |
- case kt_percent:
|
|
|
738028 |
+ /* because the third argument was also a keyword, we dig up the string representation. */
|
|
|
738028 |
+ const char *value = $3.keydef->keyname;
|
|
|
738028 |
+
|
|
|
738028 |
+ char *string = NULL; /* neutral placeholding value */
|
|
|
738028 |
+ unsigned int number = 0; /* neutral placeholding value */
|
|
|
738028 |
+
|
|
|
738028 |
+ switch(kw.keydef->type) {
|
|
|
738028 |
+ case kt_list:
|
|
|
738028 |
+ number = parser_enum_list(kw.keydef, value, TRUE);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_enum:
|
|
|
738028 |
+ number = parser_enum_list(kw.keydef, value, FALSE);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_rsakey:
|
|
|
738028 |
+ case kt_loose_enum:
|
|
|
738028 |
+ number = parser_loose_enum(&kw, value);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_string:
|
|
|
738028 |
+ case kt_appendstring:
|
|
|
738028 |
+ case kt_appendlist:
|
|
|
738028 |
+ case kt_filename:
|
|
|
738028 |
+ case kt_dirname:
|
|
|
738028 |
+ case kt_ipaddr:
|
|
|
738028 |
+ case kt_bitstring:
|
|
|
738028 |
+ case kt_idtype:
|
|
|
738028 |
+ case kt_range:
|
|
|
738028 |
+ case kt_subnet:
|
|
|
738028 |
+ string = strdup(value);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+
|
|
|
738028 |
+ case kt_bool:
|
|
|
738028 |
+ case kt_invertbool:
|
|
|
738028 |
+ case kt_number:
|
|
|
738028 |
+ case kt_time:
|
|
|
738028 |
+ case kt_percent:
|
|
|
738028 |
yyerror("keyword value is a keyword, but type not a string");
|
|
|
738028 |
assert(kw.keydef->type != kt_bool);
|
|
|
738028 |
break;
|
|
|
738028 |
|
|
|
738028 |
- case kt_comment:
|
|
|
738028 |
- break;
|
|
|
738028 |
+ case kt_comment:
|
|
|
738028 |
+ break;
|
|
|
738028 |
|
|
|
738028 |
- case kt_obsolete:
|
|
|
738028 |
- case kt_obsolete_quiet:
|
|
|
738028 |
- break;
|
|
|
738028 |
- }
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
-
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (*_parser_kw == NULL)
|
|
|
738028 |
- *_parser_kw = new;
|
|
|
738028 |
+ case kt_obsolete:
|
|
|
738028 |
+ case kt_obsolete_quiet:
|
|
|
738028 |
+ break;
|
|
|
738028 |
}
|
|
|
738028 |
+
|
|
|
738028 |
+ new_parser_kw(&kw, string, number);
|
|
|
738028 |
}
|
|
|
738028 |
| COMMENT EQUAL STRING {
|
|
|
738028 |
- struct starter_comments *new;
|
|
|
738028 |
+ struct starter_comments *new =
|
|
|
738028 |
+ malloc(sizeof(struct starter_comments));
|
|
|
738028 |
|
|
|
738028 |
- new = alloc_comment();
|
|
|
738028 |
if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
+ yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
} else {
|
|
|
738028 |
- new->x_comment = strdup($1.string);
|
|
|
738028 |
- new->commentvalue = strdup($3);
|
|
|
738028 |
- TAILQ_INSERT_TAIL(_parser_comments, new, link);
|
|
|
738028 |
+ new->x_comment = strdup($1.string);
|
|
|
738028 |
+ new->commentvalue = strdup($3);
|
|
|
738028 |
+ TAILQ_INSERT_TAIL(parser_comments, new, link);
|
|
|
738028 |
}
|
|
|
738028 |
}
|
|
|
738028 |
| KEYWORD EQUAL STRING {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
+ struct keyword kw = $1;
|
|
|
738028 |
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- struct keyword kw;
|
|
|
738028 |
+ char *string = NULL; /* neutral placeholding value */
|
|
|
738028 |
+ unsigned int number = 0; /* neutral placeholding value */
|
|
|
738028 |
|
|
|
738028 |
- kw = $1;
|
|
|
738028 |
- new->keyword = kw;
|
|
|
738028 |
+ switch(kw.keydef->type) {
|
|
|
738028 |
+ case kt_list:
|
|
|
738028 |
+ number = parser_enum_list(kw.keydef, $3, TRUE);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_enum:
|
|
|
738028 |
+ number = parser_enum_list(kw.keydef, $3, FALSE);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_rsakey:
|
|
|
738028 |
+ case kt_loose_enum:
|
|
|
738028 |
+ number = parser_loose_enum(&kw, $3);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_string:
|
|
|
738028 |
+ case kt_appendstring:
|
|
|
738028 |
+ case kt_appendlist:
|
|
|
738028 |
+ case kt_filename:
|
|
|
738028 |
+ case kt_dirname:
|
|
|
738028 |
+ case kt_ipaddr:
|
|
|
738028 |
+ case kt_bitstring:
|
|
|
738028 |
+ case kt_idtype:
|
|
|
738028 |
+ case kt_range:
|
|
|
738028 |
+ case kt_subnet:
|
|
|
738028 |
+ string = $3;
|
|
|
738028 |
+ break;
|
|
|
738028 |
|
|
|
738028 |
- switch(kw.keydef->type) {
|
|
|
738028 |
- case kt_list:
|
|
|
738028 |
- new->number = parser_enum_list(kw.keydef, $3, TRUE);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_enum:
|
|
|
738028 |
- new->number = parser_enum_list(kw.keydef, $3, FALSE);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_rsakey:
|
|
|
738028 |
- case kt_loose_enum:
|
|
|
738028 |
- new->number = parser_loose_enum(&new->keyword, $3);
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_string:
|
|
|
738028 |
- case kt_appendstring:
|
|
|
738028 |
- case kt_appendlist:
|
|
|
738028 |
- case kt_filename:
|
|
|
738028 |
- case kt_dirname:
|
|
|
738028 |
- case kt_ipaddr:
|
|
|
738028 |
- case kt_bitstring:
|
|
|
738028 |
- case kt_idtype:
|
|
|
738028 |
- case kt_range:
|
|
|
738028 |
- case kt_subnet:
|
|
|
738028 |
- new->string = $3;
|
|
|
738028 |
- break;
|
|
|
738028 |
-
|
|
|
738028 |
- case kt_bool:
|
|
|
738028 |
- case kt_invertbool:
|
|
|
738028 |
- case kt_number:
|
|
|
738028 |
- case kt_time:
|
|
|
738028 |
- case kt_percent:
|
|
|
738028 |
+ case kt_bool:
|
|
|
738028 |
+ case kt_invertbool:
|
|
|
738028 |
+ case kt_number:
|
|
|
738028 |
+ case kt_time:
|
|
|
738028 |
+ case kt_percent:
|
|
|
738028 |
yyerror("valid keyword, but value is not a number");
|
|
|
738028 |
- assert(!(kw.keydef->type == kt_bool));
|
|
|
738028 |
+ assert(kw.keydef->type != kt_bool);
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_comment:
|
|
|
738028 |
+ break;
|
|
|
738028 |
+ case kt_obsolete:
|
|
|
738028 |
+ case kt_obsolete_quiet:
|
|
|
738028 |
break;
|
|
|
738028 |
- case kt_comment:
|
|
|
738028 |
- break;
|
|
|
738028 |
- case kt_obsolete:
|
|
|
738028 |
- case kt_obsolete_quiet:
|
|
|
738028 |
- break;
|
|
|
738028 |
- }
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
-
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (!*_parser_kw) *_parser_kw = new;
|
|
|
738028 |
}
|
|
|
738028 |
+
|
|
|
738028 |
+ new_parser_kw(&kw, string, number);
|
|
|
738028 |
}
|
|
|
738028 |
|
|
|
738028 |
| BOOLWORD EQUAL BOOL {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
-
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- new->keyword = $1;
|
|
|
738028 |
- new->number = $<num>3; /* Should not be necessary! */
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (!*_parser_kw) *_parser_kw = new;
|
|
|
738028 |
- }
|
|
|
738028 |
+ new_parser_kw(&$1, NULL, $<num>3);
|
|
|
738028 |
}
|
|
|
738028 |
| KEYWORD EQUAL INTEGER {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
-
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- new->keyword = $1;
|
|
|
738028 |
- new->number = $<num>3; /* Should not be necessary! */
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (!*_parser_kw) *_parser_kw = new;
|
|
|
738028 |
- }
|
|
|
738028 |
+ new_parser_kw(&$1, NULL, $<num>3);
|
|
|
738028 |
}
|
|
|
738028 |
- | TIMEWORD EQUAL STRING {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
- char *endptr, *str;
|
|
|
738028 |
- unsigned int val;
|
|
|
738028 |
+ | TIMEWORD EQUAL duration {
|
|
|
738028 |
+ new_parser_kw(&$1, NULL, $3);
|
|
|
738028 |
+ }
|
|
|
738028 |
+ | PERCENTWORD EQUAL STRING {
|
|
|
738028 |
struct keyword kw = $1;
|
|
|
738028 |
- bool fail;
|
|
|
738028 |
- char buf[80];
|
|
|
738028 |
-
|
|
|
738028 |
-
|
|
|
738028 |
- fail = FALSE;
|
|
|
738028 |
-
|
|
|
738028 |
- str = $3;
|
|
|
738028 |
-
|
|
|
738028 |
- val = strtoul(str, &endptr, 10);
|
|
|
738028 |
-
|
|
|
738028 |
- if(endptr == str) {
|
|
|
738028 |
- snprintf(buf, sizeof(buf), "bad duration value %s=%s", kw.keydef->keyname, str);
|
|
|
738028 |
- yyerror(buf);
|
|
|
738028 |
- fail = TRUE;
|
|
|
738028 |
+ const char *const str = $3;
|
|
|
738028 |
+ /*const*/ char *endptr;
|
|
|
738028 |
+ char buf[80];
|
|
|
738028 |
+ unsigned long val = (errno = 0, strtoul(str, &endptr, 10));
|
|
|
738028 |
+
|
|
|
738028 |
+ if (endptr == str) {
|
|
|
738028 |
+ snprintf(buf, sizeof(buf),
|
|
|
738028 |
+ "malformed percentage %s=%s",
|
|
|
738028 |
+ kw.keydef->keyname, str);
|
|
|
738028 |
+ yyerror(buf);
|
|
|
738028 |
+ } else if (*endptr != '%' || endptr[1] != '\0') {
|
|
|
738028 |
+ snprintf(buf, sizeof(buf),
|
|
|
738028 |
+ "bad percentage multiplier \"%s\" on %s",
|
|
|
738028 |
+ endptr, str);
|
|
|
738028 |
+ yyerror(buf);
|
|
|
738028 |
+ } else if (errno != 0 || val > UINT_MAX) {
|
|
|
738028 |
+ snprintf(buf, sizeof(buf),
|
|
|
738028 |
+ "percentage way too large \"%s\"", str);
|
|
|
738028 |
+ yyerror(buf);
|
|
|
738028 |
+ } else {
|
|
|
738028 |
+ new_parser_kw(&kw, NULL, (unsigned int)val);
|
|
|
738028 |
}
|
|
|
738028 |
+ }
|
|
|
738028 |
+ | KEYWORD EQUAL BOOL {
|
|
|
738028 |
+ new_parser_kw(&$1, NULL, $<num>3);
|
|
|
738028 |
+ }
|
|
|
738028 |
+ | KEYWORD EQUAL { /* this is meaningless, we ignore it */ }
|
|
|
738028 |
+ ;
|
|
|
738028 |
|
|
|
738028 |
- if(!fail)
|
|
|
738028 |
- {
|
|
|
738028 |
+duration:
|
|
|
738028 |
+ INTEGER {
|
|
|
738028 |
+ $$ = $1;
|
|
|
738028 |
+ }
|
|
|
738028 |
+ | STRING {
|
|
|
738028 |
+ const char *const str = $1;
|
|
|
738028 |
+ /*const*/ char *endptr;
|
|
|
738028 |
+ char buf[80];
|
|
|
738028 |
+
|
|
|
738028 |
+ unsigned long val = (errno = 0, strtoul(str, &endptr, 10));
|
|
|
738028 |
+ int strtoul_errno = errno;
|
|
|
738028 |
+
|
|
|
738028 |
+ if (endptr == str) {
|
|
|
738028 |
+ snprintf(buf, sizeof(buf), "bad duration value \"%s\"", str);
|
|
|
738028 |
+ yyerror(buf);
|
|
|
738028 |
+ } else {
|
|
|
738028 |
+ bool bad_suffix = FALSE;
|
|
|
738028 |
unsigned scale;
|
|
|
738028 |
|
|
|
738028 |
if (*endptr == '\0') {
|
|
|
738028 |
@@ -350,194 +327,87 @@
|
|
|
738028 |
case 'd': scale = secs_per_day; break;
|
|
|
738028 |
case 'w': scale = 7*secs_per_day; break;
|
|
|
738028 |
default:
|
|
|
738028 |
- snprintf(buf, sizeof(buf),
|
|
|
738028 |
- "bad duration multiplier '%c' on %s",
|
|
|
738028 |
- *endptr, str);
|
|
|
738028 |
- yyerror(buf);
|
|
|
738028 |
- fail=TRUE;
|
|
|
738028 |
+ bad_suffix = TRUE;
|
|
|
738028 |
}
|
|
|
738028 |
} else {
|
|
|
738028 |
+ bad_suffix = TRUE;
|
|
|
738028 |
+ }
|
|
|
738028 |
+
|
|
|
738028 |
+ if (bad_suffix) {
|
|
|
738028 |
snprintf(buf, sizeof(buf),
|
|
|
738028 |
"bad duration multiplier \"%s\" on %s",
|
|
|
738028 |
endptr, str);
|
|
|
738028 |
yyerror(buf);
|
|
|
738028 |
- fail=TRUE;
|
|
|
738028 |
- }
|
|
|
738028 |
-
|
|
|
738028 |
- if (!fail) {
|
|
|
738028 |
- if (UINT_MAX / scale < val) {
|
|
|
738028 |
- snprintf(buf, sizeof(buf),
|
|
|
738028 |
- "overflow scaling %s",
|
|
|
738028 |
- str);
|
|
|
738028 |
- yyerror(buf);
|
|
|
738028 |
- fail=TRUE;
|
|
|
738028 |
- } else {
|
|
|
738028 |
- val *= scale;
|
|
|
738028 |
- }
|
|
|
738028 |
+ } else if (strtoul_errno != 0 || UINT_MAX / scale < val) {
|
|
|
738028 |
+ snprintf(buf, sizeof(buf),
|
|
|
738028 |
+ "duration too large: \"%s\" is more than %u seconds",
|
|
|
738028 |
+ str, UINT_MAX);
|
|
|
738028 |
+ yyerror(buf);
|
|
|
738028 |
+ } else {
|
|
|
738028 |
+ $$ = val * scale;
|
|
|
738028 |
}
|
|
|
738028 |
- }
|
|
|
738028 |
-
|
|
|
738028 |
- if(!fail)
|
|
|
738028 |
- {
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- new->keyword = $1;
|
|
|
738028 |
- new->number = val;
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (*_parser_kw == NULL)
|
|
|
738028 |
- *_parser_kw = new;
|
|
|
738028 |
- }
|
|
|
738028 |
- }
|
|
|
738028 |
- }
|
|
|
738028 |
- | PERCENTWORD EQUAL STRING {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
- char *endptr, *str;
|
|
|
738028 |
- struct keyword kw = $1;
|
|
|
738028 |
- unsigned int val;
|
|
|
738028 |
- bool fail;
|
|
|
738028 |
- char buf[80];
|
|
|
738028 |
-
|
|
|
738028 |
-
|
|
|
738028 |
- fail = FALSE;
|
|
|
738028 |
-
|
|
|
738028 |
- str = $3;
|
|
|
738028 |
-
|
|
|
738028 |
- val = strtoul(str, &endptr, 10);
|
|
|
738028 |
-
|
|
|
738028 |
- if(endptr == str) {
|
|
|
738028 |
- snprintf(buf, sizeof(buf), "bad percent value %s=%s", kw.keydef->keyname, str);
|
|
|
738028 |
- yyerror(buf);
|
|
|
738028 |
- fail = TRUE;
|
|
|
738028 |
-
|
|
|
738028 |
- }
|
|
|
738028 |
-
|
|
|
738028 |
- if(!fail)
|
|
|
738028 |
- {
|
|
|
738028 |
- if ((*endptr == '%') && (endptr[1] == '\0')) { }
|
|
|
738028 |
- else {
|
|
|
738028 |
- snprintf(buf, sizeof(buf), "bad percentage multiplier '%c' on %s", *endptr, str);
|
|
|
738028 |
- yyerror(buf);
|
|
|
738028 |
- fail=TRUE;
|
|
|
738028 |
- }
|
|
|
738028 |
- }
|
|
|
738028 |
-
|
|
|
738028 |
- if(!fail)
|
|
|
738028 |
- {
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new == NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- new->keyword = $1;
|
|
|
738028 |
- new->number = val;
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (*_parser_kw == NULL)
|
|
|
738028 |
- *_parser_kw = new;
|
|
|
738028 |
- }
|
|
|
738028 |
- }
|
|
|
738028 |
- }
|
|
|
738028 |
- | KEYWORD EQUAL BOOL {
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
-
|
|
|
738028 |
- assert(_parser_kw != NULL);
|
|
|
738028 |
- new = alloc_kwlist();
|
|
|
738028 |
- if (new != NULL) {
|
|
|
738028 |
- yyerror("can't allocate memory in statement_kw");
|
|
|
738028 |
- } else {
|
|
|
738028 |
- new->keyword = $1;
|
|
|
738028 |
- new->number = $<num>3; /* Should not be necessary! */
|
|
|
738028 |
- new->next = NULL;
|
|
|
738028 |
- if (_parser_kw_last)
|
|
|
738028 |
- _parser_kw_last->next = new;
|
|
|
738028 |
- _parser_kw_last = new;
|
|
|
738028 |
- if (*_parser_kw == NULL)
|
|
|
738028 |
- *_parser_kw = new;
|
|
|
738028 |
}
|
|
|
738028 |
- }
|
|
|
738028 |
- | KEYWORD EQUAL { /* this is meaningless, we ignore it */ }
|
|
|
738028 |
- ;
|
|
|
738028 |
-
|
|
|
738028 |
+ };
|
|
|
738028 |
%%
|
|
|
738028 |
|
|
|
738028 |
void yyerror(const char *s)
|
|
|
738028 |
{
|
|
|
738028 |
- if (_save_errors_)
|
|
|
738028 |
+ if (save_errors)
|
|
|
738028 |
parser_y_error(parser_errstring, ERRSTRING_LEN, s);
|
|
|
738028 |
}
|
|
|
738028 |
|
|
|
738028 |
struct config_parsed *parser_load_conf(const char *file, err_t *perr)
|
|
|
738028 |
{
|
|
|
738028 |
- struct config_parsed *cfg=NULL;
|
|
|
738028 |
- int err = 0;
|
|
|
738028 |
- FILE *f;
|
|
|
738028 |
-
|
|
|
738028 |
- zero(&parser_errstring);
|
|
|
738028 |
+ parser_errstring[0] = '\0';
|
|
|
738028 |
if (perr != NULL)
|
|
|
738028 |
*perr = NULL;
|
|
|
738028 |
|
|
|
738028 |
- cfg = (struct config_parsed *)malloc(sizeof(struct config_parsed));
|
|
|
738028 |
- if (cfg == NULL)
|
|
|
738028 |
- {
|
|
|
738028 |
- snprintf(parser_errstring, ERRSTRING_LEN, "can't allocate memory");
|
|
|
738028 |
- err++;
|
|
|
738028 |
- goto end;
|
|
|
738028 |
+ struct config_parsed *cfg = malloc(sizeof(struct config_parsed));
|
|
|
738028 |
+
|
|
|
738028 |
+ if (cfg == NULL) {
|
|
|
738028 |
+ snprintf(parser_errstring, ERRSTRING_LEN, "can't allocate memory");
|
|
|
738028 |
+ goto err;
|
|
|
738028 |
}
|
|
|
738028 |
zero(cfg); /* ??? pointer fields may not be NULLed */
|
|
|
738028 |
- if (strncmp(file, "-", sizeof("-")) == 0) {
|
|
|
738028 |
- f = fdopen(STDIN_FILENO, "r");
|
|
|
738028 |
- }
|
|
|
738028 |
- else {
|
|
|
738028 |
- f = fopen(file, "r");
|
|
|
738028 |
- }
|
|
|
738028 |
- if (!f)
|
|
|
738028 |
- {
|
|
|
738028 |
- snprintf(parser_errstring, ERRSTRING_LEN, "can't load file '%s'",
|
|
|
738028 |
- file);
|
|
|
738028 |
- err++;
|
|
|
738028 |
- goto end;
|
|
|
738028 |
+
|
|
|
738028 |
+ FILE *f = streq(file, "-") ?
|
|
|
738028 |
+ fdopen(STDIN_FILENO, "r") : fopen(file, "r");
|
|
|
738028 |
+
|
|
|
738028 |
+ if (f == NULL) {
|
|
|
738028 |
+ snprintf(parser_errstring, ERRSTRING_LEN, "can't load file '%s'",
|
|
|
738028 |
+ file);
|
|
|
738028 |
+ goto err;
|
|
|
738028 |
}
|
|
|
738028 |
|
|
|
738028 |
yyin = f;
|
|
|
738028 |
parser_y_init(file, f);
|
|
|
738028 |
- _save_errors_=1;
|
|
|
738028 |
+ save_errors = TRUE;
|
|
|
738028 |
TAILQ_INIT(&cfg->sections);
|
|
|
738028 |
TAILQ_INIT(&cfg->comments);
|
|
|
738028 |
- _parser_cfg = cfg;
|
|
|
738028 |
+ parser_cfg = cfg;
|
|
|
738028 |
|
|
|
738028 |
- if (yyparse()!=0) {
|
|
|
738028 |
- if (parser_errstring[0]=='\0') {
|
|
|
738028 |
- snprintf(parser_errstring, ERRSTRING_LEN,
|
|
|
738028 |
- "Unknown error...");
|
|
|
738028 |
- }
|
|
|
738028 |
- _save_errors_=0;
|
|
|
738028 |
- while (yyparse()!=0);
|
|
|
738028 |
- err++;
|
|
|
738028 |
- goto end;
|
|
|
738028 |
- }
|
|
|
738028 |
- if (parser_errstring[0]!='\0') {
|
|
|
738028 |
- err++;
|
|
|
738028 |
- goto end;
|
|
|
738028 |
- }
|
|
|
738028 |
- /**
|
|
|
738028 |
- * Config valid
|
|
|
738028 |
- */
|
|
|
738028 |
-end:
|
|
|
738028 |
- if (err) {
|
|
|
738028 |
- if (perr) *perr = (err_t)strdup(parser_errstring);
|
|
|
738028 |
- if (cfg) parser_free_conf (cfg);
|
|
|
738028 |
- cfg = NULL;
|
|
|
738028 |
+ if (yyparse() != 0) {
|
|
|
738028 |
+ if (parser_errstring[0] == '\0') {
|
|
|
738028 |
+ snprintf(parser_errstring, ERRSTRING_LEN,
|
|
|
738028 |
+ "Unknown error...");
|
|
|
738028 |
+ }
|
|
|
738028 |
+ save_errors = FALSE;
|
|
|
738028 |
+ do {} while (yyparse() != 0);
|
|
|
738028 |
+ } else if (parser_errstring[0] == '\0') {
|
|
|
738028 |
+ /**
|
|
|
738028 |
+ * Config valid
|
|
|
738028 |
+ */
|
|
|
738028 |
+ return cfg;
|
|
|
738028 |
}
|
|
|
738028 |
+ /* falls through on error */
|
|
|
738028 |
+
|
|
|
738028 |
+err:
|
|
|
738028 |
+ if (perr != NULL)
|
|
|
738028 |
+ *perr = (err_t)strdup(parser_errstring);
|
|
|
738028 |
+ if (cfg != NULL)
|
|
|
738028 |
+ parser_free_conf(cfg);
|
|
|
738028 |
|
|
|
738028 |
- return cfg;
|
|
|
738028 |
+ return NULL;
|
|
|
738028 |
}
|
|
|
738028 |
|
|
|
738028 |
static void parser_free_kwlist(struct kw_list *list)
|
|
|
738028 |
@@ -546,7 +416,7 @@
|
|
|
738028 |
struct kw_list *elt = list;
|
|
|
738028 |
|
|
|
738028 |
list = list->next;
|
|
|
738028 |
- if (elt->string)
|
|
|
738028 |
+ if (elt->string != NULL)
|
|
|
738028 |
free(elt->string);
|
|
|
738028 |
free(elt);
|
|
|
738028 |
}
|
|
|
738028 |
@@ -554,16 +424,18 @@
|
|
|
738028 |
|
|
|
738028 |
void parser_free_conf(struct config_parsed *cfg)
|
|
|
738028 |
{
|
|
|
738028 |
- struct section_list *seci, *sec;
|
|
|
738028 |
- if (cfg) {
|
|
|
738028 |
+ if (cfg != NULL) {
|
|
|
738028 |
+ struct section_list *seci;
|
|
|
738028 |
+
|
|
|
738028 |
parser_free_kwlist(cfg->config_setup);
|
|
|
738028 |
|
|
|
738028 |
- for(seci = cfg->sections.tqh_first; seci != NULL; )
|
|
|
738028 |
- {
|
|
|
738028 |
- sec = seci;
|
|
|
738028 |
+ for (seci = cfg->sections.tqh_first; seci != NULL; ) {
|
|
|
738028 |
+ struct section_list *sec = seci;
|
|
|
738028 |
+
|
|
|
738028 |
seci = seci->link.tqe_next;
|
|
|
738028 |
|
|
|
738028 |
- if (sec->name) free(sec->name);
|
|
|
738028 |
+ if (sec->name != NULL)
|
|
|
738028 |
+ free(sec->name);
|
|
|
738028 |
parser_free_kwlist(sec->kw);
|
|
|
738028 |
free(sec);
|
|
|
738028 |
}
|
|
|
738028 |
@@ -572,20 +444,32 @@
|
|
|
738028 |
}
|
|
|
738028 |
}
|
|
|
738028 |
|
|
|
738028 |
-static struct kw_list *alloc_kwlist(void)
|
|
|
738028 |
+static void new_parser_kw(struct keyword *keyword, char *string, unsigned int number)
|
|
|
738028 |
{
|
|
|
738028 |
- struct kw_list *new;
|
|
|
738028 |
-
|
|
|
738028 |
- new = (struct kw_list *)malloc(sizeof(struct kw_list));
|
|
|
738028 |
- zero(new); /* ??? pointer members might not be set to NULL */
|
|
|
738028 |
- return new;
|
|
|
738028 |
-}
|
|
|
738028 |
+ struct kw_list *new = malloc(sizeof(struct kw_list));
|
|
|
738028 |
|
|
|
738028 |
-static struct starter_comments *alloc_comment(void)
|
|
|
738028 |
-{
|
|
|
738028 |
- struct starter_comments *new;
|
|
|
738028 |
+ if (new == NULL) {
|
|
|
738028 |
+ yyerror("cannot allocate memory for a kw_list");
|
|
|
738028 |
+ } else {
|
|
|
738028 |
+ /*
|
|
|
738028 |
+ * fill the values into new
|
|
|
738028 |
+ * (either string or number might have a placeholder value
|
|
|
738028 |
+ */
|
|
|
738028 |
+ new->keyword = *keyword;
|
|
|
738028 |
+ new->string = string;
|
|
|
738028 |
+ new->number = number;
|
|
|
738028 |
+ new->next = NULL;
|
|
|
738028 |
+
|
|
|
738028 |
+ /* link the new kw_list into the list */
|
|
|
738028 |
+
|
|
|
738028 |
+ if (*parser_kw == NULL)
|
|
|
738028 |
+ *parser_kw = new; /* first in (some) list */
|
|
|
738028 |
+
|
|
|
738028 |
+ /* connect to previous last on list */
|
|
|
738028 |
+ if (parser_kw_last != NULL)
|
|
|
738028 |
+ parser_kw_last->next = new;
|
|
|
738028 |
|
|
|
738028 |
- new = (struct starter_comments *)malloc(sizeof(struct starter_comments));
|
|
|
738028 |
- zero(new); /* ??? pointer members might not be set to NULL */
|
|
|
738028 |
- return new;
|
|
|
738028 |
+ /* new is new last on list */
|
|
|
738028 |
+ parser_kw_last = new;
|
|
|
738028 |
+ }
|
|
|
738028 |
}
|