summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dev/afccheck.c2
-rw-r--r--dev/iphoneclient.c2
-rw-r--r--dev/iphoneenterrecovery.c2
-rw-r--r--dev/lckdclient.c2
-rw-r--r--dev/msyncclient.c2
-rw-r--r--include/libiphone/lockdown.h3
-rw-r--r--src/lockdown.c46
-rw-r--r--src/lockdown.h1
-rw-r--r--swig/iphone.i2
-rw-r--r--tools/iphone_id.c2
-rw-r--r--tools/iphoneinfo.c2
-rw-r--r--tools/iphonesyslog.c2
12 files changed, 57 insertions, 11 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c
index 88935a0..00c0f52 100644
--- a/dev/afccheck.c
+++ b/dev/afccheck.c
@@ -109,7 +109,7 @@ int main(int argc, char *argv[])
109 return 1; 109 return 1;
110 } 110 }
111 111
112 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 112 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "afccheck")) {
113 iphone_device_free(phone); 113 iphone_device_free(phone);
114 return 1; 114 return 1;
115 } 115 }
diff --git a/dev/iphoneclient.c b/dev/iphoneclient.c
index d62d23f..685f6ef 100644
--- a/dev/iphoneclient.c
+++ b/dev/iphoneclient.c
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
87 if (uuid) 87 if (uuid)
88 free(uuid); 88 free(uuid);
89 89
90 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 90 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "iphoneclient")) {
91 iphone_device_free(phone); 91 iphone_device_free(phone);
92 printf("Exiting.\n"); 92 printf("Exiting.\n");
93 return -1; 93 return -1;
diff --git a/dev/iphoneenterrecovery.c b/dev/iphoneenterrecovery.c
index 1d4d332..126941c 100644
--- a/dev/iphoneenterrecovery.c
+++ b/dev/iphoneenterrecovery.c
@@ -74,7 +74,7 @@ int main(int argc, char *argv[])
74 return -1; 74 return -1;
75 } 75 }
76 76
77 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 77 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "iphoneenterrecovery")) {
78 iphone_device_free(phone); 78 iphone_device_free(phone);
79 return -1; 79 return -1;
80 } 80 }
diff --git a/dev/lckdclient.c b/dev/lckdclient.c
index d866435..c8d717c 100644
--- a/dev/lckdclient.c
+++ b/dev/lckdclient.c
@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
48 if (uuid) 48 if (uuid)
49 free(uuid); 49 free(uuid);
50 50
51 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 51 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "lckdclient")) {
52 iphone_device_free(phone); 52 iphone_device_free(phone);
53 return -1; 53 return -1;
54 } 54 }
diff --git a/dev/msyncclient.c b/dev/msyncclient.c
index 53018ac..dfe2a2b 100644
--- a/dev/msyncclient.c
+++ b/dev/msyncclient.c
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
153 return -1; 153 return -1;
154 } 154 }
155 155
156 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 156 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "msyncclient")) {
157 iphone_device_free(phone); 157 iphone_device_free(phone);
158 return -1; 158 return -1;
159 } 159 }
diff --git a/include/libiphone/lockdown.h b/include/libiphone/lockdown.h
index 31ffeab..55dc3eb 100644
--- a/include/libiphone/lockdown.h
+++ b/include/libiphone/lockdown.h
@@ -53,8 +53,9 @@ struct lockdownd_client_int;
53typedef struct lockdownd_client_int *lockdownd_client_t; 53typedef struct lockdownd_client_int *lockdownd_client_t;
54 54
55/* Interface */ 55/* Interface */
56lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client); 56lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client, const char *label);
57lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); 57lockdownd_error_t lockdownd_client_free(lockdownd_client_t client);
58void lockdownd_client_set_label(lockdownd_client_t client, const char *label);
58lockdownd_error_t lockdownd_query_type(lockdownd_client_t client); 59lockdownd_error_t lockdownd_query_type(lockdownd_client_t client);
59lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); 60lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value);
60lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); 61lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value);
diff --git a/src/lockdown.c b/src/lockdown.c
index fb5f8f5..76d063c 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -108,6 +108,21 @@ static int lockdown_check_result(plist_t dict, const char *query_match)
108} 108}
109 109
110/** 110/**
111 * Adds a label key with the passed value to a plist dict node.
112 *
113 * @param plist The plist to add the key to
114 * @param label The value for the label key
115 *
116 */
117static void plist_dict_add_label(plist_t plist, const char *label)
118{
119 if (plist && label) {
120 if (plist_get_node_type(plist) == PLIST_DICT)
121 plist_dict_insert_item(plist, "Label", plist_new_string(label));
122 }
123}
124
125/**
111 * Closes the lockdownd communication session, by sending 126 * Closes the lockdownd communication session, by sending
112 * the StopSession Request to the device. 127 * the StopSession Request to the device.
113 * 128 *
@@ -128,6 +143,7 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client)
128 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 143 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
129 144
130 plist_t dict = plist_new_dict(); 145 plist_t dict = plist_new_dict();
146 plist_dict_add_label(dict, client->label);
131 plist_dict_insert_item(dict,"Request", plist_new_string("StopSession")); 147 plist_dict_insert_item(dict,"Request", plist_new_string("StopSession"));
132 plist_dict_insert_item(dict,"SessionID", plist_new_string(client->session_id)); 148 plist_dict_insert_item(dict,"SessionID", plist_new_string(client->session_id));
133 149
@@ -223,11 +239,27 @@ lockdownd_error_t lockdownd_client_free(lockdownd_client_t client)
223 if (client->uuid) { 239 if (client->uuid) {
224 free(client->uuid); 240 free(client->uuid);
225 } 241 }
242 if (client->label) {
243 free(client->label);
244 }
226 245
227 free(client); 246 free(client);
228 return ret; 247 return ret;
229} 248}
230 249
250/**
251 * Sets the label to send for requests to lockdownd.
252 *
253 * @param client The lockdown client
254 * @param label The label to set or NULL to disable
255 *
256 */
257void lockdownd_client_set_label(lockdownd_client_t client, const char *label)
258{
259 if (client)
260 client->label = strdup(label);
261}
262
231/** Polls the iPhone for lockdownd data. 263/** Polls the iPhone for lockdownd data.
232 * 264 *
233 * @param control The lockdownd client 265 * @param control The lockdownd client
@@ -366,6 +398,7 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client)
366 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 398 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
367 399
368 plist_t dict = plist_new_dict(); 400 plist_t dict = plist_new_dict();
401 plist_dict_add_label(dict, client->label);
369 plist_dict_insert_item(dict,"Request", plist_new_string("QueryType")); 402 plist_dict_insert_item(dict,"Request", plist_new_string("QueryType"));
370 403
371 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); 404 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
@@ -409,6 +442,7 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom
409 442
410 /* setup request plist */ 443 /* setup request plist */
411 dict = plist_new_dict(); 444 dict = plist_new_dict();
445 plist_dict_add_label(dict, client->label);
412 if (domain) { 446 if (domain) {
413 plist_dict_insert_item(dict,"Domain", plist_new_string(domain)); 447 plist_dict_insert_item(dict,"Domain", plist_new_string(domain));
414 } 448 }
@@ -470,6 +504,7 @@ lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *dom
470 504
471 /* setup request plist */ 505 /* setup request plist */
472 dict = plist_new_dict(); 506 dict = plist_new_dict();
507 plist_dict_add_label(dict, client->label);
473 if (domain) { 508 if (domain) {
474 plist_dict_insert_item(dict,"Domain", plist_new_string(domain)); 509 plist_dict_insert_item(dict,"Domain", plist_new_string(domain));
475 } 510 }
@@ -527,6 +562,7 @@ lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *
527 562
528 /* setup request plist */ 563 /* setup request plist */
529 dict = plist_new_dict(); 564 dict = plist_new_dict();
565 plist_dict_add_label(dict, client->label);
530 if (domain) { 566 if (domain) {
531 plist_dict_insert_item(dict,"Domain", plist_new_string(domain)); 567 plist_dict_insert_item(dict,"Domain", plist_new_string(domain));
532 } 568 }
@@ -636,10 +672,11 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de
636 * 672 *
637 * @param phone The iPhone to create a lockdownd client for 673 * @param phone The iPhone to create a lockdownd client for
638 * @param client The pointer to the location of the new lockdownd_client 674 * @param client The pointer to the location of the new lockdownd_client
675 * @param label The label to use for communication. Usually the program name
639 * 676 *
640 * @return an error code (LOCKDOWN_E_SUCCESS on success) 677 * @return an error code (LOCKDOWN_E_SUCCESS on success)
641 */ 678 */
642lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client) 679lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_t *client, const char *label)
643{ 680{
644 if (!client) 681 if (!client)
645 return LOCKDOWN_E_INVALID_ARG; 682 return LOCKDOWN_E_INVALID_ARG;
@@ -659,6 +696,7 @@ lockdownd_error_t lockdownd_client_new(iphone_device_t device, lockdownd_client_
659 client_loc->in_SSL = 0; 696 client_loc->in_SSL = 0;
660 client_loc->session_id = NULL; 697 client_loc->session_id = NULL;
661 client_loc->uuid = NULL; 698 client_loc->uuid = NULL;
699 client_loc->label = strdup(label);
662 700
663 if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) { 701 if (LOCKDOWN_E_SUCCESS != lockdownd_query_type(client_loc)) {
664 log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__); 702 log_debug_msg("%s: QueryType failed in the lockdownd client.\n", __func__);
@@ -741,6 +779,7 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, char *host
741 /* Setup Pair request plist */ 779 /* Setup Pair request plist */
742 dict = plist_new_dict(); 780 dict = plist_new_dict();
743 dict_record = plist_new_dict(); 781 dict_record = plist_new_dict();
782 plist_dict_add_label(dict, client->label);
744 plist_dict_insert_item(dict,"PairRecord", dict_record); 783 plist_dict_insert_item(dict,"PairRecord", dict_record);
745 784
746 plist_dict_insert_item(dict_record, "DeviceCertificate", plist_new_data((const char*)device_cert.data, device_cert.size)); 785 plist_dict_insert_item(dict_record, "DeviceCertificate", plist_new_data((const char*)device_cert.data, device_cert.size));
@@ -833,6 +872,7 @@ lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client)
833 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 872 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
834 873
835 plist_t dict = plist_new_dict(); 874 plist_t dict = plist_new_dict();
875 plist_dict_add_label(dict, client->label);
836 plist_dict_insert_item(dict,"Request", plist_new_string("EnterRecovery")); 876 plist_dict_insert_item(dict,"Request", plist_new_string("EnterRecovery"));
837 877
838 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: telling device to enter recovery mode\n", __func__); 878 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: telling device to enter recovery mode\n", __func__);
@@ -868,6 +908,7 @@ lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client)
868 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; 908 lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR;
869 909
870 plist_t dict = plist_new_dict(); 910 plist_t dict = plist_new_dict();
911 plist_dict_add_label(dict, client->label);
871 plist_dict_insert_item(dict,"Request", plist_new_string("Goodbye")); 912 plist_dict_insert_item(dict,"Request", plist_new_string("Goodbye"));
872 913
873 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__); 914 log_dbg_msg(DBGMASK_LOCKDOWND, "%s: called\n", __func__);
@@ -1050,6 +1091,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
1050 1091
1051 /* Setup DevicePublicKey request plist */ 1092 /* Setup DevicePublicKey request plist */
1052 dict = plist_new_dict(); 1093 dict = plist_new_dict();
1094 plist_dict_add_label(dict, client->label);
1053 plist_dict_insert_item(dict,"HostID", plist_new_string(HostID)); 1095 plist_dict_insert_item(dict,"HostID", plist_new_string(HostID));
1054 plist_dict_insert_item(dict,"Request", plist_new_string("StartSession")); 1096 plist_dict_insert_item(dict,"Request", plist_new_string("StartSession"));
1055 1097
@@ -1080,6 +1122,7 @@ lockdownd_error_t lockdownd_start_ssl_session(lockdownd_client_t client, const c
1080 /* start session again */ 1122 /* start session again */
1081 plist_free(dict); 1123 plist_free(dict);
1082 dict = plist_new_dict(); 1124 dict = plist_new_dict();
1125 plist_dict_add_label(dict, client->label);
1083 plist_dict_insert_item(dict,"HostID", plist_new_string(HostID)); 1126 plist_dict_insert_item(dict,"HostID", plist_new_string(HostID));
1084 plist_dict_insert_item(dict,"Request", plist_new_string("StartSession")); 1127 plist_dict_insert_item(dict,"Request", plist_new_string("StartSession"));
1085 1128
@@ -1277,6 +1320,7 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char
1277 host_id = NULL; 1320 host_id = NULL;
1278 1321
1279 dict = plist_new_dict(); 1322 dict = plist_new_dict();
1323 plist_dict_add_label(dict, client->label);
1280 plist_dict_insert_item(dict,"Request", plist_new_string("StartService")); 1324 plist_dict_insert_item(dict,"Request", plist_new_string("StartService"));
1281 plist_dict_insert_item(dict,"Service", plist_new_string(service)); 1325 plist_dict_insert_item(dict,"Service", plist_new_string(service));
1282 1326
diff --git a/src/lockdown.h b/src/lockdown.h
index 931623a..6dac391 100644
--- a/src/lockdown.h
+++ b/src/lockdown.h
@@ -34,6 +34,7 @@ struct lockdownd_client_int {
34 int in_SSL; 34 int in_SSL;
35 char *session_id; 35 char *session_id;
36 char *uuid; 36 char *uuid;
37 char *label;
37}; 38};
38 39
39lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key); 40lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key);
diff --git a/swig/iphone.i b/swig/iphone.i
index a0ee509..6e1849e 100644
--- a/swig/iphone.i
+++ b/swig/iphone.i
@@ -71,7 +71,7 @@ Lockdownd* my_new_Lockdownd(iPhone* phone) {
71 Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd)); 71 Lockdownd* client = (Lockdownd*) malloc(sizeof(Lockdownd));
72 client->dev = phone; 72 client->dev = phone;
73 client->client = NULL; 73 client->client = NULL;
74 if (LOCKDOWN_E_SUCCESS == lockdownd_client_new(phone->dev , &(client->client))) { 74 if (LOCKDOWN_E_SUCCESS == lockdownd_client_new(phone->dev , &(client->client), NULL)) {
75 return client; 75 return client;
76 } 76 }
77 else { 77 else {
diff --git a/tools/iphone_id.c b/tools/iphone_id.c
index 80f22e1..a293469 100644
--- a/tools/iphone_id.c
+++ b/tools/iphone_id.c
@@ -70,7 +70,7 @@ int main(int argc, char **argv)
70 return -2; 70 return -2;
71 } 71 }
72 72
73 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 73 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "iphone_id")) {
74 iphone_device_free(phone); 74 iphone_device_free(phone);
75 fprintf(stderr, "ERROR: Connecting to device failed!\n"); 75 fprintf(stderr, "ERROR: Connecting to device failed!\n");
76 return -2; 76 return -2;
diff --git a/tools/iphoneinfo.c b/tools/iphoneinfo.c
index e0d7693..423c57e 100644
--- a/tools/iphoneinfo.c
+++ b/tools/iphoneinfo.c
@@ -136,7 +136,7 @@ int main(int argc, char *argv[])
136 } 136 }
137 } 137 }
138 138
139 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 139 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "iphoneinfo")) {
140 iphone_device_free(phone); 140 iphone_device_free(phone);
141 return -1; 141 return -1;
142 } 142 }
diff --git a/tools/iphonesyslog.c b/tools/iphonesyslog.c
index 8fa3b04..5d4f564 100644
--- a/tools/iphonesyslog.c
+++ b/tools/iphonesyslog.c
@@ -99,7 +99,7 @@ int main(int argc, char *argv[])
99 } 99 }
100 } 100 }
101 101
102 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client)) { 102 if (LOCKDOWN_E_SUCCESS != lockdownd_client_new(phone, &client, "iphonesyslog")) {
103 iphone_device_free(phone); 103 iphone_device_free(phone);
104 return -1; 104 return -1;
105 } 105 }