diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-03 21:22:50 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2019-06-03 21:22:50 +0200 |
commit | a00a49bf58c502ab860adaa6b01541c0e7e3e645 (patch) | |
tree | e9ece2ebffd1d0df735763fe5ebdfb2d334a496f | |
parent | 34c8bfb80b82a1a7f7d3db3c41e705b09a1fad7e (diff) | |
download | gnunet-a00a49bf58c502ab860adaa6b01541c0e7e3e645.tar.gz gnunet-a00a49bf58c502ab860adaa6b01541c0e7e3e645.zip |
RECLAIM: Various fixes (coverity)
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.c | 8 | ||||
-rw-r--r-- | src/reclaim/gnunet-reclaim.c | 11 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim.c | 12 | ||||
-rw-r--r-- | src/reclaim/gnunet-service-reclaim_tickets.c | 343 | ||||
-rw-r--r-- | src/reclaim/json_reclaim.c | 106 | ||||
-rw-r--r-- | src/reclaim/plugin_rest_openid_connect.c | 97 |
6 files changed, 390 insertions, 187 deletions
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index b9465bef7..96e61d431 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c | |||
@@ -495,12 +495,18 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | |||
495 | attr_ser = (struct Attribute *) data; | 495 | attr_ser = (struct Attribute *) data; |
496 | data_len = ntohs (attr_ser->data_size); | 496 | data_len = ntohs (attr_ser->data_size); |
497 | name_len = ntohs (attr_ser->name_len); | 497 | name_len = ntohs (attr_ser->name_len); |
498 | if (data_size < sizeof (struct Attribute) + data_len + name_len) | ||
499 | { | ||
500 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
501 | "Buffer too small to deserialize\n"); | ||
502 | return NULL; | ||
503 | } | ||
498 | attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + | 504 | attr = GNUNET_malloc (sizeof (struct GNUNET_RECLAIM_ATTRIBUTE_Claim) + |
499 | data_len + name_len + 1); | 505 | data_len + name_len + 1); |
500 | attr->type = ntohs (attr_ser->attribute_type); | 506 | attr->type = ntohs (attr_ser->attribute_type); |
501 | attr->version = ntohl (attr_ser->attribute_version); | 507 | attr->version = ntohl (attr_ser->attribute_version); |
502 | attr->id = GNUNET_ntohll (attr_ser->attribute_id); | 508 | attr->id = GNUNET_ntohll (attr_ser->attribute_id); |
503 | attr->data_size = ntohs (attr_ser->data_size); | 509 | attr->data_size = data_len; |
504 | 510 | ||
505 | write_ptr = (char *) &attr[1]; | 511 | write_ptr = (char *) &attr[1]; |
506 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | 512 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); |
diff --git a/src/reclaim/gnunet-reclaim.c b/src/reclaim/gnunet-reclaim.c index 4b4b73008..fcb7b9bc6 100644 --- a/src/reclaim/gnunet-reclaim.c +++ b/src/reclaim/gnunet-reclaim.c | |||
@@ -267,6 +267,8 @@ ticket_iter (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket) | |||
267 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 267 | ref = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); |
268 | 268 | ||
269 | fprintf (stdout, "Ticket ID: %s | Audience: %s\n", ref, aud); | 269 | fprintf (stdout, "Ticket ID: %s | Audience: %s\n", ref, aud); |
270 | GNUNET_free (aud); | ||
271 | GNUNET_free (ref); | ||
270 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); | 272 | GNUNET_RECLAIM_ticket_iteration_next (ticket_iterator); |
271 | } | 273 | } |
272 | 274 | ||
@@ -448,8 +450,13 @@ start_process () | |||
448 | return; | 450 | return; |
449 | } | 451 | } |
450 | 452 | ||
451 | if (NULL != rp) | 453 | if ((NULL != rp) && |
452 | GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key); | 454 | GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (rp, strlen (rp), &rp_key)) |
455 | { | ||
456 | fprintf (stderr, "%s is not a public key!\n", rp); | ||
457 | cleanup_task = GNUNET_SCHEDULER_add_now (&do_cleanup, NULL); | ||
458 | return; | ||
459 | } | ||
453 | if (NULL != consume_ticket) | 460 | if (NULL != consume_ticket) |
454 | GNUNET_STRINGS_string_to_data (consume_ticket, strlen (consume_ticket), | 461 | GNUNET_STRINGS_string_to_data (consume_ticket, strlen (consume_ticket), |
455 | &ticket, | 462 | &ticket, |
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c index ffc67c5ae..322063fd9 100644 --- a/src/reclaim/gnunet-service-reclaim.c +++ b/src/reclaim/gnunet-service-reclaim.c | |||
@@ -947,6 +947,7 @@ attr_store_task (void *cls) | |||
947 | &attr_store_cont, | 947 | &attr_store_cont, |
948 | ash); | 948 | ash); |
949 | GNUNET_free (buf); | 949 | GNUNET_free (buf); |
950 | GNUNET_free (label); | ||
950 | } | 951 | } |
951 | 952 | ||
952 | 953 | ||
@@ -1126,10 +1127,17 @@ update_tickets (void *cls) | |||
1126 | le); | 1127 | le); |
1127 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | 1128 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; |
1128 | struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1]; | 1129 | struct GNUNET_GNSRECORD_Data rd_new[le->rd_count - 1]; |
1129 | GNUNET_GNSRECORD_records_deserialize (le->data_size, | 1130 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, |
1130 | le->data, | 1131 | le->data, |
1131 | le->rd_count, | 1132 | le->rd_count, |
1132 | rd); | 1133 | rd)) |
1134 | { | ||
1135 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1136 | "Unable to deserialize record data!\n"); | ||
1137 | send_delete_response (adh, GNUNET_SYSERR); | ||
1138 | cleanup_adh (adh); | ||
1139 | return; | ||
1140 | } | ||
1133 | int j = 0; | 1141 | int j = 0; |
1134 | for (int i = 0; i < le->rd_count; i++) { | 1142 | for (int i = 0; i < le->rd_count; i++) { |
1135 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) | 1143 | if ((GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF == rd[i].record_type) |
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c index d20a4e3bf..9a595447d 100644 --- a/src/reclaim/gnunet-service-reclaim_tickets.c +++ b/src/reclaim/gnunet-service-reclaim_tickets.c | |||
@@ -312,7 +312,7 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rh); | |||
312 | static void | 312 | static void |
313 | move_attrs_cont (void *cls) | 313 | move_attrs_cont (void *cls) |
314 | { | 314 | { |
315 | move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *)cls); | 315 | move_attrs ((struct RECLAIM_TICKETS_RevokeHandle *) cls); |
316 | } | 316 | } |
317 | 317 | ||
318 | /** | 318 | /** |
@@ -329,13 +329,16 @@ cleanup_rvk (struct RECLAIM_TICKETS_RevokeHandle *rh) | |||
329 | GNUNET_NAMESTORE_cancel (rh->ns_qe); | 329 | GNUNET_NAMESTORE_cancel (rh->ns_qe); |
330 | if (NULL != rh->ns_it) | 330 | if (NULL != rh->ns_it) |
331 | GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it); | 331 | GNUNET_NAMESTORE_zone_iteration_stop (rh->ns_it); |
332 | while (NULL != (ae = rh->attrs_head)) { | 332 | while (NULL != (ae = rh->attrs_head)) |
333 | { | ||
333 | GNUNET_CONTAINER_DLL_remove (rh->attrs_head, rh->attrs_tail, ae); | 334 | GNUNET_CONTAINER_DLL_remove (rh->attrs_head, rh->attrs_tail, ae); |
334 | GNUNET_free (ae); | 335 | GNUNET_free (ae); |
335 | } | 336 | } |
336 | while (NULL != (le = rh->tickets_to_update_head)) { | 337 | while (NULL != (le = rh->tickets_to_update_head)) |
338 | { | ||
337 | GNUNET_CONTAINER_DLL_remove (rh->tickets_to_update_head, | 339 | GNUNET_CONTAINER_DLL_remove (rh->tickets_to_update_head, |
338 | rh->tickets_to_update_head, le); | 340 | rh->tickets_to_update_head, |
341 | le); | ||
339 | if (NULL != le->data) | 342 | if (NULL != le->data) |
340 | GNUNET_free (le->data); | 343 | GNUNET_free (le->data); |
341 | if (NULL != le->label) | 344 | if (NULL != le->label) |
@@ -350,8 +353,10 @@ del_attr_finished (void *cls, int32_t success, const char *emsg) | |||
350 | { | 353 | { |
351 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 354 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
352 | rvk->ns_qe = NULL; | 355 | rvk->ns_qe = NULL; |
353 | if (GNUNET_SYSERR == success) { | 356 | if (GNUNET_SYSERR == success) |
354 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error removing attribute: %s\n", | 357 | { |
358 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
359 | "Error removing attribute: %s\n", | ||
355 | emsg); | 360 | emsg); |
356 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 361 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
357 | cleanup_rvk (rvk); | 362 | cleanup_rvk (rvk); |
@@ -367,7 +372,8 @@ move_attr_finished (void *cls, int32_t success, const char *emsg) | |||
367 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 372 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
368 | char *label; | 373 | char *label; |
369 | rvk->ns_qe = NULL; | 374 | rvk->ns_qe = NULL; |
370 | if (GNUNET_SYSERR == success) { | 375 | if (GNUNET_SYSERR == success) |
376 | { | ||
371 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); | 377 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error moving attribute: %s\n", emsg); |
372 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 378 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
373 | cleanup_rvk (rvk); | 379 | cleanup_rvk (rvk); |
@@ -375,15 +381,24 @@ move_attr_finished (void *cls, int32_t success, const char *emsg) | |||
375 | } | 381 | } |
376 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | 382 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, |
377 | sizeof (uint64_t)); | 383 | sizeof (uint64_t)); |
384 | GNUNET_assert (NULL != label); | ||
378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); | 385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing attribute %s\n", label); |
379 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &rvk->identity, label, 0, | 386 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
380 | NULL, &del_attr_finished, rvk); | 387 | &rvk->identity, |
388 | label, | ||
389 | 0, | ||
390 | NULL, | ||
391 | &del_attr_finished, | ||
392 | rvk); | ||
393 | GNUNET_free (label); | ||
381 | } | 394 | } |
382 | 395 | ||
383 | 396 | ||
384 | static void | 397 | static void |
385 | rvk_move_attr_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 398 | rvk_move_attr_cb (void *cls, |
386 | const char *label, unsigned int rd_count, | 399 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
400 | const char *label, | ||
401 | unsigned int rd_count, | ||
387 | const struct GNUNET_GNSRECORD_Data *rd) | 402 | const struct GNUNET_GNSRECORD_Data *rd) |
388 | { | 403 | { |
389 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 404 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
@@ -393,9 +408,11 @@ rvk_move_attr_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
393 | char *new_label; | 408 | char *new_label; |
394 | char *attr_data; | 409 | char *attr_data; |
395 | rvk->ns_qe = NULL; | 410 | rvk->ns_qe = NULL; |
396 | if (0 == rd_count) { | 411 | if (0 == rd_count) |
412 | { | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 413 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
398 | "The attribute %s no longer exists!\n", label); | 414 | "The attribute %s no longer exists!\n", |
415 | label); | ||
399 | le = rvk->move_attr; | 416 | le = rvk->move_attr; |
400 | rvk->move_attr = le->next; | 417 | rvk->move_attr = le->next; |
401 | GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le); | 418 | GNUNET_CONTAINER_DLL_remove (rvk->attrs_head, rvk->attrs_tail, le); |
@@ -409,7 +426,8 @@ rvk_move_attr_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
409 | new_rd = *rd; | 426 | new_rd = *rd; |
410 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | 427 | claim = GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); |
411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 428 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
412 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", claim->name, | 429 | "Attribute to update: Name=%s, ID=%" PRIu64 "\n", |
430 | claim->name, | ||
413 | claim->id); | 431 | claim->id); |
414 | claim->id = rvk->move_attr->new_id; | 432 | claim->id = rvk->move_attr->new_id; |
415 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); | 433 | new_rd.data_size = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (claim); |
@@ -419,8 +437,13 @@ rvk_move_attr_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
419 | new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, | 437 | new_label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->new_id, |
420 | sizeof (uint64_t)); | 438 | sizeof (uint64_t)); |
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); | 439 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute %s\n", new_label); |
422 | rvk->ns_qe = GNUNET_NAMESTORE_records_store ( | 440 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
423 | nsh, &rvk->identity, new_label, 1, &new_rd, &move_attr_finished, rvk); | 441 | &rvk->identity, |
442 | new_label, | ||
443 | 1, | ||
444 | &new_rd, | ||
445 | &move_attr_finished, | ||
446 | rvk); | ||
424 | GNUNET_free (new_label); | 447 | GNUNET_free (new_label); |
425 | GNUNET_free (claim); | 448 | GNUNET_free (claim); |
426 | GNUNET_free (attr_data); | 449 | GNUNET_free (attr_data); |
@@ -428,8 +451,10 @@ rvk_move_attr_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
428 | 451 | ||
429 | 452 | ||
430 | static void | 453 | static void |
431 | rvk_ticket_update (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 454 | rvk_ticket_update (void *cls, |
432 | const char *label, unsigned int rd_count, | 455 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
456 | const char *label, | ||
457 | unsigned int rd_count, | ||
433 | const struct GNUNET_GNSRECORD_Data *rd) | 458 | const struct GNUNET_GNSRECORD_Data *rd) |
434 | { | 459 | { |
435 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 460 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
@@ -438,10 +463,12 @@ rvk_ticket_update (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
438 | int has_changed = GNUNET_NO; | 463 | int has_changed = GNUNET_NO; |
439 | 464 | ||
440 | /** Let everything point to the old record **/ | 465 | /** Let everything point to the old record **/ |
441 | for (int i = 0; i < rd_count; i++) { | 466 | for (int i = 0; i < rd_count; i++) |
467 | { | ||
442 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 468 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
443 | continue; | 469 | continue; |
444 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) { | 470 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) |
471 | { | ||
445 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | 472 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) |
446 | continue; | 473 | continue; |
447 | has_changed = GNUNET_YES; | 474 | has_changed = GNUNET_YES; |
@@ -450,7 +477,8 @@ rvk_ticket_update (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
450 | if (GNUNET_YES == has_changed) | 477 | if (GNUNET_YES == has_changed) |
451 | break; | 478 | break; |
452 | } | 479 | } |
453 | if (GNUNET_YES == has_changed) { | 480 | if (GNUNET_YES == has_changed) |
481 | { | ||
454 | le = GNUNET_new (struct TicketRecordsEntry); | 482 | le = GNUNET_new (struct TicketRecordsEntry); |
455 | le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); | 483 | le->data_size = GNUNET_GNSRECORD_records_get_size (rd_count, rd); |
456 | le->data = GNUNET_malloc (le->data_size); | 484 | le->data = GNUNET_malloc (le->data_size); |
@@ -458,7 +486,8 @@ rvk_ticket_update (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | |||
458 | le->label = GNUNET_strdup (label); | 486 | le->label = GNUNET_strdup (label); |
459 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data); | 487 | GNUNET_GNSRECORD_records_serialize (rd_count, rd, le->data_size, le->data); |
460 | GNUNET_CONTAINER_DLL_insert (rvk->tickets_to_update_head, | 488 | GNUNET_CONTAINER_DLL_insert (rvk->tickets_to_update_head, |
461 | rvk->tickets_to_update_tail, le); | 489 | rvk->tickets_to_update_tail, |
490 | le); | ||
462 | } | 491 | } |
463 | GNUNET_NAMESTORE_zone_iterator_next (rvk->ns_it, 1); | 492 | GNUNET_NAMESTORE_zone_iterator_next (rvk->ns_it, 1); |
464 | } | 493 | } |
@@ -482,7 +511,8 @@ process_tickets (void *cls) | |||
482 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 511 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
483 | struct TicketRecordsEntry *le; | 512 | struct TicketRecordsEntry *le; |
484 | struct RevokedAttributeEntry *ae; | 513 | struct RevokedAttributeEntry *ae; |
485 | if (NULL == rvk->tickets_to_update_head) { | 514 | if (NULL == rvk->tickets_to_update_head) |
515 | { | ||
486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
487 | "Finished updatding tickets, success\n"); | 517 | "Finished updatding tickets, success\n"); |
488 | rvk->cb (rvk->cb_cls, GNUNET_OK); | 518 | rvk->cb (rvk->cb_cls, GNUNET_OK); |
@@ -491,21 +521,38 @@ process_tickets (void *cls) | |||
491 | } | 521 | } |
492 | le = rvk->tickets_to_update_head; | 522 | le = rvk->tickets_to_update_head; |
493 | GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head, | 523 | GNUNET_CONTAINER_DLL_remove (rvk->tickets_to_update_head, |
494 | rvk->tickets_to_update_tail, le); | 524 | rvk->tickets_to_update_tail, |
525 | le); | ||
495 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; | 526 | struct GNUNET_GNSRECORD_Data rd[le->rd_count]; |
496 | GNUNET_GNSRECORD_records_deserialize (le->data_size, le->data, le->rd_count, | 527 | if (GNUNET_OK != GNUNET_GNSRECORD_records_deserialize (le->data_size, |
497 | rd); | 528 | le->data, |
498 | for (int i = 0; i < le->rd_count; i++) { | 529 | le->rd_count, |
530 | rd)) | ||
531 | { | ||
532 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
533 | "Unable to deserialize ticket record(s)\n"); | ||
534 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | ||
535 | cleanup_rvk (rvk); | ||
536 | return; | ||
537 | } | ||
538 | for (int i = 0; i < le->rd_count; i++) | ||
539 | { | ||
499 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 540 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
500 | continue; | 541 | continue; |
501 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) { | 542 | for (ae = rvk->attrs_head; NULL != ae; ae = ae->next) |
543 | { | ||
502 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) | 544 | if (0 != memcmp (rd[i].data, &ae->old_id, sizeof (uint64_t))) |
503 | continue; | 545 | continue; |
504 | rd[i].data = &ae->new_id; | 546 | rd[i].data = &ae->new_id; |
505 | } | 547 | } |
506 | } | 548 | } |
507 | rvk->ns_qe = GNUNET_NAMESTORE_records_store ( | 549 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
508 | nsh, &rvk->identity, le->label, le->rd_count, rd, &ticket_processed, rvk); | 550 | &rvk->identity, |
551 | le->label, | ||
552 | le->rd_count, | ||
553 | rd, | ||
554 | &ticket_processed, | ||
555 | rvk); | ||
509 | GNUNET_free (le->label); | 556 | GNUNET_free (le->label); |
510 | GNUNET_free (le->data); | 557 | GNUNET_free (le->data); |
511 | GNUNET_free (le); | 558 | GNUNET_free (le); |
@@ -551,19 +598,31 @@ move_attrs (struct RECLAIM_TICKETS_RevokeHandle *rvk) | |||
551 | { | 598 | { |
552 | char *label; | 599 | char *label; |
553 | 600 | ||
554 | if (NULL == rvk->move_attr) { | 601 | if (NULL == rvk->move_attr) |
602 | { | ||
555 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n"); | 603 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished moving attributes\n"); |
556 | rvk->ns_it = GNUNET_NAMESTORE_zone_iteration_start ( | 604 | rvk->ns_it = |
557 | nsh, &rvk->identity, &rvk_ns_iter_err, rvk, &rvk_ticket_update, rvk, | 605 | GNUNET_NAMESTORE_zone_iteration_start (nsh, |
558 | &rvk_ticket_update_finished, rvk); | 606 | &rvk->identity, |
607 | &rvk_ns_iter_err, | ||
608 | rvk, | ||
609 | &rvk_ticket_update, | ||
610 | rvk, | ||
611 | &rvk_ticket_update_finished, | ||
612 | rvk); | ||
559 | return; | 613 | return; |
560 | } | 614 | } |
561 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, | 615 | label = GNUNET_STRINGS_data_to_string_alloc (&rvk->move_attr->old_id, |
562 | sizeof (uint64_t)); | 616 | sizeof (uint64_t)); |
563 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label); | 617 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Moving attribute %s\n", label); |
564 | 618 | ||
565 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup ( | 619 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, |
566 | nsh, &rvk->identity, label, &rvk_ns_err, rvk, &rvk_move_attr_cb, rvk); | 620 | &rvk->identity, |
621 | label, | ||
622 | &rvk_ns_err, | ||
623 | rvk, | ||
624 | &rvk_move_attr_cb, | ||
625 | rvk); | ||
567 | GNUNET_free (label); | 626 | GNUNET_free (label); |
568 | } | 627 | } |
569 | 628 | ||
@@ -573,14 +632,16 @@ remove_ticket_cont (void *cls, int32_t success, const char *emsg) | |||
573 | { | 632 | { |
574 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 633 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
575 | rvk->ns_qe = NULL; | 634 | rvk->ns_qe = NULL; |
576 | if (GNUNET_SYSERR == success) { | 635 | if (GNUNET_SYSERR == success) |
636 | { | ||
577 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 637 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); |
578 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); | 638 | rvk->cb (rvk->cb_cls, GNUNET_SYSERR); |
579 | cleanup_rvk (rvk); | 639 | cleanup_rvk (rvk); |
580 | return; | 640 | return; |
581 | } | 641 | } |
582 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n"); | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleted ticket\n"); |
583 | if (0 == rvk->ticket_attrs) { | 643 | if (0 == rvk->ticket_attrs) |
644 | { | ||
584 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 645 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
585 | "No attributes to move... strange\n"); | 646 | "No attributes to move... strange\n"); |
586 | rvk->cb (rvk->cb_cls, GNUNET_OK); | 647 | rvk->cb (rvk->cb_cls, GNUNET_OK); |
@@ -593,26 +654,34 @@ remove_ticket_cont (void *cls, int32_t success, const char *emsg) | |||
593 | 654 | ||
594 | 655 | ||
595 | static void | 656 | static void |
596 | revoke_attrs_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 657 | revoke_attrs_cb (void *cls, |
597 | const char *label, unsigned int rd_count, | 658 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
659 | const char *label, | ||
660 | unsigned int rd_count, | ||
598 | const struct GNUNET_GNSRECORD_Data *rd) | 661 | const struct GNUNET_GNSRECORD_Data *rd) |
599 | 662 | ||
600 | { | 663 | { |
601 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; | 664 | struct RECLAIM_TICKETS_RevokeHandle *rvk = cls; |
602 | struct RevokedAttributeEntry *le; | 665 | struct RevokedAttributeEntry *le; |
603 | rvk->ns_qe = NULL; | 666 | rvk->ns_qe = NULL; |
604 | for (int i = 0; i < rd_count; i++) { | 667 | for (int i = 0; i < rd_count; i++) |
668 | { | ||
605 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 669 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
606 | continue; | 670 | continue; |
607 | le = GNUNET_new (struct RevokedAttributeEntry); | 671 | le = GNUNET_new (struct RevokedAttributeEntry); |
608 | le->old_id = *((uint64_t *)rd[i].data); | 672 | le->old_id = *((uint64_t *) rd[i].data); |
609 | GNUNET_CONTAINER_DLL_insert (rvk->attrs_head, rvk->attrs_tail, le); | 673 | GNUNET_CONTAINER_DLL_insert (rvk->attrs_head, rvk->attrs_tail, le); |
610 | rvk->ticket_attrs++; | 674 | rvk->ticket_attrs++; |
611 | } | 675 | } |
612 | 676 | ||
613 | /** Now, remove ticket **/ | 677 | /** Now, remove ticket **/ |
614 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &rvk->identity, label, 0, | 678 | rvk->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
615 | NULL, &remove_ticket_cont, rvk); | 679 | &rvk->identity, |
680 | label, | ||
681 | 0, | ||
682 | NULL, | ||
683 | &remove_ticket_cont, | ||
684 | rvk); | ||
616 | } | 685 | } |
617 | 686 | ||
618 | 687 | ||
@@ -628,7 +697,8 @@ rvk_attrs_err_cb (void *cls) | |||
628 | struct RECLAIM_TICKETS_RevokeHandle * | 697 | struct RECLAIM_TICKETS_RevokeHandle * |
629 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | 698 | RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, |
630 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 699 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
631 | RECLAIM_TICKETS_RevokeCallback cb, void *cb_cls) | 700 | RECLAIM_TICKETS_RevokeCallback cb, |
701 | void *cb_cls) | ||
632 | { | 702 | { |
633 | struct RECLAIM_TICKETS_RevokeHandle *rvk; | 703 | struct RECLAIM_TICKETS_RevokeHandle *rvk; |
634 | char *label; | 704 | char *label; |
@@ -641,9 +711,14 @@ RECLAIM_TICKETS_revoke (const struct GNUNET_RECLAIM_Ticket *ticket, | |||
641 | GNUNET_CRYPTO_ecdsa_key_get_public (&rvk->identity, &rvk->ticket.identity); | 711 | GNUNET_CRYPTO_ecdsa_key_get_public (&rvk->identity, &rvk->ticket.identity); |
642 | /** Get shared attributes **/ | 712 | /** Get shared attributes **/ |
643 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); | 713 | label = GNUNET_STRINGS_data_to_string_alloc (&ticket->rnd, sizeof (uint64_t)); |
644 | 714 | GNUNET_assert (NULL != label); | |
645 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup ( | 715 | rvk->ns_qe = GNUNET_NAMESTORE_records_lookup (nsh, |
646 | nsh, identity, label, &rvk_attrs_err_cb, rvk, &revoke_attrs_cb, rvk); | 716 | identity, |
717 | label, | ||
718 | &rvk_attrs_err_cb, | ||
719 | rvk, | ||
720 | &revoke_attrs_cb, | ||
721 | rvk); | ||
647 | return rvk; | 722 | return rvk; |
648 | } | 723 | } |
649 | 724 | ||
@@ -669,12 +744,14 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
669 | GNUNET_GNS_lookup_cancel (cth->lookup_request); | 744 | GNUNET_GNS_lookup_cancel (cth->lookup_request); |
670 | if (NULL != cth->kill_task) | 745 | if (NULL != cth->kill_task) |
671 | GNUNET_SCHEDULER_cancel (cth->kill_task); | 746 | GNUNET_SCHEDULER_cancel (cth->kill_task); |
672 | while (NULL != (lu = cth->parallel_lookups_head)) { | 747 | while (NULL != (lu = cth->parallel_lookups_head)) |
748 | { | ||
673 | if (NULL != lu->lookup_request) | 749 | if (NULL != lu->lookup_request) |
674 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 750 | GNUNET_GNS_lookup_cancel (lu->lookup_request); |
675 | GNUNET_free_non_null (lu->label); | 751 | GNUNET_free_non_null (lu->label); |
676 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 752 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
677 | cth->parallel_lookups_tail, lu); | 753 | cth->parallel_lookups_tail, |
754 | lu); | ||
678 | GNUNET_free (lu); | 755 | GNUNET_free (lu); |
679 | } | 756 | } |
680 | 757 | ||
@@ -685,23 +762,27 @@ cleanup_cth (struct RECLAIM_TICKETS_ConsumeHandle *cth) | |||
685 | 762 | ||
686 | 763 | ||
687 | static void | 764 | static void |
688 | process_parallel_lookup_result (void *cls, uint32_t rd_count, | 765 | process_parallel_lookup_result (void *cls, |
766 | uint32_t rd_count, | ||
689 | const struct GNUNET_GNSRECORD_Data *rd) | 767 | const struct GNUNET_GNSRECORD_Data *rd) |
690 | { | 768 | { |
691 | struct ParallelLookup *parallel_lookup = cls; | 769 | struct ParallelLookup *parallel_lookup = cls; |
692 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; | 770 | struct RECLAIM_TICKETS_ConsumeHandle *cth = parallel_lookup->handle; |
693 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; | 771 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *attr_le; |
694 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parallel lookup finished (count=%u)\n", | 772 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
773 | "Parallel lookup finished (count=%u)\n", | ||
695 | rd_count); | 774 | rd_count); |
696 | 775 | ||
697 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 776 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
698 | cth->parallel_lookups_tail, parallel_lookup); | 777 | cth->parallel_lookups_tail, |
778 | parallel_lookup); | ||
699 | GNUNET_free (parallel_lookup->label); | 779 | GNUNET_free (parallel_lookup->label); |
700 | 780 | ||
701 | GNUNET_STATISTICS_update ( | 781 | GNUNET_STATISTICS_update (stats, |
702 | stats, "attribute_lookup_time_total", | 782 | "attribute_lookup_time_total", |
703 | GNUNET_TIME_absolute_get_duration (parallel_lookup->lookup_start_time) | 783 | GNUNET_TIME_absolute_get_duration ( |
704 | .rel_value_us, | 784 | parallel_lookup->lookup_start_time) |
785 | .rel_value_us, | ||
705 | GNUNET_YES); | 786 | GNUNET_YES); |
706 | GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES); | 787 | GNUNET_STATISTICS_update (stats, "attribute_lookups_count", 1, GNUNET_YES); |
707 | 788 | ||
@@ -709,11 +790,13 @@ process_parallel_lookup_result (void *cls, uint32_t rd_count, | |||
709 | GNUNET_free (parallel_lookup); | 790 | GNUNET_free (parallel_lookup); |
710 | if (1 != rd_count) | 791 | if (1 != rd_count) |
711 | GNUNET_break (0); // TODO | 792 | GNUNET_break (0); // TODO |
712 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) { | 793 | if (rd->record_type == GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR) |
794 | { | ||
713 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 795 | attr_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); |
714 | attr_le->claim = | 796 | attr_le->claim = |
715 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); | 797 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (rd->data, rd->data_size); |
716 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, cth->attrs->list_tail, | 798 | GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head, |
799 | cth->attrs->list_tail, | ||
717 | attr_le); | 800 | attr_le); |
718 | } | 801 | } |
719 | if (NULL != cth->parallel_lookups_head) | 802 | if (NULL != cth->parallel_lookups_head) |
@@ -733,12 +816,14 @@ abort_parallel_lookups (void *cls) | |||
733 | struct ParallelLookup *tmp; | 816 | struct ParallelLookup *tmp; |
734 | 817 | ||
735 | cth->kill_task = NULL; | 818 | cth->kill_task = NULL; |
736 | for (lu = cth->parallel_lookups_head; NULL != lu;) { | 819 | for (lu = cth->parallel_lookups_head; NULL != lu;) |
820 | { | ||
737 | GNUNET_GNS_lookup_cancel (lu->lookup_request); | 821 | GNUNET_GNS_lookup_cancel (lu->lookup_request); |
738 | GNUNET_free (lu->label); | 822 | GNUNET_free (lu->label); |
739 | tmp = lu->next; | 823 | tmp = lu->next; |
740 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, | 824 | GNUNET_CONTAINER_DLL_remove (cth->parallel_lookups_head, |
741 | cth->parallel_lookups_tail, lu); | 825 | cth->parallel_lookups_tail, |
826 | lu); | ||
742 | GNUNET_free (lu); | 827 | GNUNET_free (lu); |
743 | lu = tmp; | 828 | lu = tmp; |
744 | } | 829 | } |
@@ -747,7 +832,8 @@ abort_parallel_lookups (void *cls) | |||
747 | 832 | ||
748 | 833 | ||
749 | static void | 834 | static void |
750 | lookup_authz_cb (void *cls, uint32_t rd_count, | 835 | lookup_authz_cb (void *cls, |
836 | uint32_t rd_count, | ||
751 | const struct GNUNET_GNSRECORD_Data *rd) | 837 | const struct GNUNET_GNSRECORD_Data *rd) |
752 | { | 838 | { |
753 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; | 839 | struct RECLAIM_TICKETS_ConsumeHandle *cth = cls; |
@@ -756,14 +842,19 @@ lookup_authz_cb (void *cls, uint32_t rd_count, | |||
756 | 842 | ||
757 | cth->lookup_request = NULL; | 843 | cth->lookup_request = NULL; |
758 | 844 | ||
759 | GNUNET_STATISTICS_update ( | 845 | GNUNET_STATISTICS_update (stats, |
760 | stats, "reclaim_authz_lookup_time_total", | 846 | "reclaim_authz_lookup_time_total", |
761 | GNUNET_TIME_absolute_get_duration (cth->lookup_start_time).rel_value_us, | 847 | GNUNET_TIME_absolute_get_duration ( |
848 | cth->lookup_start_time) | ||
849 | .rel_value_us, | ||
762 | GNUNET_YES); | 850 | GNUNET_YES); |
763 | GNUNET_STATISTICS_update (stats, "reclaim_authz_lookups_count", 1, | 851 | GNUNET_STATISTICS_update (stats, |
852 | "reclaim_authz_lookups_count", | ||
853 | 1, | ||
764 | GNUNET_YES); | 854 | GNUNET_YES); |
765 | 855 | ||
766 | for (int i = 0; i < rd_count; i++) { | 856 | for (int i = 0; i < rd_count; i++) |
857 | { | ||
767 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) | 858 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF != rd[i].record_type) |
768 | continue; | 859 | continue; |
769 | lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); | 860 | lbl = GNUNET_STRINGS_data_to_string_alloc (rd[i].data, rd[i].data_size); |
@@ -772,17 +863,24 @@ lookup_authz_cb (void *cls, uint32_t rd_count, | |||
772 | parallel_lookup->handle = cth; | 863 | parallel_lookup->handle = cth; |
773 | parallel_lookup->label = lbl; | 864 | parallel_lookup->label = lbl; |
774 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); | 865 | parallel_lookup->lookup_start_time = GNUNET_TIME_absolute_get (); |
775 | parallel_lookup->lookup_request = GNUNET_GNS_lookup ( | 866 | parallel_lookup->lookup_request = |
776 | gns, lbl, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | 867 | GNUNET_GNS_lookup (gns, |
777 | GNUNET_GNS_LO_DEFAULT, &process_parallel_lookup_result, | 868 | lbl, |
778 | parallel_lookup); | 869 | &cth->ticket.identity, |
870 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR, | ||
871 | GNUNET_GNS_LO_DEFAULT, | ||
872 | &process_parallel_lookup_result, | ||
873 | parallel_lookup); | ||
779 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, | 874 | GNUNET_CONTAINER_DLL_insert (cth->parallel_lookups_head, |
780 | cth->parallel_lookups_tail, parallel_lookup); | 875 | cth->parallel_lookups_tail, |
876 | parallel_lookup); | ||
781 | } | 877 | } |
782 | if (NULL != cth->parallel_lookups_head) { | 878 | if (NULL != cth->parallel_lookups_head) |
879 | { | ||
783 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( | 880 | cth->kill_task = GNUNET_SCHEDULER_add_delayed ( |
784 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), | 881 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 3), |
785 | &abort_parallel_lookups, cth); | 882 | &abort_parallel_lookups, |
883 | cth); | ||
786 | return; | 884 | return; |
787 | } | 885 | } |
788 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); | 886 | cth->cb (cth->cb_cls, &cth->ticket.identity, cth->attrs, GNUNET_OK, NULL); |
@@ -793,7 +891,8 @@ lookup_authz_cb (void *cls, uint32_t rd_count, | |||
793 | struct RECLAIM_TICKETS_ConsumeHandle * | 891 | struct RECLAIM_TICKETS_ConsumeHandle * |
794 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | 892 | RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, |
795 | const struct GNUNET_RECLAIM_Ticket *ticket, | 893 | const struct GNUNET_RECLAIM_Ticket *ticket, |
796 | RECLAIM_TICKETS_ConsumeCallback cb, void *cb_cls) | 894 | RECLAIM_TICKETS_ConsumeCallback cb, |
895 | void *cb_cls) | ||
797 | { | 896 | { |
798 | struct RECLAIM_TICKETS_ConsumeHandle *cth; | 897 | struct RECLAIM_TICKETS_ConsumeHandle *cth; |
799 | char *label; | 898 | char *label; |
@@ -807,12 +906,18 @@ RECLAIM_TICKETS_consume (const struct GNUNET_CRYPTO_EcdsaPrivateKey *id, | |||
807 | cth->cb_cls = cb_cls; | 906 | cth->cb_cls = cb_cls; |
808 | label = | 907 | label = |
809 | GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t)); | 908 | GNUNET_STRINGS_data_to_string_alloc (&cth->ticket.rnd, sizeof (uint64_t)); |
810 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking for AuthZ info under %s\n", | 909 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
910 | "Looking for AuthZ info under %s\n", | ||
811 | label); | 911 | label); |
812 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); | 912 | cth->lookup_start_time = GNUNET_TIME_absolute_get (); |
813 | cth->lookup_request = GNUNET_GNS_lookup ( | 913 | cth->lookup_request = |
814 | gns, label, &cth->ticket.identity, GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, | 914 | GNUNET_GNS_lookup (gns, |
815 | GNUNET_GNS_LO_DEFAULT, &lookup_authz_cb, cth); | 915 | label, |
916 | &cth->ticket.identity, | ||
917 | GNUNET_GNSRECORD_TYPE_RECLAIM_ATTR_REF, | ||
918 | GNUNET_GNS_LO_DEFAULT, | ||
919 | &lookup_authz_cb, | ||
920 | cth); | ||
816 | GNUNET_free (label); | 921 | GNUNET_free (label); |
817 | return cth; | 922 | return cth; |
818 | } | 923 | } |
@@ -848,8 +953,11 @@ store_ticket_issue_cont (void *cls, int32_t success, const char *emsg) | |||
848 | struct TicketIssueHandle *handle = cls; | 953 | struct TicketIssueHandle *handle = cls; |
849 | 954 | ||
850 | handle->ns_qe = NULL; | 955 | handle->ns_qe = NULL; |
851 | if (GNUNET_SYSERR == success) { | 956 | if (GNUNET_SYSERR == success) |
852 | handle->cb (handle->cb_cls, &handle->ticket, GNUNET_SYSERR, | 957 | { |
958 | handle->cb (handle->cb_cls, | ||
959 | &handle->ticket, | ||
960 | GNUNET_SYSERR, | ||
853 | "Error storing AuthZ ticket in GNS"); | 961 | "Error storing AuthZ ticket in GNS"); |
854 | return; | 962 | return; |
855 | } | 963 | } |
@@ -873,7 +981,8 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
873 | attrs_record = | 981 | attrs_record = |
874 | GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data)); | 982 | GNUNET_malloc (list_len * sizeof (struct GNUNET_GNSRECORD_Data)); |
875 | i = 0; | 983 | i = 0; |
876 | for (le = ih->attrs->list_head; NULL != le; le = le->next) { | 984 | for (le = ih->attrs->list_head; NULL != le; le = le->next) |
985 | { | ||
877 | attrs_record[i].data = &le->claim->id; | 986 | attrs_record[i].data = &le->claim->id; |
878 | attrs_record[i].data_size = sizeof (le->claim->id); | 987 | attrs_record[i].data_size = sizeof (le->claim->id); |
879 | //FIXME: Should this be the attribute expiration time or ticket refresh intv | 988 | //FIXME: Should this be the attribute expiration time or ticket refresh intv |
@@ -892,9 +1001,13 @@ issue_ticket (struct TicketIssueHandle *ih) | |||
892 | label = | 1001 | label = |
893 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); | 1002 | GNUNET_STRINGS_data_to_string_alloc (&ih->ticket.rnd, sizeof (uint64_t)); |
894 | // Publish record | 1003 | // Publish record |
895 | ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, &ih->identity, label, | 1004 | ih->ns_qe = GNUNET_NAMESTORE_records_store (nsh, |
896 | list_len, attrs_record, | 1005 | &ih->identity, |
897 | &store_ticket_issue_cont, ih); | 1006 | label, |
1007 | list_len, | ||
1008 | attrs_record, | ||
1009 | &store_ticket_issue_cont, | ||
1010 | ih); | ||
898 | GNUNET_free (attrs_record); | 1011 | GNUNET_free (attrs_record); |
899 | GNUNET_free (label); | 1012 | GNUNET_free (label); |
900 | } | 1013 | } |
@@ -904,7 +1017,8 @@ void | |||
904 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1017 | RECLAIM_TICKETS_issue (const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
905 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 1018 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, |
906 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, | 1019 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience, |
907 | RECLAIM_TICKETS_TicketResult cb, void *cb_cls) | 1020 | RECLAIM_TICKETS_TicketResult cb, |
1021 | void *cb_cls) | ||
908 | { | 1022 | { |
909 | struct TicketIssueHandle *tih; | 1023 | struct TicketIssueHandle *tih; |
910 | tih = GNUNET_new (struct TicketIssueHandle); | 1024 | tih = GNUNET_new (struct TicketIssueHandle); |
@@ -933,16 +1047,19 @@ cleanup_iter (struct RECLAIM_TICKETS_Iterator *iter) | |||
933 | 1047 | ||
934 | 1048 | ||
935 | static void | 1049 | static void |
936 | collect_tickets_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1050 | collect_tickets_cb (void *cls, |
937 | const char *label, unsigned int rd_count, | 1051 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1052 | const char *label, | ||
1053 | unsigned int rd_count, | ||
938 | const struct GNUNET_GNSRECORD_Data *rd) | 1054 | const struct GNUNET_GNSRECORD_Data *rd) |
939 | { | 1055 | { |
940 | struct RECLAIM_TICKETS_Iterator *iter = cls; | 1056 | struct RECLAIM_TICKETS_Iterator *iter = cls; |
941 | 1057 | ||
942 | for (int i = 0; i < rd_count; i++) { | 1058 | for (int i = 0; i < rd_count; i++) |
1059 | { | ||
943 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type) | 1060 | if (GNUNET_GNSRECORD_TYPE_RECLAIM_TICKET != rd[i].record_type) |
944 | continue; | 1061 | continue; |
945 | iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *)rd[i].data); | 1062 | iter->cb (iter->cb_cls, (struct GNUNET_RECLAIM_Ticket *) rd[i].data); |
946 | return; | 1063 | return; |
947 | } | 1064 | } |
948 | GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1); | 1065 | GNUNET_NAMESTORE_zone_iterator_next (iter->ns_it, 1); |
@@ -986,17 +1103,24 @@ RECLAIM_TICKETS_iteration_stop (struct RECLAIM_TICKETS_Iterator *iter) | |||
986 | 1103 | ||
987 | struct RECLAIM_TICKETS_Iterator * | 1104 | struct RECLAIM_TICKETS_Iterator * |
988 | RECLAIM_TICKETS_iteration_start ( | 1105 | RECLAIM_TICKETS_iteration_start ( |
989 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, | 1106 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *identity, |
990 | RECLAIM_TICKETS_TicketIter cb, void *cb_cls) | 1107 | RECLAIM_TICKETS_TicketIter cb, |
1108 | void *cb_cls) | ||
991 | { | 1109 | { |
992 | struct RECLAIM_TICKETS_Iterator *iter; | 1110 | struct RECLAIM_TICKETS_Iterator *iter; |
993 | 1111 | ||
994 | iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator); | 1112 | iter = GNUNET_new (struct RECLAIM_TICKETS_Iterator); |
995 | iter->cb = cb; | 1113 | iter->cb = cb; |
996 | iter->cb_cls = cb_cls; | 1114 | iter->cb_cls = cb_cls; |
997 | iter->ns_it = GNUNET_NAMESTORE_zone_iteration_start ( | 1115 | iter->ns_it = |
998 | nsh, identity, &collect_tickets_error_cb, iter, &collect_tickets_cb, iter, | 1116 | GNUNET_NAMESTORE_zone_iteration_start (nsh, |
999 | &collect_tickets_finished_cb, iter); | 1117 | identity, |
1118 | &collect_tickets_error_cb, | ||
1119 | iter, | ||
1120 | &collect_tickets_cb, | ||
1121 | iter, | ||
1122 | &collect_tickets_finished_cb, | ||
1123 | iter); | ||
1000 | return iter; | 1124 | return iter; |
1001 | } | 1125 | } |
1002 | 1126 | ||
@@ -1005,28 +1129,32 @@ int | |||
1005 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) | 1129 | RECLAIM_TICKETS_init (const struct GNUNET_CONFIGURATION_Handle *c) |
1006 | { | 1130 | { |
1007 | // Get ticket expiration time (relative) from config | 1131 | // Get ticket expiration time (relative) from config |
1008 | if (GNUNET_OK | 1132 | if (GNUNET_OK == |
1009 | == GNUNET_CONFIGURATION_get_value_time (c, | 1133 | GNUNET_CONFIGURATION_get_value_time (c, |
1010 | "reclaim", | 1134 | "reclaim", |
1011 | "TICKET_REFRESH_INTERVAL", | 1135 | "TICKET_REFRESH_INTERVAL", |
1012 | &ticket_refresh_interval)) { | 1136 | &ticket_refresh_interval)) |
1013 | GNUNET_log ( | 1137 | { |
1014 | GNUNET_ERROR_TYPE_DEBUG, | 1138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1015 | "Configured refresh interval for tickets: %s\n", | 1139 | "Configured refresh interval for tickets: %s\n", |
1016 | GNUNET_STRINGS_relative_time_to_string (ticket_refresh_interval, | 1140 | GNUNET_STRINGS_relative_time_to_string (ticket_refresh_interval, |
1017 | GNUNET_YES)); | 1141 | GNUNET_YES)); |
1018 | } else { | 1142 | } |
1143 | else | ||
1144 | { | ||
1019 | ticket_refresh_interval = DEFAULT_TICKET_REFRESH_INTERVAL; | 1145 | ticket_refresh_interval = DEFAULT_TICKET_REFRESH_INTERVAL; |
1020 | } | 1146 | } |
1021 | // Connect to identity and namestore services | 1147 | // Connect to identity and namestore services |
1022 | nsh = GNUNET_NAMESTORE_connect (c); | 1148 | nsh = GNUNET_NAMESTORE_connect (c); |
1023 | if (NULL == nsh) { | 1149 | if (NULL == nsh) |
1150 | { | ||
1024 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 1151 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, |
1025 | "error connecting to namestore"); | 1152 | "error connecting to namestore"); |
1026 | return GNUNET_SYSERR; | 1153 | return GNUNET_SYSERR; |
1027 | } | 1154 | } |
1028 | gns = GNUNET_GNS_connect (c); | 1155 | gns = GNUNET_GNS_connect (c); |
1029 | if (NULL == gns) { | 1156 | if (NULL == gns) |
1157 | { | ||
1030 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); | 1158 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "error connecting to gns"); |
1031 | return GNUNET_SYSERR; | 1159 | return GNUNET_SYSERR; |
1032 | } | 1160 | } |
@@ -1043,7 +1171,8 @@ RECLAIM_TICKETS_deinit (void) | |||
1043 | if (NULL != gns) | 1171 | if (NULL != gns) |
1044 | GNUNET_GNS_disconnect (gns); | 1172 | GNUNET_GNS_disconnect (gns); |
1045 | gns = NULL; | 1173 | gns = NULL; |
1046 | if (NULL != stats) { | 1174 | if (NULL != stats) |
1175 | { | ||
1047 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 1176 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1048 | stats = NULL; | 1177 | stats = NULL; |
1049 | } | 1178 | } |
diff --git a/src/reclaim/json_reclaim.c b/src/reclaim/json_reclaim.c index 3ba4300bb..222cf1dbf 100644 --- a/src/reclaim/json_reclaim.c +++ b/src/reclaim/json_reclaim.c | |||
@@ -55,24 +55,37 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
55 | 55 | ||
56 | GNUNET_assert (NULL != root); | 56 | GNUNET_assert (NULL != root); |
57 | 57 | ||
58 | if (!json_is_object (root)) { | 58 | if (! json_is_object (root)) |
59 | { | ||
59 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
60 | "Error json is not array nor object!\n"); | 61 | "Error json is not array nor object!\n"); |
61 | return GNUNET_SYSERR; | 62 | return GNUNET_SYSERR; |
62 | } | 63 | } |
63 | // interpret single attribute | 64 | // interpret single attribute |
64 | unpack_state = | 65 | unpack_state = json_unpack (root, |
65 | json_unpack (root, "{s:s, s?s, s:s, s:s!}", "name", &name_str, "id", | 66 | "{s:s, s?s, s:s, s:s!}", |
66 | &id_str, "type", &type_str, "value", &val_str); | 67 | "name", |
68 | &name_str, | ||
69 | "id", | ||
70 | &id_str, | ||
71 | "type", | ||
72 | &type_str, | ||
73 | "value", | ||
74 | &val_str); | ||
67 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || | 75 | if ((0 != unpack_state) || (NULL == name_str) || (NULL == val_str) || |
68 | (NULL == type_str)) { | 76 | (NULL == type_str)) |
77 | { | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
70 | "Error json object has a wrong format!\n"); | 79 | "Error json object has a wrong format!\n"); |
71 | return GNUNET_SYSERR; | 80 | return GNUNET_SYSERR; |
72 | } | 81 | } |
73 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); | 82 | type = GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (type_str); |
74 | if (GNUNET_SYSERR == (GNUNET_RECLAIM_ATTRIBUTE_string_to_value ( | 83 | if (GNUNET_SYSERR == |
75 | type, val_str, (void **)&data, &data_size))) { | 84 | (GNUNET_RECLAIM_ATTRIBUTE_string_to_value (type, |
85 | val_str, | ||
86 | (void **) &data, | ||
87 | &data_size))) | ||
88 | { | ||
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); | 89 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attribute value invalid!\n"); |
77 | return GNUNET_SYSERR; | 90 | return GNUNET_SYSERR; |
78 | } | 91 | } |
@@ -80,10 +93,12 @@ parse_attr (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
80 | if ((NULL == id_str) || (0 == strlen (id_str))) | 93 | if ((NULL == id_str) || (0 == strlen (id_str))) |
81 | attr->id = 0; | 94 | attr->id = 0; |
82 | else | 95 | else |
83 | GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &attr->id, | 96 | GNUNET_STRINGS_string_to_data (id_str, |
97 | strlen (id_str), | ||
98 | &attr->id, | ||
84 | sizeof (uint64_t)); | 99 | sizeof (uint64_t)); |
85 | 100 | ||
86 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr = attr; | 101 | *(struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr = attr; |
87 | return GNUNET_OK; | 102 | return GNUNET_OK; |
88 | } | 103 | } |
89 | 104 | ||
@@ -97,8 +112,9 @@ static void | |||
97 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) | 112 | clean_attr (void *cls, struct GNUNET_JSON_Specification *spec) |
98 | { | 113 | { |
99 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; | 114 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr; |
100 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **)spec->ptr; | 115 | attr = (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **) spec->ptr; |
101 | if (NULL != *attr) { | 116 | if (NULL != *attr) |
117 | { | ||
102 | GNUNET_free (*attr); | 118 | GNUNET_free (*attr); |
103 | *attr = NULL; | 119 | *attr = NULL; |
104 | } | 120 | } |
@@ -114,12 +130,12 @@ struct GNUNET_JSON_Specification | |||
114 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) | 130 | GNUNET_RECLAIM_JSON_spec_claim (struct GNUNET_RECLAIM_ATTRIBUTE_Claim **attr) |
115 | { | 131 | { |
116 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, | 132 | struct GNUNET_JSON_Specification ret = {.parser = &parse_attr, |
117 | .cleaner = &clean_attr, | 133 | .cleaner = &clean_attr, |
118 | .cls = NULL, | 134 | .cls = NULL, |
119 | .field = NULL, | 135 | .field = NULL, |
120 | .ptr = attr, | 136 | .ptr = attr, |
121 | .ptr_size = 0, | 137 | .ptr_size = 0, |
122 | .size_ptr = NULL}; | 138 | .size_ptr = NULL}; |
123 | *attr = NULL; | 139 | *attr = NULL; |
124 | return ret; | 140 | return ret; |
125 | } | 141 | } |
@@ -142,44 +158,61 @@ parse_ticket (void *cls, json_t *root, struct GNUNET_JSON_Specification *spec) | |||
142 | 158 | ||
143 | GNUNET_assert (NULL != root); | 159 | GNUNET_assert (NULL != root); |
144 | 160 | ||
145 | if (!json_is_object (root)) { | 161 | if (! json_is_object (root)) |
162 | { | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
147 | "Error json is not array nor object!\n"); | 164 | "Error json is not array nor object!\n"); |
148 | return GNUNET_SYSERR; | 165 | return GNUNET_SYSERR; |
149 | } | 166 | } |
150 | // interpret single ticket | 167 | // interpret single ticket |
151 | unpack_state = json_unpack (root, "{s:s, s:s, s:s!}", "rnd", &rnd_str, | 168 | unpack_state = json_unpack (root, |
152 | "audience", &aud_str, "identity", &id_str); | 169 | "{s:s, s:s, s:s!}", |
153 | if (0 != unpack_state) { | 170 | "rnd", |
171 | &rnd_str, | ||
172 | "audience", | ||
173 | &aud_str, | ||
174 | "identity", | ||
175 | &id_str); | ||
176 | if (0 != unpack_state) | ||
177 | { | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Error json object has a wrong format!\n"); | 179 | "Error json object has a wrong format!\n"); |
156 | return GNUNET_SYSERR; | 180 | return GNUNET_SYSERR; |
157 | } | 181 | } |
158 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 182 | ticket = GNUNET_new (struct GNUNET_RECLAIM_Ticket); |
159 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, strlen (rnd_str), | 183 | if (GNUNET_OK != GNUNET_STRINGS_string_to_data (rnd_str, |
184 | strlen (rnd_str), | ||
160 | &ticket->rnd, | 185 | &ticket->rnd, |
161 | sizeof (uint64_t))) { | 186 | sizeof (uint64_t))) |
187 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Rnd invalid\n"); |
163 | GNUNET_free (ticket); | 189 | GNUNET_free (ticket); |
164 | return GNUNET_SYSERR; | 190 | return GNUNET_SYSERR; |
165 | } | 191 | } |
166 | GNUNET_STRINGS_string_to_data (id_str, strlen (id_str), &ticket->identity, | 192 | if (GNUNET_OK != |
167 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 193 | GNUNET_STRINGS_string_to_data (id_str, |
194 | strlen (id_str), | ||
195 | &ticket->identity, | ||
196 | sizeof ( | ||
197 | struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
168 | { | 198 | { |
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity invalid\n"); |
170 | GNUNET_free (ticket); | 200 | GNUNET_free (ticket); |
171 | return GNUNET_SYSERR; | 201 | return GNUNET_SYSERR; |
172 | } | 202 | } |
173 | 203 | ||
174 | GNUNET_STRINGS_string_to_data (aud_str, strlen (aud_str), &ticket->audience, | 204 | if (GNUNET_OK != |
175 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | 205 | GNUNET_STRINGS_string_to_data (aud_str, |
206 | strlen (aud_str), | ||
207 | &ticket->audience, | ||
208 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey))) | ||
176 | { | 209 | { |
177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); | 210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience invalid\n"); |
178 | GNUNET_free (ticket); | 211 | GNUNET_free (ticket); |
179 | return GNUNET_SYSERR; | 212 | return GNUNET_SYSERR; |
180 | } | 213 | } |
181 | 214 | ||
182 | *(struct GNUNET_RECLAIM_Ticket **)spec->ptr = ticket; | 215 | *(struct GNUNET_RECLAIM_Ticket **) spec->ptr = ticket; |
183 | return GNUNET_OK; | 216 | return GNUNET_OK; |
184 | } | 217 | } |
185 | 218 | ||
@@ -193,8 +226,9 @@ static void | |||
193 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) | 226 | clean_ticket (void *cls, struct GNUNET_JSON_Specification *spec) |
194 | { | 227 | { |
195 | struct GNUNET_RECLAIM_Ticket **ticket; | 228 | struct GNUNET_RECLAIM_Ticket **ticket; |
196 | ticket = (struct GNUNET_RECLAIM_Ticket **)spec->ptr; | 229 | ticket = (struct GNUNET_RECLAIM_Ticket **) spec->ptr; |
197 | if (NULL != *ticket) { | 230 | if (NULL != *ticket) |
231 | { | ||
198 | GNUNET_free (*ticket); | 232 | GNUNET_free (*ticket); |
199 | *ticket = NULL; | 233 | *ticket = NULL; |
200 | } | 234 | } |
@@ -210,12 +244,12 @@ struct GNUNET_JSON_Specification | |||
210 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) | 244 | GNUNET_RECLAIM_JSON_spec_ticket (struct GNUNET_RECLAIM_Ticket **ticket) |
211 | { | 245 | { |
212 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, | 246 | struct GNUNET_JSON_Specification ret = {.parser = &parse_ticket, |
213 | .cleaner = &clean_ticket, | 247 | .cleaner = &clean_ticket, |
214 | .cls = NULL, | 248 | .cls = NULL, |
215 | .field = NULL, | 249 | .field = NULL, |
216 | .ptr = ticket, | 250 | .ptr = ticket, |
217 | .ptr_size = 0, | 251 | .ptr_size = 0, |
218 | .size_ptr = NULL}; | 252 | .size_ptr = NULL}; |
219 | *ticket = NULL; | 253 | *ticket = NULL; |
220 | return ret; | 254 | return ret; |
221 | } | 255 | } |
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c index 93e5ac864..e8561aed4 100644 --- a/src/reclaim/plugin_rest_openid_connect.c +++ b/src/reclaim/plugin_rest_openid_connect.c | |||
@@ -209,12 +209,12 @@ | |||
209 | * OIDC ignored parameter array | 209 | * OIDC ignored parameter array |
210 | */ | 210 | */ |
211 | static char *OIDC_ignored_parameter_array[] = {"display", | 211 | static char *OIDC_ignored_parameter_array[] = {"display", |
212 | "prompt", | 212 | "prompt", |
213 | "ui_locales", | 213 | "ui_locales", |
214 | "response_mode", | 214 | "response_mode", |
215 | "id_token_hint", | 215 | "id_token_hint", |
216 | "login_hint", | 216 | "login_hint", |
217 | "acr_values"}; | 217 | "acr_values"}; |
218 | 218 | ||
219 | /** | 219 | /** |
220 | * OIDC Hash map that keeps track of issued cookies | 220 | * OIDC Hash map that keeps track of issued cookies |
@@ -724,7 +724,7 @@ cookie_identity_interpretation (struct RequestHandle *handle) | |||
724 | strlen (OIDC_COOKIE_HEADER_KEY), | 724 | strlen (OIDC_COOKIE_HEADER_KEY), |
725 | &cache_key); | 725 | &cache_key); |
726 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 726 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle |
727 | ->header_param_map, | 727 | ->header_param_map, |
728 | &cache_key)) | 728 | &cache_key)) |
729 | { | 729 | { |
730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n"); | 730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cookie found\n"); |
@@ -772,9 +772,9 @@ cookie_identity_interpretation (struct RequestHandle *handle) | |||
772 | GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key)) | 772 | GNUNET_CONTAINER_multihashmap_contains (OIDC_cookie_jar_map, &cache_key)) |
773 | { | 773 | { |
774 | GNUNET_log ( | 774 | GNUNET_log ( |
775 | GNUNET_ERROR_TYPE_WARNING, | 775 | GNUNET_ERROR_TYPE_WARNING, |
776 | "Found cookie `%s', but no corresponding expiration entry present...\n", | 776 | "Found cookie `%s', but no corresponding expiration entry present...\n", |
777 | token); | 777 | token); |
778 | GNUNET_free (cookies); | 778 | GNUNET_free (cookies); |
779 | return; | 779 | return; |
780 | } | 780 | } |
@@ -793,6 +793,7 @@ cookie_identity_interpretation (struct RequestHandle *handle) | |||
793 | value = strtok (token, OIDC_COOKIE_HEADER_INFORMATION_KEY); | 793 | value = strtok (token, OIDC_COOKIE_HEADER_INFORMATION_KEY); |
794 | GNUNET_assert (NULL != value); | 794 | GNUNET_assert (NULL != value); |
795 | handle->oidc->login_identity = GNUNET_strdup (value); | 795 | handle->oidc->login_identity = GNUNET_strdup (value); |
796 | GNUNET_free (cookies); | ||
796 | } | 797 | } |
797 | 798 | ||
798 | /** | 799 | /** |
@@ -1020,10 +1021,10 @@ code_redirect (void *cls) | |||
1020 | { | 1021 | { |
1021 | if (GNUNET_OK != | 1022 | if (GNUNET_OK != |
1022 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc | 1023 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc |
1023 | ->login_identity, | 1024 | ->login_identity, |
1024 | strlen ( | 1025 | strlen ( |
1025 | handle->oidc | 1026 | handle->oidc |
1026 | ->login_identity), | 1027 | ->login_identity), |
1027 | &pubkey)) | 1028 | &pubkey)) |
1028 | { | 1029 | { |
1029 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); | 1030 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_COOKIE); |
@@ -1134,18 +1135,31 @@ lookup_redirect_uri_result (void *cls, | |||
1134 | if (NULL == strstr (tmp, handle->oidc->client_id)) | 1135 | if (NULL == strstr (tmp, handle->oidc->client_id)) |
1135 | { | 1136 | { |
1136 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1137 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Redirect uri %s does not contain client_id %s", | 1138 | "Redirect uri %s does not contain client_id %s\n", |
1138 | tmp, | 1139 | tmp, |
1139 | handle->oidc->client_id); | 1140 | handle->oidc->client_id); |
1140 | } | 1141 | } |
1141 | else | 1142 | else |
1142 | { | 1143 | { |
1143 | |||
1144 | pos = strrchr (tmp, (unsigned char) '.'); | 1144 | pos = strrchr (tmp, (unsigned char) '.'); |
1145 | if (NULL == pos) | ||
1146 | { | ||
1147 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1148 | "Redirect uri %s contains client_id but is malformed\n", | ||
1149 | tmp); | ||
1150 | continue; | ||
1151 | } | ||
1145 | *pos = '\0'; | 1152 | *pos = '\0'; |
1146 | handle->redirect_prefix = GNUNET_strdup (tmp); | 1153 | handle->redirect_prefix = GNUNET_strdup (tmp); |
1147 | tmp_key_str = pos + 1; | 1154 | tmp_key_str = pos + 1; |
1148 | pos = strchr (tmp_key_str, (unsigned char) '/'); | 1155 | pos = strchr (tmp_key_str, (unsigned char) '/'); |
1156 | if (NULL == pos) | ||
1157 | { | ||
1158 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1159 | "Redirect uri %s contains client_id but is malformed\n", | ||
1160 | tmp); | ||
1161 | continue; | ||
1162 | } | ||
1149 | *pos = '\0'; | 1163 | *pos = '\0'; |
1150 | handle->redirect_suffix = GNUNET_strdup (pos + 1); | 1164 | handle->redirect_suffix = GNUNET_strdup (pos + 1); |
1151 | 1165 | ||
@@ -1191,7 +1205,7 @@ get_url_parameter_copy (const struct RequestHandle *handle, const char *key) | |||
1191 | char *value; | 1205 | char *value; |
1192 | GNUNET_CRYPTO_hash (key, strlen (key), &hc); | 1206 | GNUNET_CRYPTO_hash (key, strlen (key), &hc); |
1193 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1207 | if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle |
1194 | ->url_param_map, | 1208 | ->url_param_map, |
1195 | &hc)) | 1209 | &hc)) |
1196 | return NULL; | 1210 | return NULL; |
1197 | value = | 1211 | value = |
@@ -1264,7 +1278,7 @@ build_authz_response (void *cls) | |||
1264 | &cache_key); | 1278 | &cache_key); |
1265 | if (GNUNET_YES == | 1279 | if (GNUNET_YES == |
1266 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1280 | GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle |
1267 | ->url_param_map, | 1281 | ->url_param_map, |
1268 | &cache_key)) | 1282 | &cache_key)) |
1269 | { | 1283 | { |
1270 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED); | 1284 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_ACCESS_DENIED); |
@@ -1370,7 +1384,7 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1370 | if (GNUNET_OK != | 1384 | if (GNUNET_OK != |
1371 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id, | 1385 | GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->oidc->client_id, |
1372 | strlen ( | 1386 | strlen ( |
1373 | handle->oidc->client_id), | 1387 | handle->oidc->client_id), |
1374 | &handle->oidc->client_pkey)) | 1388 | &handle->oidc->client_pkey)) |
1375 | { | 1389 | { |
1376 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); | 1390 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNAUTHORIZED_CLIENT); |
@@ -1455,8 +1469,8 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle, | |||
1455 | { | 1469 | { |
1456 | current_time = GNUNET_new (struct GNUNET_TIME_Absolute); | 1470 | current_time = GNUNET_new (struct GNUNET_TIME_Absolute); |
1457 | *current_time = GNUNET_TIME_relative_to_absolute ( | 1471 | *current_time = GNUNET_TIME_relative_to_absolute ( |
1458 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (), | 1472 | GNUNET_TIME_relative_multiply (GNUNET_TIME_relative_get_second_ (), |
1459 | OIDC_COOKIE_EXPIRATION)); | 1473 | OIDC_COOKIE_EXPIRATION)); |
1460 | last_time = | 1474 | last_time = |
1461 | GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key); | 1475 | GNUNET_CONTAINER_multihashmap_get (OIDC_cookie_jar_map, &cache_key); |
1462 | GNUNET_free_non_null (last_time); | 1476 | GNUNET_free_non_null (last_time); |
@@ -1488,7 +1502,7 @@ check_authorization (struct RequestHandle *handle, | |||
1488 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), | 1502 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), |
1489 | &cache_key); | 1503 | &cache_key); |
1490 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1504 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle |
1491 | ->header_param_map, | 1505 | ->header_param_map, |
1492 | &cache_key)) | 1506 | &cache_key)) |
1493 | { | 1507 | { |
1494 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1508 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); |
@@ -1502,7 +1516,7 @@ check_authorization (struct RequestHandle *handle, | |||
1502 | 1516 | ||
1503 | // split header in "Basic" and [content] | 1517 | // split header in "Basic" and [content] |
1504 | credentials = strtok (authorization, " "); | 1518 | credentials = strtok (authorization, " "); |
1505 | if (0 != strcmp ("Basic", credentials)) | 1519 | if ((NULL == credentials) || (0 != strcmp ("Basic", credentials))) |
1506 | { | 1520 | { |
1507 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); | 1521 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT); |
1508 | handle->response_code = MHD_HTTP_UNAUTHORIZED; | 1522 | handle->response_code = MHD_HTTP_UNAUTHORIZED; |
@@ -1568,8 +1582,7 @@ check_authorization (struct RequestHandle *handle, | |||
1568 | } | 1582 | } |
1569 | 1583 | ||
1570 | // check client_id | 1584 | // check client_id |
1571 | for (handle->ego_entry = handle->ego_head; | 1585 | for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry; |
1572 | NULL != handle->ego_entry; | ||
1573 | handle->ego_entry = handle->ego_entry->next) | 1586 | handle->ego_entry = handle->ego_entry->next) |
1574 | { | 1587 | { |
1575 | if (0 == strcmp (handle->ego_entry->keystring, client_id)) | 1588 | if (0 == strcmp (handle->ego_entry->keystring, client_id)) |
@@ -1619,11 +1632,12 @@ persist_access_token (const struct RequestHandle *handle, | |||
1619 | GNUNET_CRYPTO_hash (access_token, strlen (access_token), &hc); | 1632 | GNUNET_CRYPTO_hash (access_token, strlen (access_token), &hc); |
1620 | ticketbuf = GNUNET_new (struct GNUNET_RECLAIM_Ticket); | 1633 | ticketbuf = GNUNET_new (struct GNUNET_RECLAIM_Ticket); |
1621 | *ticketbuf = *ticket; | 1634 | *ticketbuf = *ticket; |
1622 | GNUNET_CONTAINER_multihashmap_put ( | 1635 | GNUNET_assert (GNUNET_SYSERR != |
1623 | OIDC_access_token_map, | 1636 | GNUNET_CONTAINER_multihashmap_put ( |
1624 | &hc, | 1637 | OIDC_access_token_map, |
1625 | ticketbuf, | 1638 | &hc, |
1626 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1639 | ticketbuf, |
1640 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1627 | } | 1641 | } |
1628 | 1642 | ||
1629 | /** | 1643 | /** |
@@ -1690,10 +1704,11 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1690 | { | 1704 | { |
1691 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE); | 1705 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_UNSUPPORTED_GRANT_TYPE); |
1692 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1706 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1707 | GNUNET_free (grant_type); | ||
1693 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1708 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1694 | return; | 1709 | return; |
1695 | } | 1710 | } |
1696 | 1711 | GNUNET_free (grant_type); | |
1697 | // REQUIRED code | 1712 | // REQUIRED code |
1698 | code = get_url_parameter_copy (handle, OIDC_CODE_KEY); | 1713 | code = get_url_parameter_copy (handle, OIDC_CODE_KEY); |
1699 | if (NULL == code) | 1714 | if (NULL == code) |
@@ -1710,7 +1725,9 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1710 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1725 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); |
1711 | handle->edesc = GNUNET_strdup ("Unknown client"); | 1726 | handle->edesc = GNUNET_strdup ("Unknown client"); |
1712 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1727 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1728 | GNUNET_free (code); | ||
1713 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1729 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1730 | return; | ||
1714 | } | 1731 | } |
1715 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | 1732 | privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); |
1716 | // decode code | 1733 | // decode code |
@@ -1719,9 +1736,11 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1719 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); | 1736 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST); |
1720 | handle->edesc = GNUNET_strdup ("invalid code"); | 1737 | handle->edesc = GNUNET_strdup ("invalid code"); |
1721 | handle->response_code = MHD_HTTP_BAD_REQUEST; | 1738 | handle->response_code = MHD_HTTP_BAD_REQUEST; |
1739 | GNUNET_free (code); | ||
1722 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 1740 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1723 | return; | 1741 | return; |
1724 | } | 1742 | } |
1743 | GNUNET_free (code); | ||
1725 | 1744 | ||
1726 | // create jwt | 1745 | // create jwt |
1727 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, | 1746 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, |
@@ -1826,7 +1845,7 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle, | |||
1826 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), | 1845 | strlen (OIDC_AUTHORIZATION_HEADER_KEY), |
1827 | &cache_key); | 1846 | &cache_key); |
1828 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle | 1847 | if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle |
1829 | ->header_param_map, | 1848 | ->header_param_map, |
1830 | &cache_key)) | 1849 | &cache_key)) |
1831 | { | 1850 | { |
1832 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); | 1851 | handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN); |
@@ -1915,16 +1934,16 @@ init_cont (struct RequestHandle *handle) | |||
1915 | { | 1934 | { |
1916 | struct GNUNET_REST_RequestHandlerError err; | 1935 | struct GNUNET_REST_RequestHandlerError err; |
1917 | static const struct GNUNET_REST_RequestHandler handlers[] = | 1936 | static const struct GNUNET_REST_RequestHandler handlers[] = |
1918 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint}, | 1937 | {{MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint}, |
1919 | {MHD_HTTP_METHOD_POST, | 1938 | {MHD_HTTP_METHOD_POST, |
1920 | GNUNET_REST_API_NS_AUTHORIZE, | 1939 | GNUNET_REST_API_NS_AUTHORIZE, |
1921 | &authorize_endpoint}, // url-encoded | 1940 | &authorize_endpoint}, // url-encoded |
1922 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont}, | 1941 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont}, |
1923 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint}, | 1942 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint}, |
1924 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, | 1943 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, |
1925 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, | 1944 | {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint}, |
1926 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont}, | 1945 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont}, |
1927 | GNUNET_REST_HANDLER_END}; | 1946 | GNUNET_REST_HANDLER_END}; |
1928 | 1947 | ||
1929 | if (GNUNET_NO == | 1948 | if (GNUNET_NO == |
1930 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) | 1949 | GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle)) |