s3:rpc_client: avoid using dcerpc_binding internals in rpc_pipe_get_tcp_port()
authorStefan Metzmacher <metze@samba.org>
Thu, 30 Jan 2014 08:26:26 +0000 (09:26 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 13 Feb 2014 10:54:16 +0000 (11:54 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/rpc_client/cli_pipe.c

index 39ddb2e8b15ec39c5c53111d2aaa0873d30d6f63..0def81727a622a5f433c32bb96f3f4efc113d3c4 100644 (file)
@@ -2531,6 +2531,8 @@ static NTSTATUS rpc_pipe_get_tcp_port(const char *host,
        struct pipe_auth_data *auth = NULL;
        struct dcerpc_binding *map_binding = NULL;
        struct dcerpc_binding *res_binding = NULL;
+       enum dcerpc_transport_t transport;
+       const char *endpoint = NULL;
        struct epm_twr_t *map_tower = NULL;
        struct epm_twr_t *res_towers = NULL;
        struct policy_handle *entry_handle = NULL;
@@ -2574,16 +2576,17 @@ static NTSTATUS rpc_pipe_get_tcp_port(const char *host,
 
        /* create tower for asking the epmapper */
 
-       map_binding = talloc_zero(tmp_ctx, struct dcerpc_binding);
-       if (map_binding == NULL) {
-               status = NT_STATUS_NO_MEMORY;
+       status = dcerpc_parse_binding(tmp_ctx, "ncacn_ip_tcp:[135]",
+                                     &map_binding);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
 
-       map_binding->transport = NCACN_IP_TCP;
-       map_binding->object = table->syntax_id;
-       map_binding->host = NULL;
-       map_binding->endpoint = "135";
+       status = dcerpc_binding_set_abstract_syntax(map_binding,
+                                                   &table->syntax_id);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto done;
+       }
 
        map_tower = talloc_zero(tmp_ctx, struct epm_twr_t);
        if (map_tower == NULL) {
@@ -2648,13 +2651,21 @@ static NTSTATUS rpc_pipe_get_tcp_port(const char *host,
                goto done;
        }
 
+       transport = dcerpc_binding_get_transport(res_binding);
+       endpoint = dcerpc_binding_get_string_option(res_binding, "endpoint");
+
        /* are further checks here necessary? */
-       if (res_binding->transport != NCACN_IP_TCP) {
-               status = NT_STATUS_UNSUCCESSFUL;
+       if (transport != NCACN_IP_TCP) {
+               status = NT_STATUS_INVALID_NETWORK_RESPONSE;
+               goto done;
+       }
+
+       if (endpoint == NULL) {
+               status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                goto done;
        }
 
-       *pport = (uint16_t)atoi(res_binding->endpoint);
+       *pport = (uint16_t)atoi(endpoint);
 
 done:
        TALLOC_FREE(tmp_ctx);