Index: read_config.c
===================================================================
--- read_config.c	(revision 19246)
+++ read_config.c	(working copy)
@@ -113,6 +113,23 @@
 #endif
 #include <errno.h>
 
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+#  include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+#  include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+#  include <ndir.h>
+# endif
+#endif
+
 #if HAVE_DMALLOC_H
 #include <dmalloc.h>
 #endif
@@ -697,9 +714,12 @@
  *
  * For each match, check that <when> is the designated time for the
  * <line_handler> function to be executed before processing the line.
+ *
+ * Return 0 if the file is not processed,
+ * Return 1 if it is.
  */
-void
-read_config(const char *filename,
+int
+_read_config(const char *filename,
             struct config_line *line_handler, int when)
 {
     static int      depth = 0;
@@ -733,20 +753,20 @@
 #else                           /* defined(ENOENT) || defined(EACCES) */
             snmp_log_perror(filename);
 #endif                          /* ENOENT */
-        return;
+        return 0;
     }
 
 #define CONFIG_MAX_FILES 4096
     if (files > CONFIG_MAX_FILES) {
         netsnmp_config_error("maximum conf file count (%d) exceeded\n",
                              CONFIG_MAX_FILES);
-        return;
+        return 0;
     }
 #define CONFIG_MAX_RECURSE_DEPTH 16
     if (depth > CONFIG_MAX_RECURSE_DEPTH) {
         netsnmp_config_error("nested include depth > %d\n",
                              CONFIG_MAX_RECURSE_DEPTH);
-        return;
+        return 0;
     }
     ++files;
     ++depth;
@@ -797,6 +817,29 @@
                      */
                     cptr = copy_nword(cptr, token, sizeof(token));
                 }
+            } else if ((token[0] == 'i') && (strcmp(token,"includedir")==0)) {
+                DIR *d;
+                struct dirent *entry;
+                char  filename[SNMP_MAXPATH];
+                int   len;
+                char *prev_curfilename;
+
+                if ((d=opendir(cptr)) == NULL )
+                    continue;
+                prev_curfilename = curfilename;
+                while ((entry = readdir( d )) != NULL ) {
+                    if ( entry->d_name && entry->d_name[0] != '.') {
+                        len = NAMLEN(entry);
+                        if ((len > 5) && (strcmp(&(entry->d_name[len-5]),".conf") == 0)) {
+                            snprintf(filename, SNMP_MAXPATH, "%s/%s",
+                                     cptr, entry->d_name);
+                            read_config(filename, line_handler, when);
+                        }
+                    }
+                }
+                closedir(d);
+                curfilename = prev_curfilename;
+                continue;
             } else if ((token[0] == 'i') && (strcmp(token,"include")==0)) {
                 struct config_files ctmp;
                 int len = strlen(cptr);
@@ -804,13 +847,22 @@
                 ctmp.fileHeader = cptr;
                 ctmp.start = line_handler;
                 ctmp.next = NULL;
-                if ((len > 5) && (strcmp(&cptr[len-5],".conf") == 0))
-                   cptr[len-5] = 0; /* chop off .conf */
                 prev_curfilename = curfilename;
-                read_config_files_of_type(when,&ctmp);
+                /*
+                 * Try reading the specified file directly first.
+                 */
+                if ( !_read_config(cptr, line_handler, when)) {
+                    /*
+                     * If that doesn't work,
+                     * then search the config path for suitably named file(s)
+                     */
+                    if ((len > 5) && (strcmp(&cptr[len-5],".conf") == 0))
+                        cptr[len-5] = 0; /* chop off .conf */
+                    read_config_files_of_type(when,&ctmp);
+                    if ((len > 5) && (cptr[len-5] == 0))
+                        cptr[len-5] = '.'; /* restore .conf */
+                }
                 curfilename = prev_curfilename;
-                if ((len > 5) && (cptr[len-5] == 0))
-                   cptr[len-5] = '.'; /* restore .conf */
                 continue;
             } else {
                 lptr = line_handler;
@@ -826,12 +878,19 @@
     }
     fclose(ifile);
     --depth;
-    return;
+    return 1;
 
 }                               /* end read_config() */
 
+void
+read_config(const char *filename,
+            struct config_line *line_handler, int when)
+{
+    _read_config(filename, line_handler, when);
+}
 
 
+
 void
 free_config(void)
 {
