struct vpn_setting {
gboolean hide_value;
+ gboolean immutable;
char *value;
};
guint notify_id;
char *config_file;
char *config_entry;
+ connman_bool_t immutable;
};
+static void append_properties(DBusMessageIter *iter,
+ struct vpn_provider *provider);
+
static void free_route(gpointer data)
{
struct vpn_route *route = data;
provider);
}
+static DBusMessage *get_properties(DBusConnection *conn,
+ DBusMessage *msg, void *data)
+{
+ struct vpn_provider *provider = data;
+ DBusMessage *reply;
+ DBusMessageIter array;
+
+ DBG("provider %p", provider);
+
+ reply = dbus_message_new_method_return(msg);
+ if (reply == NULL)
+ return NULL;
+
+ dbus_message_iter_init_append(reply, &array);
+
+ append_properties(&array, provider);
+
+ return reply;
+}
+
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
void *data)
{
DBG("conn %p", conn);
+ if (provider->immutable == TRUE)
+ return __connman_error_not_supported(msg);
+
if (dbus_message_iter_init(msg, &iter) == FALSE)
return __connman_error_invalid_arguments(msg);
send_routes(provider, provider->user_routes,
"UserRoutes");
}
- } else
- return __connman_error_invalid_property(msg);
+ } else {
+ const char *str;
+
+ dbus_message_iter_get_basic(&value, &str);
+ vpn_provider_set_string(provider, name, str);
+ }
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
}
DBG("conn %p", conn);
+ if (provider->immutable == TRUE)
+ return __connman_error_not_supported(msg);
+
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
if (handle_routes == FALSE)
send_routes(provider, provider->user_routes, name);
+ } else if (vpn_provider_get_string(provider, name) != NULL) {
+ vpn_provider_set_string(provider, name, NULL);
} else {
return __connman_error_invalid_property(msg);
}
}
static const GDBusMethodTable connection_methods[] = {
+ { GDBUS_METHOD("GetProperties",
+ NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
+ get_properties) },
{ GDBUS_METHOD("SetProperty",
GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
NULL, set_property) },
{
GKeyFile *keyfile;
- DBG("provider %p", provider);
+ DBG("provider %p immutable %s", provider,
+ provider->immutable ? "yes" : "no");
+
+ if (provider->immutable == TRUE) {
+ /*
+ * Do not save providers that are provisioned via .config
+ * file.
+ */
+ return -EPERM;
+ }
keyfile = g_key_file_new();
if (keyfile == NULL)
if (__sync_fetch_and_sub(&configuration_count, 1) != 1)
return;
-
- raise(SIGTERM);
}
int __vpn_provider_disconnect(struct vpn_provider *provider)
return NULL;
}
+static void append_nameservers(DBusMessageIter *iter, char **servers)
+{
+ int i;
+
+ DBG("%p", servers);
+
+ for (i = 0; servers[i] != NULL; i++) {
+ DBG("servers[%d] %s", i, servers[i]);
+ dbus_message_iter_append_basic(iter,
+ DBUS_TYPE_STRING, &servers[i]);
+ }
+}
+
+static void append_dns(DBusMessageIter *iter, void *user_data)
+{
+ struct vpn_provider *provider = user_data;
+
+ if (provider->nameservers != NULL)
+ append_nameservers(iter, provider->nameservers);
+}
+
static int provider_indicate_state(struct vpn_provider *provider,
enum vpn_provider_state state)
{
const char *str;
+ enum vpn_provider_state old_state;
str = state2string(state);
DBG("provider %p state %s/%d", provider, str, state);
if (str == NULL)
return -EINVAL;
+ old_state = provider->state;
provider->state = state;
if (state == VPN_PROVIDER_STATE_READY) {
connman_dbus_property_changed_dict(provider->path,
VPN_CONNECTION_INTERFACE, "IPv6",
append_ipv6, provider);
+
+ connman_dbus_property_changed_array(provider->path,
+ VPN_CONNECTION_INTERFACE,
+ "Nameservers",
+ DBUS_TYPE_STRING,
+ append_dns, provider);
+
+ if (provider->domain != NULL)
+ connman_dbus_property_changed_basic(provider->path,
+ VPN_CONNECTION_INTERFACE,
+ "Domain",
+ DBUS_TYPE_STRING,
+ &provider->domain);
}
- connman_dbus_property_changed_basic(provider->path,
+ if (old_state != state)
+ connman_dbus_property_changed_basic(provider->path,
VPN_CONNECTION_INTERFACE, "State",
DBUS_TYPE_STRING, &str);
+
/*
* We do not stay in failure state as clients like connmand can
* get confused about our current state.
return 0;
}
-static void append_nameservers(DBusMessageIter *iter, char **servers)
-{
- int i;
-
- DBG("%p", servers);
-
- for (i = 0; servers[i] != NULL; i++) {
- DBG("servers[%d] %s", i, servers[i]);
- dbus_message_iter_append_basic(iter,
- DBUS_TYPE_STRING, &servers[i]);
- }
-}
-
-static void append_dns(DBusMessageIter *iter, void *user_data)
-{
- struct vpn_provider *provider = user_data;
-
- if (provider->nameservers != NULL)
- append_nameservers(iter, provider->nameservers);
-}
-
static void append_state(DBusMessageIter *iter,
struct vpn_provider *provider)
{
struct vpn_provider *provider)
{
DBusMessageIter dict;
+ GHashTableIter hash;
+ gpointer value, key;
connman_dbus_dict_open(iter, &dict);
connman_dbus_dict_append_basic(&dict, "Domain",
DBUS_TYPE_STRING, &provider->domain);
+ connman_dbus_dict_append_basic(&dict, "Immutable", DBUS_TYPE_BOOLEAN,
+ &provider->immutable);
+
if (provider->family == AF_INET)
connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4,
provider);
DBUS_TYPE_DICT_ENTRY, append_routes,
provider->routes);
+ if (provider->setting_strings != NULL) {
+ g_hash_table_iter_init(&hash, provider->setting_strings);
+
+ while (g_hash_table_iter_next(&hash, &key, &value) == TRUE) {
+ struct vpn_setting *setting = value;
+
+ if (setting->hide_value == FALSE &&
+ setting->value != NULL)
+ connman_dbus_dict_append_basic(&dict, key,
+ DBUS_TYPE_STRING,
+ &setting->value);
+ }
+ }
+
connman_dbus_dict_close(iter, &dict);
}
provider->type = NULL;
provider->domain = NULL;
provider->identifier = NULL;
+ provider->immutable = FALSE;
provider->user_networks = NULL;
provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, free_route);
dbus_message_iter_get_basic(&value, &name);
else if (g_str_equal(key, "Host") == TRUE)
dbus_message_iter_get_basic(&value, &host);
- else if (g_str_equal(key, "VPN.Domain") == TRUE)
+ else if (g_str_equal(key, "VPN.Domain") == TRUE ||
+ g_str_equal(key, "Domain") == TRUE)
dbus_message_iter_get_basic(&value, &domain);
break;
case DBUS_TYPE_ARRAY:
static GSList *parse_user_networks(const char *network_str)
{
GSList *networks = NULL;
- char **elems = g_strsplit(network_str, ",", 0);
+ char **elems;
int i = 0;
+ if (network_str == NULL)
+ return NULL;
+
+ elems = g_strsplit(network_str, ",", 0);
if (elems == NULL)
return NULL;
provider->config_file = g_strdup(config_ident);
provider->config_entry = g_strdup(config_entry);
- if (provider_register(provider) == 0)
- vpn_provider_load(provider);
+ provider_register(provider);
provider_resolv_host_addr(provider);
}
g_hash_table_iter_init(&hash, settings);
while (g_hash_table_iter_next(&hash, &key, &value) == TRUE)
- vpn_provider_set_string(provider, key, value);
+ __vpn_provider_set_string_immutable(provider, key, value);
+
+ provider->immutable = TRUE;
vpn_provider_save(provider);
}
static int set_string(struct vpn_provider *provider,
- const char *key, const char *value, gboolean hide_value)
+ const char *key, const char *value,
+ gboolean hide_value, gboolean immutable)
{
- DBG("provider %p key %s value %s", provider, key,
+ DBG("provider %p key %s immutable %s value %s", provider, key,
+ immutable ? "yes" : "no",
hide_value ? "<not printed>" : value);
if (g_str_equal(key, "Type") == TRUE) {
g_free(provider->host);
provider->host = g_strdup(value);
send_value(provider->path, "Host", provider->host);
- } else if (g_str_equal(key, "VPN.Domain") == TRUE) {
+ } else if (g_str_equal(key, "VPN.Domain") == TRUE ||
+ g_str_equal(key, "Domain") == TRUE) {
g_free(provider->domain);
provider->domain = g_strdup(value);
send_value(provider->path, "Domain", provider->domain);
} else {
struct vpn_setting *setting;
- setting = g_try_new(struct vpn_setting, 1);
+ setting = g_hash_table_lookup(provider->setting_strings, key);
+ if (setting != NULL && immutable == FALSE &&
+ setting->immutable == TRUE) {
+ DBG("Trying to set immutable variable %s", key);
+ return -EPERM;
+ }
+
+ setting = g_try_new0(struct vpn_setting, 1);
if (setting == NULL)
return -ENOMEM;
setting->value = g_strdup(value);
setting->hide_value = hide_value;
+ if (immutable == TRUE)
+ setting->immutable = TRUE;
+
if (hide_value == FALSE)
send_value(provider->path, key, setting->value);
int vpn_provider_set_string(struct vpn_provider *provider,
const char *key, const char *value)
{
- return set_string(provider, key, value, FALSE);
+ return set_string(provider, key, value, FALSE, FALSE);
}
int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
const char *key, const char *value)
{
- return set_string(provider, key, value, TRUE);
+ return set_string(provider, key, value, TRUE, FALSE);
+}
+
+int __vpn_provider_set_string_immutable(struct vpn_provider *provider,
+ const char *key, const char *value)
+{
+ return set_string(provider, key, value, FALSE, TRUE);
}
const char *vpn_provider_get_string(struct vpn_provider *provider,
return provider->host;
else
return provider->host_ip[0];
- } else if (g_str_equal(key, "VPN.Domain") == TRUE)
+ } else if (g_str_equal(key, "VPN.Domain") == TRUE ||
+ g_str_equal(key, "Domain") == TRUE)
return provider->domain;
setting = g_hash_table_lookup(provider->setting_strings, key);
}
}
-static gboolean check_vpn_count(gpointer data)
-{
- if (configuration_count == 0) {
- connman_info("No VPN configurations found, quitting.");
- raise(SIGTERM);
- }
-
- return FALSE;
-}
-
-void __vpn_provider_check_connections(void)
-{
- /*
- * If we were started when there is no providers configured,
- * then just quit. This happens when connman starts and its
- * vpn plugin asks connman-vpnd if it has any connections
- * configured. If there are none, then we can stop the vpn
- * daemon.
- */
- g_timeout_add(1000, check_vpn_count, NULL);
-}
-
const char *vpn_provider_get_name(struct vpn_provider *provider)
{
return provider->name;