summaryrefslogtreecommitdiff
path: root/vpn/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'vpn/plugins')
-rw-r--r--vpn/plugins/l2tp.c106
-rw-r--r--vpn/plugins/openconnect.c357
-rw-r--r--vpn/plugins/openvpn.c63
-rw-r--r--vpn/plugins/pptp.c100
-rw-r--r--vpn/plugins/vpn.c67
-rw-r--r--vpn/plugins/vpn.h5
-rw-r--r--vpn/plugins/vpnc.c71
7 files changed, 401 insertions, 368 deletions
diff --git a/vpn/plugins/l2tp.c b/vpn/plugins/l2tp.c
index a322178..91acc85 100644
--- a/vpn/plugins/l2tp.c
+++ b/vpn/plugins/l2tp.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. All rights reserved.
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -132,18 +132,18 @@ static DBusMessage *l2tp_get_sec(struct connman_task *task,
const char *user, *passwd;
struct vpn_provider *provider = user_data;
- if (dbus_message_get_no_reply(msg) == FALSE) {
+ if (!dbus_message_get_no_reply(msg)) {
DBusMessage *reply;
user = vpn_provider_get_string(provider, "L2TP.User");
passwd = vpn_provider_get_string(provider, "L2TP.Password");
- if (user == NULL || strlen(user) == 0 ||
- passwd == NULL || strlen(passwd) == 0)
+ if (!user || strlen(user) == 0 ||
+ !passwd || strlen(passwd) == 0)
return NULL;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
@@ -198,20 +198,14 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
addressv4 = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_NETMASK")) {
- vpn_provider_set_string(provider, "Netmask", value);
+ if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
netmask = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_DNS")) {
- vpn_provider_set_string(provider, "DNS", value);
+ if (!strcmp(key, "INTERNAL_IP4_DNS"))
nameservers = g_strdup(value);
- }
if (!strcmp(key, "INTERNAL_IFNAME"))
ifname = g_strdup(value);
@@ -227,12 +221,12 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
g_free(ifname);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
connman_error("No IP address for provider");
g_free(addressv4);
g_free(netmask);
@@ -241,12 +235,12 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
}
value = vpn_provider_get_string(provider, "HostIP");
- if (value != NULL) {
+ if (value) {
vpn_provider_set_string(provider, "Gateway", value);
gateway = g_strdup(value);
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
gateway);
@@ -265,29 +259,29 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
static int l2tp_save(struct vpn_provider *provider, GKeyFile *keyfile)
{
const char *option;
- connman_bool_t l2tp_option, pppd_option;
+ bool l2tp_option, pppd_option;
int i;
for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
- l2tp_option = pppd_option = FALSE;
+ l2tp_option = pppd_option = false;
if (strncmp(pppd_options[i].cm_opt, "L2TP.", 5) == 0)
- l2tp_option = TRUE;
+ l2tp_option = true;
if (strncmp(pppd_options[i].cm_opt, "PPPD.", 5) == 0)
- pppd_option = TRUE;
+ pppd_option = true;
- if (l2tp_option == TRUE || pppd_option == TRUE) {
+ if (l2tp_option || pppd_option) {
option = vpn_provider_get_string(provider,
pppd_options[i].cm_opt);
- if (option == NULL) {
+ if (!option) {
/*
* Check if the option prefix is L2TP as the
* PPPD options were using L2TP prefix earlier.
*/
char *l2tp_str;
- if (pppd_option == FALSE)
+ if (!pppd_option)
continue;
l2tp_str = g_strdup_printf("L2TP.%s",
@@ -296,7 +290,7 @@ static int l2tp_save(struct vpn_provider *provider, GKeyFile *keyfile)
l2tp_str);
g_free(l2tp_str);
- if (option == NULL)
+ if (!option)
continue;
}
@@ -333,7 +327,7 @@ static ssize_t l2tp_write_bool_option(int fd,
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0) {
@@ -352,8 +346,8 @@ static int l2tp_write_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL) {
- if (value != NULL)
+ if (key) {
+ if (value)
buf = g_strdup_printf("%s %s\n", key, value);
else
buf = g_strdup_printf("%s\n", key);
@@ -371,7 +365,7 @@ static int l2tp_write_section(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
buf = g_strdup_printf("%s = %s\n", key, value);
ret = full_write(fd, buf, strlen(buf));
@@ -478,11 +472,11 @@ static void l2tp_died(struct connman_task *task, int exit_code, void *user_data)
vpn_died(task, exit_code, user_data);
- conf_file = g_strdup_printf("/var/run/connman/connman-xl2tpd.conf");
+ conf_file = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
unlink(conf_file);
g_free(conf_file);
- conf_file = g_strdup_printf("/var/run/connman/connman-ppp-option.conf");
+ conf_file = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
unlink(conf_file);
g_free(conf_file);
}
@@ -508,7 +502,7 @@ static void request_input_reply(DBusMessage *reply, void *user_data)
goto done;
}
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
+ if (!vpn_agent_check_reply_has_dict(reply))
goto done;
dbus_message_iter_init(reply, &iter);
@@ -567,7 +561,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
const char *error, void *user_data);
static int request_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ request_cb_t callback, const char *dbus_sender,
+ void *user_data)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
@@ -575,16 +570,17 @@ static int request_input(struct vpn_provider *provider,
DBusMessageIter dict;
struct request_input_reply *l2tp_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -602,7 +598,7 @@ static int request_input(struct vpn_provider *provider,
connman_dbus_dict_close(&iter, &dict);
l2tp_reply = g_try_new0(struct request_input_reply, 1);
- if (l2tp_reply == NULL) {
+ if (!l2tp_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -613,7 +609,7 @@ static int request_input(struct vpn_provider *provider,
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_reply, l2tp_reply);
+ request_input_reply, l2tp_reply, agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
@@ -635,7 +631,7 @@ static int run_connect(struct vpn_provider *provider,
int l2tp_fd, pppd_fd;
int err;
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
DBG("Cannot connect username %s password %p",
username, password);
err = -EINVAL;
@@ -644,7 +640,7 @@ static int run_connect(struct vpn_provider *provider,
DBG("username %s password %p", username, password);
- l2tp_name = g_strdup_printf("/var/run/connman/connman-xl2tpd.conf");
+ l2tp_name = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
l2tp_fd = open(l2tp_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (l2tp_fd < 0) {
@@ -654,7 +650,7 @@ static int run_connect(struct vpn_provider *provider,
goto done;
}
- pppd_name = g_strdup_printf("/var/run/connman/connman-ppp-option.conf");
+ pppd_name = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
pppd_fd = open(pppd_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (pppd_fd < 0) {
@@ -675,6 +671,8 @@ static int run_connect(struct vpn_provider *provider,
g_free(l2tp_name);
g_free(pppd_name);
+ close(l2tp_fd);
+ close(pppd_fd);
err = connman_task_run(task, l2tp_died, provider,
NULL, NULL, NULL);
@@ -685,7 +683,7 @@ static int run_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
@@ -704,10 +702,10 @@ static void request_input_cb(struct vpn_provider *provider,
{
struct l2tp_private_data *data = user_data;
- if (username == NULL || password == NULL)
+ if (!username || !password)
DBG("Requesting username %s or password failed, error %s",
username, error);
- else if (error != NULL)
+ else if (error)
DBG("error %s", error);
vpn_provider_set_string(provider, "L2TP.User", username);
@@ -722,7 +720,8 @@ static void request_input_cb(struct vpn_provider *provider,
static int l2tp_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *username, *password;
int err;
@@ -738,11 +737,11 @@ static int l2tp_connect(struct vpn_provider *provider,
DBG("user %s password %p", username, password);
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
struct l2tp_private_data *data;
data = g_try_new0(struct l2tp_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->task = task;
@@ -750,7 +749,8 @@ static int l2tp_connect(struct vpn_provider *provider,
data->cb = cb;
data->user_data = user_data;
- err = request_input(provider, request_input_cb, data);
+ err = request_input(provider, request_input_cb, dbus_sender,
+ data);
if (err != -EINPROGRESS) {
free_private_data(data);
goto done;
@@ -763,13 +763,13 @@ done:
username, password);
error:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int l2tp_error_code(int exit_code)
+static int l2tp_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1:
diff --git a/vpn/plugins/openconnect.c b/vpn/plugins/openconnect.c
index 83584da..c6b9cd6 100644
--- a/vpn/plugins/openconnect.c
+++ b/vpn/plugins/openconnect.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -57,12 +57,19 @@ struct {
};
struct oc_private_data {
+ struct vpn_provider *provider;
struct connman_task *task;
char *if_name;
vpn_provider_connect_cb_t cb;
void *user_data;
};
+static void free_private_data(struct oc_private_data *data)
+{
+ g_free(data->if_name);
+ g_free(data);
+}
+
static int task_append_config_data(struct vpn_provider *provider,
struct connman_task *task)
{
@@ -70,12 +77,12 @@ static int task_append_config_data(struct vpn_provider *provider,
int i;
for (i = 0; i < (int)ARRAY_SIZE(oc_options); i++) {
- if (oc_options[i].oc_opt == NULL)
+ if (!oc_options[i].oc_opt)
continue;
option = vpn_provider_get_string(provider,
oc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
if (connman_task_add_argument(task,
@@ -144,7 +151,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
/* The netmask contains the address and the prefix */
sep = strchr(value, '/');
- if (sep != NULL) {
+ if (sep) {
unsigned char ip_len = sep - value;
addressv6 = g_strndup(value, ip_len);
@@ -160,13 +167,13 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
if (!strcmp(key, "CISCO_PROXY_PAC"))
vpn_provider_set_pac(provider, value);
- if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN")) {
+ if (!domain && !strcmp(key, "CISCO_DEF_DOMAIN")) {
g_free(domain);
domain = g_strdup(value);
}
- if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
- g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
+ if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+ g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
vpn_provider_append_route(provider, key, value);
dbus_message_iter_next(&dict);
@@ -174,14 +181,14 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%p %p", addressv4, addressv6);
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
- else if (addressv6 != NULL)
+ else if (addressv6)
ipaddress = connman_ipaddress_alloc(AF_INET6);
else
ipaddress = NULL;
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_free(addressv4);
g_free(addressv6);
g_free(netmask);
@@ -191,7 +198,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4,
netmask, gateway);
else
@@ -210,8 +217,85 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_CONNECT;
}
-static void request_input_append_cookie(DBusMessageIter *iter,
- void *user_data)
+static int run_connect(struct vpn_provider *provider,
+ struct connman_task *task, const char *if_name,
+ vpn_provider_connect_cb_t cb, void *user_data)
+{
+ const char *vpnhost, *vpncookie, *servercert, *mtu;
+ int fd, err = 0, len;
+
+ vpnhost = vpn_provider_get_string(provider, "OpenConnect.VPNHost");
+ if (!vpnhost)
+ vpnhost = vpn_provider_get_string(provider, "Host");
+ vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
+ servercert = vpn_provider_get_string(provider,
+ "OpenConnect.ServerCert");
+
+ if (!vpncookie || !servercert) {
+ err = -EINVAL;
+ goto done;
+ }
+
+ task_append_config_data(provider, task);
+
+ connman_task_add_argument(task, "--servercert", servercert);
+
+ mtu = vpn_provider_get_string(provider, "VPN.MTU");
+
+ if (mtu)
+ connman_task_add_argument(task, "--mtu", (char *)mtu);
+
+ connman_task_add_argument(task, "--syslog", NULL);
+ connman_task_add_argument(task, "--cookie-on-stdin", NULL);
+
+ connman_task_add_argument(task, "--script",
+ SCRIPTDIR "/openconnect-script");
+
+ connman_task_add_argument(task, "--interface", if_name);
+
+ connman_task_add_argument(task, (char *)vpnhost, NULL);
+
+ err = connman_task_run(task, vpn_died, provider,
+ &fd, NULL, NULL);
+ if (err < 0) {
+ connman_error("openconnect failed to start");
+ err = -EIO;
+ goto done;
+ }
+
+ len = strlen(vpncookie);
+ if (write(fd, vpncookie, len) != (ssize_t)len ||
+ write(fd, "\n", 1) != 1) {
+ connman_error("openconnect failed to take cookie on stdin");
+ err = -EIO;
+ goto done;
+ }
+
+done:
+ if (cb)
+ cb(provider, user_data, err);
+
+ return err;
+}
+
+static void request_input_append_informational(DBusMessageIter *iter,
+ void *user_data)
+{
+ const char *str;
+
+ str = "string";
+ connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING, &str);
+
+ str = "informational";
+ connman_dbus_dict_append_basic(iter, "Requirement", DBUS_TYPE_STRING,
+ &str);
+
+ str = user_data;
+ connman_dbus_dict_append_basic(iter, "Value", DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_mandatory(DBusMessageIter *iter,
+ void *user_data)
{
char *str = "string";
@@ -222,29 +306,20 @@ static void request_input_append_cookie(DBusMessageIter *iter,
DBUS_TYPE_STRING, &str);
}
-struct request_input_reply {
- struct vpn_provider *provider;
- vpn_provider_auth_cb_t callback;
- void *user_data;
-};
-
static void request_input_cookie_reply(DBusMessage *reply, void *user_data)
{
- struct request_input_reply *cookie_reply = user_data;
- const char *error = NULL;
- char *cookie = NULL;
+ struct oc_private_data *data = user_data;
+ char *cookie = NULL, *servercert = NULL, *vpnhost = NULL;
char *key;
DBusMessageIter iter, dict;
- DBG("provider %p", cookie_reply->provider);
+ DBG("provider %p", data->provider);
- if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
- error = dbus_message_get_error_name(reply);
- goto done;
- }
+ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+ goto err;
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
- goto done;
+ if (!vpn_agent_check_reply_has_dict(reply))
+ goto err;
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &dict);
@@ -267,40 +342,76 @@ static void request_input_cookie_reply(DBusMessage *reply, void *user_data)
!= DBUS_TYPE_STRING)
break;
dbus_message_iter_get_basic(&value, &cookie);
+ vpn_provider_set_string_hide_value(data->provider,
+ key, cookie);
+
+ } else if (g_str_equal(key, "OpenConnect.ServerCert")) {
+ dbus_message_iter_next(&entry);
+ if (dbus_message_iter_get_arg_type(&entry)
+ != DBUS_TYPE_VARIANT)
+ break;
+ dbus_message_iter_recurse(&entry, &value);
+ if (dbus_message_iter_get_arg_type(&value)
+ != DBUS_TYPE_STRING)
+ break;
+ dbus_message_iter_get_basic(&value, &servercert);
+ vpn_provider_set_string(data->provider, key,
+ servercert);
+
+ } else if (g_str_equal(key, "OpenConnect.VPNHost")) {
+ dbus_message_iter_next(&entry);
+ if (dbus_message_iter_get_arg_type(&entry)
+ != DBUS_TYPE_VARIANT)
+ break;
+ dbus_message_iter_recurse(&entry, &value);
+ if (dbus_message_iter_get_arg_type(&value)
+ != DBUS_TYPE_STRING)
+ break;
+ dbus_message_iter_get_basic(&value, &vpnhost);
+ vpn_provider_set_string(data->provider, key, vpnhost);
}
dbus_message_iter_next(&dict);
}
-done:
- cookie_reply->callback(cookie_reply->provider, cookie, error,
- cookie_reply->user_data);
- g_free(cookie_reply);
-}
+ if (!cookie || !servercert || !vpnhost)
+ goto err;
+
+ run_connect(data->provider, data->task, data->if_name, data->cb,
+ data->user_data);
+
+ free_private_data(data);
-typedef void (* request_cb_t)(struct vpn_provider *provider,
- const char *vpncookie,
- const char *error, void *user_data);
+ return;
+
+err:
+ vpn_provider_indicate_error(data->provider,
+ VPN_PROVIDER_ERROR_AUTH_FAILED);
+
+ free_private_data(data);
+}
static int request_cookie_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ struct oc_private_data *data,
+ const char *dbus_sender)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
DBusMessageIter iter;
DBusMessageIter dict;
- struct request_input_reply *cookie_reply;
+ const char *str;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -311,30 +422,39 @@ static int request_cookie_input(struct vpn_provider *provider,
connman_dbus_dict_open(&iter, &dict);
+ str = vpn_provider_get_string(provider, "OpenConnect.CACert");
+ if (str)
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.CACert",
+ request_input_append_informational,
+ (void *)str);
+
+ str = vpn_provider_get_string(provider, "OpenConnect.ClientCert");
+ if (str)
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.ClientCert",
+ request_input_append_informational,
+ (void *)str);
+
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.ServerCert",
+ request_input_append_mandatory, NULL);
+
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.VPNHost",
+ request_input_append_mandatory, NULL);
+
connman_dbus_dict_append_dict(&dict, "OpenConnect.Cookie",
- request_input_append_cookie, provider);
+ request_input_append_mandatory, NULL);
vpn_agent_append_host_and_name(&dict, provider);
connman_dbus_dict_close(&iter, &dict);
- cookie_reply = g_try_new0(struct request_input_reply, 1);
- if (cookie_reply == NULL) {
- dbus_message_unref(message);
- return -ENOMEM;
- }
-
- cookie_reply->provider = provider;
- cookie_reply->callback = callback;
- cookie_reply->user_data = user_data;
-
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_cookie_reply, cookie_reply);
+ request_input_cookie_reply, data, agent);
+
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
- g_free(cookie_reply);
+
return err;
}
@@ -343,133 +463,46 @@ static int request_cookie_input(struct vpn_provider *provider,
return -EINPROGRESS;
}
-static int run_connect(struct vpn_provider *provider,
- struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data,
- const char *vpncookie)
-{
- const char *vpnhost, *cafile, *certsha1, *mtu;
- int fd, err = 0, len;
-
- vpnhost = vpn_provider_get_string(provider, "Host");
-
- if (vpncookie == NULL) {
- DBG("Cookie missing, cannot connect!");
- err = -EINVAL;
- goto done;
- }
-
- task_append_config_data(provider, task);
-
- vpn_provider_set_string(provider, "OpenConnect.Cookie", vpncookie);
-
- certsha1 = vpn_provider_get_string(provider,
- "OpenConnect.ServerCert");
- if (certsha1)
- connman_task_add_argument(task, "--servercert",
- (char *)certsha1);
-
- cafile = vpn_provider_get_string(provider, "OpenConnect.CACert");
- mtu = vpn_provider_get_string(provider, "VPN.MTU");
-
- if (cafile)
- connman_task_add_argument(task, "--cafile",
- (char *)cafile);
- if (mtu)
- connman_task_add_argument(task, "--mtu", (char *)mtu);
-
- connman_task_add_argument(task, "--syslog", NULL);
- connman_task_add_argument(task, "--cookie-on-stdin", NULL);
-
- connman_task_add_argument(task, "--script",
- SCRIPTDIR "/openconnect-script");
-
- connman_task_add_argument(task, "--interface", if_name);
-
- connman_task_add_argument(task, (char *)vpnhost, NULL);
-
- err = connman_task_run(task, vpn_died, provider,
- &fd, NULL, NULL);
- if (err < 0) {
- connman_error("openconnect failed to start");
- err = -EIO;
- goto done;
- }
-
- len = strlen(vpncookie);
- if (write(fd, vpncookie, len) != (ssize_t)len ||
- write(fd, "\n", 1) != 1) {
- connman_error("openconnect failed to take cookie on stdin");
- err = -EIO;
- goto done;
- }
-
-done:
- if (cb != NULL)
- cb(provider, user_data, err);
-
- return err;
-}
-
-static void free_private_data(struct oc_private_data *data)
-{
- g_free(data->if_name);
- g_free(data);
-}
-
-static void request_input_cb(struct vpn_provider *provider,
- const char *vpncookie,
- const char *error, void *user_data)
-{
- struct oc_private_data *data = user_data;
-
- if (vpncookie == NULL)
- DBG("Requesting cookie failed, error %s", error);
- else if (error != NULL)
- DBG("error %s", error);
-
- run_connect(provider, data->task, data->if_name, data->cb,
- data->user_data, vpncookie);
-
- free_private_data(data);
-}
-
static int oc_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb,
+ const char *dbus_sender, void *user_data)
{
- const char *vpnhost, *vpncookie;
+ const char *vpnhost, *vpncookie, *servercert;
int err;
vpnhost = vpn_provider_get_string(provider, "Host");
- if (vpnhost == NULL) {
+ if (!vpnhost) {
connman_error("Host not set; cannot enable VPN");
return -EINVAL;
}
vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
- if (vpncookie == NULL) {
+ servercert = vpn_provider_get_string(provider,
+ "OpenConnect.ServerCert");
+ if (!vpncookie || !servercert) {
struct oc_private_data *data;
data = g_try_new0(struct oc_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
+ data->provider = provider;
data->task = task;
data->if_name = g_strdup(if_name);
data->cb = cb;
data->user_data = user_data;
- err = request_cookie_input(provider, request_input_cb, data);
+ err = request_cookie_input(provider, data, dbus_sender);
if (err != -EINPROGRESS) {
+ vpn_provider_indicate_error(data->provider,
+ VPN_PROVIDER_ERROR_LOGIN_FAILED);
free_private_data(data);
- goto done;
}
return err;
}
-done:
- return run_connect(provider, task, if_name, cb, user_data, vpncookie);
+ return run_connect(provider, task, if_name, cb, user_data);
}
static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
@@ -479,21 +512,21 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
setting = vpn_provider_get_string(provider,
"OpenConnect.ServerCert");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"OpenConnect.ServerCert", setting);
setting = vpn_provider_get_string(provider,
"OpenConnect.CACert");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"OpenConnect.CACert", setting);
setting = vpn_provider_get_string(provider,
"VPN.MTU");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"VPN.MTU", setting);
@@ -502,7 +535,7 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
if (strncmp(oc_options[i].cm_opt, "OpenConnect.", 12) == 0) {
option = vpn_provider_get_string(provider,
oc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -514,13 +547,15 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
return 0;
}
-static int oc_error_code(int exit_code)
+static int oc_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1:
return VPN_PROVIDER_ERROR_CONNECT_FAILED;
case 2:
+ vpn_provider_set_string_hide_value(provider,
+ "OpenConnect.Cookie", NULL);
return VPN_PROVIDER_ERROR_LOGIN_FAILED;
default:
return VPN_PROVIDER_ERROR_UNKNOWN;
diff --git a/vpn/plugins/openvpn.c b/vpn/plugins/openvpn.c
index 486944d..35013c4 100644
--- a/vpn/plugins/openvpn.c
+++ b/vpn/plugins/openvpn.c
@@ -84,18 +84,18 @@ static struct nameserver_entry *ov_append_dns_entries(const char *key,
struct nameserver_entry *entry = NULL;
gchar **options;
- if (g_str_has_prefix(key, "foreign_option_") == FALSE)
+ if (!g_str_has_prefix(key, "foreign_option_"))
return NULL;
options = g_strsplit(value, " ", 3);
- if (options[0] != NULL &&
+ if (options[0] &&
!strcmp(options[0], "dhcp-option") &&
- options[1] != NULL &&
+ options[1] &&
!strcmp(options[1], "DNS") &&
- options[2] != NULL) {
+ options[2]) {
entry = g_try_new(struct nameserver_entry, 1);
- if (entry == NULL)
+ if (!entry)
return NULL;
entry->nameserver = g_strdup(options[2]);
@@ -112,15 +112,15 @@ static char *ov_get_domain_name(const char *key, const char *value)
gchar **options;
char *domain = NULL;
- if (g_str_has_prefix(key, "foreign_option_") == FALSE)
+ if (!g_str_has_prefix(key, "foreign_option_"))
return NULL;
options = g_strsplit(value, " ", 3);
- if (options[0] != NULL &&
+ if (options[0] &&
!strcmp(options[0], "dhcp-option") &&
- options[1] != NULL &&
+ options[1] &&
!strcmp(options[1], "DOMAIN") &&
- options[2] != NULL) {
+ options[2]) {
domain = g_strdup(options[2]);
}
@@ -186,30 +186,24 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "trusted_ip")) {
- vpn_provider_set_string(provider, "Gateway", value);
+ if (!strcmp(key, "trusted_ip"))
gateway = g_strdup(value);
- }
- if (!strcmp(key, "ifconfig_local")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "ifconfig_local"))
address = g_strdup(value);
- }
- if (!strcmp(key, "ifconfig_remote")) {
- vpn_provider_set_string(provider, "Peer", value);
+ if (!strcmp(key, "ifconfig_remote"))
peer = g_strdup(value);
- }
- if (g_str_has_prefix(key, "route_") == TRUE)
+ if (g_str_has_prefix(key, "route_"))
vpn_provider_append_route(provider, key, value);
- if ((ns_entry = ov_append_dns_entries(key, value)) != NULL)
+ if ((ns_entry = ov_append_dns_entries(key, value)))
nameserver_list = g_slist_prepend(nameserver_list,
ns_entry);
else {
char *domain = ov_get_domain_name(key, value);
- if (domain != NULL) {
+ if (domain) {
vpn_provider_set_domain(provider, domain);
g_free(domain);
}
@@ -219,7 +213,7 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
}
ipaddress = connman_ipaddress_alloc(AF_INET);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_slist_free_full(nameserver_list, free_ns_entry);
g_free(address);
g_free(gateway);
@@ -232,16 +226,16 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
connman_ipaddress_set_peer(ipaddress, peer);
vpn_provider_set_ipaddress(provider, ipaddress);
- if (nameserver_list != NULL) {
+ if (nameserver_list) {
char *nameservers = NULL;
GSList *tmp;
nameserver_list = g_slist_sort(nameserver_list, cmp_ns);
- for (tmp = nameserver_list; tmp != NULL;
+ for (tmp = nameserver_list; tmp;
tmp = g_slist_next(tmp)) {
struct nameserver_entry *ns = tmp->data;
- if (nameservers == NULL) {
+ if (!nameservers) {
nameservers = g_strdup(ns->nameserver);
} else {
char *str;
@@ -276,7 +270,7 @@ static int ov_save(struct vpn_provider *provider, GKeyFile *keyfile)
if (strncmp(ov_options[i].cm_opt, "OpenVPN.", 8) == 0) {
option = vpn_provider_get_string(provider,
ov_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -294,12 +288,12 @@ static int task_append_config_data(struct vpn_provider *provider,
int i;
for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
- if (ov_options[i].ov_opt == NULL)
+ if (!ov_options[i].ov_opt)
continue;
option = vpn_provider_get_string(provider,
ov_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
if (connman_task_add_argument(task,
@@ -314,13 +308,14 @@ static int task_append_config_data(struct vpn_provider *provider,
static int ov_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *option;
int err = 0, fd;
option = vpn_provider_get_string(provider, "Host");
- if (option == NULL) {
+ if (!option) {
connman_error("Host not set; cannot enable VPN");
return -EINVAL;
}
@@ -328,16 +323,16 @@ static int ov_connect(struct vpn_provider *provider,
task_append_config_data(provider, task);
option = vpn_provider_get_string(provider, "OpenVPN.ConfigFile");
- if (option == NULL) {
+ if (!option) {
/*
* Set some default options if user has no config file.
*/
option = vpn_provider_get_string(provider, "OpenVPN.TLSAuth");
- if (option != NULL) {
+ if (option) {
connman_task_add_argument(task, "--tls-auth", option);
option = vpn_provider_get_string(provider,
"OpenVPN.TLSAuthDir");
- if (option != NULL)
+ if (option)
connman_task_add_argument(task, option, NULL);
}
@@ -394,7 +389,7 @@ static int ov_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
diff --git a/vpn/plugins/pptp.c b/vpn/plugins/pptp.c
index 01b5e2b..a6e51e7 100644
--- a/vpn/plugins/pptp.c
+++ b/vpn/plugins/pptp.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. All rights reserved.
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -96,17 +96,17 @@ static DBusMessage *pptp_get_sec(struct connman_task *task,
struct vpn_provider *provider = user_data;
DBusMessage *reply;
- if (dbus_message_get_no_reply(msg) == TRUE)
+ if (dbus_message_get_no_reply(msg))
return NULL;
user = vpn_provider_get_string(provider, "PPTP.User");
passwd = vpn_provider_get_string(provider, "PPTP.Password");
- if (user == NULL || strlen(user) == 0 ||
- passwd == NULL || strlen(passwd) == 0)
+ if (!user || strlen(user) == 0 ||
+ !passwd || strlen(passwd) == 0)
return NULL;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
@@ -128,7 +128,7 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
dbus_message_iter_get_basic(&iter, &reason);
dbus_message_iter_next(&iter);
- if (provider == NULL) {
+ if (!provider) {
connman_error("No provider found");
return VPN_STATE_FAILURE;
}
@@ -157,20 +157,14 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
addressv4 = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_NETMASK")) {
- vpn_provider_set_string(provider, "Netmask", value);
+ if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
netmask = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_DNS")) {
- vpn_provider_set_string(provider, "DNS", value);
+ if (!strcmp(key, "INTERNAL_IP4_DNS"))
nameservers = g_strdup(value);
- }
if (!strcmp(key, "INTERNAL_IFNAME"))
ifname = g_strdup(value);
@@ -186,12 +180,12 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
g_free(ifname);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
connman_error("No IP address for provider");
g_free(addressv4);
g_free(netmask);
@@ -200,12 +194,12 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
}
value = vpn_provider_get_string(provider, "HostIP");
- if (value != NULL) {
+ if (value) {
vpn_provider_set_string(provider, "Gateway", value);
gateway = g_strdup(value);
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
gateway);
@@ -224,29 +218,29 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
{
const char *option;
- connman_bool_t pptp_option, pppd_option;
+ bool pptp_option, pppd_option;
int i;
for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
- pptp_option = pppd_option = FALSE;
+ pptp_option = pppd_option = false;
if (strncmp(pptp_options[i].cm_opt, "PPTP.", 5) == 0)
- pptp_option = TRUE;
+ pptp_option = true;
if (strncmp(pptp_options[i].cm_opt, "PPPD.", 5) == 0)
- pppd_option = TRUE;
+ pppd_option = true;
- if (pptp_option == TRUE || pppd_option == TRUE) {
+ if (pptp_option || pppd_option) {
option = vpn_provider_get_string(provider,
pptp_options[i].cm_opt);
- if (option == NULL) {
+ if (!option) {
/*
* Check if the option prefix is PPTP as the
* PPPD options were using PPTP prefix earlier.
*/
char *pptp_str;
- if (pppd_option == FALSE)
+ if (!pppd_option)
continue;
pptp_str = g_strdup_printf("PPTP.%s",
@@ -255,7 +249,7 @@ static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
pptp_str);
g_free(pptp_str);
- if (option == NULL)
+ if (!option)
continue;
}
@@ -271,7 +265,7 @@ static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
static void pptp_write_bool_option(struct connman_task *task,
const char *key, const char *value)
{
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0)
@@ -300,7 +294,7 @@ static void request_input_reply(DBusMessage *reply, void *user_data)
goto done;
}
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
+ if (!vpn_agent_check_reply_has_dict(reply))
goto done;
dbus_message_iter_init(reply, &iter);
@@ -359,7 +353,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
const char *error, void *user_data);
static int request_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ request_cb_t callback, const char *dbus_sender,
+ void *user_data)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
@@ -367,16 +362,17 @@ static int request_input(struct vpn_provider *provider,
DBusMessageIter dict;
struct request_input_reply *pptp_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -394,7 +390,7 @@ static int request_input(struct vpn_provider *provider,
connman_dbus_dict_close(&iter, &dict);
pptp_reply = g_try_new0(struct request_input_reply, 1);
- if (pptp_reply == NULL) {
+ if (!pptp_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -405,7 +401,7 @@ static int request_input(struct vpn_provider *provider,
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_reply, pptp_reply);
+ request_input_reply, pptp_reply, agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
@@ -428,13 +424,13 @@ static int run_connect(struct vpn_provider *provider,
int err, i;
host = vpn_provider_get_string(provider, "Host");
- if (host == NULL) {
+ if (!host) {
connman_error("Host not set; cannot enable VPN");
err = -EINVAL;
goto done;
}
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
DBG("Cannot connect username %s password %p",
username, password);
err = -EINVAL;
@@ -445,7 +441,7 @@ static int run_connect(struct vpn_provider *provider,
str = g_strdup_printf("%s %s --nolaunchpppd --loglevel 2",
PPTP, host);
- if (str == NULL) {
+ if (!str) {
connman_error("can not allocate memory");
err = -ENOMEM;
goto done;
@@ -465,10 +461,10 @@ static int run_connect(struct vpn_provider *provider,
for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
opt_s = vpn_provider_get_string(provider,
pptp_options[i].cm_opt);
- if (opt_s == NULL)
+ if (!opt_s)
opt_s = pptp_options[i].vpnc_default;
- if (opt_s == NULL)
+ if (!opt_s)
continue;
if (pptp_options[i].type == OPT_STRING)
@@ -491,7 +487,7 @@ static int run_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
@@ -510,10 +506,10 @@ static void request_input_cb(struct vpn_provider *provider,
{
struct pptp_private_data *data = user_data;
- if (username == NULL || password == NULL)
+ if (!username || !password)
DBG("Requesting username %s or password failed, error %s",
username, error);
- else if (error != NULL)
+ else if (error)
DBG("error %s", error);
vpn_provider_set_string(provider, "PPTP.User", username);
@@ -528,7 +524,8 @@ static void request_input_cb(struct vpn_provider *provider,
static int pptp_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *username, *password;
int err;
@@ -546,11 +543,11 @@ static int pptp_connect(struct vpn_provider *provider,
DBG("user %s password %p", username, password);
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
struct pptp_private_data *data;
data = g_try_new0(struct pptp_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->task = task;
@@ -558,7 +555,8 @@ static int pptp_connect(struct vpn_provider *provider,
data->cb = cb;
data->user_data = user_data;
- err = request_input(provider, request_input_cb, data);
+ err = request_input(provider, request_input_cb, dbus_sender,
+ data);
if (err != -EINPROGRESS) {
free_private_data(data);
goto done;
@@ -571,13 +569,13 @@ done:
username, password);
error:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int pptp_error_code(int exit_code)
+static int pptp_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 99f829c..b407573 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -75,16 +75,16 @@ static int stop_vpn(struct vpn_provider *provider)
struct ifreq ifr;
int fd, err;
- if (data == NULL)
+ if (!data)
return -EINVAL;
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return -EINVAL;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data != NULL && vpn_driver_data->vpn_driver != NULL &&
+ if (vpn_driver_data && vpn_driver_data->vpn_driver &&
vpn_driver_data->vpn_driver->flags == VPN_FLAG_NO_TUN)
return 0;
@@ -129,7 +129,7 @@ void vpn_died(struct connman_task *task, int exit_code, void *user_data)
DBG("provider %p data %p", provider, data);
- if (data == NULL)
+ if (!data)
goto vpn_exit;
state = data->state;
@@ -149,12 +149,13 @@ vpn_exit:
struct vpn_driver_data *vpn_data = NULL;
name = vpn_provider_get_driver_name(provider);
- if (name != NULL)
+ if (name)
vpn_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_data != NULL &&
- vpn_data->vpn_driver->error_code != NULL)
- ret = vpn_data->vpn_driver->error_code(exit_code);
+ if (vpn_data &&
+ vpn_data->vpn_driver->error_code)
+ ret = vpn_data->vpn_driver->error_code(provider,
+ exit_code);
else
ret = VPN_PROVIDER_ERROR_UNKNOWN;
@@ -166,7 +167,7 @@ vpn_exit:
vpn_provider_set_index(provider, -1);
- if (data != NULL) {
+ if (data) {
vpn_provider_unref(data->provider);
g_free(data->if_name);
g_free(data);
@@ -180,14 +181,14 @@ int vpn_set_ifname(struct vpn_provider *provider, const char *ifname)
struct vpn_data *data = vpn_provider_get_data(provider);
int index;
- if (ifname == NULL || data == NULL)
+ if (!ifname || !data)
return -EIO;
index = connman_inet_ifindex(ifname);
if (index < 0)
return -EIO;
- if (data->if_name != NULL)
+ if (data->if_name)
g_free(data->if_name);
data->if_name = (char *)g_strdup(ifname);
@@ -224,14 +225,14 @@ static DBusMessage *vpn_notify(struct connman_task *task,
name = vpn_provider_get_driver_name(provider);
- if (name == NULL) {
+ if (!name) {
DBG("Cannot find VPN driver for provider %p", provider);
vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
return NULL;
}
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data == NULL) {
+ if (!vpn_driver_data) {
DBG("Cannot find VPN driver data for name %s", name);
vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
return NULL;
@@ -290,7 +291,7 @@ static int vpn_create_tun(struct vpn_provider *provider)
int i, fd, index;
int ret = 0;
- if (data == NULL)
+ if (!data)
return -EISCONN;
fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
@@ -320,7 +321,7 @@ static int vpn_create_tun(struct vpn_provider *provider)
}
data->if_name = (char *)g_strdup(ifr.ifr_name);
- if (data->if_name == NULL) {
+ if (!data->if_name) {
connman_error("Failed to allocate memory");
close(fd);
ret = -ENOMEM;
@@ -354,7 +355,8 @@ exist_err:
}
static int vpn_connect(struct vpn_provider *provider,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb,
+ const char *dbus_sender, void *user_data)
{
struct vpn_data *data = vpn_provider_get_data(provider);
struct vpn_driver_data *vpn_driver_data;
@@ -362,7 +364,7 @@ static int vpn_connect(struct vpn_provider *provider,
int ret = 0;
enum vpn_state state = VPN_STATE_UNKNOWN;
- if (data != NULL)
+ if (data)
state = data->state;
DBG("data %p state %d", data, state);
@@ -370,7 +372,7 @@ static int vpn_connect(struct vpn_provider *provider,
switch (state) {
case VPN_STATE_UNKNOWN:
data = g_try_new0(struct vpn_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->provider = vpn_provider_ref(provider);
@@ -396,12 +398,12 @@ static int vpn_connect(struct vpn_provider *provider,
}
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return -EINVAL;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data == NULL || vpn_driver_data->vpn_driver == NULL) {
+ if (!vpn_driver_data || !vpn_driver_data->vpn_driver) {
ret = -EINVAL;
goto exist_err;
}
@@ -414,7 +416,7 @@ static int vpn_connect(struct vpn_provider *provider,
data->task = connman_task_create(vpn_driver_data->program);
- if (data->task == NULL) {
+ if (!data->task) {
ret = -ENOMEM;
stop_vpn(provider);
goto exist_err;
@@ -430,7 +432,8 @@ static int vpn_connect(struct vpn_provider *provider,
}
ret = vpn_driver_data->vpn_driver->connect(provider, data->task,
- data->if_name, cb, user_data);
+ data->if_name, cb, dbus_sender,
+ user_data);
if (ret < 0 && ret != -EINPROGRESS) {
stop_vpn(provider);
connman_task_destroy(data->task);
@@ -468,11 +471,11 @@ static int vpn_disconnect(struct vpn_provider *provider)
DBG("disconnect provider %p:", provider);
- if (data == NULL)
+ if (!data)
return 0;
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return 0;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
@@ -496,7 +499,7 @@ static int vpn_remove(struct vpn_provider *provider)
struct vpn_data *data;
data = vpn_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return 0;
if (data->watch != 0) {
@@ -519,8 +522,8 @@ static int vpn_save(struct vpn_provider *provider, GKeyFile *keyfile)
name = vpn_provider_get_driver_name(provider);
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data != NULL &&
- vpn_driver_data->vpn_driver->save != NULL)
+ if (vpn_driver_data &&
+ vpn_driver_data->vpn_driver->save)
return vpn_driver_data->vpn_driver->save(provider, keyfile);
return 0;
@@ -532,7 +535,7 @@ int vpn_register(const char *name, struct vpn_driver *vpn_driver,
struct vpn_driver_data *data;
data = g_try_new0(struct vpn_driver_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->name = name;
@@ -547,12 +550,12 @@ int vpn_register(const char *name, struct vpn_driver *vpn_driver,
data->provider_driver.remove = vpn_remove;
data->provider_driver.save = vpn_save;
- if (driver_hash == NULL)
+ if (!driver_hash)
driver_hash = g_hash_table_new_full(g_str_hash,
g_str_equal,
NULL, g_free);
- if (driver_hash == NULL) {
+ if (!driver_hash) {
connman_error("driver_hash not initialized for %s", name);
g_free(data);
return -ENOMEM;
@@ -570,7 +573,7 @@ void vpn_unregister(const char *name)
struct vpn_driver_data *data;
data = g_hash_table_lookup(driver_hash, name);
- if (data == NULL)
+ if (!data)
return;
vpn_provider_driver_unregister(&data->provider_driver);
diff --git a/vpn/plugins/vpn.h b/vpn/plugins/vpn.h
index 6f86aac..3d2b66c 100644
--- a/vpn/plugins/vpn.h
+++ b/vpn/plugins/vpn.h
@@ -45,9 +45,10 @@ struct vpn_driver {
int (*notify) (DBusMessage *msg, struct vpn_provider *provider);
int (*connect) (struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data);
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data);
void (*disconnect) (struct vpn_provider *provider);
- int (*error_code) (int exit_code);
+ int (*error_code) (struct vpn_provider *provider, int exit_code);
int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
};
diff --git a/vpn/plugins/vpnc.c b/vpn/plugins/vpnc.c
index 9f69850..04235c8 100644
--- a/vpn/plugins/vpnc.c
+++ b/vpn/plugins/vpnc.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. All rights reserved.
+ * Copyright (C) 2010,2012-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -57,29 +57,29 @@ struct {
const char *vpnc_opt;
const char *vpnc_default;
int type;
- connman_bool_t cm_save;
+ bool cm_save;
} vpnc_options[] = {
- { "Host", "IPSec gateway", NULL, OPT_STRING, TRUE },
- { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, TRUE },
- { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, FALSE },
- { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, FALSE },
- { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, FALSE },
- { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, TRUE },
- { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, TRUE },
- { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, TRUE },
- { "VPNC.Domain", "Domain", NULL, OPT_STRING, TRUE },
- { "VPNC.Vendor", "Vendor", NULL, OPT_STRING, TRUE },
- { "VPNC.LocalPort", "Local Port", "0", OPT_STRING, TRUE, },
+ { "Host", "IPSec gateway", NULL, OPT_STRING, true },
+ { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, true },
+ { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, false },
+ { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, false },
+ { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, false },
+ { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, true },
+ { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, true },
+ { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, true },
+ { "VPNC.Domain", "Domain", NULL, OPT_STRING, true },
+ { "VPNC.Vendor", "Vendor", NULL, OPT_STRING, true },
+ { "VPNC.LocalPort", "Local Port", "0", OPT_STRING, true, },
{ "VPNC.CiscoPort", "Cisco UDP Encapsulation Port", "0", OPT_STRING,
- TRUE },
- { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, TRUE },
+ true },
+ { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, true },
{ "VPNC.NATTMode", "NAT Traversal Mode", "cisco-udp", OPT_STRING,
- TRUE },
+ true },
{ "VPNC.DPDTimeout", "DPD idle timeout (our side)", NULL, OPT_STRING,
- TRUE },
- { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, TRUE },
+ true },
+ { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, true },
{ "VPNC.NoEncryption", "Enable no encryption", NULL, OPT_BOOLEAN,
- TRUE },
+ true },
};
static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
@@ -129,8 +129,8 @@ static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
if (!strcmp(key, "CISCO_DEF_DOMAIN"))
vpn_provider_set_domain(provider, value);
- if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
- g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
+ if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+ g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
vpn_provider_append_route(provider, key, value);
dbus_message_iter_next(&dict);
@@ -138,7 +138,7 @@ static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
ipaddress = connman_ipaddress_alloc(AF_INET);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_free(address);
g_free(netmask);
g_free(gateway);
@@ -180,7 +180,7 @@ static ssize_t write_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
buf = g_strdup_printf("%s %s\n", key, value);
ret = full_write(fd, buf, strlen(buf));
@@ -195,7 +195,7 @@ static ssize_t write_bool_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0) {
@@ -217,10 +217,10 @@ static int vc_write_config_data(struct vpn_provider *provider, int fd)
for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
opt_s = vpn_provider_get_string(provider,
vpnc_options[i].cm_opt);
- if (opt_s == FALSE)
+ if (!opt_s)
opt_s = vpnc_options[i].vpnc_default;
- if (opt_s == FALSE)
+ if (!opt_s)
continue;
if (vpnc_options[i].type == OPT_STRING) {
@@ -246,12 +246,12 @@ static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
if (strncmp(vpnc_options[i].cm_opt, "VPNC.", 5) == 0) {
- if (vpnc_options[i].cm_save == FALSE)
+ if (!vpnc_options[i].cm_save)
continue;
option = vpn_provider_get_string(provider,
vpnc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -264,19 +264,20 @@ static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
static int vc_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *option;
int err = 0, fd;
option = vpn_provider_get_string(provider, "Host");
- if (option == NULL) {
+ if (!option) {
connman_error("Host not set; cannot enable VPN");
err = -EINVAL;
goto done;
}
option = vpn_provider_get_string(provider, "VPNC.IPSec.ID");
- if (option == NULL) {
+ if (!option) {
connman_error("Group not set; cannot enable VPN");
err = -EINVAL;
goto done;
@@ -292,7 +293,7 @@ static int vc_connect(struct vpn_provider *provider,
SCRIPTDIR "/openconnect-script");
option = vpn_provider_get_string(provider, "VPNC.Debug");
- if (option != NULL)
+ if (option)
connman_task_add_argument(task, "--debug", option);
connman_task_add_argument(task, "-", NULL);
@@ -310,13 +311,13 @@ static int vc_connect(struct vpn_provider *provider,
close(fd);
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int vc_error_code(int exit_code)
+static int vc_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1: