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);
194 GNUNET_free (e->identifier);
201 * Send a result code back to the client.
203 * @param client client that should receive the result code
204 * @param result_code code to transmit
205 * @param emsg error message to include (or NULL for none)
208 send_result_code (struct GNUNET_SERVICE_Client *client,
209 uint32_t result_code,
212 struct ResultCodeMessage *rcm;
213 struct GNUNET_MQ_Envelope *env;
219 elen = strlen (emsg) + 1;
221 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
222 rcm->result_code = htonl (result_code);
224 GNUNET_memcpy (&rcm[1], emsg, elen);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
226 "Sending result %d (%s) to client\n",
229 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
234 * Create an update message with information about the current state of an ego.
236 * @param ego ego to create message for
237 * @return corresponding update message
239 static struct GNUNET_MQ_Envelope *
240 create_update_message (struct Ego *ego)
242 struct UpdateMessage *um;
243 struct GNUNET_MQ_Envelope *env;
246 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
247 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
248 um->name_len = htons (name_len);
249 um->end_of_list = htons (GNUNET_NO);
250 um->private_key = *ego->pk;
251 GNUNET_memcpy (&um[1], ego->identifier, name_len);
257 * Create a set default message with information about the current state of an ego.
259 * @param ego ego to create message for
260 * @param servicename name of the service to provide in the message
261 * @return corresponding set default message
263 static struct GNUNET_MQ_Envelope *
264 create_set_default_message (struct Ego *ego, const char *servicename)
266 struct SetDefaultMessage *sdm;
267 struct GNUNET_MQ_Envelope *env;
270 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
271 env = GNUNET_MQ_msg_extra (sdm,
273 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
274 sdm->name_len = htons (name_len);
275 sdm->reserved = htons (0);
276 sdm->private_key = *ego->pk;
277 GNUNET_memcpy (&sdm[1], servicename, name_len);
283 * Handler for START message from client, sends information
284 * about all identities to the client immediately and
285 * adds the client to the notification context for future
288 * @param cls a `struct GNUNET_SERVICE_Client *`
289 * @param message the message received
292 handle_start_message (void *cls, const struct GNUNET_MessageHeader *message)
294 struct GNUNET_SERVICE_Client *client = cls;
295 struct UpdateMessage *ume;
296 struct GNUNET_MQ_Envelope *env;
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
300 GNUNET_SERVICE_client_mark_monitor (client);
301 GNUNET_SERVICE_client_disable_continue_warning (client);
302 GNUNET_notification_context_add (nc, GNUNET_SERVICE_client_get_mq (client));
303 for (ego = ego_head; NULL != ego; ego = ego->next)
305 env = create_update_message (ego);
306 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
308 env = GNUNET_MQ_msg_extra (ume, 0, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
309 ume->end_of_list = htons (GNUNET_YES);
310 ume->name_len = htons (0);
311 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
312 GNUNET_SERVICE_client_continue (client);
317 * Handler for LOOKUP message from client, sends information
318 * about ONE identity to the client immediately.
321 * @param message the message received
322 * @return #GNUNET_SYSERR if message was ill-formed
325 check_lookup_message (void *cls, const struct LookupMessage *message)
327 GNUNET_MQ_check_zero_termination (message);
333 * Handler for LOOKUP message from client, sends information
334 * about ONE identity to the client immediately.
336 * @param cls a `struct GNUNET_SERVICE_Client *`
337 * @param message the message received
340 handle_lookup_message (void *cls, const struct LookupMessage *message)
342 struct GNUNET_SERVICE_Client *client = cls;
344 struct GNUNET_MQ_Envelope *env;
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received LOOKUP message from client\n");
348 name = (const char *) &message[1];
349 for (ego = ego_head; NULL != ego; ego = ego->next)
351 if (0 != strcasecmp (name, ego->identifier))
353 env = create_update_message (ego);
354 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
355 GNUNET_SERVICE_client_continue (client);
358 send_result_code (client, 0, "ego not found");
359 GNUNET_SERVICE_client_continue (client);
364 * Handler for LOOKUP message from client, sends information
365 * about ONE identity to the client immediately.
368 * @param message the message received
369 * @return #GNUNET_SYSERR if message was ill-formed
372 check_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
374 GNUNET_MQ_check_zero_termination (message);
380 * Handler for LOOKUP_BY_SUFFIX message from client, sends information
381 * about ONE identity to the client immediately.
383 * @param cls a `struct GNUNET_SERVICE_Client *`
384 * @param message the message received
387 handle_lookup_by_suffix_message (void *cls, const struct LookupMessage *message)
389 struct GNUNET_SERVICE_Client *client = cls;
391 struct GNUNET_MQ_Envelope *env;
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Received LOOKUP_BY_SUFFIX message from client\n");
396 name = (const char *) &message[1];
398 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
400 if ((strlen (ego->identifier) <= strlen (name)) &&
401 (0 == strcmp (ego->identifier,
402 &name[strlen (name) - strlen (ego->identifier)])) &&
403 ((strlen (name) == strlen (ego->identifier)) ||
404 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
405 ((NULL == lprefix) ||
406 (strlen (ego->identifier) > strlen (lprefix->identifier))))
408 /* found better match, update! */
414 env = create_update_message (lprefix);
415 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
416 GNUNET_SERVICE_client_continue (client);
419 send_result_code (client, 0, "ego not found");
420 GNUNET_SERVICE_client_continue (client);
425 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
427 * @param cls client sending the message
428 * @param msg message of type `struct GetDefaultMessage`
429 * @return #GNUNET_OK if @a msg is well-formed
432 check_get_default_message (void *cls, const struct GetDefaultMessage *msg)
438 size = ntohs (msg->header.size);
439 if (size <= sizeof(struct GetDefaultMessage))
442 return GNUNET_SYSERR;
444 name = (const char *) &msg[1];
445 name_len = ntohs (msg->name_len);
446 if ((name_len + sizeof(struct GetDefaultMessage) != size) ||
447 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
450 return GNUNET_SYSERR;
457 * Handler for GET_DEFAULT message from client, returns
458 * default identity for some service.
461 * @param client who sent the message
462 * @param message the message received
465 handle_get_default_message (void *cls, const struct GetDefaultMessage *gdm)
467 struct GNUNET_MQ_Envelope *env;
468 struct GNUNET_SERVICE_Client *client = cls;
474 name = GNUNET_strdup ((const char *) &gdm[1]);
475 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
477 "Received GET_DEFAULT for service `%s' from client\n",
479 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
481 "DEFAULT_IDENTIFIER",
484 send_result_code (client, 1, gettext_noop ("no default known"));
485 GNUNET_SERVICE_client_continue (client);
489 for (ego = ego_head; NULL != ego; ego = ego->next)
491 if (0 == strcmp (ego->identifier, identifier))
493 env = create_set_default_message (ego, name);
494 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
495 GNUNET_SERVICE_client_continue (client);
496 GNUNET_free (identifier);
501 GNUNET_free (identifier);
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find ego `%s'\n", name);
504 send_result_code (client,
507 "default configured, but ego unknown (internal error)"));
508 GNUNET_SERVICE_client_continue (client);
513 * Compare the given two private keys for equality.
515 * @param pk1 one private key
516 * @param pk2 another private key
517 * @return 0 if the keys are equal
520 key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
521 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
523 return GNUNET_memcmp (pk1, pk2);
528 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message
530 * @param cls client sending the message
531 * @param msg message of type `struct SetDefaultMessage`
532 * @return #GNUNET_OK if @a msg is well-formed
535 check_set_default_message (void *cls, const struct SetDefaultMessage *msg)
541 size = ntohs (msg->header.size);
542 if (size <= sizeof(struct SetDefaultMessage))
545 return GNUNET_SYSERR;
547 name_len = ntohs (msg->name_len);
548 GNUNET_break (0 == ntohs (msg->reserved));
549 if (name_len + sizeof(struct SetDefaultMessage) != size)
552 return GNUNET_SYSERR;
554 str = (const char *) &msg[1];
555 if ('\0' != str[name_len - 1])
558 return GNUNET_SYSERR;
565 * Handler for SET_DEFAULT message from client, updates
566 * default identity for some service.
569 * @param client who sent the message
570 * @param message the message received
573 handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm)
576 struct GNUNET_SERVICE_Client *client = cls;
579 str = GNUNET_strdup ((const char *) &sdm[1]);
580 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "Received SET_DEFAULT for service `%s' from client\n",
585 for (ego = ego_head; NULL != ego; ego = ego->next)
587 if (0 == key_cmp (ego->pk, &sdm->private_key))
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 = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
708 *ego->pk = crm->private_key;
709 ego->identifier = GNUNET_strdup (str);
710 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
711 send_result_code (client, 0, NULL);
712 fn = get_ego_filename (ego);
713 (void) GNUNET_DISK_directory_create_for_file (fn);
714 if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
715 GNUNET_DISK_fn_write (fn,
717 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
718 GNUNET_DISK_PERM_USER_READ
719 | GNUNET_DISK_PERM_USER_WRITE))
720 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
723 notify_listeners (ego);
724 GNUNET_SERVICE_client_continue (client);
729 * Closure for 'handle_ego_rename'.
736 const char *old_name;
741 const char *new_name;
745 * An ego was renamed; rename it in all subsystems where it is
746 * currently set as the default.
748 * @param cls the 'struct RenameContext'
749 * @param section a section in the configuration to process
752 handle_ego_rename (void *cls, const char *section)
754 struct RenameContext *rc = cls;
757 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
759 "DEFAULT_IDENTIFIER",
762 if (0 != strcmp (id, rc->old_name))
767 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
769 "DEFAULT_IDENTIFIER",
776 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message
778 * @param cls client sending the message
779 * @param msg message of type `struct RenameMessage`
780 * @return #GNUNET_OK if @a msg is well-formed
783 check_rename_message (void *cls, const struct RenameMessage *msg)
786 uint16_t old_name_len;
787 uint16_t new_name_len;
788 const char *old_name;
789 const char *new_name;
791 size = ntohs (msg->header.size);
792 if (size <= sizeof(struct RenameMessage))
795 return GNUNET_SYSERR;
797 old_name_len = ntohs (msg->old_name_len);
798 new_name_len = ntohs (msg->new_name_len);
799 old_name = (const char *) &msg[1];
800 new_name = &old_name[old_name_len];
801 if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
802 ('\0' != old_name[old_name_len - 1]) ||
803 ('\0' != new_name[new_name_len - 1]))
806 return GNUNET_SYSERR;
814 * Handler for RENAME message from client, creates
818 * @param client who sent the message
819 * @param message the message received
822 handle_rename_message (void *cls, const struct RenameMessage *rm)
824 uint16_t old_name_len;
828 struct RenameContext rename_ctx;
829 struct GNUNET_SERVICE_Client *client = cls;
832 const char *old_name_tmp;
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
835 old_name_len = ntohs (rm->old_name_len);
836 old_name_tmp = (const char *) &rm[1];
837 old_name = GNUNET_strdup (old_name_tmp);
838 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
839 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
840 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
842 /* check if new name is already in use */
843 for (ego = ego_head; NULL != ego; ego = ego->next)
845 if (0 == strcmp (ego->identifier, new_name))
847 send_result_code (client, 1, gettext_noop ("target name already exists"));
848 GNUNET_SERVICE_client_continue (client);
849 GNUNET_free (old_name);
850 GNUNET_free (new_name);
855 /* locate old name and, if found, perform rename */
856 for (ego = ego_head; NULL != ego; ego = ego->next)
858 if (0 == strcmp (ego->identifier, old_name))
860 fn_old = get_ego_filename (ego);
861 GNUNET_free (ego->identifier);
862 rename_ctx.old_name = old_name;
863 rename_ctx.new_name = new_name;
864 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
868 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
870 GNUNET_ERROR_TYPE_ERROR,
871 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
873 ego->identifier = GNUNET_strdup (new_name);
874 fn_new = get_ego_filename (ego);
875 if (0 != rename (fn_old, fn_new))
876 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
877 GNUNET_free (fn_old);
878 GNUNET_free (fn_new);
879 GNUNET_free (old_name);
880 GNUNET_free (new_name);
881 notify_listeners (ego);
882 send_result_code (client, 0, NULL);
883 GNUNET_SERVICE_client_continue (client);
888 /* failed to locate old name */
889 send_result_code (client, 1, gettext_noop ("no matching ego found"));
890 GNUNET_free (old_name);
891 GNUNET_free (new_name);
892 GNUNET_SERVICE_client_continue (client);
897 * An ego was removed, remove it from all subsystems where it is
898 * currently set as the default.
900 * @param cls name of the removed ego (const char *)
901 * @param section a section in the configuration to process
904 handle_ego_delete (void *cls, const char *section)
906 const char *identifier = cls;
909 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
911 "DEFAULT_IDENTIFIER",
914 if (0 != strcmp (id, identifier))
919 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
921 "DEFAULT_IDENTIFIER",
928 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
930 * @param cls client sending the message
931 * @param msg message of type `struct DeleteMessage`
932 * @return #GNUNET_OK if @a msg is well-formed
935 check_delete_message (void *cls, const struct DeleteMessage *msg)
941 size = ntohs (msg->header.size);
942 if (size <= sizeof(struct DeleteMessage))
945 return GNUNET_SYSERR;
947 name = (const char *) &msg[1];
948 name_len = ntohs (msg->name_len);
949 if ((name_len + sizeof(struct DeleteMessage) != size) ||
950 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
953 return GNUNET_SYSERR;
960 * Handler for DELETE message from client, creates
964 * @param client who sent the message
965 * @param message the message received
968 handle_delete_message (void *cls, const struct DeleteMessage *dm)
973 struct GNUNET_SERVICE_Client *client = cls;
975 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
976 name = GNUNET_strdup ((const char *) &dm[1]);
977 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
979 for (ego = ego_head; NULL != ego; ego = ego->next)
981 if (0 == strcmp (ego->identifier, name))
983 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
984 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
988 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
990 GNUNET_ERROR_TYPE_ERROR,
991 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
993 fn = get_ego_filename (ego);
994 if (0 != unlink (fn))
995 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
997 GNUNET_free (ego->identifier);
998 ego->identifier = NULL;
999 notify_listeners (ego);
1000 GNUNET_free (ego->pk);
1003 send_result_code (client, 0, NULL);
1004 GNUNET_SERVICE_client_continue (client);
1009 send_result_code (client, 1, gettext_noop ("no matching ego found"));
1011 GNUNET_SERVICE_client_continue (client);
1016 * Process the given file from the "EGODIR". Parses the file
1017 * and creates the respective 'struct Ego' in memory.
1020 * @param filename name of the file to parse
1021 * @return #GNUNET_OK to continue to iterate,
1022 * #GNUNET_NO to stop iteration with no error,
1023 * #GNUNET_SYSERR to abort iteration with error!
1026 process_ego_file (void *cls, const char *filename)
1031 fn = strrchr (filename, (int) DIR_SEPARATOR);
1037 ego = GNUNET_new (struct Ego);
1038 ego->pk = GNUNET_CRYPTO_ecdsa_key_create_from_file (filename);
1039 if (NULL == ego->pk)
1042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1043 _ ("Failed to parse ego information in `%s'\n"),
1047 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded ego `%s'\n", fn + 1);
1048 ego->identifier = GNUNET_strdup (fn + 1);
1049 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1055 * Handle network size estimate clients.
1057 * @param cls closure
1058 * @param server the initialized server
1059 * @param c configuration to use
1063 const struct GNUNET_CONFIGURATION_Handle *c,
1064 struct GNUNET_SERVICE_Handle *service)
1067 nc = GNUNET_notification_context_create (1);
1068 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1073 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1074 GNUNET_SCHEDULER_shutdown ();
1078 GNUNET_CONFIGURATION_get_value_filename (cfg,
1081 &subsystem_cfg_file))
1083 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1086 GNUNET_SCHEDULER_shutdown ();
1089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1090 "Loading subsystem configuration `%s'\n",
1091 subsystem_cfg_file);
1092 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1093 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1095 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1097 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1099 "Failed to parse subsystem identity configuration file `%s'\n"),
1100 subsystem_cfg_file);
1101 GNUNET_SCHEDULER_shutdown ();
1104 stats = GNUNET_STATISTICS_create ("identity", cfg);
1105 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1107 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1108 _ ("Failed to create directory `%s' for storing egos\n"),
1111 GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL);
1112 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1117 * Define "main" method using service macro.
1119 GNUNET_SERVICE_MAIN (
1121 GNUNET_SERVICE_OPTION_NONE,
1124 &client_disconnect_cb,
1126 GNUNET_MQ_hd_fixed_size (start_message,
1127 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1128 struct GNUNET_MessageHeader,
1130 GNUNET_MQ_hd_var_size (lookup_message,
1131 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1132 struct LookupMessage,
1134 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1135 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1136 struct LookupMessage,
1138 GNUNET_MQ_hd_var_size (get_default_message,
1139 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1140 struct GetDefaultMessage,
1142 GNUNET_MQ_hd_var_size (set_default_message,
1143 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1144 struct SetDefaultMessage,
1146 GNUNET_MQ_hd_var_size (create_message,
1147 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1148 struct CreateRequestMessage,
1150 GNUNET_MQ_hd_var_size (rename_message,
1151 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1152 struct RenameMessage,
1154 GNUNET_MQ_hd_var_size (delete_message,
1155 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1156 struct DeleteMessage,
1158 GNUNET_MQ_handler_end ());
1161 /* end of gnunet-service-identity.c */