2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file identity/gnunet-service-identity.c
23 * @brief identity management service
24 * @author Christian Grothoff
26 * The purpose of this service is to manage private keys that
27 * represent the various egos/pseudonyms/identities of a GNUnet user.
30 * - auto-initialze default egos; maybe trigger default
31 * initializations (such as gnunet-gns-import.sh?)
34 #include "gnunet_util_lib.h"
35 #include "gnunet_constants.h"
36 #include "gnunet_protocols.h"
37 #include "gnunet_statistics_service.h"
38 #include "gnunet_identity_service.h"
43 * Information we keep about each ego.
48 * We keep egos in a DLL.
53 * We keep egos in a DLL.
58 * Private key of the ego.
60 struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
63 * String identifier for the ego.
70 * Handle to our current configuration.
72 static const struct GNUNET_CONFIGURATION_Handle *cfg;
75 * Handle to subsystem configuration which for each subsystem contains
76 * the name of the default ego.
78 static struct GNUNET_CONFIGURATION_Handle *subsystem_cfg;
81 * Handle to the statistics service.
83 static struct GNUNET_STATISTICS_Handle *stats;
86 * Notification context, simplifies client broadcasts.
88 static struct GNUNET_NotificationContext *nc;
91 * Directory where we store the identities.
93 static char *ego_directory;
96 * Configuration file name where subsystem information is kept.
98 static char *subsystem_cfg_file;
101 * Head of DLL of all egos.
103 static struct Ego *ego_head;
106 * Tail of DLL of all egos.
108 static struct Ego *ego_tail;
112 * Get the name of the file we use to store a given ego.
114 * @param ego ego for which we need the filename
115 * @return full filename for the given ego
118 get_ego_filename (struct Ego *ego)
122 GNUNET_asprintf (&filename,
131 * Called whenever a client is disconnected.
134 * @param client identification of the client
135 * @param app_ctx @a client
138 client_disconnect_cb (void *cls,
139 struct GNUNET_SERVICE_Client *client,
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
147 * Add a client to our list of active clients.
150 * @param client client to add
151 * @param mq message queue for @a client
152 * @return internal namestore client structure for this client
155 client_connect_cb (void *cls,
156 struct GNUNET_SERVICE_Client *client,
157 struct GNUNET_MQ_Handle *mq)
163 * Task run during shutdown.
168 shutdown_task (void *cls)
174 GNUNET_notification_context_destroy (nc);
179 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
182 GNUNET_CONFIGURATION_destroy (subsystem_cfg);
183 subsystem_cfg = NULL;
184 GNUNET_free (subsystem_cfg_file);
185 subsystem_cfg_file = NULL;
186 GNUNET_free (ego_directory);
187 ego_directory = NULL;
188 while (NULL != (e = ego_head))
190 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
192 GNUNET_free (e->identifier);
199 * Send a result code back to the client.
201 * @param client client that should receive the result code
202 * @param result_code code to transmit
203 * @param emsg error message to include (or NULL for none)
206 send_result_code (struct GNUNET_SERVICE_Client *client,
207 uint32_t result_code,
210 struct ResultCodeMessage *rcm;
211 struct GNUNET_MQ_Envelope *env;
217 elen = strlen (emsg) + 1;
219 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
220 rcm->result_code = htonl (result_code);
222 GNUNET_memcpy (&rcm[1], emsg, elen);
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Sending result %d (%s) to client\n",
227 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
232 * Create an update message with information about the current state of an ego.
234 * @param ego ego to create message for
235 * @return corresponding update message
237 static struct GNUNET_MQ_Envelope *
238 create_update_message (struct Ego *ego)
240 struct UpdateMessage *um;
241 struct GNUNET_MQ_Envelope *env;
244 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
245 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
246 um->name_len = htons (name_len);
247 um->end_of_list = htons (GNUNET_NO);
248 um->private_key = *ego->pk;
249 GNUNET_memcpy (&um[1], ego->identifier, name_len);
255 * Create a set default message with information about the current state of an ego.
257 * @param ego ego to create message for
258 * @param servicename name of the service to provide in the message
259 * @return corresponding set default message
261 static struct GNUNET_MQ_Envelope *
262 create_set_default_message (struct Ego *ego, const char *servicename)
264 struct SetDefaultMessage *sdm;
265 struct GNUNET_MQ_Envelope *env;
268 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
269 env = GNUNET_MQ_msg_extra (sdm,
271 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
272 sdm->name_len = htons (name_len);
273 sdm->reserved = htons (0);
274 sdm->private_key = *ego->pk;
275 GNUNET_memcpy (&sdm[1], servicename, name_len);
281 * Handler for START message from client, sends information
282 * about all identities to the client immediately and
283 * adds the client to the notification context for future
286 * @param cls a `struct GNUNET_SERVICE_Client *`
287 * @param message the message received
290 handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
292 struct GNUNET_SERVICE_Client *client = cls;
293 struct UpdateMessage *ume;
294 struct GNUNET_MQ_Envelope *env;
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
298 GNUNET_SERVICE_client_mark_monitor (client);
299 GNUNET_SERVICE_client_disable_continue_warning (client);
300 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
301 for (ego = ego_head; NULL != ego; ego = ego->next)
303 env = create_update_message (ego);
304 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
306 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
307 ume->end_of_list = htons (GNUNET_YES);
308 ume->name_len = htons (0);
309 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
310 GNUNET_SERVICE_client_continue (client);
315 * Handler for LOOKUP message from client, sends information
316 * about ONE identity to the client immediately.
319 * @param message the message received
320 * @return #GNUNET_SYSERR if message was ill-formed
323 check_lookup_message (void *cls, const struct LookupMessage *message)
325 GNUNET_MQ_check_zero_termination (message);
331 * Handler for LOOKUP message from client, sends information
332 * about ONE identity to the client immediately.
334 * @param cls a `struct GNUNET_SERVICE_Client *`
335 * @param message the message received
338 handle_lookup_message (void *cls, const struct LookupMessage *message)
340 struct GNUNET_SERVICE_Client *client = cls;
342 struct GNUNET_MQ_Envelope *env;
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
346 name = (const char *) &message[1];
347 for (ego = ego_head; NULL != ego; ego = ego->next)
349 if (0 != strcasecmp (name, ego->identifier))
351 env = create_update_message (ego);
352 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
353 GNUNET_SERVICE_client_continue (client);
356 send_result_code (client, 0, "ego not found");
357 GNUNET_SERVICE_client_continue (client);
362 * Handler for LOOKUP message from client, sends information
363 * about ONE identity to the client immediately.
366 * @param message the message received
367 * @return #GNUNET_SYSERR if message was ill-formed
370 check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
372 GNUNET_MQ_check_zero_termination (message);
378 * Handler for LOOKUP_BY_SUFFIX message from client, sends information
379 * about ONE identity to the client immediately.
381 * @param cls a `struct GNUNET_SERVICE_Client *`
382 * @param message the message received
385 handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
387 struct GNUNET_SERVICE_Client *client = cls;
389 struct GNUNET_MQ_Envelope *env;
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "Received LOOKUP_BY_SUFFIX message from client\n");
394 name = (const char *) &message[1];
396 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
398 if ((strlen (ego->identifier) <= strlen (name)) &&
399 (0 == strcmp (ego->identifier,
400 &name[strlen (name) - strlen (ego->identifier)])) &&
401 ((strlen (name) == strlen (ego->identifier)) ||
402 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
403 ((NULL == lprefix) ||
404 (strlen (ego->identifier) > strlen (lprefix->identifier))))
406 /* found better match, update! */
412 env = create_update_message (lprefix);
413 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
414 GNUNET_SERVICE_client_continue (client);
417 send_result_code (client, 0, "ego not found");
418 GNUNET_SERVICE_client_continue (client);
423 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
425 * @param cls client sending the message
426 * @param msg message of type `struct GetDefaultMessage`
427 * @return #GNUNET_OK if @a msg is well-formed
430 check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
436 size = ntohs (msg->header.size);
437 if (size <= sizeof(struct GetDefaultMessage))
440 return GNUNET_SYSERR;
442 name = (const char *) &msg[1];
443 name_len = ntohs (msg->name_len);
444 if ((name_len + sizeof(struct GetDefaultMessage) != size) ||
445 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
448 return GNUNET_SYSERR;
455 * Handler for GET_DEFAULT message from client, returns
456 * default identity for some service.
459 * @param client who sent the message
460 * @param message the message received
463 handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
465 struct GNUNET_MQ_Envelope *env;
466 struct GNUNET_SERVICE_Client *client = cls;
472 name = GNUNET_strdup ((const char *) &gdm[1]);
473 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 "Received GET_DEFAULT for service `%s' from client\n",
477 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
479 "DEFAULT_IDENTIFIER",
482 send_result_code (client, 1, gettext_noop ("no default known"));
483 GNUNET_SERVICE_client_continue (client);
487 for (ego = ego_head; NULL != ego; ego = ego->next)
489 if (0 == strcmp (ego->identifier, identifier))
491 env = create_set_default_message (ego, name);
492 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
493 GNUNET_SERVICE_client_continue (client);
494 GNUNET_free (identifier);
499 GNUNET_free (identifier);
500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
502 send_result_code (client,
505 "default configured, but ego unknown (internal error)"));
506 GNUNET_SERVICE_client_continue (client);
511 * Compare the given two private keys for equality.
513 * @param pk1 one private key
514 * @param pk2 another private key
515 * @return 0 if the keys are equal
518 key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
519 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
521 return GNUNET_memcmp (pk1, pk2);
525 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message
527 * @param cls client sending the message
528 * @param msg message of type `struct SetDefaultMessage`
529 * @return #GNUNET_OK if @a msg is well-formed
532 check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
538 size = ntohs (msg->header.size);
539 if (size <= sizeof(struct SetDefaultMessage))
542 return GNUNET_SYSERR;
544 name_len = ntohs (msg->name_len);
545 GNUNET_break (0 == ntohs (msg->reserved));
546 if (name_len + sizeof(struct SetDefaultMessage) != size)
549 return GNUNET_SYSERR;
551 str = (const char *) &msg[1];
552 if ('\0' != str[name_len - 1])
555 return GNUNET_SYSERR;
561 * Handler for SET_DEFAULT message from client, updates
562 * default identity for some service.
565 * @param client who sent the message
566 * @param message the message received
569 handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
572 struct GNUNET_SERVICE_Client *client = cls;
575 str = GNUNET_strdup ((const char *) &sdm[1]);
576 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "Received SET_DEFAULT for service `%s' from client\n",
581 for (ego = ego_head; NULL != ego; ego = ego->next)
583 if (0 == key_cmp (ego->pk, &sdm->private_key))
585 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
587 "DEFAULT_IDENTIFIER",
590 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
592 GNUNET_ERROR_TYPE_ERROR,
593 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
595 send_result_code (client, 0, NULL);
596 GNUNET_SERVICE_client_continue (client);
601 send_result_code (client,
603 _ ("Unknown ego specified for service (internal error)"));
605 GNUNET_SERVICE_client_continue (client);
610 * Send an updated message for the given ego to all listeners.
612 * @param ego ego to send the update for
615 notify_listeners (struct Ego *ego)
617 struct UpdateMessage *um;
620 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
621 um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len);
622 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
623 um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
624 um->name_len = htons (name_len);
625 um->end_of_list = htons (GNUNET_NO);
626 um->private_key = *ego->pk;
627 GNUNET_memcpy (&um[1], ego->identifier, name_len);
628 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
633 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message
635 * @param cls client sending the message
636 * @param msg message of type `struct CreateRequestMessage`
637 * @return #GNUNET_OK if @a msg is well-formed
640 check_create_message (void *cls, const struct CreateRequestMessage *msg)
646 size = ntohs (msg->header.size);
647 if (size <= sizeof(struct CreateRequestMessage))
650 return GNUNET_SYSERR;
652 name_len = ntohs (msg->name_len);
653 GNUNET_break (0 == ntohs (msg->reserved));
654 if (name_len + sizeof(struct CreateRequestMessage) != size)
657 return GNUNET_SYSERR;
659 str = (const char *) &msg[1];
660 if ('\0' != str[name_len - 1])
663 return GNUNET_SYSERR;
669 * Handler for CREATE message from client, creates
673 * @param client who sent the message
674 * @param message the message received
677 handle_create_message (void *cls, const struct CreateRequestMessage *crm)
679 struct GNUNET_SERVICE_Client *client = cls;
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
685 str = GNUNET_strdup ((const char *) &crm[1]);
686 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
687 for (ego = ego_head; NULL != ego; ego = ego->next)
689 if (0 == strcmp (ego->identifier, str))
691 send_result_code (client,
694 "identifier already in use for another ego"));
695 GNUNET_SERVICE_client_continue (client);
700 ego = GNUNET_new (struct Ego);
701 ego->pk = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
702 *ego->pk = crm->private_key;
703 ego->identifier = GNUNET_strdup (str);
704 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
705 send_result_code (client, 0, NULL);
706 fn = get_ego_filename (ego);
707 (void) GNUNET_DISK_directory_create_for_file (fn);
708 if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
709 GNUNET_DISK_fn_write (fn,
711 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
712 GNUNET_DISK_PERM_USER_READ
713 | GNUNET_DISK_PERM_USER_WRITE))
714 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
717 notify_listeners (ego);
718 GNUNET_SERVICE_client_continue (client);
723 * Closure for 'handle_ego_rename'.
730 const char *old_name;
735 const char *new_name;
739 * An ego was renamed; rename it in all subsystems where it is
740 * currently set as the default.
742 * @param cls the 'struct RenameContext'
743 * @param section a section in the configuration to process
746 handle_ego_rename (void *cls, const char *section)
748 struct RenameContext *rc = cls;
751 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
753 "DEFAULT_IDENTIFIER",
756 if (0 != strcmp (id, rc->old_name))
761 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
763 "DEFAULT_IDENTIFIER",
769 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message
771 * @param cls client sending the message
772 * @param msg message of type `struct RenameMessage`
773 * @return #GNUNET_OK if @a msg is well-formed
776 check_rename_message (void *cls, const struct RenameMessage *msg)
779 uint16_t old_name_len;
780 uint16_t new_name_len;
781 const char *old_name;
782 const char *new_name;
784 size = ntohs (msg->header.size);
785 if (size <= sizeof(struct RenameMessage))
788 return GNUNET_SYSERR;
790 old_name_len = ntohs (msg->old_name_len);
791 new_name_len = ntohs (msg->new_name_len);
792 old_name = (const char *) &msg[1];
793 new_name = &old_name[old_name_len];
794 if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
795 ('\0' != old_name[old_name_len - 1]) ||
796 ('\0' != new_name[new_name_len - 1]))
799 return GNUNET_SYSERR;
807 * Handler for RENAME message from client, creates
811 * @param client who sent the message
812 * @param message the message received
815 handle_rename_message (void *cls, const struct RenameMessage *rm)
817 uint16_t old_name_len;
821 struct RenameContext rename_ctx;
822 struct GNUNET_SERVICE_Client *client = cls;
825 const char *old_name_tmp;
827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
828 old_name_len = ntohs (rm->old_name_len);
829 old_name_tmp = (const char *) &rm[1];
830 old_name = GNUNET_strdup (old_name_tmp);
831 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
832 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
833 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
835 /* check if new name is already in use */
836 for (ego = ego_head; NULL != ego; ego = ego->next)
838 if (0 == strcmp (ego->identifier, new_name))
840 send_result_code (client, 1, gettext_noop ("target name already exists"));
841 GNUNET_SERVICE_client_continue (client);
842 GNUNET_free (old_name);
843 GNUNET_free (new_name);
848 /* locate old name and, if found, perform rename */
849 for (ego = ego_head; NULL != ego; ego = ego->next)
851 if (0 == strcmp (ego->identifier, old_name))
853 fn_old = get_ego_filename (ego);
854 GNUNET_free (ego->identifier);
855 rename_ctx.old_name = old_name;
856 rename_ctx.new_name = new_name;
857 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
861 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
863 GNUNET_ERROR_TYPE_ERROR,
864 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
866 ego->identifier = GNUNET_strdup (new_name);
867 fn_new = get_ego_filename (ego);
868 if (0 != rename (fn_old, fn_new))
869 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
870 GNUNET_free (fn_old);
871 GNUNET_free (fn_new);
872 GNUNET_free (old_name);
873 GNUNET_free (new_name);
874 notify_listeners (ego);
875 send_result_code (client, 0, NULL);
876 GNUNET_SERVICE_client_continue (client);
881 /* failed to locate old name */
882 send_result_code (client, 1, gettext_noop ("no matching ego found"));
883 GNUNET_free (old_name);
884 GNUNET_free (new_name);
885 GNUNET_SERVICE_client_continue (client);
890 * An ego was removed, remove it from all subsystems where it is
891 * currently set as the default.
893 * @param cls name of the removed ego (const char *)
894 * @param section a section in the configuration to process
897 handle_ego_delete (void *cls, const char *section)
899 const char *identifier = cls;
902 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
904 "DEFAULT_IDENTIFIER",
907 if (0 != strcmp (id, identifier))
912 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
914 "DEFAULT_IDENTIFIER",
920 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
922 * @param cls client sending the message
923 * @param msg message of type `struct DeleteMessage`
924 * @return #GNUNET_OK if @a msg is well-formed
927 check_delete_message (void *cls, const struct DeleteMessage *msg)
933 size = ntohs (msg->header.size);
934 if (size <= sizeof(struct DeleteMessage))
937 return GNUNET_SYSERR;
939 name = (const char *) &msg[1];
940 name_len = ntohs (msg->name_len);
941 if ((name_len + sizeof(struct DeleteMessage) != size) ||
942 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
945 return GNUNET_SYSERR;
952 * Handler for DELETE message from client, creates
956 * @param client who sent the message
957 * @param message the message received
960 handle_delete_message (void *cls, const struct DeleteMessage *dm)
965 struct GNUNET_SERVICE_Client *client = cls;
967 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
968 name = GNUNET_strdup ((const char *) &dm[1]);
969 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
971 for (ego = ego_head; NULL != ego; ego = ego->next)
973 if (0 == strcmp (ego->identifier, name))
975 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
976 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
980 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
982 GNUNET_ERROR_TYPE_ERROR,
983 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
985 fn = get_ego_filename (ego);
986 if (0 != unlink (fn))
987 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
989 GNUNET_free (ego->identifier);
990 ego->identifier = NULL;
991 notify_listeners (ego);
992 GNUNET_free (ego->pk);
995 send_result_code (client, 0, NULL);
996 GNUNET_SERVICE_client_continue (client);
1001 send_result_code (client, 1, gettext_noop ("no matching ego found"));
1003 GNUNET_SERVICE_client_continue (client);
1008 * Process the given file from the "EGODIR". Parses the file
1009 * and creates the respective 'struct Ego' in memory.
1012 * @param filename name of the file to parse
1013 * @return #GNUNET_OK to continue to iterate,
1014 * #GNUNET_NO to stop iteration with no error,
1015 * #GNUNET_SYSERR to abort iteration with error!
1018 process_ego_file (void *cls, const char *filename)
1023 fn = strrchr (filename, (int) DIR_SEPARATOR);
1029 ego = GNUNET_new (struct Ego);
1030 ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename);
1031 if (NULL == ego->pk)
1034 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1035 _ ("Failed to parse ego information in `%s'\n"),
1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
1040 ego->identifier = GNUNET_strdup (fn + 1);
1041 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1047 * Handle network size estimate clients.
1049 * @param cls closure
1050 * @param server the initialized server
1051 * @param c configuration to use
1055 const struct GNUNET_CONFIGURATION_Handle *c,
1056 struct GNUNET_SERVICE_Handle *service)
1059 nc = GNUNET_notification_context_create (1);
1060 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1065 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1066 GNUNET_SCHEDULER_shutdown ();
1070 GNUNET_CONFIGURATION_get_value_filename (cfg,
1073 &subsystem_cfg_file))
1075 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1078 GNUNET_SCHEDULER_shutdown ();
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Loading subsystem configuration `%s'\n",
1083 subsystem_cfg_file);
1084 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1085 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1087 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1089 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1091 "Failed to parse subsystem identity configuration file `%s'\n"),
1092 subsystem_cfg_file);
1093 GNUNET_SCHEDULER_shutdown ();
1096 stats = GNUNET_STATISTICS_create ("identity", cfg);
1097 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1099 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1100 _ ("Failed to create directory `%s' for storing egos\n"),
1103 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
1104 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1109 * Define "main" method using service macro.
1111 GNUNET_SERVICE_MAIN (
1113 GNUNET_SERVICE_OPTION_NONE,
1116 &client_disconnect_cb,
1118 GNUNET_MQ_hd_fixed_size (start_message,
1119 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1120 struct GNUNET_MessageHeader,
1122 GNUNET_MQ_hd_var_size (lookup_message,
1123 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1124 struct LookupMessage,
1126 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1127 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1128 struct LookupMessage,
1130 GNUNET_MQ_hd_var_size (get_default_message,
1131 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1132 struct GetDefaultMessage,
1134 GNUNET_MQ_hd_var_size (set_default_message,
1135 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1136 struct SetDefaultMessage,
1138 GNUNET_MQ_hd_var_size (create_message,
1139 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1140 struct CreateRequestMessage,
1142 GNUNET_MQ_hd_var_size (rename_message,
1143 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1144 struct RenameMessage,
1146 GNUNET_MQ_hd_var_size (delete_message,
1147 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1148 struct DeleteMessage,
1150 GNUNET_MQ_handler_end ());
1153 /* end of gnunet-service-identity.c */