From 3aebaf4c1340292baec0db8448e60af2079600c1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 13 Feb 2014 16:28:54 +0100 Subject: [PATCH] s4:librpc/rpc: set "localaddress" and reset "host" for ncacn_ip_tcp We should remember local and remote ip address in dcerpc_pipe->binding. Note: that we still have the "target_hostname" unmodified, if present. This way dcerpc_pipe->binding can be used to create a secondary connection that is a additional connection for the existing association group. Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- source4/librpc/rpc/dcerpc_connect.c | 18 ++++++++++++++++-- source4/librpc/rpc/dcerpc_secondary.c | 21 ++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/source4/librpc/rpc/dcerpc_connect.c b/source4/librpc/rpc/dcerpc_connect.c index 39ff941e771..88898857bf6 100644 --- a/source4/librpc/rpc/dcerpc_connect.c +++ b/source4/librpc/rpc/dcerpc_connect.c @@ -38,7 +38,7 @@ struct dcerpc_pipe_connect { struct dcecli_connection *conn; - const struct dcerpc_binding *binding; + struct dcerpc_binding *binding; const char *pipe_name; const struct ndr_interface_table *interface; struct cli_credentials *creds; @@ -344,9 +344,23 @@ static void continue_pipe_open_ncacn_ip_tcp(struct composite_context *ctx) { struct composite_context *c = talloc_get_type(ctx->async.private_data, struct composite_context); + struct pipe_ip_tcp_state *s = talloc_get_type(c->private_data, + struct pipe_ip_tcp_state); + char *localaddr = NULL; + char *remoteaddr = NULL; /* receive result of named pipe open request on tcp/ip */ - c->status = dcerpc_pipe_open_tcp_recv(ctx, NULL, NULL, NULL); + c->status = dcerpc_pipe_open_tcp_recv(ctx, s, &localaddr, &remoteaddr); + if (!composite_is_ok(c)) return; + + c->status = dcerpc_binding_set_string_option(s->io.binding, + "localaddress", + localaddr); + if (!composite_is_ok(c)) return; + + c->status = dcerpc_binding_set_string_option(s->io.binding, + "host", + remoteaddr); if (!composite_is_ok(c)) return; composite_done(c); diff --git a/source4/librpc/rpc/dcerpc_secondary.c b/source4/librpc/rpc/dcerpc_secondary.c index 8fc159867b3..a84f3e6b1e6 100644 --- a/source4/librpc/rpc/dcerpc_secondary.c +++ b/source4/librpc/rpc/dcerpc_secondary.c @@ -36,7 +36,7 @@ struct sec_conn_state { struct dcerpc_pipe *pipe; struct dcerpc_pipe *pipe2; - const struct dcerpc_binding *binding; + struct dcerpc_binding *binding; struct socket_address *peer_addr; const char *localaddress; }; @@ -75,7 +75,8 @@ _PUBLIC_ struct composite_context* dcerpc_secondary_connection_send(struct dcerp c->private_data = s; s->pipe = p; - s->binding = b; + s->binding = dcerpc_binding_dup(s, b); + if (composite_nomem(s->binding, c)) return c; /* initialise second dcerpc pipe based on primary pipe's event context */ s->pipe2 = dcerpc_pipe_init(c, s->pipe->conn->event_ctx); @@ -180,8 +181,22 @@ static void continue_open_tcp(struct composite_context *ctx) { struct composite_context *c = talloc_get_type(ctx->async.private_data, struct composite_context); + struct sec_conn_state *s = talloc_get_type_abort(c->private_data, + struct sec_conn_state); + char *localaddr = NULL; + char *remoteaddr = NULL; - c->status = dcerpc_pipe_open_tcp_recv(ctx, NULL, NULL, NULL); + c->status = dcerpc_pipe_open_tcp_recv(ctx, s, &localaddr, &remoteaddr); + if (!composite_is_ok(c)) return; + + c->status = dcerpc_binding_set_string_option(s->binding, + "localaddress", + localaddr); + if (!composite_is_ok(c)) return; + + c->status = dcerpc_binding_set_string_option(s->binding, + "host", + remoteaddr); if (!composite_is_ok(c)) return; continue_pipe_open(c);