Commit a296a684 authored by Jussi Laakkonen's avatar Jussi Laakkonen

technology: Move tech value loading to separate function

[connman] Move tech value loading to separate function. Fixes JB#50601

Created new function based on technology_load() to load only the values
from the keyfile. This is required to be done also when user changes so
it is executed when the configuration for a user is being loaded. Saving
is set to be the last operation to not to clear tethering values in
settings file.

Also, the values for tethering are added to be cleared in the user
change preparation function. This eliminates the leak of other user's
tethering passwords to the next logged in one.
parent d384b9aa
......@@ -417,34 +417,25 @@ static void free_rfkill(gpointer data)
g_free(rfkill);
}
static void technology_load(struct connman_technology *technology)
static int technology_load_values(struct connman_technology *technology,
GKeyFile *keyfile)
{
GKeyFile *keyfile;
gchar *identifier;
GError *error = NULL;
bool enable, need_saving = false;
DBG("technology %p", technology);
const char *identifier;
bool enable;
bool need_saving = false;
keyfile = __connman_storage_load_global();
/* Fallback on disabling technology if file not found. */
if (!keyfile) {
if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
/* We enable ethernet by default */
technology->enable_persistent = true;
else
technology->enable_persistent = false;
return;
}
if (!technology || !keyfile)
return -EINVAL;
identifier = g_strdup_printf("%s", get_name(technology->type));
identifier = get_name(technology->type);
if (!identifier)
goto done;
return -ENOENT;
enable = g_key_file_get_boolean(keyfile, identifier, "Enable", &error);
if (!error)
if (!error) {
technology->enable_persistent = enable;
else {
} else {
if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
technology->enable_persistent = true;
else
......@@ -456,23 +447,45 @@ static void technology_load(struct connman_technology *technology)
enable = g_key_file_get_boolean(keyfile, identifier,
"Tethering", &error);
if (!error)
if (!error) {
technology->tethering_persistent = enable;
else {
} else {
need_saving = true;
g_clear_error(&error);
}
if (need_saving)
technology_save(technology);
technology->tethering_ident = g_key_file_get_string(keyfile,
identifier, "Tethering.Identifier", NULL);
technology->tethering_passphrase = g_key_file_get_string(keyfile,
identifier, "Tethering.Passphrase", NULL);
done:
g_free(identifier);
if (need_saving)
technology_save(technology);
return 0;
}
static void technology_load(struct connman_technology *technology)
{
GKeyFile *keyfile;
DBG("technology %p", technology);
keyfile = __connman_storage_load_global();
/* Fallback on disabling technology if file not found. */
if (!keyfile) {
if (technology->type == CONNMAN_SERVICE_TYPE_ETHERNET)
/* We enable ethernet by default */
technology->enable_persistent = true;
else
technology->enable_persistent = false;
return;
}
if (!technology_load_values(technology, keyfile))
DBG("Cannot load technology %p/%s keyfile %p", technology,
get_name(technology->type), keyfile);
g_key_file_unref(keyfile);
......@@ -1907,6 +1920,16 @@ bool __connman_technology_disable_all(void)
if (err != -EBUSY)
technology->enable_persistent = false;
/*
* technology_disable() will disable tethering, clean
* ident and passphrase here.
*/
g_free(technology->tethering_ident);
technology->tethering_ident = NULL;
g_free(technology->tethering_passphrase);
technology->tethering_passphrase = NULL;
DBG("result %s", err ? strerror(-err) : "ok");
}
......@@ -1918,9 +1941,7 @@ bool __connman_technology_enable_from_config()
GSList *list;
GKeyFile *keyfile;
GError *error = NULL;
const char *identifier;
bool offlinemode = false;
bool value;
int err;
keyfile = __connman_storage_load_global();
......@@ -1951,31 +1972,25 @@ bool __connman_technology_enable_from_config()
for (list = technology_list; list; list = list->next) {
struct connman_technology *technology = list->data;
identifier = get_name(technology->type);
if (!identifier)
if (!technology_load_values(technology, keyfile))
continue;
value = g_key_file_get_boolean(keyfile, identifier,
"Enable", &error);
if (error) {
value = false;
g_clear_error(&error);
}
if (technology->rfkill_driven && technology->hardblocked) {
DBG("technology %p/%s hardblocked, not set as %s",
technology, get_name(technology->type),
value ? "enabled" : "disabled");
technology->enable_persistent = value;
technology,
get_name(technology->type),
technology->enable_persistent ?
"enabled" : "disabled");
technology_save(technology);
continue;
}
DBG("technology %p/%s set as %s", technology,
get_name(technology->type),
value ? "enabled" : "disabled");
technology->enable_persistent ?
"enabled" : "disabled");
if (!value) {
if (!technology->enable_persistent) {
if (!technology->enabled) {
DBG("tech %p/%s already disabled", technology,
get_name(technology->type));
......@@ -2005,9 +2020,6 @@ bool __connman_technology_enable_from_config()
DBG("tech %p/%s not enabled in offlinemode",
technology,
get_name(technology->type));
technology->enable_persistent = value;
continue;
}
......@@ -2044,9 +2056,6 @@ bool __connman_technology_enable_from_config()
err ? strerror(-err) : "ok");
}
if (err != -EBUSY)
technology->enable_persistent = value;
technology_save(technology);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment