[Xorp-cvs] SF.net SVN: xorp:[11532] trunk/xorp/rtrmgr/master_conf_tree.cc
bms_fbsd at users.sourceforge.net
bms_fbsd at users.sourceforge.net
Wed Sep 2 09:49:23 PDT 2009
Revision: 11532
http://xorp.svn.sourceforge.net/xorp/?rev=11532&view=rev
Author: bms_fbsd
Date: 2009-09-02 16:49:23 +0000 (Wed, 02 Sep 2009)
Log Message:
-----------
Add useful metadata to the XORP configuration file header.
Preserve backwards compatibility only for overwriting pre-1.7 config files.
Bugzilla URL: http://bugzilla.xorp.net/show_bug.cgi?id=53
Submitted by: Kristian Larsson (with fixups)
Modified Paths:
--------------
trunk/xorp/rtrmgr/master_conf_tree.cc
Modified: trunk/xorp/rtrmgr/master_conf_tree.cc
===================================================================
--- trunk/xorp/rtrmgr/master_conf_tree.cc 2009-09-02 15:17:22 UTC (rev 11531)
+++ trunk/xorp/rtrmgr/master_conf_tree.cc 2009-09-02 16:49:23 UTC (rev 11532)
@@ -29,6 +29,9 @@
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -65,6 +68,9 @@
#endif
+#define XORP_CONFIG_FORMAT_VERSION "1.1"
+#define XORP_CONFIG_XORP_VERSION "1.7-WIP"
+
//
// The strings that are used to add and delete a load or save file, to
// access the content of the loaded file, etc.
@@ -837,7 +843,10 @@
umask(orig_mask);
return false;
}
- if (strncmp(line, "/*XORP", 6) != 0) {
+ // Check for pre-1.7 config file header first.
+ if ((strncmp(&line[0], "/*", 2) != 0) &&
+ ((strncmp(&line[2], "XORP", 4) != 0) ||
+ (strncmp(&line[2], " XORP", 5) != 0))) {
error_msg = c_format("File %s exists, but it is not an "
"existing XORP config file.\n",
full_filename.c_str());
@@ -875,8 +884,43 @@
return false;
}
+ // Prepare values for the file header
+#ifdef HOST_OS_WINDOWS
+ string username("root");
+#else
+ struct passwd *pwent = getpwuid(user_id);
+ string username;
+ if (pwent == NULL)
+ username = c_format("UID:%u", XORP_UINT_CAST(user_id));
+ else
+ username = pwent->pw_name;
+#endif
+
+ char hbuf[MAXHOSTNAMELEN];
+ if (gethostname(hbuf, sizeof(hbuf)) < 0) {
+#ifdef HOST_OS_WINDOWS
+ XLOG_FATAL("gethostname() failed: %d", WSAGetLastError());
+#else
+ XLOG_FATAL("gethostname() failed: %s", strerror(errno));
+#endif
+ }
+ hbuf[sizeof(hbuf) - 1] = '\0';
+
// Write the file header
- string header = "/*XORP Configuration File, v1.0*/\n";
+ string header = "/* XORP configuration file";
+ header += "\n *";
+ header += "\n * Configuration format: ";
+ header += XORP_CONFIG_FORMAT_VERSION;
+ header += "\n * XORP version: ";
+ header += XORP_CONFIG_XORP_VERSION;
+ header += "\n * Date: ";
+ header += xlog_localtime2string();
+ header += "\n * Host: ";
+ header += hbuf;
+ header += "\n * User: ";
+ header += username;
+ header += "\n */\n\n";
+
size_t bytes;
bytes = fwrite(header.c_str(), sizeof(char), header.size(), file);
if (bytes < header.size()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Xorp-cvs
mailing list