diff options
| author | 2016-12-01 03:56:00 +0100 | |
|---|---|---|
| committer | 2016-12-01 03:56:00 +0100 | |
| commit | 9df4e695c55ddd319c5acaf7fa21f960afaa1e90 (patch) | |
| tree | 64c10405f2e1fb4b1ccbca96ed38d425621f7c20 /tools | |
| parent | 9083475cd899a09040b265863fcfee0b390c89b3 (diff) | |
| download | libimobiledevice-9df4e695c55ddd319c5acaf7fa21f960afaa1e90.tar.gz libimobiledevice-9df4e695c55ddd319c5acaf7fa21f960afaa1e90.tar.bz2 | |
ideviceprovision: Allow copying single profiles instead of all
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/ideviceprovision.c | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/tools/ideviceprovision.c b/tools/ideviceprovision.c index 7938580..79293bc 100644 --- a/tools/ideviceprovision.c +++ b/tools/ideviceprovision.c | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
| 29 | #include <string.h> | 29 | #include <string.h> |
| 30 | #include <sys/stat.h> | ||
| 30 | #include <errno.h> | 31 | #include <errno.h> |
| 31 | 32 | ||
| 32 | #ifdef WIN32 | 33 | #ifdef WIN32 |
| @@ -54,6 +55,9 @@ static void print_usage(int argc, char **argv) | |||
| 54 | printf(" copy PATH\tRetrieves all provisioning profiles from the device and\n"); | 55 | printf(" copy PATH\tRetrieves all provisioning profiles from the device and\n"); |
| 55 | printf(" \tstores them into the existing directory specified by PATH.\n"); | 56 | printf(" \tstores them into the existing directory specified by PATH.\n"); |
| 56 | printf(" \tThe files will be stored as UUID.mobileprovision\n"); | 57 | printf(" \tThe files will be stored as UUID.mobileprovision\n"); |
| 58 | printf(" copy UUID PATH Retrieves the provisioning profile identified by UUID\n"); | ||
| 59 | printf(" \tfrom the device and stores it into the exisiting directory\n"); | ||
| 60 | printf(" \tspecified by PATH. The file will be stored as UUID.mobileprovision.\n"); | ||
| 57 | printf(" remove UUID\tRemoves the provisioning profile identified by UUID.\n"); | 61 | printf(" remove UUID\tRemoves the provisioning profile identified by UUID.\n"); |
| 58 | printf(" dump FILE\tPrints detailed information about the provisioning profile\n"); | 62 | printf(" dump FILE\tPrints detailed information about the provisioning profile\n"); |
| 59 | printf(" \tspecified by FILE.\n\n"); | 63 | printf(" \tspecified by FILE.\n\n"); |
| @@ -261,6 +265,7 @@ int main(int argc, char *argv[]) | |||
| 261 | int output_xml = 0; | 265 | int output_xml = 0; |
| 262 | const char* udid = NULL; | 266 | const char* udid = NULL; |
| 263 | const char* param = NULL; | 267 | const char* param = NULL; |
| 268 | const char* param2 = NULL; | ||
| 264 | 269 | ||
| 265 | /* parse cmdline args */ | 270 | /* parse cmdline args */ |
| 266 | for (i = 1; i < argc; i++) { | 271 | for (i = 1; i < argc; i++) { |
| @@ -298,6 +303,10 @@ int main(int argc, char *argv[]) | |||
| 298 | } | 303 | } |
| 299 | param = argv[i]; | 304 | param = argv[i]; |
| 300 | op = OP_COPY; | 305 | op = OP_COPY; |
| 306 | i++; | ||
| 307 | if (argv[i] && (strlen(argv[i]) > 0)) { | ||
| 308 | param2 = argv[i]; | ||
| 309 | } | ||
| 301 | continue; | 310 | continue; |
| 302 | } | 311 | } |
| 303 | else if (!strcmp(argv[i], "remove")) { | 312 | else if (!strcmp(argv[i], "remove")) { |
| @@ -375,8 +384,9 @@ int main(int argc, char *argv[]) | |||
| 375 | return res; | 384 | return res; |
| 376 | } else if (op == OP_COPY) { | 385 | } else if (op == OP_COPY) { |
| 377 | struct stat st; | 386 | struct stat st; |
| 378 | if ((stat(param, &st) < 0) || !S_ISDIR(st.st_mode)) { | 387 | const char *checkdir = (param2) ? param2 : param; |
| 379 | fprintf(stderr, "ERROR: %s does not exist or is not a directory!\n", param); | 388 | if ((stat(checkdir, &st) < 0) || !S_ISDIR(st.st_mode)) { |
| 389 | fprintf(stderr, "ERROR: %s does not exist or is not a directory!\n", checkdir); | ||
| 380 | return -1; | 390 | return -1; |
| 381 | } | 391 | } |
| 382 | } | 392 | } |
| @@ -473,10 +483,13 @@ int main(int argc, char *argv[]) | |||
| 473 | merr = misagent_copy_all(mis, &profiles); | 483 | merr = misagent_copy_all(mis, &profiles); |
| 474 | } | 484 | } |
| 475 | if (merr == MISAGENT_E_SUCCESS) { | 485 | if (merr == MISAGENT_E_SUCCESS) { |
| 486 | int found_match = 0; | ||
| 476 | uint32_t num_profiles = plist_array_get_size(profiles); | 487 | uint32_t num_profiles = plist_array_get_size(profiles); |
| 477 | printf("Device has %d provisioning %s installed:\n", num_profiles, (num_profiles == 1) ? "profile" : "profiles"); | 488 | if (op == OP_LIST || !param2) { |
| 489 | printf("Device has %d provisioning %s installed:\n", num_profiles, (num_profiles == 1) ? "profile" : "profiles"); | ||
| 490 | } | ||
| 478 | uint32_t j; | 491 | uint32_t j; |
| 479 | for (j = 0; j < num_profiles; j++) { | 492 | for (j = 0; !found_match && j < num_profiles; j++) { |
| 480 | char* p_name = NULL; | 493 | char* p_name = NULL; |
| 481 | char* p_uuid = NULL; | 494 | char* p_uuid = NULL; |
| 482 | plist_t profile = plist_array_get_item(profiles, j); | 495 | plist_t profile = plist_array_get_item(profiles, j); |
| @@ -492,13 +505,22 @@ int main(int argc, char *argv[]) | |||
| 492 | plist_get_string_val(node, &p_uuid); | 505 | plist_get_string_val(node, &p_uuid); |
| 493 | } | 506 | } |
| 494 | } | 507 | } |
| 508 | if (param2) { | ||
| 509 | if (p_uuid && !strcmp(p_uuid, param)) { | ||
| 510 | found_match = 1; | ||
| 511 | } else { | ||
| 512 | free(p_uuid); | ||
| 513 | free(p_name); | ||
| 514 | continue; | ||
| 515 | } | ||
| 516 | } | ||
| 495 | printf("%s - %s\n", (p_uuid) ? p_uuid : "(unknown id)", (p_name) ? p_name : "(no name)"); | 517 | printf("%s - %s\n", (p_uuid) ? p_uuid : "(unknown id)", (p_name) ? p_name : "(no name)"); |
| 496 | if (op == OP_COPY) { | 518 | if (op == OP_COPY) { |
| 497 | char pfname[512]; | 519 | char pfname[512]; |
| 498 | if (p_uuid) { | 520 | if (p_uuid) { |
| 499 | sprintf(pfname, "%s/%s.mobileprovision", param, p_uuid); | 521 | sprintf(pfname, "%s/%s.mobileprovision", (param2) ? param2 : param, p_uuid); |
| 500 | } else { | 522 | } else { |
| 501 | sprintf(pfname, "%s/profile%d.mobileprovision", param, j); | 523 | sprintf(pfname, "%s/profile%d.mobileprovision", (param2) ? param2 : param, j); |
| 502 | } | 524 | } |
| 503 | FILE* f = fopen(pfname, "wb"); | 525 | FILE* f = fopen(pfname, "wb"); |
| 504 | if (f) { | 526 | if (f) { |
| @@ -515,6 +537,10 @@ int main(int argc, char *argv[]) | |||
| 515 | free(p_uuid); | 537 | free(p_uuid); |
| 516 | free(p_name); | 538 | free(p_name); |
| 517 | } | 539 | } |
| 540 | if (param2 && !found_match) { | ||
| 541 | fprintf(stderr, "Profile '%s' was not found on the device.\n", param); | ||
| 542 | res = -1; | ||
| 543 | } | ||
| 518 | } else { | 544 | } else { |
| 519 | int sc = misagent_get_status_code(mis); | 545 | int sc = misagent_get_status_code(mis); |
| 520 | fprintf(stderr, "Could not get installed profiles from device, status code: 0x%x\n", sc); | 546 | fprintf(stderr, "Could not get installed profiles from device, status code: 0x%x\n", sc); |
