s4:lib/http: pass down the target service/hostname to gensec
authorStefan Metzmacher <metze@samba.org>
Thu, 20 Jul 2017 14:11:48 +0000 (16:11 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 7 Aug 2017 13:20:02 +0000 (15:20 +0200)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/lib/http/http_auth.c

index 31f6a2b6307b8e31205eb5ef5d0cd8b665872f5f..f561c4968537a84f859417815de5cca91bd1fc3e 100644 (file)
@@ -118,6 +118,7 @@ struct tevent_req *http_send_auth_request_send(TALLOC_CTX *mem_ctx,
        struct tevent_req *subreq = NULL;
        DATA_BLOB gensec_in = data_blob_null;
        NTSTATUS status;
+       struct http_header *h = NULL;
        const char *mech_name = NULL;
 
        req = tevent_req_create(mem_ctx, &state, struct http_auth_state);
@@ -146,6 +147,26 @@ struct tevent_req *http_send_auth_request_send(TALLOC_CTX *mem_ctx,
                return tevent_req_post(req, ev);
        }
 
+       for (h = original_request->headers; h != NULL; h = h->next) {
+               int cmp;
+
+               cmp = strcasecmp(h->key, "Host");
+               if (cmp != 0) {
+                       continue;
+               }
+
+               status = gensec_set_target_service(state->gensec_ctx, "http");
+               if (tevent_req_nterror(req, status)) {
+                       return tevent_req_post(req, ev);
+               }
+
+               status = gensec_set_target_hostname(state->gensec_ctx, h->value);
+               if (tevent_req_nterror(req, status)) {
+                       return tevent_req_post(req, ev);
+               }
+               break;
+       }
+
        switch (state->auth) {
        case HTTP_AUTH_BASIC:
                mech_name = "http_basic";