summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anytun.cpp30
-rw-r--r--src/options.cpp50
-rw-r--r--src/options.h7
3 files changed, 68 insertions, 19 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index b6f370b..fa1d186 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -362,33 +362,39 @@ int main(int argc, char* argv[])
{
try
{
+ bool result = gOpt.parse(argc, argv);
+ if(!result) {
+ gOpt.printUsage();
+ exit(0);
+ }
+ StringList targets = gOpt.getLogTargets();
+ if(targets.empty()) {
#ifndef _MSC_VER
- cLog.addTarget("syslog:7,anytun,daemon");
+ cLog.addTarget("syslog:5,anytun,daemon");
#else
#ifdef WIN_SERVICE
- cLog.addTarget("eventlog:7,anytun");
+ cLog.addTarget("eventlog:5,anytun");
#else
- cLog.addTarget("stdout:7");
+ cLog.addTarget("stdout:5");
#endif
#endif
- cLog.msg(Log::PRIO_NOTICE) << "anytun started...";
-/// std::cout << "anytun - secure anycast tunneling protocol" << std::endl;
-
- bool result = gOpt.parse(argc, argv);
- if(!result) {
- cLog.msg(Log::PRIO_NOTICE) << "printing help text and exitting";
- gOpt.printUsage();
- exit(0);
+ }
+ else {
+ StringList::const_iterator it;
+ for(it = targets.begin();it != targets.end(); ++it)
+ cLog.addTarget(*it);
}
}
catch(syntax_error& e)
{
std::cerr << e << std::endl;
- cLog.msg(Log::PRIO_ERR) << "exitting after syntax error";
gOpt.printUsage();
exit(-1);
}
+ cLog.msg(Log::PRIO_NOTICE) << "anytun started...";
+ gOpt.parse_post(); // print warnings
+
#ifndef NO_DAEMON
#ifndef NO_PRIVDROP
PrivInfo privs(gOpt.getUsername(), gOpt.getGroupname());
diff --git a/src/options.cpp b/src/options.cpp
index f7bacf4..ca55856 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -294,7 +294,6 @@ Options::~Options()
u_int32_t pos = str.length() + 1; \
throw syntax_error(str.append(" ").append(argv[i+1]), pos); \
} \
- std::stringstream tmp; \
VALUE = argv[i+1]; \
for(size_t j=0; j < strlen(argv[i+1]); ++j) \
argv[i+1][j] = '#'; \
@@ -302,6 +301,20 @@ Options::~Options()
i++; \
}
+#define PARSE_STRING_LIST(SHORT, LONG, LIST) \
+ else if(str == SHORT || str == LONG) \
+ { \
+ if(argc < 1) \
+ throw syntax_error(str, str.length()); \
+ if(argv[i+1][0] == '-') { \
+ u_int32_t pos = str.length() + 1; \
+ throw syntax_error(str.append(" ").append(argv[i+1]), pos); \
+ } \
+ LIST.push_back(argv[i+1]); \
+ argc--; \
+ i++; \
+ }
+
bool Options::parse(int argc, char* argv[])
{
WritersLock lock(mutex);
@@ -328,6 +341,9 @@ bool Options::parse(int argc, char* argv[])
#endif
#endif
+
+ PARSE_STRING_LIST("-L","--log", log_targets_)
+
#if defined(ANYCTR_OPTIONS)
PARSE_SCALAR_PARAM("-f","--file", file_name_)
@@ -396,15 +412,18 @@ bool Options::parse(int argc, char* argv[])
}
ld_kdr_ = static_cast<int8_t>(ld_kdr_tmp);
+ return true;
+}
+
+void Options::parse_post()
+{
if(cipher_ == "null" && auth_algo_ == "null")
kd_prf_ = "null";
if((cipher_ != "null" || auth_algo_ != "null") && kd_prf_ == "null")
cLog.msg(Log::PRIO_WARNING) << "using NULL key derivation with encryption and or authentication enabled!";
-
+
if(dev_name_ == "" && dev_type_ == "")
dev_type_ = "tun";
-
- return true;
}
void Options::printUsage()
@@ -432,6 +451,10 @@ void Options::printUsage()
#endif
#endif
+
+ std::cout << " [-L|--log] <target>:<level>[,<param1>[,<param2>..]]" << std::endl;
+ std::cout << " add a log target" << std::endl;
+
#if defined(ANYCTR_OPTIONS)
std::cout << " [-f|--file] <path> path to input file" << std::endl;
@@ -512,6 +535,11 @@ void Options::printOptions()
std::cout << "chroot_dir = '" << chroot_dir_ << "'" << std::endl;
std::cout << "pid_file = '" << pid_file_ << "'" << std::endl;
std::cout << std::endl;
+ std::cout << "log_targets:";
+ StringList::const_iterator lit = log_targets_.begin();
+ for(; lit != log_targets_.end(); ++lit)
+ std::cout << " '" << *lit << "',";
+ std::cout << std::endl << std::endl;
std::cout << "file_name = '" << file_name_ << "'" << std::endl;
std::cout << "bind_to.addr = '" << bind_to_.addr << "'" << std::endl;
std::cout << "bind_to.port = '" << bind_to_.port << "'" << std::endl;
@@ -523,9 +551,9 @@ void Options::printOptions()
std::cout << "local_sync.addr = '" << local_sync_.addr << "'" << std::endl;
std::cout << "local_sync.port = '" << local_sync_.port << "'" << std::endl;
std::cout << "remote_sync_hosts:" << std::endl;
- HostList::const_iterator it = remote_sync_hosts_.begin();
- for(; it != remote_sync_hosts_.end(); ++it)
- std::cout << " '" << it->addr << "','" << it->port << "'" << std::endl;
+ HostList::const_iterator hit = remote_sync_hosts_.begin();
+ for(; hit != remote_sync_hosts_.end(); ++hit)
+ std::cout << " '" << hit->addr << "','" << hit->port << "'" << std::endl;
std::cout << std::endl;
std::cout << "dev_name = '" << dev_name_ << "'" << std::endl;
std::cout << "dev_type = '" << dev_type_ << "'" << std::endl;
@@ -632,6 +660,14 @@ Options& Options::setPidFile(std::string p)
+StringList Options::getLogTargets()
+{
+ ReadersLock lock(mutex);
+ return log_targets_;
+}
+
+
+
std::string Options::getFileName()
{
ReadersLock lock(mutex);
diff --git a/src/options.h b/src/options.h
index 17da8a4..3e1b5ce 100644
--- a/src/options.h
+++ b/src/options.h
@@ -75,12 +75,15 @@ public:
typedef std::list<OptionNetwork> NetworkList;
std::istream& operator>>(std::istream& stream, OptionNetwork& network);
+typedef std::list<std::string> StringList;
+
class Options
{
public:
static Options& instance();
bool parse(int argc, char* argv[]);
+ void parse_post();
void printUsage();
void printOptions();
@@ -97,6 +100,8 @@ public:
std::string getPidFile();
Options& setPidFile(std::string p);
+ StringList getLogTargets();
+
std::string getFileName();
Options& setFileName(std::string f);
std::string getBindToAddr();
@@ -179,6 +184,8 @@ private:
std::string chroot_dir_;
std::string pid_file_;
+ StringList log_targets_;
+
std::string file_name_;
OptionHost bind_to_;