]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Correctly install DNS servers on Android if frontend is not used.
authorTobias Brunner <tobias@strongswan.org>
Wed, 5 Oct 2011 13:04:24 +0000 (15:04 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 5 Oct 2011 13:04:24 +0000 (15:04 +0200)
src/libcharon/plugins/android/android_handler.c
src/libcharon/plugins/android/android_handler.h
src/libcharon/plugins/android/android_plugin.c

index ec3ff7a51990974b418b584d7cd12783140f1b81..a53962f160853f561c241430b5922e55259bc446 100644 (file)
@@ -1,6 +1,6 @@
 /*
+ * Copyright (C) 2010-2011 Tobias Brunner
  * Copyright (C) 2010 Martin Willi
- * Copyright (C) 2010 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -36,8 +36,19 @@ struct private_android_handler_t {
         * List of registered DNS servers
         */
        linked_list_t *dns;
+
+       /**
+        * Whether the VPN frontend is used
+        */
+       bool frontend;
 };
 
+/**
+ * Prefixes to be used when installing DNS servers
+ */
+#define DNS_PREFIX_DEFAULT  "net"
+#define DNS_PREFIX_FRONTEND "vpn"
+
 /**
  * Struct to store a pair of old and installed DNS servers
  */
@@ -70,12 +81,13 @@ bool filter_dns_pair(void *data, dns_pair_t **in, host_t **out)
 /**
  * Read DNS server property with a given index
  */
-host_t *get_dns_server(int index)
+host_t *get_dns_server(private_android_handler_t *this, int index)
 {
        host_t *dns = NULL;
-       char key[10], value[PROPERTY_VALUE_MAX];
+       char key[10], value[PROPERTY_VALUE_MAX],
+                *prefix = this->frontend ? DNS_PREFIX_FRONTEND : DNS_PREFIX_DEFAULT;
 
-       if (snprintf(key, sizeof(key), "vpn.dns%d", index) >= sizeof(key))
+       if (snprintf(key, sizeof(key), "%s.dns%d", prefix, index) >= sizeof(key))
        {
                return NULL;
        }
@@ -90,11 +102,12 @@ host_t *get_dns_server(int index)
 /**
  * Set DNS server property with a given index
  */
-bool set_dns_server(int index, host_t *dns)
+bool set_dns_server(private_android_handler_t *this, int index, host_t *dns)
 {
-       char key[10], value[PROPERTY_VALUE_MAX];
+       char key[10], value[PROPERTY_VALUE_MAX],
+                *prefix = this->frontend ? DNS_PREFIX_FRONTEND : DNS_PREFIX_DEFAULT;
 
-       if (snprintf(key, sizeof(key), "vpn.dns%d", index) >= sizeof(key))
+       if (snprintf(key, sizeof(key), "%s.dns%d", prefix, index) >= sizeof(key))
        {
                return FALSE;
        }
@@ -136,8 +149,8 @@ METHOD(attribute_handler_t, handle, bool,
                                pair = malloc_thing(dns_pair_t);
                                pair->dns = dns;
                                index = this->dns->get_count(this->dns) + 1;
-                               pair->old = get_dns_server(index);
-                               set_dns_server(index, dns);
+                               pair->old = get_dns_server(this, index);
+                               set_dns_server(this, index, dns);
                                this->dns->insert_last(this->dns, pair);
                                return TRUE;
                        }
@@ -164,7 +177,7 @@ METHOD(attribute_handler_t, release, void,
                        if (chunk_equals(pair->dns->get_address(pair->dns), data))
                        {
                                this->dns->remove_at(this->dns, enumerator);
-                               set_dns_server(index, pair->old);
+                               set_dns_server(this, index, pair->old);
                                destroy_dns_pair(pair);
                        }
                }
@@ -204,7 +217,7 @@ METHOD(android_handler_t, destroy, void,
 /**
  * See header
  */
-android_handler_t *android_handler_create()
+android_handler_t *android_handler_create(bool frontend)
 {
        private_android_handler_t *this;
 
@@ -218,6 +231,7 @@ android_handler_t *android_handler_create()
                        .destroy = _destroy,
                },
                .dns = linked_list_create(),
+               .frontend = frontend,
        );
 
        return &this->public;
index af620505b3e4ed115b56c7a040c9f5131e6be42b..0170958ee9d157cb707bf955cfa83f74b939afe4 100644 (file)
@@ -1,6 +1,6 @@
 /*
+ * Copyright (C) 2010-2011 Tobias Brunner
  * Copyright (C) 2010 Martin Willi
- * Copyright (C) 2010 Tobias Brunner
  * Hochschule fuer Technik Rapperswil
  *
  * This program is free software; you can redistribute it and/or modify it
@@ -44,7 +44,9 @@ struct android_handler_t {
 
 /**
  * Create a android_handler instance.
+ *
+ * @param frontend             TRUE if the VPN frontend is used
  */
-android_handler_t *android_handler_create();
+android_handler_t *android_handler_create(bool frontend);
 
 #endif /** ANDROID_HANDLER_H_ @}*/
index d5101f47522cba329515bb863c198ae1aedc4cd0..b23c94384fc96852400dc4424e37020b92a950ef 100644 (file)
@@ -92,7 +92,6 @@ plugin_t *android_plugin_create()
                        },
                },
                .logger = android_logger_create(),
-               .handler = android_handler_create(),
                .creds = android_creds_create(),
        );
 
@@ -101,6 +100,7 @@ plugin_t *android_plugin_create()
        hydra->attributes->add_handler(hydra->attributes, &this->handler->handler);
 
        this->service = android_service_create(this->creds);
+       this->handler = android_handler_create(this->service != NULL);
 
        return &this->public.plugin;
 }