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,
144 "Client %p disconnected\n",
150 * Add a client to our list of active clients.
153 * @param client client to add
154 * @param mq message queue for @a client
155 * @return internal namestore client structure for this client
158 client_connect_cb (void *cls,
159 struct GNUNET_SERVICE_Client *client,
160 struct GNUNET_MQ_Handle *mq)
167 * Task run during shutdown.
172 shutdown_task (void *cls)
178 GNUNET_notification_context_destroy (nc);
183 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
186 GNUNET_CONFIGURATION_destroy (subsystem_cfg);
187 subsystem_cfg = NULL;
188 GNUNET_free (subsystem_cfg_file);
189 subsystem_cfg_file = NULL;
190 GNUNET_free (ego_directory);
191 ego_directory = NULL;
192 while (NULL != (e = ego_head))
194 GNUNET_CONTAINER_DLL_remove (ego_head,
197 GNUNET_free (e->identifier);
204 * Send a result code back to the client.
206 * @param client client that should receive the result code
207 * @param result_code code to transmit
208 * @param emsg error message to include (or NULL for none)
211 send_result_code (struct GNUNET_SERVICE_Client *client,
212 uint32_t result_code,
215 struct ResultCodeMessage *rcm;
216 struct GNUNET_MQ_Envelope *env;
222 elen = strlen (emsg) + 1;
224 GNUNET_MQ_msg_extra (rcm, elen, GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE);
225 rcm->result_code = htonl (result_code);
227 GNUNET_memcpy (&rcm[1], emsg, elen);
228 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
229 "Sending result %d (%s) to client\n",
232 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
237 * Create an update message with information about the current state of an ego.
239 * @param ego ego to create message for
240 * @return corresponding update message
242 static struct GNUNET_MQ_Envelope *
243 create_update_message (struct Ego *ego)
245 struct UpdateMessage *um;
246 struct GNUNET_MQ_Envelope *env;
249 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
250 env = GNUNET_MQ_msg_extra (um, name_len, GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
251 um->name_len = htons (name_len);
252 um->end_of_list = htons (GNUNET_NO);
253 um->private_key = ego->pk;
254 GNUNET_memcpy (&um[1], ego->identifier, name_len);
260 * Create a set default message with information about the current state of an ego.
262 * @param ego ego to create message for
263 * @param servicename name of the service to provide in the message
264 * @return corresponding set default message
266 static struct GNUNET_MQ_Envelope *
267 create_set_default_message (struct Ego *ego,
268 const char *servicename)
270 struct SetDefaultMessage *sdm;
271 struct GNUNET_MQ_Envelope *env;
274 name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
275 env = GNUNET_MQ_msg_extra (sdm,
277 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT);
278 sdm->name_len = htons (name_len);
279 sdm->reserved = htons (0);
280 sdm->private_key = ego->pk;
281 GNUNET_memcpy (&sdm[1], servicename, name_len);
287 * Handler for START message from client, sends information
288 * about all identities to the client immediately and
289 * adds the client to the notification context for future
292 * @param cls a `struct GNUNET_SERVICE_Client *`
293 * @param message the message received
296 handle_start_message (void *cls,
297 const struct GNUNET_MessageHeader *message)
299 struct GNUNET_SERVICE_Client *client = cls;
301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
302 "Received START message from client\n");
303 GNUNET_SERVICE_client_mark_monitor (client);
304 GNUNET_SERVICE_client_disable_continue_warning (client);
305 GNUNET_notification_context_add (nc,
306 GNUNET_SERVICE_client_get_mq (client));
307 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
309 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
310 create_update_message (ego));
313 struct UpdateMessage *ume;
314 struct GNUNET_MQ_Envelope *env;
316 env = GNUNET_MQ_msg_extra (ume,
318 GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
319 ume->end_of_list = htons (GNUNET_YES);
320 ume->name_len = htons (0);
321 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
324 GNUNET_SERVICE_client_continue (client);
329 * Handler for LOOKUP message from client, sends information
330 * about ONE identity to the client immediately.
333 * @param message the message received
334 * @return #GNUNET_SYSERR if message was ill-formed
337 check_lookup_message (void *cls,
338 const struct LookupMessage *message)
340 GNUNET_MQ_check_zero_termination (message);
346 * Handler for LOOKUP message from client, sends information
347 * about ONE identity to the client immediately.
349 * @param cls a `struct GNUNET_SERVICE_Client *`
350 * @param message the message received
353 handle_lookup_message (void *cls,
354 const struct LookupMessage *message)
356 struct GNUNET_SERVICE_Client *client = cls;
358 struct GNUNET_MQ_Envelope *env;
361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
362 "Received LOOKUP message from client\n");
363 name = (const char *) &message[1];
364 for (ego = ego_head; NULL != ego; ego = ego->next)
366 if (0 != strcasecmp (name, ego->identifier))
368 env = create_update_message (ego);
369 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
370 GNUNET_SERVICE_client_continue (client);
373 send_result_code (client, 0, "ego not found");
374 GNUNET_SERVICE_client_continue (client);
379 * Handler for LOOKUP message from client, sends information
380 * about ONE identity to the client immediately.
383 * @param message the message received
384 * @return #GNUNET_SYSERR if message was ill-formed
387 check_lookup_by_suffix_message (void *cls,
388 const struct LookupMessage *message)
390 GNUNET_MQ_check_zero_termination (message);
396 * Handler for LOOKUP_BY_SUFFIX message from client, sends information
397 * about ONE identity to the client immediately.
399 * @param cls a `struct GNUNET_SERVICE_Client *`
400 * @param message the message received
403 handle_lookup_by_suffix_message (void *cls,
404 const struct LookupMessage *message)
406 struct GNUNET_SERVICE_Client *client = cls;
408 struct GNUNET_MQ_Envelope *env;
411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
412 "Received LOOKUP_BY_SUFFIX message from client\n");
413 name = (const char *) &message[1];
415 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
417 if ((strlen (ego->identifier) <= strlen (name)) &&
418 (0 == strcmp (ego->identifier,
419 &name[strlen (name) - strlen (ego->identifier)])) &&
420 ((strlen (name) == strlen (ego->identifier)) ||
421 ('.' == name[strlen (name) - strlen (ego->identifier) - 1])) &&
422 ((NULL == lprefix) ||
423 (strlen (ego->identifier) > strlen (lprefix->identifier))))
425 /* found better match, update! */
431 env = create_update_message (lprefix);
432 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
433 GNUNET_SERVICE_client_continue (client);
436 send_result_code (client, 0, "ego not found");
437 GNUNET_SERVICE_client_continue (client);
442 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message
444 * @param cls client sending the message
445 * @param msg message of type `struct GetDefaultMessage`
446 * @return #GNUNET_OK if @a msg is well-formed
449 check_get_default_message (void *cls,
450 const struct GetDefaultMessage *msg)
456 size = ntohs (msg->header.size);
457 if (size <= sizeof(struct GetDefaultMessage))
460 return GNUNET_SYSERR;
462 name = (const char *) &msg[1];
463 name_len = ntohs (msg->name_len);
464 if ((name_len + sizeof(struct GetDefaultMessage) != size) ||
465 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
468 return GNUNET_SYSERR;
475 * Handler for GET_DEFAULT message from client, returns
476 * default identity for some service.
479 * @param client who sent the message
480 * @param message the message received
483 handle_get_default_message (void *cls,
484 const struct GetDefaultMessage *gdm)
486 struct GNUNET_MQ_Envelope *env;
487 struct GNUNET_SERVICE_Client *client = cls;
491 name = GNUNET_strdup ((const char *) &gdm[1]);
492 GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1],
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Received GET_DEFAULT for service `%s' from client\n",
498 GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
500 "DEFAULT_IDENTIFIER",
503 send_result_code (client, 1, gettext_noop ("no default known"));
504 GNUNET_SERVICE_client_continue (client);
508 for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
510 if (0 == strcmp (ego->identifier, identifier))
512 env = create_set_default_message (ego, name);
513 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
514 GNUNET_SERVICE_client_continue (client);
515 GNUNET_free (identifier);
520 GNUNET_free (identifier);
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "Failed to find ego `%s'\n",
525 send_result_code (client,
528 "default configured, but ego unknown (internal error)"));
529 GNUNET_SERVICE_client_continue (client);
534 * Compare the given two private keys for equality.
536 * @param pk1 one private key
537 * @param pk2 another private key
538 * @return 0 if the keys are equal
541 key_cmp (const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk1,
542 const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk2)
544 return GNUNET_memcmp (pk1, pk2);
549 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message
551 * @param cls client sending the message
552 * @param msg message of type `struct SetDefaultMessage`
553 * @return #GNUNET_OK if @a msg is well-formed
556 check_set_default_message (void *cls,
557 const struct SetDefaultMessage *msg)
563 size = ntohs (msg->header.size);
564 if (size <= sizeof(struct SetDefaultMessage))
567 return GNUNET_SYSERR;
569 name_len = ntohs (msg->name_len);
570 GNUNET_break (0 == ntohs (msg->reserved));
571 if (name_len + sizeof(struct SetDefaultMessage) != size)
574 return GNUNET_SYSERR;
576 str = (const char *) &msg[1];
577 if ('\0' != str[name_len - 1])
580 return GNUNET_SYSERR;
587 * Handler for SET_DEFAULT message from client, updates
588 * default identity for some service.
591 * @param client who sent the message
592 * @param message the message received
595 handle_set_default_message (void *cls,
596 const struct SetDefaultMessage *sdm)
599 struct GNUNET_SERVICE_Client *client = cls;
602 str = GNUNET_strdup ((const char *) &sdm[1]);
603 GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
606 "Received SET_DEFAULT for service `%s' from client\n",
608 for (ego = ego_head; NULL != ego; ego = ego->next)
610 if (0 == key_cmp (&ego->pk,
613 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
615 "DEFAULT_IDENTIFIER",
618 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
620 GNUNET_ERROR_TYPE_ERROR,
621 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
623 send_result_code (client, 0, NULL);
624 GNUNET_SERVICE_client_continue (client);
629 send_result_code (client,
631 _ ("Unknown ego specified for service (internal error)"));
633 GNUNET_SERVICE_client_continue (client);
638 * Send an updated message for the given ego to all listeners.
640 * @param ego ego to send the update for
643 notify_listeners (struct Ego *ego)
645 struct UpdateMessage *um;
648 name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
649 um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len);
650 um->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE);
651 um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
652 um->name_len = htons (name_len);
653 um->end_of_list = htons (GNUNET_NO);
654 um->private_key = ego->pk;
655 GNUNET_memcpy (&um[1], ego->identifier, name_len);
656 GNUNET_notification_context_broadcast (nc, &um->header, GNUNET_NO);
662 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message
664 * @param cls client sending the message
665 * @param msg message of type `struct CreateRequestMessage`
666 * @return #GNUNET_OK if @a msg is well-formed
669 check_create_message (void *cls,
670 const struct CreateRequestMessage *msg)
676 size = ntohs (msg->header.size);
677 if (size <= sizeof(struct CreateRequestMessage))
680 return GNUNET_SYSERR;
682 name_len = ntohs (msg->name_len);
683 GNUNET_break (0 == ntohs (msg->reserved));
684 if (name_len + sizeof(struct CreateRequestMessage) != size)
687 return GNUNET_SYSERR;
689 str = (const char *) &msg[1];
690 if ('\0' != str[name_len - 1])
693 return GNUNET_SYSERR;
700 * Handler for CREATE message from client, creates
704 * @param client who sent the message
705 * @param message the message received
708 handle_create_message (void *cls,
709 const struct CreateRequestMessage *crm)
711 struct GNUNET_SERVICE_Client *client = cls;
716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
717 str = GNUNET_strdup ((const char *) &crm[1]);
718 GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
719 for (ego = ego_head; NULL != ego; ego = ego->next)
721 if (0 == strcmp (ego->identifier, str))
723 send_result_code (client,
726 "identifier already in use for another ego"));
727 GNUNET_SERVICE_client_continue (client);
732 ego = GNUNET_new (struct Ego);
733 ego->pk = crm->private_key;
734 ego->identifier = GNUNET_strdup (str);
735 GNUNET_CONTAINER_DLL_insert (ego_head,
738 send_result_code (client, 0, NULL);
739 fn = get_ego_filename (ego);
740 (void) GNUNET_DISK_directory_create_for_file (fn);
741 if (sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey) !=
742 GNUNET_DISK_fn_write (fn,
744 sizeof(struct GNUNET_CRYPTO_EcdsaPrivateKey),
745 GNUNET_DISK_PERM_USER_READ
746 | GNUNET_DISK_PERM_USER_WRITE))
747 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", fn);
750 notify_listeners (ego);
751 GNUNET_SERVICE_client_continue (client);
756 * Closure for 'handle_ego_rename'.
763 const char *old_name;
768 const char *new_name;
772 * An ego was renamed; rename it in all subsystems where it is
773 * currently set as the default.
775 * @param cls the 'struct RenameContext'
776 * @param section a section in the configuration to process
779 handle_ego_rename (void *cls, const char *section)
781 struct RenameContext *rc = cls;
784 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
786 "DEFAULT_IDENTIFIER",
789 if (0 != strcmp (id, rc->old_name))
794 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
796 "DEFAULT_IDENTIFIER",
803 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message
805 * @param cls client sending the message
806 * @param msg message of type `struct RenameMessage`
807 * @return #GNUNET_OK if @a msg is well-formed
810 check_rename_message (void *cls, const struct RenameMessage *msg)
813 uint16_t old_name_len;
814 uint16_t new_name_len;
815 const char *old_name;
816 const char *new_name;
818 size = ntohs (msg->header.size);
819 if (size <= sizeof(struct RenameMessage))
822 return GNUNET_SYSERR;
824 old_name_len = ntohs (msg->old_name_len);
825 new_name_len = ntohs (msg->new_name_len);
826 old_name = (const char *) &msg[1];
827 new_name = &old_name[old_name_len];
828 if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
829 ('\0' != old_name[old_name_len - 1]) ||
830 ('\0' != new_name[new_name_len - 1]))
833 return GNUNET_SYSERR;
841 * Handler for RENAME message from client, creates
845 * @param client who sent the message
846 * @param message the message received
849 handle_rename_message (void *cls, const struct RenameMessage *rm)
851 uint16_t old_name_len;
855 struct RenameContext rename_ctx;
856 struct GNUNET_SERVICE_Client *client = cls;
859 const char *old_name_tmp;
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
862 old_name_len = ntohs (rm->old_name_len);
863 old_name_tmp = (const char *) &rm[1];
864 old_name = GNUNET_strdup (old_name_tmp);
865 GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
866 new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
867 GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
869 /* check if new name is already in use */
870 for (ego = ego_head; NULL != ego; ego = ego->next)
872 if (0 == strcmp (ego->identifier, new_name))
874 send_result_code (client, 1, gettext_noop ("target name already exists"));
875 GNUNET_SERVICE_client_continue (client);
876 GNUNET_free (old_name);
877 GNUNET_free (new_name);
882 /* locate old name and, if found, perform rename */
883 for (ego = ego_head; NULL != ego; ego = ego->next)
885 if (0 == strcmp (ego->identifier, old_name))
887 fn_old = get_ego_filename (ego);
888 GNUNET_free (ego->identifier);
889 rename_ctx.old_name = old_name;
890 rename_ctx.new_name = new_name;
891 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
895 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
897 GNUNET_ERROR_TYPE_ERROR,
898 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
900 ego->identifier = GNUNET_strdup (new_name);
901 fn_new = get_ego_filename (ego);
902 if (0 != rename (fn_old, fn_new))
903 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old);
904 GNUNET_free (fn_old);
905 GNUNET_free (fn_new);
906 GNUNET_free (old_name);
907 GNUNET_free (new_name);
908 notify_listeners (ego);
909 send_result_code (client, 0, NULL);
910 GNUNET_SERVICE_client_continue (client);
915 /* failed to locate old name */
916 send_result_code (client, 1, gettext_noop ("no matching ego found"));
917 GNUNET_free (old_name);
918 GNUNET_free (new_name);
919 GNUNET_SERVICE_client_continue (client);
924 * An ego was removed, remove it from all subsystems where it is
925 * currently set as the default.
927 * @param cls name of the removed ego (const char *)
928 * @param section a section in the configuration to process
931 handle_ego_delete (void *cls, const char *section)
933 const char *identifier = cls;
936 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (subsystem_cfg,
938 "DEFAULT_IDENTIFIER",
941 if (0 != strcmp (id, identifier))
946 GNUNET_CONFIGURATION_set_value_string (subsystem_cfg,
948 "DEFAULT_IDENTIFIER",
955 * Checks a #GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message
957 * @param cls client sending the message
958 * @param msg message of type `struct DeleteMessage`
959 * @return #GNUNET_OK if @a msg is well-formed
962 check_delete_message (void *cls, const struct DeleteMessage *msg)
968 size = ntohs (msg->header.size);
969 if (size <= sizeof(struct DeleteMessage))
972 return GNUNET_SYSERR;
974 name = (const char *) &msg[1];
975 name_len = ntohs (msg->name_len);
976 if ((name_len + sizeof(struct DeleteMessage) != size) ||
977 (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
980 return GNUNET_SYSERR;
987 * Handler for DELETE message from client, creates
991 * @param client who sent the message
992 * @param message the message received
995 handle_delete_message (void *cls, const struct DeleteMessage *dm)
1000 struct GNUNET_SERVICE_Client *client = cls;
1002 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
1003 name = GNUNET_strdup ((const char *) &dm[1]);
1004 GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
1006 for (ego = ego_head; NULL != ego; ego = ego->next)
1008 if (0 == strcmp (ego->identifier, name))
1010 GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego);
1011 GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg,
1015 GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file))
1017 GNUNET_ERROR_TYPE_ERROR,
1018 _ ("Failed to write subsystem default identifier map to `%s'.\n"),
1019 subsystem_cfg_file);
1020 fn = get_ego_filename (ego);
1021 if (0 != unlink (fn))
1022 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn);
1024 GNUNET_free (ego->identifier);
1025 ego->identifier = NULL;
1026 notify_listeners (ego);
1029 send_result_code (client, 0, NULL);
1030 GNUNET_SERVICE_client_continue (client);
1035 send_result_code (client, 1, gettext_noop ("no matching ego found"));
1037 GNUNET_SERVICE_client_continue (client);
1042 * Process the given file from the "EGODIR". Parses the file
1043 * and creates the respective 'struct Ego' in memory.
1046 * @param filename name of the file to parse
1047 * @return #GNUNET_OK to continue to iterate,
1048 * #GNUNET_NO to stop iteration with no error,
1049 * #GNUNET_SYSERR to abort iteration with error!
1052 process_ego_file (void *cls,
1053 const char *filename)
1058 fn = strrchr (filename, (int) DIR_SEPARATOR);
1064 ego = GNUNET_new (struct Ego);
1066 GNUNET_CRYPTO_ecdsa_key_from_file (filename,
1071 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1072 _ ("Failed to parse ego information in `%s'\n"),
1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1077 "Loaded ego `%s'\n",
1079 ego->identifier = GNUNET_strdup (fn + 1);
1080 GNUNET_CONTAINER_DLL_insert (ego_head, ego_tail, ego);
1086 * Handle network size estimate clients.
1088 * @param cls closure
1089 * @param server the initialized server
1090 * @param c configuration to use
1094 const struct GNUNET_CONFIGURATION_Handle *c,
1095 struct GNUNET_SERVICE_Handle *service)
1098 nc = GNUNET_notification_context_create (1);
1099 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
1104 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1105 GNUNET_SCHEDULER_shutdown ();
1109 GNUNET_CONFIGURATION_get_value_filename (cfg,
1112 &subsystem_cfg_file))
1114 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
1117 GNUNET_SCHEDULER_shutdown ();
1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "Loading subsystem configuration `%s'\n",
1122 subsystem_cfg_file);
1123 subsystem_cfg = GNUNET_CONFIGURATION_create ();
1124 if ((GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) &&
1126 GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)))
1128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1130 "Failed to parse subsystem identity configuration file `%s'\n"),
1131 subsystem_cfg_file);
1132 GNUNET_SCHEDULER_shutdown ();
1135 stats = GNUNET_STATISTICS_create ("identity", cfg);
1136 if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory))
1138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1139 _ ("Failed to create directory `%s' for storing egos\n"),
1142 GNUNET_DISK_directory_scan (ego_directory,
1145 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
1150 * Define "main" method using service macro.
1152 GNUNET_SERVICE_MAIN (
1154 GNUNET_SERVICE_OPTION_NONE,
1157 &client_disconnect_cb,
1159 GNUNET_MQ_hd_fixed_size (start_message,
1160 GNUNET_MESSAGE_TYPE_IDENTITY_START,
1161 struct GNUNET_MessageHeader,
1163 GNUNET_MQ_hd_var_size (lookup_message,
1164 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP,
1165 struct LookupMessage,
1167 GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1168 GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX,
1169 struct LookupMessage,
1171 GNUNET_MQ_hd_var_size (get_default_message,
1172 GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT,
1173 struct GetDefaultMessage,
1175 GNUNET_MQ_hd_var_size (set_default_message,
1176 GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT,
1177 struct SetDefaultMessage,
1179 GNUNET_MQ_hd_var_size (create_message,
1180 GNUNET_MESSAGE_TYPE_IDENTITY_CREATE,
1181 struct CreateRequestMessage,
1183 GNUNET_MQ_hd_var_size (rename_message,
1184 GNUNET_MESSAGE_TYPE_IDENTITY_RENAME,
1185 struct RenameMessage,
1187 GNUNET_MQ_hd_var_size (delete_message,
1188 GNUNET_MESSAGE_TYPE_IDENTITY_DELETE,
1189 struct DeleteMessage,
1191 GNUNET_MQ_handler_end ());
1194 /* end of gnunet-service-identity.c */