]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-oauth2, auth: Remove redundant oauth2_request_result.success
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 26 May 2020 21:19:42 +0000 (00:19 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 7 Dec 2020 08:59:28 +0000 (08:59 +0000)
success is the same as (error == NULL)

src/auth/db-oauth2.c
src/lib-oauth2/oauth2-request.c
src/lib-oauth2/oauth2.h

index f926d272f24904ee1f233be2aa74c4cb8bbcdc12..113249310af74513a9b721a6bf26da5ba2202e1f 100644 (file)
@@ -617,9 +617,9 @@ db_oauth2_introspect_continue(struct oauth2_request_result *result,
 
        e_debug(authdb_event(req->auth_request),
                "Introspection result: %s",
-               result->success ? "success" : "failed");
+               result->error == NULL ? "success" : "failed");
 
-       if (!result->success) {
+       if (result->error != NULL) {
                /* fail here */
                passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
                error = result->error;
@@ -680,7 +680,7 @@ db_oauth2_lookup_continue(struct oauth2_request_result *result,
 
        req->req = NULL;
 
-       if (!result->success) {
+       if (result->error != NULL) {
                passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
                error = result->error;
        } else if (!result->valid) {
@@ -721,7 +721,7 @@ db_oauth2_lookup_passwd_grant(struct oauth2_request_result *result,
 
        if (!result->valid) {
                passdb_result = PASSDB_RESULT_INTERNAL_FAILURE;
-               if (result->success) {
+               if (result->error == NULL) {
                        error = NULL;
                        array_foreach(result->fields, f) {
                                if (strcmp(f->name, "error") == 0) {
index a3fae585430dfbf50af50e0333410b6b8460cbb4..15bce9d7d7904af50b2fa32c71a1fab8ab2e0984 100644 (file)
@@ -14,7 +14,6 @@ static void
 oauth2_request_callback(struct oauth2_request *req,
                        struct oauth2_request_result *res)
 {
-       i_assert(res->success == (res->error == NULL));
        i_assert(req->req_callback != NULL);
        oauth2_request_callback_t *callback = req->req_callback;
        req->req_callback = NULL;
@@ -29,7 +28,6 @@ oauth2_request_field_parse(const struct oauth2_field *field,
        if (strcasecmp(field->name, "expires_in") == 0) {
                uint32_t expires_in = 0;
                if (str_to_uint32(field->value, &expires_in) < 0) {
-                       res->success = FALSE;
                        res->error = t_strdup_printf(
                                "Malformed number '%s' in expires_in",
                                field->value);
@@ -39,7 +37,6 @@ oauth2_request_field_parse(const struct oauth2_field *field,
                }
        } else if (strcasecmp(field->name, "token_type") == 0) {
                if (strcasecmp(field->value, "bearer") != 0) {
-                       res->success = FALSE;
                        res->error = t_strdup_printf(
                                "Expected Bearer token, got '%s'",
                                field->value);
@@ -57,19 +54,19 @@ oauth2_request_continue(struct oauth2_request *req, const char *error)
 
        unsigned int status_hi = req->response_status/100;
 
-       res.success = error == NULL && (status_hi == 2 || status_hi == 4);
-       res.valid = error == NULL && (status_hi == 2);
-       res.error = error;
-
-       if (res.success) {
+       if (error != NULL)
+               res.error = error;
+       else if (status_hi != 2 && status_hi != 4)
+               res.error = "Internal Server Error";
+       else {
                const struct oauth2_field *field;
                /* see if we can figure out when it expires */
                array_foreach(&req->fields, field) {
                        if (!oauth2_request_field_parse(field, &res))
                                break;
                }
-       } else if (res.error == NULL)
-               res.error = "Internal Server Error";
+               res.valid = (status_hi == 2) && res.error == NULL;
+       }
 
        res.fields = &req->fields;
 
index b549f4cde432f2fd565b60466ef90297f882c3c0..e18bd35e2d29f54079e9ba713697c739cb95dc83 100644 (file)
@@ -56,13 +56,11 @@ struct oauth2_settings {
 struct oauth2_request_result {
        /* Oauth2 server response fields */
        ARRAY_TYPE(oauth2_field) *fields;
-       /* Error message */
+       /* Non-NULL if there was an unexpected internal error. */
        const char *error;
-       /* Request handled successfully */
-       bool success:1;
        /* timestamp token expires at */
        time_t expires_at;
-       /* User authenticated successfully */
+       /* User authenticated successfully. Implies that error==NULL. */
        bool valid:1;
 };