librpc/rpc: avoid loosing data with dcerpc_binding_string() -> dcerpc_parse_binding()
authorStefan Metzmacher <metze@samba.org>
Fri, 7 Feb 2014 13:50:11 +0000 (14:50 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 13 Feb 2014 10:54:15 +0000 (11:54 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
librpc/rpc/binding.c

index 2b584b573268eaea9015ecc7a71784cd3899f2b0..6a9a5ea41c3dc8438fb63a8ec45df1675ac94959 100644 (file)
@@ -198,6 +198,8 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi
        char *o = s;
        int i;
        const char *t_name = NULL;
+       bool option_section = false;
+       const char *target_hostname = NULL;
 
        if (b->transport != NCA_UNKNOWN) {
                t_name = derpc_transport_string_by_transport(b->transport);
@@ -235,7 +237,28 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi
                }
        }
 
-       if (!b->endpoint && !b->options && !b->flags) {
+       target_hostname = b->target_hostname;
+       if (target_hostname != NULL && b->host != NULL) {
+               if (strcmp(target_hostname, b->host) == 0) {
+                       target_hostname = NULL;
+               }
+       }
+
+       if (b->endpoint) {
+               option_section = true;
+       } else if (target_hostname) {
+               option_section = true;
+       } else if (b->target_principal) {
+               option_section = true;
+       } else if (b->assoc_group_id != 0) {
+               option_section = true;
+       } else if (b->options) {
+               option_section = true;
+       } else if (b->flags) {
+               option_section = true;
+       }
+
+       if (!option_section) {
                return s;
        }
 
@@ -268,6 +291,36 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi
                }
        }
 
+       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;
+               }
+       }
+
+       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;
+               }
+       }
+
+       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;
+               }
+       }
+
        for (i=0;b->options && b->options[i];i++) {
                o = s;
                s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);