#include "lib/events/events.h"
#include "librpc/rpc/dcerpc.h"
#include "librpc/rpc/dcerpc_proto.h"
+#include "libcli/smb/smbXcli_base.h"
#include "auth/credentials/credentials.h"
#include "param/param.h"
#include "libcli/resolve/resolve.h"
-#include "lib/socket/socket.h"
+#include "lib/util/util_net.h"
struct sec_conn_state {
struct dcerpc_pipe *pipe;
struct dcerpc_pipe *pipe2;
struct dcerpc_binding *binding;
- struct socket_address *peer_addr;
+ struct {
+ struct smbXcli_conn *conn;
+ struct smbXcli_session *session;
+ struct smbXcli_tcon *tcon;
+ } smb;
};
static void continue_open_smb(struct composite_context *ctx);
static void continue_open_tcp(struct composite_context *ctx);
-static void continue_open_pipe(struct composite_context *ctx);
+static void continue_open_ncalrpc(struct composite_context *ctx);
+static void continue_open_ncacn_unix(struct composite_context *ctx);
static void continue_pipe_open(struct composite_context *c);
connection
*/
_PUBLIC_ struct composite_context* dcerpc_secondary_connection_send(struct dcerpc_pipe *p,
- struct dcerpc_binding *b)
+ const struct dcerpc_binding *b)
{
struct composite_context *c;
struct sec_conn_state *s;
struct composite_context *pipe_smb_req;
struct composite_context *pipe_tcp_req;
+ const char *localaddress = NULL;
struct composite_context *pipe_ncalrpc_req;
-
+ const char *ncalrpc_dir = NULL;
+ struct composite_context *pipe_unix_req;
+ const char *host;
+ const char *target_hostname;
+ const char *endpoint;
+
/* composite context allocation and setup */
c = composite_create(p, p->conn->event_ctx);
if (c == NULL) return NULL;
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);
if (DEBUGLEVEL >= 10)
s->pipe2->conn->packet_log_dir = s->pipe->conn->packet_log_dir;
+ host = dcerpc_binding_get_string_option(s->binding, "host");
+ if (host == NULL) {
+ /*
+ * We may fallback to the host of the given connection
+ */
+ host = dcerpc_binding_get_string_option(s->pipe->binding,
+ "host");
+ }
+ target_hostname = dcerpc_binding_get_string_option(s->binding, "target_hostname");
+ if (target_hostname == NULL) {
+ /*
+ * We may fallback to the target_hostname of the given connection
+ */
+ target_hostname = dcerpc_binding_get_string_option(s->pipe->binding,
+ "target_hostname");
+ }
+ endpoint = dcerpc_binding_get_string_option(s->binding, "endpoint");
+ if (endpoint == NULL) {
+ /*
+ * We may fallback to the endpoint of the given connection
+ */
+ endpoint = dcerpc_binding_get_string_option(s->pipe->binding, "endpoint");
+ }
+ if (endpoint == NULL) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+ return c;
+ }
+
/* open second dcerpc pipe using the same transport as for primary pipe */
switch (s->pipe->conn->transport.transport) {
case NCACN_NP:
- pipe_smb_req = dcerpc_secondary_smb_send(s->pipe->conn, s->pipe2->conn,
- s->binding->endpoint);
+ c->status = dcerpc_binding_get_smbXcli_pointers(s->pipe->binding,
+ &s->smb.conn,
+ &s->smb.session,
+ &s->smb.tcon);
+ if (!NT_STATUS_IS_OK(c->status)) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+ return c;
+ }
+
+ pipe_smb_req = dcerpc_pipe_open_smb_send(s->pipe2->conn,
+ s->smb.conn,
+ s->smb.session,
+ s->smb.tcon,
+ DCERPC_REQUEST_TIMEOUT * 1000,
+ endpoint);
composite_continue(c, pipe_smb_req, continue_open_smb, c);
return c;
case NCACN_IP_TCP:
- s->peer_addr = dcerpc_socket_peer_addr(s->pipe->conn, s);
- if (!s->peer_addr) {
- composite_error(c, NT_STATUS_INVALID_PARAMETER);
+ if (host == NULL) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
return c;
}
+ if (!is_ipaddress(host)) {
+ /*
+ * We may fallback to the host of the given connection
+ */
+ host = dcerpc_binding_get_string_option(s->pipe->binding,
+ "host");
+ if (host == NULL) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+ return c;
+ }
+ if (!is_ipaddress(host)) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+ return c;
+ }
+ }
+
+ localaddress = dcerpc_binding_get_string_option(s->binding,
+ "localaddress");
+ if (localaddress == NULL) {
+ /*
+ * We may fallback to the localaddress of the given connection
+ */
+ localaddress = dcerpc_binding_get_string_option(s->pipe->binding,
+ "localaddress");
+ }
+
pipe_tcp_req = dcerpc_pipe_open_tcp_send(s->pipe2->conn,
- s->binding->localaddress,
- s->peer_addr->addr,
- s->binding->target_hostname,
- atoi(s->binding->endpoint),
+ localaddress,
+ host,
+ target_hostname,
+ atoi(endpoint),
resolve_context_init(s));
composite_continue(c, pipe_tcp_req, continue_open_tcp, c);
return c;
case NCALRPC:
+ ncalrpc_dir = dcerpc_binding_get_string_option(s->binding,
+ "ncalrpc_dir");
+ if (ncalrpc_dir == NULL) {
+ ncalrpc_dir = dcerpc_binding_get_string_option(s->pipe->binding,
+ "ncalrpc_dir");
+ }
+ if (ncalrpc_dir == NULL) {
+ composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+ return c;
+ }
+
+ pipe_ncalrpc_req = dcerpc_pipe_open_pipe_send(s->pipe2->conn,
+ ncalrpc_dir,
+ endpoint);
+ composite_continue(c, pipe_ncalrpc_req, continue_open_ncalrpc, c);
+ return c;
+
case NCACN_UNIX_STREAM:
- pipe_ncalrpc_req = dcerpc_pipe_open_unix_stream_send(s->pipe2->conn,
- dcerpc_unix_socket_path(s->pipe->conn));
- composite_continue(c, pipe_ncalrpc_req, continue_open_pipe, c);
+ pipe_unix_req = dcerpc_pipe_open_unix_stream_send(s->pipe2->conn,
+ endpoint);
+ composite_continue(c, pipe_unix_req, continue_open_ncacn_unix, c);
return c;
default:
{
struct composite_context *c = talloc_get_type(ctx->async.private_data,
struct composite_context);
-
- c->status = dcerpc_secondary_smb_recv(ctx);
+ struct sec_conn_state *s = talloc_get_type_abort(c->private_data,
+ struct sec_conn_state);
+
+ c->status = dcerpc_pipe_open_smb_recv(ctx);
+ if (!composite_is_ok(c)) return;
+
+ c->status = dcerpc_binding_set_smbXcli_pointers(s->binding,
+ s->smb.conn,
+ s->smb.session,
+ s->smb.tcon);
if (!composite_is_ok(c)) return;
continue_pipe_open(c);
{
struct composite_context *c = talloc_get_type(ctx->async.private_data,
struct composite_context);
-
- c->status = dcerpc_pipe_open_tcp_recv(ctx);
+ 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, 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);
}
-
/*
Stage 2 of secondary_connection: Receive result of pipe open request on ncalrpc
*/
-static void continue_open_pipe(struct composite_context *ctx)
+static void continue_open_ncalrpc(struct composite_context *ctx)
{
struct composite_context *c = talloc_get_type(ctx->async.private_data,
struct composite_context);
continue_pipe_open(c);
}
+/*
+ Stage 2 of secondary_connection: Receive result of pipe open request on ncacn_unix
+*/
+static void continue_open_ncacn_unix(struct composite_context *ctx)
+{
+ struct composite_context *c = talloc_get_type(ctx->async.private_data,
+ struct composite_context);
+
+ c->status = dcerpc_pipe_open_unix_stream_recv(ctx);
+ if (!composite_is_ok(c)) return;
+
+ continue_pipe_open(c);
+}
+
/*
Stage 3 of secondary_connection: Get binding data and flags from primary pipe
s = talloc_get_type(c->private_data, struct sec_conn_state);
s->pipe2->conn->flags = s->pipe->conn->flags;
- s->pipe2->binding = dcerpc_binding_dup(s->pipe2, s->binding);
- if (composite_nomem(s->pipe2->binding, c)) {
- return;
- }
+ s->pipe2->binding = talloc_move(s->pipe2, &s->binding);
composite_done(c);
}
return status;
}
-/*
- Create a secondary dcerpc connection from a primary connection
- - sync version
-
- If the primary is a SMB connection then the secondary connection
- will be on the same SMB connection, but using a new fnum
-*/
-_PUBLIC_ NTSTATUS dcerpc_secondary_connection(struct dcerpc_pipe *p,
- struct dcerpc_pipe **p2,
- struct dcerpc_binding *b)
-{
- struct composite_context *c;
-
- c = dcerpc_secondary_connection_send(p, b);
- return dcerpc_secondary_connection_recv(c, p2);
-}
-
/*
Create a secondary DCERPC connection, then bind (and possibly
authenticate) using the supplied credentials.
*/
struct sec_auth_conn_state {
struct dcerpc_pipe *pipe2;
- struct dcerpc_binding *binding;
+ const struct dcerpc_binding *binding;
const struct ndr_interface_table *table;
struct cli_credentials *credentials;
struct composite_context *ctx;
static void dcerpc_secondary_auth_connection_continue(struct composite_context *ctx);
_PUBLIC_ struct composite_context* dcerpc_secondary_auth_connection_send(struct dcerpc_pipe *p,
- struct dcerpc_binding *binding,
+ const struct dcerpc_binding *binding,
const struct ndr_interface_table *table,
struct cli_credentials *credentials,
struct loadparm_context *lp_ctx)
talloc_free(c);
return status;
}
+
+_PUBLIC_ NTSTATUS dcerpc_secondary_auth_connection(struct dcerpc_pipe *p,
+ const struct dcerpc_binding *binding,
+ const struct ndr_interface_table *table,
+ struct cli_credentials *credentials,
+ struct loadparm_context *lp_ctx,
+ TALLOC_CTX *mem_ctx,
+ struct dcerpc_pipe **p2)
+{
+ struct composite_context *c;
+
+ c = dcerpc_secondary_auth_connection_send(p, binding, table,
+ credentials, lp_ctx);
+ return dcerpc_secondary_auth_connection_recv(c, mem_ctx, p2);
+}