1diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/include/net-snmp/library/dir_utils.h APPLE/include/net-snmp/library/dir_utils.h 2--- SVN/include/net-snmp/library/dir_utils.h 3+++ APPLE/include/net-snmp/library/dir_utils.h 4@@ -0,0 +1,32 @@ 5+ 6+#ifndef NETSNMP_DIR_UTILS_H 7+#define NETSNMP_DIR_UTILS_H 8+ 9+#ifdef _cplusplus 10+extern "C" { 11+#endif 12+ 13+ /*------------------------------------------------------------------ 14+ * 15+ * Prototypes 16+ */ 17+ netsnmp_container * netsnmp_directory_container_read(netsnmp_container *c, 18+ const char *dir, 19+ u_int flags); 20+ void netsnmp_directory_container_free(netsnmp_container *c); 21+ 22+ 23+ 24+ /*------------------------------------------------------------------ 25+ * 26+ * flags 27+ */ 28+#define NETSNMP_DIR_RECURSE 0x1 29+ 30+ 31+ 32+#ifdef _cplusplus 33+} 34+#endif 35+ 36+#endif /* NETSNMP_DIR_UTILS_H */ 37diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/snmplib/Makefile.in APPLE/snmplib/Makefile.in 38--- SVN/snmplib/Makefile.in 39+++ APPLE/snmplib/Makefile.in 40@@ -55,6 +55,7 @@ INCLUDESUBDIRHEADERS=README \ 41 factory.h \ 42 data_list.h \ 43 default_store.h \ 44+ dir_utils.h \ 45 fd_event_manager.h \ 46 file_utils.h \ 47 int64.h \ 48@@ -137,7 +138,7 @@ CSRCS= snmp_client.c mib.c parse.c snmp_ 49 snmp_auth.c asn1.c md5.c snmp_parse_args.c \ 50 system.c vacm.c int64.c read_config.c pkcs.c \ 51 snmp_debug.c tools.c snmp_logging.c text_utils.c \ 52- snmpv3.c lcd_time.c keytools.c file_utils.c \ 53+ snmpv3.c lcd_time.c keytools.c file_utils.c dir_utils.c \ 54 scapi.c callback.c default_store.c snmp_alarm.c \ 55 data_list.c oid_stash.c fd_event_manager.c \ 56 mt_support.c snmp_enum.c snmp-tc.c snmp_service.c \ 57@@ -152,7 +153,7 @@ OBJS= snmp_client.o mib.o parse.o snmp_a 58 snmp_auth.o asn1.o md5.o snmp_parse_args.o \ 59 system.o vacm.o int64.o read_config.o pkcs.o \ 60 snmp_debug.o tools.o snmp_logging.o text_utils.o \ 61- snmpv3.o lcd_time.o keytools.o file_utils.o \ 62+ snmpv3.o lcd_time.o keytools.o file_utils.o dir_utils.o \ 63 scapi.o callback.o default_store.o snmp_alarm.o \ 64 data_list.o oid_stash.o fd_event_manager.o \ 65 mt_support.o snmp_enum.o snmp-tc.o snmp_service.o \ 66@@ -167,7 +168,7 @@ LOBJS= snmp_client.lo mib.lo parse.lo sn 67 snmp_auth.lo asn1.lo md5.lo snmp_parse_args.lo \ 68 system.lo vacm.lo int64.lo read_config.lo pkcs.lo \ 69 snmp_debug.lo tools.lo snmp_logging.lo text_utils.lo \ 70- snmpv3.lo lcd_time.lo keytools.lo file_utils.lo \ 71+ snmpv3.lo lcd_time.lo keytools.lo file_utils.lo dir_utils.lo \ 72 scapi.lo callback.lo default_store.lo snmp_alarm.lo \ 73 data_list.lo oid_stash.lo fd_event_manager.lo \ 74 mt_support.lo snmp_enum.lo snmp-tc.lo snmp_service.lo \ 75diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/snmplib/dir_utils.c APPLE/snmplib/dir_utils.c 76--- SVN/snmplib/dir_utils.c 77+++ APPLE/snmplib/dir_utils.c 78@@ -0,0 +1,125 @@ 79+#include <net-snmp/net-snmp-config.h> 80+#include <net-snmp/net-snmp-includes.h> 81+ 82+#include <stdio.h> 83+#include <ctype.h> 84+#if HAVE_STDLIB_H 85+# include <stdlib.h> 86+#endif 87+#if HAVE_UNISTD_H 88+# include <unistd.h> 89+#endif 90+#if HAVE_STRING_H 91+# include <string.h> 92+#else 93+# include <strings.h> 94+#endif 95+ 96+#include <sys/types.h> 97+#if HAVE_LIMITS_H 98+#include <limits.h> 99+#endif 100+#if HAVE_SYS_STAT_H 101+#include <sys/stat.h> 102+#endif 103+#ifdef HAVE_DIRENT_H 104+#include <dirent.h> 105+#endif 106+ 107+#include <errno.h> 108+ 109+#if HAVE_DMALLOC_H 110+# include <dmalloc.h> 111+#endif 112+ 113+#include <net-snmp/types.h> 114+#include <net-snmp/library/container.h> 115+#include <net-snmp/library/dir_utils.h> 116+ 117+netsnmp_container * 118+netsnmp_directory_container_read(netsnmp_container *user_container, 119+ const char *dirname, u_int flags) 120+{ 121+ DIR *dir; 122+ netsnmp_container *container = user_container, *tmp_c; 123+ struct dirent *file; 124+ char path[PATH_MAX]; 125+ u_char dirname_len; 126+ int rc; 127+ 128+ DEBUGMSGTL(("directory:container", "reading %s\n", dirname)); 129+ 130+ /* 131+ * create the container, if needed 132+ */ 133+ if (NULL == container) { 134+ container = netsnmp_container_find("directory_container:cstring"); 135+ if (NULL == container) 136+ return NULL; 137+ container->container_name = strdup("directory container"); 138+ netsnmp_binary_array_options_set(container, 1, CONTAINER_KEY_UNSORTED); 139+ } 140+ 141+ dir = opendir(dirname); 142+ if (NULL == dir) { 143+ DEBUGMSGTL(("directory:container", " not a dir\n")); 144+ return NULL; 145+ } 146+ 147+ /** copy dirname into path */ 148+ dirname_len = strlen(dirname); 149+ strncpy(path, dirname, sizeof(path)); 150+ if ((dirname_len + 2) > sizeof(path)) { 151+ /** not enough room for files */ 152+ closedir(dir); 153+ return NULL; 154+ } 155+ path[dirname_len] = '/'; 156+ path[++dirname_len] = 0; 157+ 158+ /** iterate over dir */ 159+ while ((file = readdir(dir))) { 160+ 161+ if ((file->d_name == NULL) || (file->d_name[0] == 0)) 162+ continue; 163+ 164+ /** skip '.' and '..' */ 165+ if ((file->d_name[0] == '.') && 166+ ((file->d_name[1] == 0) || 167+ ((file->d_name[1] == '.') && ((file->d_name[2] == 0))))) 168+ continue; 169+ 170+ strncpy(&path[dirname_len], file->d_name, sizeof(path) - dirname_len); 171+ DEBUGMSGTL(("9:directory:container", " found %s\n", path)); 172+ if ((file->d_type == DT_DIR) && (flags & NETSNMP_DIR_RECURSE)) { 173+ /** xxx add the dir as well? not for now.. maybe another flag? */ 174+ tmp_c = netsnmp_directory_container_read(container, path, flags); 175+ } 176+ else { 177+ char *dup = strdup(path); 178+ if (NULL == dup) { 179+ snmp_log(LOG_ERR, "strdup failed\n"); 180+ break; 181+ } 182+ rc = CONTAINER_INSERT(container, dup); 183+ if (-1 == rc ) { 184+ DEBUGMSGTL(("directory:container", " err adding %s\n", path)); 185+ free(dup); 186+ } 187+ } 188+ } 189+ 190+ closedir(dir); 191+ 192+ DEBUGMSGTL(("directory:container", " container now has %d items\n", 193+ CONTAINER_SIZE(container))); 194+ 195+ return container; 196+} 197+ 198+void 199+netsnmp_directory_container_free(netsnmp_container *container) 200+{ 201+ CONTAINER_CLEAR(container, netsnmp_container_simple_free, NULL); 202+ CONTAINER_FREE(container); 203+} 204