summaryrefslogtreecommitdiffstats
path: root/src/userpref.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/userpref.c')
-rw-r--r--src/userpref.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/src/userpref.c b/src/userpref.c
index 2f4e55b..a0c3545 100644
--- a/src/userpref.c
+++ b/src/userpref.c
@@ -432,26 +432,26 @@ void userpref_get_host_id(char **host_id)
432/** 432/**
433 * Determines whether this device has been connected to this system before. 433 * Determines whether this device has been connected to this system before.
434 * 434 *
435 * @param uid The device uid as given by the device. 435 * @param udid The device UDID as given by the device.
436 * 436 *
437 * @return 1 if the device has been connected previously to this configuration 437 * @return 1 if the device has been connected previously to this configuration
438 * or 0 otherwise. 438 * or 0 otherwise.
439 */ 439 */
440int userpref_has_device_public_key(const char *uuid) 440int userpref_has_device_public_key(const char *udid)
441{ 441{
442 int ret = 0; 442 int ret = 0;
443 const char *config_path; 443 const char *config_path;
444 char *config_file; 444 char *config_file;
445 struct stat st; 445 struct stat st;
446 446
447 if (!uuid) return 0; 447 if (!udid) return 0;
448 448
449 /* first get config file */ 449 /* first get config file */
450 config_path = userpref_get_config_dir(); 450 config_path = userpref_get_config_dir();
451 config_file = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1); 451 config_file = (char*)malloc(strlen(config_path)+1+strlen(udid)+4+1);
452 strcpy(config_file, config_path); 452 strcpy(config_file, config_path);
453 strcat(config_file, DIR_SEP_S); 453 strcat(config_file, DIR_SEP_S);
454 strcat(config_file, uuid); 454 strcat(config_file, udid);
455 strcat(config_file, ".pem"); 455 strcat(config_file, ".pem");
456 456
457 if ((stat(config_file, &st) == 0) && S_ISREG(st.st_mode)) 457 if ((stat(config_file, &st) == 0) && S_ISREG(st.st_mode))
@@ -461,21 +461,21 @@ int userpref_has_device_public_key(const char *uuid)
461} 461}
462 462
463/** 463/**
464 * Fills a list with UUIDs of devices that have been connected to this 464 * Fills a list with UDIDs of devices that have been connected to this
465 * system before, i.e. for which a public key file exists. 465 * system before, i.e. for which a public key file exists.
466 * 466 *
467 * @param list A pointer to a char** initially pointing to NULL that will 467 * @param list A pointer to a char** initially pointing to NULL that will
468 * hold a newly allocated list of UUIDs upon successful return. 468 * hold a newly allocated list of UDIDs upon successful return.
469 * The caller is responsible for freeing the memory. Note that if 469 * The caller is responsible for freeing the memory. Note that if
470 * no public key file was found the list has to be freed too as it 470 * no public key file was found the list has to be freed too as it
471 * points to a terminating NULL element. 471 * points to a terminating NULL element.
472 * @param count The number of UUIDs found. This parameter can be NULL if it 472 * @param count The number of UDIDs found. This parameter can be NULL if it
473 * is not required. 473 * is not required.
474 * 474 *
475 * @return USERPREF_E_SUCCESS on success, or USERPREF_E_INVALID_ARG if the 475 * @return USERPREF_E_SUCCESS on success, or USERPREF_E_INVALID_ARG if the
476 * list parameter is not pointing to NULL. 476 * list parameter is not pointing to NULL.
477 */ 477 */
478userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count) 478userpref_error_t userpref_get_paired_udids(char ***list, unsigned int *count)
479{ 479{
480 struct slist_t { 480 struct slist_t {
481 char *name; 481 char *name;
@@ -483,7 +483,7 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
483 }; 483 };
484 DIR *config_dir; 484 DIR *config_dir;
485 const char *config_path; 485 const char *config_path;
486 struct slist_t *uuids = NULL; 486 struct slist_t *udids = NULL;
487 unsigned int i; 487 unsigned int i;
488 unsigned int found = 0; 488 unsigned int found = 0;
489 489
@@ -500,7 +500,7 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
500 config_dir = opendir(config_path); 500 config_dir = opendir(config_path);
501 if (config_dir) { 501 if (config_dir) {
502 struct dirent *entry; 502 struct dirent *entry;
503 struct slist_t *listp = uuids; 503 struct slist_t *listp = udids;
504 while ((entry = readdir(config_dir))) { 504 while ((entry = readdir(config_dir))) {
505 char *ext = strstr(entry->d_name, ".pem"); 505 char *ext = strstr(entry->d_name, ".pem");
506 if (ext && ((ext - entry->d_name) == 40) && (strlen(entry->d_name) == 44)) { 506 if (ext && ((ext - entry->d_name) == 40) && (strlen(entry->d_name) == 44)) {
@@ -511,7 +511,7 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
511 ne->next = NULL; 511 ne->next = NULL;
512 if (!listp) { 512 if (!listp) {
513 listp = ne; 513 listp = ne;
514 uuids = listp; 514 udids = listp;
515 } else { 515 } else {
516 listp->next = ne; 516 listp->next = ne;
517 listp = listp->next; 517 listp = listp->next;
@@ -523,10 +523,10 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
523 } 523 }
524 *list = (char**)malloc(sizeof(char*) * (found+1)); 524 *list = (char**)malloc(sizeof(char*) * (found+1));
525 i = 0; 525 i = 0;
526 while (uuids) { 526 while (udids) {
527 (*list)[i++] = uuids->name; 527 (*list)[i++] = udids->name;
528 struct slist_t *old = uuids; 528 struct slist_t *old = udids;
529 uuids = uuids->next; 529 udids = udids->next;
530 free(old); 530 free(old);
531 } 531 }
532 (*list)[i] = NULL; 532 (*list)[i] = NULL;
@@ -542,17 +542,18 @@ userpref_error_t userpref_get_paired_uuids(char ***list, unsigned int *count)
542 * Mark the device (as represented by the key) as having connected to this 542 * Mark the device (as represented by the key) as having connected to this
543 * configuration. 543 * configuration.
544 * 544 *
545 * @param udid The device UDID as given by the device
545 * @param public_key The public key given by the device 546 * @param public_key The public key given by the device
546 * 547 *
547 * @return 1 on success and 0 if no public key is given or if it has already 548 * @return 1 on success and 0 if no public key is given or if it has already
548 * been marked as connected previously. 549 * been marked as connected previously.
549 */ 550 */
550userpref_error_t userpref_set_device_public_key(const char *uuid, key_data_t public_key) 551userpref_error_t userpref_set_device_public_key(const char *udid, key_data_t public_key)
551{ 552{
552 if (NULL == public_key.data) 553 if (NULL == public_key.data)
553 return USERPREF_E_INVALID_ARG; 554 return USERPREF_E_INVALID_ARG;
554 555
555 if (userpref_has_device_public_key(uuid)) 556 if (userpref_has_device_public_key(udid))
556 return USERPREF_E_SUCCESS; 557 return USERPREF_E_SUCCESS;
557 558
558 /* ensure config directory exists */ 559 /* ensure config directory exists */
@@ -560,10 +561,10 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, key_data_t pub
560 561
561 /* build file path */ 562 /* build file path */
562 const char *config_path = userpref_get_config_dir(); 563 const char *config_path = userpref_get_config_dir();
563 char *pem = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1); 564 char *pem = (char*)malloc(strlen(config_path)+1+strlen(udid)+4+1);
564 strcpy(pem, config_path); 565 strcpy(pem, config_path);
565 strcat(pem, DIR_SEP_S); 566 strcat(pem, DIR_SEP_S);
566 strcat(pem, uuid); 567 strcat(pem, udid);
567 strcat(pem, ".pem"); 568 strcat(pem, ".pem");
568 569
569 /* store file */ 570 /* store file */
@@ -580,23 +581,23 @@ userpref_error_t userpref_set_device_public_key(const char *uuid, key_data_t pub
580} 581}
581 582
582/** 583/**
583 * Remove the public key stored for the device with uuid from this host. 584 * Remove the public key stored for the device with udid from this host.
584 * 585 *
585 * @param uuid The uuid of the device 586 * @param udid The udid of the device
586 * 587 *
587 * @return USERPREF_E_SUCCESS on success. 588 * @return USERPREF_E_SUCCESS on success.
588 */ 589 */
589userpref_error_t userpref_remove_device_public_key(const char *uuid) 590userpref_error_t userpref_remove_device_public_key(const char *udid)
590{ 591{
591 if (!userpref_has_device_public_key(uuid)) 592 if (!userpref_has_device_public_key(udid))
592 return USERPREF_E_SUCCESS; 593 return USERPREF_E_SUCCESS;
593 594
594 /* build file path */ 595 /* build file path */
595 const char *config_path = userpref_get_config_dir(); 596 const char *config_path = userpref_get_config_dir();
596 char *pem = (char*)malloc(strlen(config_path)+1+strlen(uuid)+4+1); 597 char *pem = (char*)malloc(strlen(config_path)+1+strlen(udid)+4+1);
597 strcpy(pem, config_path); 598 strcpy(pem, config_path);
598 strcat(pem, DIR_SEP_S); 599 strcat(pem, DIR_SEP_S);
599 strcat(pem, uuid); 600 strcat(pem, udid);
600 strcat(pem, ".pem"); 601 strcat(pem, ".pem");
601 602
602 /* remove file */ 603 /* remove file */