krb5 commit: Make profile includedir accept all *.conf files

Greg Hudson ghudson at mit.edu
Thu Mar 24 16:41:59 EDT 2016


https://github.com/krb5/krb5/commit/0744026f06e8cbf477aa49cfe16b5fd28a9ddc9e
commit 0744026f06e8cbf477aa49cfe16b5fd28a9ddc9e
Author: Peter Jones <pjones at redhat.com>
Date:   Fri Feb 26 09:49:58 2016 -0500

    Make profile includedir accept all *.conf files
    
    Since the main config file is krb5.conf, it is intuitive to name
    included files with a ".conf" extension; currently such files are
    silently ignored.  Accept filenames ending in ".conf" as well as files
    with no special characters.
    
    [ghudson at mit.edu: shorten commit message and comment; accept the
    filename ".conf" itself for simplicity; add a test; adjust
    documentation change to note that allowing .conf is new in 1.15]
    
    ticket: 8389 (new)

 doc/admin/conf_files/krb5_conf.rst |    7 ++++---
 src/man/krb5.conf.man              |    7 ++++---
 src/util/profile/prof_parse.c      |   13 +++++++++----
 src/util/profile/prof_test1        |    9 ++++++---
 4 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/doc/admin/conf_files/krb5_conf.rst b/doc/admin/conf_files/krb5_conf.rst
index bf7d240..b31ddff 100644
--- a/doc/admin/conf_files/krb5_conf.rst
+++ b/doc/admin/conf_files/krb5_conf.rst
@@ -54,9 +54,10 @@ following directives at the beginning of a line::
 *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
-files are syntactically independent of their parents, so each included
-file must begin with a section header.
+alphanumeric characters, dashes, or underscores.  Starting in release
+1.15, files with names ending in ".conf" are also included.  Included
+profile files are syntactically independent of their parents, so each
+included file must begin with a section header.
 
 The krb5.conf file can specify that configuration should be obtained
 from a loadable module, rather than the file itself, using the
diff --git a/src/man/krb5.conf.man b/src/man/krb5.conf.man
index a4b30e9..e035072 100644
--- a/src/man/krb5.conf.man
+++ b/src/man/krb5.conf.man
@@ -111,9 +111,10 @@ includedir DIRNAME
 \fIFILENAME\fP or \fIDIRNAME\fP 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
-files are syntactically independent of their parents, so each included
-file must begin with a section header.
+alphanumeric characters, dashes, or underscores, or any filename
+ending in ".conf".  Included profile files are syntactically
+independent of their parents, so each included file must begin with a
+section header.
 .sp
 The krb5.conf file can specify that configuration should be obtained
 from a loadable module, rather than the file itself, using the
diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c
index 1c2a270..e7c1f65 100644
--- a/src/util/profile/prof_parse.c
+++ b/src/util/profile/prof_parse.c
@@ -222,10 +222,14 @@ static errcode_t parse_include_file(const char *filename,
 }
 
 /* Return non-zero if filename contains only alphanumeric characters, dashes,
- * and underscores. */
+ * and underscores, or if the filename ends in ".conf". */
 static int valid_name(const char *filename)
 {
     const char *p;
+    size_t len = strlen(filename);
+
+    if (len >= 5 && !strcmp(filename + len - 5, ".conf"))
+        return 1;
 
     for (p = filename; *p != '\0'; p++) {
         if (!isalnum((unsigned char)*p) && *p != '-' && *p != '_')
@@ -235,9 +239,10 @@ static int valid_name(const char *filename)
 }
 
 /*
- * 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.
+ * Include files within dirname.  Only files with names ending in ".conf", or
+ * consisting entirely of alphanumeric characters, dashes, and underscores are
+ * included.  This restriction avoids including editor backup files, .rpmsave
+ * files, and the like.
  */
 static errcode_t parse_include_dir(const char *dirname,
                                    struct profile_node *root_section)
diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1
index 87368d8..d0bb187 100644
--- a/src/util/profile/prof_test1
+++ b/src/util/profile/prof_test1
@@ -183,12 +183,15 @@ proc test4 {} {
     }
     profile_release $p
 
-    # Test including a directory.  (Put two copies of test2.ini inside
-    # it and check that we get two values for one of the variables.)
+    # Test including a directory.  Put four copies of test2.ini inside
+    # the directory, two with invalid names.  Check that we get two
+    # values for one of the variables.
     catch [file delete -force $wd/test_include_dir]
     exec mkdir $wd/test_include_dir
     exec cp $wd/test2.ini $wd/test_include_dir/a
-    exec cp $wd/test2.ini $wd/test_include_dir/b
+    exec cp $wd/test2.ini $wd/test_include_dir/a~
+    exec cp $wd/test2.ini $wd/test_include_dir/b.conf
+    exec cp $wd/test2.ini $wd/test_include_dir/b.conf.rpmsave
     catch [file delete $wd/testinc.ini]
     exec echo "includedir $wd/test_include_dir" >$wd/testinc.ini
     set p [profile_init_path $wd/testinc.ini]


More information about the cvs-krb5 mailing list