From 99be0e73e3addded4ee2c0bfeaba2e19ad178fac Mon Sep 17 00:00:00 2001 From: Greg Hudson Date: Wed, 25 Aug 2010 18:22:53 +0000 Subject: [PATCH] Revise the profile include design so that included files are syntactically independent of parent files. ticket: 6761 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24256 dc483132-0cff-0310-8789-dd5450dbe970 --- doc/krb5conf.texinfo | 5 +++-- src/config-files/krb5.conf.M | 3 ++- src/util/profile/prof_parse.c | 35 ++++++++++++++++++++--------------- src/util/profile/prof_test1 | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/doc/krb5conf.texinfo b/doc/krb5conf.texinfo index 21f539653..911435061 100644 --- a/doc/krb5conf.texinfo +++ b/doc/krb5conf.texinfo @@ -51,8 +51,9 @@ includedir @var{DIRNAME} @var{FILENAME} or @var{DIRNAME} should be an absolute path. The named file or directory must exist and be readable. Including a directory includes all files within the directory whose names consist solely of -alphanumeric characters, dashes, or underscores. Included configuration -fragments should begin with a section header. +alphanumeric characters, dashes, or underscores. Included profile files +are syntactically independent of their parents, so each included file +must begin with a section header. The @code{krb5.conf} file may contain any or all of the following sections: diff --git a/src/config-files/krb5.conf.M b/src/config-files/krb5.conf.M index 40db552d3..db3305f59 100644 --- a/src/config-files/krb5.conf.M +++ b/src/config-files/krb5.conf.M @@ -67,7 +67,8 @@ FILENAME or DIRNAME should be an absolute path. The named file or directory must exist and be readable. Including a directory includes all files within the directory whose names consist solely of alphanumeric characters, dashes, or underscores. Included profile -fragments should begin with a section header. +files are syntactically independent of their parents, so each included +file must begin with a section header. .PP The following sections are currently used in the diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c index 742db0555..7f3d4c9d4 100644 --- a/src/util/profile/prof_parse.c +++ b/src/util/profile/prof_parse.c @@ -70,14 +70,6 @@ static void parse_quoted_string(char *str) } -static errcode_t parse_init_state(struct parse_state *state) -{ - state->state = STATE_INIT_COMMENT; - state->group_level = 0; - - return profile_create_node("(root)", 0, &state->root_section); -} - static errcode_t parse_std_line(char *line, struct parse_state *state) { char *cp, ch, *tag, *value; @@ -205,16 +197,24 @@ static errcode_t parse_std_line(char *line, struct parse_state *state) return 0; } -/* Parse lines from filename as if they were part of the profile file. */ +/* Open and parse an included profile file. */ static errcode_t parse_include_file(char *filename, struct parse_state *state) { FILE *fp; errcode_t retval = 0; + struct parse_state incstate; + + /* Create a new state so that fragments are syntactically independent, + * sharing the root section with the existing state. */ + incstate.state = STATE_INIT_COMMENT; + incstate.group_level = 0; + incstate.root_section = state->root_section; + incstate.current_section = NULL; fp = fopen(filename, "r"); if (fp == NULL) return PROF_FAIL_INCLUDE_FILE; - retval = parse_file(fp, state); + retval = parse_file(fp, &incstate); fclose(fp); return retval; } @@ -233,10 +233,9 @@ static int valid_name(const char *filename) } /* - * Parse lines from files in dirname as if they were part of the profile file. - * Only files with names consisting entirely of alphanumeric chracters and - * underscores are parsed, in order to avoid parsing editor backup files, - * .rpmsave files, and the like. + * Include files within dirname. Only files with names consisting entirely of + * alphanumeric chracters, dashes, and underscores are included, in order to + * avoid including editor backup files, .rpmsave files, and the like. */ static errcode_t parse_include_dir(char *dirname, struct parse_state *state) { @@ -371,9 +370,15 @@ errcode_t profile_parse_file(FILE *f, struct profile_node **root) errcode_t retval; *root = NULL; - retval = parse_init_state(&state); + + /* Initialize parsing state with a new root node. */ + state.state = STATE_INIT_COMMENT; + state.group_level = 0; + state.current_section = NULL; + retval = profile_create_node("(root)", 0, &state.root_section); if (retval) return retval; + retval = parse_file(f, &state); if (retval) { profile_free_node(state.root_section); diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1 index dc0867123..27ecbb252 100644 --- a/src/util/profile/prof_test1 +++ b/src/util/profile/prof_test1 @@ -203,9 +203,41 @@ proc test4 {} { puts "OK: test4: include and includedir directives" } +proc test5 {} { + global wd verbose + + # Test syntactic independence of included profile files. + catch [file delete $wd/testinc.ini] + set f [open "$wd/testinc.ini" w] + puts $f {[sec1]} + puts $f "var = {" + puts $f "a = 1" + puts $f "include testinc2.ini" + puts $f "c = 3" + puts $f "}" + close $f + catch [file delete $wd/testinc2.ini] + set f [open "$wd/testinc2.ini" w] + puts $f {[sec2]} + puts $f "b = 2" + close $f + set p [profile_init_path $wd/testinc.ini] + set a [profile_get_values $p {sec1 var a}] + set b [profile_get_values $p {sec2 b}] + set c [profile_get_values $p {sec1 var c}] + if $verbose { puts "Read values [concat $a $b $c] from profile" } + if { $a != 1 || $b != 2 || $c != 3 } { + puts stderr, "Error: test5: Wrong results from profile" + exit 1 + } + + puts "OK: test5: syntax independence of included files" +} + test1 test2 test3 test4 +test5 exit 0 -- 2.26.2