anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

commit 8bda3af5232944998bc0500b68dcae38942185fa
parent 0477b8aa8692d6f129e8a400a02d8048e1d37316
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 14 Aug 2026 17:47:38 +0200

disambiguate return values

Diffstat:
Msrc/authorization/anastasis_authorization_plugin_email.c | 38++++++++++++++++++++++++++++++++------
Msrc/authorization/anastasis_authorization_plugin_post.c | 45+++++++++++++++++++++++++++++++++++----------
Msrc/authorization/anastasis_authorization_plugin_sms.c | 44++++++++++++++++++++++++++++++++++----------
3 files changed, 101 insertions(+), 26 deletions(-)

diff --git a/src/authorization/anastasis_authorization_plugin_email.c b/src/authorization/anastasis_authorization_plugin_email.c @@ -341,11 +341,35 @@ email_start (void *cls, /** + * Did a transmission helper report that the challenge was transmitted? + * + * Exit code 0 means the challenge was confirmed to have reached the address. + * The 200-210 band means a service accepted it for delivery without confirming + * that it arrived: 201 accepted by the provider, 202 suppressed as a duplicate + * of a message already in flight. + * + * The band deliberately does not start at 1: libgnunetutil reports a helper it + * failed to exec() as exit code 1, and that must not be mistaken for a + * delivery. + * + * @param exit_code exit status of the helper, which must have exited normally + * @return true if the challenge was transmitted + */ +static bool +helper_reported_success (unsigned long int exit_code) +{ + return (0 == exit_code) || + ( (exit_code >= 200) && + (exit_code <= 210) ); +} + + +/** * Map the exit status of the Email helper onto an HTTP status and error code. * * The helpers shipped with Challenger use a banded exit-code scheme documented - * in challenger-send-email(1): anything below 10 means the challenge was - * transmitted -- for e-mail always 1 (accepted by the mail transfer agent), + * in challenger-send-email(1): 0 and 200-210 mean the challenge was + * transmitted -- for e-mail always 201 (accepted by the mail transfer agent), * since delivery to a mailbox cannot be confirmed -- 10-19 blames the address * the user gave us, 20-29 is a recipient that is temporarily unreachable, * 30-39 is the transmission provider and 40-49 is our own configuration. @@ -362,17 +386,19 @@ static enum TALER_ErrorCode classify_helper_status (unsigned long int exit_code, unsigned int *http_status) { - if (exit_code < 10) + if (helper_reported_success (exit_code)) { *http_status = MHD_HTTP_OK; return TALER_EC_NONE; } - if (exit_code < 20) + if ( (exit_code >= 10) && + (exit_code < 20) ) { *http_status = MHD_HTTP_CONFLICT; return TALER_EC_ANASTASIS_EMAIL_INVALID; } - if (exit_code < 30) + if ( (exit_code >= 20) && + (exit_code < 30) ) { *http_status = MHD_HTTP_SERVICE_UNAVAILABLE; return TALER_EC_ANASTASIS_ADDRESS_UNREACHABLE; @@ -548,7 +574,7 @@ email_challenge (struct ANASTASIS_AUTHORIZATION_State *as, return ANASTASIS_AUTHORIZATION_CRES_SUSPENDED; } if ( (GNUNET_OS_PROCESS_EXITED != as->pst) || - (as->exit_code >= 10) ) + (! helper_reported_success (as->exit_code)) ) { char es[32]; unsigned int http_status; diff --git a/src/authorization/anastasis_authorization_plugin_post.c b/src/authorization/anastasis_authorization_plugin_post.c @@ -379,15 +379,38 @@ post_start (void *cls, /** + * Did a transmission helper report that the challenge was transmitted? + * + * Exit code 0 means the challenge was confirmed to have reached the address. + * The 200-210 band means a service accepted it for delivery without confirming + * that it arrived: 201 accepted by the provider, 202 suppressed as a duplicate + * of a message already in flight. + * + * The band deliberately does not start at 1: libgnunetutil reports a helper it + * failed to exec() as exit code 1, and that must not be mistaken for a + * delivery. + * + * @param exit_code exit status of the helper, which must have exited normally + * @return true if the challenge was transmitted + */ +static bool +helper_reported_success (unsigned long int exit_code) +{ + return (0 == exit_code) || + ( (exit_code >= 200) && + (exit_code <= 210) ); +} + + +/** * Map the exit status of the Post helper onto an HTTP status and error code. * * The helpers shipped with Challenger use a banded exit-code scheme documented - * in challenger-send-post(1): anything below 10 means the challenge was - * transmitted -- for physical mail always 1 (accepted for printing and - * dispatch), since delivery takes days and is never reported back -- 10-19 - * blames the address the user gave us, 20-29 is a recipient that is - * temporarily unreachable, 30-39 is the transmission provider and 40-49 is our - * own configuration. + * in challenger-send-post(1): 0 and 200-210 mean the challenge was transmitted + * -- for physical mail always 201 (accepted for printing and dispatch), since + * delivery takes days and is never reported back -- 10-19 blames the address + * the user gave us, 20-29 is a recipient that is temporarily unreachable, + * 30-39 is the transmission provider and 40-49 is our own configuration. * * Codes we do not recognise are reported as an upstream failure rather than * blamed on the user, so that a helper predating this scheme -- which used @@ -401,17 +424,19 @@ static enum TALER_ErrorCode classify_helper_status (unsigned long int exit_code, unsigned int *http_status) { - if (exit_code < 10) + if (helper_reported_success (exit_code)) { *http_status = MHD_HTTP_OK; return TALER_EC_NONE; } - if (exit_code < 20) + if ( (exit_code >= 10) && + (exit_code < 20) ) { *http_status = MHD_HTTP_CONFLICT; return TALER_EC_ANASTASIS_POST_INVALID; } - if (exit_code < 30) + if ( (exit_code >= 20) && + (exit_code < 30) ) { *http_status = MHD_HTTP_SERVICE_UNAVAILABLE; return TALER_EC_ANASTASIS_ADDRESS_UNREACHABLE; @@ -627,7 +652,7 @@ post_challenge (struct ANASTASIS_AUTHORIZATION_State *as, return ANASTASIS_AUTHORIZATION_CRES_SUSPENDED; } if ( (GNUNET_OS_PROCESS_EXITED != as->pst) || - (as->exit_code >= 10) ) + (! helper_reported_success (as->exit_code)) ) { char es[32]; unsigned int http_status; diff --git a/src/authorization/anastasis_authorization_plugin_sms.c b/src/authorization/anastasis_authorization_plugin_sms.c @@ -308,15 +308,37 @@ sms_start (void *cls, /** + * Did a transmission helper report that the challenge was transmitted? + * + * Exit code 0 means the challenge was confirmed to have reached the address. + * The 200-210 band means a service accepted it for delivery without confirming + * that it arrived: 201 accepted by the provider, 202 suppressed as a duplicate + * of a message already in flight. + * + * The band deliberately does not start at 1: libgnunetutil reports a helper it + * failed to exec() as exit code 1, and that must not be mistaken for a + * delivery. + * + * @param exit_code exit status of the helper, which must have exited normally + * @return true if the challenge was transmitted + */ +static bool +helper_reported_success (unsigned long int exit_code) +{ + return (0 == exit_code) || + ( (exit_code >= 200) && + (exit_code <= 210) ); +} + + +/** * Map the exit status of the SMS helper onto an HTTP status and error code. * * The helpers shipped with Challenger use a banded exit-code scheme documented - * in challenger-send-sms(1): anything below 10 means the challenge was - * transmitted (0 confirmed on the handset, 1 accepted by the provider, 2 - * suppressed as a duplicate of a message already in flight), 10-19 blames the - * address the user gave us, 20-29 is a recipient that is temporarily - * unreachable, 30-39 is the transmission provider and 40-49 is our own - * configuration. + * in challenger-send-sms(1): 0 and 200-210 mean the challenge was transmitted + * (see #helper_reported_success()), 10-19 blames the address the user gave + * us, 20-29 is a recipient that is temporarily unreachable, 30-39 is the + * transmission provider and 40-49 is our own configuration. * * Codes we do not recognise are reported as an upstream failure rather than * blamed on the user, so that a helper predating this scheme -- which used @@ -330,17 +352,19 @@ static enum TALER_ErrorCode classify_helper_status (unsigned long int exit_code, unsigned int *http_status) { - if (exit_code < 10) + if (helper_reported_success (exit_code)) { *http_status = MHD_HTTP_OK; return TALER_EC_NONE; } - if (exit_code < 20) + if ( (exit_code >= 10) && + (exit_code < 20) ) { *http_status = MHD_HTTP_CONFLICT; return TALER_EC_ANASTASIS_SMS_PHONE_INVALID; } - if (exit_code < 30) + if ( (exit_code >= 20) && + (exit_code < 30) ) { *http_status = MHD_HTTP_SERVICE_UNAVAILABLE; return TALER_EC_ANASTASIS_ADDRESS_UNREACHABLE; @@ -500,7 +524,7 @@ sms_challenge (struct ANASTASIS_AUTHORIZATION_State *as, return ANASTASIS_AUTHORIZATION_CRES_SUSPENDED; } if ( (GNUNET_OS_PROCESS_EXITED != as->pst) || - (as->exit_code >= 10) ) + (! helper_reported_success (as->exit_code)) ) { char es[32]; unsigned int http_status;