The HTTP connection code is common to in and out channels.
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Wed Aug 7 14:12:40 UTC 2019 on sn-devel-184
* always use local proxy. Otherwise, run the proxy use discovery
*/
state->roh->connection_state = ROH_STATE_OPEN_START;
- subreq = roh_connect_channel_in_send(state,
- state->event_ctx,
- state->rpcproxy_addresses[state->rpcproxy_address_index],
- state->rpc_proxy_port,
- state->credentials,
- state->roh, state->tls,
- state->tls_params);
+ subreq = roh_connect_channel_send(state,
+ state->event_ctx,
+ state->rpcproxy_addresses[state->rpcproxy_address_index],
+ state->rpc_proxy_port,
+ state->credentials,
+ state->tls,
+ state->tls_params);
if (tevent_req_nomem(subreq, state->req)) {
return;
}
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct roh_open_connection_state);
- status = roh_connect_channel_in_recv(subreq);
+ status = roh_connect_channel_recv(subreq, state->roh,
+ &state->roh->default_channel_in);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
- subreq = roh_connect_channel_out_send(state,
- state->event_ctx,
- state->rpcproxy_addresses[state->rpcproxy_address_index],
- state->rpc_proxy_port,
- state->credentials,
- state->roh,
- state->tls,
- state->tls_params);
+ subreq = roh_connect_channel_send(state,
+ state->event_ctx,
+ state->rpcproxy_addresses[state->rpcproxy_address_index],
+ state->rpc_proxy_port,
+ state->credentials,
+ state->tls,
+ state->tls_params);
if (tevent_req_nomem(subreq, req)) {
return;
}
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct roh_open_connection_state);
- status = roh_connect_channel_out_recv(subreq);
+ status = roh_connect_channel_recv(subreq, state->roh,
+ &state->roh->default_channel_out);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
#include "librpc/rpc/dcerpc_proto.h"
#include "libcli/http/http.h"
-struct roh_connect_channel_state {
- struct tevent_context *ev;
- struct cli_credentials *credentials;
- struct roh_connection *roh;
- struct tstream_tls_params *tls_params;
-};
-
-static void roh_connect_channel_in_done(struct tevent_req *);
-struct tevent_req *roh_connect_channel_in_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- const char *rpcproxy_ip_address,
- unsigned int rpcproxy_port,
- struct cli_credentials *credentials,
- struct roh_connection *roh,
- bool tls,
- struct tstream_tls_params *tls_params)
-{
- struct tevent_req *req;
- struct tevent_req *subreq;
- struct roh_connect_channel_state *state;
-
- DEBUG(8, ("%s: Connecting channel in socket, RPC proxy is %s:%d (TLS: %s)\n",
- __func__, rpcproxy_ip_address, rpcproxy_port,
- (tls ? "true" : "false")));
-
- req = tevent_req_create(mem_ctx, &state, struct roh_connect_channel_state);
- if (req == NULL) {
- return NULL;
- }
-
- if (!is_ipaddress(rpcproxy_ip_address)) {
- DEBUG(0, ("%s: Invalid host (%s), needs to be an IP address\n",
- __func__, rpcproxy_ip_address));
- tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return tevent_req_post(req, ev);
- }
-
- state->ev = ev;
- state->credentials = credentials;
- state->roh = roh;
- state->tls_params = tls_params;
-
- /* Initialize channel structure */
- state->roh->default_channel_in = talloc_zero(roh, struct roh_channel);
- if (tevent_req_nomem(state->roh->default_channel_in, req)) {
- return tevent_req_post(req, ev);
- }
-
- state->roh->default_channel_in->channel_cookie = GUID_random();
-
- subreq = http_connect_send(state,
- ev,
- rpcproxy_ip_address,
- rpcproxy_port,
- credentials,
- tls ? tls_params : NULL);
- if (tevent_req_nomem(subreq, req)) {
- return tevent_req_post(req, ev);
- }
- tevent_req_set_callback(subreq, roh_connect_channel_in_done, req);
-
- return req;
-}
-
-static void roh_connect_channel_in_done(struct tevent_req *subreq)
-{
- NTSTATUS status;
- struct tevent_req *req;
- struct roh_connect_channel_state *state;
- int ret;
-
- req = tevent_req_callback_data(subreq, struct tevent_req);
- state = tevent_req_data(req, struct roh_connect_channel_state);
-
- ret = http_connect_recv(subreq,
- state->roh->default_channel_in,
- &state->roh->default_channel_in->http_conn);
- TALLOC_FREE(subreq);
- if (ret != 0) {
- status = map_nt_error_from_unix_common(ret);
- tevent_req_nterror(req, status);
- return;
- }
-
- DBG_DEBUG("HTTP connected\n");
- tevent_req_done(req);
-}
-
-NTSTATUS roh_connect_channel_in_recv(struct tevent_req *req)
-{
- NTSTATUS status;
-
- if (tevent_req_is_nterror(req, &status)) {
- tevent_req_received(req);
- return status;
- }
-
- tevent_req_received(req);
- return NT_STATUS_OK;
-}
-
struct roh_request_state {
struct http_request *request;
struct http_request *response;
#include "librpc/rpc/dcerpc_proto.h"
#include "libcli/http/http.h"
-struct roh_connect_channel_state {
- struct tevent_context *ev;
- struct cli_credentials *credentials;
- struct roh_connection *roh;
- struct tstream_tls_params *tls_params;
-};
-
-static void roh_connect_channel_out_done(struct tevent_req *subreq);
-struct tevent_req *roh_connect_channel_out_send(TALLOC_CTX *mem_ctx,
- struct tevent_context *ev,
- const char *rpcproxy_ip_address,
- unsigned int rpcproxy_port,
- struct cli_credentials *credentials,
- struct roh_connection *roh,
- bool tls,
- struct tstream_tls_params *tls_params)
-{
- struct tevent_req *req;
- struct tevent_req *subreq;
- struct roh_connect_channel_state *state;
-
- DEBUG(8, ("%s: Connecting channel out socket, RPC proxy is %s:%d (TLS: %s)\n",
- __func__, rpcproxy_ip_address, rpcproxy_port,
- (tls ? "true" : "false")));
-
- req = tevent_req_create(mem_ctx, &state, struct roh_connect_channel_state);
- if (req == NULL) {
- return NULL;
- }
-
- if (!is_ipaddress(rpcproxy_ip_address)) {
- DEBUG(0, ("%s: Invalid host (%s), needs to be an IP address\n",
- __func__, rpcproxy_ip_address));
- tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
- return tevent_req_post(req, ev);
- }
-
- state->ev = ev;
- state->credentials = credentials;
- state->roh = roh;
- state->tls_params = tls_params;
-
- /* Initialize channel structure */
- state->roh->default_channel_out = talloc_zero(roh, struct roh_channel);
- if (tevent_req_nomem(state->roh->default_channel_out, req)) {
- return tevent_req_post(req, ev);
- }
-
- state->roh->default_channel_out->channel_cookie = GUID_random();
-
- subreq = http_connect_send(state,
- ev,
- rpcproxy_ip_address,
- rpcproxy_port,
- credentials,
- tls ? tls_params : NULL);
- if (tevent_req_nomem(subreq, req)) {
- return tevent_req_post(req, ev);
- }
- tevent_req_set_callback(subreq, roh_connect_channel_out_done, req);
-
- return req;
-}
-
-static void roh_connect_channel_out_done(struct tevent_req *subreq)
-{
- struct tevent_req *req;
- struct roh_connect_channel_state *state;
- NTSTATUS status;
- int ret;
-
- req = tevent_req_callback_data(subreq, struct tevent_req);
- state = tevent_req_data(req, struct roh_connect_channel_state);
-
- ret = http_connect_recv(subreq,
- state->roh->default_channel_out,
- &state->roh->default_channel_out->http_conn);
- TALLOC_FREE(subreq);
- if (ret != 0) {
- status = map_nt_error_from_unix_common(ret);
- tevent_req_nterror(req, status);
- return;
- }
-
- DBG_DEBUG("HTTP connected\n");
- tevent_req_done(req);
-}
-
-NTSTATUS roh_connect_channel_out_recv(struct tevent_req *req)
-{
- NTSTATUS status;
-
- if (tevent_req_is_nterror(req, &status)) {
- tevent_req_received(req);
- return status;
- }
-
- tevent_req_received(req);
- return NT_STATUS_OK;
-}
-
struct roh_request_state {
struct http_request *request;
struct http_request *response;