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 | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 91 insertions(+), 14 deletions(-)
diff --git a/src/config.c b/src/config.c
index bdbb704..0d69017 100644
--- a/src/config.c
+++ b/src/config.c
@@ -56,6 +56,45 @@ struct connman_config {
static GHashTable *config_table = NULL;
+/* Definition of possible strings in the .config files */
+#define CONFIG_KEY_NAME "Name"
+#define CONFIG_KEY_DESC "Description"
+
+#define SERVICE_KEY_TYPE "Type"
+#define SERVICE_KEY_NAME "Name"
+#define SERVICE_KEY_SSID "SSID"
+#define SERVICE_KEY_EAP "EAP"
+#define SERVICE_KEY_CA_CERT "CACertFile"
+#define SERVICE_KEY_CL_CERT "ClientCertFile"
+#define SERVICE_KEY_PRV_KEY "PrivateKeyFile"
+#define SERVICE_KEY_PRV_KEY_PASS "PrivateKeyPassphrase"
+#define SERVICE_KEY_PRV_KEY_PASS_TYPE "PrivateKeyPassphraseType"
+#define SERVICE_KEY_IDENTITY "Identity"
+#define SERVICE_KEY_PHASE2 "Phase2"
+#define SERVICE_KEY_PASSPHRASE "Passphrase"
+
+gchar *config_possible_keys[] = {
+ CONFIG_KEY_NAME,
+ CONFIG_KEY_DESC,
+ NULL,
+};
+
+gchar *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;
@@ -92,6 +131,36 @@ static void unregister_service(gpointer data)
g_free(service);
}
+void check_keys(GKeyFile *keyfile, const char *group, gchar **possible_keys)
+{
+ gchar **avail_keys = NULL;
+ gsize nb_avail_keys;
+ int index_avail, index_possible;
+ GError *error = NULL;
+
+ avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys,
+ &error);
+ if (error) {
+ connman_warn("Unable to check keys validity for [%s]", group);
+ return;
+ }
+
+ for (index_avail = 0 ; index_avail < nb_avail_keys; index_avail++) {
+ for (index_possible = 0; possible_keys[index_possible] ;
+ index_possible++) {
+ if (g_strcmp0(avail_keys[index_avail],
+ possible_keys[index_possible]) == 0)
+ break;
+ }
+
+ if (possible_keys[index_possible] == NULL)
+ connman_warn("Unknown configuration key %s in [%s]",
+ avail_keys[index_avail], group);
+ }
+
+ g_strfreev(avail_keys);
+}
+
static int load_service(GKeyFile *keyfile, const char *group,
struct connman_config *config)
{
@@ -105,6 +174,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);
@@ -114,19 +186,20 @@ static int load_service(GKeyFile *keyfile, const char
*group,
service->ident = g_strdup(ident);
}
- str = g_key_file_get_string(keyfile, group, "Type", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_TYPE, NULL);
if (str != NULL) {
g_free(service->type);
service->type = str;
}
- str = g_key_file_get_string(keyfile, group, "Name", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_NAME, NULL);
if (str != NULL) {
g_free(service->name);
service->name = str;
}
- hex_ssid = g_key_file_get_string(keyfile, group, "SSID", NULL);
+ hex_ssid = g_key_file_get_string(keyfile, group, SERVICE_KEY_SSID,
+ NULL);
if (hex_ssid != NULL) {
char *ssid;
unsigned int i, j = 0, hex;
@@ -163,57 +236,58 @@ static int load_service(GKeyFile *keyfile, const char
*group,
service->ssid_len = ssid_len;
}
- str = g_key_file_get_string(keyfile, group, "EAP", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_EAP, NULL);
if (str != NULL) {
g_free(service->eap);
service->eap = str;
}
- str = g_key_file_get_string(keyfile, group, "CACertFile", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CA_CERT, NULL);
if (str != NULL) {
g_free(service->ca_cert_file);
service->ca_cert_file = str;
}
- str = g_key_file_get_string(keyfile, group, "ClientCertFile", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_CL_CERT, NULL);
if (str != NULL) {
g_free(service->client_cert_file);
service->client_cert_file = str;
}
- str = g_key_file_get_string(keyfile, group, "PrivateKeyFile", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PRV_KEY, NULL);
if (str != NULL) {
g_free(service->private_key_file);
service->private_key_file = str;
}
str = g_key_file_get_string(keyfile, group,
- "PrivateKeyPassphrase", NULL);
+ SERVICE_KEY_PRV_KEY_PASS, NULL);
if (str != NULL) {
g_free(service->private_key_passphrase);
service->private_key_passphrase = str;
}
str = g_key_file_get_string(keyfile, group,
- "PrivateKeyPassphraseType", NULL);
+ SERVICE_KEY_PRV_KEY_PASS_TYPE, NULL);
if (str != NULL) {
g_free(service->private_key_passphrase_type);
service->private_key_passphrase_type = str;
}
- str = g_key_file_get_string(keyfile, group, "Identity", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_IDENTITY, NULL);
if (str != NULL) {
g_free(service->identity);
service->identity = str;
}
- str = g_key_file_get_string(keyfile, group, "Phase2", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PHASE2, NULL);
if (str != NULL) {
g_free(service->phase2);
service->phase2 = str;
}
- str = g_key_file_get_string(keyfile, group, "Passphrase", NULL);
+ str = g_key_file_get_string(keyfile, group, SERVICE_KEY_PASSPHRASE,
+ NULL);
if (str != NULL) {
g_free(service->passphrase);
service->passphrase = str;
@@ -240,13 +314,16 @@ static int load_config(struct connman_config *config)
if (keyfile == NULL)
return -EIO;
- str = g_key_file_get_string(keyfile, "global", "Name", NULL);
+ /* 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);
config->name = str;
}
- str = g_key_file_get_string(keyfile, "global", "Description", NULL);
+ str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
if (str != NULL) {
g_free(config->description);
config->description = str;
--
1.7.0.4
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number: 302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman