From a290d7b823969913163af6afe07232456ea3dadb Mon Sep 17 00:00:00 2001
From: Ralf Jung <post@ralfj.de>
Date: Fri, 9 Aug 2013 19:49:14 +0200
Subject: [PATCH] set config file statically; parse it

---
 CMakeLists.txt   |  4 ++++
 dyn-nsupdate.cpp | 35 +++++++----------------------------
 2 files changed, 11 insertions(+), 28 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3865aad..5879f85 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,8 +4,12 @@ project(Dyn-NSupdate)
 FIND_PACKAGE( Boost 1.40 REQUIRED )
 INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
 
+set(DYNNSUPDATE_CONFIG_FILE "/some/config/file" CACHE FILEPATH "Choose the file dyn-nsupdate reads its configuration from (for security reasons, this is hard-coded in the binary)")
+
 set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}")
 
+add_definitions("-DCONFIG_FILE=\"${DYNNSUPDATE_CONFIG_FILE}\"")
+
 ADD_EXECUTABLE( dyn-nsupdate dyn-nsupdate.cpp )
 
 TARGET_LINK_LIBRARIES( dyn-nsupdate ${Boost_LIBRARIES} )
diff --git a/dyn-nsupdate.cpp b/dyn-nsupdate.cpp
index e378082..745595d 100644
--- a/dyn-nsupdate.cpp
+++ b/dyn-nsupdate.cpp
@@ -1,37 +1,16 @@
 #include <iostream>
+#include <fstream>
+
 #include <boost/property_tree/ptree.hpp>
 #include <boost/property_tree/ini_parser.hpp>
 
-#include <sys/stat.h>
+using namespace boost::property_tree;
 
-int main(int argc, const char **argv)
+int main(int, const char **)
 {
-	if (argc < 2) {
-		std::cerr << "Usage: " << argv[0] << " <configuration file>" << std::endl;
-		return 1;
-	}
-	const char *filename = argv[1];
-	
-	struct stat file_stat;
-	int ret = lstat(filename, &file_stat);
-	if (ret != 0) {
-		std::cerr << "Unable to stat " << filename << "." << std::endl;
-		return 1;
-	}
-	/* Check if the file is suited */
-	if (!S_ISREG(file_stat.st_mode)) {
-		std::cerr << filename << " is not a file." << std::endl;
-		return 1;
-	}
-	if (file_stat.st_uid != geteuid()) {
-		std::cerr << filename << " must be owned by user executing " << argv[0] << "." << std::endl;
-		return 1;
-	}
-	if (file_stat.st_mode & (S_IWGRP | S_IWOTH)) { /* can be written by group/others */
-		std::cerr << filename << " must not be writeable by group or others." << std::endl;
-		return 1;
-	}
+	ptree config;
+	ini_parser::read_ini(CONFIG_FILE, config);
 	
-	std::cout << "Hi world!" << std::endl;
+	std::cout << "Hi world! " << CONFIG_FILE << std::endl;
 	return 0;
 }
-- 
2.39.5