summaryrefslogtreecommitdiffstats
path: root/tools/idevicebackup2.c
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-09-27 17:39:21 +0200
committerGravatar Martin Szulecki2013-09-27 17:39:21 +0200
commit744e014d5240b8621b8b8a2aec954641e18d3ac7 (patch)
treee2b6e4d8b3fb28e73c9172ec9c0214c6b4d5bd07 /tools/idevicebackup2.c
parent185eb2f49e4d038d1b16d37b0914ffba4a67f866 (diff)
downloadlibimobiledevice-744e014d5240b8621b8b8a2aec954641e18d3ac7.tar.gz
libimobiledevice-744e014d5240b8621b8b8a2aec954641e18d3ac7.tar.bz2
idevicebackup2: Cloud support broke other commands thus change it be a command
The experimental cloud support was triggered on each run of any command which caused some to break on devices without iCloud setup. We now trigger the cloud support in a separate command to fix this and allow further investigation into a proper implementation.
Diffstat (limited to 'tools/idevicebackup2.c')
-rw-r--r--tools/idevicebackup2.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index eebbd87..353d5f3 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -71,7 +71,8 @@ enum cmd_mode {
71 CMD_LIST, 71 CMD_LIST,
72 CMD_UNBACK, 72 CMD_UNBACK,
73 CMD_CHANGEPW, 73 CMD_CHANGEPW,
74 CMD_LEAVE 74 CMD_LEAVE,
75 CMD_CLOUD
75}; 76};
76 77
77enum plist_format_t { 78enum plist_format_t {
@@ -89,7 +90,8 @@ enum cmd_flags {
89 CMD_FLAG_ENCRYPTION_DISABLE = (1 << 7), 90 CMD_FLAG_ENCRYPTION_DISABLE = (1 << 7),
90 CMD_FLAG_ENCRYPTION_CHANGEPW = (1 << 8), 91 CMD_FLAG_ENCRYPTION_CHANGEPW = (1 << 8),
91 CMD_FLAG_FORCE_FULL_BACKUP = (1 << 9), 92 CMD_FLAG_FORCE_FULL_BACKUP = (1 << 9),
92 CMD_FLAG_ENABLE_CLOUD_BACKUP = (1 << 10) 93 CMD_FLAG_CLOUD_ENABLE = (1 << 10),
94 CMD_FLAG_CLOUD_DISABLE = (1 << 11)
93}; 95};
94 96
95static int backup_domain_changed = 0; 97static int backup_domain_changed = 0;
@@ -1278,13 +1280,13 @@ static void print_usage(int argc, char **argv)
1278 printf(" NOTE: password will be requested in interactive mode if omitted\n"); 1280 printf(" NOTE: password will be requested in interactive mode if omitted\n");
1279 printf(" changepw [OLD NEW] change backup password on target device\n"); 1281 printf(" changepw [OLD NEW] change backup password on target device\n");
1280 printf(" NOTE: passwords will be requested in interactive mode if omitted\n"); 1282 printf(" NOTE: passwords will be requested in interactive mode if omitted\n");
1283 printf(" cloud on|off\tenable or disable cloud use (requires iCloud account)\n");
1281 printf("\n"); 1284 printf("\n");
1282 printf("options:\n"); 1285 printf("options:\n");
1283 printf(" -d, --debug\t\tenable communication debugging\n"); 1286 printf(" -d, --debug\t\tenable communication debugging\n");
1284 printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n"); 1287 printf(" -u, --udid UDID\ttarget specific device by its 40-digit device UDID\n");
1285 printf(" -s, --source UDID\tuse backup data from device specified by UDID\n"); 1288 printf(" -s, --source UDID\tuse backup data from device specified by UDID\n");
1286 printf(" -i, --interactive\trequest passwords interactively\n"); 1289 printf(" -i, --interactive\trequest passwords interactively\n");
1287 printf(" -c, --cloud\t\tUse cloud storage using iCloud account of device\n");
1288 printf(" -h, --help\t\tprints usage information\n"); 1290 printf(" -h, --help\t\tprints usage information\n");
1289 printf("\n"); 1291 printf("\n");
1290} 1292}
@@ -1382,8 +1384,22 @@ int main(int argc, char *argv[])
1382 backup_password = strdup(argv[i]); 1384 backup_password = strdup(argv[i]);
1383 continue; 1385 continue;
1384 } 1386 }
1385 else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--cloud")) { 1387 else if (!strcmp(argv[i], "cloud")) {
1386 cmd_flags |= CMD_FLAG_ENABLE_CLOUD_BACKUP; 1388 cmd = CMD_CLOUD;
1389 i++;
1390 if (!argv[i]) {
1391 printf("No argument given for cloud command; requires either 'on' or 'off'.\n");
1392 print_usage(argc, argv);
1393 return -1;
1394 }
1395 if (!strcmp(argv[i], "on")) {
1396 cmd_flags |= CMD_FLAG_CLOUD_ENABLE;
1397 } else if (!strcmp(argv[i], "off")) {
1398 cmd_flags |= CMD_FLAG_CLOUD_DISABLE;
1399 } else {
1400 printf("Invalid argument '%s' for cloud command; must be either 'on' or 'off'.\n", argv[i]);
1401 }
1402 continue;
1387 } 1403 }
1388 else if (!strcmp(argv[i], "--full")) { 1404 else if (!strcmp(argv[i], "--full")) {
1389 cmd_flags |= CMD_FLAG_FORCE_FULL_BACKUP; 1405 cmd_flags |= CMD_FLAG_FORCE_FULL_BACKUP;
@@ -1474,7 +1490,7 @@ int main(int argc, char *argv[])
1474 return -1; 1490 return -1;
1475 } 1491 }
1476 1492
1477 if (cmd == CMD_CHANGEPW) { 1493 if (cmd == CMD_CHANGEPW || cmd == CMD_CLOUD) {
1478 backup_directory = strdup(".this_folder_is_not_present_on_purpose"); 1494 backup_directory = strdup(".this_folder_is_not_present_on_purpose");
1479 } else { 1495 } else {
1480 if (backup_directory == NULL) { 1496 if (backup_directory == NULL) {
@@ -1519,7 +1535,7 @@ int main(int argc, char *argv[])
1519 printf("ERROR: Can't get password input in non-interactive mode. Either pass password(s) on the command line, or enable interactive mode with -i or --interactive.\n"); 1535 printf("ERROR: Can't get password input in non-interactive mode. Either pass password(s) on the command line, or enable interactive mode with -i or --interactive.\n");
1520 return -1; 1536 return -1;
1521 } 1537 }
1522 } else { 1538 } else if (cmd != CMD_CLOUD) {
1523 /* backup directory must contain an Info.plist */ 1539 /* backup directory must contain an Info.plist */
1524 info_path = build_path(backup_directory, source_udid, "Info.plist", NULL); 1540 info_path = build_path(backup_directory, source_udid, "Info.plist", NULL);
1525 if (cmd == CMD_RESTORE) { 1541 if (cmd == CMD_RESTORE) {
@@ -1550,7 +1566,7 @@ int main(int argc, char *argv[])
1550 PRINT_VERBOSE(1, "Backup directory is \"%s\"\n", backup_directory); 1566 PRINT_VERBOSE(1, "Backup directory is \"%s\"\n", backup_directory);
1551 } 1567 }
1552 1568
1553 if (is_encrypted) { 1569 if (cmd != CMD_CLOUD && is_encrypted) {
1554 PRINT_VERBOSE(1, "This is an encrypted backup.\n"); 1570 PRINT_VERBOSE(1, "This is an encrypted backup.\n");
1555 if (backup_password == NULL) { 1571 if (backup_password == NULL) {
1556 if (interactive_mode) { 1572 if (interactive_mode) {
@@ -1639,7 +1655,7 @@ int main(int argc, char *argv[])
1639 } 1655 }
1640 1656
1641 /* verify existing Info.plist */ 1657 /* verify existing Info.plist */
1642 if (info_path && (stat(info_path, &st) == 0)) { 1658 if (info_path && (stat(info_path, &st) == 0) && cmd != CMD_CLOUD) {
1643 PRINT_VERBOSE(1, "Reading Info.plist from backup.\n"); 1659 PRINT_VERBOSE(1, "Reading Info.plist from backup.\n");
1644 plist_read_from_filename(&info_plist, info_path); 1660 plist_read_from_filename(&info_plist, info_path);
1645 1661
@@ -1656,21 +1672,6 @@ int main(int argc, char *argv[])
1656 } 1672 }
1657 } 1673 }
1658 1674
1659 opts = plist_new_dict();
1660 if (cmd_flags & CMD_FLAG_ENABLE_CLOUD_BACKUP) {
1661 PRINT_VERBOSE(1, "Enabling cloud backup for device...\n");
1662 } else {
1663 PRINT_VERBOSE(1, "Disabling cloud backup for device...\n");
1664 }
1665 plist_dict_insert_item(opts, "CloudBackupState", plist_new_bool(cmd & CMD_FLAG_ENABLE_CLOUD_BACKUP ? 1: 0));
1666 err = mobilebackup2_send_request(mobilebackup2, "EnableCloudBackup", udid, source_udid, opts);
1667 plist_free(opts);
1668 opts = NULL;
1669 if (err != MOBILEBACKUP2_E_SUCCESS) {
1670 printf("Error setting cloud backup state on device, error code %d\n", err);
1671 cmd = CMD_LEAVE;
1672 }
1673
1674 uint64_t lockfile = 0; 1675 uint64_t lockfile = 0;
1675 if (cmd == CMD_BACKUP) { 1676 if (cmd == CMD_BACKUP) {
1676 do_post_notification(device, NP_SYNC_WILL_START); 1677 do_post_notification(device, NP_SYNC_WILL_START);
@@ -1715,6 +1716,17 @@ int main(int argc, char *argv[])
1715checkpoint: 1716checkpoint:
1716 1717
1717 switch(cmd) { 1718 switch(cmd) {
1719 case CMD_CLOUD:
1720 opts = plist_new_dict();
1721 plist_dict_insert_item(opts, "CloudBackupState", plist_new_bool(cmd_flags & CMD_FLAG_CLOUD_ENABLE ? 1: 0));
1722 err = mobilebackup2_send_request(mobilebackup2, "EnableCloudBackup", udid, source_udid, opts);
1723 plist_free(opts);
1724 opts = NULL;
1725 if (err != MOBILEBACKUP2_E_SUCCESS) {
1726 printf("Error setting cloud backup state on device, error code %d\n", err);
1727 cmd = CMD_LEAVE;
1728 }
1729 break;
1718 case CMD_BACKUP: 1730 case CMD_BACKUP:
1719 PRINT_VERBOSE(1, "Starting backup...\n"); 1731 PRINT_VERBOSE(1, "Starting backup...\n");
1720 1732
@@ -2214,6 +2226,21 @@ files_out:
2214 2226
2215 /* report operation status to user */ 2227 /* report operation status to user */
2216 switch (cmd) { 2228 switch (cmd) {
2229 case CMD_CLOUD:
2230 if (cmd_flags & CMD_FLAG_CLOUD_ENABLE) {
2231 if (operation_ok) {
2232 PRINT_VERBOSE(1, "Cloud backup has been enabled successfully.\n");
2233 } else {
2234 PRINT_VERBOSE(1, "Could not enable cloud backup.\n");
2235 }
2236 } else if (cmd_flags & CMD_FLAG_CLOUD_DISABLE) {
2237 if (operation_ok) {
2238 PRINT_VERBOSE(1, "Cloud backup has been disabled successfully.\n");
2239 } else {
2240 PRINT_VERBOSE(1, "Could not disable cloud backup.\n");
2241 }
2242 }
2243 break;
2217 case CMD_BACKUP: 2244 case CMD_BACKUP:
2218 PRINT_VERBOSE(1, "Received %d files from device.\n", file_count); 2245 PRINT_VERBOSE(1, "Received %d files from device.\n", file_count);
2219 if (operation_ok && mb2_status_check_snapshot_state(backup_directory, udid, "finished")) { 2246 if (operation_ok && mb2_status_check_snapshot_state(backup_directory, udid, "finished")) {