diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-11-04 19:22:53 +0100 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-12-19 18:24:26 +0100 |
commit | fcbe8f0c80e3848e87d37476a46c7eb553d592c1 (patch) | |
tree | 6e63d1b2086a410f99454c25d9d49a64659f0c03 /source4/kdc | |
parent | 4dc958c7c8cff9044b86e59b9ea8165ee1847aad (diff) | |
download | samba-fcbe8f0c80e3848e87d37476a46c7eb553d592c1.tar.gz samba-fcbe8f0c80e3848e87d37476a46c7eb553d592c1.tar.bz2 samba-fcbe8f0c80e3848e87d37476a46c7eb553d592c1.zip |
s4:kdc: setup the local and remote tsocket_address at accept time
metze
Diffstat (limited to 'source4/kdc')
-rw-r--r-- | source4/kdc/kdc.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/source4/kdc/kdc.c b/source4/kdc/kdc.c index 2ee14f551d..2c07f89f17 100644 --- a/source4/kdc/kdc.c +++ b/source4/kdc/kdc.c @@ -71,11 +71,12 @@ struct kdc_tcp_connection { struct stream_connection *conn; /* the kdc_server the connection belongs to */ - struct kdc_server *kdc; + struct kdc_socket *kdc_socket; - struct packet_context *packet; + struct tsocket_address *local_address; + struct tsocket_address *remote_address; - kdc_process_fn_t process; + struct packet_context *packet; }; static void kdc_tcp_terminate_connection(struct kdc_tcp_connection *kdcconn, const char *reason) @@ -94,49 +95,18 @@ static NTSTATUS kdc_tcp_recv(void *private_data, DATA_BLOB blob) TALLOC_CTX *tmp_ctx = talloc_new(kdcconn); int ret; DATA_BLOB input, reply; - struct socket_address *src_addr; - struct socket_address *my_addr; - struct tsocket_address *tsrcaddr; - struct tsocket_address *tmyaddr; - talloc_steal(tmp_ctx, blob.data); - src_addr = socket_get_peer_addr(kdcconn->conn->socket, tmp_ctx); - if (!src_addr) { - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - my_addr = socket_get_my_addr(kdcconn->conn->socket, tmp_ctx); - if (!my_addr) { - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - ret = tsocket_address_bsd_from_sockaddr(tmp_ctx, src_addr->sockaddr, - src_addr->sockaddrlen, &tsrcaddr); - if (ret < 0) { - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - - ret = tsocket_address_bsd_from_sockaddr(tmp_ctx, my_addr->sockaddr, - my_addr->sockaddrlen, &tmyaddr); - if (ret < 0) { - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - /* Call krb5 */ input = data_blob_const(blob.data + 4, blob.length - 4); - ret = kdcconn->process(kdcconn->kdc, - tmp_ctx, - &input, - &reply, - tsrcaddr, - tmyaddr, - 0 /* Not datagram */); + ret = kdcconn->kdc_socket->process(kdcconn->kdc_socket->kdc, + tmp_ctx, + &input, + &reply, + kdcconn->remote_address, + kdcconn->local_address, + 0 /* Not datagram */); if (!ret) { talloc_free(tmp_ctx); return NT_STATUS_INTERNAL_ERROR; @@ -254,17 +224,52 @@ static void kdc_tcp_accept(struct stream_connection *conn) { struct kdc_socket *kdc_socket = talloc_get_type(conn->private_data, struct kdc_socket); struct kdc_tcp_connection *kdcconn; + struct socket_address *src_addr; + struct socket_address *my_addr; + int ret; kdcconn = talloc_zero(conn, struct kdc_tcp_connection); if (!kdcconn) { stream_terminate_connection(conn, "kdc_tcp_accept: out of memory"); return; } - kdcconn->conn = conn; - kdcconn->kdc = kdc_socket->kdc; - kdcconn->process = kdc_socket->process; + kdcconn->conn = conn; + kdcconn->kdc_socket = kdc_socket; conn->private_data = kdcconn; + src_addr = socket_get_peer_addr(kdcconn->conn->socket, kdcconn); + if (!src_addr) { + kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory"); + return; + } + + my_addr = socket_get_my_addr(kdcconn->conn->socket, kdcconn); + if (!my_addr) { + kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory"); + return; + } + + ret = tsocket_address_bsd_from_sockaddr(kdcconn, + src_addr->sockaddr, + src_addr->sockaddrlen, + &kdcconn->remote_address); + if (ret < 0) { + kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory"); + return; + } + + ret = tsocket_address_bsd_from_sockaddr(kdcconn, + my_addr->sockaddr, + my_addr->sockaddrlen, + &kdcconn->local_address); + if (ret < 0) { + kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory"); + return; + } + + TALLOC_FREE(src_addr); + TALLOC_FREE(my_addr); + kdcconn->packet = packet_init(kdcconn); if (kdcconn->packet == NULL) { kdc_tcp_terminate_connection(kdcconn, "kdc_tcp_accept: out of memory"); |