From 70cc2b56d1f67aee7d6485f4c339251d6eaca5aa Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 20 Nov 2018 23:00:58 +0100 Subject: [PATCH] http: rewrite again the access verification routines, fixes #5339 --- src/http.c | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/http.c b/src/http.c index 1f8551771..3a9a1a8d0 100644 --- a/src/http.c +++ b/src/http.c @@ -981,26 +981,26 @@ int http_access_verify(http_connection_t *hc, int mask) { struct http_verify_structure v; - int res = -1; - http_access_verify_ticket(hc); if (hc->hc_access) - res = access_verify2(hc->hc_access, mask); + return access_verify2(hc->hc_access, mask); - if (res) { - access_destroy(hc->hc_access); - if (http_verify_prepare(hc, &v)) { - hc->hc_access = NULL; - return -1; - } - hc->hc_access = access_get(hc->hc_peer, hc->hc_username, - http_verify_callback, &v); - http_verify_free(&v); - if (hc->hc_access) - res = access_verify2(hc->hc_access, mask); + http_access_verify_ticket(hc); + if (hc->hc_access && !access_verify2(hc->hc_access, mask)) + return 0; + + access_destroy(hc->hc_access); + if (http_verify_prepare(hc, &v)) { + hc->hc_access = NULL; + return -1; } + hc->hc_access = access_get(hc->hc_peer, hc->hc_username, + http_verify_callback, &v); + http_verify_free(&v); + if (hc->hc_access) + return access_verify2(hc->hc_access, mask); - return res; + return -1; } /** @@ -1010,20 +1010,12 @@ int http_access_verify_channel(http_connection_t *hc, int mask, struct channel *ch) { - int res = 0; - assert(ch); - if (hc->hc_access == NULL) { - res = http_access_verify(hc, mask); - if (res) - return res; - } - - if (!channel_access(ch, hc->hc_access, 0)) - res = -1; + if (http_access_verify(hc, mask)) + return -1; - return res; + return channel_access(ch, hc->hc_access, 0) ? 0 : -1; } /** -- 2.47.2