From beec9c1133647f94e42d43b6ee3d3672794eee19 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 11 Dec 2018 14:42:29 +0100 Subject: [PATCH] http: add auth type detection --- src/http.c | 14 ++++++++++++-- src/http.h | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/http.c b/src/http.c index af6521f75..098874305 100644 --- a/src/http.c +++ b/src/http.c @@ -936,6 +936,7 @@ http_access_verify_ticket(http_connection_t *hc) hc->hc_access = access_ticket_verify2(ticket_id, hc->hc_url); if (hc->hc_access == NULL) return; + hc->hc_auth_type = HC_AUTH_TICKET; tvhinfo(hc->hc_subsys, "%s: using ticket %s for %s", hc->hc_peer_ipstr, ticket_id, hc->hc_url); } @@ -952,6 +953,7 @@ http_access_verify_auth(http_connection_t *hc) hc->hc_access = access_get_by_auth(hc->hc_peer, auth_id); if (hc->hc_access == NULL) return; + hc->hc_auth_type = HC_AUTH_PERM; tvhinfo(hc->hc_subsys, "%s: using auth %s for %s", hc->hc_peer_ipstr, auth_id, hc->hc_url); } @@ -1081,6 +1083,7 @@ int http_access_verify(http_connection_t *hc, int mask) { struct http_verify_structure v; + int r; /* quick path */ if (hc->hc_access) @@ -1103,8 +1106,15 @@ http_access_verify(http_connection_t *hc, int mask) 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); + if (hc->hc_access) { + r = access_verify2(hc->hc_access, mask); + if (r == 0) { + if (!strempty(hc->hc_username)) + hc->hc_auth_type = hc->hc_authhdr ? HC_AUTH_DIGEST : HC_AUTH_PLAIN; + else + hc->hc_auth_type = HC_AUTH_ADDR; + } + } return -1; } diff --git a/src/http.h b/src/http.h index c07773223..e193717e9 100644 --- a/src/http.h +++ b/src/http.h @@ -171,6 +171,14 @@ typedef struct http_connection { char *hc_authhdr; char *hc_nonce; access_t *hc_access; + enum { + HC_AUTH_NONE, + HC_AUTH_ADDR, + HC_AUTH_PLAIN, + HC_AUTH_DIGEST, + HC_AUTH_TICKET, + HC_AUTH_PERM + } hc_auth_type; /* RTSP */ uint64_t hc_cseq; -- 2.47.2