summaryrefslogtreecommitdiff
path: root/service/OneService.cpp
diff options
context:
space:
mode:
authorMichał Zieliński <michal@zielinscy.org.pl>2017-01-22 23:02:34 +0100
committerMichał Zieliński <michal@zielinscy.org.pl>2017-01-23 12:16:40 +0100
commit8f2a42d1ad84e5dba590e7f593d8a46cc81389b3 (patch)
treee61e1ff9fb430eb1d9eadf16ed5daacfa9551071 /service/OneService.cpp
parent9a475eeff90a181af0661b87b09af7337e39167a (diff)
downloadinfinitytier-8f2a42d1ad84e5dba590e7f593d8a46cc81389b3.tar.gz
infinitytier-8f2a42d1ad84e5dba590e7f593d8a46cc81389b3.zip
allow user to specify arbitrary allowed IP networks in allowManaged
Diffstat (limited to 'service/OneService.cpp')
-rw-r--r--service/OneService.cpp41
1 files changed, 38 insertions, 3 deletions
diff --git a/service/OneService.cpp b/service/OneService.cpp
index 93f5b5f0..603234a2 100644
--- a/service/OneService.cpp
+++ b/service/OneService.cpp
@@ -1039,6 +1039,18 @@ public:
{
if (!n.settings.allowManaged)
return false;
+
+ if (n.settings.allowManagedWhitelist.size() > 0) {
+ bool allowed = false;
+ for (InetAddress addr : n.settings.allowManagedWhitelist) {
+ if (addr.containsAddress(target) && addr.netmaskBits() <= target.netmaskBits()) {
+ allowed = true;
+ break;
+ }
+ }
+ if (!allowed) return false;
+ }
+
if (target.isDefaultRoute())
return n.settings.allowDefault;
switch(target.ipScope()) {
@@ -1423,9 +1435,32 @@ public:
if (OSUtils::readFile(nlcpath,nlcbuf)) {
Dictionary<4096> nc;
nc.load(nlcbuf.c_str());
- n.settings.allowManaged = nc.getB("allowManaged",true);
- n.settings.allowGlobal = nc.getB("allowGlobal",false);
- n.settings.allowDefault = nc.getB("allowDefault",false);
+ Buffer<1024> allowManaged;
+ if (nc.get("allowManaged", allowManaged) && allowManaged.size() != 0) {
+ std::string addresses (allowManaged.begin(), allowManaged.size());
+ if (allowManaged.size() <= 5) { // untidy parsing for backward compatibility
+ if (allowManaged[0] == '1' || allowManaged[0] == 't' || allowManaged[0] == 'T') {
+ n.settings.allowManaged = true;
+ } else {
+ n.settings.allowManaged = false;
+ }
+ } else {
+ // this should be a list of IP addresses
+ n.settings.allowManaged = true;
+ size_t pos = 0;
+ while (true) {
+ size_t nextPos = addresses.find(',', pos);
+ std::string address = addresses.substr(pos, (nextPos == std::string::npos ? addresses.size() : nextPos) - pos);
+ n.settings.allowManagedWhitelist.push_back(InetAddress(address));
+ if (nextPos == std::string::npos) break;
+ pos = nextPos + 1;
+ }
+ }
+ } else {
+ n.settings.allowManaged = true;
+ }
+ n.settings.allowGlobal = nc.getB("allowGlobal", false);
+ n.settings.allowDefault = nc.getB("allowDefault", false);
}
} catch (std::exception &exc) {
#ifdef __WINDOWS__