diff options
| author | 2013-12-27 12:47:26 +0100 | |
|---|---|---|
| committer | 2013-12-27 12:47:26 +0100 | |
| commit | 0bfec4d45b29ac992a30061b8f7190ca8fdc9cbc (patch) | |
| tree | 784bd482da6bb966e6bd68e3b0d2bfd1cf1a3ec9 /src | |
| parent | 61d50ad1fbd12454baaec0531d4e75f8160d0579 (diff) | |
| download | usbmuxd-0bfec4d45b29ac992a30061b8f7190ca8fdc9cbc.tar.gz usbmuxd-0bfec4d45b29ac992a30061b8f7190ca8fdc9cbc.tar.bz2 | |
preflight: check for device record before trying to read host id
Diffstat (limited to 'src')
| -rw-r--r-- | src/conf.c | 32 | ||||
| -rw-r--r-- | src/conf.h | 1 | ||||
| -rw-r--r-- | src/preflight.c | 25 |
3 files changed, 47 insertions, 11 deletions
| @@ -326,6 +326,35 @@ static int config_set_system_buid(const char *system_buid) | |||
| 326 | } | 326 | } |
| 327 | 327 | ||
| 328 | /** | 328 | /** |
| 329 | * Determines whether a pairing record is present for the given device. | ||
| 330 | * | ||
| 331 | * @param udid The device UDID as given by the device. | ||
| 332 | * | ||
| 333 | * @return 1 if there's a pairing record for the given udid or 0 otherwise. | ||
| 334 | */ | ||
| 335 | int config_has_device_record(const char *udid) | ||
| 336 | { | ||
| 337 | int res = 0; | ||
| 338 | if (!udid) return 0; | ||
| 339 | |||
| 340 | /* ensure config directory exists */ | ||
| 341 | config_create_config_dir(); | ||
| 342 | |||
| 343 | /* build file path */ | ||
| 344 | const char *config_path = config_get_config_dir(); | ||
| 345 | char *device_record_file = string_concat(config_path, DIR_SEP_S, udid, CONFIG_EXT, NULL); | ||
| 346 | |||
| 347 | struct stat st; | ||
| 348 | |||
| 349 | if ((stat(device_record_file, &st) == 0) && S_ISREG(st.st_mode)) | ||
| 350 | res = 1; | ||
| 351 | |||
| 352 | free(device_record_file); | ||
| 353 | |||
| 354 | return res; | ||
| 355 | } | ||
| 356 | |||
| 357 | /** | ||
| 329 | * Reads the BUID from a previously generated configuration file. | 358 | * Reads the BUID from a previously generated configuration file. |
| 330 | * | 359 | * |
| 331 | * @param system_buid pointer to a variable that will be set to point to a | 360 | * @param system_buid pointer to a variable that will be set to point to a |
| @@ -430,7 +459,8 @@ int config_get_device_record(const char *udid, char **record_data, uint64_t *rec | |||
| 430 | char *device_record_file = string_concat(config_path, DIR_SEP_S, udid, CONFIG_EXT, NULL); | 459 | char *device_record_file = string_concat(config_path, DIR_SEP_S, udid, CONFIG_EXT, NULL); |
| 431 | 460 | ||
| 432 | /* read file */ | 461 | /* read file */ |
| 433 | buffer_read_from_filename(device_record_file, record_data, record_size); if (!*record_data) { | 462 | buffer_read_from_filename(device_record_file, record_data, record_size); |
| 463 | if (!*record_data) { | ||
| 434 | usbmuxd_log(LL_ERROR, "%s: failed to read '%s': %s", __func__, device_record_file, strerror(errno)); | 464 | usbmuxd_log(LL_ERROR, "%s: failed to read '%s': %s", __func__, device_record_file, strerror(errno)); |
| 435 | res = -ENOENT; | 465 | res = -ENOENT; |
| 436 | } | 466 | } |
| @@ -31,6 +31,7 @@ const char *config_get_config_dir(); | |||
| 31 | 31 | ||
| 32 | void config_get_system_buid(char **system_buid); | 32 | void config_get_system_buid(char **system_buid); |
| 33 | 33 | ||
| 34 | int config_has_device_record(const char *udid); | ||
| 34 | int config_get_device_record(const char *udid, char **record_data, uint64_t *record_size); | 35 | int config_get_device_record(const char *udid, char **record_data, uint64_t *record_size); |
| 35 | int config_set_device_record(const char *udid, char* record_data, uint64_t record_size); | 36 | int config_set_device_record(const char *udid, char* record_data, uint64_t record_size); |
| 36 | int config_remove_device_record(const char *udid); | 37 | int config_remove_device_record(const char *udid); |
diff --git a/src/preflight.c b/src/preflight.c index b011344..5198d8c 100644 --- a/src/preflight.c +++ b/src/preflight.c | |||
| @@ -161,17 +161,22 @@ retry: | |||
| 161 | 161 | ||
| 162 | int is_device_paired = 0; | 162 | int is_device_paired = 0; |
| 163 | char *host_id = NULL; | 163 | char *host_id = NULL; |
| 164 | config_device_record_get_host_id(dev->udid, &host_id); | 164 | if (config_has_device_record(dev->udid)) { |
| 165 | lerr = lockdownd_start_session(lockdown, host_id, NULL, NULL); | 165 | config_device_record_get_host_id(dev->udid, &host_id); |
| 166 | free(host_id); | 166 | lerr = lockdownd_start_session(lockdown, host_id, NULL, NULL); |
| 167 | if (lerr == LOCKDOWN_E_SUCCESS) { | 167 | if (host_id) |
| 168 | usbmuxd_log(LL_INFO, "%s: StartSession success for device %s", __func__, _dev->udid); | 168 | free(host_id); |
| 169 | usbmuxd_log(LL_INFO, "%s: Finished preflight on device %s", __func__, _dev->udid); | 169 | if (lerr == LOCKDOWN_E_SUCCESS) { |
| 170 | client_device_add(info); | 170 | usbmuxd_log(LL_INFO, "%s: StartSession success for device %s", __func__, _dev->udid); |
| 171 | goto leave; | 171 | usbmuxd_log(LL_INFO, "%s: Finished preflight on device %s", __func__, _dev->udid); |
| 172 | } | 172 | client_device_add(info); |
| 173 | goto leave; | ||
| 174 | } | ||
| 173 | 175 | ||
| 174 | usbmuxd_log(LL_INFO, "%s: StartSession failed on device %s, lockdown error %d", __func__, _dev->udid, lerr); | 176 | usbmuxd_log(LL_INFO, "%s: StartSession failed on device %s, lockdown error %d", __func__, _dev->udid, lerr); |
| 177 | } else { | ||
| 178 | lerr = LOCKDOWN_E_INVALID_HOST_ID; | ||
| 179 | } | ||
| 175 | switch (lerr) { | 180 | switch (lerr) { |
| 176 | case LOCKDOWN_E_INVALID_HOST_ID: | 181 | case LOCKDOWN_E_INVALID_HOST_ID: |
| 177 | usbmuxd_log(LL_INFO, "%s: Device %s is not paired with this host.", __func__, _dev->udid); | 182 | usbmuxd_log(LL_INFO, "%s: Device %s is not paired with this host.", __func__, _dev->udid); |
