summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicebackup.c29
-rw-r--r--tools/idevicebackup2.c63
2 files changed, 19 insertions, 73 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index c5315d2..67d82fd 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -234,33 +234,6 @@ static char *str_toupper(char* str)
234 return res; 234 return res;
235} 235}
236 236
237static char* build_path(const char* elem, ...)
238{
239 if (!elem) return NULL;
240 va_list args;
241 int len = strlen(elem)+1;
242 va_start(args, elem);
243 char *arg = va_arg(args, char*);
244 while (arg) {
245 len += strlen(arg)+1;
246 arg = va_arg(args, char*);
247 }
248 va_end(args);
249
250 char* out = (char*)malloc(len);
251 strcpy(out, elem);
252
253 va_start(args, elem);
254 arg = va_arg(args, char*);
255 while (arg) {
256 strcat(out, "/");
257 strcat(out, arg);
258 arg = va_arg(args, char*);
259 }
260 va_end(args);
261 return out;
262}
263
264static char* format_size_for_display(uint64_t size) 237static char* format_size_for_display(uint64_t size)
265{ 238{
266 char buf[32]; 239 char buf[32];
@@ -370,7 +343,7 @@ static char *mobilebackup_build_path(const char *backup_directory, const char *n
370 strcpy(filename, name); 343 strcpy(filename, name);
371 if (extension != NULL) 344 if (extension != NULL)
372 strcat(filename, extension); 345 strcat(filename, extension);
373 char *path = build_path(backup_directory, filename, NULL); 346 char *path = string_build_path(backup_directory, filename, NULL);
374 free(filename); 347 free(filename);
375 return path; 348 return path;
376} 349}
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index 4fde24f..209dfe6 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -199,33 +199,6 @@ static int mkdir_with_parents(const char *dir, int mode)
199 return res; 199 return res;
200} 200}
201 201
202static char* build_path(const char* elem, ...)
203{
204 if (!elem) return NULL;
205 va_list args;
206 int len = strlen(elem)+1;
207 va_start(args, elem);
208 char *arg = va_arg(args, char*);
209 while (arg) {
210 len += strlen(arg)+1;
211 arg = va_arg(args, char*);
212 }
213 va_end(args);
214
215 char* out = (char*)malloc(len);
216 strcpy(out, elem);
217
218 va_start(args, elem);
219 arg = va_arg(args, char*);
220 while (arg) {
221 strcat(out, "/");
222 strcat(out, arg);
223 arg = va_arg(args, char*);
224 }
225 va_end(args);
226 return out;
227}
228
229static char* format_size_for_display(uint64_t size) 202static char* format_size_for_display(uint64_t size)
230{ 203{
231 char buf[32]; 204 char buf[32];
@@ -357,7 +330,7 @@ static int mb2_status_check_snapshot_state(const char *path, const char *udid, c
357{ 330{
358 int ret = -1; 331 int ret = -1;
359 plist_t status_plist = NULL; 332 plist_t status_plist = NULL;
360 char *file_path = build_path(path, udid, "Status.plist", NULL); 333 char *file_path = string_build_path(path, udid, "Status.plist", NULL);
361 334
362 plist_read_from_filename(&status_plist, file_path); 335 plist_read_from_filename(&status_plist, file_path);
363 free(file_path); 336 free(file_path);
@@ -522,7 +495,7 @@ static int mb2_handle_send_file(mobilebackup2_client_t mobilebackup2, const char
522 uint32_t nlen = 0; 495 uint32_t nlen = 0;
523 uint32_t pathlen = strlen(path); 496 uint32_t pathlen = strlen(path);
524 uint32_t bytes = 0; 497 uint32_t bytes = 0;
525 char *localfile = build_path(backup_dir, path, NULL); 498 char *localfile = string_build_path(backup_dir, path, NULL);
526 char buf[32768]; 499 char buf[32768];
527#ifdef WIN32 500#ifdef WIN32
528 struct _stati64 fst; 501 struct _stati64 fst;
@@ -809,7 +782,7 @@ static int mb2_handle_receive_files(mobilebackup2_client_t mobilebackup2, plist_
809 bname = NULL; 782 bname = NULL;
810 } 783 }
811 784
812 bname = build_path(backup_dir, fname, NULL); 785 bname = string_build_path(backup_dir, fname, NULL);
813 786
814 if (fname != NULL) { 787 if (fname != NULL) {
815 free(fname); 788 free(fname);
@@ -942,7 +915,7 @@ static void mb2_handle_list_directory(mobilebackup2_client_t mobilebackup2, plis
942 return; 915 return;
943 } 916 }
944 917
945 char *path = build_path(backup_dir, str, NULL); 918 char *path = string_build_path(backup_dir, str, NULL);
946 free(str); 919 free(str);
947 920
948 plist_t dirlist = plist_new_dict(); 921 plist_t dirlist = plist_new_dict();
@@ -954,7 +927,7 @@ static void mb2_handle_list_directory(mobilebackup2_client_t mobilebackup2, plis
954 if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) { 927 if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) {
955 continue; 928 continue;
956 } 929 }
957 char *fpath = build_path(path, ep->d_name, NULL); 930 char *fpath = string_build_path(path, ep->d_name, NULL);
958 if (fpath) { 931 if (fpath) {
959 plist_t fdict = plist_new_dict(); 932 plist_t fdict = plist_new_dict();
960 struct stat st; 933 struct stat st;
@@ -995,7 +968,7 @@ static void mb2_handle_make_directory(mobilebackup2_client_t mobilebackup2, plis
995 char *errdesc = NULL; 968 char *errdesc = NULL;
996 plist_get_string_val(dir, &str); 969 plist_get_string_val(dir, &str);
997 970
998 char *newpath = build_path(backup_dir, str, NULL); 971 char *newpath = string_build_path(backup_dir, str, NULL);
999 free(str); 972 free(str);
1000 973
1001 if (mkdir_with_parents(newpath, 0755) < 0) { 974 if (mkdir_with_parents(newpath, 0755) < 0) {
@@ -1075,8 +1048,8 @@ static void mb2_copy_directory_by_path(const char *src, const char *dst)
1075 if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) { 1048 if ((strcmp(ep->d_name, ".") == 0) || (strcmp(ep->d_name, "..") == 0)) {
1076 continue; 1049 continue;
1077 } 1050 }
1078 char *srcpath = build_path(src, ep->d_name, NULL); 1051 char *srcpath = string_build_path(src, ep->d_name, NULL);
1079 char *dstpath = build_path(dst, ep->d_name, NULL); 1052 char *dstpath = string_build_path(dst, ep->d_name, NULL);
1080 if (srcpath && dstpath) { 1053 if (srcpath && dstpath) {
1081 /* copy file */ 1054 /* copy file */
1082 mb2_copy_file_by_path(srcpath, dstpath); 1055 mb2_copy_file_by_path(srcpath, dstpath);
@@ -1446,7 +1419,7 @@ int main(int argc, char *argv[])
1446 } 1419 }
1447 } else if (cmd != CMD_CLOUD) { 1420 } else if (cmd != CMD_CLOUD) {
1448 /* backup directory must contain an Info.plist */ 1421 /* backup directory must contain an Info.plist */
1449 info_path = build_path(backup_directory, source_udid, "Info.plist", NULL); 1422 info_path = string_build_path(backup_directory, source_udid, "Info.plist", NULL);
1450 if (cmd == CMD_RESTORE || cmd == CMD_UNBACK) { 1423 if (cmd == CMD_RESTORE || cmd == CMD_UNBACK) {
1451 if (stat(info_path, &st) != 0) { 1424 if (stat(info_path, &st) != 0) {
1452 idevice_free(device); 1425 idevice_free(device);
@@ -1454,7 +1427,7 @@ int main(int argc, char *argv[])
1454 printf("ERROR: Backup directory \"%s\" is invalid. No Info.plist found for UDID %s.\n", backup_directory, source_udid); 1427 printf("ERROR: Backup directory \"%s\" is invalid. No Info.plist found for UDID %s.\n", backup_directory, source_udid);
1455 return -1; 1428 return -1;
1456 } 1429 }
1457 char* manifest_path = build_path(backup_directory, source_udid, "Manifest.plist", NULL); 1430 char* manifest_path = string_build_path(backup_directory, source_udid, "Manifest.plist", NULL);
1458 if (stat(manifest_path, &st) != 0) { 1431 if (stat(manifest_path, &st) != 0) {
1459 free(info_path); 1432 free(info_path);
1460 } 1433 }
@@ -1647,20 +1620,20 @@ checkpoint:
1647 PRINT_VERBOSE(1, "Starting backup...\n"); 1620 PRINT_VERBOSE(1, "Starting backup...\n");
1648 1621
1649 /* make sure backup device sub-directory exists */ 1622 /* make sure backup device sub-directory exists */
1650 char* devbackupdir = build_path(backup_directory, source_udid, NULL); 1623 char* devbackupdir = string_build_path(backup_directory, source_udid, NULL);
1651 __mkdir(devbackupdir, 0755); 1624 __mkdir(devbackupdir, 0755);
1652 free(devbackupdir); 1625 free(devbackupdir);
1653 1626
1654 if (strcmp(source_udid, udid) != 0) { 1627 if (strcmp(source_udid, udid) != 0) {
1655 /* handle different source backup directory */ 1628 /* handle different source backup directory */
1656 // make sure target backup device sub-directory exists 1629 // make sure target backup device sub-directory exists
1657 devbackupdir = build_path(backup_directory, udid, NULL); 1630 devbackupdir = string_build_path(backup_directory, udid, NULL);
1658 __mkdir(devbackupdir, 0755); 1631 __mkdir(devbackupdir, 0755);
1659 free(devbackupdir); 1632 free(devbackupdir);
1660 1633
1661 // use Info.plist path in target backup folder */ 1634 // use Info.plist path in target backup folder */
1662 free(info_path); 1635 free(info_path);
1663 info_path = build_path(backup_directory, udid, "Info.plist", NULL); 1636 info_path = string_build_path(backup_directory, udid, "Info.plist", NULL);
1664 } 1637 }
1665 1638
1666 /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */ 1639 /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */
@@ -1942,9 +1915,9 @@ checkpoint:
1942 char *str = NULL; 1915 char *str = NULL;
1943 plist_get_string_val(val, &str); 1916 plist_get_string_val(val, &str);
1944 if (str) { 1917 if (str) {
1945 char *newpath = build_path(backup_directory, str, NULL); 1918 char *newpath = string_build_path(backup_directory, str, NULL);
1946 free(str); 1919 free(str);
1947 char *oldpath = build_path(backup_directory, key, NULL); 1920 char *oldpath = string_build_path(backup_directory, key, NULL);
1948 1921
1949#ifdef WIN32 1922#ifdef WIN32
1950 if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode)) 1923 if ((stat(newpath, &st) == 0) && S_ISDIR(st.st_mode))
@@ -2000,7 +1973,7 @@ checkpoint:
2000 suppress_warning = 1; 1973 suppress_warning = 1;
2001 } 1974 }
2002 } 1975 }
2003 char *newpath = build_path(backup_directory, str, NULL); 1976 char *newpath = string_build_path(backup_directory, str, NULL);
2004 free(str); 1977 free(str);
2005#ifdef WIN32 1978#ifdef WIN32
2006 int res = 0; 1979 int res = 0;
@@ -2044,8 +2017,8 @@ checkpoint:
2044 plist_get_string_val(srcpath, &src); 2017 plist_get_string_val(srcpath, &src);
2045 plist_get_string_val(dstpath, &dst); 2018 plist_get_string_val(dstpath, &dst);
2046 if (src && dst) { 2019 if (src && dst) {
2047 char *oldpath = build_path(backup_directory, src, NULL); 2020 char *oldpath = string_build_path(backup_directory, src, NULL);
2048 char *newpath = build_path(backup_directory, dst, NULL); 2021 char *newpath = string_build_path(backup_directory, dst, NULL);
2049 2022
2050 PRINT_VERBOSE(1, "Copying '%s' to '%s'\n", src, dst); 2023 PRINT_VERBOSE(1, "Copying '%s' to '%s'\n", src, dst);
2051 2024