AUTHORS: Mention Lucas De Marchi's contributions
[platform/upstream/connman.git] / plugins / openvpn.c
index b1cad60..8df8a3f 100644 (file)
@@ -48,19 +48,21 @@ static DBusConnection *connection;
 struct {
        const char *cm_opt;
        const char *ov_opt;
+       char       has_value;
 } ov_options[] = {
-       { "Host", "--remote" },
-       { "OpenVPN.CACert", "--ca" },
-       { "OpenVPN.Cert", "--cert" },
-       { "OpenVPN.Key", "--key" },
-       { "OpenVPN.MTU", "--mtu" },
-       { "OpenVPN.Proto", "--proto" },
-       { "OpenVPN.Port", "--port" },
-       { "OpenVPN.AuthUserPass", "--auth-user-pass" },
-       { "OpenVPN.TLSRemote", "--tls-remote" },
-       { "OpenVPN.Cipher", "--cipher" },
-       { "OpenVPN.Auth", "--auth" },
-       { "OpenVPN.CompLZO", "--comp-lzo" },
+       { "Host", "--remote", 1 },
+       { "OpenVPN.CACert", "--ca", 1 },
+       { "OpenVPN.Cert", "--cert", 1 },
+       { "OpenVPN.Key", "--key", 1 },
+       { "OpenVPN.MTU", "--mtu", 1 },
+       { "OpenVPN.Proto", "--proto", 1 },
+       { "OpenVPN.Port", "--port", 1 },
+       { "OpenVPN.AuthUserPass", "--auth-user-pass", 1 },
+       { "OpenVPN.TLSRemote", "--tls-remote", 1 },
+       { "OpenVPN.Cipher", "--cipher", 1 },
+       { "OpenVPN.Auth", "--auth", 1 },
+       { "OpenVPN.CompLZO", "--comp-lzo", 0 },
+       { "OpenVPN.RemoteCertTls", "--remote-cert-tls", 1 },
 };
 
 static void ov_append_dns_entries(const char *key, const char *value,
@@ -97,7 +99,6 @@ static int ov_notify(DBusMessage *msg, struct connman_provider *provider)
 {
        DBusMessageIter iter, dict;
        const char *reason, *key, *value;
-       const char *domain = NULL;
        char *nameservers = NULL;
        char *address = NULL, *gateway = NULL, *peer = NULL;
        struct connman_ipaddress *ipaddress;
@@ -115,8 +116,6 @@ static int ov_notify(DBusMessage *msg, struct connman_provider *provider)
        if (strcmp(reason, "up"))
                return VPN_STATE_DISCONNECT;
 
-       domain = connman_provider_get_string(provider, "VPN.Domain");
-
        dbus_message_iter_recurse(&iter, &dict);
 
        while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
@@ -177,6 +176,26 @@ static int ov_notify(DBusMessage *msg, struct connman_provider *provider)
        return VPN_STATE_CONNECT;
 }
 
+static int ov_save(struct connman_provider *provider, GKeyFile *keyfile)
+{
+       const char *option;
+       int i;
+
+       for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
+               if (strncmp(ov_options[i].cm_opt, "OpenVPN.", 8) == 0) {
+                       option = connman_provider_get_string(provider,
+                                                       ov_options[i].cm_opt);
+                       if (option == NULL)
+                               continue;
+
+                       g_key_file_set_string(keyfile,
+                                       connman_provider_get_save_group(provider),
+                                       ov_options[i].cm_opt, option);
+               }
+       }
+       return 0;
+}
+
 static int task_append_config_data(struct connman_provider *provider,
                                        struct connman_task *task)
 {
@@ -190,7 +209,8 @@ static int task_append_config_data(struct connman_provider *provider,
                        continue;
 
                if (connman_task_add_argument(task,
-                                       ov_options[i].ov_opt, option) < 0) {
+                                       ov_options[i].ov_opt,
+                                       ov_options[i].has_value ? option : NULL) < 0) {
                        return -EIO;
                }
        }
@@ -269,6 +289,7 @@ static int ov_connect(struct connman_provider *provider,
 static struct vpn_driver vpn_driver = {
        .notify = ov_notify,
        .connect        = ov_connect,
+       .save           = ov_save,
 };
 
 static int openvpn_init(void)