From f534dcdca3184a342df2d702663088a4afba6571 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 24 Mar 2011 14:39:37 +0100 Subject: librpc: Added a dcerpc_binding_dup() function. --- librpc/rpc/binding.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ librpc/rpc/rpc_common.h | 2 ++ 2 files changed, 82 insertions(+) (limited to 'librpc/rpc') diff --git a/librpc/rpc/binding.c b/librpc/rpc/binding.c index 2a0295b1e8..cc0aed931a 100644 --- a/librpc/rpc/binding.c +++ b/librpc/rpc/binding.c @@ -702,6 +702,86 @@ _PUBLIC_ NTSTATUS dcerpc_binding_from_tower(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +_PUBLIC_ struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx, + const struct dcerpc_binding *b) +{ + struct dcerpc_binding *n; + uint32_t count; + + n = talloc_zero(mem_ctx, struct dcerpc_binding); + if (n == NULL) { + return NULL; + } + + n->transport = b->transport; + n->object = b->object; + n->flags = b->flags; + n->assoc_group_id = b->assoc_group_id; + + if (b->host != NULL) { + n->host = talloc_strdup(n, b->host); + if (n->host == NULL) { + talloc_free(n); + return NULL; + } + } + + if (b->target_hostname != NULL) { + n->target_hostname = talloc_strdup(n, b->target_hostname); + if (n->target_hostname == NULL) { + talloc_free(n); + return NULL; + } + } + + if (b->target_principal != NULL) { + n->target_principal = talloc_strdup(n, b->target_principal); + if (n->target_principal == NULL) { + talloc_free(n); + return NULL; + } + } + + if (b->localaddress != NULL) { + n->localaddress = talloc_strdup(n, b->localaddress); + if (n->localaddress == NULL) { + talloc_free(n); + return NULL; + } + } + + if (b->endpoint != NULL) { + n->endpoint = talloc_strdup(n, b->endpoint); + if (n->endpoint == NULL) { + talloc_free(n); + return NULL; + } + } + + for (count = 0; b->options && b->options[count]; count++); + + if (count > 0) { + uint32_t i; + + n->options = talloc_array(n, const char *, count + 1); + if (n->options == NULL) { + talloc_free(n); + return NULL; + } + + for (i = 0; i < count; i++) { + n->options[i] = talloc_strdup(n->options, b->options[i]); + if (n->options[i] == NULL) { + talloc_free(n); + return NULL; + } + } + n->options[count] = NULL; + } + + return n; +} + _PUBLIC_ NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *binding, struct epm_tower *tower) diff --git a/librpc/rpc/rpc_common.h b/librpc/rpc/rpc_common.h index d0ffe61c2a..44c3cfd39b 100644 --- a/librpc/rpc/rpc_common.h +++ b/librpc/rpc/rpc_common.h @@ -117,6 +117,8 @@ NTSTATUS dcerpc_fault_to_nt_status(uint32_t fault_code); const char *epm_floor_string(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor); const char *dcerpc_floor_get_rhs_data(TALLOC_CTX *mem_ctx, struct epm_floor *epm_floor); enum dcerpc_transport_t dcerpc_transport_by_endpoint_protocol(int prot); +struct dcerpc_binding *dcerpc_binding_dup(TALLOC_CTX *mem_ctx, + const struct dcerpc_binding *b); NTSTATUS dcerpc_binding_build_tower(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *binding, struct epm_tower *tower); -- cgit