From 5bc7abf8bb9a91177f3a72943d0a6a030054fd83 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Apr 2008 16:30:50 +0200 Subject: [PATCH] Revert "Introduce a redirection for ncacn_np and ncacn_ip_tcp in rpc_pipe_client" This reverts commit 3433f430b0c1f7d350a40eac783385a2d30d905c. --- source/include/client.h | 14 +--- source/rpc_client/cli_pipe.c | 123 +++++++++++++++-------------------- 2 files changed, 55 insertions(+), 82 deletions(-) diff --git a/source/include/client.h b/source/include/client.h index 7d76b8e6f57..5ab457a2abf 100644 --- a/source/include/client.h +++ b/source/include/client.h @@ -63,18 +63,10 @@ struct cli_pipe_auth_data { struct rpc_pipe_client { struct rpc_pipe_client *prev, *next; - enum dcerpc_transport_t transport_type; + struct cli_state *cli; - union { - struct { - struct cli_state *cli; - const char *pipe_name; - uint16 fnum; - } np; - struct { - int sock; - } tcp; - } trans ; + const char *pipe_name; + uint16 fnum; const struct ndr_syntax_id *abstract_syntax; const struct ndr_syntax_id *transfer_syntax; diff --git a/source/rpc_client/cli_pipe.c b/source/rpc_client/cli_pipe.c index af12999995a..642784c7659 100644 --- a/source/rpc_client/cli_pipe.c +++ b/source/rpc_client/cli_pipe.c @@ -64,9 +64,8 @@ static char *rpccli_pipe_txt(TALLOC_CTX *mem_ctx, struct rpc_pipe_client *cli) { char *result; result = talloc_asprintf(mem_ctx, "host %s, pipe %s, fnum 0x%x", - cli->desthost, - cli->trans.np.pipe_name, - (unsigned int)(cli->trans.np.fnum)); + cli->desthost, cli->pipe_name, + (unsigned int)(cli->fnum)); SMB_ASSERT(result != NULL); return result; } @@ -120,8 +119,8 @@ static NTSTATUS rpc_read(struct rpc_pipe_client *cli, size = (size_t)data_to_read; } - num_read = cli_read(cli->trans.np.cli, cli->trans.np.fnum, - pdata, (off_t)stream_offset, size); + num_read = cli_read(cli->cli, cli->fnum, pdata, + (off_t)stream_offset, size); DEBUG(5,("rpc_read: num_read = %d, read offset: %u, to read: %u\n", (int)num_read, (unsigned int)stream_offset, (unsigned int)data_to_read)); @@ -129,14 +128,14 @@ static NTSTATUS rpc_read(struct rpc_pipe_client *cli, /* * A dos error of ERRDOS/ERRmoredata is not an error. */ - if (cli_is_dos_error(cli->trans.np.cli)) { + if (cli_is_dos_error(cli->cli)) { uint32 ecode; uint8 eclass; - cli_dos_error(cli->trans.np.cli, &eclass, &ecode); + cli_dos_error(cli->cli, &eclass, &ecode); if (eclass != ERRDOS && ecode != ERRmoredata) { DEBUG(0,("rpc_read: DOS Error %d/%u (%s) in cli_read on pipe %s\n", eclass, (unsigned int)ecode, - cli_errstr(cli->trans.np.cli), + cli_errstr(cli->cli), rpccli_pipe_txt(debug_ctx(), cli))); return dos_to_ntstatus(eclass, ecode); } @@ -145,20 +144,19 @@ static NTSTATUS rpc_read(struct rpc_pipe_client *cli, /* * Likewise for NT_STATUS_BUFFER_TOO_SMALL */ - if (cli_is_nt_error(cli->trans.np.cli)) { - if (!NT_STATUS_EQUAL(cli_nt_error(cli->trans.np.cli), - NT_STATUS_BUFFER_TOO_SMALL)) { + if (cli_is_nt_error(cli->cli)) { + if (!NT_STATUS_EQUAL(cli_nt_error(cli->cli), NT_STATUS_BUFFER_TOO_SMALL)) { DEBUG(0,("rpc_read: Error (%s) in cli_read on pipe %s\n", - nt_errstr(cli_nt_error(cli->trans.np.cli)), + nt_errstr(cli_nt_error(cli->cli)), rpccli_pipe_txt(debug_ctx(), cli))); - return cli_nt_error(cli->trans.np.cli); + return cli_nt_error(cli->cli); } } if (num_read == -1) { DEBUG(0,("rpc_read: Error - cli_read on pipe %s returned -1\n", rpccli_pipe_txt(debug_ctx(), cli))); - return cli_get_nt_error(cli->trans.np.cli); + return cli_get_nt_error(cli->cli); } data_to_read -= num_read; @@ -757,7 +755,7 @@ static NTSTATUS rpc_api_pipe(struct rpc_pipe_client *cli, /* Create setup parameters - must be in native byte order. */ setup[0] = TRANSACT_DCERPCCMD; - setup[1] = cli->trans.np.fnum; /* Pipe file handle. */ + setup[1] = cli->fnum; /* Pipe file handle. */ DEBUG(5,("rpc_api_pipe: %s\n", rpccli_pipe_txt(debug_ctx(), cli))); @@ -767,7 +765,7 @@ static NTSTATUS rpc_api_pipe(struct rpc_pipe_client *cli, * appears in a SMBtrans request and response. */ - if (!cli_api_pipe(cli->trans.np.cli, "\\PIPE\\", + if (!cli_api_pipe(cli->cli, "\\PIPE\\", setup, 2, 0, /* Setup, length, max */ NULL, 0, 0, /* Params, length, max */ pdata, data_len, max_data, /* data, length, max */ @@ -776,8 +774,8 @@ static NTSTATUS rpc_api_pipe(struct rpc_pipe_client *cli, { DEBUG(0, ("rpc_api_pipe: %s returned critical error. Error " "was %s\n", rpccli_pipe_txt(debug_ctx(), cli), - cli_errstr(cli->trans.np.cli))); - ret = cli_get_nt_error(cli->trans.np.cli); + cli_errstr(cli->cli))); + ret = cli_get_nt_error(cli->cli); SAFE_FREE(rparam); SAFE_FREE(prdata); goto err; @@ -1542,13 +1540,12 @@ NTSTATUS rpc_api_pipe_req(struct rpc_pipe_client *cli, ret = rpc_api_pipe(cli, &outgoing_pdu, out_data, RPC_RESPONSE); prs_mem_free(&outgoing_pdu); - if ((DEBUGLEVEL >= 50) - && (cli->transport_type == NCACN_NP)) { + if (DEBUGLEVEL >= 50) { char *dump_name = NULL; /* Also capture received data */ if (asprintf(&dump_name, "%s/reply_%s_%d", - get_dyn_LOGFILEBASE(), - cli->trans.np.pipe_name, op_num) > 0) { + get_dyn_LOGFILEBASE(), cli->pipe_name, + op_num) > 0) { prs_dump(dump_name, op_num, out_data); SAFE_FREE(dump_name); } @@ -1557,16 +1554,14 @@ NTSTATUS rpc_api_pipe_req(struct rpc_pipe_client *cli, return ret; } else { /* More packets to come - write and continue. */ - ssize_t num_written = cli_write(cli->trans.np.cli, - cli->trans.np.fnum, - 8, /* 8 means message mode. */ + ssize_t num_written = cli_write(cli->cli, cli->fnum, 8, /* 8 means message mode. */ prs_data_p(&outgoing_pdu), (off_t)0, (size_t)hdr.frag_len); if (num_written != hdr.frag_len) { prs_mem_free(&outgoing_pdu); - return cli_get_nt_error(cli->trans.np.cli); + return cli_get_nt_error(cli->cli); } } @@ -1775,8 +1770,7 @@ static NTSTATUS rpc_finish_auth3_bind(struct rpc_pipe_client *cli, } /* 8 here is named pipe message mode. */ - ret = cli_write(cli->trans.np.cli, cli->trans.np.fnum, - 0x8, prs_data_p(&rpc_out), 0, + ret = cli_write(cli->cli, cli->fnum, 0x8, prs_data_p(&rpc_out), 0, (size_t)prs_offset(&rpc_out)); if (ret != (ssize_t)prs_offset(&rpc_out)) { @@ -1784,7 +1778,7 @@ static NTSTATUS rpc_finish_auth3_bind(struct rpc_pipe_client *cli, prs_mem_free(&rpc_out); data_blob_free(&client_reply); data_blob_free(&server_response); - return cli_get_nt_error(cli->trans.np.cli); + return cli_get_nt_error(cli->cli); } DEBUG(5,("rpc_send_auth_auth3: %s sent auth3 response ok.\n", @@ -2110,7 +2104,7 @@ static NTSTATUS rpc_pipe_bind(struct rpc_pipe_client *cli, unsigned int rpccli_set_timeout(struct rpc_pipe_client *cli, unsigned int timeout) { - return cli_set_timeout(cli->trans.np.cli, timeout); + return cli_set_timeout(cli->cli, timeout); } bool rpccli_is_pipe_idx(struct rpc_pipe_client *cli, int pipe_idx) @@ -2120,48 +2114,39 @@ bool rpccli_is_pipe_idx(struct rpc_pipe_client *cli, int pipe_idx) bool rpccli_get_pwd_hash(struct rpc_pipe_client *cli, uint8_t nt_hash[16]) { - if ((cli->auth->auth_type == PIPE_AUTH_TYPE_NTLMSSP) - || (cli->auth->auth_type == PIPE_AUTH_TYPE_SPNEGO_NTLMSSP)) { - memcpy(nt_hash, cli->auth->a_u.ntlmssp_state->nt_hash, 16); + if (!((cli->auth->auth_type == PIPE_AUTH_TYPE_NTLMSSP) + || (cli->auth->auth_type == PIPE_AUTH_TYPE_SPNEGO_NTLMSSP))) { + E_md4hash(cli->cli->pwd.password, nt_hash); return true; } - if (cli->transport_type == NCACN_NP) { - E_md4hash(cli->trans.np.cli->pwd.password, nt_hash); - return true; - } - - return false; + memcpy(nt_hash, cli->auth->a_u.ntlmssp_state->nt_hash, 16); + return true; } struct cli_state *rpc_pipe_np_smb_conn(struct rpc_pipe_client *p) { - if (p->transport_type == NCACN_NP) { - return p->trans.np.cli; - } - return NULL; + return p->cli; } static int rpc_pipe_destructor(struct rpc_pipe_client *p) { - if (p->transport_type == NCACN_NP) { - bool ret; - ret = cli_close(p->trans.np.cli, p->trans.np.fnum); - if (!ret) { - DEBUG(1, ("rpc_pipe_destructor: cli_close failed on " - "pipe %s. Error was %s\n", - rpccli_pipe_txt(debug_ctx(), p), - cli_errstr(p->trans.np.cli))); - } - - DEBUG(10, ("rpc_pipe_destructor: closed %s\n", - rpccli_pipe_txt(debug_ctx(), p))); + bool ret; - DLIST_REMOVE(p->trans.np.cli->pipe_list, p); - return ret ? -1 : 0; + ret = cli_close(p->cli, p->fnum); + if (!ret) { + DEBUG(1, ("rpc_pipe_destructor: cli_close failed on pipe %s. " + "Error was %s\n", + rpccli_pipe_txt(debug_ctx(), p), + cli_errstr(p->cli))); } - return -1; + DEBUG(10, ("rpc_pipe_destructor: closed %s\n", + rpccli_pipe_txt(debug_ctx(), p))); + + DLIST_REMOVE(p->cli->pipe_list, p); + + return ret ? -1 : 0; } NTSTATUS rpccli_anon_bind_data(TALLOC_CTX *mem_ctx, @@ -2398,11 +2383,9 @@ static struct rpc_pipe_client *cli_rpc_pipe_open(struct cli_state *cli, int pipe return NULL; } - result->transport_type = NCACN_NP; - - result->trans.np.pipe_name = cli_get_pipe_name(pipe_idx); + result->pipe_name = cli_get_pipe_name(pipe_idx); - result->trans.np.cli = cli; + result->cli = cli; result->abstract_syntax = pipe_names[pipe_idx].abstr_syntax; result->transfer_syntax = pipe_names[pipe_idx].trans_syntax; result->desthost = talloc_strdup(result, cli->desthost); @@ -2425,19 +2408,18 @@ static struct rpc_pipe_client *cli_rpc_pipe_open(struct cli_state *cli, int pipe } } - fnum = cli_nt_create(cli, result->trans.np.pipe_name, - DESIRED_ACCESS_PIPE); + fnum = cli_nt_create(cli, result->pipe_name, DESIRED_ACCESS_PIPE); if (fnum == -1) { DEBUG(1,("cli_rpc_pipe_open: cli_nt_create failed on pipe %s " "to machine %s. Error was %s\n", - result->trans.np.pipe_name, cli->desthost, + result->pipe_name, cli->desthost, cli_errstr(cli))); *perr = cli_get_nt_error(cli); talloc_destroy(result); return NULL; } - result->trans.np.fnum = fnum; + result->fnum = fnum; DLIST_ADD(cli->pipe_list, result); talloc_set_destructor(result, rpc_pipe_destructor); @@ -2501,9 +2483,8 @@ struct rpc_pipe_client *cli_rpc_pipe_open_noauth(struct cli_state *cli, int pipe return NULL; } - DEBUG(10,("cli_rpc_pipe_open_noauth: opened pipe %s to machine " - "%s and bound anonymously.\n", result->trans.np.pipe_name, - cli->desthost )); + DEBUG(10,("cli_rpc_pipe_open_noauth: opened pipe %s to machine %s and bound anonymously.\n", + result->pipe_name, cli->desthost )); return result; } @@ -2548,7 +2529,7 @@ static struct rpc_pipe_client *cli_rpc_pipe_open_ntlmssp_internal(struct cli_sta DEBUG(10,("cli_rpc_pipe_open_ntlmssp_internal: opened pipe %s to " "machine %s and bound NTLMSSP as user %s\\%s.\n", - result->trans.np.pipe_name, cli->desthost, + result->pipe_name, cli->desthost, domain, username )); return result; @@ -2729,7 +2710,7 @@ struct rpc_pipe_client *cli_rpc_pipe_open_schannel_with_key(struct cli_state *cl DEBUG(10,("cli_rpc_pipe_open_schannel_with_key: opened pipe %s to machine %s " "for domain %s " "and bound using schannel.\n", - result->trans.np.pipe_name, cli->desthost, domain )); + result->pipe_name, cli->desthost, domain )); return result; } -- 2.47.3