diff options
| author | 2018-09-03 17:14:18 +0200 | |
|---|---|---|
| committer | 2018-09-03 17:14:18 +0200 | |
| commit | a00b019c4421ce4937a45a0529d3e3b369876cef (patch) | |
| tree | 767287d18af0a0fc0e3514d69d4d7286527cfc2a /tools/idevicebackup2.c | |
| parent | d7a2e04d2e7880c56116fd35489a7f98755501b7 (diff) | |
| download | libimobiledevice-a00b019c4421ce4937a45a0529d3e3b369876cef.tar.gz libimobiledevice-a00b019c4421ce4937a45a0529d3e3b369876cef.tar.bz2 | |
idevicebackup2: Prevent lockdownd timeouts
Diffstat (limited to 'tools/idevicebackup2.c')
| -rw-r--r-- | tools/idevicebackup2.c | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c index 84b8a61..e4bcdb9 100644 --- a/tools/idevicebackup2.c +++ b/tools/idevicebackup2.c | |||
| @@ -293,18 +293,33 @@ static char* get_uuid() | |||
| 293 | return uuid; | 293 | return uuid; |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t device, lockdownd_client_t lockdown, afc_client_t afc) | 296 | static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t device, afc_client_t afc) |
| 297 | { | 297 | { |
| 298 | /* gather data from lockdown */ | 298 | /* gather data from lockdown */ |
| 299 | plist_t value_node = NULL; | 299 | plist_t value_node = NULL; |
| 300 | plist_t root_node = NULL; | 300 | plist_t root_node = NULL; |
| 301 | plist_t itunes_settings = NULL; | ||
| 302 | plist_t min_itunes_version = NULL; | ||
| 301 | char *udid_uppercase = NULL; | 303 | char *udid_uppercase = NULL; |
| 302 | 304 | ||
| 305 | lockdownd_client_t lockdown = NULL; | ||
| 306 | if (lockdownd_client_new_with_handshake(device, &lockdown, "idevicebackup2") != LOCKDOWN_E_SUCCESS) { | ||
| 307 | return NULL; | ||
| 308 | } | ||
| 309 | |||
| 303 | plist_t ret = plist_new_dict(); | 310 | plist_t ret = plist_new_dict(); |
| 304 | 311 | ||
| 305 | /* get basic device information in one go */ | 312 | /* get basic device information in one go */ |
| 306 | lockdownd_get_value(lockdown, NULL, NULL, &root_node); | 313 | lockdownd_get_value(lockdown, NULL, NULL, &root_node); |
| 307 | 314 | ||
| 315 | /* get iTunes settings */ | ||
| 316 | lockdownd_get_value(lockdown, "com.apple.iTunes", NULL, &itunes_settings); | ||
| 317 | |||
| 318 | /* get minimum iTunes version */ | ||
| 319 | lockdownd_get_value(lockdown, "com.apple.mobile.iTunes", "MinITunesVersion", &min_itunes_version); | ||
| 320 | |||
| 321 | lockdownd_client_free(lockdown); | ||
| 322 | |||
| 308 | /* get a list of installed user applications */ | 323 | /* get a list of installed user applications */ |
| 309 | plist_t app_dict = plist_new_dict(); | 324 | plist_t app_dict = plist_new_dict(); |
| 310 | plist_t installed_apps = plist_new_array(); | 325 | plist_t installed_apps = plist_new_array(); |
| @@ -325,7 +340,6 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t d | |||
| 325 | if (apps && (plist_get_node_type(apps) == PLIST_ARRAY)) { | 340 | if (apps && (plist_get_node_type(apps) == PLIST_ARRAY)) { |
| 326 | uint32_t app_count = plist_array_get_size(apps); | 341 | uint32_t app_count = plist_array_get_size(apps); |
| 327 | uint32_t i; | 342 | uint32_t i; |
| 328 | time_t starttime = time(NULL); | ||
| 329 | for (i = 0; i < app_count; i++) { | 343 | for (i = 0; i < app_count; i++) { |
| 330 | plist_t app_entry = plist_array_get_item(apps, i); | 344 | plist_t app_entry = plist_array_get_item(apps, i); |
| 331 | plist_t bundle_id = plist_dict_get_item(app_entry, "CFBundleIdentifier"); | 345 | plist_t bundle_id = plist_dict_get_item(app_entry, "CFBundleIdentifier"); |
| @@ -353,11 +367,6 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t d | |||
| 353 | } | 367 | } |
| 354 | free(bundle_id_str); | 368 | free(bundle_id_str); |
| 355 | } | 369 | } |
| 356 | if ((time(NULL) - starttime) > 5) { | ||
| 357 | // make sure our lockdown connection doesn't time out in case this takes longer | ||
| 358 | lockdownd_query_type(lockdown, NULL); | ||
| 359 | starttime = time(NULL); | ||
| 360 | } | ||
| 361 | } | 370 | } |
| 362 | } | 371 | } |
| 363 | plist_free(apps); | 372 | plist_free(apps); |
| @@ -470,20 +479,17 @@ static plist_t mobilebackup_factory_info_plist_new(const char* udid, idevice_t d | |||
| 470 | } | 479 | } |
| 471 | plist_dict_set_item(ret, "iTunes Files", files); | 480 | plist_dict_set_item(ret, "iTunes Files", files); |
| 472 | 481 | ||
| 473 | plist_t itunes_settings = NULL; | ||
| 474 | lockdownd_get_value(lockdown, "com.apple.iTunes", NULL, &itunes_settings); | ||
| 475 | plist_dict_set_item(ret, "iTunes Settings", itunes_settings ? itunes_settings : plist_new_dict()); | 482 | plist_dict_set_item(ret, "iTunes Settings", itunes_settings ? itunes_settings : plist_new_dict()); |
| 476 | 483 | ||
| 477 | /* since we usually don't have iTunes, let's get the minimum required iTunes version from the device */ | 484 | /* since we usually don't have iTunes, let's get the minimum required iTunes version from the device */ |
| 478 | value_node = NULL; | 485 | if (min_itunes_version) { |
| 479 | lockdownd_get_value(lockdown, "com.apple.mobile.iTunes", "MinITunesVersion", &value_node); | 486 | plist_dict_set_item(ret, "iTunes Version", plist_copy(min_itunes_version)); |
| 480 | if (value_node) { | ||
| 481 | plist_dict_set_item(ret, "iTunes Version", plist_copy(value_node)); | ||
| 482 | plist_free(value_node); | ||
| 483 | } else { | 487 | } else { |
| 484 | plist_dict_set_item(ret, "iTunes Version", plist_new_string("10.0.1")); | 488 | plist_dict_set_item(ret, "iTunes Version", plist_new_string("10.0.1")); |
| 485 | } | 489 | } |
| 486 | 490 | ||
| 491 | plist_free(itunes_settings); | ||
| 492 | plist_free(min_itunes_version); | ||
| 487 | plist_free(root_node); | 493 | plist_free(root_node); |
| 488 | 494 | ||
| 489 | return ret; | 495 | return ret; |
| @@ -1632,6 +1638,17 @@ int main(int argc, char *argv[]) | |||
| 1632 | return -1; | 1638 | return -1; |
| 1633 | } | 1639 | } |
| 1634 | 1640 | ||
| 1641 | uint8_t willEncrypt = 0; | ||
| 1642 | node_tmp = NULL; | ||
| 1643 | lockdownd_get_value(lockdown, "com.apple.mobile.backup", "WillEncrypt", &node_tmp); | ||
| 1644 | if (node_tmp) { | ||
| 1645 | if (plist_get_node_type(node_tmp) == PLIST_BOOLEAN) { | ||
| 1646 | plist_get_bool_val(node_tmp, &willEncrypt); | ||
| 1647 | } | ||
| 1648 | plist_free(node_tmp); | ||
| 1649 | node_tmp = NULL; | ||
| 1650 | } | ||
| 1651 | |||
| 1635 | /* start notification_proxy */ | 1652 | /* start notification_proxy */ |
| 1636 | np_client_t np = NULL; | 1653 | np_client_t np = NULL; |
| 1637 | ldret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); | 1654 | ldret = lockdownd_start_service(lockdown, NP_SERVICE_NAME, &service); |
| @@ -1669,6 +1686,8 @@ int main(int argc, char *argv[]) | |||
| 1669 | /* start mobilebackup service and retrieve port */ | 1686 | /* start mobilebackup service and retrieve port */ |
| 1670 | mobilebackup2_client_t mobilebackup2 = NULL; | 1687 | mobilebackup2_client_t mobilebackup2 = NULL; |
| 1671 | ldret = lockdownd_start_service_with_escrow_bag(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); | 1688 | ldret = lockdownd_start_service_with_escrow_bag(lockdown, MOBILEBACKUP2_SERVICE_NAME, &service); |
| 1689 | lockdownd_client_free(lockdown); | ||
| 1690 | lockdown = NULL; | ||
| 1672 | if ((ldret == LOCKDOWN_E_SUCCESS) && service && service->port) { | 1691 | if ((ldret == LOCKDOWN_E_SUCCESS) && service && service->port) { |
| 1673 | PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); | 1692 | PRINT_VERBOSE(1, "Started \"%s\" service on port %d.\n", MOBILEBACKUP2_SERVICE_NAME, service->port); |
| 1674 | mobilebackup2_client_new(device, service, &mobilebackup2); | 1693 | mobilebackup2_client_new(device, service, &mobilebackup2); |
| @@ -1745,16 +1764,6 @@ int main(int argc, char *argv[]) | |||
| 1745 | cmd = CMD_LEAVE; | 1764 | cmd = CMD_LEAVE; |
| 1746 | } | 1765 | } |
| 1747 | } | 1766 | } |
| 1748 | uint8_t willEncrypt = 0; | ||
| 1749 | node_tmp = NULL; | ||
| 1750 | lockdownd_get_value(lockdown, "com.apple.mobile.backup", "WillEncrypt", &node_tmp); | ||
| 1751 | if (node_tmp) { | ||
| 1752 | if (plist_get_node_type(node_tmp) == PLIST_BOOLEAN) { | ||
| 1753 | plist_get_bool_val(node_tmp, &willEncrypt); | ||
| 1754 | } | ||
| 1755 | plist_free(node_tmp); | ||
| 1756 | node_tmp = NULL; | ||
| 1757 | } | ||
| 1758 | 1767 | ||
| 1759 | checkpoint: | 1768 | checkpoint: |
| 1760 | 1769 | ||
| @@ -1798,7 +1807,11 @@ checkpoint: | |||
| 1798 | plist_free(info_plist); | 1807 | plist_free(info_plist); |
| 1799 | info_plist = NULL; | 1808 | info_plist = NULL; |
| 1800 | } | 1809 | } |
| 1801 | info_plist = mobilebackup_factory_info_plist_new(udid, device, lockdown, afc); | 1810 | info_plist = mobilebackup_factory_info_plist_new(udid, device, afc); |
| 1811 | if (!info_plist) { | ||
| 1812 | fprintf(stderr, "Failed to generate Info.plist - aborting\n"); | ||
| 1813 | cmd = CMD_LEAVE; | ||
| 1814 | } | ||
| 1802 | remove_file(info_path); | 1815 | remove_file(info_path); |
| 1803 | plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML); | 1816 | plist_write_to_filename(info_plist, info_path, PLIST_FORMAT_XML); |
| 1804 | free(info_path); | 1817 | free(info_path); |
| @@ -1988,12 +2001,6 @@ checkpoint: | |||
| 1988 | break; | 2001 | break; |
| 1989 | } | 2002 | } |
| 1990 | 2003 | ||
| 1991 | /* close down the lockdown connection as it is no longer needed */ | ||
| 1992 | if (lockdown) { | ||
| 1993 | lockdownd_client_free(lockdown); | ||
| 1994 | lockdown = NULL; | ||
| 1995 | } | ||
| 1996 | |||
| 1997 | if (cmd != CMD_LEAVE) { | 2004 | if (cmd != CMD_LEAVE) { |
| 1998 | /* reset operation success status */ | 2005 | /* reset operation success status */ |
| 1999 | int operation_ok = 0; | 2006 | int operation_ok = 0; |
