GNUnet  0.17.6
gnunet-service-identity.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2013 GNUnet e.V.
4 
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.
9 
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.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
33 #include "platform.h"
34 #include "gnunet_util_lib.h"
35 #include "gnunet_constants.h"
36 #include "gnunet_protocols.h"
39 #include "identity.h"
40 
41 
45 struct Ego
46 {
50  struct Ego *next;
51 
55  struct Ego *prev;
56 
61 
65  char *identifier;
66 };
67 
68 
72 static const struct GNUNET_CONFIGURATION_Handle *cfg;
73 
79 
84 
89 
93 static char *ego_directory;
94 
98 static char *subsystem_cfg_file;
99 
103 static struct Ego *ego_head;
104 
108 static struct Ego *ego_tail;
109 
110 
117 static char *
118 get_ego_filename (struct Ego *ego)
119 {
120  char *filename;
121 
123  "%s%s%s",
126  ego->identifier);
127  return filename;
128 }
129 
130 
138 static void
140  struct GNUNET_SERVICE_Client *client,
141  void *app_ctx)
142 {
144  "Client %p disconnected\n",
145  client);
146 }
147 
148 
157 static void *
158 client_connect_cb (void *cls,
159  struct GNUNET_SERVICE_Client *client,
160  struct GNUNET_MQ_Handle *mq)
161 {
162  return client;
163 }
164 
165 
171 static void
172 shutdown_task (void *cls)
173 {
174  struct Ego *e;
175 
176  if (NULL != nc)
177  {
179  nc = NULL;
180  }
181  if (NULL != stats)
182  {
184  stats = NULL;
185  }
187  subsystem_cfg = NULL;
189  subsystem_cfg_file = NULL;
191  ego_directory = NULL;
192  while (NULL != (e = ego_head))
193  {
195  ego_tail,
196  e);
197  GNUNET_free (e->identifier);
198  GNUNET_free (e);
199  }
200 }
201 
202 
210 static void
212  uint32_t result_code,
213  const char *emsg)
214 {
215  struct ResultCodeMessage *rcm;
216  struct GNUNET_MQ_Envelope *env;
217  size_t elen;
218 
219  if (NULL == emsg)
220  elen = 0;
221  else
222  elen = strlen (emsg) + 1;
223  env =
225  rcm->result_code = htonl (result_code);
226  if (0 < elen)
227  GNUNET_memcpy (&rcm[1], emsg, elen);
229  "Sending result %d (%s) to client\n",
230  (int) result_code,
231  emsg);
233 }
234 
235 
242 static struct GNUNET_MQ_Envelope *
244 {
245  struct UpdateMessage *um;
246  struct GNUNET_MQ_Envelope *env;
247  size_t name_len;
248 
249  name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
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);
255  return env;
256 }
257 
258 
266 static struct GNUNET_MQ_Envelope *
268  const char *servicename)
269 {
270  struct SetDefaultMessage *sdm;
271  struct GNUNET_MQ_Envelope *env;
272  size_t name_len;
273 
274  name_len = (NULL == servicename) ? 0 : (strlen (servicename) + 1);
275  env = GNUNET_MQ_msg_extra (sdm,
276  name_len,
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);
282  return env;
283 }
284 
285 
295 static void
297  const struct GNUNET_MessageHeader *message)
298 {
299  struct GNUNET_SERVICE_Client *client = cls;
300 
302  "Received START message from client\n");
307  for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
308  {
310  create_update_message (ego));
311  }
312  {
313  struct UpdateMessage *ume;
314  struct GNUNET_MQ_Envelope *env;
315 
316  env = GNUNET_MQ_msg_extra (ume,
317  0,
319  ume->end_of_list = htons (GNUNET_YES);
320  ume->name_len = htons (0);
322  env);
323  }
325 }
326 
327 
336 static int
338  const struct LookupMessage *message)
339 {
341  return GNUNET_OK;
342 }
343 
344 
352 static void
354  const struct LookupMessage *message)
355 {
356  struct GNUNET_SERVICE_Client *client = cls;
357  const char *name;
358  struct GNUNET_MQ_Envelope *env;
359  struct Ego *ego;
360 
362  "Received LOOKUP message from client\n");
363  name = (const char *) &message[1];
364  for (ego = ego_head; NULL != ego; ego = ego->next)
365  {
366  if (0 != strcasecmp (name, ego->identifier))
367  continue;
368  env = create_update_message (ego);
371  return;
372  }
373  send_result_code (client, 0, "ego not found");
375 }
376 
377 
386 static int
388  const struct LookupMessage *message)
389 {
391  return GNUNET_OK;
392 }
393 
394 
402 static void
404  const struct LookupMessage *message)
405 {
406  struct GNUNET_SERVICE_Client *client = cls;
407  const char *name;
408  struct GNUNET_MQ_Envelope *env;
409  struct Ego *lprefix;
410 
412  "Received LOOKUP_BY_SUFFIX message from client\n");
413  name = (const char *) &message[1];
414  lprefix = NULL;
415  for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
416  {
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))))
424  {
425  /* found better match, update! */
426  lprefix = ego;
427  }
428  }
429  if (NULL != lprefix)
430  {
431  env = create_update_message (lprefix);
434  return;
435  }
436  send_result_code (client, 0, "ego not found");
438 }
439 
440 
448 static int
450  const struct GetDefaultMessage *msg)
451 {
452  uint16_t size;
453  uint16_t name_len;
454  const char *name;
455 
456  size = ntohs (msg->header.size);
457  if (size <= sizeof(struct GetDefaultMessage))
458  {
459  GNUNET_break (0);
460  return GNUNET_SYSERR;
461  }
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]))
466  {
467  GNUNET_break (0);
468  return GNUNET_SYSERR;
469  }
470  return GNUNET_OK;
471 }
472 
473 
482 static void
484  const struct GetDefaultMessage *gdm)
485 {
486  struct GNUNET_MQ_Envelope *env;
487  struct GNUNET_SERVICE_Client *client = cls;
488  char *name;
489  char *identifier;
490 
491  name = GNUNET_strdup ((const char *) &gdm[1]);
492  GNUNET_STRINGS_utf8_tolower ((const char *) &gdm[1], name);
494  "Received GET_DEFAULT for service `%s' from client\n",
495  name);
496  if (GNUNET_OK !=
498  name,
499  "DEFAULT_IDENTIFIER",
500  &identifier))
501  {
502  send_result_code (client, 1, gettext_noop ("no default known"));
504  GNUNET_free (name);
505  return;
506  }
507  for (struct Ego *ego = ego_head; NULL != ego; ego = ego->next)
508  {
509  if (0 == strcmp (ego->identifier, identifier))
510  {
514  GNUNET_free (identifier);
515  GNUNET_free (name);
516  return;
517  }
518  }
519  GNUNET_free (identifier);
521  "Failed to find ego `%s'\n",
522  name);
523  GNUNET_free (name);
524  send_result_code (client,
525  1,
526  gettext_noop (
527  "default configured, but ego unknown (internal error)"));
529 }
530 
531 
539 static int
541  const struct GNUNET_IDENTITY_PrivateKey *pk2)
542 {
543  return GNUNET_memcmp (pk1, pk2);
544 }
545 
546 
554 static int
556  const struct SetDefaultMessage *msg)
557 {
558  uint16_t size;
559  uint16_t name_len;
560  const char *str;
561 
562  size = ntohs (msg->header.size);
563  if (size <= sizeof(struct SetDefaultMessage))
564  {
565  GNUNET_break (0);
566  return GNUNET_SYSERR;
567  }
568  name_len = ntohs (msg->name_len);
569  GNUNET_break (0 == ntohs (msg->reserved));
570  if (name_len + sizeof(struct SetDefaultMessage) != size)
571  {
572  GNUNET_break (0);
573  return GNUNET_SYSERR;
574  }
575  str = (const char *) &msg[1];
576  if ('\0' != str[name_len - 1])
577  {
578  GNUNET_break (0);
579  return GNUNET_SYSERR;
580  }
581  return GNUNET_OK;
582 }
583 
584 
593 static void
595  const struct SetDefaultMessage *sdm)
596 {
597  struct Ego *ego;
598  struct GNUNET_SERVICE_Client *client = cls;
599  char *str;
600 
601  str = GNUNET_strdup ((const char *) &sdm[1]);
602  GNUNET_STRINGS_utf8_tolower ((const char *) &sdm[1], str);
603 
605  "Received SET_DEFAULT for service `%s' from client\n",
606  str);
607  for (ego = ego_head; NULL != ego; ego = ego->next)
608  {
609  if (0 == key_cmp (&ego->pk,
610  &sdm->private_key))
611  {
613  str,
614  "DEFAULT_IDENTIFIER",
615  ego->identifier);
616  if (GNUNET_OK !=
618  GNUNET_log (
620  _ ("Failed to write subsystem default identifier map to `%s'.\n"),
622  send_result_code (client, 0, NULL);
624  GNUNET_free (str);
625  return;
626  }
627  }
628  send_result_code (client,
629  1,
630  _ ("Unknown ego specified for service (internal error)"));
631  GNUNET_free (str);
633 }
634 
635 
641 static void
642 notify_listeners (struct Ego *ego)
643 {
644  struct UpdateMessage *um;
645  size_t name_len;
646 
647  name_len = (NULL == ego->identifier) ? 0 : (strlen (ego->identifier) + 1);
648  um = GNUNET_malloc (sizeof(struct UpdateMessage) + name_len);
650  um->header.size = htons (sizeof(struct UpdateMessage) + name_len);
651  um->name_len = htons (name_len);
652  um->end_of_list = htons (GNUNET_NO);
653  um->private_key = ego->pk;
654  GNUNET_memcpy (&um[1], ego->identifier, name_len);
656  GNUNET_free (um);
657 }
658 
659 
667 static int
669  const struct CreateRequestMessage *msg)
670 {
671  uint16_t size;
672  uint16_t name_len;
673  const char *str;
674 
675  size = ntohs (msg->header.size);
676  if (size <= sizeof(struct CreateRequestMessage))
677  {
678  GNUNET_break (0);
679  return GNUNET_SYSERR;
680  }
681  name_len = ntohs (msg->name_len);
682  GNUNET_break (0 == ntohs (msg->reserved));
683  if (name_len + sizeof(struct CreateRequestMessage) != size)
684  {
685  GNUNET_break (0);
686  return GNUNET_SYSERR;
687  }
688  str = (const char *) &msg[1];
689  if ('\0' != str[name_len - 1])
690  {
691  GNUNET_break (0);
692  return GNUNET_SYSERR;
693  }
694  return GNUNET_OK;
695 }
696 
697 
705 static void
707  const struct CreateRequestMessage *crm)
708 {
709  struct GNUNET_SERVICE_Client *client = cls;
710  struct Ego *ego;
711  char *str;
712  char *fn;
713 
714  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received CREATE message from client\n");
715  str = GNUNET_strdup ((const char *) &crm[1]);
716  GNUNET_STRINGS_utf8_tolower ((const char *) &crm[1], str);
717  for (ego = ego_head; NULL != ego; ego = ego->next)
718  {
719  if (0 == strcmp (ego->identifier, str))
720  {
721  send_result_code (client,
722  1,
723  gettext_noop (
724  "identifier already in use for another ego"));
726  GNUNET_free (str);
727  return;
728  }
729  }
730  ego = GNUNET_new (struct Ego);
731  ego->pk = crm->private_key;
732  ego->identifier = GNUNET_strdup (str);
734  ego_tail,
735  ego);
736  send_result_code (client, 0, NULL);
737  fn = get_ego_filename (ego);
738  if (GNUNET_OK !=
740  &crm->private_key,
741  sizeof(struct GNUNET_IDENTITY_PrivateKey),
745  GNUNET_free (fn);
746  GNUNET_free (str);
747  notify_listeners (ego);
749 }
750 
751 
756 {
760  const char *old_name;
761 
765  const char *new_name;
766 };
767 
775 static void
776 handle_ego_rename (void *cls, const char *section)
777 {
778  struct RenameContext *rc = cls;
779  char *id;
780 
782  section,
783  "DEFAULT_IDENTIFIER",
784  &id))
785  return;
786  if (0 != strcmp (id, rc->old_name))
787  {
788  GNUNET_free (id);
789  return;
790  }
792  section,
793  "DEFAULT_IDENTIFIER",
794  rc->new_name);
795  GNUNET_free (id);
796 }
797 
798 
806 static int
807 check_rename_message (void *cls, const struct RenameMessage *msg)
808 {
809  uint16_t size;
810  uint16_t old_name_len;
811  uint16_t new_name_len;
812  const char *old_name;
813  const char *new_name;
814 
815  size = ntohs (msg->header.size);
816  if (size <= sizeof(struct RenameMessage))
817  {
818  GNUNET_break (0);
819  return GNUNET_SYSERR;
820  }
821  old_name_len = ntohs (msg->old_name_len);
822  new_name_len = ntohs (msg->new_name_len);
823  old_name = (const char *) &msg[1];
824  new_name = &old_name[old_name_len];
825  if ((old_name_len + new_name_len + sizeof(struct RenameMessage) != size) ||
826  ('\0' != old_name[old_name_len - 1]) ||
827  ('\0' != new_name[new_name_len - 1]))
828  {
829  GNUNET_break (0);
830  return GNUNET_SYSERR;
831  }
832 
833  return GNUNET_OK;
834 }
835 
836 
845 static void
846 handle_rename_message (void *cls, const struct RenameMessage *rm)
847 {
848  uint16_t old_name_len;
849  struct Ego *ego;
850  char *old_name;
851  char *new_name;
852  struct RenameContext rename_ctx;
853  struct GNUNET_SERVICE_Client *client = cls;
854  char *fn_old;
855  char *fn_new;
856  const char *old_name_tmp;
857 
858  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n");
859  old_name_len = ntohs (rm->old_name_len);
860  old_name_tmp = (const char *) &rm[1];
861  old_name = GNUNET_strdup (old_name_tmp);
862  GNUNET_STRINGS_utf8_tolower (old_name_tmp, old_name);
863  new_name = GNUNET_strdup (&old_name_tmp[old_name_len]);
864  GNUNET_STRINGS_utf8_tolower (&old_name_tmp[old_name_len], new_name);
865 
866  /* check if new name is already in use */
867  for (ego = ego_head; NULL != ego; ego = ego->next)
868  {
869  if (0 == strcmp (ego->identifier, new_name))
870  {
871  send_result_code (client, 1, gettext_noop ("target name already exists"));
873  GNUNET_free (old_name);
874  GNUNET_free (new_name);
875  return;
876  }
877  }
878 
879  /* locate old name and, if found, perform rename */
880  for (ego = ego_head; NULL != ego; ego = ego->next)
881  {
882  if (0 == strcmp (ego->identifier, old_name))
883  {
884  fn_old = get_ego_filename (ego);
885  GNUNET_free (ego->identifier);
886  rename_ctx.old_name = old_name;
887  rename_ctx.new_name = new_name;
890  &rename_ctx);
891  if (GNUNET_OK !=
893  GNUNET_log (
895  _ ("Failed to write subsystem default identifier map to `%s'.\n"),
897  ego->identifier = GNUNET_strdup (new_name);
898  fn_new = get_ego_filename (ego);
899  if (0 != rename (fn_old, fn_new))
901  GNUNET_free (fn_old);
902  GNUNET_free (fn_new);
903  GNUNET_free (old_name);
904  GNUNET_free (new_name);
905  notify_listeners (ego);
906  send_result_code (client, 0, NULL);
908  return;
909  }
910  }
911 
912  /* failed to locate old name */
913  send_result_code (client, 1, gettext_noop ("no matching ego found"));
914  GNUNET_free (old_name);
915  GNUNET_free (new_name);
917 }
918 
919 
927 static void
928 handle_ego_delete (void *cls, const char *section)
929 {
930  const char *identifier = cls;
931  char *id;
932 
934  section,
935  "DEFAULT_IDENTIFIER",
936  &id))
937  return;
938  if (0 != strcmp (id, identifier))
939  {
940  GNUNET_free (id);
941  return;
942  }
944  section,
945  "DEFAULT_IDENTIFIER",
946  NULL);
947  GNUNET_free (id);
948 }
949 
950 
958 static int
959 check_delete_message (void *cls, const struct DeleteMessage *msg)
960 {
961  uint16_t size;
962  uint16_t name_len;
963  const char *name;
964 
965  size = ntohs (msg->header.size);
966  if (size <= sizeof(struct DeleteMessage))
967  {
968  GNUNET_break (0);
969  return GNUNET_SYSERR;
970  }
971  name = (const char *) &msg[1];
972  name_len = ntohs (msg->name_len);
973  if ((name_len + sizeof(struct DeleteMessage) != size) ||
974  (0 != ntohs (msg->reserved)) || ('\0' != name[name_len - 1]))
975  {
976  GNUNET_break (0);
977  return GNUNET_SYSERR;
978  }
979  return GNUNET_OK;
980 }
981 
982 
991 static void
992 handle_delete_message (void *cls, const struct DeleteMessage *dm)
993 {
994  struct Ego *ego;
995  char *name;
996  char *fn;
997  struct GNUNET_SERVICE_Client *client = cls;
998 
999  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n");
1000  name = GNUNET_strdup ((const char *) &dm[1]);
1001  GNUNET_STRINGS_utf8_tolower ((const char *) &dm[1], name);
1002 
1003  for (ego = ego_head; NULL != ego; ego = ego->next)
1004  {
1005  if (0 == strcmp (ego->identifier, name))
1006  {
1010  ego->identifier);
1011  if (GNUNET_OK !=
1013  GNUNET_log (
1015  _ ("Failed to write subsystem default identifier map to `%s'.\n"),
1017  fn = get_ego_filename (ego);
1018  if (0 != unlink (fn))
1020  GNUNET_free (fn);
1021  GNUNET_free (ego->identifier);
1022  ego->identifier = NULL;
1023  notify_listeners (ego);
1024  GNUNET_free (ego);
1025  GNUNET_free (name);
1026  send_result_code (client, 0, NULL);
1028  return;
1029  }
1030  }
1031 
1032  send_result_code (client, 1, gettext_noop ("no matching ego found"));
1033  GNUNET_free (name);
1035 }
1036 
1037 
1038 static int
1040  void *buf,
1041  size_t buf_size)
1042 {
1043  int fd;
1044  struct stat sb;
1045 
1046  fd = open (filename,
1047  O_RDONLY);
1048  if (-1 == fd)
1049  {
1050  memset (buf,
1051  0,
1052  buf_size);
1053  return GNUNET_SYSERR;
1054  }
1055  if (0 != fstat (fd,
1056  &sb))
1057  {
1059  "stat",
1060  filename);
1061  GNUNET_assert (0 == close (fd));
1062  memset (buf,
1063  0,
1064  buf_size);
1065  return GNUNET_SYSERR;
1066  }
1067  if (sb.st_size != buf_size)
1068  {
1070  "File `%s' has wrong size (%llu), expected %llu bytes\n",
1071  filename,
1072  (unsigned long long) sb.st_size,
1073  (unsigned long long) buf_size);
1074  GNUNET_assert (0 == close (fd));
1075  memset (buf,
1076  0,
1077  buf_size);
1078  return GNUNET_SYSERR;
1079  }
1080  if (buf_size !=
1081  read (fd,
1082  buf,
1083  buf_size))
1084  {
1086  "read",
1087  filename);
1088  GNUNET_assert (0 == close (fd));
1089  memset (buf,
1090  0,
1091  buf_size);
1092  return GNUNET_SYSERR;
1093  }
1094  GNUNET_assert (0 == close (fd));
1095  return GNUNET_OK;
1096 }
1097 
1098 
1109 static int
1110 process_ego_file (void *cls,
1111  const char *filename)
1112 {
1113  struct Ego *ego;
1114  const char *fn;
1115 
1116  fn = strrchr (filename, (int) DIR_SEPARATOR);
1117  if (NULL == fn)
1118  {
1119  GNUNET_break (0);
1120  return GNUNET_OK;
1121  }
1122  ego = GNUNET_new (struct Ego);
1123  if (GNUNET_OK !=
1125  &ego->pk,
1126  sizeof (ego->pk)))
1127  {
1128  GNUNET_free (ego);
1130  _ ("Failed to parse ego information in `%s'\n"),
1131  filename);
1132  return GNUNET_OK;
1133  }
1135  "Loaded ego `%s'\n",
1136  fn + 1);
1137  ego->identifier = GNUNET_strdup (fn + 1);
1139  return GNUNET_OK;
1140 }
1141 
1142 
1150 static void
1151 run (void *cls,
1152  const struct GNUNET_CONFIGURATION_Handle *c,
1154 {
1155  cfg = c;
1158  "identity",
1159  "EGODIR",
1160  &ego_directory))
1161  {
1162  GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR");
1164  return;
1165  }
1166  if (GNUNET_OK !=
1168  "identity",
1169  "SUBSYSTEM_CFG",
1171  {
1173  "identity",
1174  "SUBSYSTEM_CFG");
1176  return;
1177  }
1179  "Loading subsystem configuration `%s'\n",
1183  (GNUNET_OK !=
1185  {
1187  _ (
1188  "Failed to parse subsystem identity configuration file `%s'\n"),
1191  return;
1192  }
1193  stats = GNUNET_STATISTICS_create ("identity", cfg);
1195  {
1197  _ ("Failed to create directory `%s' for storing egos\n"),
1198  ego_directory);
1199  }
1202  NULL);
1204 }
1205 
1206 
1211  "identity",
1213  &run,
1216  NULL,
1217  GNUNET_MQ_hd_fixed_size (start_message,
1219  struct GNUNET_MessageHeader,
1220  NULL),
1221  GNUNET_MQ_hd_var_size (lookup_message,
1223  struct LookupMessage,
1224  NULL),
1225  GNUNET_MQ_hd_var_size (lookup_by_suffix_message,
1227  struct LookupMessage,
1228  NULL),
1229  GNUNET_MQ_hd_var_size (get_default_message,
1231  struct GetDefaultMessage,
1232  NULL),
1233  GNUNET_MQ_hd_var_size (set_default_message,
1235  struct SetDefaultMessage,
1236  NULL),
1239  struct CreateRequestMessage,
1240  NULL),
1241  GNUNET_MQ_hd_var_size (rename_message,
1243  struct RenameMessage,
1244  NULL),
1245  GNUNET_MQ_hd_var_size (delete_message,
1247  struct DeleteMessage,
1248  NULL),
1250 
1251 
1252 /* end of gnunet-service-identity.c */
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define gettext_noop(String)
Definition: gettext.h:69
static struct Experiment * e
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static char * filename
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static void handle_create_message(void *cls, const struct CreateRequestMessage *crm)
Handler for CREATE message from client, creates new identity.
static struct GNUNET_MQ_Envelope * create_set_default_message(struct Ego *ego, const char *servicename)
Create a set default message with information about the current state of an ego.
static int check_set_default_message(void *cls, const struct SetDefaultMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT message.
static int key_cmp(const struct GNUNET_IDENTITY_PrivateKey *pk1, const struct GNUNET_IDENTITY_PrivateKey *pk2)
Compare the given two private keys for equality.
GNUNET_SERVICE_MAIN("identity", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(start_message, GNUNET_MESSAGE_TYPE_IDENTITY_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(lookup_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(lookup_by_suffix_message, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX, struct LookupMessage, NULL), GNUNET_MQ_hd_var_size(get_default_message, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, struct GetDefaultMessage, NULL), GNUNET_MQ_hd_var_size(set_default_message, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, struct SetDefaultMessage, NULL), GNUNET_MQ_hd_var_size(create_message, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, struct CreateRequestMessage, NULL), GNUNET_MQ_hd_var_size(rename_message, GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, struct RenameMessage, NULL), GNUNET_MQ_hd_var_size(delete_message, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, struct DeleteMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static struct Ego * ego_tail
Tail of DLL of all egos.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static int check_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
static int check_create_message(void *cls, const struct CreateRequestMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_CREATE message.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
static void handle_start_message(void *cls, const struct GNUNET_MessageHeader *message)
Handler for START message from client, sends information about all identities to the client immediate...
static struct GNUNET_MQ_Envelope * create_update_message(struct Ego *ego)
Create an update message with information about the current state of an ego.
static int check_delete_message(void *cls, const struct DeleteMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_DELETE message.
static void handle_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP_BY_SUFFIX message from client, sends information about ONE identity to the client ...
static void shutdown_task(void *cls)
Task run during shutdown.
static char * subsystem_cfg_file
Configuration file name where subsystem information is kept.
static void send_result_code(struct GNUNET_SERVICE_Client *client, uint32_t result_code, const char *emsg)
Send a result code back to the client.
static int process_ego_file(void *cls, const char *filename)
Process the given file from the "EGODIR".
static void handle_ego_rename(void *cls, const char *section)
An ego was renamed; rename it in all subsystems where it is currently set as the default.
static char * get_ego_filename(struct Ego *ego)
Get the name of the file we use to store a given ego.
static void handle_rename_message(void *cls, const struct RenameMessage *rm)
Handler for RENAME message from client, creates new identity.
static int read_from_file(const char *filename, void *buf, size_t buf_size)
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Handle network size estimate clients.
static void handle_lookup_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static void handle_set_default_message(void *cls, const struct SetDefaultMessage *sdm)
Handler for SET_DEFAULT message from client, updates default identity for some service.
static char * ego_directory
Directory where we store the identities.
static void notify_listeners(struct Ego *ego)
Send an updated message for the given ego to all listeners.
static int check_get_default_message(void *cls, const struct GetDefaultMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT message.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Add a client to our list of active clients.
static void handle_delete_message(void *cls, const struct DeleteMessage *dm)
Handler for DELETE message from client, creates new identity.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Called whenever a client is disconnected.
static void handle_get_default_message(void *cls, const struct GetDefaultMessage *gdm)
Handler for GET_DEFAULT message from client, returns default identity for some service.
static int check_rename_message(void *cls, const struct RenameMessage *msg)
Checks a GNUNET_MESSAGE_TYPE_IDENTITY_RENAME message.
static void handle_ego_delete(void *cls, const char *section)
An ego was removed, remove it from all subsystems where it is currently set as the default.
static struct Ego * ego_head
Head of DLL of all egos.
static struct GNUNET_CONFIGURATION_Handle * subsystem_cfg
Handle to subsystem configuration which for each subsystem contains the name of the default ego.
static int check_lookup_by_suffix_message(void *cls, const struct LookupMessage *message)
Handler for LOOKUP message from client, sends information about ONE identity to the client immediatel...
static char buf[2048]
Identity service; implements identity management for GNUnet.
Constants for network protocols.
API to create, modify and access statistics.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(void)
Create a new configuration object.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_parse(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Parse a configuration file, add all of the options in the file to the configuration environment.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:482
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:725
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
Definition: disk.c:496
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
Definition: disk.c:814
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:137
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:302
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:56
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:189
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:121
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:160
#define GNUNET_MESSAGE_TYPE_IDENTITY_CREATE
Create new identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_START
First message send from identity client to service (to subscribe to updates).
#define GNUNET_MESSAGE_TYPE_IDENTITY_DELETE
Delete identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP
First message send from identity client to service to lookup a single ego.
#define GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT
Client sets default identity; or service informs about default identity.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE
Generic response from identity service with success and/or error message.
#define GNUNET_MESSAGE_TYPE_IDENTITY_RENAME
Rename existing identity (client->service).
#define GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX
First message send from identity client to service to lookup a single ego matching the given suffix (...
#define GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE
Update about identity status from service to clients.
#define GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT
Client requests to know default identity for a subsystem.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:533
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1316
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
Definition: service.c:2412
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2442
void GNUNET_SERVICE_client_disable_continue_warning(struct GNUNET_SERVICE_Client *c)
Disable the warning the server issues if a message is not acknowledged in a timely fashion.
Definition: service.c:2272
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2248
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:450
Common type definitions for the identity service and API.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
static unsigned int size
Size of the "table".
Definition: peer.c:67
#define DIR_SEPARATOR
Definition: platform.h:164
#define DIR_SEPARATOR_STR
Definition: platform.h:165
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
const char * name
Client requests creation of an identity.
Definition: identity.h:203
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
Definition: identity.h:222
Client requests deletion of an identity.
Definition: identity.h:259
Information we keep about each ego.
struct Ego * prev
We keep egos in a DLL.
struct GNUNET_IDENTITY_PrivateKey pk
Private key of the ego.
char * identifier
String identifier for the ego.
struct Ego * next
We keep egos in a DLL.
A private key for an identity as per LSD0001.
Handle to a message queue.
Definition: mq.c:86
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:76
Handle to a client that is connected to a service.
Definition: service.c:251
Handle to a service.
Definition: service.c:117
Handle for the service.
Client requests knowledge about default identity for a subsystem from identity service.
Definition: identity.h:147
Message from client to GNS service to lookup records.
Definition: gns.h:37
Closure for 'handle_ego_rename'.
const char * old_name
Old name.
const char * new_name
New name.
Client requests renaming of an identity.
Definition: identity.h:233
uint16_t old_name_len
Number of characters in the old name including 0-termination, in NBO.
Definition: identity.h:242
Answer from service to client about last operation; GET_DEFAULT maybe answered with this message on f...
Definition: identity.h:81
uint32_t result_code
Status code for the last operation, in NBO.
Definition: identity.h:91
Used from service to client as a result to the GET_DEFAULT message, used from client to service to SE...
Definition: identity.h:173
uint16_t reserved
Always zero.
Definition: identity.h:187
uint16_t name_len
Number of bytes in service name string including 0-termination, in NBO.
Definition: identity.h:182
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
Definition: identity.h:192
Service informs client about status of a pseudonym.
Definition: identity.h:116
struct GNUNET_IDENTITY_PrivateKey private_key
The private key.
Definition: identity.h:136
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:131
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted.
Definition: identity.h:126
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:120