krb5 commit: Read /etc/gss/mech if no mech.d/*.conf found

Greg Hudson ghudson at MIT.EDU
Wed Jun 4 16:54:10 EDT 2014


https://github.com/krb5/krb5/commit/ac98187641f6943ae571606c0b6a97f236f9b60c
commit ac98187641f6943ae571606c0b6a97f236f9b60c
Author: Greg Hudson <ghudson at mit.edu>
Date:   Wed May 28 23:51:49 2014 -0400

    Read /etc/gss/mech if no mech.d/*.conf found
    
    Always read /etc/gss/mech, even if globbing /etc/gss/mech.d/*.conf
    doesn't work.  Doing this using GLOB_DOOFFS proved error-prone, so use
    a simpler approach: factor out the per-pathname handling into a helper
    function load_if_changed, call it with MECH_CONF before the glob, then
    pass each glob result through the helper.
    
    ticket: 7925

 src/lib/gssapi/mechglue/g_initialize.c |   43 ++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/lib/gssapi/mechglue/g_initialize.c b/src/lib/gssapi/mechglue/g_initialize.c
index f0acf1a..8bce14c 100644
--- a/src/lib/gssapi/mechglue/g_initialize.c
+++ b/src/lib/gssapi/mechglue/g_initialize.c
@@ -402,38 +402,45 @@ check_link_mtime(const char *filename, time_t *mtime_out)
 	return (st1.st_mtime > st2.st_mtime) ? st1.st_mtime : st2.st_mtime;
 }
 
+/* Load pathname if it is newer than last.  Update *highest to the maximum of
+ * its current value and pathname's mod time. */
+static void
+load_if_changed(const char *pathname, time_t last, time_t *highest)
+{
+	time_t mtime;
+
+	mtime = check_link_mtime(pathname, &mtime);
+	if (mtime == (time_t)-1)
+		return;
+	if (mtime > *highest)
+		*highest = mtime;
+	if (mtime > last)
+		loadConfigFile(pathname);
+}
+
 /* Try to load any config files which have changed since the last call.  Config
  * files are MECH_CONF and any files matching MECH_CONF_PATTERN. */
 static void
 loadConfigFiles()
 {
 	glob_t globbuf;
-	time_t highest_mtime = 0, mtime, now;
-	char **pathptr;
+	time_t highest = 0, now;
+	char **path;
 
 	/* Don't glob and stat more than once per second. */
 	if (time(&now) == (time_t)-1 || now == g_confLastCall)
 		return;
 	g_confLastCall = now;
 
-	globbuf.gl_offs = 1;
-	if (glob(MECH_CONF_PATTERN, GLOB_DOOFFS, NULL, &globbuf) != 0)
-		return;
-	globbuf.gl_pathv[0] = MECH_CONF;
+	load_if_changed(MECH_CONF, g_confFileModTime, &highest);
 
-	for (pathptr = globbuf.gl_pathv; *pathptr != NULL; pathptr++) {
-		mtime = check_link_mtime(*pathptr, &mtime);
-		if (mtime == (time_t)-1)
-			continue;
-		if (mtime > highest_mtime)
-			highest_mtime = mtime;
-		if (mtime > g_confFileModTime)
-			loadConfigFile(*pathptr);
+	if (glob(MECH_CONF_PATTERN, 0, NULL, &globbuf) == 0) {
+		for (path = globbuf.gl_pathv; *path != NULL; path++)
+			load_if_changed(*path, g_confFileModTime, &highest);
+		globfree(&globbuf);
 	}
-	g_confFileModTime = highest_mtime;
 
-	globbuf.gl_pathv[0] = NULL;
-	globfree(&globbuf);
+	g_confFileModTime = highest;
 }
 
 /*


More information about the cvs-krb5 mailing list