diff options
-rw-r--r-- | src/identity/gnunet-service-identity.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/identity/gnunet-service-identity.c b/src/identity/gnunet-service-identity.c index 166f86697..4de7746b0 100644 --- a/src/identity/gnunet-service-identity.c +++ b/src/identity/gnunet-service-identity.c | |||
@@ -25,9 +25,6 @@ | |||
25 | * | 25 | * |
26 | * The purpose of this service is to manage private keys that | 26 | * The purpose of this service is to manage private keys that |
27 | * represent the various egos/pseudonyms/identities of a GNUnet user. | 27 | * represent the various egos/pseudonyms/identities of a GNUnet user. |
28 | * | ||
29 | * TODO: | ||
30 | * - disk operations | ||
31 | */ | 28 | */ |
32 | #include "platform.h" | 29 | #include "platform.h" |
33 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
@@ -484,8 +481,10 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
484 | uint16_t name_len; | 481 | uint16_t name_len; |
485 | uint16_t pk_len; | 482 | uint16_t pk_len; |
486 | struct Ego *ego; | 483 | struct Ego *ego; |
484 | const char *pks; | ||
487 | const char *str; | 485 | const char *str; |
488 | struct GNUNET_CRYPTO_EccPrivateKey *pk; | 486 | struct GNUNET_CRYPTO_EccPrivateKey *pk; |
487 | char *fn; | ||
489 | 488 | ||
490 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 489 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
491 | "Received CREATE message from client\n"); | 490 | "Received CREATE message from client\n"); |
@@ -499,15 +498,15 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
499 | crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message; | 498 | crm = (const struct GNUNET_IDENTITY_CreateRequestMessage *) message; |
500 | name_len = ntohs (crm->name_len); | 499 | name_len = ntohs (crm->name_len); |
501 | pk_len = ntohs (crm->pk_len); | 500 | pk_len = ntohs (crm->pk_len); |
502 | str = (const char *) &crm[1]; | 501 | pks = (const char *) &crm[1]; |
503 | if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) || | 502 | if ( (name_len + pk_len + sizeof (struct GNUNET_IDENTITY_CreateRequestMessage) != size) || |
504 | (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (str, pk_len, GNUNET_YES))) ) | 503 | (NULL == (pk = GNUNET_CRYPTO_ecc_decode_key (pks, pk_len, GNUNET_YES))) ) |
505 | { | 504 | { |
506 | GNUNET_break (0); | 505 | GNUNET_break (0); |
507 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 506 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
508 | return; | 507 | return; |
509 | } | 508 | } |
510 | str = &str[pk_len]; | 509 | str = &pks[pk_len]; |
511 | if ('\0' != str[name_len - 1]) | 510 | if ('\0' != str[name_len - 1]) |
512 | { | 511 | { |
513 | GNUNET_break (0); | 512 | GNUNET_break (0); |
@@ -532,7 +531,15 @@ handle_create_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
532 | ego_tail, | 531 | ego_tail, |
533 | ego); | 532 | ego); |
534 | send_result_code (client, 0, NULL); | 533 | send_result_code (client, 0, NULL); |
535 | /* FIXME: also write to file! */ | 534 | fn = get_ego_filename (ego); |
535 | (void) GNUNET_DISK_directory_create_for_file (fn); | ||
536 | if (pk_len != | ||
537 | GNUNET_DISK_fn_write (fn, pks, pk_len, | ||
538 | GNUNET_DISK_PERM_USER_READ | | ||
539 | GNUNET_DISK_PERM_USER_WRITE)) | ||
540 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
541 | "write", fn); | ||
542 | GNUNET_free (fn); | ||
536 | notify_listeners (ego); | 543 | notify_listeners (ego); |
537 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 544 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
538 | } | 545 | } |
@@ -633,6 +640,8 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
633 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 640 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
634 | return; | 641 | return; |
635 | } | 642 | } |
643 | |||
644 | /* check if new name is already in use */ | ||
636 | for (ego = ego_head; NULL != ego; ego = ego->next) | 645 | for (ego = ego_head; NULL != ego; ego = ego->next) |
637 | { | 646 | { |
638 | if (0 == strcmp (ego->identifier, | 647 | if (0 == strcmp (ego->identifier, |
@@ -644,6 +653,7 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
644 | } | 653 | } |
645 | } | 654 | } |
646 | 655 | ||
656 | /* locate old name and, if found, perform rename */ | ||
647 | for (ego = ego_head; NULL != ego; ego = ego->next) | 657 | for (ego = ego_head; NULL != ego; ego = ego->next) |
648 | { | 658 | { |
649 | if (0 == strcmp (ego->identifier, | 659 | if (0 == strcmp (ego->identifier, |
@@ -663,8 +673,7 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
663 | _("Failed to write subsystem default identifier map to `%s'.\n"), | 673 | _("Failed to write subsystem default identifier map to `%s'.\n"), |
664 | subsystem_cfg_file); | 674 | subsystem_cfg_file); |
665 | ego->identifier = GNUNET_strdup (new_name); | 675 | ego->identifier = GNUNET_strdup (new_name); |
666 | fn_new = get_ego_filename (ego); | 676 | fn_new = get_ego_filename (ego); |
667 | |||
668 | if (0 != RENAME (fn_old, fn_new)) | 677 | if (0 != RENAME (fn_old, fn_new)) |
669 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); | 678 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); |
670 | GNUNET_free (fn_old); | 679 | GNUNET_free (fn_old); |
@@ -676,6 +685,7 @@ handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, | |||
676 | } | 685 | } |
677 | } | 686 | } |
678 | 687 | ||
688 | /* failed to locate old name */ | ||
679 | send_result_code (client, 1, gettext_noop ("no matching ego found")); | 689 | send_result_code (client, 1, gettext_noop ("no matching ego found")); |
680 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 690 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
681 | } | 691 | } |