Fix the build.
[jra/samba/.git] / source4 / librpc / rpc / dcerpc_connect.c
index 63fd25dd1abd88750d7f3e1da34b3e32a8aea5b9..32485f5653f30b8274db7383535974a7326be7c2 100644 (file)
@@ -30,6 +30,7 @@
 #include "libcli/smb2/smb2.h"
 #include "libcli/smb2/smb2_calls.h"
 #include "librpc/rpc/dcerpc.h"
+#include "librpc/rpc/dcerpc_proto.h"
 #include "auth/credentials/credentials.h"
 #include "param/param.h"
 #include "libcli/resolve/resolve.h"
@@ -89,8 +90,7 @@ static void continue_smb_connect(struct composite_context *ctx)
   Initiate async open of a rpc connection to a rpc pipe on SMB using
   the binding structure to determine the endpoint and options
 */
-static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *mem_ctx, 
-                                                               struct dcerpc_pipe_connect *io)
+static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CTX *mem_ctx, struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx)
 {
        struct composite_context *c;
        struct pipe_np_smb_state *s;
@@ -111,14 +111,20 @@ static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CT
        /* prepare smb connection parameters: we're connecting to IPC$ share on
           remote rpc server */
        conn->in.dest_host              = s->io.binding->host;
-       conn->in.dest_ports                  = lp_smb_ports(global_loadparm);
+       conn->in.dest_ports                  = lp_smb_ports(lp_ctx);
        if (s->io.binding->target_hostname == NULL)
                conn->in.called_name = "*SMBSERVER"; /* FIXME: This is invalid */
        else
                conn->in.called_name            = s->io.binding->target_hostname;
+       conn->in.socket_options         = lp_socket_options(lp_ctx);
        conn->in.service                = "IPC$";
        conn->in.service_type           = NULL;
-       conn->in.workgroup              = lp_workgroup(global_loadparm);
+       conn->in.workgroup              = lp_workgroup(lp_ctx);
+       conn->in.gensec_settings = lp_gensec_settings(conn, lp_ctx);
+       conn->in.iconv_convenience = lp_iconv_convenience(lp_ctx);
+
+       lp_smbcli_options(lp_ctx, &conn->in.options);
+       lp_smbcli_session_options(lp_ctx, &conn->in.session_options);
 
        /*
         * provide proper credentials - user supplied, but allow a
@@ -134,7 +140,9 @@ static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb_send(TALLOC_CT
        }
 
        /* send smb connect request */
-       conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, s->io.pipe->conn->event_ctx);
+       conn_req = smb_composite_connect_send(conn, s->io.pipe->conn, 
+                                             s->io.resolve_ctx,
+                                             s->io.pipe->conn->event_ctx);
        if (composite_nomem(conn_req, c)) return c;
 
        composite_continue(c, conn_req, continue_smb_connect, c);
@@ -208,11 +216,13 @@ static void continue_smb2_connect(struct composite_context *ctx)
 */
 static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(
                                        TALLOC_CTX *mem_ctx,
-                                       struct dcerpc_pipe_connect *io)
+                                       struct dcerpc_pipe_connect *io,
+                                       struct loadparm_context *lp_ctx)
 {
        struct composite_context *c;
        struct pipe_np_smb2_state *s;
        struct composite_context *conn_req;
+       struct smbcli_options options;
 
        /* composite context allocation and setup */
        c = composite_create(mem_ctx, io->pipe->conn->event_ctx);
@@ -232,14 +242,22 @@ static struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(
                s->io.creds = cli_credentials_init(mem_ctx);
                if (composite_nomem(s->io.creds, c)) return c;
 
-               cli_credentials_guess(s->io.creds, global_loadparm);
+               cli_credentials_guess(s->io.creds, lp_ctx);
        }
 
+       lp_smbcli_options(lp_ctx, &options);
+
        /* send smb2 connect request */
-       conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, "IPC$", 
+       conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, 
+                       lp_parm_string_list(mem_ctx, lp_ctx, NULL, "smb2", "ports", NULL),
+                                       "IPC$", 
                                     s->io.resolve_ctx,
                                     s->io.creds,
-                                    c->event_ctx);
+                                    c->event_ctx,
+                                    &options,
+                                        lp_socket_options(lp_ctx),
+                                        lp_gensec_settings(mem_ctx, lp_ctx)
+                                        );
        composite_continue(c, conn_req, continue_smb2_connect, c);
        return c;
 }
@@ -427,7 +445,7 @@ static void continue_pipe_open_ncalrpc(struct composite_context *ctx)
    the binding structure to determine the endpoint and options
 */
 static struct composite_context* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX *mem_ctx,
-                                                                 struct dcerpc_pipe_connect *io)
+                                                                 struct dcerpc_pipe_connect *io, struct loadparm_context *lp_ctx)
 {
        struct composite_context *c;
        struct pipe_ncalrpc_state *s;
@@ -445,7 +463,7 @@ static struct composite_context* dcerpc_pipe_connect_ncalrpc_send(TALLOC_CTX *me
        s->io  = *io;
 
        /* send pipe open request */
-       pipe_req = dcerpc_pipe_open_pipe_send(s->io.pipe->conn, lp_ncalrpc_dir(global_loadparm), 
+       pipe_req = dcerpc_pipe_open_pipe_send(s->io.pipe->conn, lp_ncalrpc_dir(lp_ctx), 
                                              s->io.binding->endpoint);
        composite_continue(c, pipe_req, continue_pipe_open_ncalrpc, c);
        return c;
@@ -522,20 +540,20 @@ static void continue_connect(struct composite_context *c, struct pipe_connect_st
        pc.binding      = s->binding;
        pc.interface    = s->table;
        pc.creds        = s->credentials;
-       pc.resolve_ctx  = lp_resolve_context(global_loadparm);
+       pc.resolve_ctx  = lp_resolve_context(s->lp_ctx);
 
        /* connect dcerpc pipe depending on required transport */
        switch (s->binding->transport) {
        case NCACN_NP:
                if (pc.binding->flags & DCERPC_SMB2) {
                        /* new varient of SMB a.k.a. SMB2 */
-                       ncacn_np_smb2_req = dcerpc_pipe_connect_ncacn_np_smb2_send(c, &pc);
+                       ncacn_np_smb2_req = dcerpc_pipe_connect_ncacn_np_smb2_send(c, &pc, s->lp_ctx);
                        composite_continue(c, ncacn_np_smb2_req, continue_pipe_connect_ncacn_np_smb2, c);
                        return;
 
                } else {
                        /* good old ordinary SMB */
-                       ncacn_np_smb_req = dcerpc_pipe_connect_ncacn_np_smb_send(c, &pc);
+                       ncacn_np_smb_req = dcerpc_pipe_connect_ncacn_np_smb_send(c, &pc, s->lp_ctx);
                        composite_continue(c, ncacn_np_smb_req, continue_pipe_connect_ncacn_np_smb, c);
                        return;
                }
@@ -552,7 +570,7 @@ static void continue_connect(struct composite_context *c, struct pipe_connect_st
                return;
 
        case NCALRPC:
-               ncalrpc_req = dcerpc_pipe_connect_ncalrpc_send(c, &pc);
+               ncalrpc_req = dcerpc_pipe_connect_ncalrpc_send(c, &pc, s->lp_ctx);
                composite_continue(c, ncalrpc_req, continue_pipe_connect_ncalrpc, c);
                return;
 
@@ -701,7 +719,7 @@ static void dcerpc_connect_timeout_handler(struct event_context *ev, struct time
   start a request to open a rpc connection to a rpc pipe, using
   specified binding structure to determine the endpoint and options
 */
-struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
+_PUBLIC_ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
                                                     struct dcerpc_binding *binding,
                                                     const struct ndr_interface_table *table,
                                                     struct cli_credentials *credentials,
@@ -712,12 +730,6 @@ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
        struct pipe_connect_state *s;
        struct event_context *new_ev = NULL;
 
-       if (ev == NULL) {
-               new_ev = event_context_init(parent_ctx);
-               if (new_ev == NULL) return NULL;
-               ev = new_ev;
-       }
-
        /* composite context allocation and setup */
        c = composite_create(parent_ctx, ev);
        if (c == NULL) {
@@ -734,6 +746,9 @@ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
        s->pipe = dcerpc_pipe_init(c, ev, lp_iconv_convenience(lp_ctx));
        if (composite_nomem(s->pipe, c)) return c;
 
+       if (DEBUGLEVEL >= 10)
+               s->pipe->conn->packet_log_dir = lp_lockdir(lp_ctx);
+
        /* store parameters in state structure */
        s->binding      = binding;
        s->table        = table;
@@ -778,7 +793,7 @@ struct composite_context* dcerpc_pipe_connect_b_send(TALLOC_CTX *parent_ctx,
 /*
   receive result of a request to open a rpc connection to a rpc pipe
 */
-NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
+_PUBLIC_ NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
                                    struct dcerpc_pipe **p)
 {
        NTSTATUS status;
@@ -800,7 +815,7 @@ NTSTATUS dcerpc_pipe_connect_b_recv(struct composite_context *c, TALLOC_CTX *mem
   open a rpc connection to a rpc pipe, using the specified 
   binding structure to determine the endpoint and options - sync version
 */
-NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
+_PUBLIC_ NTSTATUS dcerpc_pipe_connect_b(TALLOC_CTX *parent_ctx,
                               struct dcerpc_pipe **pp,
                               struct dcerpc_binding *binding,
                               const struct ndr_interface_table *table,
@@ -829,7 +844,7 @@ static void continue_pipe_connect_b(struct composite_context *ctx);
   binding to determine the endpoint and options.
   The string is to be parsed to a binding structure first.
 */
-struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
+_PUBLIC_ struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
                                                   const char *binding,
                                                   const struct ndr_interface_table *table,
                                                   struct cli_credentials *credentials,
@@ -839,21 +854,12 @@ struct composite_context* dcerpc_pipe_connect_send(TALLOC_CTX *parent_ctx,
        struct pipe_conn_state *s;
        struct dcerpc_binding *b;
        struct composite_context *pipe_conn_req;
-       struct event_context *new_ev = NULL;
-
-       if (ev == NULL) {
-               new_ev = event_context_init(parent_ctx);
-               if (new_ev == NULL) return NULL;
-               ev = new_ev;
-       }
 
        /* composite context allocation and setup */
        c = composite_create(parent_ctx, ev);
        if (c == NULL) {
-               talloc_free(new_ev);
                return NULL;
        }
-       talloc_steal(c, new_ev);
 
        s = talloc_zero(c, struct pipe_conn_state);
        if (composite_nomem(s, c)) return c;
@@ -924,7 +930,7 @@ NTSTATUS dcerpc_pipe_connect_recv(struct composite_context *c,
   Open a rpc connection to a rpc pipe, using the specified string
   binding to determine the endpoint and options - sync version
 */
-NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
+_PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, 
                             struct dcerpc_pipe **pp, 
                             const char *binding,
                             const struct ndr_interface_table *table,