diff options
| author | 2010-03-16 03:13:38 +0100 | |
|---|---|---|
| committer | 2010-03-16 03:13:38 +0100 | |
| commit | 08d2af5d611319748afba2aaba5e6c8a99f1b396 (patch) | |
| tree | 8bf4a3533f2acf11368dc37a9c653689ace99b77 /src/lockdown.c | |
| parent | 3e0c5021100c879ff7d0776d4c7bb4f0ec88e0d7 (diff) | |
| download | libimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.gz libimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.bz2 | |
Complete documentation of public interface and fix a lot of bogus comments
This change unifies the documentation comment syntax, fixes a few bad
documentation comments and completes documentation where it was missing.
Diffstat (limited to 'src/lockdown.c')
| -rw-r--r-- | src/lockdown.c | 247 |
1 files changed, 168 insertions, 79 deletions
diff --git a/src/lockdown.c b/src/lockdown.c index 25a6c6a..515c58e 100644 --- a/src/lockdown.c +++ b/src/lockdown.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * lockdown.c | 2 | * lockdown.c |
| 3 | * libimobiledevice built-in lockdownd client | 3 | * com.apple.mobile.lockdownd service implementation. |
| 4 | * | 4 | * |
| 5 | * Copyright (c) 2008 Zach C. All Rights Reserved. | 5 | * Copyright (c) 2008 Zach C. All Rights Reserved. |
| 6 | * | 6 | * |
| @@ -124,15 +124,14 @@ static void plist_dict_add_label(plist_t plist, const char *label) | |||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | /** | 126 | /** |
| 127 | * Closes the lockdownd communication session, by sending the StopSession | 127 | * Closes the lockdownd session by sending the StopSession request. |
| 128 | * Request to the device. | ||
| 129 | * | 128 | * |
| 130 | * @see lockdownd_start_session | 129 | * @see lockdownd_start_session |
| 131 | * | 130 | * |
| 132 | * @param control The lockdown client | 131 | * @param client The lockdown client |
| 133 | * @param session_id The id of a running session | 132 | * @param session_id The id of a running session |
| 134 | * | 133 | * |
| 135 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 134 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 136 | */ | 135 | */ |
| 137 | lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) | 136 | lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id) |
| 138 | { | 137 | { |
| @@ -178,11 +177,13 @@ lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char * | |||
| 178 | return ret; | 177 | return ret; |
| 179 | } | 178 | } |
| 180 | 179 | ||
| 181 | /** Closes the lockdownd client and does the necessary housekeeping. | 180 | /** |
| 181 | * Closes the lockdownd client session if one is running and frees up the | ||
| 182 | * lockdownd_client struct. | ||
| 182 | * | 183 | * |
| 183 | * @param client The lockdown client | 184 | * @param client The lockdown client |
| 184 | * | 185 | * |
| 185 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 186 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 186 | */ | 187 | */ |
| 187 | lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) | 188 | lockdownd_error_t lockdownd_client_free(lockdownd_client_t client) |
| 188 | { | 189 | { |
| @@ -229,12 +230,14 @@ void lockdownd_client_set_label(lockdownd_client_t client, const char *label) | |||
| 229 | } | 230 | } |
| 230 | } | 231 | } |
| 231 | 232 | ||
| 232 | /** Polls the device for lockdownd data. | 233 | /** |
| 234 | * Receives a plist from lockdownd. | ||
| 233 | * | 235 | * |
| 234 | * @param control The lockdownd client | 236 | * @param client The lockdownd client |
| 235 | * @param plist The plist to store the received data | 237 | * @param plist The plist to store the received data |
| 236 | * | 238 | * |
| 237 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 239 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or |
| 240 | * plist is NULL | ||
| 238 | */ | 241 | */ |
| 239 | lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) | 242 | lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) |
| 240 | { | 243 | { |
| @@ -254,7 +257,8 @@ lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) | |||
| 254 | return ret; | 257 | return ret; |
| 255 | } | 258 | } |
| 256 | 259 | ||
| 257 | /** Sends lockdownd data to the device | 260 | /** |
| 261 | * Sends a plist to lockdownd. | ||
| 258 | * | 262 | * |
| 259 | * @note This function is low-level and should only be used if you need to send | 263 | * @note This function is low-level and should only be used if you need to send |
| 260 | * a new type of message. | 264 | * a new type of message. |
| @@ -262,7 +266,8 @@ lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist) | |||
| 262 | * @param client The lockdownd client | 266 | * @param client The lockdownd client |
| 263 | * @param plist The plist to send | 267 | * @param plist The plist to send |
| 264 | * | 268 | * |
| 265 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 269 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or |
| 270 | * plist is NULL | ||
| 266 | */ | 271 | */ |
| 267 | lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) | 272 | lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) |
| 268 | { | 273 | { |
| @@ -279,13 +284,14 @@ lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist) | |||
| 279 | return ret; | 284 | return ret; |
| 280 | } | 285 | } |
| 281 | 286 | ||
| 282 | /** Query the type of the service daemon. Depending on whether the device is | 287 | /** |
| 288 | * Query the type of the service daemon. Depending on whether the device is | ||
| 283 | * queried in normal mode or restore mode, different types will be returned. | 289 | * queried in normal mode or restore mode, different types will be returned. |
| 284 | * | 290 | * |
| 285 | * @param client The lockdownd client | 291 | * @param client The lockdownd client |
| 286 | * @param type The type returned by the service daemon. Can be NULL to ignore. | 292 | * @param type The type returned by the service daemon. Pass NULL to ignore. |
| 287 | * | 293 | * |
| 288 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 294 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 289 | */ | 295 | */ |
| 290 | lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type) | 296 | lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type) |
| 291 | { | 297 | { |
| @@ -325,14 +331,15 @@ lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type) | |||
| 325 | return ret; | 331 | return ret; |
| 326 | } | 332 | } |
| 327 | 333 | ||
| 328 | /** Retrieves a preferences plist using an optional domain and/or key name. | 334 | /** |
| 335 | * Retrieves a preferences plist using an optional domain and/or key name. | ||
| 329 | * | 336 | * |
| 330 | * @param client an initialized lockdownd client. | 337 | * @param client An initialized lockdownd client. |
| 331 | * @param domain the domain to query on or NULL for global domain | 338 | * @param domain The domain to query on or NULL for global domain |
| 332 | * @param key the key name to request or NULL to query for all keys | 339 | * @param key The key name to request or NULL to query for all keys |
| 333 | * @param value a plist node representing the result value node | 340 | * @param value A plist node representing the result value node |
| 334 | * | 341 | * |
| 335 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 342 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 336 | */ | 343 | */ |
| 337 | lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) | 344 | lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value) |
| 338 | { | 345 | { |
| @@ -387,14 +394,16 @@ lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *dom | |||
| 387 | return ret; | 394 | return ret; |
| 388 | } | 395 | } |
| 389 | 396 | ||
| 390 | /** Sets a preferences value using a plist and optional domain and/or key name. | 397 | /** |
| 398 | * Sets a preferences value using a plist and optional by domain and/or key name. | ||
| 391 | * | 399 | * |
| 392 | * @param client an initialized lockdownd client. | 400 | * @param client an initialized lockdownd client. |
| 393 | * @param domain the domain to query on or NULL for global domain | 401 | * @param domain the domain to query on or NULL for global domain |
| 394 | * @param key the key name to set the value or NULL to set a value dict plist | 402 | * @param key the key name to set the value or NULL to set a value dict plist |
| 395 | * @param value a plist node of any node type representing the value to set | 403 | * @param value a plist node of any node type representing the value to set |
| 396 | * | 404 | * |
| 397 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 405 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or |
| 406 | * value is NULL | ||
| 398 | */ | 407 | */ |
| 399 | lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) | 408 | lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value) |
| 400 | { | 409 | { |
| @@ -444,15 +453,16 @@ lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *dom | |||
| 444 | return ret; | 453 | return ret; |
| 445 | } | 454 | } |
| 446 | 455 | ||
| 447 | /** Removes a preference node on the device by domain and/or key name | 456 | /** |
| 457 | * Removes a preference node by domain and/or key name. | ||
| 448 | * | 458 | * |
| 449 | * @note: Use with caution as this could remove vital information on the device | 459 | * @note: Use with caution as this could remove vital information on the device |
| 450 | * | 460 | * |
| 451 | * @param client an initialized lockdownd client. | 461 | * @param client An initialized lockdownd client. |
| 452 | * @param domain the domain to query on or NULL for global domain | 462 | * @param domain The domain to query on or NULL for global domain |
| 453 | * @param key the key name to remove or NULL remove all keys for the current domain | 463 | * @param key The key name to remove or NULL remove all keys for the current domain |
| 454 | * | 464 | * |
| 455 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 465 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 456 | */ | 466 | */ |
| 457 | lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) | 467 | lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key) |
| 458 | { | 468 | { |
| @@ -501,9 +511,14 @@ lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char * | |||
| 501 | return ret; | 511 | return ret; |
| 502 | } | 512 | } |
| 503 | 513 | ||
| 504 | /** Asks for the device's unique id. Part of the lockdownd handshake. | 514 | /** |
| 515 | * Returns the unique id of the device from lockdownd. | ||
| 505 | * | 516 | * |
| 506 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 517 | * @param client An initialized lockdownd client. |
| 518 | * @param uuid Holds the unique id of the device. The caller is responsible | ||
| 519 | * for freeing the memory. | ||
| 520 | * | ||
| 521 | * @return LOCKDOWN_E_SUCCESS on success | ||
| 507 | */ | 522 | */ |
| 508 | lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid) | 523 | lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uuid) |
| 509 | { | 524 | { |
| @@ -521,9 +536,14 @@ lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t client, char **uu | |||
| 521 | return ret; | 536 | return ret; |
| 522 | } | 537 | } |
| 523 | 538 | ||
| 524 | /** Askes for the device's public key. Part of the lockdownd handshake. | 539 | /** |
| 540 | * Retrieves the public key of the device from lockdownd. | ||
| 525 | * | 541 | * |
| 526 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 542 | * @param client An initialized lockdownd client. |
| 543 | * @param public_key Holds the public key of the device. The caller is | ||
| 544 | * responsible for freeing the memory. | ||
| 545 | * | ||
| 546 | * @return LOCKDOWN_E_SUCCESS on success | ||
| 527 | */ | 547 | */ |
| 528 | lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) | 548 | lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnutls_datum_t * public_key) |
| 529 | { | 549 | { |
| @@ -546,12 +566,14 @@ lockdownd_error_t lockdownd_get_device_public_key(lockdownd_client_t client, gnu | |||
| 546 | return ret; | 566 | return ret; |
| 547 | } | 567 | } |
| 548 | 568 | ||
| 549 | /** Askes for the device's name. | 569 | /** |
| 550 | * | 570 | * Retrieves the name of the device from lockdownd set by the user. |
| 551 | * @param client The pointer to the location of the new lockdownd_client | ||
| 552 | * | 571 | * |
| 572 | * @param client An initialized lockdownd client. | ||
| 573 | * @param device_name Holds the name of the device. The caller is | ||
| 574 | * responsible for freeing the memory. | ||
| 553 | * | 575 | * |
| 554 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 576 | * @return LOCKDOWN_E_SUCCESS on success |
| 555 | */ | 577 | */ |
| 556 | lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) | 578 | lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name) |
| 557 | { | 579 | { |
| @@ -570,13 +592,17 @@ lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **de | |||
| 570 | return ret; | 592 | return ret; |
| 571 | } | 593 | } |
| 572 | 594 | ||
| 573 | /** Creates a lockdownd client for the device. | 595 | /** |
| 596 | * Creates a new lockdownd client for the device. | ||
| 574 | * | 597 | * |
| 575 | * @param phone The device to create a lockdownd client for | 598 | * @note This function does not pair with the device or start a session. This |
| 599 | * has to be done manually by the caller after the client is created. | ||
| 600 | * | ||
| 601 | * @param device The device to create a lockdownd client for | ||
| 576 | * @param client The pointer to the location of the new lockdownd_client | 602 | * @param client The pointer to the location of the new lockdownd_client |
| 577 | * @param label The label to use for communication. Usually the program name | 603 | * @param label The label to use for communication. Usually the program name. |
| 578 | * | 604 | * |
| 579 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 605 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 580 | */ | 606 | */ |
| 581 | lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label) | 607 | lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label) |
| 582 | { | 608 | { |
| @@ -609,15 +635,18 @@ lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *cli | |||
| 609 | return ret; | 635 | return ret; |
| 610 | } | 636 | } |
| 611 | 637 | ||
| 612 | /** Creates a lockdownd client for the device and starts initial handshake. | 638 | /** |
| 613 | * The handshake consists of query_type, validate_pair, pair and | 639 | * Creates a new lockdownd client for the device and starts initial handshake. |
| 614 | * start_session calls. | 640 | * The handshake consists out of query_type, validate_pair, pair and |
| 641 | * start_session calls. It uses the internal pairing record management. | ||
| 615 | * | 642 | * |
| 616 | * @param phone The device to create a lockdownd client for | 643 | * @param device The device to create a lockdownd client for |
| 617 | * @param client The pointer to the location of the new lockdownd_client | 644 | * @param client The pointer to the location of the new lockdownd_client |
| 618 | * @param label The label to use for communication. Usually the program name | 645 | * @param label The label to use for communication. Usually the program name. |
| 646 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 619 | * | 647 | * |
| 620 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 648 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 649 | * LOCKDOWN_E_INVALID_CONF if configuration data is wrong | ||
| 621 | */ | 650 | */ |
| 622 | lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label) | 651 | lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label) |
| 623 | { | 652 | { |
| @@ -690,6 +719,14 @@ lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdown | |||
| 690 | return ret; | 719 | return ret; |
| 691 | } | 720 | } |
| 692 | 721 | ||
| 722 | /** | ||
| 723 | * Returns a new plist from the supplied lockdownd pair record. The caller is | ||
| 724 | * responsible for freeing the plist. | ||
| 725 | * | ||
| 726 | * @param pair_record The pair record to create a plist from. | ||
| 727 | * | ||
| 728 | * @return A pair record plist from the device, NULL if pair_record is not set | ||
| 729 | */ | ||
| 693 | static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_record) | 730 | static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_record) |
| 694 | { | 731 | { |
| 695 | if (!pair_record) | 732 | if (!pair_record) |
| @@ -712,6 +749,17 @@ static plist_t lockdownd_pair_record_to_plist(lockdownd_pair_record_t pair_recor | |||
| 712 | return dict; | 749 | return dict; |
| 713 | } | 750 | } |
| 714 | 751 | ||
| 752 | /** | ||
| 753 | * Generates a new pairing record plist and required certificates for the | ||
| 754 | * supplied public key of the device and the host_id of the caller's host | ||
| 755 | * computer. | ||
| 756 | * | ||
| 757 | * @param public_key The public key of the device. | ||
| 758 | * @param host_id The HostID to use for the pair record plist. | ||
| 759 | * @param pair_record_plist Holds the generated pair record. | ||
| 760 | * | ||
| 761 | * @return LOCKDOWN_E_SUCCESS on success | ||
| 762 | */ | ||
| 715 | static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, char *host_id, plist_t *pair_record_plist) | 763 | static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, char *host_id, plist_t *pair_record_plist) |
| 716 | { | 764 | { |
| 717 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; | 765 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| @@ -743,7 +791,8 @@ static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, c | |||
| 743 | return ret; | 791 | return ret; |
| 744 | } | 792 | } |
| 745 | 793 | ||
| 746 | /** Function used internally by lockdownd_pair() and lockdownd_validate_pair() | 794 | /** |
| 795 | * Function used internally by lockdownd_pair() and lockdownd_validate_pair() | ||
| 747 | * | 796 | * |
| 748 | * @param client The lockdown client to pair with. | 797 | * @param client The lockdown client to pair with. |
| 749 | * @param pair_record The pair record to use for pairing. If NULL is passed, then | 798 | * @param pair_record The pair record to use for pairing. If NULL is passed, then |
| @@ -751,10 +800,17 @@ static lockdownd_error_t generate_pair_record_plist(gnutls_datum_t public_key, c | |||
| 751 | * generated automatically when pairing is done for the first time. | 800 | * generated automatically when pairing is done for the first time. |
| 752 | * @param verb This is either "Pair", "ValidatePair" or "Unpair". | 801 | * @param verb This is either "Pair", "ValidatePair" or "Unpair". |
| 753 | * | 802 | * |
| 754 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 803 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 804 | * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, | ||
| 805 | * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, | ||
| 806 | * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, | ||
| 807 | * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id | ||
| 755 | */ | 808 | */ |
| 756 | static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record, const char *verb) | 809 | static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record, const char *verb) |
| 757 | { | 810 | { |
| 811 | if (!client) | ||
| 812 | return LOCKDOWN_E_INVALID_ARG; | ||
| 813 | |||
| 758 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; | 814 | lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; |
| 759 | plist_t dict = NULL; | 815 | plist_t dict = NULL; |
| 760 | plist_t dict_record = NULL; | 816 | plist_t dict_record = NULL; |
| @@ -855,15 +911,18 @@ static lockdownd_error_t lockdownd_do_pair(lockdownd_client_t client, lockdownd_ | |||
| 855 | } | 911 | } |
| 856 | 912 | ||
| 857 | /** | 913 | /** |
| 858 | * Pairs the device with the given HostID. | 914 | * Pairs the device using the supplied pair record. |
| 859 | * It's part of the lockdownd handshake. | ||
| 860 | * | 915 | * |
| 861 | * @param client The lockdown client to pair with. | 916 | * @param client The lockdown client to pair with. |
| 862 | * @param pair_record The pair record to use for pairing. If NULL is passed, then | 917 | * @param pair_record The pair record to use for pairing. If NULL is passed, then |
| 863 | * the pair records from the current machine are used. New records will be | 918 | * the pair records from the current machine are used. New records will be |
| 864 | * generated automatically when pairing is done for the first time. | 919 | * generated automatically when pairing is done for the first time. |
| 865 | * | 920 | * |
| 866 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 921 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 922 | * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, | ||
| 923 | * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, | ||
| 924 | * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, | ||
| 925 | * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id | ||
| 867 | */ | 926 | */ |
| 868 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) | 927 | lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) |
| 869 | { | 928 | { |
| @@ -871,17 +930,21 @@ lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_recor | |||
| 871 | } | 930 | } |
| 872 | 931 | ||
| 873 | /** | 932 | /** |
| 874 | * Pairs the device with the given HostID. The difference to lockdownd_pair() | 933 | * Validates if the device is paired with the given HostID. If succeeded them |
| 875 | * is that the specified host will become trusted host of the device. | 934 | * specified host will become trusted host of the device indicated by the |
| 876 | * It's part of the lockdownd handshake. | 935 | * lockdownd preference named TrustedHostAttached. Otherwise the host must because |
| 936 | * paired using lockdownd_pair() first. | ||
| 877 | * | 937 | * |
| 878 | * @param client The lockdown client to pair with. | 938 | * @param client The lockdown client to pair with. |
| 879 | * @param pair_record The pair record to validate pairing with. If NULL is | 939 | * @param pair_record The pair record to validate pairing with. If NULL is |
| 880 | * passed, then the pair records from the current machine are used. | 940 | * passed, then the pair record is read from the internal pairing record |
| 881 | * New records will be generated automatically when pairing is done | 941 | * management. |
| 882 | * for the first time. | ||
| 883 | * | 942 | * |
| 884 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 943 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 944 | * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, | ||
| 945 | * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, | ||
| 946 | * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, | ||
| 947 | * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id | ||
| 885 | */ | 948 | */ |
| 886 | lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) | 949 | lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) |
| 887 | { | 950 | { |
| @@ -890,13 +953,17 @@ lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_p | |||
| 890 | 953 | ||
| 891 | /** | 954 | /** |
| 892 | * Unpairs the device with the given HostID and removes the pairing records | 955 | * Unpairs the device with the given HostID and removes the pairing records |
| 893 | * from the device and host. | 956 | * from the device and host if the internal pairing record management is used. |
| 894 | * | 957 | * |
| 895 | * @param client The lockdown client to pair with. | 958 | * @param client The lockdown client to pair with. |
| 896 | * @param pair_record The pair record to use for unpair. If NULL is passed, then | 959 | * @param pair_record The pair record to use for unpair. If NULL is passed, then |
| 897 | * the pair records from the current machine are used. | 960 | * the pair records from the current machine are used. |
| 898 | * | 961 | * |
| 899 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 962 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 963 | * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong, | ||
| 964 | * LOCKDOWN_E_PAIRING_FAILED if the pairing failed, | ||
| 965 | * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected, | ||
| 966 | * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id | ||
| 900 | */ | 967 | */ |
| 901 | lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) | 968 | lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record) |
| 902 | { | 969 | { |
| @@ -908,7 +975,7 @@ lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_rec | |||
| 908 | * | 975 | * |
| 909 | * @param client The lockdown client | 976 | * @param client The lockdown client |
| 910 | * | 977 | * |
| 911 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 978 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL |
| 912 | */ | 979 | */ |
| 913 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) | 980 | lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) |
| 914 | { | 981 | { |
| @@ -939,12 +1006,12 @@ lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client) | |||
| 939 | } | 1006 | } |
| 940 | 1007 | ||
| 941 | /** | 1008 | /** |
| 942 | * Performs the Goodbye Request to tell the device the communication | 1009 | * Sends the Goodbye request to lockdownd signaling the end of communication. |
| 943 | * session is now closed. | ||
| 944 | * | 1010 | * |
| 945 | * @param client The lockdown client | 1011 | * @param client The lockdown client |
| 946 | * | 1012 | * |
| 947 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1013 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 1014 | * LOCKDOWN_E_PLIST_ERROR if the device did not acknowledge the request | ||
| 948 | */ | 1015 | */ |
| 949 | lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) | 1016 | lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) |
| 950 | { | 1017 | { |
| @@ -978,10 +1045,18 @@ lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client) | |||
| 978 | return ret; | 1045 | return ret; |
| 979 | } | 1046 | } |
| 980 | 1047 | ||
| 981 | /** Generates the device certificate from the public key as well as the host | 1048 | /** |
| 982 | * and root certificates. | 1049 | * Generates the device certificate from the public key as well as the host |
| 1050 | * and root certificates. | ||
| 983 | * | 1051 | * |
| 984 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1052 | * @param public_key The public key of the device to use for generation. |
| 1053 | * @param odevice_cert Holds the generated device certificate. | ||
| 1054 | * @param ohost_cert Holds the generated host certificate. | ||
| 1055 | * @param oroot_cert Holds the generated root certificate. | ||
| 1056 | * | ||
| 1057 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when a parameter is NULL, | ||
| 1058 | * LOCKDOWN_E_INVALID_CONF if the internal configuration system failed, | ||
| 1059 | * LOCKDOWN_E_SSL_ERROR if the certificates could not be generated | ||
| 985 | */ | 1060 | */ |
| 986 | lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, | 1061 | lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datum_t * odevice_cert, |
| 987 | gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) | 1062 | gnutls_datum_t * ohost_cert, gnutls_datum_t * oroot_cert) |
| @@ -1116,15 +1191,18 @@ lockdownd_error_t lockdownd_gen_pair_cert(gnutls_datum_t public_key, gnutls_datu | |||
| 1116 | return ret; | 1191 | return ret; |
| 1117 | } | 1192 | } |
| 1118 | 1193 | ||
| 1119 | /** Starts communication with lockdownd after the device has been paired, | 1194 | /** |
| 1120 | * and if the device requires it, switches to SSL mode. | 1195 | * Opens a session with lockdownd and switches to SSL mode if device wants it. |
| 1121 | * | 1196 | * |
| 1122 | * @param client The lockdownd client | 1197 | * @param client The lockdownd client |
| 1123 | * @param host_id The HostID of the computer | 1198 | * @param host_id The HostID of the computer |
| 1124 | * @param session_id The session_id of the created session | 1199 | * @param session_id The new session_id of the created session |
| 1125 | * @param ssl_enabled Whether SSL communication is used in the session | 1200 | * @param ssl_enabled Whether SSL communication is used in the session |
| 1126 | * | 1201 | * |
| 1127 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1202 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when a client or |
| 1203 | * host_id is NULL, LOCKDOWN_E_PLIST_ERROR if the response plist had errors, | ||
| 1204 | * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the supplied HostID, | ||
| 1205 | * LOCKDOWN_E_SSL_ERROR if enabling SSL communication failed | ||
| 1128 | */ | 1206 | */ |
| 1129 | lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled) | 1207 | lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled) |
| 1130 | { | 1208 | { |
| @@ -1212,13 +1290,17 @@ lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char | |||
| 1212 | return ret; | 1290 | return ret; |
| 1213 | } | 1291 | } |
| 1214 | 1292 | ||
| 1215 | /** Command to start the desired service | 1293 | /** |
| 1294 | * Requests to start a service and retrieve it's port on success. | ||
| 1216 | * | 1295 | * |
| 1217 | * @param client The lockdownd client | 1296 | * @param client The lockdownd client |
| 1218 | * @param service The name of the service to start | 1297 | * @param service The name of the service to start |
| 1219 | * @param port The port number the service was started on | 1298 | * @param port The port number the service was started on |
| 1220 | 1299 | ||
| 1221 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1300 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG if a parameter |
| 1301 | * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known | ||
| 1302 | * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because | ||
| 1303 | * started by the device | ||
| 1222 | */ | 1304 | */ |
| 1223 | lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) | 1305 | lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port) |
| 1224 | { | 1306 | { |
| @@ -1300,10 +1382,15 @@ lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char | |||
| 1300 | * | 1382 | * |
| 1301 | * @see http://iphone-docs.org/doku.php?id=docs:protocols:activation | 1383 | * @see http://iphone-docs.org/doku.php?id=docs:protocols:activation |
| 1302 | * | 1384 | * |
| 1303 | * @param control The lockdown client | 1385 | * @param client The lockdown client |
| 1304 | * @param activation_record The activation record plist dictionary | 1386 | * @param activation_record The activation record plist dictionary |
| 1305 | * | 1387 | * |
| 1306 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1388 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client or |
| 1389 | * activation_record is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if no session is | ||
| 1390 | * open, LOCKDOWN_E_PLIST_ERROR if the received plist is broken, | ||
| 1391 | * LOCKDOWN_E_ACTIVATION_FAILED if the activation failed, | ||
| 1392 | * LOCKDOWN_E_INVALID_ACTIVATION_RECORD if the device reports that the | ||
| 1393 | * activation_record is invalid | ||
| 1307 | */ | 1394 | */ |
| 1308 | lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) | 1395 | lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record) |
| 1309 | { | 1396 | { |
| @@ -1357,12 +1444,14 @@ lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activati | |||
| 1357 | } | 1444 | } |
| 1358 | 1445 | ||
| 1359 | /** | 1446 | /** |
| 1360 | * Deactivates the device, returning it to the locked | 1447 | * Deactivates the device, returning it to the locked “Activate with iTunes” |
| 1361 | * “Activate with iTunes” screen. | 1448 | * screen. |
| 1362 | * | 1449 | * |
| 1363 | * @param control The lockdown client | 1450 | * @param client The lockdown client |
| 1364 | * | 1451 | * |
| 1365 | * @return an error code (LOCKDOWN_E_SUCCESS on success) | 1452 | * @return LOCKDOWN_E_SUCCESS on success, NP_E_INVALID_ARG when client is NULL, |
| 1453 | * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open, | ||
| 1454 | * LOCKDOWN_E_PLIST_ERROR if the received plist is broken | ||
| 1366 | */ | 1455 | */ |
| 1367 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) | 1456 | lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client) |
| 1368 | { | 1457 | { |
