فهرست منبع

While processing 'include_dir' statement, sort the files

Fix for issue #97.

Thanks to Philippe Kueck for the patch!
John C. Frickson 9 سال پیش
والد
کامیت
25f49109ec
4فایلهای تغییر یافته به همراه35 افزوده شده و 6 حذف شده
  1. 2 2
      configure
  2. 1 1
      configure.ac
  3. 3 0
      include/config.h.in
  4. 29 3
      src/nrpe.c

+ 2 - 2
configure

@@ -7154,7 +7154,7 @@ rm -f core conftest.err conftest.$ac_objext \
 
 fi
 
-for ac_func in strdup strstr strtoul strtok_r initgroups closesocket sigaction
+for ac_func in strdup strstr strtoul strtok_r initgroups closesocket sigaction scandir
 do :
   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
 ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
@@ -7280,7 +7280,7 @@ fi
 
 if test x$check_for_ssl = xyes; then
 	# need_dh should only be set for NRPE
-	need_dh=no
+	need_dh=yes
 
 
 # -------------------------------

+ 1 - 1
configure.ac

@@ -243,7 +243,7 @@ AC_CHECK_LIB(wrap,main,[
 	AC_TRY_LINK([#include <tcpd.h>
 		],[int a = rfc931_timeout;],AC_DEFINE(HAVE_RFC931_TIMEOUT))
 	])
-AC_CHECK_FUNCS(strdup strstr strtoul strtok_r initgroups closesocket sigaction)
+AC_CHECK_FUNCS(strdup strstr strtoul strtok_r initgroups closesocket sigaction scandir)
 
 dnl socklen_t check - from curl
 AC_CHECK_TYPE([socklen_t], ,[

+ 3 - 0
include/config.h.in

@@ -73,6 +73,9 @@
 /* Define to 1 if you have the `sigaction' function. */
 #undef HAVE_SIGACTION
 
+/* Define to 1 if you have the `scandir' function. */
+#undef HAVE_SCANDIR
+
 /* Set to 1 if you have rfc931_timeout */
 #undef HAVE_RFC931_TIMEOUT
 

+ 29 - 3
src/nrpe.c

@@ -912,12 +912,28 @@ int read_config_file(char *filename)
 int read_config_dir(char *dirname)
 {
 	struct dirent *dirfile;
+#ifdef HAVE_SCANDIR
+	struct dirent **dirfiles;
+	int       x, i, n;
+#else
+	DIR      *dirp;
+	int       x;
+#endif
 	struct stat buf;
 	char      config_file[MAX_FILENAME_LENGTH];
-	DIR      *dirp;
 	int       result = OK;
-	int       x;
 
+#ifdef HAVE_SCANDIR
+	/* read and sort the directory contents */
+	n = scandir(dirname, &dirfiles, 0, alphasort);
+	if (n < 0) {
+		syslog(LOG_ERR, "Could not open config directory '%s' for reading.\n", dirname);
+		return ERROR;
+	}
+
+	for (i = 0; i < n; i++) {
+		dirfile = dirfiles[i];
+#else
 	/* open the directory for reading */
 	dirp = opendir(dirname);
 	if (dirp == NULL) {
@@ -925,8 +941,10 @@ int read_config_dir(char *dirname)
 		return ERROR;
 	}
 
-	/* process all files in the directory... */
 	while ((dirfile = readdir(dirp)) != NULL) {
+#endif
+
+		/* process all files in the directory... */
 
 		/* create the full path to the config file or subdirectory */
 		snprintf(config_file, sizeof(config_file) - 1, "%s/%s", dirname, dirfile->d_name);
@@ -962,10 +980,18 @@ int read_config_dir(char *dirname)
 			/* break out if we encountered an error */
 			if (result == ERROR)
 				break;
+
 		}
 	}
 
+#ifdef HAVE_SCANDIR
+	for (i = 0; i < n; i++)
+		free(dirfiles[i]);
+	free(dirfiles);
+#else
 	closedir(dirp);
+#endif
+
 	return result;
 }