r12135: Move named pipe connect on smb2 function to async implementation.
authorRafal Szczesniak <mimir@samba.org>
Fri, 9 Dec 2005 00:04:38 +0000 (00:04 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:47:12 +0000 (13:47 -0500)
Completely untested, it's a bit difficult without having vista
around (yet), so - Andrew, please test it and let me know what's
wrong.

rafal

source/librpc/rpc/dcerpc_connect.c
source/librpc/rpc/dcerpc_util.c

index 9af54740a2503cf23dfc7416f7cb95d042304c09..35a0602cbf3cb287abe038bdd3ccae16b233fbb2 100644 (file)
@@ -194,3 +194,121 @@ NTSTATUS dcerpc_pipe_connect_ncacn_np_smb(TALLOC_CTX *tmp_ctx,
        c = dcerpc_pipe_connect_ncacn_np_smb_send(tmp_ctx, io);
        return dcerpc_pipe_connect_ncacn_np_smb_recv(c);
 }
+
+
+struct pipe_np_smb2_state {
+       struct smb2_tree *tree;
+       struct dcerpc_pipe_connect io;
+};
+
+
+void continue_pipe_open_smb2(struct composite_context *ctx)
+{
+       struct composite_context *c = talloc_get_type(ctx->async.private_data,
+                                                     struct composite_context);
+       struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,
+                                                      struct pipe_np_smb2_state);
+
+       c->status = dcerpc_pipe_open_smb2_recv(ctx);
+       if (!NT_STATUS_IS_OK(c->status)) {
+               DEBUG(0,("Failed to open pipe %s - %s\n", s->io.pipe_name, nt_errstr(c->status)));
+               composite_error(c, c->status);
+               return;
+       }
+
+       composite_done(c);
+}
+
+
+void continue_smb2_connect(struct composite_context *ctx)
+{
+       struct composite_context *open_req;
+       struct composite_context *c = talloc_get_type(ctx->async.private_data,
+                                                     struct composite_context);
+       struct pipe_np_smb2_state *s = talloc_get_type(c->private_data,
+                                                      struct pipe_np_smb2_state);
+
+       c->status = smb2_connect_recv(ctx, c, &s->tree);
+       if (!NT_STATUS_IS_OK(c->status)) {
+               DEBUG(0,("Failed to connect to %s - %s\n", s->io.binding->host, nt_errstr(c->status)));
+               composite_error(c, c->status);
+               return;
+       }
+       
+       s->io.pipe_name = s->io.binding->endpoint;
+
+       open_req = dcerpc_pipe_open_smb2_send(s->io.pipe->conn, s->tree, s->io.pipe_name);
+       if (open_req == NULL) {
+               composite_error(c, NT_STATUS_NO_MEMORY);
+               return;
+       }
+
+       composite_continue(c, open_req, continue_pipe_open_smb2, c);
+}
+
+
+struct composite_context *dcerpc_pipe_connect_ncacn_np_smb2_send(TALLOC_CTX *mem_ctx,
+                                                                struct dcerpc_pipe_connect *io)
+{
+       struct composite_context *c;
+       struct pipe_np_smb2_state *s;
+       struct composite_context *conn_req;
+
+       c = talloc_zero(mem_ctx, struct composite_context);
+       if (c == NULL) return NULL;
+
+       s = talloc_zero(c, struct pipe_np_smb2_state);
+       if (s == NULL) {
+               composite_error(c, NT_STATUS_NO_MEMORY);
+               goto done;
+       }
+       
+       c->state = COMPOSITE_STATE_IN_PROGRESS;
+       c->private_data = s;
+       c->event_ctx = io->pipe->conn->event_ctx;
+
+       s->io = *io;
+
+       if (s->io.binding->flags & DCERPC_SCHANNEL) {
+               s->io.creds = cli_credentials_init(mem_ctx);
+               if (s->io.creds) {
+                       composite_error(c, NT_STATUS_NO_MEMORY);
+                       goto done;
+               }
+
+               cli_credentials_set_anonymous(s->io.creds);
+               cli_credentials_guess(s->io.creds);
+       }
+
+       conn_req = smb2_connect_send(mem_ctx, s->io.binding->host, "IPC$", s->io.creds,
+                                    c->event_ctx);
+       if (conn_req == NULL) {
+               composite_error(c, NT_STATUS_NO_MEMORY);
+               goto done;
+       }
+
+       composite_continue(c, conn_req, continue_smb2_connect, c);
+
+done:
+       return c;
+}
+
+
+NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2_recv(struct composite_context *c)
+{
+       NTSTATUS status = composite_wait(c);
+       
+       talloc_free(c);
+       return status;
+}
+
+
+/* open a rpc connection to a rpc pipe on SMB2 using the binding
+   structure to determine the endpoint and options */
+NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2(TALLOC_CTX *mem_ctx,
+                                          struct dcerpc_pipe_connect *io)
+{
+       struct composite_context *c;
+       c = dcerpc_pipe_connect_ncacn_np_smb2_send(mem_ctx, io);
+       return dcerpc_pipe_connect_ncacn_np_smb2_recv(c);
+}
index 732eade6946de39b621f20d69aef619cc7959def..72975461d009f687a7a853519bf8d083420ec260 100644 (file)
@@ -1016,59 +1016,19 @@ NTSTATUS dcerpc_pipe_auth(struct dcerpc_pipe *p,
 }
 
 
-/* open a rpc connection to a rpc pipe on SMB2 using the binding
-   structure to determine the endpoint and options */
-static NTSTATUS dcerpc_pipe_connect_ncacn_np_smb2(TALLOC_CTX *tmp_ctx, 
-                                                 struct dcerpc_pipe *p, 
-                                                 struct dcerpc_binding *binding,
-                                                 const char *pipe_uuid, 
-                                                 uint32_t pipe_version,
-                                                 struct cli_credentials *credentials)
-{
-       NTSTATUS status;
-       struct smb2_tree *tree;
-       const char *pipe_name = NULL;
-
-       if (binding->flags & DCERPC_SCHANNEL) {
-               credentials = cli_credentials_init(tmp_ctx);
-               cli_credentials_set_anonymous(credentials);
-               cli_credentials_guess(credentials);
-       }
-       status = smb2_connect(tmp_ctx, binding->host, "IPC$", credentials, &tree,
-                             p->conn->event_ctx);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0,("Failed to connect to %s - %s\n", 
-                        binding->host, nt_errstr(status)));
-               return status;
-       }
-
-       pipe_name = binding->endpoint;
-
-       status = dcerpc_pipe_open_smb2(p->conn, tree, pipe_name);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0,("Failed to open pipe %s - %s\n", pipe_name, nt_errstr(status)));
-               return status;
-       }
-
-       talloc_steal(p->conn, tree);
-
-       return NT_STATUS_OK;
-}
-
-
 /* open a rpc connection to a rpc pipe on SMB using the binding
    structure to determine the endpoint and options */
 static NTSTATUS dcerpc_pipe_connect_ncacn_np(TALLOC_CTX *tmp_ctx, 
                                             struct dcerpc_pipe_connect *io)
 {
        if (io->binding->flags & DCERPC_SMB2) {
-               return dcerpc_pipe_connect_ncacn_np_smb2(tmp_ctx, io->pipe, io->binding,
-                                                        io->pipe_uuid, io->pipe_version,
-                                                        io->creds);
+               return dcerpc_pipe_connect_ncacn_np_smb2(tmp_ctx, io);
+
        }
        return dcerpc_pipe_connect_ncacn_np_smb(tmp_ctx, io);
 }
 
+
 /* open a rpc connection to a rpc pipe on SMP using the binding
    structure to determine the endpoint and options */
 static NTSTATUS dcerpc_pipe_connect_ncalrpc(TALLOC_CTX *tmp_ctx,