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,
132 * Called whenever a client is disconnected.
135 * @param client identification of the client
136 * @param app_ctx @a client
139 client_disconnect_cb (void *cls,
140 struct GNUNET_SERVICE_Client *client,
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
148 * Add a client to our list of active clients.
151 * @param client client to add
152 * @param mq message queue for @a client
153 * @return internal namestore client structure for this client
156 client_connect_cb (void *cls,
157 struct GNUNET_SERVICE_Client *client,
158 struct GNUNET_MQ_Handle *mq)
165 * Task run during shutdown.
170 shutdown_task (void *cls)
176 GNUNET_notification_context_destroy (nc);
181 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
184 GNUNET_CONFIGURATION_destroy (subsystem_cfg);
185 subsystem_cfg = NULL;
186 GNUNET_free (subsystem_cfg_file);
187 subsystem_cfg_file = NULL;
188 GNUNET_free (ego_directory);
189 ego_directory = NULL;
190 while (NULL != (e = ego_head))
192 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, e);
193 GNUNET_free (e->identifier);
200 * Send a result code back to the client.
202 * @param client client that should receive the result code
203 * @param result_code code to transmit
204 * @param emsg error message to include (or NULL for none)
207 send_result_code (struct GNUNET_SERVICE_Client *client,
208 uint32_t result_code,
211 struct ResultCodeMessage *rcm;
212 struct GNUNET_MQ_Envelope *env;
218 elen = strlen (emsg) + 1;
220 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
221 rcm->result_code = htonl (result_code);
223 GNUNET_memcpy (&rcm[1], emsg, elen);
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Sending result %d (%s) to client\n",
228 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
233 * Create an update message with information about the current state of an ego.
235 * @param ego ego to create message for
236 * @return corresponding update message
238 static struct GNUNET_MQ_Envelope *
239 create_update_message (struct Ego *ego)
241 struct UpdateMessage *um;
242 struct GNUNET_MQ_Envelope *env;
245 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
246 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
247 um->name_len = htons (name_len);
248 um->end_of_list = htons (GNUNET_NO);
249 um->private_key = ego->pk;
250 GNUNET_memcpy (&um[1], ego->identifier, name_len);
256 * Create a set default message with information about the current state of an ego.
258 * @param ego ego to create message for
259 * @param servicename name of the service to provide in the message
260 * @return corresponding set default message
262 static struct GNUNET_MQ_Envelope *
263 create_set_default_message (struct Ego *ego, const char *servicename)
265 struct SetDefaultMessage *sdm;
266 struct GNUNET_MQ_Envelope *env;
269 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
270 env = GNUNET_MQ_msg_extra (sdm,
272 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
273 sdm->name_len = htons (name_len);
274 sdm->reserved = htons (0);
275 sdm->private_key = ego->pk;
276 GNUNET_memcpy (&sdm[1], servicename, name_len);
282 * Handler for START message from client, sends information
283 * about all identities to the client immediately and
284 * adds the client to the notification context for future
287 * @param cls a `struct GNUNET_SERVICE_Client *`
288 * @param message the message received
291 handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
293 struct GNUNET_SERVICE_Client *client = cls;
294 struct UpdateMessage *ume;
295 struct GNUNET_MQ_Envelope *env;
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
299 GNUNET_SERVICE_client_mark_monitor (client);
300 GNUNET_SERVICE_client_disable_continue_warning (client);
301 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
302 for (ego = ego_head; NULL != ego; ego = ego->next)
304 env = create_update_message (ego);
305 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
307 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
308 ume->end_of_list = htons (GNUNET_YES);
309 ume->name_len = htons (0);
310 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
311 GNUNET_SERVICE_client_continue (client);
316 * Handler for LOOKUP message from client, sends information
317 * about ONE identity to the client immediately.
320 * @param message the message received
321 * @return #GNUNET_SYSERR if message was ill-formed
324 check_lookup_message (void *cls, const struct LookupMessage *message)
326 GNUNET_MQ_check_zero_termination (message);
332 * Handler for LOOKUP message from client, sends information
333 * about ONE identity to the client immediately.
335 * @param cls a `struct GNUNET_SERVICE_Client *`
336 * @param message the message received
339 handle_lookup_message (void *cls, const struct LookupMessage *message)
341 struct GNUNET_SERVICE_Client *client = cls;
343 struct GNUNET_MQ_Envelope *env;
346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
347 name = (const char *) &message[1];
348 for (ego = ego_head; NULL != ego; ego = ego->next)
350 if (0 != strcasecmp (name, ego->identifier))
352 env = create_update_message (ego);
353 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
354 GNUNET_SERVICE_client_continue (client);
357 send_result_code (client, 0, "ego not found");
358 GNUNET_SERVICE_client_continue (client);
363 * Handler for LOOKUP message from client, sends information
364 * about ONE identity to the client immediately.
367 * @param message the message received
368 * @return #GNUNET_SYSERR if message was ill-formed
371 check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
373 GNUNET_MQ_check_zero_termination (message);
379 * Handler for LOOKUP_BY_SUFFIX message from client, sends information
380 * about ONE identity to the client immediately.
382 * @param cls a `struct GNUNET_SERVICE_Client *`
383 * @param message the message received
386 handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
388 struct GNUNET_SERVICE_Client *client = cls;
390 struct GNUNET_MQ_Envelope *env;
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Received LOOKUP_BY_SUFFIX message from client\n");
395 name = (const char *) &message[1];
397 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
399 if ((strlen (ego->identifier) <= strlen (name)) &&
400 (0 == strcmp (ego->identifier,
401 &name[strlen (name) - strlen (ego->identifier)])) &&
402 ((strlen (name) == strlen (ego->identifier)) ||
403 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
404 ((NULL == lprefix) ||
405 (strlen (ego->identifier) > strlen (lprefix->identifier))))
407 /* found better match, update! */
413 env = create_update_message (lprefix);
414 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
415 GNUNET_SERVICE_client_continue (client);
418 send_result_code (client, 0, "ego not found");
419 GNUNET_SERVICE_client_continue (client);
424 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
426 * @param cls client sending the message
427 * @param msg message of type `struct GetDefaultMessage`
428 * @return #GNUNET_OK if @a msg is well-formed
431 check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
437 size = ntohs (msg->header.size);
438 if (size <= sizeof(struct GetDefaultMessage))
441 return GNUNET_SYSERR;
443 name = (const char *) &msg[1];
444 name_len = ntohs (msg->name_len);
445 if ((name_len + sizeof(struct GetDefaultMessage) != size) ||
446 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
449 return GNUNET_SYSERR;
456 * Handler for GET_DEFAULT message from client, returns
457 * default identity for some service.
460 * @param client who sent the message
461 * @param message the message received
464 handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
466 struct GNUNET_MQ_Envelope *env;
467 struct GNUNET_SERVICE_Client *client = cls;
473 name = GNUNET_strdup ((const char *) &gdm[1]);
474 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Received GET_DEFAULT for service `%s' from client\n",
478 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
480 "DEFAULT_IDENTIFIER",
483 send_result_code (client, 1, gettext_noop ("no default known"));
484 GNUNET_SERVICE_client_continue (client);
488 for (ego = ego_head; NULL != ego; ego = ego->next)
490 if (0 == strcmp (ego->identifier, identifier))
492 env = create_set_default_message (ego, name);
493 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
494 GNUNET_SERVICE_client_continue (client);
495 GNUNET_free (identifier);
500 GNUNET_free (identifier);
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
503 send_result_code (client,
506 "default configured, but ego unknown (internal error)"));
507 GNUNET_SERVICE_client_continue (client);
512 * Compare the given two private keys for equality.
514 * @param pk1 one private key
515 * @param pk2 another private key
516 * @return 0 if the keys are equal
519 key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
520 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
522 return GNUNET_memcmp (pk1, pk2);
527 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message
529 * @param cls client sending the message
530 * @param msg message of type `struct SetDefaultMessage`
531 * @return #GNUNET_OK if @a msg is well-formed
534 check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
540 size = ntohs (msg->header.size);
541 if (size <= sizeof(struct SetDefaultMessage))
544 return GNUNET_SYSERR;
546 name_len = ntohs (msg->name_len);
547 GNUNET_break (0 == ntohs (msg->reserved));
548 if (name_len + sizeof(struct SetDefaultMessage) != size)
551 return GNUNET_SYSERR;
553 str = (const char *) &msg[1];
554 if ('\0' != str[name_len - 1])
557 return GNUNET_SYSERR;
564 * Handler for SET_DEFAULT message from client, updates
565 * default identity for some service.
568 * @param client who sent the message
569 * @param message the message received
572 handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
575 struct GNUNET_SERVICE_Client *client = cls;
578 str = GNUNET_strdup ((const char *) &sdm[1]);
579 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
582 "Received SET_DEFAULT for service `%s' from client\n",
584 for (ego = ego_head; NULL != ego; ego = ego->next)
586 if (0 == key_cmp (&ego->pk,
589 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
591 "DEFAULT_IDENTIFIER",
594 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
596 GNUNET_ERROR_TYPE_ERROR,
597 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
599 send_result_code (client, 0, NULL);
600 GNUNET_SERVICE_client_continue (client);
605 send_result_code (client,
607 _ ("Unknown ego specified for service (internal error)"));
609 GNUNET_SERVICE_client_continue (client);
614 * Send an updated message for the given ego to all listeners.
616 * @param ego ego to send the update for
619 notify_listeners (struct Ego *ego)
621 struct UpdateMessage *um;
624 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
625 um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len);
626 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
627 um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
628 um->name_len = htons (name_len);
629 um->end_of_list = htons (GNUNET_NO);
630 um->private_key = ego->pk;
631 GNUNET_memcpy (&um[1], ego->identifier, name_len);
632 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
638 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message
640 * @param cls client sending the message
641 * @param msg message of type `struct CreateRequestMessage`
642 * @return #GNUNET_OK if @a msg is well-formed
645 check_create_message (void *cls, const struct CreateRequestMessage *msg)
651 size = ntohs (msg->header.size);
652 if (size <= sizeof(struct CreateRequestMessage))
655 return GNUNET_SYSERR;
657 name_len = ntohs (msg->name_len);
658 GNUNET_break (0 == ntohs (msg->reserved));
659 if (name_len + sizeof(struct CreateRequestMessage) != size)
662 return GNUNET_SYSERR;
664 str = (const char *) &msg[1];
665 if ('\0' != str[name_len - 1])
668 return GNUNET_SYSERR;
675 * Handler for CREATE message from client, creates
679 * @param client who sent the message
680 * @param message the message received
683 handle_create_message (void *cls, const struct CreateRequestMessage *crm)
685 struct GNUNET_SERVICE_Client *client = cls;
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
691 str = GNUNET_strdup ((const char *) &crm[1]);
692 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
693 for (ego = ego_head; NULL != ego; ego = ego->next)
695 if (0 == strcmp (ego->identifier, str))
697 send_result_code (client,
700 "identifier already in use for another ego"));
701 GNUNET_SERVICE_client_continue (client);
706 ego = GNUNET_new (struct Ego);
707 ego->pk = crm->private_key;
708 ego->identifier = GNUNET_strdup (str);
709 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
710 send_result_code (client, 0, NULL);
711 fn = get_ego_filename (ego);
712 (void) GNUNET_DISK_directory_create_for_file (fn);
713 if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
714 GNUNET_DISK_fn_write (fn,
716 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
717 GNUNET_DISK_PERM_USER_READ
718 | GNUNET_DISK_PERM_USER_WRITE))
719 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
722 notify_listeners (ego);
723 GNUNET_SERVICE_client_continue (client);
728 * Closure for 'handle_ego_rename'.
735 const char *old_name;
740 const char *new_name;
744 * An ego was renamed; rename it in all subsystems where it is
745 * currently set as the default.
747 * @param cls the 'struct RenameContext'
748 * @param section a section in the configuration to process
751 handle_ego_rename (void *cls, const char *section)
753 struct RenameContext *rc = cls;
756 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
758 "DEFAULT_IDENTIFIER",
761 if (0 != strcmp (id, rc->old_name))
766 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
768 "DEFAULT_IDENTIFIER",
775 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message
777 * @param cls client sending the message
778 * @param msg message of type `struct RenameMessage`
779 * @return #GNUNET_OK if @a msg is well-formed
782 check_rename_message (void *cls, const struct RenameMessage *msg)
785 uint16_t old_name_len;
786 uint16_t new_name_len;
787 const char *old_name;
788 const char *new_name;
790 size = ntohs (msg->header.size);
791 if (size <= sizeof(struct RenameMessage))
794 return GNUNET_SYSERR;
796 old_name_len = ntohs (msg->old_name_len);
797 new_name_len = ntohs (msg->new_name_len);
798 old_name = (const char *) &msg[1];
799 new_name = &old_name[old_name_len];
800 if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
801 ('\0' != old_name[old_name_len - 1]) ||
802 ('\0' != new_name[new_name_len - 1]))
805 return GNUNET_SYSERR;
813 * Handler for RENAME message from client, creates
817 * @param client who sent the message
818 * @param message the message received
821 handle_rename_message (void *cls, const struct RenameMessage *rm)
823 uint16_t old_name_len;
827 struct RenameContext rename_ctx;
828 struct GNUNET_SERVICE_Client *client = cls;
831 const char *old_name_tmp;
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
834 old_name_len = ntohs (rm->old_name_len);
835 old_name_tmp = (const char *) &rm[1];
836 old_name = GNUNET_strdup (old_name_tmp);
837 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
838 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
839 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
841 /* check if new name is already in use */
842 for (ego = ego_head; NULL != ego; ego = ego->next)
844 if (0 == strcmp (ego->identifier, new_name))
846 send_result_code (client, 1, gettext_noop ("target name already exists"));
847 GNUNET_SERVICE_client_continue (client);
848 GNUNET_free (old_name);
849 GNUNET_free (new_name);
854 /* locate old name and, if found, perform rename */
855 for (ego = ego_head; NULL != ego; ego = ego->next)
857 if (0 == strcmp (ego->identifier, old_name))
859 fn_old = get_ego_filename (ego);
860 GNUNET_free (ego->identifier);
861 rename_ctx.old_name = old_name;
862 rename_ctx.new_name = new_name;
863 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
867 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
869 GNUNET_ERROR_TYPE_ERROR,
870 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
872 ego->identifier = GNUNET_strdup (new_name);
873 fn_new = get_ego_filename (ego);
874 if (0 != rename (fn_old, fn_new))
875 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
876 GNUNET_free (fn_old);
877 GNUNET_free (fn_new);
878 GNUNET_free (old_name);
879 GNUNET_free (new_name);
880 notify_listeners (ego);
881 send_result_code (client, 0, NULL);
882 GNUNET_SERVICE_client_continue (client);
887 /* failed to locate old name */
888 send_result_code (client, 1, gettext_noop ("no matching ego found"));
889 GNUNET_free (old_name);
890 GNUNET_free (new_name);
891 GNUNET_SERVICE_client_continue (client);
896 * An ego was removed, remove it from all subsystems where it is
897 * currently set as the default.
899 * @param cls name of the removed ego (const char *)
900 * @param section a section in the configuration to process
903 handle_ego_delete (void *cls, const char *section)
905 const char *identifier = cls;
908 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
910 "DEFAULT_IDENTIFIER",
913 if (0 != strcmp (id, identifier))
918 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
920 "DEFAULT_IDENTIFIER",
927 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
929 * @param cls client sending the message
930 * @param msg message of type `struct DeleteMessage`
931 * @return #GNUNET_OK if @a msg is well-formed
934 check_delete_message (void *cls, const struct DeleteMessage *msg)
940 size = ntohs (msg->header.size);
941 if (size <= sizeof(struct DeleteMessage))
944 return GNUNET_SYSERR;
946 name = (const char *) &msg[1];
947 name_len = ntohs (msg->name_len);
948 if ((name_len + sizeof(struct DeleteMessage) != size) ||
949 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
952 return GNUNET_SYSERR;
959 * Handler for DELETE message from client, creates
963 * @param client who sent the message
964 * @param message the message received
967 handle_delete_message (void *cls, const struct DeleteMessage *dm)
972 struct GNUNET_SERVICE_Client *client = cls;
974 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
975 name = GNUNET_strdup ((const char *) &dm[1]);
976 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
978 for (ego = ego_head; NULL != ego; ego = ego->next)
980 if (0 == strcmp (ego->identifier, name))
982 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
983 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
987 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
989 GNUNET_ERROR_TYPE_ERROR,
990 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
992 fn = get_ego_filename (ego);
993 if (0 != unlink (fn))
994 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
996 GNUNET_free (ego->identifier);
997 ego->identifier = NULL;
998 notify_listeners (ego);
1001 send_result_code (client, 0, NULL);
1002 GNUNET_SERVICE_client_continue (client);
1007 send_result_code (client, 1, gettext_noop ("no matching ego found"));
1009 GNUNET_SERVICE_client_continue (client);
1014 * Process the given file from the "EGODIR". Parses the file
1015 * and creates the respective 'struct Ego' in memory.
1018 * @param filename name of the file to parse
1019 * @return #GNUNET_OK to continue to iterate,
1020 * #GNUNET_NO to stop iteration with no error,
1021 * #GNUNET_SYSERR to abort iteration with error!
1024 process_ego_file (void *cls,
1025 const char *filename)
1030 fn = strrchr (filename, (int) DIR_SEPARATOR);
1036 ego = GNUNET_new (struct Ego);
1038 GNUNET_CRYPTO_ecdsa_key_from_file (filename,
1043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1044 _ ("Failed to parse ego information in `%s'\n"),
1048 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1049 "Loaded ego `%s'\n",
1051 ego->identifier = GNUNET_strdup (fn + 1);
1052 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1058 * Handle network size estimate clients.
1060 * @param cls closure
1061 * @param server the initialized server
1062 * @param c configuration to use
1066 const struct GNUNET_CONFIGURATION_Handle *c,
1067 struct GNUNET_SERVICE_Handle *service)
1070 nc = GNUNET_notification_context_create (1);
1071 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1076 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1077 GNUNET_SCHEDULER_shutdown ();
1081 GNUNET_CONFIGURATION_get_value_filename (cfg,
1084 &subsystem_cfg_file))
1086 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1089 GNUNET_SCHEDULER_shutdown ();
1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1093 "Loading subsystem configuration `%s'\n",
1094 subsystem_cfg_file);
1095 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1096 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1098 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1102 "Failed to parse subsystem identity configuration file `%s'\n"),
1103 subsystem_cfg_file);
1104 GNUNET_SCHEDULER_shutdown ();
1107 stats = GNUNET_STATISTICS_create ("identity", cfg);
1108 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1111 _ ("Failed to create directory `%s' for storing egos\n"),
1114 GNUNET_DISK_directory_scan (ego_directory,
1117 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1122 * Define "main" method using service macro.
1124 GNUNET_SERVICE_MAIN (
1126 GNUNET_SERVICE_OPTION_NONE,
1129 &client_disconnect_cb,
1131 GNUNET_MQ_hd_fixed_size (start_message,
1132 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1133 struct GNUNET_MessageHeader,
1135 GNUNET_MQ_hd_var_size (lookup_message,
1136 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1137 struct LookupMessage,
1139 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1140 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1141 struct LookupMessage,
1143 GNUNET_MQ_hd_var_size (get_default_message,
1144 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1145 struct GetDefaultMessage,
1147 GNUNET_MQ_hd_var_size (set_default_message,
1148 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1149 struct SetDefaultMessage,
1151 GNUNET_MQ_hd_var_size (create_message,
1152 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1153 struct CreateRequestMessage,
1155 GNUNET_MQ_hd_var_size (rename_message,
1156 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1157 struct RenameMessage,
1159 GNUNET_MQ_hd_var_size (delete_message,
1160 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1161 struct DeleteMessage,
1163 GNUNET_MQ_handler_end ());
1166 /* end of gnunet-service-identity.c */