summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicepair.c49
1 files changed, 32 insertions, 17 deletions
diff --git a/tools/idevicepair.c b/tools/idevicepair.c
index d634d5f..91ed49b 100644
--- a/tools/idevicepair.c
+++ b/tools/idevicepair.c
@@ -38,7 +38,8 @@ static void print_usage(int argc, char **argv)
38 printf("\n%s - Manage pairings with devices and this host.\n\n", (name ? name + 1: argv[0])); 38 printf("\n%s - Manage pairings with devices and this host.\n\n", (name ? name + 1: argv[0]));
39 printf("Usage: %s [OPTIONS] COMMAND\n\n", (name ? name + 1: argv[0])); 39 printf("Usage: %s [OPTIONS] COMMAND\n\n", (name ? name + 1: argv[0]));
40 printf(" Where COMMAND is one of:\n"); 40 printf(" Where COMMAND is one of:\n");
41 printf(" hostid print the host id of this computer\n"); 41 printf(" systembuid print the system buid of this computer\n");
42 printf(" hostid print the host id for target device\n");
42 printf(" pair pair device with this computer\n"); 43 printf(" pair pair device with this computer\n");
43 printf(" validate validate if device is paired with this computer\n"); 44 printf(" validate validate if device is paired with this computer\n");
44 printf(" unpair unpair device with this computer\n"); 45 printf(" unpair unpair device with this computer\n");
@@ -99,7 +100,7 @@ int main(int argc, char **argv)
99 char *type = NULL; 100 char *type = NULL;
100 char *cmd; 101 char *cmd;
101 typedef enum { 102 typedef enum {
102 OP_NONE = 0, OP_PAIR, OP_VALIDATE, OP_UNPAIR, OP_LIST, OP_HOSTID 103 OP_NONE = 0, OP_PAIR, OP_VALIDATE, OP_UNPAIR, OP_LIST, OP_HOSTID, OP_SYSTEMBUID
103 } op_t; 104 } op_t;
104 op_t op = OP_NONE; 105 op_t op = OP_NONE;
105 106
@@ -123,20 +124,22 @@ int main(int argc, char **argv)
123 op = OP_LIST; 124 op = OP_LIST;
124 } else if (!strcmp(cmd, "hostid")) { 125 } else if (!strcmp(cmd, "hostid")) {
125 op = OP_HOSTID; 126 op = OP_HOSTID;
127 } else if (!strcmp(cmd, "systembuid")) {
128 op = OP_SYSTEMBUID;
126 } else { 129 } else {
127 printf("ERROR: Invalid command '%s' specified\n", cmd); 130 printf("ERROR: Invalid command '%s' specified\n", cmd);
128 print_usage(argc, argv); 131 print_usage(argc, argv);
129 exit(EXIT_FAILURE); 132 exit(EXIT_FAILURE);
130 } 133 }
131 134
132 if (op == OP_HOSTID) { 135 if (op == OP_SYSTEMBUID) {
133 char *hostid = NULL; 136 char *systembuid = NULL;
134 userpref_get_host_id(&hostid); 137 userpref_get_system_buid(&systembuid);
135 138
136 printf("%s\n", hostid); 139 printf("%s\n", systembuid);
137 140
138 if (hostid) 141 if (systembuid)
139 free(hostid); 142 free(systembuid);
140 143
141 return EXIT_SUCCESS; 144 return EXIT_SUCCESS;
142 } 145 }
@@ -173,6 +176,25 @@ int main(int argc, char **argv)
173 } 176 }
174 } 177 }
175 178
179 ret = idevice_get_udid(device, &udid);
180 if (ret != IDEVICE_E_SUCCESS) {
181 printf("ERROR: Could not get device udid, error code %d\n", ret);
182 result = EXIT_FAILURE;
183 goto leave;
184 }
185
186 if (op == OP_HOSTID) {
187 char *hostid = NULL;
188 userpref_device_record_get_host_id(udid, &hostid);
189
190 printf("%s\n", hostid);
191
192 if (hostid)
193 free(hostid);
194
195 return EXIT_SUCCESS;
196 }
197
176 lerr = lockdownd_client_new(device, &client, "idevicepair"); 198 lerr = lockdownd_client_new(device, &client, "idevicepair");
177 if (lerr != LOCKDOWN_E_SUCCESS) { 199 if (lerr != LOCKDOWN_E_SUCCESS) {
178 idevice_free(device); 200 idevice_free(device);
@@ -196,13 +218,6 @@ int main(int argc, char **argv)
196 } 218 }
197 } 219 }
198 220
199 ret = idevice_get_udid(device, &udid);
200 if (ret != IDEVICE_E_SUCCESS) {
201 printf("ERROR: Could not get device udid, error code %d\n", ret);
202 result = EXIT_FAILURE;
203 goto leave;
204 }
205
206 switch(op) { 221 switch(op) {
207 default: 222 default:
208 case OP_PAIR: 223 case OP_PAIR:
@@ -238,8 +253,8 @@ int main(int argc, char **argv)
238 case OP_UNPAIR: 253 case OP_UNPAIR:
239 lerr = lockdownd_unpair(client, NULL); 254 lerr = lockdownd_unpair(client, NULL);
240 if (lerr == LOCKDOWN_E_SUCCESS) { 255 if (lerr == LOCKDOWN_E_SUCCESS) {
241 /* also remove local device public key */ 256 /* also remove local device record */
242 userpref_remove_device_public_key(udid); 257 userpref_remove_device_record(udid);
243 printf("SUCCESS: Unpaired with device %s\n", udid); 258 printf("SUCCESS: Unpaired with device %s\n", udid);
244 } else { 259 } else {
245 result = EXIT_FAILURE; 260 result = EXIT_FAILURE;