s3-dcerpc: fix remaining old auth level constants.
[ira/wip.git] / source3 / rpc_client / cli_pipe.c
index 6b83c170f5791d06097c2d0671dbbc8651fa30ee..a667a9fb13afb9c4a968c8beb8b03e0ee1edf391 100644 (file)
@@ -18,7 +18,9 @@
  */
 
 #include "includes.h"
+#include "../libcli/auth/libcli_auth.h"
 #include "librpc/gen_ndr/cli_epmapper.h"
+#include "../librpc/gen_ndr/ndr_schannel.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_CLI
@@ -55,7 +57,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 },
@@ -121,20 +123,20 @@ static int map_pipe_auth_type_to_rpc_auth_type(enum pipe_auth_type auth_type)
        switch (auth_type) {
 
        case PIPE_AUTH_TYPE_NONE:
-               return RPC_ANONYMOUS_AUTH_TYPE;
+               return DCERPC_AUTH_TYPE_NONE;
 
        case PIPE_AUTH_TYPE_NTLMSSP:
-               return RPC_NTLMSSP_AUTH_TYPE;
+               return DCERPC_AUTH_TYPE_NTLMSSP;
 
        case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP:
        case PIPE_AUTH_TYPE_SPNEGO_KRB5:
-               return RPC_SPNEGO_AUTH_TYPE;
+               return DCERPC_AUTH_TYPE_SPNEGO;
 
        case PIPE_AUTH_TYPE_SCHANNEL:
-               return RPC_SCHANNEL_AUTH_TYPE;
+               return DCERPC_AUTH_TYPE_SCHANNEL;
 
        case PIPE_AUTH_TYPE_KRB5:
-               return RPC_KRB5_AUTH_TYPE;
+               return DCERPC_AUTH_TYPE_KRB5;
 
        default:
                DEBUG(0,("map_pipe_auth_type_to_rpc_type: unknown pipe "
@@ -557,8 +559,8 @@ static NTSTATUS cli_pipe_verify_ntlmssp(struct rpc_pipe_client *cli, RPC_HDR *pr
        DATA_BLOB auth_blob;
        NTSTATUS status;
 
-       if (cli->auth->auth_level == PIPE_AUTH_LEVEL_NONE
-           || cli->auth->auth_level == PIPE_AUTH_LEVEL_CONNECT) {
+       if (cli->auth->auth_level == DCERPC_AUTH_LEVEL_NONE
+           || cli->auth->auth_level == DCERPC_AUTH_LEVEL_CONNECT) {
                return NT_STATUS_OK;
        }
 
@@ -603,7 +605,7 @@ static NTSTATUS cli_pipe_verify_ntlmssp(struct rpc_pipe_client *cli, RPC_HDR *pr
        auth_blob.length = auth_len;
 
        switch (cli->auth->auth_level) {
-               case PIPE_AUTH_LEVEL_PRIVACY:
+               case DCERPC_AUTH_LEVEL_PRIVACY:
                        /* Data is encrypted. */
                        status = ntlmssp_unseal_packet(ntlmssp_state,
                                                        data, data_len,
@@ -618,7 +620,7 @@ static NTSTATUS cli_pipe_verify_ntlmssp(struct rpc_pipe_client *cli, RPC_HDR *pr
                                return status;
                        }
                        break;
-               case PIPE_AUTH_LEVEL_INTEGRITY:
+               case DCERPC_AUTH_LEVEL_INTEGRITY:
                        /* Data is signed. */
                        status = ntlmssp_check_packet(ntlmssp_state,
                                                        data, data_len,
@@ -668,19 +670,21 @@ static NTSTATUS cli_pipe_verify_schannel(struct rpc_pipe_client *cli, RPC_HDR *p
                                uint8 *p_ss_padding_len)
 {
        RPC_HDR_AUTH auth_info;
-       RPC_AUTH_SCHANNEL_CHK schannel_chk;
+       struct NL_AUTH_SIGNATURE schannel_chk;
        uint32 auth_len = prhdr->auth_len;
        uint32 save_offset = prs_offset(current_pdu);
        struct schannel_auth_struct *schannel_auth =
                cli->auth->a_u.schannel_auth;
        uint32 data_len;
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
 
-       if (cli->auth->auth_level == PIPE_AUTH_LEVEL_NONE
-           || cli->auth->auth_level == PIPE_AUTH_LEVEL_CONNECT) {
+       if (cli->auth->auth_level == DCERPC_AUTH_LEVEL_NONE
+           || cli->auth->auth_level == DCERPC_AUTH_LEVEL_CONNECT) {
                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;
        }
@@ -710,16 +714,23 @@ static NTSTATUS cli_pipe_verify_schannel(struct rpc_pipe_client *cli, RPC_HDR *p
                return NT_STATUS_BUFFER_TOO_SMALL;
        }
 
-       if (auth_info.auth_type != RPC_SCHANNEL_AUTH_TYPE) {
+       if (auth_info.auth_type != DCERPC_AUTH_TYPE_SCHANNEL) {
                DEBUG(0,("cli_pipe_verify_schannel: Invalid auth info %d on schannel\n",
                        auth_info.auth_type));
                return NT_STATUS_BUFFER_TOO_SMALL;
        }
 
-       if(!smb_io_rpc_auth_schannel_chk("", RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN,
-                               &schannel_chk, current_pdu, 0)) {
+       blob = data_blob_const(prs_data_p(current_pdu) + prs_offset(current_pdu), data_len);
+
+       ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), NULL, &schannel_chk,
+                              (ndr_pull_flags_fn_t)ndr_pull_NL_AUTH_SIGNATURE);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
                DEBUG(0,("cli_pipe_verify_schannel: failed to unmarshal RPC_AUTH_SCHANNEL_CHK.\n"));
-               return NT_STATUS_BUFFER_TOO_SMALL;
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(NL_AUTH_SIGNATURE, &schannel_chk);
        }
 
        if (!schannel_decode(schannel_auth,
@@ -1459,7 +1470,7 @@ static NTSTATUS rpc_api_pipe_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
  ********************************************************************/
 
 static NTSTATUS create_krb5_auth_bind_req( struct rpc_pipe_client *cli,
-                                               enum pipe_auth_level auth_level,
+                                               enum dcerpc_AuthLevel auth_level,
                                                RPC_HDR_AUTH *pauth_out,
                                                prs_struct *auth_data)
 {
@@ -1470,7 +1481,7 @@ static NTSTATUS create_krb5_auth_bind_req( struct rpc_pipe_client *cli,
        DATA_BLOB tkt_wrapped = data_blob_null;
 
        /* We may change the pad length before marshalling. */
-       init_rpc_hdr_auth(pauth_out, RPC_KRB5_AUTH_TYPE, (int)auth_level, 0, 1);
+       init_rpc_hdr_auth(pauth_out, DCERPC_AUTH_TYPE_KRB5, (int)auth_level, 0, 1);
 
        DEBUG(5, ("create_krb5_auth_bind_req: creating a service ticket for principal %s\n",
                a->service_principal ));
@@ -1518,7 +1529,7 @@ static NTSTATUS create_krb5_auth_bind_req( struct rpc_pipe_client *cli,
  ********************************************************************/
 
 static NTSTATUS create_spnego_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client *cli,
-                                               enum pipe_auth_level auth_level,
+                                               enum dcerpc_AuthLevel auth_level,
                                                RPC_HDR_AUTH *pauth_out,
                                                prs_struct *auth_data)
 {
@@ -1528,7 +1539,7 @@ static NTSTATUS create_spnego_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client
        DATA_BLOB spnego_msg = data_blob_null;
 
        /* We may change the pad length before marshalling. */
-       init_rpc_hdr_auth(pauth_out, RPC_SPNEGO_AUTH_TYPE, (int)auth_level, 0, 1);
+       init_rpc_hdr_auth(pauth_out, DCERPC_AUTH_TYPE_SPNEGO, (int)auth_level, 0, 1);
 
        DEBUG(5, ("create_spnego_ntlmssp_auth_rpc_bind_req: Processing NTLMSSP Negotiate\n"));
        nt_status = ntlmssp_update(cli->auth->a_u.ntlmssp_state,
@@ -1565,7 +1576,7 @@ static NTSTATUS create_spnego_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client
  ********************************************************************/
 
 static NTSTATUS create_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client *cli,
-                                               enum pipe_auth_level auth_level,
+                                               enum dcerpc_AuthLevel auth_level,
                                                RPC_HDR_AUTH *pauth_out,
                                                prs_struct *auth_data)
 {
@@ -1574,7 +1585,7 @@ static NTSTATUS create_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client *cli,
        DATA_BLOB request = data_blob_null;
 
        /* We may change the pad length before marshalling. */
-       init_rpc_hdr_auth(pauth_out, RPC_NTLMSSP_AUTH_TYPE, (int)auth_level, 0, 1);
+       init_rpc_hdr_auth(pauth_out, DCERPC_AUTH_TYPE_NTLMSSP, (int)auth_level, 0, 1);
 
        DEBUG(5, ("create_ntlmssp_auth_rpc_bind_req: Processing NTLMSSP Negotiate\n"));
        nt_status = ntlmssp_update(cli->auth->a_u.ntlmssp_state,
@@ -1606,14 +1617,16 @@ static NTSTATUS create_ntlmssp_auth_rpc_bind_req( struct rpc_pipe_client *cli,
  ********************************************************************/
 
 static NTSTATUS create_schannel_auth_rpc_bind_req( struct rpc_pipe_client *cli,
-                                               enum pipe_auth_level auth_level,
+                                               enum dcerpc_AuthLevel auth_level,
                                                RPC_HDR_AUTH *pauth_out,
                                                prs_struct *auth_data)
 {
-       RPC_AUTH_SCHANNEL_NEG schannel_neg;
+       struct NL_AUTH_MESSAGE r;
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
 
        /* We may change the pad length before marshalling. */
-       init_rpc_hdr_auth(pauth_out, RPC_SCHANNEL_AUTH_TYPE, (int)auth_level, 0, 1);
+       init_rpc_hdr_auth(pauth_out, DCERPC_AUTH_TYPE_SCHANNEL, (int)auth_level, 0, 1);
 
        /* Use lp_workgroup() if domain not specified */
 
@@ -1624,16 +1637,30 @@ static NTSTATUS create_schannel_auth_rpc_bind_req( struct rpc_pipe_client *cli,
                }
        }
 
-       init_rpc_auth_schannel_neg(&schannel_neg, cli->auth->domain,
-                                  global_myname());
-
        /*
         * Now marshall the data into the auth parse_struct.
         */
 
-       if(!smb_io_rpc_auth_schannel_neg("schannel_neg",
-                                      &schannel_neg, auth_data, 0)) {
-               DEBUG(0,("Failed to marshall RPC_AUTH_SCHANNEL_NEG.\n"));
+       r.MessageType                   = NL_NEGOTIATE_REQUEST;
+       r.Flags                         = NL_FLAG_OEM_NETBIOS_DOMAIN_NAME |
+                                         NL_FLAG_OEM_NETBIOS_COMPUTER_NAME;
+       r.oem_netbios_domain.a          = cli->auth->domain;
+       r.oem_netbios_computer.a        = global_myname();
+
+       ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), NULL, &r,
+                      (ndr_push_flags_fn_t)ndr_push_NL_AUTH_MESSAGE);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               DEBUG(0,("Failed to marshall NL_AUTH_MESSAGE.\n"));
+               prs_mem_free(auth_data);
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(NL_AUTH_MESSAGE, &r);
+       }
+
+       if (!prs_copy_data_in(auth_data, (const char *)blob.data, blob.length))
+       {
                prs_mem_free(auth_data);
                return NT_STATUS_NO_MEMORY;
        }
@@ -1648,8 +1675,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)
 {
@@ -1730,10 +1757,10 @@ 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)
+                               enum dcerpc_AuthLevel auth_level)
 {
        RPC_HDR_AUTH hdr_auth;
        prs_struct auth_info;
@@ -1829,7 +1856,7 @@ static NTSTATUS add_ntlmssp_auth_footer(struct rpc_pipe_client *cli,
        }
 
        switch (cli->auth->auth_level) {
-               case PIPE_AUTH_LEVEL_PRIVACY:
+               case DCERPC_AUTH_LEVEL_PRIVACY:
                        /* Data portion is encrypted. */
                        status = ntlmssp_seal_packet(cli->auth->a_u.ntlmssp_state,
                                        (unsigned char *)prs_data_p(outgoing_pdu) + RPC_HEADER_LEN + RPC_HDR_RESP_LEN,
@@ -1843,7 +1870,7 @@ static NTSTATUS add_ntlmssp_auth_footer(struct rpc_pipe_client *cli,
                        }
                        break;
 
-               case PIPE_AUTH_LEVEL_INTEGRITY:
+               case DCERPC_AUTH_LEVEL_INTEGRITY:
                        /* Data is signed. */
                        status = ntlmssp_sign_packet(cli->auth->a_u.ntlmssp_state,
                                        (unsigned char *)prs_data_p(outgoing_pdu) + RPC_HEADER_LEN + RPC_HDR_RESP_LEN,
@@ -1887,10 +1914,12 @@ static NTSTATUS add_schannel_auth_footer(struct rpc_pipe_client *cli,
                                        prs_struct *outgoing_pdu)
 {
        RPC_HDR_AUTH auth_info;
-       RPC_AUTH_SCHANNEL_CHK verf;
+       struct NL_AUTH_SIGNATURE verf;
        struct schannel_auth_struct *sas = cli->auth->a_u.schannel_auth;
        char *data_p = prs_data_p(outgoing_pdu) + RPC_HEADER_LEN + RPC_HDR_RESP_LEN;
        size_t data_and_pad_len = prs_offset(outgoing_pdu) - RPC_HEADER_LEN - RPC_HDR_RESP_LEN;
+       enum ndr_err_code ndr_err;
+       DATA_BLOB blob;
 
        if (!sas) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -1909,8 +1938,8 @@ static NTSTATUS add_schannel_auth_footer(struct rpc_pipe_client *cli,
        }
 
        switch (cli->auth->auth_level) {
-               case PIPE_AUTH_LEVEL_PRIVACY:
-               case PIPE_AUTH_LEVEL_INTEGRITY:
+               case DCERPC_AUTH_LEVEL_PRIVACY:
+               case DCERPC_AUTH_LEVEL_INTEGRITY:
                        DEBUG(10,("add_schannel_auth_footer: SCHANNEL seq_num=%d\n",
                                sas->seq_num));
 
@@ -1931,12 +1960,20 @@ static NTSTATUS add_schannel_auth_footer(struct rpc_pipe_client *cli,
                        return NT_STATUS_INVALID_PARAMETER;
        }
 
+       ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), NULL, &verf,
+                              (ndr_push_flags_fn_t)ndr_push_NL_AUTH_SIGNATURE);
+       if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+               return ndr_map_error2ntstatus(ndr_err);
+       }
+
+       if (DEBUGLEVEL >= 10) {
+               NDR_PRINT_DEBUG(NL_AUTH_SIGNATURE, &verf);
+       }
+
        /* Finally marshall the blob. */
-       smb_io_rpc_auth_schannel_chk("",
-                       RPC_AUTH_SCHANNEL_SIGN_OR_SEAL_CHK_LEN,
-                       &verf,
-                       outgoing_pdu,
-                       0);
+       if (!prs_copy_data_in(outgoing_pdu, (const char *)blob.data, blob.length)) {
+               return NT_STATUS_NO_MEMORY;
+       }
 
        return NT_STATUS_OK;
 }
@@ -1961,8 +1998,8 @@ static uint32 calculate_data_len_tosend(struct rpc_pipe_client *cli,
 #endif
 
        switch (cli->auth->auth_level) {
-               case PIPE_AUTH_LEVEL_NONE:
-               case PIPE_AUTH_LEVEL_CONNECT:
+               case DCERPC_AUTH_LEVEL_NONE:
+               case DCERPC_AUTH_LEVEL_CONNECT:
                        data_space = cli->max_xmit_frag - RPC_HEADER_LEN - RPC_HDR_REQ_LEN;
                        data_len = MIN(data_space, data_left);
                        *p_ss_padding = 0;
@@ -1970,8 +2007,8 @@ static uint32 calculate_data_len_tosend(struct rpc_pipe_client *cli,
                        *p_frag_len = RPC_HEADER_LEN + RPC_HDR_REQ_LEN + data_len;
                        return data_len;
 
-               case PIPE_AUTH_LEVEL_INTEGRITY:
-               case PIPE_AUTH_LEVEL_PRIVACY:
+               case DCERPC_AUTH_LEVEL_INTEGRITY:
+               case DCERPC_AUTH_LEVEL_PRIVACY:
                        /* Treat the same for all authenticated rpc requests. */
                        switch(cli->auth->auth_type) {
                                case PIPE_AUTH_TYPE_SPNEGO_NTLMSSP:
@@ -2283,34 +2320,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_NO_MEMORY;
-
-       ev = event_context_init(frame);
-       if (ev == NULL) {
-               goto fail;
-       }
-
-       req = rpc_api_pipe_req_send(frame, ev, cli, op_num, in_data);
-       if (req == NULL) {
-               goto fail;
-       }
-
-       tevent_req_poll(req, ev);
-
-       status = rpc_api_pipe_req_recv(req, mem_ctx, out_data);
- fail:
-       TALLOC_FREE(frame);
-       return status;
-}
-
 #if 0
 /****************************************************************************
  Set the handle state.
@@ -2362,7 +2371,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)"));
@@ -2394,7 +2404,7 @@ static bool check_bind_response(RPC_HDR_BA *hdr_ba, const RPC_IFACE *transfer)
 static NTSTATUS create_rpc_bind_auth3(struct rpc_pipe_client *cli,
                                uint32 rpc_call_id,
                                enum pipe_auth_type auth_type,
-                               enum pipe_auth_level auth_level,
+                               enum dcerpc_AuthLevel auth_level,
                                DATA_BLOB *pauth_blob,
                                prs_struct *rpc_out)
 {
@@ -2452,9 +2462,9 @@ 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,
-                                       enum pipe_auth_level auth_level,
+                                       const struct ndr_syntax_id *abstract,
+                                       const struct ndr_syntax_id *transfer,
+                                       enum dcerpc_AuthLevel auth_level,
                                        const DATA_BLOB *pauth_blob, /* spnego auth blob already created. */
                                        prs_struct *rpc_out)
 {
@@ -2467,7 +2477,7 @@ static NTSTATUS create_rpc_alter_context(uint32 rpc_call_id,
                return NT_STATUS_NO_MEMORY;
 
        /* We may change the pad length before marshalling. */
-       init_rpc_hdr_auth(&hdr_auth, RPC_SPNEGO_AUTH_TYPE, (int)auth_level, 0, 1);
+       init_rpc_hdr_auth(&hdr_auth, DCERPC_AUTH_TYPE_SPNEGO, (int)auth_level, 0, 1);
 
        if (pauth_blob->length) {
                if (!prs_copy_data_in(&auth_info, (const char *)pauth_blob->data, pauth_blob->length)) {
@@ -2905,19 +2915,24 @@ NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli,
        TALLOC_CTX *frame = talloc_stackframe();
        struct event_context *ev;
        struct tevent_req *req;
-       NTSTATUS status = NT_STATUS_NO_MEMORY;
+       NTSTATUS status = NT_STATUS_OK;
 
        ev = event_context_init(frame);
        if (ev == NULL) {
+               status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
 
        req = rpc_pipe_bind_send(frame, ev, cli, auth);
        if (req == NULL) {
+               status = NT_STATUS_NO_MEMORY;
                goto fail;
        }
 
-       tevent_req_poll(req, ev);
+       if (!tevent_req_poll(req, ev)) {
+               status = map_nt_error_from_unix(errno);
+               goto fail;
+       }
 
        status = rpc_pipe_bind_recv(req);
  fail:
@@ -2965,7 +2980,7 @@ NTSTATUS rpccli_anon_bind_data(TALLOC_CTX *mem_ctx,
        }
 
        result->auth_type = PIPE_AUTH_TYPE_NONE;
-       result->auth_level = PIPE_AUTH_LEVEL_NONE;
+       result->auth_level = DCERPC_AUTH_LEVEL_NONE;
 
        result->user_name = talloc_strdup(result, "");
        result->domain = talloc_strdup(result, "");
@@ -2986,7 +3001,7 @@ static int cli_auth_ntlmssp_data_destructor(struct cli_pipe_auth_data *auth)
 
 NTSTATUS rpccli_ntlmssp_bind_data(TALLOC_CTX *mem_ctx,
                                  enum pipe_auth_type auth_type,
-                                 enum pipe_auth_level auth_level,
+                                 enum dcerpc_AuthLevel auth_level,
                                  const char *domain,
                                  const char *username,
                                  const char *password,
@@ -3038,9 +3053,9 @@ NTSTATUS rpccli_ntlmssp_bind_data(TALLOC_CTX *mem_ctx,
        result->a_u.ntlmssp_state->neg_flags &=
                ~(NTLMSSP_NEGOTIATE_SIGN | NTLMSSP_NEGOTIATE_SEAL);
 
-       if (auth_level == PIPE_AUTH_LEVEL_INTEGRITY) {
+       if (auth_level == DCERPC_AUTH_LEVEL_INTEGRITY) {
                result->a_u.ntlmssp_state->neg_flags |= NTLMSSP_NEGOTIATE_SIGN;
-       } else if (auth_level == PIPE_AUTH_LEVEL_PRIVACY) {
+       } else if (auth_level == DCERPC_AUTH_LEVEL_PRIVACY) {
                result->a_u.ntlmssp_state->neg_flags
                        |= NTLMSSP_NEGOTIATE_SEAL | NTLMSSP_NEGOTIATE_SIGN;
        }
@@ -3054,7 +3069,7 @@ NTSTATUS rpccli_ntlmssp_bind_data(TALLOC_CTX *mem_ctx,
 }
 
 NTSTATUS rpccli_schannel_bind_data(TALLOC_CTX *mem_ctx, const char *domain,
-                                  enum pipe_auth_level auth_level,
+                                  enum dcerpc_AuthLevel auth_level,
                                   const uint8_t sess_key[16],
                                   struct cli_pipe_auth_data **presult)
 {
@@ -3101,7 +3116,7 @@ static int cli_auth_kerberos_data_destructor(struct kerberos_auth_struct *auth)
 #endif
 
 NTSTATUS rpccli_kerberos_bind_data(TALLOC_CTX *mem_ctx,
-                                  enum pipe_auth_level auth_level,
+                                  enum dcerpc_AuthLevel auth_level,
                                   const char *service_princ,
                                   const char *username,
                                   const char *password,
@@ -3180,6 +3195,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(
@@ -3192,7 +3209,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;
        }
@@ -3209,6 +3226,8 @@ static NTSTATUS rpc_pipe_open_tcp_port(TALLOC_CTX *mem_ctx, const char *host,
                goto fail;
        }
 
+       result->transport->transport = NCACN_IP_TCP;
+
        *presult = result;
        return NT_STATUS_OK;
 
@@ -3392,6 +3411,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(
@@ -3414,7 +3435,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);
@@ -3427,6 +3448,8 @@ NTSTATUS rpc_pipe_open_ncalrpc(TALLOC_CTX *mem_ctx, const char *socket_path,
                goto fail;
        }
 
+       result->transport->transport = NCALRPC;
+
        *presult = result;
        return NT_STATUS_OK;
 
@@ -3480,6 +3503,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);
@@ -3499,6 +3524,8 @@ static NTSTATUS rpc_pipe_open_np(struct cli_state *cli,
                return status;
        }
 
+       result->transport->transport = NCACN_NP;
+
        DLIST_ADD(cli->pipe_list, result);
        talloc_set_destructor(result, rpc_pipe_client_np_destructor);
 
@@ -3522,6 +3549,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;
 
@@ -3557,6 +3586,8 @@ NTSTATUS rpc_pipe_open_local(TALLOC_CTX *mem_ctx,
                return status;
        }
 
+       result->transport->transport = NCACN_INTERNAL;
+
        *presult = result;
        return NT_STATUS_OK;
 }
@@ -3566,34 +3597,35 @@ NTSTATUS rpc_pipe_open_local(TALLOC_CTX *mem_ctx,
  ****************************************************************************/
 
 static NTSTATUS cli_rpc_pipe_open(struct cli_state *cli,
+                                 enum dcerpc_transport_t transport,
                                  const struct ndr_syntax_id *interface,
                                  struct rpc_pipe_client **presult)
 {
-       if (ndr_syntax_id_equal(interface, &ndr_table_drsuapi.syntax_id)) {
-               /*
-                * We should have a better way to figure out this drsuapi
-                * speciality...
-                */
+       switch (transport) {
+       case NCACN_IP_TCP:
                return rpc_pipe_open_tcp(NULL, cli->desthost, interface,
                                         presult);
+       case NCACN_NP:
+               return rpc_pipe_open_np(cli, interface, presult);
+       default:
+               return NT_STATUS_NOT_IMPLEMENTED;
        }
-
-       return rpc_pipe_open_np(cli, interface, presult);
 }
 
 /****************************************************************************
  Open a named pipe to an SMB server and bind anonymously.
  ****************************************************************************/
 
-NTSTATUS cli_rpc_pipe_open_noauth(struct cli_state *cli,
-                                 const struct ndr_syntax_id *interface,
-                                 struct rpc_pipe_client **presult)
+NTSTATUS cli_rpc_pipe_open_noauth_transport(struct cli_state *cli,
+                                           enum dcerpc_transport_t transport,
+                                           const struct ndr_syntax_id *interface,
+                                           struct rpc_pipe_client **presult)
 {
        struct rpc_pipe_client *result;
        struct cli_pipe_auth_data *auth;
        NTSTATUS status;
 
-       status = cli_rpc_pipe_open(cli, interface, &result);
+       status = cli_rpc_pipe_open(cli, transport, interface, &result);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -3651,14 +3683,26 @@ NTSTATUS cli_rpc_pipe_open_noauth(struct cli_state *cli,
        return NT_STATUS_OK;
 }
 
+/****************************************************************************
+ ****************************************************************************/
+
+NTSTATUS cli_rpc_pipe_open_noauth(struct cli_state *cli,
+                                 const struct ndr_syntax_id *interface,
+                                 struct rpc_pipe_client **presult)
+{
+       return cli_rpc_pipe_open_noauth_transport(cli, NCACN_NP,
+                                                 interface, presult);
+}
+
 /****************************************************************************
  Open a named pipe to an SMB server and bind using NTLMSSP or SPNEGO NTLMSSP
  ****************************************************************************/
 
 static NTSTATUS cli_rpc_pipe_open_ntlmssp_internal(struct cli_state *cli,
                                                   const struct ndr_syntax_id *interface,
+                                                  enum dcerpc_transport_t transport,
                                                   enum pipe_auth_type auth_type,
-                                                  enum pipe_auth_level auth_level,
+                                                  enum dcerpc_AuthLevel auth_level,
                                                   const char *domain,
                                                   const char *username,
                                                   const char *password,
@@ -3668,7 +3712,7 @@ static NTSTATUS cli_rpc_pipe_open_ntlmssp_internal(struct cli_state *cli,
        struct cli_pipe_auth_data *auth;
        NTSTATUS status;
 
-       status = cli_rpc_pipe_open(cli, interface, &result);
+       status = cli_rpc_pipe_open(cli, transport, interface, &result);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
@@ -3710,7 +3754,8 @@ static NTSTATUS cli_rpc_pipe_open_ntlmssp_internal(struct cli_state *cli,
 
 NTSTATUS cli_rpc_pipe_open_ntlmssp(struct cli_state *cli,
                                   const struct ndr_syntax_id *interface,
-                                  enum pipe_auth_level auth_level,
+                                  enum dcerpc_transport_t transport,
+                                  enum dcerpc_AuthLevel auth_level,
                                   const char *domain,
                                   const char *username,
                                   const char *password,
@@ -3718,6 +3763,7 @@ NTSTATUS cli_rpc_pipe_open_ntlmssp(struct cli_state *cli,
 {
        return cli_rpc_pipe_open_ntlmssp_internal(cli,
                                                interface,
+                                               transport,
                                                PIPE_AUTH_TYPE_NTLMSSP,
                                                auth_level,
                                                domain,
@@ -3733,7 +3779,8 @@ NTSTATUS cli_rpc_pipe_open_ntlmssp(struct cli_state *cli,
 
 NTSTATUS cli_rpc_pipe_open_spnego_ntlmssp(struct cli_state *cli,
                                          const struct ndr_syntax_id *interface,
-                                         enum pipe_auth_level auth_level,
+                                         enum dcerpc_transport_t transport,
+                                         enum dcerpc_AuthLevel auth_level,
                                          const char *domain,
                                          const char *username,
                                          const char *password,
@@ -3741,6 +3788,7 @@ NTSTATUS cli_rpc_pipe_open_spnego_ntlmssp(struct cli_state *cli,
 {
        return cli_rpc_pipe_open_ntlmssp_internal(cli,
                                                interface,
+                                               transport,
                                                PIPE_AUTH_TYPE_SPNEGO_NTLMSSP,
                                                auth_level,
                                                domain,
@@ -3834,26 +3882,29 @@ 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,
+                                            enum dcerpc_transport_t transport,
+                                            enum dcerpc_AuthLevel auth_level,
                                             const char *domain,
-                                            const struct dcinfo *pdc,
+                                            struct netlogon_creds_CredentialState **pdc,
                                             struct rpc_pipe_client **presult)
 {
        struct rpc_pipe_client *result;
        struct cli_pipe_auth_data *auth;
        NTSTATUS status;
 
-       status = cli_rpc_pipe_open(cli, interface, &result);
+       status = cli_rpc_pipe_open(cli, transport, interface, &result);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }
 
        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)));
@@ -3872,11 +3923,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;
        }
@@ -3907,7 +3958,8 @@ static NTSTATUS get_schannel_session_key_auth_ntlmssp(struct cli_state *cli,
        NTSTATUS status;
 
        status = cli_rpc_pipe_open_spnego_ntlmssp(
-               cli, &ndr_table_netlogon.syntax_id, PIPE_AUTH_LEVEL_PRIVACY,
+               cli, &ndr_table_netlogon.syntax_id, NCACN_NP,
+               DCERPC_AUTH_LEVEL_PRIVACY,
                domain, username, password, &netlogon_pipe);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -3932,7 +3984,8 @@ static NTSTATUS get_schannel_session_key_auth_ntlmssp(struct cli_state *cli,
 
 NTSTATUS cli_rpc_pipe_open_ntlmssp_auth_schannel(struct cli_state *cli,
                                                 const struct ndr_syntax_id *interface,
-                                                enum pipe_auth_level auth_level,
+                                                enum dcerpc_transport_t transport,
+                                                enum dcerpc_AuthLevel auth_level,
                                                 const char *domain,
                                                 const char *username,
                                                 const char *password,
@@ -3953,7 +4006,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, transport, auth_level, domain, &netlogon_pipe->dc,
                &result);
 
        /* Now we've bound using the session key we can close the netlog pipe. */
@@ -3972,7 +4025,8 @@ NTSTATUS cli_rpc_pipe_open_ntlmssp_auth_schannel(struct cli_state *cli,
 
 NTSTATUS cli_rpc_pipe_open_schannel(struct cli_state *cli,
                                    const struct ndr_syntax_id *interface,
-                                   enum pipe_auth_level auth_level,
+                                   enum dcerpc_transport_t transport,
+                                   enum dcerpc_AuthLevel auth_level,
                                    const char *domain,
                                    struct rpc_pipe_client **presult)
 {
@@ -3991,7 +4045,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, transport, auth_level, domain, &netlogon_pipe->dc,
                &result);
 
        /* Now we've bound using the session key we can close the netlog pipe. */
@@ -4012,7 +4066,7 @@ NTSTATUS cli_rpc_pipe_open_schannel(struct cli_state *cli,
 
 NTSTATUS cli_rpc_pipe_open_krb5(struct cli_state *cli,
                                const struct ndr_syntax_id *interface,
-                               enum pipe_auth_level auth_level,
+                               enum dcerpc_AuthLevel auth_level,
                                const char *service_princ,
                                const char *username,
                                const char *password,
@@ -4023,7 +4077,7 @@ NTSTATUS cli_rpc_pipe_open_krb5(struct cli_state *cli,
        struct cli_pipe_auth_data *auth;
        NTSTATUS status;
 
-       status = cli_rpc_pipe_open(cli, interface, &result);
+       status = cli_rpc_pipe_open(cli, NCACN_NP, interface, &result);
        if (!NT_STATUS_IS_OK(status)) {
                return status;
        }