*/
_PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b)
{
- char *s = talloc_strdup(mem_ctx, "");
- char *o = s;
+ char *s = NULL;
+ char *tmp = NULL;
size_t i;
const char *t_name = NULL;
bool option_section = false;
const char *target_hostname = NULL;
+ s = talloc_strdup(mem_ctx, "");
+ if (s == NULL) {
+ goto nomem;
+ }
+
if (b->transport != NCA_UNKNOWN) {
t_name = derpc_transport_string_by_transport(b->transport);
if (!t_name) {
- talloc_free(o);
- return NULL;
+ goto nomem;
}
}
if (!GUID_all_zero(&b->object)) {
struct GUID_txt_buf buf;
- o = s;
- s = talloc_asprintf_append_buffer(
+ tmp = talloc_asprintf_append_buffer(
s, "%s@", GUID_buf_string(&b->object, &buf));
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
if (t_name != NULL) {
- o = s;
- s = talloc_asprintf_append_buffer(s, "%s:", t_name);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, "%s:", t_name);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
if (b->host) {
- o = s;
- s = talloc_asprintf_append_buffer(s, "%s", b->host);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, "%s", b->host);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
target_hostname = b->target_hostname;
return s;
}
- o = s;
- s = talloc_asprintf_append_buffer(s, "[");
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, "[");
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
if (b->endpoint) {
- o = s;
- s = talloc_asprintf_append_buffer(s, "%s", b->endpoint);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, "%s", b->endpoint);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
continue;
}
- o = s;
- s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(
+ s, ",%s", ncacn_options[i].name);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
if (target_hostname) {
- o = s;
- s = talloc_asprintf_append_buffer(s, ",target_hostname=%s",
- b->target_hostname);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(
+ s, ",target_hostname=%s", b->target_hostname);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
if (b->target_principal) {
- o = s;
- s = talloc_asprintf_append_buffer(s, ",target_principal=%s",
- b->target_principal);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(
+ s, ",target_principal=%s", b->target_principal);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
if (b->assoc_group_id != 0) {
- o = s;
- s = talloc_asprintf_append_buffer(s, ",assoc_group_id=0x%08x",
- b->assoc_group_id);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(
+ s, ",assoc_group_id=0x%08x", b->assoc_group_id);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
for (i=0;b->options && b->options[i];i++) {
- o = s;
- s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
}
- o = s;
- s = talloc_asprintf_append_buffer(s, "]");
- if (s == NULL) {
- talloc_free(o);
- return NULL;
+ tmp = talloc_asprintf_append_buffer(s, "]");
+ if (tmp == NULL) {
+ goto nomem;
}
+ s = tmp;
return s;
+nomem:
+ TALLOC_FREE(s);
+ return NULL;
}
/*