Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: src/service.c

Issue 6659006: flimflam: add support for multiple profiles (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/flimflam.git@master
Patch Set: rebase Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« src/profile.c ('K') | « src/profile.c ('k') | src/storage.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * 2 *
3 * Connection Manager 3 * Connection Manager
4 * 4 *
5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 * 10 *
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 char *private_key_passwd; 89 char *private_key_passwd;
90 char *key_id; 90 char *key_id;
91 char *ca_cert; /* formerly authpath */ 91 char *ca_cert; /* formerly authpath */
92 char *ca_cert_id; 92 char *ca_cert_id;
93 connman_bool_t use_system_cas; 93 connman_bool_t use_system_cas;
94 char *pin; 94 char *pin;
95 char *password; 95 char *password;
96 char *key_mgmt; 96 char *key_mgmt;
97 } eap; 97 } eap;
98 98
99 » char *profile; 99 » const struct connman_storage_ident *profile;
100 char *proxy_config; 100 char *proxy_config;
101 101
102 /* TODO(sleffler) overlay storage */ 102 /* TODO(sleffler) overlay storage */
103 struct { 103 struct {
104 char *operator_name; 104 char *operator_name;
105 char *operator_code; 105 char *operator_code;
106 char *olp_url; 106 char *olp_url;
107 char *usage_url; 107 char *usage_url;
108 enum connman_network_activation_state activation_state; 108 enum connman_network_activation_state activation_state;
109 enum connman_network_cellular_technology network_technology; 109 enum connman_network_cellular_technology network_technology;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 static const char* kEAPPrivateKey = "EAP.PrivateKey"; 209 static const char* kEAPPrivateKey = "EAP.PrivateKey";
210 static const char* kEAPPrivateKeyPassword = "EAP.PrivateKeyPassword"; 210 static const char* kEAPPrivateKeyPassword = "EAP.PrivateKeyPassword";
211 static const char* kEAPKeyID = "EAP.KeyID"; 211 static const char* kEAPKeyID = "EAP.KeyID";
212 static const char* kEAPCACert = "EAP.CACert"; 212 static const char* kEAPCACert = "EAP.CACert";
213 static const char* kEAPCACertID = "EAP.CACertID"; 213 static const char* kEAPCACertID = "EAP.CACertID";
214 static const char* kEAPUseSystemCAs = "EAP.UseSystemCAs"; 214 static const char* kEAPUseSystemCAs = "EAP.UseSystemCAs";
215 static const char* kEAPPIN = "EAP.PIN"; 215 static const char* kEAPPIN = "EAP.PIN";
216 static const char* kEAPPassword = "EAP.Password"; 216 static const char* kEAPPassword = "EAP.Password";
217 static const char* kEAPKeyMgmt = "EAP.KeyMgmt"; 217 static const char* kEAPKeyMgmt = "EAP.KeyMgmt";
218 218
219 static void service_clear_passphrase(struct connman_service *service);
219 static void service_modified(struct connman_service *service); 220 static void service_modified(struct connman_service *service);
221 static void service_clear_eap(struct connman_service *service);
220 static void __service_resort(struct connman_service *service); 222 static void __service_resort(struct connman_service *service);
223 static void set_reconnect_state(struct connman_service *service,
224 connman_bool_t onoff);
221 225
222 static connman_bool_t is_timeset(const GTimeVal *tv) 226 static connman_bool_t is_timeset(const GTimeVal *tv)
223 { 227 {
224 return !(tv->tv_sec == 0 && tv->tv_usec == 0); 228 return !(tv->tv_sec == 0 && tv->tv_usec == 0);
225 } 229 }
226 230
227 static void append_path(gpointer value, gpointer user_data) 231 static void append_path(gpointer value, gpointer user_data)
228 { 232 {
229 struct connman_service *service = value; 233 struct connman_service *service = value;
230 DBusMessageIter *iter = user_data; 234 DBusMessageIter *iter = user_data;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 { 389 {
386 struct find_data data = { .path = path, .service = NULL }; 390 struct find_data data = { .path = path, .service = NULL };
387 391
388 _DBG_SERVICE("path %s", path); 392 _DBG_SERVICE("path %s", path);
389 393
390 g_sequence_foreach(service_list, compare_path, &data); 394 g_sequence_foreach(service_list, compare_path, &data);
391 395
392 return data.service; 396 return data.service;
393 } 397 }
394 398
399 static void invalidate_profile(gpointer value, gpointer user_data)
400 {
401 struct connman_service *service = value;
402 const struct connman_storage_ident *profile = user_data;
403
404 if (service->profile == profile) {
405 /*
406 * Invalidate profile-related data and force a re-load
407 * the next time the service is to be used (so it can
408 * come from the active profile).
409 */
410 service->profile = NULL;
411
412 /*
413 * network_disconnect may drop the last reference to the
414 * service and cause it to be freed, so take a reference
415 * temporarily until we are done with it.
416 */
417 connman_service_ref(service);
418 /* TODO(sleffler) skip wired ethernet, open auth? */
419 __connman_service_disconnect(service);
420 service_clear_passphrase(service);
421 service_clear_eap(service);
422 connman_service_unref(service);
423 }
424 }
425
426 void __connman_service_invalidate_profile(const struct connman_storage_ident *id ent)
427 {
428 _DBG_SERVICE("ident %s/%s", ident->user, ident->ident);
429
430 g_sequence_foreach(service_list, invalidate_profile, (gpointer) ident);
431 }
432
395 static const char *identifier(struct connman_service *service) 433 static const char *identifier(struct connman_service *service)
396 { 434 {
397 return service ? service->identifier : "<nil>"; 435 return service ? service->identifier : "<nil>";
398 } 436 }
399 437
400 static const char *type2string(enum connman_service_type type) 438 static const char *type2string(enum connman_service_type type)
401 { 439 {
402 switch (type) { 440 switch (type) {
403 case CONNMAN_SERVICE_TYPE_UNKNOWN: 441 case CONNMAN_SERVICE_TYPE_UNKNOWN:
404 break; 442 break;
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 } 792 }
755 793
756 static void hidden_ssid_changed(struct connman_service *service) 794 static void hidden_ssid_changed(struct connman_service *service)
757 { 795 {
758 if (service->path != NULL) 796 if (service->path != NULL)
759 connman_dbus_send_property_changed_variant(service->path, 797 connman_dbus_send_property_changed_variant(service->path,
760 CONNMAN_SERVICE_INTERFACE, "WiFi.HiddenSSID", 798 CONNMAN_SERVICE_INTERFACE, "WiFi.HiddenSSID",
761 DBUS_TYPE_BOOLEAN, &service->wifi.hidden_ssid); 799 DBUS_TYPE_BOOLEAN, &service->wifi.hidden_ssid);
762 } 800 }
763 801
764 /**
765 * connman_service_append_hidden_ssids:
766 * @hidden_ssids: pointer to a list of hidden SSIDs
767 *
768 * Append the list of SSIDs whose services whose WiFi.HiddenSSID property is
769 * TRUE. These SSIDs should be directly probed whenever performing a WiFi
770 * network scan.
771 *
772 * Return -EINVAL if profile could not be parsed cleanly
773 */
774 int connman_service_append_hidden_ssids(GSList **hidden_ssids)
775 {
776 const char *ident = __connman_profile_active_ident();
777 GKeyFile *keyfile;
778 gchar **keys;
779 int ret = 0;
780
781 _DBG_SERVICE("ident %s", ident);
782
783 keyfile = __connman_storage_open(ident);
784 if (keyfile == NULL)
785 return -EINVAL;
786
787 keys = g_key_file_get_groups(keyfile, NULL);
788 if (keys == NULL) {
789 ret = -EINVAL;
790 goto done;
791 }
792
793 for (; *keys != NULL; keys++) {
794 gchar *key = *keys;
795 gchar *hex_ssid;
796 struct blob *ssid;
797
798 if (g_ascii_strncasecmp(key, "wifi_", 5) != 0)
799 continue;
800
801 if (!g_key_file_get_boolean(keyfile, key, "WiFi.HiddenSSID",
802 NULL))
803 continue;
804
805 hex_ssid = g_key_file_get_string(keyfile, key, "SSID", NULL);
806 if (hex_ssid == NULL)
807 continue;
808
809 _DBG_SERVICE("service %s", key);
810
811 ret = blob_new_from_hex(&ssid, hex_ssid);
812 g_free(hex_ssid);
813 if (ret < 0)
814 goto done;
815
816 _DBG_SERVICE("ssid %.*s", ssid->len, ssid->data);
817 *hidden_ssids = g_slist_prepend(*hidden_ssids, ssid);
818 }
819
820 done:
821 g_key_file_free(keyfile);
822
823 return ret;
824 }
825
826 static connman_bool_t is_connectable(const struct connman_service *service) 802 static connman_bool_t is_connectable(const struct connman_service *service)
827 { 803 {
828 804
829 if (service->security == CONNMAN_SERVICE_SECURITY_802_1X) { 805 if (service->security == CONNMAN_SERVICE_SECURITY_802_1X) {
830 /* Identity is required for EAP. */ 806 /* Identity is required for EAP. */
831 if (service->eap.identity == NULL) { 807 if (service->eap.identity == NULL) {
832 _DBG_SERVICE("NOT CONNECTABLE: identity is NULL"); 808 _DBG_SERVICE("NOT CONNECTABLE: identity is NULL");
833 return FALSE; 809 return FALSE;
834 } 810 }
835 811
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 1424
1449 if (service->network != NULL) 1425 if (service->network != NULL)
1450 prepare_network_string(service, networkname, 1426 prepare_network_string(service, networkname,
1451 *storage); 1427 *storage);
1452 1428
1453 if (service->path != NULL) 1429 if (service->path != NULL)
1454 connman_dbus_send_property_changed_variant(service->path, 1430 connman_dbus_send_property_changed_variant(service->path,
1455 CONNMAN_SERVICE_INTERFACE, servicename, 1431 CONNMAN_SERVICE_INTERFACE, servicename,
1456 DBUS_TYPE_STRING, storage); 1432 DBUS_TYPE_STRING, storage);
1457 1433
1458 » __connman_storage_save_service(service); 1434 » service_modified(service);
1459 1435
1460 return NULL; 1436 return NULL;
1461 } 1437 }
1462 1438
1463 static DBusMessage *set_property(DBusConnection *conn, 1439 static DBusMessage *set_property(DBusConnection *conn,
1464 DBusMessage *msg, void *user_data) 1440 DBusMessage *msg, void *user_data)
1465 { 1441 {
1466 struct connman_service *service = user_data; 1442 struct connman_service *service = user_data;
1467 DBusMessageIter iter, value; 1443 DBusMessageIter iter, value;
1468 DBusMessage *returnmsg; 1444 DBusMessage *returnmsg;
(...skipping 26 matching lines...) Expand all
1495 1471
1496 dbus_message_iter_get_basic(&value, &hidden_ssid); 1472 dbus_message_iter_get_basic(&value, &hidden_ssid);
1497 1473
1498 if (service->wifi.hidden_ssid == hidden_ssid) 1474 if (service->wifi.hidden_ssid == hidden_ssid)
1499 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1475 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1500 1476
1501 service->wifi.hidden_ssid = hidden_ssid; 1477 service->wifi.hidden_ssid = hidden_ssid;
1502 1478
1503 hidden_ssid_changed(service); 1479 hidden_ssid_changed(service);
1504 1480
1505 » » __connman_storage_save_service(service); 1481 » » service_modified(service);
1506
1507 } else if (g_str_equal(name, "Passphrase") == TRUE) { 1482 } else if (g_str_equal(name, "Passphrase") == TRUE) {
1508 const char *passphrase; 1483 const char *passphrase;
1509 1484
1510 if (type != DBUS_TYPE_STRING) 1485 if (type != DBUS_TYPE_STRING)
1511 return __connman_error_invalid_arguments(msg); 1486 return __connman_error_invalid_arguments(msg);
1512 1487
1513 if (__connman_security_check_privilege(msg, 1488 if (__connman_security_check_privilege(msg,
1514 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0) 1489 CONNMAN_SECURITY_PRIVILEGE_SECRET) < 0)
1515 return __connman_error_permission_denied(msg); 1490 return __connman_error_permission_denied(msg);
1516 1491
(...skipping 21 matching lines...) Expand all
1538 * passphrase has never been tried. 1513 * passphrase has never been tried.
1539 */ 1514 */
1540 service->last_attempt.tv_sec = 0; 1515 service->last_attempt.tv_sec = 0;
1541 service->last_attempt.tv_usec = 0; 1516 service->last_attempt.tv_usec = 0;
1542 1517
1543 passphrase_required_changed(service); 1518 passphrase_required_changed(service);
1544 1519
1545 if (service->network != NULL) 1520 if (service->network != NULL)
1546 prepare_network_passphrase(service); 1521 prepare_network_passphrase(service);
1547 1522
1548 » » __connman_storage_save_service(service); 1523 » » service_modified(service);
1549 } else if (g_str_equal(name, kEAPIdentity) == TRUE) { 1524 } else if (g_str_equal(name, kEAPIdentity) == TRUE) {
1550 returnmsg = set_eap_string(service, msg, type, value, 1525 returnmsg = set_eap_string(service, msg, type, value,
1551 &service->eap.identity, 1526 &service->eap.identity,
1552 kEAPIdentity, CONNMAN_WIFI_EAP_IDENTITY); 1527 kEAPIdentity, CONNMAN_WIFI_EAP_IDENTITY);
1553 if (returnmsg != NULL) 1528 if (returnmsg != NULL)
1554 return returnmsg; 1529 return returnmsg;
1555 } else if (g_str_equal(name, kEAPEAP) == TRUE) { 1530 } else if (g_str_equal(name, kEAPEAP) == TRUE) {
1556 returnmsg = set_eap_string(service, msg, type, value, 1531 returnmsg = set_eap_string(service, msg, type, value,
1557 &service->eap.eap, 1532 &service->eap.eap,
1558 kEAPEAP, CONNMAN_WIFI_EAP_EAP); 1533 kEAPEAP, CONNMAN_WIFI_EAP_EAP);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1625 service->eap.use_system_cas = use_system_cas; 1600 service->eap.use_system_cas = use_system_cas;
1626 1601
1627 connman_network_set_uint8(service->network, 1602 connman_network_set_uint8(service->network,
1628 CONNMAN_WIFI_EAP_USESYSTEMCAS, 1603 CONNMAN_WIFI_EAP_USESYSTEMCAS,
1629 service->eap.use_system_cas); 1604 service->eap.use_system_cas);
1630 1605
1631 connman_dbus_send_property_changed_variant(service->path, 1606 connman_dbus_send_property_changed_variant(service->path,
1632 CONNMAN_SERVICE_INTERFACE, kEAPUseSystemCAs, 1607 CONNMAN_SERVICE_INTERFACE, kEAPUseSystemCAs,
1633 DBUS_TYPE_BOOLEAN, &service->eap.use_system_cas); 1608 DBUS_TYPE_BOOLEAN, &service->eap.use_system_cas);
1634 1609
1635 » » __connman_storage_save_service(service); 1610 » » __connman_profile_save_service(service);
1636 } else if (g_str_equal(name, kEAPPIN) == TRUE) { 1611 } else if (g_str_equal(name, kEAPPIN) == TRUE) {
1637 returnmsg = set_eap_string(service, msg, type, value, 1612 returnmsg = set_eap_string(service, msg, type, value,
1638 &service->eap.pin, 1613 &service->eap.pin,
1639 kEAPPIN, CONNMAN_WIFI_EAP_PIN); 1614 kEAPPIN, CONNMAN_WIFI_EAP_PIN);
1640 if (returnmsg != NULL) 1615 if (returnmsg != NULL)
1641 return returnmsg; 1616 return returnmsg;
1642 } else if (g_str_equal(name, kEAPPassword) == TRUE) { 1617 } else if (g_str_equal(name, kEAPPassword) == TRUE) {
1643 returnmsg = set_eap_string(service, msg, type, value, 1618 returnmsg = set_eap_string(service, msg, type, value,
1644 &service->eap.password, 1619 &service->eap.password,
1645 kEAPPassword, CONNMAN_WIFI_EAP_PASSWORD); 1620 kEAPPassword, CONNMAN_WIFI_EAP_PASSWORD);
(...skipping 16 matching lines...) Expand all
1662 1637
1663 dbus_message_iter_get_basic(&value, &autoconnect); 1638 dbus_message_iter_get_basic(&value, &autoconnect);
1664 1639
1665 if (service->autoconnect == autoconnect) 1640 if (service->autoconnect == autoconnect)
1666 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1641 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1667 1642
1668 service->autoconnect = autoconnect; 1643 service->autoconnect = autoconnect;
1669 1644
1670 autoconnect_changed(service); 1645 autoconnect_changed(service);
1671 1646
1672 » » __connman_storage_save_service(service); 1647 » » service_modified(service);
1673 } else if (g_str_equal(name, "ProxyConfig") == TRUE) { 1648 } else if (g_str_equal(name, "ProxyConfig") == TRUE) {
1674 const char *proxy_config; 1649 const char *proxy_config;
1675 1650
1676 if (type != DBUS_TYPE_STRING) 1651 if (type != DBUS_TYPE_STRING)
1677 return __connman_error_invalid_arguments(msg); 1652 return __connman_error_invalid_arguments(msg);
1678 1653
1679 dbus_message_iter_get_basic(&value, &proxy_config); 1654 dbus_message_iter_get_basic(&value, &proxy_config);
1680 1655
1681 g_free(service->proxy_config); 1656 g_free(service->proxy_config);
1682 service->proxy_config = g_strdup(proxy_config); 1657 service->proxy_config = g_strdup(proxy_config);
1683 1658
1684 proxy_configuration_changed(service); 1659 proxy_configuration_changed(service);
1685 1660
1686 » » __connman_storage_save_service(service); 1661 » » service_modified(service);
1687 } else if (g_str_has_prefix(name, "Priority") == TRUE) { 1662 } else if (g_str_has_prefix(name, "Priority") == TRUE) {
1688 int pri; 1663 int pri;
1689 1664
1690 if (type != DBUS_TYPE_INT32) 1665 if (type != DBUS_TYPE_INT32)
1691 return __connman_error_invalid_arguments(msg); 1666 return __connman_error_invalid_arguments(msg);
1692 1667
1693 dbus_message_iter_get_basic(&value, &pri); 1668 dbus_message_iter_get_basic(&value, &pri);
1694 1669
1695 if (!(CONNMAN_SERVICE_PRI_MIN <= pri && 1670 if (!(CONNMAN_SERVICE_PRI_MIN <= pri &&
1696 pri <= CONNMAN_SERVICE_PRI_MAX)) { 1671 pri <= CONNMAN_SERVICE_PRI_MAX)) {
1697 _DBG_SERVICE("service priority %d out of range", pri); 1672 _DBG_SERVICE("service priority %d out of range", pri);
1698 return __connman_error_invalid_arguments(msg); 1673 return __connman_error_invalid_arguments(msg);
1699 } 1674 }
1700 1675
1701 if (service->pri != pri) { 1676 if (service->pri != pri) {
1702 service->pri = pri; 1677 service->pri = pri;
1703 __service_resort(service); 1678 __service_resort(service);
1704 1679
1705 service_priority_changed(service); 1680 service_priority_changed(service);
1706 1681
1707 » » » __connman_storage_save_service(service); 1682 » » » service_modified(service);
1708 } 1683 }
1709 } else 1684 } else
1710 return __connman_error_invalid_property(msg); 1685 return __connman_error_invalid_property(msg);
1711 1686
1712 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 1687 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
1713 } 1688 }
1714 1689
1715 static void state_change(struct connman_service *service, 1690 static void state_change(struct connman_service *service,
1716 enum connman_service_state state, int notify) 1691 enum connman_service_state state, int notify)
1717 { 1692 {
1718 _DBG_SERVICE("service state change (%p) %s -> %s", service, 1693 _DBG_SERVICE("service state change (%p) %s -> %s", service,
1719 __statename(service->state), __statename(state)); 1694 __statename(service->state), __statename(state));
1720 service->state = state; 1695 service->state = state;
1721 g_get_current_time(&service->last_state[state]); 1696 g_get_current_time(&service->last_state[state]);
1722 if (notify == TRUE) 1697 if (notify == TRUE)
1723 __connman_notifier_service_state_changed(service); 1698 __connman_notifier_service_state_changed(service);
1724 } 1699 }
1725 1700
1726 static void set_idle(struct connman_service *service) 1701 static void set_idle(struct connman_service *service)
1727 { 1702 {
1728 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN; 1703 service->error = CONNMAN_SERVICE_ERROR_UNKNOWN;
1729 state_change(service, CONNMAN_SERVICE_STATE_IDLE, TRUE); 1704 state_change(service, CONNMAN_SERVICE_STATE_IDLE, TRUE);
1730 } 1705 }
1731 1706
1732 static void __connman_service_clear_passphrase(struct connman_service *service) 1707 static void service_clear_passphrase(struct connman_service *service)
1733 { 1708 {
1734 g_free(service->passphrase); 1709 g_free(service->passphrase);
1735 service->passphrase = NULL; 1710 service->passphrase = NULL;
1736 1711
1737 memset(&service->wifi, 0, sizeof(service->wifi)); 1712 memset(&service->wifi, 0, sizeof(service->wifi));
1713 }
1714
1715 static void __connman_service_clear_passphrase(struct connman_service *service)
1716 {
1717 service_clear_passphrase(service);
1738 1718
1739 passphrase_required_changed(service); 1719 passphrase_required_changed(service);
1740 } 1720 }
1741 1721
1742 static void service_modified(struct connman_service *service) 1722 static void service_modified(struct connman_service *service)
1743 { 1723 {
1744 g_get_current_time(&service->modified); 1724 g_get_current_time(&service->modified);
1745 » __connman_storage_save_service(service); 1725
1726 » service->profile = __connman_profile_active_ident();
1727 » __connman_profile_save_service(service);
1746 } 1728 }
1747 1729
1748 void __connman_service_reset(struct connman_service *service) 1730 static void service_clear_eap(struct connman_service *service)
1749 { 1731 {
1750 connman_service_set_favorite(service, FALSE);
1751 __connman_service_clear_passphrase(service);
1752
1753 g_free(service->eap.identity); 1732 g_free(service->eap.identity);
1754 service->eap.identity = NULL; 1733 service->eap.identity = NULL;
1755 1734
1756 g_free(service->eap.eap); 1735 g_free(service->eap.eap);
1757 service->eap.eap = NULL; 1736 service->eap.eap = NULL;
1758 1737
1759 g_free(service->eap.inner_eap); 1738 g_free(service->eap.inner_eap);
1760 service->eap.inner_eap = NULL; 1739 service->eap.inner_eap = NULL;
1761 1740
1762 g_free(service->eap.anonymous_identity); 1741 g_free(service->eap.anonymous_identity);
(...skipping 20 matching lines...) Expand all
1783 g_free(service->eap.ca_cert_id); 1762 g_free(service->eap.ca_cert_id);
1784 service->eap.ca_cert_id = NULL; 1763 service->eap.ca_cert_id = NULL;
1785 1764
1786 service->eap.use_system_cas = TRUE; 1765 service->eap.use_system_cas = TRUE;
1787 1766
1788 g_free(service->eap.pin); 1767 g_free(service->eap.pin);
1789 service->eap.pin = NULL; 1768 service->eap.pin = NULL;
1790 1769
1791 g_free(service->eap.password); 1770 g_free(service->eap.password);
1792 service->eap.password = NULL; 1771 service->eap.password = NULL;
1772 }
1773
1774 void __connman_service_reset(struct connman_service *service)
1775 {
1776 connman_service_set_favorite(service, FALSE);
1777 __connman_service_clear_passphrase(service);
1778 service_clear_eap(service);
1793 1779
1794 service_modified(service); 1780 service_modified(service);
1795 } 1781 }
1796 1782
1797 static DBusMessage *clear_property(DBusConnection *conn, 1783 static DBusMessage *clear_property(DBusConnection *conn,
1798 DBusMessage *msg, void *user_data) 1784 DBusMessage *msg, void *user_data)
1799 { 1785 {
1800 struct connman_service *service = user_data; 1786 struct connman_service *service = user_data;
1801 const char *name; 1787 const char *name;
1802 1788
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 /* 2131 /*
2146 * Attempt autoconnect on the device associated with the specified 2132 * Attempt autoconnect on the device associated with the specified
2147 * service. Note this is deferred to the main event loop. 2133 * service. Note this is deferred to the main event loop.
2148 */ 2134 */
2149 void connman_service_auto_connect(struct connman_service *service) 2135 void connman_service_auto_connect(struct connman_service *service)
2150 { 2136 {
2151 struct connman_device *device = connman_service_get_device(service); 2137 struct connman_device *device = connman_service_get_device(service);
2152 __connman_service_device_auto_connect(device); 2138 __connman_service_device_auto_connect(device);
2153 } 2139 }
2154 2140
2141 static gboolean auto_connect_any(gpointer data)
2142 {
2143 _DBG_SERVICE("");
2144
2145 if (__connman_connection_is_online() == FALSE)
2146 __auto_connect(NULL, NULL);
2147 return FALSE;
2148 }
2149
2150 /*
2151 * Attempt autoconnect on any device, but only if offline.
2152 */
2153 void __connman_service_auto_connect_any(void)
2154 {
2155 g_idle_add(auto_connect_any, NULL);
2156 }
2157
2155 /** 2158 /**
2156 * __connman_service_set_activation_state: 2159 * __connman_service_set_activation_state:
2157 * @service: service structure 2160 * @service: service structure
2158 * @activation state: control interface 2161 * @activation state: control interface
2159 * @err: if the activation failed a reason for the failure 2162 * @err: if the activation failed a reason for the failure
2160 * 2163 *
2161 * Set the activation state of the network 2164 * Set the activation state of the network
2162 */ 2165 */
2163 void __connman_service_set_activation_state(struct connman_service *service, 2166 void __connman_service_set_activation_state(struct connman_service *service,
2164 enum connman_network_activation_state activation_state, 2167 enum connman_network_activation_state activation_state,
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
2699 apn_info->username = g_strdup(username); 2702 apn_info->username = g_strdup(username);
2700 if (password != NULL) 2703 if (password != NULL)
2701 apn_info->password = g_strdup(password); 2704 apn_info->password = g_strdup(password);
2702 /* 2705 /*
2703 * Clear the last-good-apn, otherwise the one 2706 * Clear the last-good-apn, otherwise the one
2704 * the user just set won't be used. 2707 * the user just set won't be used.
2705 */ 2708 */
2706 __connman_service_save_last_good_apn(service, NULL); 2709 __connman_service_save_last_good_apn(service, NULL);
2707 } 2710 }
2708 2711
2709 » __connman_storage_save_service(service); 2712 » service_modified(service);
2710 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); 2713 return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
2711 } 2714 }
2712 2715
2713 static GDBusMethodTable service_methods[] = { 2716 static GDBusMethodTable service_methods[] = {
2714 { "GetProperties", "", "a{sv}", get_properties }, 2717 { "GetProperties", "", "a{sv}", get_properties },
2715 { "SetProperty", "sv", "", set_property }, 2718 { "SetProperty", "sv", "", set_property },
2716 { "ClearProperty", "s", "", clear_property }, 2719 { "ClearProperty", "s", "", clear_property },
2717 { "Connect", "", "", connect_service, }, 2720 { "Connect", "", "", connect_service, },
2718 { "Disconnect", "", "", disconnect_service }, 2721 { "Disconnect", "", "", disconnect_service },
2719 { "Remove", "", "", remove_service }, 2722 { "Remove", "", "", remove_service },
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2753 g_dbus_unregister_interface(connection, path, 2756 g_dbus_unregister_interface(connection, path,
2754 CONNMAN_SERVICE_INTERFACE); 2757 CONNMAN_SERVICE_INTERFACE);
2755 g_free(path); 2758 g_free(path);
2756 } 2759 }
2757 2760
2758 if (service->network != NULL) 2761 if (service->network != NULL)
2759 connman_network_unref(service->network); 2762 connman_network_unref(service->network);
2760 if (service->provider != NULL) 2763 if (service->provider != NULL)
2761 connman_provider_unref(service->provider); 2764 connman_provider_unref(service->provider);
2762 2765
2763 g_free(service->profile);
2764 g_free(service->name); 2766 g_free(service->name);
2765 g_free(service->passphrase); 2767 g_free(service->passphrase);
2766 g_free(service->eap.identity); 2768 g_free(service->eap.identity);
2767 g_free(service->eap.eap); 2769 g_free(service->eap.eap);
2768 g_free(service->eap.inner_eap); 2770 g_free(service->eap.inner_eap);
2769 g_free(service->eap.anonymous_identity); 2771 g_free(service->eap.anonymous_identity);
2770 g_free(service->eap.client_cert); 2772 g_free(service->eap.client_cert);
2771 g_free(service->eap.cert_id); 2773 g_free(service->eap.cert_id);
2772 g_free(service->eap.private_key); 2774 g_free(service->eap.private_key);
2773 g_free(service->eap.private_key_passwd); 2775 g_free(service->eap.private_key_passwd);
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
3843 3845
3844 /* NB: Set HiddenSSID = FALSE when creating service not in scan list */ 3846 /* NB: Set HiddenSSID = FALSE when creating service not in scan list */
3845 reply = __connman_get_wifi_service_int(msg, &service, &created, FALSE); 3847 reply = __connman_get_wifi_service_int(msg, &service, &created, FALSE);
3846 if (reply != NULL) 3848 if (reply != NULL)
3847 return reply; 3849 return reply;
3848 else if (service == NULL) 3850 else if (service == NULL)
3849 return __connman_error_internal_error(msg); 3851 return __connman_error_internal_error(msg);
3850 3852
3851 _DBG_SERVICE("service %p created %d", service, created); 3853 _DBG_SERVICE("service %p created %d", service, created);
3852 3854
3853 » __connman_storage_save_service(service); 3855 » service_modified(service);
3854 3856
3855 /* 3857 /*
3856 * If __connman_get_wifi_service_int created the network object 3858 * If __connman_get_wifi_service_int created the network object
3857 * because the service didn't already exist, then we need to 3859 * because the service didn't already exist, then we need to
3858 * get rid of it and the associated service. Removing the network 3860 * get rid of it and the associated service. Removing the network
3859 * from the device will do this; this will be the only reference 3861 * from the device will do this; this will be the only reference
3860 * to the network and when it's reclaimed the service will also 3862 * to the network and when it's reclaimed the service will also
3861 * go away because the network layer calls up into the service 3863 * go away because the network layer calls up into the service
3862 * layer to clear the (unreferenced) pointer. 3864 * layer to clear the (unreferenced) pointer.
3863 */ 3865 */
(...skipping 26 matching lines...) Expand all
3890 } 3892 }
3891 3893
3892 service = connman_service_create(); 3894 service = connman_service_create();
3893 if (service == NULL) 3895 if (service == NULL)
3894 return NULL; 3896 return NULL;
3895 3897
3896 _DBG_SERVICE("service %p", service); 3898 _DBG_SERVICE("service %p", service);
3897 3899
3898 service->identifier = g_strdup(identifier); 3900 service->identifier = g_strdup(identifier);
3899 3901
3900 » service->profile = g_strdup(__connman_profile_active_ident()); 3902 » service->profile = __connman_profile_active_ident();
3901 3903
3902 » __connman_storage_load_service(service); 3904 » __connman_profile_load_service(service);
3903 3905
3904 iter = g_sequence_insert_sorted(service_list, service, 3906 iter = g_sequence_insert_sorted(service_list, service,
3905 service_compare, NULL); 3907 service_compare, NULL);
3906 3908
3907 g_hash_table_insert(service_hash, service->identifier, iter); 3909 g_hash_table_insert(service_hash, service->identifier, iter);
3908 3910
3909 return service; 3911 return service;
3910 } 3912 }
3911 3913
3912 static int service_register(struct connman_service *service) 3914 static int service_register(struct connman_service *service)
3913 { 3915 {
3914 const char *path = __connman_profile_active_path(); 3916 const char *path = __connman_profile_active_path();
3915 3917
3916 _DBG_SERVICE("service %p", service); 3918 _DBG_SERVICE("service %p", service);
3917 3919
3918 if (service->path != NULL) 3920 if (service->path != NULL)
3919 return -EALREADY; 3921 return -EALREADY;
3920 3922
3921 service->path = g_strdup_printf("%s/%s", path, service->identifier); 3923 service->path = g_strdup_printf("%s/%s", path, service->identifier);
3922 3924
3923 _DBG_SERVICE("path %s", service->path); 3925 _DBG_SERVICE("path %s", service->path);
3924 3926
3925 g_dbus_register_interface(connection, service->path, 3927 g_dbus_register_interface(connection, service->path,
3926 CONNMAN_SERVICE_INTERFACE, 3928 CONNMAN_SERVICE_INTERFACE,
3927 service_methods, service_signals, 3929 service_methods, service_signals,
3928 NULL, service, NULL); 3930 NULL, service, NULL);
3929 3931
3930 » __connman_storage_load_service(service); 3932 » __connman_profile_load_service(service);
3931 3933
3932 __service_resort(service); 3934 __service_resort(service);
3933 3935
3934 __connman_profile_changed(TRUE); 3936 __connman_profile_changed(TRUE);
3935 3937
3936 return 0; 3938 return 0;
3937 } 3939 }
3938 3940
3939 /** 3941 /**
3940 * __connman_service_lookup_from_device: 3942 * __connman_service_lookup_from_device:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3989 __connman_profile_changed(TRUE); 3991 __connman_profile_changed(TRUE);
3990 return service; 3992 return service;
3991 } 3993 }
3992 3994
3993 service->type = __connman_device_get_service_type(device); 3995 service->type = __connman_device_get_service_type(device);
3994 3996
3995 service->autoconnect = FALSE; 3997 service->autoconnect = FALSE;
3996 3998
3997 service->device = device; 3999 service->device = device;
3998 4000
3999 » __connman_storage_load_service(service); 4001 » __connman_profile_load_service(service);
4000 4002
4001 service_register(service); 4003 service_register(service);
4002 4004
4003 __connman_profile_changed(TRUE); 4005 __connman_profile_changed(TRUE);
4004 4006
4005 if (service->favorite == TRUE) 4007 if (service->favorite == TRUE)
4006 connman_service_auto_connect(service); 4008 connman_service_auto_connect(service);
4007 4009
4008 return service; 4010 return service;
4009 } 4011 }
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
4391 } 4393 }
4392 4394
4393 str = connman_network_get_string(network, "WiFi.Mode"); 4395 str = connman_network_get_string(network, "WiFi.Mode");
4394 service->mode = convert_wifi_mode(str); 4396 service->mode = convert_wifi_mode(str);
4395 4397
4396 str = connman_network_get_string(network, "WiFi.Security"); 4398 str = connman_network_get_string(network, "WiFi.Security");
4397 service->security = convert_wifi_security(str); 4399 service->security = convert_wifi_security(str);
4398 4400
4399 update_from_network(service, network, FALSE); 4401 update_from_network(service, network, FALSE);
4400 4402
4401 » __connman_storage_load_service(service); 4403 » __connman_profile_load_service(service);
4402 4404
4403 service_register(service); 4405 service_register(service);
4404 4406
4405 __connman_profile_changed(TRUE); 4407 __connman_profile_changed(TRUE);
4406 4408
4407 if (service->favorite == TRUE) 4409 if (service->favorite == TRUE)
4408 connman_service_auto_connect(service); 4410 connman_service_auto_connect(service);
4409 4411
4410 return service; 4412 return service;
4411 } 4413 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
4600 service->cellular.last_good_apn.network_id = g_strdup(apn->netwo rk_id); 4602 service->cellular.last_good_apn.network_id = g_strdup(apn->netwo rk_id);
4601 service->cellular.last_good_apn.username = g_strdup(apn->usernam e); 4603 service->cellular.last_good_apn.username = g_strdup(apn->usernam e);
4602 service->cellular.last_good_apn.password = g_strdup(apn->passwor d); 4604 service->cellular.last_good_apn.password = g_strdup(apn->passwor d);
4603 } else { 4605 } else {
4604 service->cellular.last_good_apn.apn = NULL; 4606 service->cellular.last_good_apn.apn = NULL;
4605 service->cellular.last_good_apn.network_id = NULL; 4607 service->cellular.last_good_apn.network_id = NULL;
4606 service->cellular.last_good_apn.username = NULL; 4608 service->cellular.last_good_apn.username = NULL;
4607 service->cellular.last_good_apn.password = NULL; 4609 service->cellular.last_good_apn.password = NULL;
4608 } 4610 }
4609 4611
4610 » __connman_storage_save_service(service); 4612 » __connman_profile_save_service(service);
4611 } 4613 }
4612 4614
4613 static void populate_service_from_keyfile(GKeyFile *keyfile, 4615 static void populate_service_from_keyfile(GKeyFile *keyfile,
4614 struct connman_service *service, 4616 struct connman_service *service,
4615 const char *key, 4617 const char *key,
4616 char **storage) 4618 char **storage)
4617 { 4619 {
4618 char *str; 4620 char *str;
4619 4621
4620 str = g_key_file_get_string(keyfile, service->identifier, key, NULL); 4622 str = g_key_file_get_string(keyfile, service->identifier, key, NULL);
4621 if (str != NULL) { 4623 if (str != NULL) {
4622 g_free(*storage); 4624 g_free(*storage);
4623 *storage = str; 4625 *storage = str;
4624 } 4626 }
4625 } 4627 }
4626 4628
4627 /* 4629 /*
4628 * Construct old-style entries for wpa/rsn services. 4630 * Construct old-style entries for wpa/rsn services.
4629 */ 4631 */
4630 static char *__old_security(GKeyFile *keyfile, 4632 static char *__old_security(GKeyFile *keyfile,
4631 const struct connman_service *service) 4633 const struct connman_service *service)
4632 { 4634 {
4633 char *group = NULL; 4635 char *group = NULL;
4634 4636
4635 if (service->security == CONNMAN_SERVICE_SECURITY_WPA) { 4637 if (service->security == CONNMAN_SERVICE_SECURITY_WPA) {
4636 group = g_strdup(service->identifier); 4638 group = g_strdup(service->identifier);
4637 g_strlcpy(group + strlen(group) - 3, "wpa", 4); 4639 g_strlcpy(group + strlen(group) - 3, "wpa", 4);
4640 if (g_key_file_has_group(keyfile, group) == FALSE) {
4641 g_free(group);
4642 group = NULL;
4643 }
4638 } else if (service->security == CONNMAN_SERVICE_SECURITY_RSN) { 4644 } else if (service->security == CONNMAN_SERVICE_SECURITY_RSN) {
4639 group = g_strdup(service->identifier); 4645 group = g_strdup(service->identifier);
4640 g_strlcpy(group + strlen(group) - 3, "rsn", 4); 4646 g_strlcpy(group + strlen(group) - 3, "rsn", 4);
4647 if (g_key_file_has_group(keyfile, group) == FALSE) {
4648 g_free(group);
4649 group = NULL;
4650 }
4641 } 4651 }
4642 return group; 4652 return group;
4643 } 4653 }
4644 4654
4645 static void load_apn(struct connman_service *service, 4655 static void load_apn(struct connman_service *service,
4646 GKeyFile *keyfile, 4656 GKeyFile *keyfile,
4647 const char *group, 4657 const char *group,
4648 struct connman_network_apn *apn, 4658 struct connman_network_apn *apn,
4649 const char *keytag) 4659 const char *keytag)
4650 { 4660 {
(...skipping 20 matching lines...) Expand all
4671 apn->password = NULL; 4681 apn->password = NULL;
4672 apn->network_id = NULL; 4682 apn->network_id = NULL;
4673 } 4683 }
4674 4684
4675 g_free(apn_key); 4685 g_free(apn_key);
4676 g_free(username_key); 4686 g_free(username_key);
4677 g_free(password_key); 4687 g_free(password_key);
4678 g_free(network_id_key); 4688 g_free(network_id_key);
4679 } 4689 }
4680 4690
4681 static int service_load(struct connman_service *service) 4691 static int service_load(struct connman_service *service, GKeyFile *keyfile)
4682 { 4692 {
4683 const char *ident = service->profile;
4684 const char *group = service->identifier; 4693 const char *group = service->identifier;
4685 GKeyFile *keyfile;
4686 GError *error = NULL; 4694 GError *error = NULL;
4687 gchar *pathname, *data = NULL;
4688 gsize length;
4689 gchar *str; 4695 gchar *str;
4690 connman_bool_t autoconnect, use_system_cas; 4696 connman_bool_t autoconnect, use_system_cas;
4691 unsigned int ssid_len; 4697 unsigned int ssid_len;
4692 struct connman_network_apn *apn; 4698 struct connman_network_apn *apn;
4693 int err = 0, pri; 4699 int err = 0, pri;
4694 4700
4695 _DBG_SERVICE("service %p", service); 4701 _DBG_SERVICE("service %p", service);
4696 4702
4697 » if (ident == NULL) 4703 » if (g_key_file_has_group(keyfile, group) == FALSE) {
4698 » » return -EINVAL; 4704 » » char *old_group;
4699 4705 » » /*
4700 » pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident); 4706 » » * Handle upgrade of old-style entries for wpa/rsn services.
4701 » if (pathname == NULL) 4707 » » */
4702 » » return -ENOMEM; 4708 » » if (g_str_has_suffix(group, "_psk") == FALSE) {
4703 4709 » » » err = -ESRCH;
4704 » keyfile = g_key_file_new(); 4710 » » » goto done;
4705
4706 » if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE) {
4707 » » g_free(pathname);
4708 » » return -ENOENT;
4709 » }
4710
4711 » g_free(pathname);
4712
4713 » if (g_key_file_load_from_data(keyfile, data, length,
4714 » » » » » » » 0, NULL) == FALSE) {
4715 » » g_free(data);
4716 » » return -EILSEQ;
4717 » }
4718
4719 » g_free(data);
4720
4721 » /*
4722 » * Handle upgrade of old-style entries for wpa/rsn services.
4723 » */
4724 » if (g_key_file_has_group(keyfile, group) == FALSE &&
4725 » g_str_has_suffix(group, "_psk") == TRUE) {
4726 » » char *old_group = __old_security(keyfile, service);
4727 » » if (old_group != NULL) {
4728 » » » _DBG_SERVICE("check old entry %s", old_group);
4729 » » » group = old_group;
4730 } 4711 }
4712 old_group = __old_security(keyfile, service);
4713 if (old_group == NULL) {
4714 err = -ESRCH;
4715 goto done;
4716 }
4717 _DBG_SERVICE("check old entry %s", old_group);
4718 group = old_group;
4731 } 4719 }
4732 4720
4733 switch (service->type) { 4721 switch (service->type) {
4734 case CONNMAN_SERVICE_TYPE_UNKNOWN: 4722 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4735 case CONNMAN_SERVICE_TYPE_ETHERNET: 4723 case CONNMAN_SERVICE_TYPE_ETHERNET:
4736 case CONNMAN_SERVICE_TYPE_VPN: 4724 case CONNMAN_SERVICE_TYPE_VPN:
4737 break; 4725 break;
4738 case CONNMAN_SERVICE_TYPE_WIFI: 4726 case CONNMAN_SERVICE_TYPE_WIFI:
4739 service->wifi.hidden_ssid = g_key_file_get_boolean(keyfile, 4727 service->wifi.hidden_ssid = g_key_file_get_boolean(keyfile,
4740 group, "WiFi.HiddenSSID", NULL); 4728 group, "WiFi.HiddenSSID", NULL);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
4806 g_free(str); 4794 g_free(str);
4807 } 4795 }
4808 4796
4809 str = g_key_file_get_string(keyfile, 4797 str = g_key_file_get_string(keyfile,
4810 group, "LastAttempt", NULL); 4798 group, "LastAttempt", NULL);
4811 if (str != NULL) { 4799 if (str != NULL) {
4812 g_time_val_from_iso8601(str, &service->last_attempt); 4800 g_time_val_from_iso8601(str, &service->last_attempt);
4813 g_free(str); 4801 g_free(str);
4814 } 4802 }
4815 4803
4816 » str = __connman_storage_get_encrypted_value(keyfile, service->profile, 4804 » str = __connman_storage_get_encrypted_value(keyfile, group,
4817 » group, "Passphrase"); 4805 » "Passphrase");
4818 if (str != NULL) { 4806 if (str != NULL) {
4819 connman_bool_t valid_pass = TRUE; 4807 connman_bool_t valid_pass = TRUE;
4820 g_free(service->passphrase); 4808 g_free(service->passphrase);
4821 service->passphrase = NULL; 4809 service->passphrase = NULL;
4822 4810
4823 switch (service->security) { 4811 switch (service->security) {
4824 case CONNMAN_SERVICE_SECURITY_WEP: 4812 case CONNMAN_SERVICE_SECURITY_WEP:
4825 valid_pass = __connman_service_parse_wep_key(str, 4813 valid_pass = __connman_service_parse_wep_key(str,
4826 &service->wifi.wep_key_idx, 4814 &service->wifi.wep_key_idx,
4827 &service->wifi.wep_key_len, 4815 &service->wifi.wep_key_len,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
4885 pri = g_key_file_get_integer(keyfile, 4873 pri = g_key_file_get_integer(keyfile,
4886 group, "Priority", &error); 4874 group, "Priority", &error);
4887 if (error == NULL) 4875 if (error == NULL)
4888 service->pri = pri; 4876 service->pri = pri;
4889 4877
4890 apn = &service->cellular.apn; 4878 apn = &service->cellular.apn;
4891 load_apn(service, keyfile, group, &service->cellular.apn, "APN"); 4879 load_apn(service, keyfile, group, &service->cellular.apn, "APN");
4892 load_apn(service, keyfile, group, &service->cellular.last_good_apn, 4880 load_apn(service, keyfile, group, &service->cellular.last_good_apn,
4893 "LastGoodAPN"); 4881 "LastGoodAPN");
4894 done: 4882 done:
4895 g_key_file_free(keyfile);
4896
4897 if (group != service->identifier) 4883 if (group != service->identifier)
4898 g_free((char *)group); 4884 g_free((char *)group);
4899 4885
4900 return err; 4886 return err;
4901 } 4887 }
4902 4888
4903 static void save_property(GKeyFile *keyfile, struct connman_service *service, 4889 static void save_property(GKeyFile *keyfile, struct connman_service *service,
4904 const char *key, const char *value) 4890 const char *key, const char *value)
4905 { 4891 {
4906 if (value != NULL && strlen(value) > 0) 4892 if (value != NULL && strlen(value) > 0)
(...skipping 27 matching lines...) Expand all
4934 password_key, NULL); 4920 password_key, NULL);
4935 g_key_file_remove_key(keyfile, service->identifier, 4921 g_key_file_remove_key(keyfile, service->identifier,
4936 network_id_key, NULL); 4922 network_id_key, NULL);
4937 } 4923 }
4938 g_free(apn_key); 4924 g_free(apn_key);
4939 g_free(username_key); 4925 g_free(username_key);
4940 g_free(password_key); 4926 g_free(password_key);
4941 g_free(network_id_key); 4927 g_free(network_id_key);
4942 } 4928 }
4943 4929
4944 static int service_save(struct connman_service *service) 4930 static int service_save(struct connman_service *service, GKeyFile *keyfile)
4945 { 4931 {
4946 const char *ident = service->profile;
4947 GKeyFile *keyfile;
4948 gchar *pathname, *data = NULL;
4949 gsize length;
4950 gchar *str; 4932 gchar *str;
4951 int err = 0;
4952 4933
4953 _DBG_SERVICE("service %p", service); 4934 _DBG_SERVICE("service %p", service);
4954 4935
4955 if (ident == NULL)
4956 return -EINVAL;
4957
4958 pathname = g_strdup_printf("%s/%s.profile", STORAGEDIR, ident);
4959 if (pathname == NULL)
4960 return -ENOMEM;
4961
4962 keyfile = g_key_file_new();
4963
4964 if (g_file_get_contents(pathname, &data, &length, NULL) == FALSE)
4965 goto update;
4966
4967 if (length > 0) {
4968 if (g_key_file_load_from_data(keyfile, data, length,
4969 0, NULL) == FALSE)
4970 goto done;
4971 }
4972
4973 g_free(data);
4974
4975 update:
4976 if (service->name != NULL) 4936 if (service->name != NULL)
4977 g_key_file_set_string(keyfile, service->identifier, 4937 g_key_file_set_string(keyfile, service->identifier,
4978 "Name", service->name); 4938 "Name", service->name);
4979 4939
4980 switch (service->type) { 4940 switch (service->type) {
4981 case CONNMAN_SERVICE_TYPE_UNKNOWN: 4941 case CONNMAN_SERVICE_TYPE_UNKNOWN:
4982 case CONNMAN_SERVICE_TYPE_ETHERNET: 4942 case CONNMAN_SERVICE_TYPE_ETHERNET:
4983 case CONNMAN_SERVICE_TYPE_VPN: 4943 case CONNMAN_SERVICE_TYPE_VPN:
4984 break; 4944 break;
4985 case CONNMAN_SERVICE_TYPE_WIFI: 4945 case CONNMAN_SERVICE_TYPE_WIFI:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5035 if (is_timeset(&service->last_attempt)) { 4995 if (is_timeset(&service->last_attempt)) {
5036 str = g_time_val_to_iso8601(&service->last_attempt); 4996 str = g_time_val_to_iso8601(&service->last_attempt);
5037 if (str != NULL) { 4997 if (str != NULL) {
5038 g_key_file_set_string(keyfile, service->identifier, 4998 g_key_file_set_string(keyfile, service->identifier,
5039 "LastAttempt", str); 4999 "LastAttempt", str);
5040 g_free(str); 5000 g_free(str);
5041 } 5001 }
5042 } 5002 }
5043 5003
5044 if (service->passphrase != NULL && strlen(service->passphrase) > 0) { 5004 if (service->passphrase != NULL && strlen(service->passphrase) > 0) {
5045 __connman_storage_set_encrypted_value(keyfile, service->profile, 5005 __connman_storage_set_encrypted_value(keyfile,
5046 service->identifier, "Passphrase", service->passphrase); 5006 service->identifier, "Passphrase", service->passphrase);
5047 } else { 5007 } else {
5048 g_key_file_remove_key(keyfile, service->identifier, 5008 g_key_file_remove_key(keyfile, service->identifier,
5049 "Passphrase", NULL); 5009 "Passphrase", NULL);
5050 } 5010 }
5051 5011
5052 save_property(keyfile, service, kEAPIdentity, service->eap.identity); 5012 save_property(keyfile, service, kEAPIdentity, service->eap.identity);
5053 save_property(keyfile, service, kEAPEAP, service->eap.eap); 5013 save_property(keyfile, service, kEAPEAP, service->eap.eap);
5054 save_property(keyfile, service, kEAPInnerEAP, service->eap.inner_eap); 5014 save_property(keyfile, service, kEAPInnerEAP, service->eap.inner_eap);
5055 save_property(keyfile, service, kEAPAnonymousIdentity, 5015 save_property(keyfile, service, kEAPAnonymousIdentity,
(...skipping 25 matching lines...) Expand all
5081 g_key_file_set_integer(keyfile, service->identifier, 5041 g_key_file_set_integer(keyfile, service->identifier,
5082 "Priority", service->pri); 5042 "Priority", service->pri);
5083 else 5043 else
5084 g_key_file_remove_key(keyfile, service->identifier, 5044 g_key_file_remove_key(keyfile, service->identifier,
5085 "Priority", NULL); 5045 "Priority", NULL);
5086 5046
5087 save_apn(service, keyfile, &service->cellular.apn, "APN"); 5047 save_apn(service, keyfile, &service->cellular.apn, "APN");
5088 save_apn(service, keyfile, &service->cellular.last_good_apn, 5048 save_apn(service, keyfile, &service->cellular.last_good_apn,
5089 "LastGoodAPN"); 5049 "LastGoodAPN");
5090 5050
5091 » data = g_key_file_to_data(keyfile, &length, NULL); 5051 » return 0;
5092
5093 » if (g_file_set_contents(pathname, data, length, NULL) == FALSE)
5094 » » connman_error("Failed to store service information");
5095
5096 done:
5097 » g_free(data);
5098
5099 » g_key_file_free(keyfile);
5100
5101 » g_free(pathname);
5102
5103 » return err;
5104 } 5052 }
5105 5053
5106 static struct connman_storage service_storage = { 5054 static struct connman_storage service_storage = {
5107 .name = "service", 5055 .name = "service",
5108 .priority = CONNMAN_STORAGE_PRIORITY_LOW, 5056 .priority = CONNMAN_STORAGE_PRIORITY_LOW,
5109 .service_load = service_load, 5057 .service_load = service_load,
5110 .service_save = service_save, 5058 .service_save = service_save,
5111 }; 5059 };
5112 5060
5113 static struct connman_notifier service_notifier = { 5061 static struct connman_notifier service_notifier = {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5154 service_list = NULL; 5102 service_list = NULL;
5155 5103
5156 g_hash_table_destroy(service_hash); 5104 g_hash_table_destroy(service_hash);
5157 service_hash = NULL; 5105 service_hash = NULL;
5158 5106
5159 connman_storage_unregister(&service_storage); 5107 connman_storage_unregister(&service_storage);
5160 connman_notifier_unregister(&service_notifier); 5108 connman_notifier_unregister(&service_notifier);
5161 5109
5162 dbus_connection_unref(connection); 5110 dbus_connection_unref(connection);
5163 } 5111 }
OLDNEW
« src/profile.c ('K') | « src/profile.c ('k') | src/storage.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698