s4:librpc/rpc: Use generic roh_connect_channel_send/recv
authorSamuel Cabrero <scabrero@suse.de>
Tue, 6 Aug 2019 16:21:12 +0000 (18:21 +0200)
committerRalph Boehme <slow@samba.org>
Wed, 7 Aug 2019 14:12:40 +0000 (14:12 +0000)
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

source4/librpc/rpc/dcerpc_roh.c
source4/librpc/rpc/dcerpc_roh_channel_in.c
source4/librpc/rpc/dcerpc_roh_channel_out.c

index e614d130652f2cc32785c0da953059374f9eb184..33baa52c6186227bfeb00893de1472e33a126b18 100644 (file)
@@ -349,13 +349,13 @@ static void roh_continue_resolve_name(struct composite_context *ctx)
         * 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;
        }
@@ -372,20 +372,20 @@ static void roh_connect_channel_in_done(struct tevent_req *subreq)
        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;
        }
@@ -402,7 +402,8 @@ static void roh_connect_channel_out_done(struct tevent_req *subreq)
        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;
index bc630f77e4298e70c3e35700e84125b7aa0bba4a..50104527c3f84033fac2956b57cbad07b0a7caef 100644 (file)
 #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;
index 4a227823f4a5133d9bd67f017dde4ede1fa8bb3f..e431689d41984ded7f0508d95967c42292a88608 100644 (file)
 #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;