diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lockdown.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 0623469..11f3c85 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * lockdown.c | 2 | * lockdown.c |
| 3 | * com.apple.mobile.lockdownd service implementation. | 3 | * com.apple.mobile.lockdownd service implementation. |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2010 Bryan Forbes All Rights Reserved. | ||
| 5 | * Copyright (c) 2008 Zach C. All Rights Reserved. | 6 | * Copyright (c) 2008 Zach C. All Rights Reserved. |
| 6 | * | 7 | * |
| 7 | * This library is free software; you can redistribute it and/or | 8 | * This library is free software; you can redistribute it and/or |
| @@ -21,6 +22,10 @@ | |||
| 21 | 22 | ||
| 22 | #include <string.h> | 23 | #include <string.h> |
| 23 | #include <stdlib.h> | 24 | #include <stdlib.h> |
| 25 | #define _GNU_SOURCE 1 | ||
| 26 | #define __USE_GNU 1 | ||
| 27 | #include <stdio.h> | ||
| 28 | #include <ctype.h> | ||
| 24 | #include <glib.h> | 29 | #include <glib.h> |
| 25 | #include <libtasn1.h> | 30 | #include <libtasn1.h> |
| 26 | #include <gnutls/x509.h> | 31 | #include <gnutls/x509.h> |
| @@ -1506,3 +1511,109 @@ lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) | |||
| 1506 | return ret; | 1511 | return ret; |
| 1507 | } | 1512 | } |
| 1508 | 1513 | ||
| 1514 | static void str_remove_spaces(char *source) | ||
| 1515 | { | ||
| 1516 | char *dest = source; | ||
| 1517 | while (*source != 0) { | ||
| 1518 | if (!isspace(*source)) { | ||
| 1519 | *dest++ = *source; /* copy */ | ||
| 1520 | } | ||
| 1521 | source++; | ||
| 1522 | } | ||
| 1523 | *dest = 0; | ||
| 1524 | } | ||
| 1525 | |||
| 1526 | lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count) | ||
| 1527 | { | ||
| 1528 | if (!client) | ||
| 1529 | return LOCKDOWN_E_INVALID_ARG; | ||
| 1530 | |||
| 1531 | if (!client->session_id) | ||
| 1532 | return LOCKDOWN_E_NO_RUNNING_SESSION; | ||
| 1533 | |||
| 1534 | plist_t dict = NULL; | ||
| 1535 | plist_dict_iter iter = NULL; | ||
| 1536 | lockdownd_error_t err = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 1537 | |||
| 1538 | char *key = NULL; | ||
| 1539 | plist_t value = NULL; | ||
| 1540 | |||
| 1541 | char **newlist = NULL; | ||
| 1542 | int newcount = 0; | ||
| 1543 | |||
| 1544 | *classes = NULL; | ||
| 1545 | *count = 0; | ||
| 1546 | |||
| 1547 | err = lockdownd_get_value(client, "com.apple.mobile.tethered_sync", NULL, &dict); | ||
| 1548 | if (err != LOCKDOWN_E_SUCCESS) { | ||
| 1549 | if (dict) { | ||
| 1550 | plist_free(dict); | ||
| 1551 | } | ||
| 1552 | return err; | ||
| 1553 | } | ||
| 1554 | |||
| 1555 | if (plist_get_node_type(dict) != PLIST_DICT) { | ||
| 1556 | plist_free(dict); | ||
| 1557 | return LOCKDOWN_E_PLIST_ERROR; | ||
| 1558 | } | ||
| 1559 | |||
| 1560 | plist_dict_new_iter(dict, &iter); | ||
| 1561 | |||
| 1562 | plist_dict_next_item(dict, iter, &key, &value); | ||
| 1563 | while (key && value) { | ||
| 1564 | int add_to_list = 0; | ||
| 1565 | plist_t disabled = NULL; | ||
| 1566 | |||
| 1567 | disabled = plist_dict_get_item(value, "DisableTethered"); | ||
| 1568 | |||
| 1569 | if (!disabled) { | ||
| 1570 | add_to_list = 1; | ||
| 1571 | } else { | ||
| 1572 | if (plist_get_node_type(disabled) == PLIST_BOOLEAN) { | ||
| 1573 | uint8_t val = 0; | ||
| 1574 | plist_get_bool_val(disabled, &val); | ||
| 1575 | add_to_list = val > 0 ? 0 : 1; | ||
| 1576 | } else { | ||
| 1577 | uint64_t val = 0; | ||
| 1578 | plist_get_uint_val(disabled, &val); | ||
| 1579 | add_to_list = val > 0 ? 0 : 1; | ||
| 1580 | } | ||
| 1581 | } | ||
| 1582 | |||
| 1583 | if (add_to_list) { | ||
| 1584 | newlist = realloc(*classes, sizeof(char*) * (newcount+1)); | ||
| 1585 | str_remove_spaces(key); | ||
| 1586 | asprintf(&newlist[newcount++], "com.apple.%s", key); | ||
| 1587 | *classes = newlist; | ||
| 1588 | } | ||
| 1589 | free(key); | ||
| 1590 | key = NULL; | ||
| 1591 | value = NULL; | ||
| 1592 | plist_dict_next_item(dict, iter, &key, &value); | ||
| 1593 | } | ||
| 1594 | |||
| 1595 | *count = newcount; | ||
| 1596 | newlist = realloc(*classes, sizeof(char*) * (newcount+1)); | ||
| 1597 | newlist[newcount] = NULL; | ||
| 1598 | *classes = newlist; | ||
| 1599 | |||
| 1600 | if (iter) { | ||
| 1601 | free(iter); | ||
| 1602 | } | ||
| 1603 | if (dict) { | ||
| 1604 | plist_free(dict); | ||
| 1605 | } | ||
| 1606 | return LOCKDOWN_E_SUCCESS; | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | lockdownd_error_t lockdownd_data_classes_free(char **classes) | ||
| 1610 | { | ||
| 1611 | if (classes) { | ||
| 1612 | int i = 0; | ||
| 1613 | while (classes[i++]) { | ||
| 1614 | free(classes[i]); | ||
| 1615 | } | ||
| 1616 | free(classes); | ||
| 1617 | } | ||
| 1618 | return LOCKDOWN_E_SUCCESS; | ||
| 1619 | } | ||
