--- snmplib/mib.c.CLN	2006-10-16 17:45:54.000000000 +0100
+++ snmplib/mib.c	2006-10-16 22:43:21.000000000 +0100
@@ -42,6 +42,24 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <sys/types.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_NETINET_IN_H
 #include <netinet/in.h>
 #endif
@@ -2537,6 +2555,7 @@
      */
     netsnmp_fixup_mib_directory();
     env_var = strdup(netsnmp_get_mib_directory());
+    mibindex_load();
 
     DEBUGMSGTL(("init_mib",
                 "Seen MIBDIRS: Looking in '%s' for mib dirs ...\n",
@@ -2698,6 +2717,130 @@
     }
 }
 
+/*
+ * Handle MIB indexes centrally
+ */
+static int _mibindex     = 0;   /* Last index in use */
+static int _mibindex_max = 0;   /* Size of index array */
+char     **_mibindexes   = NULL;
+
+int _mibindex_add( const char *dirname, int i );
+void
+mibindex_load( void )
+{
+    DIR *dir;
+    struct dirent *file;
+    FILE *fp;
+    char tmpbuf[ 300];
+    char tmpbuf2[300];
+    int  i;
+
+    /*
+     * Open the MIB index directory, or create it (empty)
+     */
+    snprintf( tmpbuf, sizeof(tmpbuf), "%s/mib_indexes",
+              get_persistent_directory());
+    tmpbuf[sizeof(tmpbuf)-1] = 0;
+    dir = opendir( tmpbuf );
+    if ( dir == NULL ) {
+        DEBUGMSGTL(("mibindex", "load: (new)\n"));
+        mkdirhier( tmpbuf, NETSNMP_AGENT_DIRECTORY_MODE, 0);
+        return;
+    }
+
+    /*
+     * Create a list of which directory each file refers to
+     */
+    while ((file = readdir( dir ))) {
+        if ( !isdigit(file->d_name[0]))
+            continue;
+        i = atoi( file->d_name );
+
+        snprintf( tmpbuf, sizeof(tmpbuf), "%s/mib_indexes/%d",
+              get_persistent_directory(), i );
+        tmpbuf[sizeof(tmpbuf)-1] = 0;
+        fp = fopen( tmpbuf, "r" );
+        fgets( tmpbuf2, sizeof(tmpbuf2), fp );
+        tmpbuf2[strlen(tmpbuf2)-1] = 0;
+        DEBUGMSGTL(("mibindex", "load: (%d) %s\n", i, tmpbuf2));
+        (void)_mibindex_add( tmpbuf2+4, i );  /* Skip 'DIR ' */
+        fclose( fp );
+    }
+}
+
+char *
+mibindex_lookup( const char *dirname )
+{
+    int i;
+    static char tmpbuf[300];
+
+    for (i=0; i<_mibindex; i++) {
+        if ( _mibindexes[i] &&
+             strcmp( _mibindexes[i], dirname ) == 0) {
+             snprintf(tmpbuf, sizeof(tmpbuf), "%s/mib_indexes/%d",
+                      get_persistent_directory(), i);
+             tmpbuf[sizeof(tmpbuf)-1] = 0;
+             DEBUGMSGTL(("mibindex", "lookup: %s (%d) %s\n", dirname, i, tmpbuf ));
+             return tmpbuf;
+        }
+    }
+    DEBUGMSGTL(("mibindex", "lookup: (none)\n"));
+    return NULL;
+}
+
+int
+_mibindex_add( const char *dirname, int i )
+{
+    char **cpp;
+
+    DEBUGMSGTL(("mibindex", "add: %s (%d)\n", dirname, i ));
+    if ( i == -1 )
+        i = _mibindex++;
+    if ( i >= _mibindex_max ) {
+        /*
+         * If the index array is full (or non-exitent)
+         *   then expand (or create) it
+         */
+        cpp = (char **)malloc( (10+i) * sizeof(char*));
+        if ( _mibindexes ) {
+            memcpy( cpp, _mibindexes, _mibindex * sizeof(char*));
+            free(_mibindexes);
+        }
+        _mibindexes   = cpp;
+        _mibindex_max = i+10;
+    }
+    DEBUGMSGTL(("mibindex", "add: %d/%d/%d\n", i, _mibindex, _mibindex_max ));
+
+    _mibindexes[ i ] = strdup( dirname );
+    if ( i >= _mibindex )
+        _mibindex = i+1;
+
+    return i;
+}
+    
+FILE *
+mibindex_new( const char *dirname )
+{
+    FILE *fp;
+    char  tmpbuf[300];
+    char *cp;
+    int   i;
+
+    cp = mibindex_lookup( dirname );
+    if (!cp) {
+        i  = _mibindex_add( dirname, -1 );
+        snprintf( tmpbuf, sizeof(tmpbuf), "%s/mib_indexes/%d",
+                  get_persistent_directory(), i );
+        tmpbuf[sizeof(tmpbuf)-1] = 0;
+        cp = tmpbuf;
+    }
+    DEBUGMSGTL(("mibindex", "new: %s (%s)\n", dirname, cp ));
+    fp = fopen( cp, "w" );
+    fprintf( fp, "DIR %s\n", dirname );
+    return fp;
+}
+
+
 /**
  * Unloads all mibs.
  */
--- snmplib/parse.c.CLN	2006-10-16 17:37:53.000000000 +0100
+++ snmplib/parse.c	2006-10-16 20:44:36.000000000 +0100
@@ -4705,8 +4705,8 @@
     char            tmpstr[300];
     int             count = 0;
     int             fname_len = 0;
+    char           *token;
 #if !(defined(WIN32) || defined(cygwin))
-    char            token[MAXTOKEN];
     char space;
     char newline;
     struct stat     dir_stat, idx_stat;
@@ -4715,12 +4715,12 @@
 
     DEBUGMSGTL(("parse-mibs", "Scanning directory %s\n", dirname));
 #if !(defined(WIN32) || defined(cygwin))
-    snprintf(token, sizeof(token), "%s/%s", dirname, ".index");
-    token[ sizeof(token)-1 ] = 0;
-    if (stat(token, &idx_stat) == 0 && stat(dirname, &dir_stat) == 0) {
+    token = mibindex_lookup( dirname );
+    if (token && stat(token, &idx_stat) == 0 && stat(dirname, &dir_stat) == 0) {
         if (dir_stat.st_mtime < idx_stat.st_mtime) {
             DEBUGMSGTL(("parse-mibs", "The index is good\n"));
             if ((ip = fopen(token, "r")) != NULL) {
+                fgets(tmpstr, sizeof(tmpstr), ip); /* Skip dir line */
                 while (fscanf(ip, "%127s%c%299s%c", token, &space, tmpstr,
 		    &newline) == 4) {
 
@@ -4753,9 +4753,7 @@
 #endif
 
     if ((dir = opendir(dirname))) {
-        snprintf(tmpstr, sizeof(tmpstr), "%s/.index", dirname);
-        tmpstr[ sizeof(tmpstr)-1 ] = 0;
-        ip = fopen(tmpstr, "w");
+        ip = mibindex_new( dirname );
         while ((file = readdir(dir))) {
             /*
              * Only parse file names that don't begin with a '.' 
--- include/net-snmp/library/mib.h.CLN	2006-10-16 20:38:23.000000000 +0100
+++ include/net-snmp/library/mib.h	2006-10-16 20:45:33.000000000 +0100
@@ -118,6 +118,9 @@
     void            netsnmp_set_mib_directory(const char *dir);
     char            *netsnmp_get_mib_directory(void);
     void            netsnmp_fixup_mib_directory(void);
+    void            mibindex_load( void );
+    char *          mibindex_lookup( const char * );
+    FILE *          mibindex_new( const char * );
     void            init_mib(void);
     void            shutdown_mib(void);
     void            print_description(oid *, size_t, int);
