diff options
author | Christian Pointner <equinox@anytun.org> | 2008-04-11 15:26:41 +0000 |
---|---|---|
committer | Christian Pointner <equinox@anytun.org> | 2008-04-11 15:26:41 +0000 |
commit | 2dcab0372d9b7604aee8e0034599a5a2cbb66613 (patch) | |
tree | e38740d6c6f01d97f9b225c783c2cbfe648166cb /options.cpp | |
parent | added basic config files (diff) |
added chroot and drop privileges
added write-pid option
Diffstat (limited to 'options.cpp')
-rw-r--r-- | options.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/options.cpp b/options.cpp index 53589cb..86fd50a 100644 --- a/options.cpp +++ b/options.cpp @@ -54,6 +54,10 @@ Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0)) { progname_ = "anytun"; daemonize_ = true; + chroot_ = false; + username_ = "nobody"; + chroot_dir_ = "/var/run/anytun"; + pid_file_ = ""; sender_id_ = 0; local_addr_ = ""; local_port_ = 4444; @@ -152,6 +156,10 @@ bool Options::parse(int argc, char* argv[]) if(str == "-h" || str == "--help") return false; PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", daemonize_) + PARSE_BOOL_PARAM("-C","--chroot", chroot_) + PARSE_SCALAR_PARAM("-u","--username", username_) + PARSE_SCALAR_PARAM("-H","--chroot-dir", chroot_dir_) + PARSE_SCALAR_PARAM("-P","--write-pid", pid_file_) PARSE_SCALAR_PARAM("-s","--sender-id", sender_id_) PARSE_SCALAR_PARAM("-i","--interface", local_addr_) PARSE_SCALAR_PARAM("-p","--port", local_port_) @@ -201,6 +209,10 @@ void Options::printUsage() std::cout << "anytun [-h|--help] prints this..." << std::endl; // std::cout << " [-f|--config] <file> the config file" << std::endl; std::cout << " [-D|--nodaemonize] don't run in background" << std::endl; + std::cout << " [-C|--chroot] chroot and drop privileges" << std::endl; + std::cout << " [-u|--username] if chroot change to this user" << std::endl; + std::cout << " [-H|--chroot-dir] chroot to this directory" << std::endl; + std::cout << " [-P|--write-pid] write pid to this file" << std::endl; std::cout << " [-s|--sender-id ] <sender id> the sender id to use" << std::endl; std::cout << " [-i|--interface] <ip-address> local anycast ip address to bind to" << std::endl; std::cout << " [-p|--port] <port> local anycast(data) port to bind to" << std::endl; @@ -228,6 +240,10 @@ void Options::printOptions() Lock lock(mutex); std::cout << "Options:" << std::endl; std::cout << "daemonize=" << daemonize_ << std::endl; + std::cout << "chroot=" << chroot_ << std::endl; + std::cout << "username='" << username_ << "'" << std::endl; + std::cout << "chroot_dir='" << chroot_dir_ << "'" << std::endl; + std::cout << "pid_file='" << pid_file_ << "'" << std::endl; std::cout << "sender_id='" << sender_id_ << "'" << std::endl; std::cout << "local_addr='" << local_addr_ << "'" << std::endl; std::cout << "local_port='" << local_port_ << "'" << std::endl; @@ -273,6 +289,56 @@ Options& Options::setDaemonize(bool d) return *this; } +bool Options::getChroot() +{ + return chroot_; +} + +Options& Options::setChroot(bool c) +{ + chroot_ = c; + return *this; +} + +std::string Options::getUsername() +{ + Lock lock(mutex); + return username_; +} + +Options& Options::setUsername(std::string u) +{ + Lock lock(mutex); + username_ = u; + return *this; +} + +std::string Options::getChrootDir() +{ + Lock lock(mutex); + return chroot_dir_; +} + +Options& Options::setChrootDir(std::string c) +{ + Lock lock(mutex); + chroot_dir_ = c; + return *this; +} + +std::string Options::getPidFile() +{ + Lock lock(mutex); + return pid_file_; +} + +Options& Options::setPidFile(std::string p) +{ + Lock lock(mutex); + pid_file_ = p; + return *this; +} + ConnectToList Options::getConnectTo() { Lock lock(mutex); |