Actually connect to RPC.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 15 Apr 2008 16:24:11 +0000 (18:24 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 17 Apr 2008 08:58:10 +0000 (10:58 +0200)
(This used to be commit 3082534454ff936ac0b78b5a2c72c9b060e21244)

source3/librpc/rpc/dcerpc.c
source3/librpc/rpc/dcerpc.h
source3/rpc_parse/parse_rpc.c

index 7609757417a2403cb1ad2aa477a2da7ed92689b4..f297c7200ee2096575761bfeaecb808d245d060d 100644 (file)
@@ -74,7 +74,7 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
 
        prs_init_empty( &r_ps, req, UNMARSHALL );
 
-       status = rpc_api_pipe_req(req->pipe->cli, req->opnum, &req->q_ps, &r_ps); 
+       status = rpc_api_pipe_req(req->pipe->rpc_cli, req->opnum, &req->q_ps, &r_ps); 
 
        prs_mem_free( &req->q_ps );
 
@@ -104,8 +104,6 @@ NTSTATUS dcerpc_ndr_request_recv(struct rpc_request *req)
                return ndr_map_error2ntstatus(ndr_err);
        }
 
-
-
        return NT_STATUS_NOT_IMPLEMENTED;
 }
 
@@ -117,14 +115,23 @@ _PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, struct dcerpc_pipe
        struct dcerpc_pipe *p = talloc(parent_ctx, struct dcerpc_pipe);
        struct dcerpc_binding *binding;
        NTSTATUS nt_status;
+       int idx;
+       RPC_IFACE iface_syntax;
 
        nt_status = dcerpc_parse_binding(p, binding_string, &binding);
 
        if (NT_STATUS_IS_ERR(nt_status)) {
-               DEBUG(1, ("Unable to parse binding string '%s'", binding));
+               DEBUG(1, ("Unable to parse binding string '%s'", binding_string));
+               talloc_free(p);
                return nt_status;
        }
 
+       if (binding->transport != NCACN_NP) {
+               DEBUG(0, ("Only ncacn_np supported"));
+               talloc_free(p);
+               return NT_STATUS_NOT_SUPPORTED;
+       }
+
        /* FIXME: Actually use loadparm_context.. */
 
        /* FIXME: actually use credentials */
@@ -138,6 +145,28 @@ _PUBLIC_ NTSTATUS dcerpc_pipe_connect(TALLOC_CTX *parent_ctx, struct dcerpc_pipe
                                        get_cmdline_auth_info_use_kerberos() ? CLI_FULL_CONNECTION_USE_KERBEROS : 0,
                                        get_cmdline_auth_info_signing_state(), NULL);
 
+       if (NT_STATUS_IS_ERR(nt_status)) {
+               talloc_free(p);
+               return nt_status;
+       }
+
+       iface_syntax.uuid = table->syntax_id.uuid;
+       iface_syntax.version = table->syntax_id.if_version;
+
+       idx = cli_get_pipe_idx(&iface_syntax);
+       if (idx < 0) {
+               DEBUG(0, ("Unable to find interface index"));
+               talloc_free(p);
+               return NT_STATUS_OBJECT_PATH_INVALID;
+       }
+
+       p->rpc_cli = cli_rpc_pipe_open_noauth(p->cli, idx, &nt_status);
+
+       if (p->rpc_cli == NULL) {
+               talloc_free(p);
+               return nt_status;
+       }
+
        p->table = table;
 
        *pp = p;
index 9e2bd9b4f6288d55ee4c2a124d813afd6b14152d..a225f821895e7e89c5f351cd60bd3914a8eb4585 100644 (file)
@@ -35,7 +35,8 @@ struct cli_credentials;
 
 struct dcerpc_pipe {
        const struct ndr_interface_table *table;
-       struct rpc_pipe_client *cli;
+       struct cli_state *cli;
+       struct rpc_pipe_client *rpc_cli;
 };
 
 struct rpc_request {
index 268bee7e516b3a921a714634ed84ec292b71bd95..9eeae176c715ea042923734692446bf65f4c0381 100644 (file)
@@ -234,6 +234,21 @@ const char *cli_get_pipe_name(int pipe_idx)
        return &pipe_names[pipe_idx].client_pipe[5];
 }
 
+/****************************************************************************
+ Return the pipe idx from the syntax.
+ ****************************************************************************/
+int cli_get_pipe_idx(const RPC_IFACE *syntax)
+{
+       int i;
+       for (i = 0; pipe_names[i].client_pipe; i++) {
+               if (GUID_equal(&pipe_names[i].abstr_syntax.uuid, &syntax->uuid) &&
+                   pipe_names[i].abstr_syntax.version == syntax->version)
+                       return i;
+       }
+
+       return -1;
+}
+
 /*******************************************************************
  Inits an RPC_HDR structure.
 ********************************************************************/