]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http: add auth type detection
authorJaroslav Kysela <perex@perex.cz>
Tue, 11 Dec 2018 13:42:29 +0000 (14:42 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 11 Dec 2018 13:42:29 +0000 (14:42 +0100)
src/http.c
src/http.h

index af6521f7572dbbd451ce30b97e1d5ff82af7f809..09887430592591505882a8ee2884f2f7c40c7dbe 100644 (file)
@@ -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;
 }
index c07773223cde4a0a0789bb175e1a794b05157868..e193717e94f82c3ca5bf6cf0ecd30fb2fcb0926e 100644 (file)
@@ -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;