diff options
| author | 2013-02-26 03:20:56 +0100 | |
|---|---|---|
| committer | 2013-02-26 03:20:56 +0100 | |
| commit | fcc1bb855efb6860417ed827d3b50feba24a9a8b (patch) | |
| tree | 47d3c7d6a985dc647f7962329014c8116d657cc9 /src/lockdown.c | |
| parent | 3b54aac30447bc02fafd721a63a752968628e7e0 (diff) | |
| download | libimobiledevice-fcc1bb855efb6860417ed827d3b50feba24a9a8b.tar.gz libimobiledevice-fcc1bb855efb6860417ed827d3b50feba24a9a8b.tar.bz2 | |
Refactor port number use into service descriptor to enable SSL for services
This is a major change which breaks API but is required in order to support
SSL communication for services as used by network connections.
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index e899baa..df1f60f 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -646,8 +646,13 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli | |||
| 646 | if (!client) | 646 | if (!client) |
| 647 | return LOCKDOWN_E_INVALID_ARG; | 647 | return LOCKDOWN_E_INVALID_ARG; |
| 648 | 648 | ||
| 649 | static struct lockdownd_service_descriptor service = { | ||
| 650 | .port = 0xf27e, | ||
| 651 | .ssl_enabled = 0 | ||
| 652 | }; | ||
| 653 | |||
| 649 | property_list_service_client_t plistclient = NULL; | 654 | property_list_service_client_t plistclient = NULL; |
| 650 | if (property_list_service_client_new(device, 0xf27e, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { | 655 | if (property_list_service_client_new(device, (lockdownd_service_descriptor_t)&service, &plistclient) != PROPERTY_LIST_SERVICE_E_SUCCESS) { |
| 651 | debug_info("could not connect to lockdownd (device %s)", device->udid); | 656 | debug_info("could not connect to lockdownd (device %s)", device->udid); |
| 652 | return LOCKDOWN_E_MUX_ERROR; | 657 | return LOCKDOWN_E_MUX_ERROR; |
| 653 | } | 658 | } |
| @@ -1494,17 +1499,17 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char | |||
| 1494 | * Requests to start a service and retrieve it's port on success. | 1499 | * Requests to start a service and retrieve it's port on success. |
| 1495 | * | 1500 | * |
| 1496 | * @param client The lockdownd client | 1501 | * @param client The lockdownd client |
| 1497 | * @param service The name of the service to start | 1502 | * @param identifier The identifier of the service to start |
| 1498 | * @param port The port number the service was started on | 1503 | * @param descriptor The service descriptor on success or NULL on failure |
| 1499 | 1504 | ||
| 1500 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter | 1505 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter |
| 1501 | * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known | 1506 | * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known |
| 1502 | * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because | 1507 | * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because |
| 1503 | * started by the device | 1508 | * started by the device |
| 1504 | */ | 1509 | */ |
| 1505 | lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) | 1510 | lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service) |
| 1506 | { | 1511 | { |
| 1507 | if (!client || !service || !port) | 1512 | if (!client || !identifier || !service) |
| 1508 | return LOCKDOWN_E_INVALID_ARG; | 1513 | return LOCKDOWN_E_INVALID_ARG; |
| 1509 | 1514 | ||
| 1510 | char *host_id = NULL; | 1515 | char *host_id = NULL; |
| @@ -1524,7 +1529,7 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char | |||
| 1524 | dict = plist_new_dict(); | 1529 | dict = plist_new_dict(); |
| 1525 | plist_dict_add_label(dict, client->label); | 1530 | plist_dict_add_label(dict, client->label); |
| 1526 | plist_dict_insert_item(dict,"Request", plist_new_string("StartService")); | 1531 | plist_dict_insert_item(dict,"Request", plist_new_string("StartService")); |
| 1527 | plist_dict_insert_item(dict,"Service", plist_new_string(service)); | 1532 | plist_dict_insert_item(dict,"Service", plist_new_string(identifier)); |
| 1528 | 1533 | ||
| 1529 | /* send to device */ | 1534 | /* send to device */ |
| 1530 | ret = lockdownd_send(client, dict); | 1535 | ret = lockdownd_send(client, dict); |
| @@ -1542,20 +1547,34 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char | |||
| 1542 | if (!dict) | 1547 | if (!dict) |
| 1543 | return LOCKDOWN_E_PLIST_ERROR; | 1548 | return LOCKDOWN_E_PLIST_ERROR; |
| 1544 | 1549 | ||
| 1550 | if (*service == NULL) | ||
| 1551 | *service = (lockdownd_service_descriptor_t)malloc(sizeof(struct lockdownd_service_descriptor)); | ||
| 1552 | (*service)->port = 0; | ||
| 1553 | (*service)->ssl_enabled = 0; | ||
| 1554 | |||
| 1545 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | 1555 | ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 1546 | if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { | 1556 | if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { |
| 1547 | plist_t port_value_node = plist_dict_get_item(dict, "Port"); | 1557 | /* read service port number */ |
| 1548 | 1558 | plist_t node = plist_dict_get_item(dict, "Port"); | |
| 1549 | if (port_value_node && (plist_get_node_type(port_value_node) == PLIST_UINT)) { | 1559 | if (node && (plist_get_node_type(node) == PLIST_UINT)) { |
| 1550 | uint64_t port_value = 0; | 1560 | uint64_t port_value = 0; |
| 1551 | plist_get_uint_val(port_value_node, &port_value); | 1561 | plist_get_uint_val(node, &port_value); |
| 1552 | 1562 | ||
| 1553 | if (port_value) { | 1563 | if (port_value) { |
| 1554 | port_loc = port_value; | 1564 | port_loc = port_value; |
| 1555 | ret = LOCKDOWN_E_SUCCESS; | 1565 | ret = LOCKDOWN_E_SUCCESS; |
| 1556 | } | 1566 | } |
| 1557 | if (port && ret == LOCKDOWN_E_SUCCESS) | 1567 | if (port_loc && ret == LOCKDOWN_E_SUCCESS) { |
| 1558 | *port = port_loc; | 1568 | (*service)->port = port_loc; |
| 1569 | } | ||
| 1570 | } | ||
| 1571 | |||
| 1572 | /* check if the service requires SSL */ | ||
| 1573 | node = plist_dict_get_item(dict, "EnableServiceSSL"); | ||
| 1574 | if (node && (plist_get_node_type(node) == PLIST_BOOLEAN)) { | ||
| 1575 | uint8_t b = 0; | ||
| 1576 | plist_get_bool_val(node, &b); | ||
| 1577 | (*service)->ssl_enabled = b; | ||
| 1559 | } | 1578 | } |
| 1560 | } else { | 1579 | } else { |
| 1561 | ret = LOCKDOWN_E_START_SERVICE_FAILED; | 1580 | ret = LOCKDOWN_E_START_SERVICE_FAILED; |
| @@ -1785,3 +1804,18 @@ lockdownd_error_t lockdownd_data_classes_free(char **classes) | |||
| 1785 | } | 1804 | } |
| 1786 | return LOCKDOWN_E_SUCCESS; | 1805 | return LOCKDOWN_E_SUCCESS; |
| 1787 | } | 1806 | } |
| 1807 | |||
| 1808 | /** | ||
| 1809 | * Frees memory of a service descriptor as returned by lockdownd_start_service() | ||
| 1810 | * | ||
| 1811 | * @param sevice A service descriptor instance to free. | ||
| 1812 | * | ||
| 1813 | * @return LOCKDOWN_E_SUCCESS on success | ||
| 1814 | */ | ||
| 1815 | lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service) | ||
| 1816 | { | ||
| 1817 | if (service) | ||
| 1818 | free(service); | ||
| 1819 | |||
| 1820 | return LOCKDOWN_E_SUCCESS; | ||
| 1821 | } | ||
