network: Avoid connection to a network with invalid key
authorJulien Massot <jmassot@aldebaran-robotics.com>
Fri, 13 Apr 2012 15:16:32 +0000 (15:16 +0000)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 17 Apr 2012 10:37:13 +0000 (13:37 +0300)
src/network.c
src/service.c

index 4664ea5..5078fd1 100644 (file)
@@ -1400,6 +1400,7 @@ connman_bool_t connman_network_get_associating(struct connman_network *network)
 int connman_network_connect_hidden(struct connman_network *network,
                                char *identity, char* passphrase)
 {
+       int err = 0;
        struct connman_service *service;
 
        DBG("");
@@ -1412,9 +1413,14 @@ int connman_network_connect_hidden(struct connman_network *network,
                __connman_service_set_agent_identity(service, identity);
 
        if (passphrase != NULL)
-               __connman_service_add_passphrase(service, passphrase);
+               err = __connman_service_add_passphrase(service, passphrase);
 
-       return __connman_service_connect(service);
+       if (err == -ENOKEY) {
+               __connman_service_indicate_error(service,
+                                       CONNMAN_SERVICE_ERROR_INVALID_KEY);
+               return err;
+       } else
+               return __connman_service_connect(service);
 }
 
 /**
index e1286b8..df86ce5 100644 (file)
@@ -4284,6 +4284,7 @@ static void request_input_cb (struct connman_service *service,
                        void *user_data)
 {
        struct connman_device *device;
+       int err = 0;
 
        DBG ("RequestInput return, %p", service);
 
@@ -4305,13 +4306,21 @@ static void request_input_cb (struct connman_service *service,
                __connman_service_set_agent_identity(service, identity);
 
        if (passphrase != NULL)
-               __connman_service_add_passphrase(service, passphrase);
+               err = __connman_service_add_passphrase(service, passphrase);
 
-       __connman_service_connect(service);
+       if (err >= 0) {
+               __connman_service_connect(service);
 
-       /* Never cache agent provided credentials */
-       __connman_service_set_agent_identity(service, NULL);
-       __connman_service_set_agent_passphrase(service, NULL);
+               /* Never cache agent provided credentials */
+               __connman_service_set_agent_identity(service, NULL);
+               __connman_service_set_agent_passphrase(service, NULL);
+       } else if (err == -ENOKEY) {
+               __connman_service_indicate_error(service,
+                                       CONNMAN_SERVICE_ERROR_INVALID_KEY);
+               __connman_agent_report_error(service,
+                                       error2string(service->error),
+                                       report_error_cb, NULL);
+       }
 }
 
 static void downgrade_connected_services(void)