s3-schannel: Fix Bug #6697. Interdomain trusts with Windows 2008 R2 DCs.
[ira/wip.git] / source3 / rpc_client / cli_pipe.c
index 2832a6d1c3a7c114e152cf7ea0633fd0097d709a..5af2c95811fb2c06728dc6586a2f36a8ae5a0638 100644 (file)
@@ -56,7 +56,7 @@ static const struct pipe_id_info {
        /* the names appear not to matter: the syntaxes _do_ matter */
 
        const char *client_pipe;
-       const RPC_IFACE *abstr_syntax; /* this one is the abstract syntax id */
+       const struct ndr_syntax_id *abstr_syntax; /* this one is the abstract syntax id */
 } pipe_names [] =
 {
        { PIPE_LSARPC,          &ndr_table_lsarpc.syntax_id },
@@ -681,7 +681,7 @@ static NTSTATUS cli_pipe_verify_schannel(struct rpc_pipe_client *cli, RPC_HDR *p
                return NT_STATUS_OK;
        }
 
-       if (auth_len != RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN) {
+       if (auth_len < RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN) {
                DEBUG(0,("cli_pipe_verify_schannel: auth_len %u.\n", (unsigned int)auth_len ));
                return NT_STATUS_INVALID_PARAMETER;
        }
@@ -1649,8 +1649,8 @@ static NTSTATUS create_schannel_auth_rpc_bind_req( struct rpc_pipe_client *cli,
 static NTSTATUS create_bind_or_alt_ctx_internal(enum RPC_PKT_TYPE pkt_type,
                                                prs_struct *rpc_out, 
                                                uint32 rpc_call_id,
-                                               const RPC_IFACE *abstract,
-                                               const RPC_IFACE *transfer,
+                                               const struct ndr_syntax_id *abstract,
+                                               const struct ndr_syntax_id *transfer,
                                                RPC_HDR_AUTH *phdr_auth,
                                                prs_struct *pauth_info)
 {
@@ -1731,8 +1731,8 @@ static NTSTATUS create_bind_or_alt_ctx_internal(enum RPC_PKT_TYPE pkt_type,
 static NTSTATUS create_rpc_bind_req(struct rpc_pipe_client *cli,
                                prs_struct *rpc_out, 
                                uint32 rpc_call_id,
-                               const RPC_IFACE *abstract,
-                               const RPC_IFACE *transfer,
+                               const struct ndr_syntax_id *abstract,
+                               const struct ndr_syntax_id *transfer,
                                enum pipe_auth_type auth_type,
                                enum pipe_auth_level auth_level)
 {
@@ -2284,39 +2284,6 @@ NTSTATUS rpc_api_pipe_req_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
        return NT_STATUS_OK;
 }
 
-NTSTATUS rpc_api_pipe_req(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *cli,
-                       uint8 op_num,
-                       prs_struct *in_data,
-                       prs_struct *out_data)
-{
-       TALLOC_CTX *frame = talloc_stackframe();
-       struct event_context *ev;
-       struct tevent_req *req;
-       NTSTATUS status = NT_STATUS_OK;
-
-       ev = event_context_init(frame);
-       if (ev == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto fail;
-       }
-
-       req = rpc_api_pipe_req_send(frame, ev, cli, op_num, in_data);
-       if (req == NULL) {
-               status = NT_STATUS_NO_MEMORY;
-               goto fail;
-       }
-
-       if (!tevent_req_poll(req, ev)) {
-               status = map_nt_error_from_unix(errno);
-               goto fail;
-       }
-
-       status = rpc_api_pipe_req_recv(req, mem_ctx, out_data);
- fail:
-       TALLOC_FREE(frame);
-       return status;
-}
-
 #if 0
 /****************************************************************************
  Set the handle state.
@@ -2368,7 +2335,8 @@ static bool rpc_pipe_set_hnd_state(struct rpc_pipe_client *cli,
  Check the rpc bind acknowledge response.
 ****************************************************************************/
 
-static bool check_bind_response(RPC_HDR_BA *hdr_ba, const RPC_IFACE *transfer)
+static bool check_bind_response(RPC_HDR_BA *hdr_ba,
+                               const struct ndr_syntax_id *transfer)
 {
        if ( hdr_ba->addr.len == 0) {
                DEBUG(4,("Ignoring length check -- ASU bug (server didn't fill in the pipe name correctly)"));
@@ -2458,8 +2426,8 @@ static NTSTATUS create_rpc_bind_auth3(struct rpc_pipe_client *cli,
  ********************************************************************/
 
 static NTSTATUS create_rpc_alter_context(uint32 rpc_call_id,
-                                       const RPC_IFACE *abstract,
-                                       const RPC_IFACE *transfer,
+                                       const struct ndr_syntax_id *abstract,
+                                       const struct ndr_syntax_id *transfer,
                                        enum pipe_auth_level auth_level,
                                        const DATA_BLOB *pauth_blob, /* spnego auth blob already created. */
                                        prs_struct *rpc_out)
@@ -3191,6 +3159,8 @@ static NTSTATUS rpc_pipe_open_tcp_port(TALLOC_CTX *mem_ctx, const char *host,
        result->abstract_syntax = *abstract_syntax;
        result->transfer_syntax = ndr_transfer_syntax;
        result->dispatch = cli_do_rpc_ndr;
+       result->dispatch_send = cli_do_rpc_ndr_send;
+       result->dispatch_recv = cli_do_rpc_ndr_recv;
 
        result->desthost = talloc_strdup(result, host);
        result->srv_name_slash = talloc_asprintf_strupper_m(
@@ -3203,7 +3173,7 @@ static NTSTATUS rpc_pipe_open_tcp_port(TALLOC_CTX *mem_ctx, const char *host,
        result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN;
        result->max_recv_frag = RPC_MAX_PDU_FRAG_LEN;
 
-       if (!resolve_name(host, &addr, 0)) {
+       if (!resolve_name(host, &addr, 0, false)) {
                status = NT_STATUS_NOT_FOUND;
                goto fail;
        }
@@ -3403,6 +3373,8 @@ NTSTATUS rpc_pipe_open_ncalrpc(TALLOC_CTX *mem_ctx, const char *socket_path,
        result->abstract_syntax = *abstract_syntax;
        result->transfer_syntax = ndr_transfer_syntax;
        result->dispatch = cli_do_rpc_ndr;
+       result->dispatch_send = cli_do_rpc_ndr_send;
+       result->dispatch_recv = cli_do_rpc_ndr_recv;
 
        result->desthost = get_myname(result);
        result->srv_name_slash = talloc_asprintf_strupper_m(
@@ -3425,7 +3397,7 @@ NTSTATUS rpc_pipe_open_ncalrpc(TALLOC_CTX *mem_ctx, const char *socket_path,
        addr.sun_family = AF_UNIX;
        strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
 
-       if (sys_connect(fd, (struct sockaddr *)&addr) == -1) {
+       if (sys_connect(fd, (struct sockaddr *)(void *)&addr) == -1) {
                DEBUG(0, ("connect(%s) failed: %s\n", socket_path,
                          strerror(errno)));
                close(fd);
@@ -3491,6 +3463,8 @@ static NTSTATUS rpc_pipe_open_np(struct cli_state *cli,
        result->abstract_syntax = *abstract_syntax;
        result->transfer_syntax = ndr_transfer_syntax;
        result->dispatch = cli_do_rpc_ndr;
+       result->dispatch_send = cli_do_rpc_ndr_send;
+       result->dispatch_recv = cli_do_rpc_ndr_recv;
        result->desthost = talloc_strdup(result, cli->desthost);
        result->srv_name_slash = talloc_asprintf_strupper_m(
                result, "\\\\%s", result->desthost);
@@ -3533,6 +3507,8 @@ NTSTATUS rpc_pipe_open_local(TALLOC_CTX *mem_ctx,
        result->abstract_syntax = *syntax;
        result->transfer_syntax = ndr_transfer_syntax;
        result->dispatch = cli_do_rpc_ndr;
+       result->dispatch_send = cli_do_rpc_ndr_send;
+       result->dispatch_recv = cli_do_rpc_ndr_recv;
        result->max_xmit_frag = RPC_MAX_PDU_FRAG_LEN;
        result->max_recv_frag = RPC_MAX_PDU_FRAG_LEN;
 
@@ -3845,13 +3821,15 @@ NTSTATUS get_schannel_session_key(struct cli_state *cli,
  External interface.
  Open a named pipe to an SMB server and bind using schannel (bind type 68)
  using session_key. sign and seal.
+
+ The *pdc will be stolen onto this new pipe
  ****************************************************************************/
 
 NTSTATUS cli_rpc_pipe_open_schannel_with_key(struct cli_state *cli,
                                             const struct ndr_syntax_id *interface,
                                             enum pipe_auth_level auth_level,
                                             const char *domain,
-                                            const struct dcinfo *pdc,
+                                            struct netlogon_creds_CredentialState **pdc,
                                             struct rpc_pipe_client **presult)
 {
        struct rpc_pipe_client *result;
@@ -3864,7 +3842,7 @@ NTSTATUS cli_rpc_pipe_open_schannel_with_key(struct cli_state *cli,
        }
 
        status = rpccli_schannel_bind_data(result, domain, auth_level,
-                                          pdc->sess_key, &auth);
+                                          (*pdc)->session_key, &auth);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("rpccli_schannel_bind_data returned %s\n",
                          nt_errstr(status)));
@@ -3883,11 +3861,11 @@ NTSTATUS cli_rpc_pipe_open_schannel_with_key(struct cli_state *cli,
 
        /*
         * The credentials on a new netlogon pipe are the ones we are passed
-        * in - copy them over.
+        * in - reference them in
         */
-       result->dc = (struct dcinfo *)talloc_memdup(result, pdc, sizeof(*pdc));
+       result->dc = talloc_move(result, pdc);
        if (result->dc == NULL) {
-               DEBUG(0, ("talloc failed\n"));
+               DEBUG(0, ("talloc reference failed\n"));
                TALLOC_FREE(result);
                return NT_STATUS_NO_MEMORY;
        }
@@ -3964,7 +3942,7 @@ NTSTATUS cli_rpc_pipe_open_ntlmssp_auth_schannel(struct cli_state *cli,
        }
 
        status = cli_rpc_pipe_open_schannel_with_key(
-               cli, interface, auth_level, domain, netlogon_pipe->dc,
+               cli, interface, auth_level, domain, &netlogon_pipe->dc,
                &result);
 
        /* Now we've bound using the session key we can close the netlog pipe. */
@@ -4002,7 +3980,7 @@ NTSTATUS cli_rpc_pipe_open_schannel(struct cli_state *cli,
        }
 
        status = cli_rpc_pipe_open_schannel_with_key(
-               cli, interface, auth_level, domain, netlogon_pipe->dc,
+               cli, interface, auth_level, domain, &netlogon_pipe->dc,
                &result);
 
        /* Now we've bound using the session key we can close the netlog pipe. */