summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/AFC.c67
-rw-r--r--src/MobileSync.c4
-rw-r--r--src/NotificationProxy.c1
-rw-r--r--src/lockdown.c95
-rw-r--r--src/userpref.c5
-rw-r--r--src/utils.c3
6 files changed, 79 insertions, 96 deletions
diff --git a/src/AFC.c b/src/AFC.c
index cd120fc..8cc88f1 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -39,11 +39,7 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15);
39 */ 39 */
40static void afc_lock(afc_client_t client) 40static void afc_lock(afc_client_t client)
41{ 41{
42 log_debug_msg("Locked\n"); 42 log_debug_msg("%s: Locked\n", __func__);
43 /*while (client->lock) {
44 usleep(500); // they say it's obsolete, but whatever
45 }
46 client->lock = 1; */
47 g_mutex_lock(client->mutex); 43 g_mutex_lock(client->mutex);
48} 44}
49 45
@@ -52,9 +48,8 @@ static void afc_lock(afc_client_t client)
52 * @param client The AFC 48 * @param client The AFC
53 */ 49 */
54static void afc_unlock(afc_client_t client) 50static void afc_unlock(afc_client_t client)
55{ // just to be pretty 51{
56 log_debug_msg("Unlocked\n"); 52 log_debug_msg("%s: Unlocked\n", __func__);
57 //client->lock = 0;
58 g_mutex_unlock(client->mutex); 53 g_mutex_unlock(client->mutex);
59} 54}
60 55
@@ -245,12 +240,12 @@ static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t l
245 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); 240 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket));
246 offset = client->afc_packet->this_length - sizeof(AFCPacket); 241 offset = client->afc_packet->this_length - sizeof(AFCPacket);
247 242
248 log_debug_msg("dispatch_AFC_packet: Offset: %i\n", offset); 243 log_debug_msg("%s: Offset: %i\n", __func__, offset);
249 if ((length) < (client->afc_packet->entire_length - client->afc_packet->this_length)) { 244 if ((length) < (client->afc_packet->entire_length - client->afc_packet->this_length)) {
250 log_debug_msg("dispatch_AFC_packet: Length did not resemble what it was supposed"); 245 log_debug_msg("%s: Length did not resemble what it was supposed", __func__);
251 log_debug_msg("to based on the packet.\n"); 246 log_debug_msg("to based on the packet.\n");
252 log_debug_msg("length minus offset: %i\n", length - offset); 247 log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset);
253 log_debug_msg("rest of packet: %i\n", client->afc_packet->entire_length - client->afc_packet->this_length); 248 log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length);
254 free(buffer); 249 free(buffer);
255 return -1; 250 return -1;
256 } 251 }
@@ -261,19 +256,19 @@ static int dispatch_AFC_packet(afc_client_t client, const char *data, uint64_t l
261 return bytes; 256 return bytes;
262 } 257 }
263 258
264 log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); 259 log_debug_msg("%s: sent the first now go with the second\n", __func__);
265 log_debug_msg("Length: %i\n", length - offset); 260 log_debug_msg("%s: Length: %i\n", __func__, length - offset);
266 log_debug_msg("Buffer: \n"); 261 log_debug_msg("%s: Buffer: \n", __func__);
267 log_debug_buffer(data + offset, length - offset); 262 log_debug_buffer(data + offset, length - offset);
268 263
269 usbmuxd_send(client->sfd, data + offset, length - offset, (uint32_t*)&bytes); 264 usbmuxd_send(client->sfd, data + offset, length - offset, (uint32_t*)&bytes);
270 return bytes; 265 return bytes;
271 } else { 266 } else {
272 log_debug_msg("dispatch_AFC_packet doin things the old way\n"); 267 log_debug_msg("%s: doin things the old way\n", __func__);
273 buffer = (char *) malloc(sizeof(char) * client->afc_packet->this_length); 268 buffer = (char *) malloc(sizeof(char) * client->afc_packet->this_length);
274 log_debug_msg("dispatch_AFC_packet packet length = %i\n", client->afc_packet->this_length); 269 log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length);
275 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket)); 270 memcpy(buffer, (char *) client->afc_packet, sizeof(AFCPacket));
276 log_debug_msg("dispatch_AFC_packet packet data follows\n"); 271 log_debug_msg("%s: packet data follows\n", __func__);
277 if (length > 0) { 272 if (length > 0) {
278 memcpy(buffer + sizeof(AFCPacket), data, length); 273 memcpy(buffer + sizeof(AFCPacket), data, length);
279 } 274 }
@@ -354,7 +349,7 @@ static int receive_AFC_data(afc_client_t client, char **dump_here)
354 } 349 }
355 } 350 }
356 351
357 log_debug_msg("%s: received AFC packet, full len=%lld, this len=%lld, operation=%lld\n", __func__, header.entire_length, header.this_length, header.operation); 352 log_debug_msg("%s: received AFC packet, full len=%lld, this len=%lld, operation=0x%llx\n", __func__, header.entire_length, header.this_length, header.operation);
358 353
359 entire_len = (uint32_t)header.entire_length - sizeof(AFCPacket); 354 entire_len = (uint32_t)header.entire_length - sizeof(AFCPacket);
360 this_len = (uint32_t)header.this_length - sizeof(AFCPacket); 355 this_len = (uint32_t)header.this_length - sizeof(AFCPacket);
@@ -758,7 +753,7 @@ afc_open_file(afc_client_t client, const char *filename,
758 free(data); 753 free(data);
759 754
760 if (bytes <= 0) { 755 if (bytes <= 0) {
761 log_debug_msg("afc_open_file: Didn't receive a response to the command\n"); 756 log_debug_msg("%s: Didn't receive a response to the command\n", __func__);
762 afc_unlock(client); 757 afc_unlock(client);
763 return IPHONE_E_NOT_ENOUGH_DATA; 758 return IPHONE_E_NOT_ENOUGH_DATA;
764 } 759 }
@@ -800,14 +795,14 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
800 795
801 if (!client || !client->afc_packet || client->sfd < 0 || handle == 0) 796 if (!client || !client->afc_packet || client->sfd < 0 || handle == 0)
802 return IPHONE_E_INVALID_ARG; 797 return IPHONE_E_INVALID_ARG;
803 log_debug_msg("afc_read_file called for length %i\n", length); 798 log_debug_msg("%s: called for length %i\n", __func__, length);
804 799
805 afc_lock(client); 800 afc_lock(client);
806 801
807 // Looping here to get around the maximum amount of data that 802 // Looping here to get around the maximum amount of data that
808 // recieve_AFC_data can handle 803 // recieve_AFC_data can handle
809 while (current_count < length) { 804 while (current_count < length) {
810 log_debug_msg("afc_read_file: current count is %i but length is %i\n", current_count, length); 805 log_debug_msg("%s: current count is %i but length is %i\n", __func__, current_count, length);
811 806
812 // Send the read command 807 // Send the read command
813 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); 808 AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket));
@@ -824,7 +819,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
824 } 819 }
825 // Receive the data 820 // Receive the data
826 bytes_loc = receive_AFC_data(client, &input); 821 bytes_loc = receive_AFC_data(client, &input);
827 log_debug_msg("afc_read_file: bytes returned: %i\n", bytes_loc); 822 log_debug_msg("%s: bytes returned: %i\n", __func__, bytes_loc);
828 if (bytes_loc < 0) { 823 if (bytes_loc < 0) {
829 afc_unlock(client); 824 afc_unlock(client);
830 return IPHONE_E_AFC_ERROR; 825 return IPHONE_E_AFC_ERROR;
@@ -837,7 +832,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
837 // success 832 // success
838 } else { 833 } else {
839 if (input) { 834 if (input) {
840 log_debug_msg("afc_read_file: %d\n", bytes_loc); 835 log_debug_msg("%s: %d\n", __func__, bytes_loc);
841 memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc); 836 memcpy(data + current_count, input, (bytes_loc > length) ? length : bytes_loc);
842 free(input); 837 free(input);
843 input = NULL; 838 input = NULL;
@@ -845,7 +840,7 @@ afc_read_file(afc_client_t client, uint64_t handle, char *data, int length, uint
845 } 840 }
846 } 841 }
847 } 842 }
848 log_debug_msg("afc_read_file: returning current_count as %i\n", current_count); 843 log_debug_msg("%s: returning current_count as %i\n", __func__, current_count);
849 844
850 afc_unlock(client); 845 afc_unlock(client);
851 *bytes = current_count; 846 *bytes = current_count;
@@ -878,7 +873,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
878 873
879 afc_lock(client); 874 afc_lock(client);
880 875
881 log_debug_msg("afc_write_file: Write length: %i\n", length); 876 log_debug_msg("%s: Write length: %i\n", __func__, length);
882 877
883 // Divide the file into segments. 878 // Divide the file into segments.
884 for (i = 0; i < segments; i++) { 879 for (i = 0; i < segments; i++) {
@@ -939,7 +934,7 @@ afc_write_file(afc_client_t client, uint64_t handle,
939 bytes_loc = receive_AFC_data(client, &acknowledgement); 934 bytes_loc = receive_AFC_data(client, &acknowledgement);
940 afc_unlock(client); 935 afc_unlock(client);
941 if (bytes_loc < 0) { 936 if (bytes_loc < 0) {
942 log_debug_msg("afc_write_file: uh oh?\n"); 937 log_debug_msg("%s: uh oh?\n", __func__);
943 } else { 938 } else {
944 free(acknowledgement); 939 free(acknowledgement);
945 } 940 }
@@ -961,7 +956,7 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
961 956
962 afc_lock(client); 957 afc_lock(client);
963 958
964 log_debug_msg("afc_close_file: File handle %i\n", handle); 959 log_debug_msg("%s: File handle %i\n", __func__, handle);
965 960
966 // Send command 961 // Send command
967 memcpy(buffer, &handle, sizeof(uint64_t)); 962 memcpy(buffer, &handle, sizeof(uint64_t));
@@ -971,18 +966,16 @@ iphone_error_t afc_close_file(afc_client_t client, uint64_t handle)
971 free(buffer); 966 free(buffer);
972 buffer = NULL; 967 buffer = NULL;
973 968
974 // FIXME: Is this necesary?
975 // client->afc_packet->entire_length = client->afc_packet->this_length
976 // = 0;
977
978 if (bytes <= 0) { 969 if (bytes <= 0) {
979 afc_unlock(client); 970 afc_unlock(client);
980 return IPHONE_E_UNKNOWN_ERROR; 971 return IPHONE_E_UNKNOWN_ERROR;
981 } 972 }
973
982 // Receive the response 974 // Receive the response
983 bytes = receive_AFC_data(client, &buffer); 975 bytes = receive_AFC_data(client, &buffer);
984 if (buffer) 976 if (buffer)
985 free(buffer); 977 free(buffer);
978
986 afc_unlock(client); 979 afc_unlock(client);
987 return IPHONE_E_SUCCESS; 980 return IPHONE_E_SUCCESS;
988} 981}
@@ -1008,7 +1001,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t
1008 1001
1009 afc_lock(client); 1002 afc_lock(client);
1010 1003
1011 log_debug_msg("afc_lock_file: File handle %i\n", handle); 1004 log_debug_msg("%s: file handle %i\n", __func__, handle);
1012 1005
1013 // Send command 1006 // Send command
1014 memcpy(buffer, &handle, sizeof(uint64_t)); 1007 memcpy(buffer, &handle, sizeof(uint64_t));
@@ -1022,7 +1015,7 @@ iphone_error_t afc_lock_file(afc_client_t client, uint64_t handle, afc_lock_op_t
1022 1015
1023 if (bytes <= 0) { 1016 if (bytes <= 0) {
1024 afc_unlock(client); 1017 afc_unlock(client);
1025 log_debug_msg("Could not send lock command\n"); 1018 log_debug_msg("%s: could not send lock command\n", __func__);
1026 return IPHONE_E_UNKNOWN_ERROR; 1019 return IPHONE_E_UNKNOWN_ERROR;
1027 } 1020 }
1028 // Receive the response 1021 // Receive the response
@@ -1194,9 +1187,9 @@ iphone_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, cons
1194 1187
1195 afc_lock(client); 1188 afc_lock(client);
1196 1189
1197 log_debug_msg("link type: %lld\n", type); 1190 log_debug_msg("%s: link type: %lld\n", __func__, type);
1198 log_debug_msg("target: %s, length:%d\n", target, strlen(target)); 1191 log_debug_msg("%s: target: %s, length:%d\n", __func__, target, strlen(target));
1199 log_debug_msg("linkname: %s, length:%d\n", linkname, strlen(linkname)); 1192 log_debug_msg("%s: linkname: %s, length:%d\n", __func__, linkname, strlen(linkname));
1200 1193
1201 // Send command 1194 // Send command
1202 memcpy(send, &type, 8); 1195 memcpy(send, &type, 8);
diff --git a/src/MobileSync.c b/src/MobileSync.c
index b9a1cb0..f544400 100644
--- a/src/MobileSync.c
+++ b/src/MobileSync.c
@@ -161,7 +161,7 @@ iphone_error_t mobilesync_recv(mobilesync_client_t client, plist_t * plist)
161 char *XMLContent = NULL; 161 char *XMLContent = NULL;
162 uint32_t length = 0; 162 uint32_t length = 0;
163 plist_to_xml(*plist, &XMLContent, &length); 163 plist_to_xml(*plist, &XMLContent, &length);
164 log_dbg_msg(DBGMASK_MOBILESYNC, "Recv msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); 164 log_dbg_msg(DBGMASK_MOBILESYNC, "%s: plist size: %i\nbuffer :\n%s\n", __func__, length, XMLContent);
165 free(XMLContent); 165 free(XMLContent);
166 166
167 return ret; 167 return ret;
@@ -185,7 +185,7 @@ iphone_error_t mobilesync_send(mobilesync_client_t client, plist_t plist)
185 char *XMLContent = NULL; 185 char *XMLContent = NULL;
186 uint32_t length = 0; 186 uint32_t length = 0;
187 plist_to_xml(plist, &XMLContent, &length); 187 plist_to_xml(plist, &XMLContent, &length);
188 log_dbg_msg(DBGMASK_MOBILESYNC, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); 188 log_dbg_msg(DBGMASK_MOBILESYNC, "%s: plist size: %i\nbuffer :\n%s\n", __func__, length, XMLContent);
189 free(XMLContent); 189 free(XMLContent);
190 190
191 char *content = NULL; 191 char *content = NULL;
diff --git a/src/NotificationProxy.c b/src/NotificationProxy.c
index 374420c..1bbdc6d 100644
--- a/src/NotificationProxy.c
+++ b/src/NotificationProxy.c
@@ -226,7 +226,6 @@ iphone_error_t np_observe_notification( np_client_t client, const char *notifica
226 return res; 226 return res;
227} 227}
228 228
229
230/** Notifies the iphone to send a notification on specified events. 229/** Notifies the iphone to send a notification on specified events.
231 * 230 *
232 * observation messages seen so far: 231 * observation messages seen so far:
diff --git a/src/lockdown.c b/src/lockdown.c
index 1a434aa..bfb44d0 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -140,7 +140,7 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
140 plist_add_sub_key_el(dict, "SessionID"); 140 plist_add_sub_key_el(dict, "SessionID");
141 plist_add_sub_string_el(dict, client->session_id); 141 plist_add_sub_string_el(dict, client->session_id);
142 142
143 log_dbg_msg(DBGMASK_LOCKDOWND, "iphone_lckd_stop_session() called\n"); 143 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
144 144
145 ret = lockdownd_send(client, dict); 145 ret = lockdownd_send(client, dict);
146 146
@@ -150,13 +150,13 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
150 ret = lockdownd_recv(client, &dict); 150 ret = lockdownd_recv(client, &dict);
151 151
152 if (!dict) { 152 if (!dict) {
153 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); 153 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: LOCKDOWN_E_PLIST_ERROR\n", __func__);
154 return IPHONE_E_PLIST_ERROR; 154 return IPHONE_E_PLIST_ERROR;
155 } 155 }
156 156
157 ret = IPHONE_E_UNKNOWN_ERROR; 157 ret = IPHONE_E_UNKNOWN_ERROR;
158 if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) { 158 if (lockdown_check_result(dict, "StopSession") == RESULT_SUCCESS) {
159 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_session(): success\n"); 159 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
160 ret = IPHONE_E_SUCCESS; 160 ret = IPHONE_E_SUCCESS;
161 } 161 }
162 plist_free(dict); 162 plist_free(dict);
@@ -175,15 +175,15 @@ iphone_error_t lockdownd_stop_session(lockdownd_client_t client)
175static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client) 175static iphone_error_t lockdownd_stop_ssl_session(lockdownd_client_t client)
176{ 176{
177 if (!client) { 177 if (!client) {
178 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_stop_ssl_session(): invalid argument!\n"); 178 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: invalid argument!\n", __func__);
179 return IPHONE_E_INVALID_ARG; 179 return IPHONE_E_INVALID_ARG;
180 } 180 }
181 iphone_error_t ret = IPHONE_E_SUCCESS; 181 iphone_error_t ret = IPHONE_E_SUCCESS;
182 182
183 if (client->in_SSL) { 183 if (client->in_SSL) {
184 log_dbg_msg(DBGMASK_LOCKDOWND, "Stopping SSL Session\n"); 184 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: stopping SSL session\n", __func__);
185 ret = lockdownd_stop_session(client); 185 ret = lockdownd_stop_session(client);
186 log_dbg_msg(DBGMASK_LOCKDOWND, "Sending SSL close notify\n"); 186 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending SSL close notify\n", __func__);
187 gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); 187 gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR);
188 } 188 }
189 if (client->ssl_session) { 189 if (client->ssl_session) {
@@ -281,7 +281,7 @@ iphone_error_t lockdownd_recv(lockdownd_client_t client, plist_t *plist)
281 return IPHONE_E_NOT_ENOUGH_DATA; 281 return IPHONE_E_NOT_ENOUGH_DATA;
282 } 282 }
283 283
284 log_dbg_msg(DBGMASK_LOCKDOWND, "Recv msg :\nsize : %i\nbuffer :\n%s\n", received_bytes, receive); 284 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: received msg size: %i, buffer follows:\n%s", __func__, received_bytes, receive);
285 plist_from_xml(receive, received_bytes, plist); 285 plist_from_xml(receive, received_bytes, plist);
286 free(receive); 286 free(receive);
287 287
@@ -312,14 +312,14 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
312 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 312 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
313 313
314 plist_to_xml(plist, &XMLContent, &length); 314 plist_to_xml(plist, &XMLContent, &length);
315 log_dbg_msg(DBGMASK_LOCKDOWND, "Send msg :\nsize : %i\nbuffer :\n%s\n", length, XMLContent); 315 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending msg size %i, buffer follows:\n%s", __func__, length, XMLContent);
316 316
317 real_query = (char *) malloc(sizeof(char) * (length + 4)); 317 real_query = (char *) malloc(sizeof(char) * (length + 4));
318 length = htonl(length); 318 length = htonl(length);
319 memcpy(real_query, &length, sizeof(length)); 319 memcpy(real_query, &length, sizeof(length));
320 memcpy(real_query + 4, XMLContent, ntohl(length)); 320 memcpy(real_query + 4, XMLContent, ntohl(length));
321 free(XMLContent); 321 free(XMLContent);
322 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): made the query, sending it along\n"); 322 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: made the query, sending it along\n", __func__);
323 323
324 if (!client->in_SSL) 324 if (!client->in_SSL)
325 ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes); 325 ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes);
@@ -334,9 +334,9 @@ iphone_error_t lockdownd_send(lockdownd_client_t client, plist_t plist)
334 } 334 }
335 } 335 }
336 if (ret == IPHONE_E_SUCCESS) { 336 if (ret == IPHONE_E_SUCCESS) {
337 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): sent it!\n"); 337 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sent it!\n", __func__);
338 } else { 338 } else {
339 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): sending failed!\n"); 339 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: sending failed!\n", __func__);
340 } 340 }
341 free(real_query); 341 free(real_query);
342 342
@@ -360,7 +360,7 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
360 plist_add_sub_key_el(dict, "Request"); 360 plist_add_sub_key_el(dict, "Request");
361 plist_add_sub_string_el(dict, "QueryType"); 361 plist_add_sub_string_el(dict, "QueryType");
362 362
363 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type() called\n"); 363 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
364 ret = lockdownd_send(client, dict); 364 ret = lockdownd_send(client, dict);
365 365
366 plist_free(dict); 366 plist_free(dict);
@@ -373,7 +373,7 @@ iphone_error_t lockdownd_query_type(lockdownd_client_t client)
373 373
374 ret = IPHONE_E_UNKNOWN_ERROR; 374 ret = IPHONE_E_UNKNOWN_ERROR;
375 if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) { 375 if (lockdown_check_result(dict, "QueryType") == RESULT_SUCCESS) {
376 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_query_type(): success\n"); 376 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
377 ret = IPHONE_E_SUCCESS; 377 ret = IPHONE_E_SUCCESS;
378 } 378 }
379 plist_free(dict); 379 plist_free(dict);
@@ -445,7 +445,7 @@ iphone_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain
445 plist_get_key_val(value_key_node, &result_key); 445 plist_get_key_val(value_key_node, &result_key);
446 446
447 if (!strcmp(result_key, "Value")) { 447 if (!strcmp(result_key, "Value")) {
448 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_get_value(): has a value\n"); 448 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: has a value\n", __func__);
449 *value = plist_copy(value_value_node); 449 *value = plist_copy(value_value_node);
450 } 450 }
451 free(result_key); 451 free(result_key);
@@ -669,17 +669,16 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
669 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); 669 client_loc->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t));
670 client_loc->in_SSL = 0; 670 client_loc->in_SSL = 0;
671 671
672 if (IPHONE_E_SUCCESS != lockdownd_query_type(client_loc)) { 672 log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__);
673 log_debug_msg("QueryType failed in the lockdownd client.\n");
674 ret = IPHONE_E_NOT_ENOUGH_DATA; 673 ret = IPHONE_E_NOT_ENOUGH_DATA;
675 } 674 }
676 675
677 char *uid = NULL; 676 char *uid = NULL;
678 ret = lockdownd_get_device_uid(client_loc, &uid); 677 ret = lockdownd_get_device_uid(client_loc, &uid);
679 if (IPHONE_E_SUCCESS != ret) { 678 if (IPHONE_E_SUCCESS != ret) {
680 log_debug_msg("Device refused to send uid.\n"); 679 log_debug_msg("%s: failed to get device uuid.\n", __func__);
681 } 680 }
682 log_debug_msg("Device uid: %s\n", uid); 681 log_debug_msg("%s: device uuid: %s\n", __func__, uid);
683 682
684 host_id = get_host_id(); 683 host_id = get_host_id();
685 if (IPHONE_E_SUCCESS == ret && !host_id) { 684 if (IPHONE_E_SUCCESS == ret && !host_id) {
@@ -698,7 +697,7 @@ iphone_error_t lockdownd_new_client(iphone_device_t device, lockdownd_client_t *
698 ret = lockdownd_start_ssl_session(client_loc, host_id); 697 ret = lockdownd_start_ssl_session(client_loc, host_id);
699 if (IPHONE_E_SUCCESS != ret) { 698 if (IPHONE_E_SUCCESS != ret) {
700 ret = IPHONE_E_SSL_ERROR; 699 ret = IPHONE_E_SSL_ERROR;
701 log_debug_msg("SSL Session opening failed.\n"); 700 log_debug_msg("%s: SSL Session opening failed.\n", __func__);
702 } 701 }
703 702
704 if (host_id) { 703 if (host_id) {
@@ -731,10 +730,10 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
731 730
732 ret = lockdownd_get_device_public_key(client, &public_key); 731 ret = lockdownd_get_device_public_key(client, &public_key);
733 if (ret != IPHONE_E_SUCCESS) { 732 if (ret != IPHONE_E_SUCCESS) {
734 log_debug_msg("Device refused to send public key.\n"); 733 log_debug_msg("%s: device refused to send public key.\n", __func__);
735 return ret; 734 return ret;
736 } 735 }
737 log_debug_msg("device public key :\n %s.\n", public_key.data); 736 log_debug_msg("%s: device public key follows:\n%s\n", __func__, public_key.data);
738 737
739 ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert); 738 ret = lockdownd_gen_pair_cert(public_key, &device_cert, &host_cert, &root_cert);
740 if (ret != IPHONE_E_SUCCESS) { 739 if (ret != IPHONE_E_SUCCESS) {
@@ -780,11 +779,11 @@ iphone_error_t lockdownd_pair(lockdownd_client_t client, char *uid, char *host_i
780 779
781 /* store public key in config if pairing succeeded */ 780 /* store public key in config if pairing succeeded */
782 if (ret == IPHONE_E_SUCCESS) { 781 if (ret == IPHONE_E_SUCCESS) {
783 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair success\n"); 782 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair success\n", __func__);
784 store_device_public_key(uid, public_key); 783 store_device_public_key(uid, public_key);
785 ret = IPHONE_E_SUCCESS; 784 ret = IPHONE_E_SUCCESS;
786 } else { 785 } else {
787 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_pair: pair failure\n"); 786 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pair failure\n", __func__);
788 ret = IPHONE_E_PAIRING_FAILED; 787 ret = IPHONE_E_PAIRING_FAILED;
789 } 788 }
790 free(public_key.data); 789 free(public_key.data);
@@ -809,7 +808,7 @@ iphone_error_t lockdownd_enter_recovery(lockdownd_client_t client)
809 plist_add_sub_key_el(dict, "Request"); 808 plist_add_sub_key_el(dict, "Request");
810 plist_add_sub_string_el(dict, "EnterRecovery"); 809 plist_add_sub_string_el(dict, "EnterRecovery");
811 810
812 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Telling device to enter recovery mode\n", __func__); 811 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: telling device to enter recovery mode\n", __func__);
813 812
814 ret = lockdownd_send(client, dict); 813 ret = lockdownd_send(client, dict);
815 plist_free(dict); 814 plist_free(dict);
@@ -845,21 +844,20 @@ iphone_error_t lockdownd_goodbye(lockdownd_client_t client)
845 plist_add_sub_key_el(dict, "Request"); 844 plist_add_sub_key_el(dict, "Request");
846 plist_add_sub_string_el(dict, "Goodbye"); 845 plist_add_sub_string_el(dict, "Goodbye");
847 846
848 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye() called\n"); 847 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
849 848
850 ret = lockdownd_send(client, dict); 849 ret = lockdownd_send(client, dict);
851 plist_free(dict); 850 plist_free(dict);
852 dict = NULL; 851 dict = NULL;
853 852
854 ret = lockdownd_recv(client, &dict); 853 ret = lockdownd_recv(client, &dict);
855
856 if (!dict) { 854 if (!dict) {
857 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): IPHONE_E_PLIST_ERROR\n"); 855 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: did not get goodbye response back\n", __func__);
858 return IPHONE_E_PLIST_ERROR; 856 return IPHONE_E_PLIST_ERROR;
859 } 857 }
860 858
861 if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) { 859 if (lockdown_check_result(dict, "Goodbye") == RESULT_SUCCESS) {
862 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_goodbye(): success\n"); 860 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: success\n", __func__);
863 ret = IPHONE_E_SUCCESS; 861 ret = IPHONE_E_SUCCESS;
864 } 862 }
865 plist_free(dict); 863 plist_free(dict);
@@ -1062,7 +1060,7 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1062 //gnutls_anon_client_credentials_t anoncred; 1060 //gnutls_anon_client_credentials_t anoncred;
1063 gnutls_certificate_credentials_t xcred; 1061 gnutls_certificate_credentials_t xcred;
1064 1062
1065 log_dbg_msg(DBGMASK_LOCKDOWND, "We started the session OK, now trying GnuTLS\n"); 1063 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: started the session OK, now trying GnuTLS\n", __func__);
1066 errno = 0; 1064 errno = 0;
1067 gnutls_global_init(); 1065 gnutls_global_init();
1068 //gnutls_anon_allocate_client_credentials(&anoncred); 1066 //gnutls_anon_allocate_client_credentials(&anoncred);
@@ -1084,23 +1082,22 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1084 } 1082 }
1085 gnutls_credentials_set(*client->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me. 1083 gnutls_credentials_set(*client->ssl_session, GNUTLS_CRD_CERTIFICATE, xcred); // this part is killing me.
1086 1084
1087 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 1...\n"); 1085 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 1...\n", __func__);
1088 gnutls_transport_set_ptr(*client->ssl_session, (gnutls_transport_ptr_t) client); 1086 gnutls_transport_set_ptr(*client->ssl_session, (gnutls_transport_ptr_t) client);
1089 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 2...\n"); 1087 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 2...\n", __func__);
1090 gnutls_transport_set_push_function(*client->ssl_session, (gnutls_push_func) & lockdownd_secuwrite); 1088 gnutls_transport_set_push_function(*client->ssl_session, (gnutls_push_func) & lockdownd_secuwrite);
1091 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 3...\n"); 1089 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 3...\n", __func__);
1092 gnutls_transport_set_pull_function(*client->ssl_session, (gnutls_pull_func) & lockdownd_securead); 1090 gnutls_transport_set_pull_function(*client->ssl_session, (gnutls_pull_func) & lockdownd_securead);
1093 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS step 4 -- now handshaking...\n"); 1091 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS step 4 -- now handshaking...\n", __func__);
1094
1095 if (errno) 1092 if (errno)
1096 log_dbg_msg(DBGMASK_LOCKDOWND, "WARN: errno says %s before handshake!\n", strerror(errno)); 1093 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: WARN: errno says %s before handshake!\n", __func__, strerror(errno));
1097 return_me = gnutls_handshake(*client->ssl_session); 1094 return_me = gnutls_handshake(*client->ssl_session);
1098 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS handshake done...\n"); 1095 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS handshake done...\n", __func__);
1099 1096
1100 if (return_me != GNUTLS_E_SUCCESS) { 1097 if (return_me != GNUTLS_E_SUCCESS) {
1101 log_dbg_msg(DBGMASK_LOCKDOWND, "GnuTLS reported something wrong.\n"); 1098 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: GnuTLS reported something wrong.\n", __func__);
1102 gnutls_perror(return_me); 1099 gnutls_perror(return_me);
1103 log_dbg_msg(DBGMASK_LOCKDOWND, "oh.. errno says %s\n", strerror(errno)); 1100 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: oh.. errno says %s\n", __func__, strerror(errno));
1104 return IPHONE_E_SSL_ERROR; 1101 return IPHONE_E_SSL_ERROR;
1105 } else { 1102 } else {
1106 client->in_SSL = 1; 1103 client->in_SSL = 1;
@@ -1122,20 +1119,20 @@ iphone_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const char
1122 if (session_node_val_type == PLIST_STRING && session_id) { 1119 if (session_node_val_type == PLIST_STRING && session_id) {
1123 // we need to store the session ID for StopSession 1120 // we need to store the session ID for StopSession
1124 strcpy(client->session_id, session_id); 1121 strcpy(client->session_id, session_id);
1125 log_dbg_msg(DBGMASK_LOCKDOWND, "SessionID: %s\n", client->session_id); 1122 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: SessionID: %s\n", __func__, client->session_id);
1126 } 1123 }
1127 if (session_id) 1124 if (session_id)
1128 free(session_id); 1125 free(session_id);
1129 } 1126 }
1130 } else 1127 } else
1131 log_dbg_msg(DBGMASK_LOCKDOWND, "Failed to get SessionID!\n"); 1128 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Failed to get SessionID!\n", __func__);
1132 plist_free(dict); 1129 plist_free(dict);
1133 dict = NULL; 1130 dict = NULL;
1134 1131
1135 if (ret == IPHONE_E_SUCCESS) 1132 if (ret == IPHONE_E_SUCCESS)
1136 return ret; 1133 return ret;
1137 1134
1138 log_dbg_msg(DBGMASK_LOCKDOWND, "Apparently failed negotiating with lockdownd.\n"); 1135 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: Apparently failed negotiating with lockdownd.\n", __func__);
1139 return IPHONE_E_SSL_ERROR; 1136 return IPHONE_E_SSL_ERROR;
1140} 1137}
1141 1138
@@ -1152,12 +1149,10 @@ ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size
1152 uint32_t bytes = 0; 1149 uint32_t bytes = 0;
1153 lockdownd_client_t client; 1150 lockdownd_client_t client;
1154 client = (lockdownd_client_t) transport; 1151 client = (lockdownd_client_t) transport;
1155 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n"); 1152 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
1156 log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length); 1153 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: pre-send length = %zi\n", __func__, length);
1157 usbmuxd_send(client->sfd, buffer, length, &bytes); 1154 usbmuxd_send(client->sfd, buffer, length, &bytes);
1158 log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes); 1155 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: post-send sent %i bytes\n", __func__, bytes);
1159
1160 dump_debug_buffer("sslpacketwrite.out", buffer, length);
1161 return bytes; 1156 return bytes;
1162} 1157}
1163 1158
@@ -1179,9 +1174,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1179 client = (lockdownd_client_t) transport; 1174 client = (lockdownd_client_t) transport;
1180 char *recv_buffer; 1175 char *recv_buffer;
1181 1176
1182 log_debug_msg("lockdownd_securead() called\nlength = %zi\n", length); 1177 log_debug_msg("%s: pre-read client wants %zi bytes\n", __func__, length);
1183
1184 log_debug_msg("pre-read\nclient wants %zi bytes\n", length);
1185 1178
1186 recv_buffer = (char *) malloc(sizeof(char) * this_len); 1179 recv_buffer = (char *) malloc(sizeof(char) * this_len);
1187 1180
@@ -1191,7 +1184,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1191 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res); 1184 log_debug_msg("%s: ERROR: usbmux_recv returned %d\n", __func__, res);
1192 return res; 1185 return res;
1193 } 1186 }
1194 log_debug_msg("post-read\nwe got %i bytes\n", bytes); 1187 log_debug_msg("%s: post-read we got %i bytes\n", __func__, bytes);
1195 1188
1196 // increase read count 1189 // increase read count
1197 tbytes += bytes; 1190 tbytes += bytes;
@@ -1205,7 +1198,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1205 } 1198 }
1206 1199
1207 this_len = length - tbytes; 1200 this_len = length - tbytes;
1208 log_debug_msg("re-read\ntrying to read missing %i bytes\n", this_len); 1201 log_debug_msg("%s: re-read trying to read missing %i bytes\n", __func__, this_len);
1209 } while (tbytes < length); 1202 } while (tbytes < length);
1210 1203
1211 if (recv_buffer) { 1204 if (recv_buffer) {
diff --git a/src/userpref.c b/src/userpref.c
index 0e83133..f7ddaeb 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -102,7 +102,7 @@ static int write_host_id(char *host_id)
102 key_file = g_key_file_new(); 102 key_file = g_key_file_new();
103 103
104 /* Store in config file */ 104 /* Store in config file */
105 log_debug_msg("init_config_file(): setting hostID to %s\n", host_id); 105 log_debug_msg("%s: setting hostID to %s\n", __func__, host_id);
106 g_key_file_set_value(key_file, "Global", "HostID", host_id); 106 g_key_file_set_value(key_file, "Global", "HostID", host_id);
107 107
108 /* Write config file on disk */ 108 /* Write config file on disk */
@@ -152,7 +152,7 @@ char *get_host_id(void)
152 write_host_id(host_id); 152 write_host_id(host_id);
153 } 153 }
154 154
155 log_debug_msg("get_host_id(): Using %s as HostID\n", host_id); 155 log_debug_msg("%s: Using %s as HostID\n", __func__, host_id);
156 return host_id; 156 return host_id;
157} 157}
158 158
@@ -275,7 +275,6 @@ static iphone_error_t gen_keys_and_cert(void)
275 gnutls_x509_crt_set_expiration_time(root_cert, time(NULL) + (60 * 60 * 24 * 365 * 10)); 275 gnutls_x509_crt_set_expiration_time(root_cert, time(NULL) + (60 * 60 * 24 * 365 * 10));
276 gnutls_x509_crt_sign(root_cert, root_cert, root_privkey); 276 gnutls_x509_crt_sign(root_cert, root_cert, root_privkey);
277 277
278
279 gnutls_x509_crt_set_key(host_cert, host_privkey); 278 gnutls_x509_crt_set_key(host_cert, host_privkey);
280 gnutls_x509_crt_set_serial(host_cert, "\x00", 1); 279 gnutls_x509_crt_set_serial(host_cert, "\x00", 1);
281 gnutls_x509_crt_set_version(host_cert, 3); 280 gnutls_x509_crt_set_version(host_cert, 3);
diff --git a/src/utils.c b/src/utils.c
index 121bc55..6535a07 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -116,13 +116,12 @@ inline void log_debug_buffer(const char *data, const int length)
116inline void dump_debug_buffer(const char *file, const char *data, const int length) 116inline void dump_debug_buffer(const char *file, const char *data, const int length)
117{ 117{
118#ifndef STRIP_DEBUG_CODE 118#ifndef STRIP_DEBUG_CODE
119
120 /* run the real fprintf */ 119 /* run the real fprintf */
121 if (toto_debug) { 120 if (toto_debug) {
122 FILE *my_ssl_packet = fopen(file, "w+"); 121 FILE *my_ssl_packet = fopen(file, "w+");
123 fwrite(data, 1, length, my_ssl_packet); 122 fwrite(data, 1, length, my_ssl_packet);
124 fflush(my_ssl_packet); 123 fflush(my_ssl_packet);
125 fprintf(stderr, "Wrote SSL packet to drive, too.\n"); 124 fprintf(stderr, "%s: Wrote SSL packet to drive, too.\n", __func__);
126 fclose(my_ssl_packet); 125 fclose(my_ssl_packet);
127 } 126 }
128#endif 127#endif