Chromium Code Reviews| Index: src/service.c |
| diff --git a/src/service.c b/src/service.c |
| index 8828ddf65153724e36ccbc086cff8574964c83b0..a849326c690abca2ccbd39b35a3553a1b09482c6 100644 |
| --- a/src/service.c |
| +++ b/src/service.c |
| @@ -179,6 +179,7 @@ static int security_priority[CONNMAN_SERVICE_SECURITY_MAX] = { |
| [CONNMAN_SERVICE_SECURITY_WPA] = 1, |
| [CONNMAN_SERVICE_SECURITY_RSN] = 1, |
| [CONNMAN_SERVICE_SECURITY_802_1X] = 0, |
| + [CONNMAN_SERVICE_SECURITY_PSK] = 1, |
| }; |
| static const char *__statename(enum connman_service_state state) |
| @@ -467,6 +468,8 @@ static const char *security2string(enum connman_service_security security) |
| return "rsn"; |
| case CONNMAN_SERVICE_SECURITY_802_1X: |
| return "802_1x"; |
| + case CONNMAN_SERVICE_SECURITY_PSK: |
| + return "psk"; |
| default: |
| break; |
| } |
| @@ -706,6 +709,7 @@ static connman_bool_t is_passphrase_required( |
| case CONNMAN_SERVICE_SECURITY_WEP: |
| case CONNMAN_SERVICE_SECURITY_WPA: |
| case CONNMAN_SERVICE_SECURITY_RSN: |
| + case CONNMAN_SERVICE_SECURITY_PSK: |
| if (service->passphrase == NULL) |
| return TRUE; /* must have a passphrase */ |
| if (service->favorite == TRUE) |
| @@ -1498,8 +1502,10 @@ static DBusMessage *set_property(DBusConnection *conn, |
| service->wifi.wep_key_matter) == FALSE) |
| return __connman_error_invalid_passphrase(msg); |
| - if ((service->security == CONNMAN_SERVICE_SECURITY_WPA || |
| - service->security == CONNMAN_SERVICE_SECURITY_RSN) && |
| + |
| + if ((service->security == CONNMAN_SERVICE_SECURITY_PSK || |
| + service->security == CONNMAN_SERVICE_SECURITY_RSN || |
| + service->security == CONNMAN_SERVICE_SECURITY_WPA) && |
| __connman_service_validate_passphrase(passphrase) == FALSE) |
| return __connman_error_invalid_passphrase(msg); |
| @@ -3211,6 +3217,7 @@ connman_bool_t __connman_service_check_prepared(const struct connman_service |
| case CONNMAN_SERVICE_SECURITY_WEP: |
| case CONNMAN_SERVICE_SECURITY_WPA: |
| case CONNMAN_SERVICE_SECURITY_RSN: |
| + case CONNMAN_SERVICE_SECURITY_PSK: |
| if (service->passphrase == NULL) { |
| _DBG_SERVICE("service %p missing passphrase", |
| service); |
| @@ -3408,6 +3415,13 @@ static void populate_service(char **service_property, const char *value, |
| } |
| } |
| +static inline gboolean ispsk(const char *security) |
| +{ |
| + return (g_strcmp0(security, "wpa") == 0 || |
| + g_strcmp0(security, "rsn") == 0 || |
| + g_strcmp0(security, "psk") == 0); |
| +} |
| + |
| /** |
| * __connman_get_wifi_service_int: |
| * |
| @@ -3576,9 +3590,8 @@ static DBusMessage *__connman_get_wifi_service_int(DBusMessage *msg, |
| if (g_strcmp0(security, "none") != 0 && |
| g_strcmp0(security, "wep") != 0 && |
| - g_strcmp0(security, "wpa") != 0 && |
| - g_strcmp0(security, "rsn") != 0 && |
| - g_strcmp0(security, "802_1x") != 0) { |
| + g_strcmp0(security, "802_1x") != 0 && |
| + !ispsk(security)) { |
| connman_error("%s: invalid security %s", __func__, security); |
| return __connman_error_invalid_arguments(msg); |
| } |
| @@ -3593,8 +3606,7 @@ static DBusMessage *__connman_get_wifi_service_int(DBusMessage *msg, |
| wep_key_idx = u8_idx; |
| } |
| - if ((g_strcmp0(security, "wpa") == 0 || |
| - g_strcmp0(security, "rsn") == 0) && passphrase != NULL && |
| + if (ispsk(security) && passphrase != NULL && |
| __connman_service_validate_passphrase(passphrase) == FALSE) |
| return __connman_error_invalid_passphrase(msg); |
| @@ -3610,8 +3622,8 @@ static DBusMessage *__connman_get_wifi_service_int(DBusMessage *msg, |
| return __connman_error_invalid_arguments(msg); |
| } |
| - group = connman_wifi_build_group_name((unsigned char *) ssid, |
| - ssid_len, mode, security); |
| + group = connman_wifi_build_group_name((unsigned char *) ssid, ssid_len, |
| + mode, security); |
| if (group == NULL) { |
| connman_error("%s: cannot build group name", __func__); |
| return __connman_error_invalid_arguments(msg); |
| @@ -4156,6 +4168,8 @@ static enum connman_service_mode convert_wifi_security(const char *security) |
| return CONNMAN_SERVICE_SECURITY_NONE; |
| else if (g_str_equal(security, "wep") == TRUE) |
| return CONNMAN_SERVICE_SECURITY_WEP; |
| + else if (g_str_equal(security, "psk") == TRUE) |
| + return CONNMAN_SERVICE_SECURITY_PSK; |
| else if (g_str_equal(security, "wpa") == TRUE) |
| return CONNMAN_SERVICE_SECURITY_WPA; |
| else if (g_str_equal(security, "rsn") == TRUE) |
| @@ -4502,9 +4516,28 @@ static void populate_service_from_keyfile(GKeyFile *keyfile, |
| } |
| } |
| +/* |
| + * Construct old-style entries for wpa/rsn services. |
| + */ |
| +static char *__old_security(GKeyFile *keyfile, |
| + const struct connman_service *service) |
| +{ |
| + char *group = NULL; |
| + |
|
Paul Stewart
2011/03/03 19:55:04
I suggest a test (perhaps not an assert) that
g_st
|
| + if (service->security == CONNMAN_SERVICE_SECURITY_WPA) { |
| + group = g_strdup(service->identifier); |
| + g_strlcpy(group + strlen(group) - 3, "wpa", 4); |
| + } else if (service->security == CONNMAN_SERVICE_SECURITY_RSN) { |
| + group = g_strdup(service->identifier); |
| + g_strlcpy(group + strlen(group) - 3, "rsn", 4); |
| + } |
| + return group; |
| +} |
| + |
| static int service_load(struct connman_service *service) |
| { |
| const char *ident = service->profile; |
| + const char *group = service->identifier; |
| GKeyFile *keyfile; |
| GError *error = NULL; |
| gchar *pathname, *data = NULL; |
| @@ -4541,6 +4574,17 @@ static int service_load(struct connman_service *service) |
| g_free(data); |
| + /* |
| + * Handle upgrade of old-style entries for wpa/rsn services. |
| + */ |
| + if (g_key_file_has_group(keyfile, group) == FALSE) { |
| + char *old_group = __old_security(keyfile, service); |
| + if (old_group != NULL) { |
| + _DBG_SERVICE("check old entry %s", old_group); |
| + group = old_group; |
| + } |
| + } |
| + |
| switch (service->type) { |
| case CONNMAN_SERVICE_TYPE_UNKNOWN: |
| case CONNMAN_SERVICE_TYPE_ETHERNET: |
| @@ -4548,11 +4592,11 @@ static int service_load(struct connman_service *service) |
| break; |
| case CONNMAN_SERVICE_TYPE_WIFI: |
| service->wifi.hidden_ssid = g_key_file_get_boolean(keyfile, |
| - service->identifier, "WiFi.HiddenSSID", NULL); |
| + group, "WiFi.HiddenSSID", NULL); |
| if (service->name == NULL) { |
| service->name = g_key_file_get_string(keyfile, |
| - service->identifier, "Name", NULL); |
| + group, "Name", NULL); |
| if (service->network != NULL && service->name != NULL) |
| connman_network_set_name(service->network, |
| @@ -4565,8 +4609,7 @@ static int service_load(struct connman_service *service) |
| gchar *hex_ssid; |
| hex_ssid = g_key_file_get_string(keyfile, |
| - service->identifier, |
| - "SSID", NULL); |
| + group, "SSID", NULL); |
| if (hex_ssid != NULL) { |
| struct blob *ssid; |
| @@ -4588,8 +4631,7 @@ static int service_load(struct connman_service *service) |
| case CONNMAN_SERVICE_TYPE_WIMAX: |
| case CONNMAN_SERVICE_TYPE_BLUETOOTH: |
| str = g_key_file_get_string(keyfile, |
| - service->identifier, |
| - "Failure", NULL); |
| + group, "Failure", NULL); |
| if (str != NULL) { |
| service->error = string2error(str); |
| state_change(service, |
| @@ -4600,10 +4642,10 @@ static int service_load(struct connman_service *service) |
| case CONNMAN_SERVICE_TYPE_CELLULAR: |
| service->favorite = g_key_file_get_boolean(keyfile, |
| - service->identifier, "Favorite", NULL); |
| + group, "Favorite", NULL); |
| autoconnect = g_key_file_get_boolean(keyfile, |
| - service->identifier, "AutoConnect", &error); |
| + group, "AutoConnect", &error); |
| if (error == NULL) |
| service->autoconnect = autoconnect; |
| g_clear_error(&error); |
| @@ -4613,21 +4655,21 @@ static int service_load(struct connman_service *service) |
| } |
| str = g_key_file_get_string(keyfile, |
| - service->identifier, "Modified", NULL); |
| + group, "Modified", NULL); |
| if (str != NULL) { |
| g_time_val_from_iso8601(str, &service->modified); |
| g_free(str); |
| } |
| str = g_key_file_get_string(keyfile, |
| - service->identifier, "LastAttempt", NULL); |
| + group, "LastAttempt", NULL); |
| if (str != NULL) { |
| g_time_val_from_iso8601(str, &service->last_attempt); |
| g_free(str); |
| } |
| str = __connman_storage_get_encrypted_value(keyfile, service->profile, |
| - service->identifier, "Passphrase"); |
| + group, "Passphrase"); |
| if (str != NULL) { |
| connman_bool_t valid_pass = TRUE; |
| g_free(service->passphrase); |
| @@ -4642,6 +4684,7 @@ static int service_load(struct connman_service *service) |
| break; |
| case CONNMAN_SERVICE_SECURITY_WPA: |
| case CONNMAN_SERVICE_SECURITY_RSN: |
| + case CONNMAN_SERVICE_SECURITY_PSK: |
| valid_pass = __connman_service_validate_passphrase(str); |
| break; |
| default: |
| @@ -4683,14 +4726,14 @@ static int service_load(struct connman_service *service) |
| kEAPKeyMgmt, &service->eap.key_mgmt); |
| str = g_key_file_get_string(keyfile, |
| - service->identifier, "ProxyConfig", NULL); |
| + group, "ProxyConfig", NULL); |
| if (str != NULL) { |
| g_free(service->proxy_config); |
| service->proxy_config = str; |
| } |
| pri = g_key_file_get_integer(keyfile, |
| - service->identifier, "Priority", &error); |
| + group, "Priority", &error); |
| if (error == NULL) |
| service->pri = pri; |
| @@ -4700,16 +4743,16 @@ static int service_load(struct connman_service *service) |
| g_free(apn->password); |
| g_free(apn->network_id); |
| apn->apn = g_key_file_get_string(keyfile, |
| - service->identifier, "Cellular.APN.apn", NULL); |
| + group, "Cellular.APN.apn", NULL); |
| if (apn->apn != NULL) { |
| apn->username = g_key_file_get_string(keyfile, |
| - service->identifier, |
| + group, |
| "Cellular.APN.username", NULL); |
| apn->password = g_key_file_get_string(keyfile, |
| - service->identifier, |
| + group, |
| "Cellular.APN.password", NULL); |
| apn->network_id = g_key_file_get_string(keyfile, |
| - service->identifier, |
| + group, |
| "Cellular.APN.network_id", NULL); |
| } else { |
| apn->username = NULL; |
| @@ -4719,6 +4762,9 @@ static int service_load(struct connman_service *service) |
| done: |
| g_key_file_free(keyfile); |
| + if (group != service->identifier) |
| + g_free((char *)group); |
| + |
| return err; |
| } |