Attached is a patch that does the following:
-Fixes snmp.conf persistentDir by changing it to premib. With this change, any createUser tokens are read at startup and the persistent file will be updated with a usmUser at shutdown.
-Config file defined by SNMP_PERSISTENT_FILE is now read. From what I could tell, the file defined by SNMP_PERSISTENT_FILE was written to at shutdown, but it was never READ at startup. This prevented the createUser token from working.
-Config file defined by SNMP_PERSISTENT_FILE is now backed up and purged before writing so it doesn't continiously grow. Previously, the file would keep getting bigger and bigger. Actually, it wasn't even being backed up at all as the backup code didn't check for SNMP_PERSISTENT_FILE. Note: It does not currently load the backed up config files when SNMP_PERSISTENT_FILE is used. I'm out of time, so I'll look at it on Monday.
-Update DIRECTORIES SEARCHED section of snmp_config (5). It now details how the peristent data is loaded and saved, and adds a 'see also' for snmp_config. BTW, I updated the date of the man page.
-Update -c description in snmpd (8). Added a note about how to specify snmp.conf options etc when using -c.
Please let me know if this is the correct behaviour, especially SNMP_PERSISTENT_FILE as it seemed rather broken. If it is correct, then I will also have to update the Windows installer, documentation etc. I would expect to port this to previous versions, but without mentioning SNMP_PERSISTENT_DIR as it is new to main.
Thanks
Alex
Index: man/snmp_config.5.def =================================================================== RCS file: /cvsroot/net-snmp/net-snmp/man/snmp_config.5.def,v retrieving revision 5.3 diff -u -r5.3 snmp_config.5.def --- man/snmp_config.5.def 9 Dec 2004 16:58:03 -0000 5.3 +++ man/snmp_config.5.def 6 May 2005 03:00:46 -0000 @@ -1,4 +1,4 @@ -.TH SNMP.CONF 5 "28 Aug 2001" VVERSIONINFO "Net-SNMP" +.TH SNMP.CONF 5 "5 May 2005" VVERSIONINFO "Net-SNMP" .UC 4 .SH NAME snmp_config - handling of Net-SNMP configuration files @@ -20,10 +20,61 @@ .PP Additionally, the above default search path can be overridden by setting the environment variable SNMPCONFPATH to a colon-separated -list of directories to search for. +list of directories to search for. The path for the persistent +data should be included when running applications that use +persistent storage, such as snmpd. .PP -Finally, applications that store persistent data will also look in the -PERSISTENT_DIRECTORY directory for configuration files there. +Applications will read persistent configuration files +in the following order of preference: +.RS +.PP +file in +.B SNMP_PERSISTENT_FILE +environment variable +.PP +directories in +.B SNMPCONFPATH +environment variable +.PP +directory defined by +.B +persistentDir +snmp.conf variable +.PP +directory in +.B +SNMP_PERSISTENT_DIR +environment variable +.PP +default +.B +PERSISTENT_DIRECTORY +directory +.RE +.PP +Finally, applications will write persistent configuration files +in the following order of preference: +.RS +.PP +file in +.B SNMP_PERSISTENT_FILE +environment variable +.PP +directory defined by +.B +persistentDir +snmp.conf variable +.PP +directory in +.B +SNMP_PERSISTENT_DIR +environment variable +.PP +default +.B +PERSISTENT_DIRECTORY +directory +.RE .SH "CONFIGURATION FILE TYPES" Each application may use multiple configuration files, which will configure various different aspects of the application. For instance, Index: man/snmpd.8.def =================================================================== RCS file: /cvsroot/net-snmp/net-snmp/man/snmpd.8.def,v retrieving revision 5.4 diff -u -r5.4 snmpd.8.def --- man/snmpd.8.def 10 Mar 2004 15:08:25 -0000 5.4 +++ man/snmpd.8.def 6 May 2005 03:00:46 -0000 @@ -1,4 +1,4 @@ -.TH SNMPD 8 "7 Feb 2002" VVERSIONINFO "Net-SNMP" +.TH SNMPD 8 "5 May 2005" VVERSIONINFO "Net-SNMP" .UC 4 .SH NAME snmpd - daemon to respond to SNMP request packets. @@ -23,7 +23,10 @@ Read .I FILE as a configuration file -(or a comma-separated list of configuration files). +(or a comma-separated list of configuration files). Note that the loaded +file will only understand snmpd.conf tokens, unless the configuration type +is specified in the file as described in the snmp_config man page under +SWITCHING CONFIGURATION TYPES IN MID-FILE. .TP .B -C Do not read any configuration files except the ones optionally specified by the @@ -274,6 +277,7 @@ .SH SEE ALSO (in recommended reading order) .PP +snmp_config(5), snmp.conf(5), snmpd.conf(5) .\" Local Variables: Index: snmplib/read_config.c =================================================================== RCS file: /cvsroot/net-snmp/net-snmp/snmplib/read_config.c,v retrieving revision 5.31 diff -u -r5.31 read_config.c --- snmplib/read_config.c 25 Mar 2005 03:06:25 -0000 5.31 +++ snmplib/read_config.c 6 May 2005 03:00:47 -0000 @@ -1085,10 +1085,12 @@ * then we read all the configuration files we can, starting with * the oldest first. */ - persfile = netsnmp_getenv("SNMP_PERSISTENT_FILE"); + if (persfile = netsnmp_getenv("SNMP_PERSISTENT_FILE")) { + read_config(persfile, ltmp, when); + } + if (strncmp(cptr2, perspath, strlen(perspath)) == 0 || - (persfile != NULL && - strncmp(cptr2, persfile, strlen(persfile)) == 0)) { + (persfile != NULL && strncmp(cptr2, persfile, strlen(persfile)) == 0)) { /* * limit this to the known storage directory only */ @@ -1168,10 +1170,13 @@ } /** - * read_config_store intended for use by applications to store permenant + * read_config_store intended for use by applications to store permanent * configuration information generated by sets or persistent counters. - * Appends line to a file named either ENV(SNMP_PERSISTENT_FILE) or - * "<PERSISTENT_DIRECTORY>/<type>.conf". + * Appends line to a file named either: + * 1. ENV variable SNMP_PERSISTENT_FILE + * 2. configured "ENV(SNMP_PERSISTENT_DIR)/<type>.conf" + * 3. configured (persistentDir snmp.conf variable)/<type>.conf + * 4. configured <PERSISTENT_DIRECTORY>/<type>.conf * Adds a trailing newline to the stored file if necessary. * * @param type is the application name @@ -1196,7 +1201,9 @@ /* * store configuration directives in the following order of preference: * 1. ENV variable SNMP_PERSISTENT_FILE - * 2. configured <PERSISTENT_DIRECTORY>/<type>.conf + * 2. configured "ENV(SNMP_PERSISTENT_DIR)/<type>.conf" + * 3. configured (persistentDir snmp.conf variable)/<type>.conf + * 4. configured <PERSISTENT_DIRECTORY>/<type>.conf */ if ((filep = netsnmp_getenv("SNMP_PERSISTENT_FILE")) == NULL) { snprintf(file, sizeof(file), @@ -1260,7 +1267,7 @@ void snmp_save_persistent(const char *type) { - char file[512], fileold[SPRINT_MAX_LEN]; + char file[512], *filep, fileold[SPRINT_MAX_LEN]; struct stat statbuf; int j; @@ -1268,12 +1275,23 @@ NETSNMP_DS_LIB_DONT_PERSIST_STATE)) return; DEBUGMSGTL(("snmp_save_persistent", "saving %s files...\n", type)); - snprintf(file, sizeof(file), - "%s/%s.conf", get_persistent_directory(), type); - file[ sizeof(file)-1 ] = 0; + + if ((filep = netsnmp_getenv("SNMP_PERSISTENT_FILE"))) { + snprintf(file, sizeof(file), "%s", filep); + file[ sizeof(file)-1 ] = 0; + } + else { + snprintf(file, sizeof(file), + "%s/%s.conf", get_persistent_directory(), type); + file[ sizeof(file)-1 ] = 0; + } + if (stat(file, &statbuf) == 0) { for (j = 0; j <= MAX_PERSISTENT_BACKUPS; j++) { - snprintf(fileold, sizeof(fileold), + if (filep) /* SNMP_PERSISTENT_FILE defined */ + snprintf(fileold, sizeof(fileold), "%s.%d", file, j); + else + snprintf(fileold, sizeof(fileold), "%s/%s.%d.conf", get_persistent_directory(), type, j); fileold[ sizeof(fileold)-1 ] = 0; if (stat(fileold, &statbuf) != 0) { @@ -1322,7 +1340,7 @@ void snmp_clean_persistent(const char *type) { - char file[512]; + char file[512], filetemp[512], *filep; struct stat statbuf; int j; @@ -1330,20 +1348,39 @@ NETSNMP_DS_LIB_DONT_PERSIST_STATE)) return; DEBUGMSGTL(("snmp_clean_persistent", "cleaning %s files...\n", type)); - snprintf(file, sizeof(file), - "%s/%s.conf", get_persistent_directory(), type); - file[ sizeof(file)-1 ] = 0; - if (stat(file, &statbuf) == 0) { - for (j = 0; j <= MAX_PERSISTENT_BACKUPS; j++) { + + if ((filep = netsnmp_getenv("SNMP_PERSISTENT_FILE"))) { + snprintf(file, sizeof(file), "%s", filep); + file[ sizeof(file)-1 ] = 0; + if (stat(file, &statbuf) == 0) { + for (j = 0; j <= MAX_PERSISTENT_BACKUPS; j++) { + snprintf(filetemp, sizeof(filetemp), "%s.%d", file, j); + filetemp[ sizeof(filetemp)-1 ] = 0; + if (stat(filetemp, &statbuf) == 0) { + DEBUGMSGTL(("snmp_clean_persistent", + " removing old config file: %s\n", filetemp)); + if (unlink(filetemp) == -1) + snmp_log(LOG_ERR, "Cannot unlink %s\n", filetemp); + } + } + } + } + else { + snprintf(file, sizeof(file), + "%s/%s.conf", get_persistent_directory(), type); + file[ sizeof(file)-1 ] = 0; + if (stat(file, &statbuf) == 0) { + for (j = 0; j <= MAX_PERSISTENT_BACKUPS; j++) { snprintf(file, sizeof(file), - "%s/%s.%d.conf", get_persistent_directory(), type, j); + "%s/%s.%d.conf", get_persistent_directory(), type, j); file[ sizeof(file)-1 ] = 0; if (stat(file, &statbuf) == 0) { - DEBUGMSGTL(("snmp_clean_persistent", - " removing old config file: %s\n", file)); - if (unlink(file) == -1) - snmp_log(LOG_ERR, "Cannot unlink %s\n", file); + DEBUGMSGTL(("snmp_clean_persistent", + " removing old config file: %s\n", file)); + if (unlink(file) == -1) + snmp_log(LOG_ERR, "Cannot unlink %s\n", file); } + } } } } Index: snmplib/snmp_api.c =================================================================== RCS file: /cvsroot/net-snmp/net-snmp/snmplib/snmp_api.c,v retrieving revision 5.72 diff -u -r5.72 snmp_api.c --- snmplib/snmp_api.c 29 Mar 2005 20:05:17 -0000 5.72 +++ snmplib/snmp_api.c 6 May 2005 03:00:47 -0000 @@ -724,7 +724,7 @@ NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NO_TOKEN_WARNINGS); netsnmp_ds_register_config(ASN_BOOLEAN, "snmp", "noRangeCheck", NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_CHECK_RANGE); - netsnmp_ds_register_config(ASN_OCTET_STR, "snmp", "persistentDir", + netsnmp_ds_register_premib(ASN_OCTET_STR, "snmp", "persistentDir", NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PERSISTENT_DIR); netsnmp_ds_register_config(ASN_OCTET_STR, "snmp", "tempFilePattern", NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_TEMP_FILE_PATTERN);