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,
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);
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);
{
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)
{
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);
}
if (old_state != 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)
{
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);
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);
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) {
} 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,
}
}
-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;