From 44e1cacbcf1e6a93b0f942ccc4079ca08d466116 Mon Sep 17 00:00:00 2001 From: Fabien Marotte Date: Wed, 15 Sep 2010 11:51:11 +0200 Subject: [PATCH] Add verification of the .config file parameters Connman reads the *.config files in STORAGE_DIR during its boot but it looks only for parameters it is interrested in. The configuration parameters syntax is complex and it is very simple to make a mistake without getting connman warnings. This leads the user to think that connman understands the configuration file although it doesn't. This patch is the code that adds warnings to the logs if connman reads unknown parameters from the *.config files. --- src/config.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/config.c b/src/config.c index 498c97a..d203935 100644 --- a/src/config.c +++ b/src/config.c @@ -73,6 +73,28 @@ static GHashTable *config_table = NULL; #define SERVICE_KEY_PHASE2 "Phase2" #define SERVICE_KEY_PASSPHRASE "Passphrase" +static const char *config_possible_keys[] = { + CONFIG_KEY_NAME, + CONFIG_KEY_DESC, + NULL, +}; + +static const char *service_possible_keys[] = { + SERVICE_KEY_TYPE, + SERVICE_KEY_NAME, + SERVICE_KEY_SSID, + SERVICE_KEY_EAP, + SERVICE_KEY_CA_CERT, + SERVICE_KEY_CL_CERT, + SERVICE_KEY_PRV_KEY, + SERVICE_KEY_PRV_KEY_PASS, + SERVICE_KEY_PRV_KEY_PASS_TYPE, + SERVICE_KEY_IDENTITY, + SERVICE_KEY_PHASE2, + SERVICE_KEY_PASSPHRASE, + NULL, +}; + static void unregister_config(gpointer data) { struct connman_config *config = data; @@ -109,6 +131,33 @@ static void unregister_service(gpointer data) g_free(service); } +static void check_keys(GKeyFile *keyfile, const char *group, + const char **possible_keys) +{ + char **avail_keys; + gsize nb_avail_keys, i, j; + + avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL); + if (avail_keys == NULL) + return; + + /* + * For each key in the configuration file, + * verify it is understood by connman + */ + for (i = 0 ; i < nb_avail_keys; i++) { + for (j = 0; possible_keys[j] ; j++) + if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0) + break; + + if (possible_keys[j] == NULL) + connman_warn("Unknown configuration key %s in [%s]", + avail_keys[i], group); + } + + g_strfreev(avail_keys); +} + static int load_service(GKeyFile *keyfile, const char *group, struct connman_config *config) { @@ -122,6 +171,9 @@ static int load_service(GKeyFile *keyfile, const char *group, if (strlen(ident) < 1) return -EINVAL; + /* Verify that provided keys are good */ + check_keys(keyfile, group, service_possible_keys); + service = g_hash_table_lookup(config->service_table, ident); if (service == NULL) { service = g_try_new0(struct connman_config_service, 1); @@ -259,6 +311,9 @@ static int load_config(struct connman_config *config) if (keyfile == NULL) return -EIO; + /* Verify keys validity of the global section */ + check_keys(keyfile, "global", config_possible_keys); + str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL); if (str != NULL) { g_free(config->name); -- 2.7.4