summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/osx_attr
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2015-10-22 11:43:58 +0200
committerYves-Alexis Perez <corsac@debian.org>2015-10-22 11:43:58 +0200
commit5dca9ea0e2931f0e2a056c7964d311bcc30a01b8 (patch)
tree037f1ec5bb860846938ddcf29771c24e9c529be0 /src/libcharon/plugins/osx_attr
parentb238cf34df3fe4476ae6b7012e7cb3e9769d4d51 (diff)
downloadvyos-strongswan-5dca9ea0e2931f0e2a056c7964d311bcc30a01b8.tar.gz
vyos-strongswan-5dca9ea0e2931f0e2a056c7964d311bcc30a01b8.zip
Imported Upstream version 5.3.3
Diffstat (limited to 'src/libcharon/plugins/osx_attr')
-rw-r--r--src/libcharon/plugins/osx_attr/osx_attr_handler.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/src/libcharon/plugins/osx_attr/osx_attr_handler.c b/src/libcharon/plugins/osx_attr/osx_attr_handler.c
index d974b57ce..6baf76d35 100644
--- a/src/libcharon/plugins/osx_attr/osx_attr_handler.c
+++ b/src/libcharon/plugins/osx_attr/osx_attr_handler.c
@@ -31,6 +31,16 @@ struct private_osx_attr_handler_t {
* Public interface
*/
osx_attr_handler_t public;
+
+ /**
+ * Backup of original DNS servers, before we mess with it
+ */
+ CFMutableArrayRef original;
+
+ /**
+ * Append DNS servers to existing entries, instead of replacing
+ */
+ bool append;
};
/**
@@ -110,7 +120,8 @@ static CFMutableArrayRef get_array_from_dict(CFDictionaryRef dict,
/**
* Add/Remove a DNS server to the configuration
*/
-static bool manage_dns(int family, chunk_t data, bool add)
+static bool manage_dns(private_osx_attr_handler_t *this,
+ int family, chunk_t data, bool add)
{
SCDynamicStoreRef store;
CFStringRef path, dns;
@@ -138,6 +149,11 @@ static bool manage_dns(int family, chunk_t data, bool add)
dns = CFStringCreateWithCString(NULL, buf, kCFStringEncodingUTF8);
if (add)
{
+ if (!this->append && !this->original)
+ { /* backup orignal config, start with empty set */
+ this->original = arr;
+ arr = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
+ }
DBG1(DBG_CFG, "installing %s as DNS server", buf);
CFArrayInsertValueAtIndex(arr, 0, dns);
}
@@ -150,6 +166,12 @@ static bool manage_dns(int family, chunk_t data, bool add)
DBG1(DBG_CFG, "removing %s from DNS servers (%d)", buf, i);
CFArrayRemoveValueAtIndex(arr, i);
}
+ if (!this->append && this->original && CFArrayGetCount(arr) == 0)
+ { /* restore original config */
+ CFRelease(arr);
+ arr = this->original;
+ this->original = NULL;
+ }
}
CFRelease(dns);
CFDictionarySetValue(dict, CFSTR("ServerAddresses"), arr);
@@ -175,7 +197,7 @@ METHOD(attribute_handler_t, handle, bool,
switch (type)
{
case INTERNAL_IP4_DNS:
- return manage_dns(AF_INET, data, TRUE);
+ return manage_dns(this, AF_INET, data, TRUE);
default:
return FALSE;
}
@@ -188,7 +210,7 @@ METHOD(attribute_handler_t, release, void,
switch (type)
{
case INTERNAL_IP4_DNS:
- manage_dns(AF_INET, data, FALSE);
+ manage_dns(this, AF_INET, data, FALSE);
break;
default:
break;
@@ -240,6 +262,8 @@ osx_attr_handler_t *osx_attr_handler_create()
},
.destroy = _destroy,
},
+ .append = lib->settings->get_bool(lib->settings,
+ "%s.plugins.osx-attr.append", TRUE, lib->ns),
);
return &this->public;