diff options
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 205 |
1 files changed, 123 insertions, 82 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 29dde02..12cefa5 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -2,7 +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) 2014 Martin Szulecki All Rights Reserved. | 5 | * Copyright (c) 2009-2015 Martin Szulecki All Rights Reserved. |
| 6 | * Copyright (c) 2014 Nikias Bassen. All Rights Reserved. | 6 | * Copyright (c) 2014 Nikias Bassen. All Rights Reserved. |
| 7 | * Copyright (c) 2010 Bryan Forbes All Rights Reserved. | 7 | * Copyright (c) 2010 Bryan Forbes All Rights Reserved. |
| 8 | * Copyright (c) 2008 Zach C. All Rights Reserved. | 8 | * Copyright (c) 2008 Zach C. All Rights Reserved. |
| @@ -57,8 +57,75 @@ | |||
| 57 | #define sleep(x) Sleep(x*1000) | 57 | #define sleep(x) Sleep(x*1000) |
| 58 | #endif | 58 | #endif |
| 59 | 59 | ||
| 60 | #define RESULT_SUCCESS 0 | 60 | /** |
| 61 | #define RESULT_FAILURE 1 | 61 | * Convert an error string identifier to a lockdownd_error_t value. |
| 62 | * Used internally to get correct error codes from a response. | ||
| 63 | * | ||
| 64 | * @param name The error name to convert. | ||
| 65 | * | ||
| 66 | * @return A matching lockdownd_error_t error code, | ||
| 67 | * LOCKDOWN_E_UNKNOWN_ERROR otherwise. | ||
| 68 | */ | ||
| 69 | static lockdownd_error_t lockdownd_strtoerr(const char* name) | ||
| 70 | { | ||
| 71 | lockdownd_error_t err = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 72 | |||
| 73 | if (strcmp(name, "InvalidResponse") == 0) { | ||
| 74 | err = LOCKDOWN_E_INVALID_RESPONSE; | ||
| 75 | } else if (strcmp(name, "MissingKey") == 0) { | ||
| 76 | err = LOCKDOWN_E_MISSING_KEY; | ||
| 77 | } else if (strcmp(name, "MissingValue") == 0) { | ||
| 78 | err = LOCKDOWN_E_MISSING_VALUE; | ||
| 79 | } else if (strcmp(name, "GetProhibited") == 0) { | ||
| 80 | err = LOCKDOWN_E_GET_PROHIBITED; | ||
| 81 | } else if (strcmp(name, "SetProhibited") == 0) { | ||
| 82 | err = LOCKDOWN_E_SET_PROHIBITED; | ||
| 83 | } else if (strcmp(name, "RemoveProhibited") == 0) { | ||
| 84 | err = LOCKDOWN_E_REMOVE_PROHIBITED; | ||
| 85 | } else if (strcmp(name, "ImmutableValue") == 0) { | ||
| 86 | err = LOCKDOWN_E_IMMUTABLE_VALUE; | ||
| 87 | } else if (strcmp(name, "PasswordProtected") == 0) { | ||
| 88 | err = LOCKDOWN_E_PASSWORD_PROTECTED; | ||
| 89 | } else if (strcmp(name, "UserDeniedPairing") == 0) { | ||
| 90 | err = LOCKDOWN_E_USER_DENIED_PAIRING; | ||
| 91 | } else if (strcmp(name, "PairingDialogResponsePending") == 0) { | ||
| 92 | err = LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING; | ||
| 93 | } else if (strcmp(name, "MissingHostID") == 0) { | ||
| 94 | err = LOCKDOWN_E_MISSING_HOST_ID; | ||
| 95 | } else if (strcmp(name, "InvalidHostID") == 0) { | ||
| 96 | err = LOCKDOWN_E_INVALID_HOST_ID; | ||
| 97 | } else if (strcmp(name, "SessionActive") == 0) { | ||
| 98 | err = LOCKDOWN_E_SESSION_ACTIVE; | ||
| 99 | } else if (strcmp(name, "SessionInactive") == 0) { | ||
| 100 | err = LOCKDOWN_E_SESSION_INACTIVE; | ||
| 101 | } else if (strcmp(name, "MissingSessionID") == 0) { | ||
| 102 | err = LOCKDOWN_E_MISSING_SESSION_ID; | ||
| 103 | } else if (strcmp(name, "InvalidSessionID") == 0) { | ||
| 104 | err = LOCKDOWN_E_INVALID_SESSION_ID; | ||
| 105 | } else if (strcmp(name, "MissingService") == 0) { | ||
| 106 | err = LOCKDOWN_E_MISSING_SERVICE; | ||
| 107 | } else if (strcmp(name, "InvalidService") == 0) { | ||
| 108 | err = LOCKDOWN_E_INVALID_SERVICE; | ||
| 109 | } else if (strcmp(name, "ServiceLimit") == 0) { | ||
| 110 | err = LOCKDOWN_E_SERVICE_LIMIT; | ||
| 111 | } else if (strcmp(name, "MissingPairRecord") == 0) { | ||
| 112 | err = LOCKDOWN_E_MISSING_PAIR_RECORD; | ||
| 113 | } else if (strcmp(name, "SavePairRecordFailed") == 0) { | ||
| 114 | err = LOCKDOWN_E_SAVE_PAIR_RECORD_FAILED; | ||
| 115 | } else if (strcmp(name, "InvalidPairRecord") == 0) { | ||
| 116 | err = LOCKDOWN_E_INVALID_PAIR_RECORD; | ||
| 117 | } else if (strcmp(name, "InvalidActivationRecord") == 0) { | ||
| 118 | err = LOCKDOWN_E_INVALID_ACTIVATION_RECORD; | ||
| 119 | } else if (strcmp(name, "MissingActivationRecord") == 0) { | ||
| 120 | err = LOCKDOWN_E_MISSING_ACTIVATION_RECORD; | ||
| 121 | } else if (strcmp(name, "ServiceProhibited") == 0) { | ||
| 122 | err = LOCKDOWN_E_SERVICE_PROHIBITED; | ||
| 123 | } else if (strcmp(name, "EscrowLocked") == 0) { | ||
| 124 | err = LOCKDOWN_E_ESCROW_LOCKED; | ||
| 125 | } | ||
| 126 | |||
| 127 | return err; | ||
| 128 | } | ||
| 62 | 129 | ||
| 63 | /** | 130 | /** |
| 64 | * Internally used function for checking the result from lockdown's answer | 131 | * Internally used function for checking the result from lockdown's answer |
| @@ -68,30 +135,34 @@ | |||
| 68 | * @param query_match Name of the request to match or NULL if no match is | 135 | * @param query_match Name of the request to match or NULL if no match is |
| 69 | * required. | 136 | * required. |
| 70 | * | 137 | * |
| 71 | * @return RESULT_SUCCESS when the result is 'Success', | 138 | * @return LOCKDOWN_E_SUCCESS when the result is 'Success', |
| 72 | * RESULT_FAILURE when the result is 'Failure', | 139 | * LOCKDOWN_E_UNKNOWN_ERROR when the result is 'Failure', |
| 73 | * or a negative value if an error occured during evaluation. | 140 | * or a specific error code if derieved from the result. |
| 74 | */ | 141 | */ |
| 75 | static int lockdown_check_result(plist_t dict, const char *query_match) | 142 | static lockdownd_error_t lockdown_check_result(plist_t dict, const char *query_match) |
| 76 | { | 143 | { |
| 77 | int ret = -1; | 144 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 78 | 145 | ||
| 79 | plist_t query_node = plist_dict_get_item(dict, "Request"); | 146 | plist_t query_node = plist_dict_get_item(dict, "Request"); |
| 80 | if (!query_node) { | 147 | if (!query_node) { |
| 81 | return ret; | 148 | return ret; |
| 82 | } | 149 | } |
| 150 | |||
| 83 | if (plist_get_node_type(query_node) != PLIST_STRING) { | 151 | if (plist_get_node_type(query_node) != PLIST_STRING) { |
| 84 | return ret; | 152 | return ret; |
| 85 | } else { | 153 | } else { |
| 86 | char *query_value = NULL; | 154 | char *query_value = NULL; |
| 155 | |||
| 87 | plist_get_string_val(query_node, &query_value); | 156 | plist_get_string_val(query_node, &query_value); |
| 88 | if (!query_value) { | 157 | if (!query_value) { |
| 89 | return ret; | 158 | return ret; |
| 90 | } | 159 | } |
| 160 | |||
| 91 | if (query_match && (strcmp(query_value, query_match) != 0)) { | 161 | if (query_match && (strcmp(query_value, query_match) != 0)) { |
| 92 | free(query_value); | 162 | free(query_value); |
| 93 | return ret; | 163 | return ret; |
| 94 | } | 164 | } |
| 165 | |||
| 95 | free(query_value); | 166 | free(query_value); |
| 96 | } | 167 | } |
| 97 | 168 | ||
| @@ -103,39 +174,43 @@ static int lockdown_check_result(plist_t dict, const char *query_match) | |||
| 103 | if (err_node) { | 174 | if (err_node) { |
| 104 | if (plist_get_node_type(err_node) == PLIST_STRING) { | 175 | if (plist_get_node_type(err_node) == PLIST_STRING) { |
| 105 | char *err_value = NULL; | 176 | char *err_value = NULL; |
| 177 | |||
| 106 | plist_get_string_val(err_node, &err_value); | 178 | plist_get_string_val(err_node, &err_value); |
| 107 | if (err_value) { | 179 | if (err_value) { |
| 108 | debug_info("ERROR: %s", err_value); | 180 | debug_info("ERROR: %s", err_value); |
| 181 | ret = lockdownd_strtoerr(err_value); | ||
| 109 | free(err_value); | 182 | free(err_value); |
| 110 | } else { | 183 | } else { |
| 111 | debug_info("ERROR: unknown error occured"); | 184 | debug_info("ERROR: unknown error occured"); |
| 112 | } | 185 | } |
| 113 | } | 186 | } |
| 114 | return RESULT_FAILURE; | 187 | return ret; |
| 115 | } | 188 | } |
| 116 | return RESULT_SUCCESS; | 189 | |
| 190 | ret = LOCKDOWN_E_SUCCESS; | ||
| 191 | |||
| 192 | return ret; | ||
| 117 | } | 193 | } |
| 118 | 194 | ||
| 119 | plist_type result_type = plist_get_node_type(result_node); | 195 | plist_type result_type = plist_get_node_type(result_node); |
| 120 | |||
| 121 | if (result_type == PLIST_STRING) { | 196 | if (result_type == PLIST_STRING) { |
| 122 | |||
| 123 | char *result_value = NULL; | 197 | char *result_value = NULL; |
| 124 | 198 | ||
| 125 | plist_get_string_val(result_node, &result_value); | 199 | plist_get_string_val(result_node, &result_value); |
| 126 | |||
| 127 | if (result_value) { | 200 | if (result_value) { |
| 128 | if (!strcmp(result_value, "Success")) { | 201 | if (!strcmp(result_value, "Success")) { |
| 129 | ret = RESULT_SUCCESS; | 202 | ret = LOCKDOWN_E_SUCCESS; |
| 130 | } else if (!strcmp(result_value, "Failure")) { | 203 | } else if (!strcmp(result_value, "Failure")) { |
| 131 | ret = RESULT_FAILURE; | 204 | ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 132 | } else { | 205 | } else { |
| 133 | debug_info("ERROR: unknown result value '%s'", result_value); | 206 | debug_info("ERROR: unknown result value '%s'", result_value); |
| 134 | } | 207 | } |
| 135 | } | 208 | } |
| 209 | |||
| 136 | if (result_value) | 210 | if (result_value) |
| 137 | free(result_value); | 211 | free(result_value); |
| 138 | } | 212 | } |
| 213 | |||
| 139 | return ret; | 214 | return ret; |
| 140 | } | 215 | } |
| 141 | 216 | ||
| @@ -185,10 +260,9 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_stop_session(lockdownd_client_t | |||
| 185 | return LOCKDOWN_E_PLIST_ERROR; | 260 | return LOCKDOWN_E_PLIST_ERROR; |
| 186 | } | 261 | } |
| 187 | 262 | ||
| 188 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | 263 | ret = lockdown_check_result(dict, "StopSession"); |
| 189 | if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { | 264 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 190 | debug_info("success"); | 265 | debug_info("success"); |
| 191 | ret = LOCKDOWN_E_SUCCESS; | ||
| 192 | } | 266 | } |
| 193 | 267 | ||
| 194 | plist_free(dict); | 268 | plist_free(dict); |
| @@ -374,12 +448,11 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t cl | |||
| 374 | if (ret != LOCKDOWN_E_SUCCESS) | 448 | if (ret != LOCKDOWN_E_SUCCESS) |
| 375 | return ret; | 449 | return ret; |
| 376 | 450 | ||
| 377 | if (lockdown_check_result(dict, "GetValue") == RESULT_SUCCESS) { | 451 | ret = lockdown_check_result(dict, "GetValue"); |
| 452 | if (ret == LOCKDOWN_E_SUCCESS) { | ||
| 378 | debug_info("success"); | 453 | debug_info("success"); |
| 379 | ret = LOCKDOWN_E_SUCCESS; | ||
| 380 | } else { | ||
| 381 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | ||
| 382 | } | 454 | } |
| 455 | |||
| 383 | if (ret != LOCKDOWN_E_SUCCESS) { | 456 | if (ret != LOCKDOWN_E_SUCCESS) { |
| 384 | plist_free(dict); | 457 | plist_free(dict); |
| 385 | return ret; | 458 | return ret; |
| @@ -430,9 +503,9 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_set_value(lockdownd_client_t cl | |||
| 430 | if (ret != LOCKDOWN_E_SUCCESS) | 503 | if (ret != LOCKDOWN_E_SUCCESS) |
| 431 | return ret; | 504 | return ret; |
| 432 | 505 | ||
| 433 | if (lockdown_check_result(dict, "SetValue") == RESULT_SUCCESS) { | 506 | ret = lockdown_check_result(dict, "SetValue"); |
| 507 | if (ret == LOCKDOWN_E_SUCCESS) { | ||
| 434 | debug_info("success"); | 508 | debug_info("success"); |
| 435 | ret = LOCKDOWN_E_SUCCESS; | ||
| 436 | } | 509 | } |
| 437 | 510 | ||
| 438 | if (ret != LOCKDOWN_E_SUCCESS) { | 511 | if (ret != LOCKDOWN_E_SUCCESS) { |
| @@ -477,9 +550,9 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_remove_value(lockdownd_client_t | |||
| 477 | if (ret != LOCKDOWN_E_SUCCESS) | 550 | if (ret != LOCKDOWN_E_SUCCESS) |
| 478 | return ret; | 551 | return ret; |
| 479 | 552 | ||
| 480 | if (lockdown_check_result(dict, "RemoveValue") == RESULT_SUCCESS) { | 553 | ret = lockdown_check_result(dict, "RemoveValue"); |
| 554 | if (ret == LOCKDOWN_E_SUCCESS) { | ||
| 481 | debug_info("success"); | 555 | debug_info("success"); |
| 482 | ret = LOCKDOWN_E_SUCCESS; | ||
| 483 | } | 556 | } |
| 484 | 557 | ||
| 485 | if (ret != LOCKDOWN_E_SUCCESS) { | 558 | if (ret != LOCKDOWN_E_SUCCESS) { |
| @@ -641,7 +714,7 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevi | |||
| 641 | ret = lockdownd_pair(client_loc, NULL); | 714 | ret = lockdownd_pair(client_loc, NULL); |
| 642 | if (LOCKDOWN_E_SUCCESS == ret) { | 715 | if (LOCKDOWN_E_SUCCESS == ret) { |
| 643 | ret = lockdownd_validate_pair(client_loc, NULL); | 716 | ret = lockdownd_validate_pair(client_loc, NULL); |
| 644 | } else if (LOCKDOWN_E_PAIRING_DIALOG_PENDING == ret) { | 717 | } else if (LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING == ret) { |
| 645 | debug_info("Device shows the pairing dialog."); | 718 | debug_info("Device shows the pairing dialog."); |
| 646 | } | 719 | } |
| 647 | } | 720 | } |
| @@ -762,7 +835,7 @@ leave: | |||
| 762 | /** | 835 | /** |
| 763 | * Function used internally by lockdownd_pair() and lockdownd_validate_pair() | 836 | * Function used internally by lockdownd_pair() and lockdownd_validate_pair() |
| 764 | * | 837 | * |
| 765 | * @param client The lockdown client to pair with. | 838 | * @param client The lockdown client |
| 766 | * @param pair_record The pair record to use for pairing. If NULL is passed, then | 839 | * @param pair_record The pair record to use for pairing. If NULL is passed, then |
| 767 | * the pair records from the current machine are used. New records will be | 840 | * the pair records from the current machine are used. New records will be |
| 768 | * generated automatically when pairing is done for the first time. | 841 | * generated automatically when pairing is done for the first time. |
| @@ -863,11 +936,11 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_ | |||
| 863 | if (strcmp(verb, "Unpair") == 0) { | 936 | if (strcmp(verb, "Unpair") == 0) { |
| 864 | /* workaround for Unpair giving back ValidatePair, | 937 | /* workaround for Unpair giving back ValidatePair, |
| 865 | * seems to be a bug in the device's fw */ | 938 | * seems to be a bug in the device's fw */ |
| 866 | if (lockdown_check_result(dict, NULL) != RESULT_SUCCESS) { | 939 | if (lockdown_check_result(dict, NULL) != LOCKDOWN_E_SUCCESS) { |
| 867 | ret = LOCKDOWN_E_PAIRING_FAILED; | 940 | ret = LOCKDOWN_E_PAIRING_FAILED; |
| 868 | } | 941 | } |
| 869 | } else { | 942 | } else { |
| 870 | if (lockdown_check_result(dict, verb) != RESULT_SUCCESS) { | 943 | if (lockdown_check_result(dict, verb) != LOCKDOWN_E_SUCCESS) { |
| 871 | ret = LOCKDOWN_E_PAIRING_FAILED; | 944 | ret = LOCKDOWN_E_PAIRING_FAILED; |
| 872 | } | 945 | } |
| 873 | } | 946 | } |
| @@ -915,15 +988,7 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_ | |||
| 915 | plist_get_string_val(error_node, &value); | 988 | plist_get_string_val(error_node, &value); |
| 916 | if (value) { | 989 | if (value) { |
| 917 | /* the first pairing fails if the device is password protected */ | 990 | /* the first pairing fails if the device is password protected */ |
| 918 | if (!strcmp(value, "PasswordProtected")) { | 991 | ret = lockdownd_strtoerr(value); |
| 919 | ret = LOCKDOWN_E_PASSWORD_PROTECTED; | ||
| 920 | } else if (!strcmp(value, "InvalidHostID")) { | ||
| 921 | ret = LOCKDOWN_E_INVALID_HOST_ID; | ||
| 922 | } else if (!strcmp(value, "UserDeniedPairing")) { | ||
| 923 | ret = LOCKDOWN_E_USER_DENIED_PAIRING; | ||
| 924 | } else if (!strcmp(value, "PairingDialogResponsePending")) { | ||
| 925 | ret = LOCKDOWN_E_PAIRING_DIALOG_PENDING; | ||
| 926 | } | ||
| 927 | free(value); | 992 | free(value); |
| 928 | } | 993 | } |
| 929 | 994 | ||
| @@ -982,12 +1047,14 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client | |||
| 982 | 1047 | ||
| 983 | ret = lockdownd_receive(client, &dict); | 1048 | ret = lockdownd_receive(client, &dict); |
| 984 | 1049 | ||
| 985 | if (lockdown_check_result(dict, "EnterRecovery") == RESULT_SUCCESS) { | 1050 | ret = lockdown_check_result(dict, "EnterRecovery"); |
| 1051 | if (ret == LOCKDOWN_E_SUCCESS) { | ||
| 986 | debug_info("success"); | 1052 | debug_info("success"); |
| 987 | ret = LOCKDOWN_E_SUCCESS; | ||
| 988 | } | 1053 | } |
| 1054 | |||
| 989 | plist_free(dict); | 1055 | plist_free(dict); |
| 990 | dict = NULL; | 1056 | dict = NULL; |
| 1057 | |||
| 991 | return ret; | 1058 | return ret; |
| 992 | } | 1059 | } |
| 993 | 1060 | ||
| @@ -1014,10 +1081,11 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_goodbye(lockdownd_client_t clie | |||
| 1014 | return LOCKDOWN_E_PLIST_ERROR; | 1081 | return LOCKDOWN_E_PLIST_ERROR; |
| 1015 | } | 1082 | } |
| 1016 | 1083 | ||
| 1017 | if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { | 1084 | ret = lockdown_check_result(dict, "Goodbye"); |
| 1085 | if (ret == LOCKDOWN_E_SUCCESS) { | ||
| 1018 | debug_info("success"); | 1086 | debug_info("success"); |
| 1019 | ret = LOCKDOWN_E_SUCCESS; | ||
| 1020 | } | 1087 | } |
| 1088 | |||
| 1021 | plist_free(dict); | 1089 | plist_free(dict); |
| 1022 | dict = NULL; | 1090 | dict = NULL; |
| 1023 | 1091 | ||
| @@ -1071,17 +1139,8 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_session(lockdownd_client_ | |||
| 1071 | if (!dict) | 1139 | if (!dict) |
| 1072 | return LOCKDOWN_E_PLIST_ERROR; | 1140 | return LOCKDOWN_E_PLIST_ERROR; |
| 1073 | 1141 | ||
| 1074 | if (lockdown_check_result(dict, "StartSession") == RESULT_FAILURE) { | 1142 | ret = lockdown_check_result(dict, "StartSession"); |
| 1075 | plist_t error_node = plist_dict_get_item(dict, "Error"); | 1143 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 1076 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { | ||
| 1077 | char *error = NULL; | ||
| 1078 | plist_get_string_val(error_node, &error); | ||
| 1079 | if (!strcmp(error, "InvalidHostID")) { | ||
| 1080 | ret = LOCKDOWN_E_INVALID_HOST_ID; | ||
| 1081 | } | ||
| 1082 | free(error); | ||
| 1083 | } | ||
| 1084 | } else { | ||
| 1085 | uint8_t use_ssl = 0; | 1144 | uint8_t use_ssl = 0; |
| 1086 | 1145 | ||
| 1087 | plist_t enable_ssl = plist_dict_get_item(dict, "EnableSessionSSL"); | 1146 | plist_t enable_ssl = plist_dict_get_item(dict, "EnableSessionSSL"); |
| @@ -1230,8 +1289,8 @@ static lockdownd_error_t lockdownd_do_start_service(lockdownd_client_t client, c | |||
| 1230 | if (!dict) | 1289 | if (!dict) |
| 1231 | return LOCKDOWN_E_PLIST_ERROR; | 1290 | return LOCKDOWN_E_PLIST_ERROR; |
| 1232 | 1291 | ||
| 1233 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | 1292 | ret = lockdown_check_result(dict, "StartService"); |
| 1234 | if (lockdown_check_result(dict, "StartService") == RESULT_SUCCESS) { | 1293 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 1235 | if (*service == NULL) | 1294 | if (*service == NULL) |
| 1236 | *service = (lockdownd_service_descriptor_t)malloc(sizeof(struct lockdownd_service_descriptor)); | 1295 | *service = (lockdownd_service_descriptor_t)malloc(sizeof(struct lockdownd_service_descriptor)); |
| 1237 | (*service)->port = 0; | 1296 | (*service)->port = 0; |
| @@ -1260,24 +1319,18 @@ static lockdownd_error_t lockdownd_do_start_service(lockdownd_client_t client, c | |||
| 1260 | (*service)->ssl_enabled = b; | 1319 | (*service)->ssl_enabled = b; |
| 1261 | } | 1320 | } |
| 1262 | } else { | 1321 | } else { |
| 1263 | ret = LOCKDOWN_E_START_SERVICE_FAILED; | ||
| 1264 | plist_t error_node = plist_dict_get_item(dict, "Error"); | 1322 | plist_t error_node = plist_dict_get_item(dict, "Error"); |
| 1265 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { | 1323 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { |
| 1266 | char *error = NULL; | 1324 | char *error = NULL; |
| 1267 | plist_get_string_val(error_node, &error); | 1325 | plist_get_string_val(error_node, &error); |
| 1268 | if (!strcmp(error, "InvalidService")) { | 1326 | ret = lockdownd_strtoerr(error); |
| 1269 | ret = LOCKDOWN_E_INVALID_SERVICE; | ||
| 1270 | } else if (!strcmp(error, "ServiceLimit")) { | ||
| 1271 | ret = LOCKDOWN_E_SERVICE_LIMIT; | ||
| 1272 | } else if (!strcmp(error, "NoRunningSession")) { | ||
| 1273 | ret = LOCKDOWN_E_NO_RUNNING_SESSION; | ||
| 1274 | } | ||
| 1275 | free(error); | 1327 | free(error); |
| 1276 | } | 1328 | } |
| 1277 | } | 1329 | } |
| 1278 | 1330 | ||
| 1279 | plist_free(dict); | 1331 | plist_free(dict); |
| 1280 | dict = NULL; | 1332 | dict = NULL; |
| 1333 | |||
| 1281 | return ret; | 1334 | return ret; |
| 1282 | } | 1335 | } |
| 1283 | 1336 | ||
| @@ -1319,23 +1372,11 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t cli | |||
| 1319 | return LOCKDOWN_E_PLIST_ERROR; | 1372 | return LOCKDOWN_E_PLIST_ERROR; |
| 1320 | } | 1373 | } |
| 1321 | 1374 | ||
| 1322 | ret = LOCKDOWN_E_ACTIVATION_FAILED; | 1375 | ret = lockdown_check_result(dict, "Activate"); |
| 1323 | if (lockdown_check_result(dict, "Activate") == RESULT_SUCCESS) { | 1376 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 1324 | debug_info("success"); | 1377 | debug_info("success"); |
| 1325 | ret = LOCKDOWN_E_SUCCESS; | ||
| 1326 | |||
| 1327 | } else { | ||
| 1328 | plist_t error_node = plist_dict_get_item(dict, "Error"); | ||
| 1329 | if (error_node && PLIST_STRING == plist_get_node_type(error_node)) { | ||
| 1330 | char *error = NULL; | ||
| 1331 | plist_get_string_val(error_node, &error); | ||
| 1332 | if (!strcmp(error, "InvalidActivationRecord")) { | ||
| 1333 | ret = LOCKDOWN_E_INVALID_ACTIVATION_RECORD; | ||
| 1334 | } | ||
| 1335 | free(error); | ||
| 1336 | } | ||
| 1337 | } | 1378 | } |
| 1338 | 1379 | ||
| 1339 | plist_free(dict); | 1380 | plist_free(dict); |
| 1340 | dict = NULL; | 1381 | dict = NULL; |
| 1341 | 1382 | ||
| @@ -1366,11 +1407,11 @@ LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_deactivate(lockdownd_client_t c | |||
| 1366 | return LOCKDOWN_E_PLIST_ERROR; | 1407 | return LOCKDOWN_E_PLIST_ERROR; |
| 1367 | } | 1408 | } |
| 1368 | 1409 | ||
| 1369 | ret = LOCKDOWN_E_UNKNOWN_ERROR; | 1410 | ret = lockdown_check_result(dict, "Deactivate"); |
| 1370 | if (lockdown_check_result(dict, "Deactivate") == RESULT_SUCCESS) { | 1411 | if (ret == LOCKDOWN_E_SUCCESS) { |
| 1371 | debug_info("success"); | 1412 | debug_info("success"); |
| 1372 | ret = LOCKDOWN_E_SUCCESS; | ||
| 1373 | } | 1413 | } |
| 1414 | |||
| 1374 | plist_free(dict); | 1415 | plist_free(dict); |
| 1375 | dict = NULL; | 1416 | dict = NULL; |
| 1376 | 1417 | ||
