From ebb0b35242f5c2967afdba9e746679bc87c5b745 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 27 May 2005 11:57:14 +0000 Subject: r7013: added tls support to the builtin web server. It auto-detects if the client is using tls by looking at the first byte on the connection. This allows both https and http services to be on the same port (This used to be commit 6369dfb6585ce4d4e3028c557395f2d73c290c92) --- source4/web_server/web_server.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source4/web_server/web_server.c') diff --git a/source4/web_server/web_server.c b/source4/web_server/web_server.c index 9bbf423d29..faa30fc55f 100644 --- a/source4/web_server/web_server.c +++ b/source4/web_server/web_server.c @@ -68,7 +68,7 @@ static void websrv_recv(struct stream_connection *conn, uint16_t flags) DATA_BLOB b; /* not the most efficient http parser ever, but good enough for us */ - status = socket_recv(conn->socket, buf, sizeof(buf), &nread, 0); + status = tls_socket_recv(web, buf, sizeof(buf), &nread); if (NT_STATUS_IS_ERR(status)) goto failed; if (!NT_STATUS_IS_OK(status)) return; @@ -128,7 +128,7 @@ static void websrv_send(struct stream_connection *conn, uint16_t flags) b.data += web->output.nsent; b.length -= web->output.nsent; - status = socket_send(conn->socket, &b, &nsent, 0); + status = tls_socket_send(web, &b, &nsent); if (NT_STATUS_IS_ERR(status)) { stream_terminate_connection(web->conn, "socket_send: failed"); return; @@ -159,7 +159,8 @@ static void websrv_send(struct stream_connection *conn, uint16_t flags) web->output.content = data_blob_talloc(web, buf, nread); } - if (web->output.content.length == web->output.nsent) { + if (web->output.content.length == web->output.nsent && + web->output.fd == -1) { stream_terminate_connection(web->conn, NULL); } } @@ -171,6 +172,7 @@ static void websrv_accept(struct stream_connection *conn) { struct task_server *task = talloc_get_type(conn->private, struct task_server); struct websrv_context *web; + NTSTATUS status; web = talloc_zero(conn, struct websrv_context); if (web == NULL) goto failed; @@ -184,6 +186,10 @@ static void websrv_accept(struct stream_connection *conn) event_add_timed(conn->event.ctx, web, timeval_current_ofs(HTTP_TIMEOUT, 0), websrv_timeout, web); + + status = tls_init_connection(web); + if (!NT_STATUS_IS_OK(status)) goto failed; + return; failed: @@ -235,6 +241,8 @@ static void websrv_task_init(struct task_server *task) status = http_setup_esp(task); if (!NT_STATUS_IS_OK(status)) goto failed; + tls_initialise(task); + return; failed: -- cgit