diff options
-rw-r--r-- | librpc/rpc/dcerpc_util.c | 55 | ||||
-rw-r--r-- | librpc/rpc/rpc_common.h | 3 |
2 files changed, 58 insertions, 0 deletions
diff --git a/librpc/rpc/dcerpc_util.c b/librpc/rpc/dcerpc_util.c index de292c8366..980b0709db 100644 --- a/librpc/rpc/dcerpc_util.c +++ b/librpc/rpc/dcerpc_util.c @@ -318,3 +318,58 @@ NTSTATUS dcerpc_read_ncacn_packet_recv(struct tevent_req *req, tevent_req_received(req); return NT_STATUS_OK; } + +const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx, + enum dcerpc_transport_t transport, + const struct ndr_interface_table *table) +{ + NTSTATUS status; + const char *p = NULL; + const char *endpoint = NULL; + int i; + struct dcerpc_binding *default_binding = NULL; + TALLOC_CTX *frame = talloc_stackframe(); + + /* Find one of the default pipes for this interface */ + + for (i = 0; i < table->endpoints->count; i++) { + + status = dcerpc_parse_binding(frame, table->endpoints->names[i], + &default_binding); + if (NT_STATUS_IS_OK(status)) { + if (transport == NCA_UNKNOWN && + default_binding->endpoint != NULL) { + p = default_binding->endpoint; + break; + } + if (default_binding->transport == transport && + default_binding->endpoint != NULL) { + p = default_binding->endpoint; + break; + } + } + } + + if (i == table->endpoints->count || p == NULL) { + goto done; + } + + /* + * extract the pipe name without \\pipe from for example + * ncacn_np:[\\pipe\\epmapper] + */ + if (default_binding->transport == NCACN_NP) { + if (strncasecmp(p, "\\pipe\\", 6) == 0) { + p += 6; + } + if (strncmp(p, "\\", 1) == 0) { + p += 1; + } + } + + endpoint = talloc_strdup(mem_ctx, p); + + done: + talloc_free(frame); + return endpoint; +} diff --git a/librpc/rpc/rpc_common.h b/librpc/rpc/rpc_common.h index e2b37550e1..d2816f508b 100644 --- a/librpc/rpc/rpc_common.h +++ b/librpc/rpc/rpc_common.h @@ -143,6 +143,9 @@ void dcerpc_set_frag_length(DATA_BLOB *blob, uint16_t v); uint16_t dcerpc_get_frag_length(const DATA_BLOB *blob); void dcerpc_set_auth_length(DATA_BLOB *blob, uint16_t v); uint8_t dcerpc_get_endian_flag(DATA_BLOB *blob); +const char *dcerpc_default_transport_endpoint(TALLOC_CTX *mem_ctx, + enum dcerpc_transport_t transport, + const struct ndr_interface_table *table); /** * @brief Pull a dcerpc_auth structure, taking account of any auth |