From 88af7a47fc7194a1bd4c699f1da55e86f4576dec Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 9 Aug 2013 19:30:55 +0200 Subject: [PATCH] Initial commit: Mode checks for config file --- .gitignore | 1 + CMakeLists.txt | 11 +++++++++++ dyn-nsupdate.cpp | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 dyn-nsupdate.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3865aad --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.6) +project(Dyn-NSupdate) + +FIND_PACKAGE( Boost 1.40 REQUIRED ) +INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} ) + +set(CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}") + +ADD_EXECUTABLE( dyn-nsupdate dyn-nsupdate.cpp ) + +TARGET_LINK_LIBRARIES( dyn-nsupdate ${Boost_LIBRARIES} ) diff --git a/dyn-nsupdate.cpp b/dyn-nsupdate.cpp new file mode 100644 index 0000000..e378082 --- /dev/null +++ b/dyn-nsupdate.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +#include + +int main(int argc, const char **argv) +{ + if (argc < 2) { + std::cerr << "Usage: " << argv[0] << " " << 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; + } + + std::cout << "Hi world!" << std::endl; + return 0; +} -- 2.30.2