librpc/rpc: let derpc_binding_string() add ncacn_options before key=value options
authorStefan Metzmacher <metze@samba.org>
Fri, 24 Jan 2014 08:24:49 +0000 (09:24 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 13 Feb 2014 10:54:14 +0000 (11:54 +0100)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
librpc/rpc/binding.c
source4/librpc/tests/binding_string.c

index d55939031f69434f37a1e7e65e7beb285b37e908..975ee554f87cf9aea996c9d2b6a6b037692c4b11 100644 (file)
@@ -238,28 +238,27 @@ _PUBLIC_ char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_bi
                }
        }
 
-       /* this is a *really* inefficent way of dealing with strings,
-          but this is rarely called and the strings are always short,
-          so I don't care */
-       for (i=0;b->options && b->options[i];i++) {
+       for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
+               if (!(b->flags & ncacn_options[i].flag)) {
+                       continue;
+               }
+
                o = s;
-               s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);
+               if (ncacn_options[i].flag == DCERPC_LOCALADDRESS && b->localaddress) {
+                       s = talloc_asprintf_append_buffer(s, ",%s=%s", ncacn_options[i].name,
+                                                         b->localaddress);
+               } else {
+                       s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
+               }
                if (s == NULL) {
                        talloc_free(o);
                        return NULL;
                }
        }
 
-       for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
+       for (i=0;b->options && b->options[i];i++) {
                o = s;
-               if (b->flags & ncacn_options[i].flag) {
-                       if (ncacn_options[i].flag == DCERPC_LOCALADDRESS && b->localaddress) {
-                               s = talloc_asprintf_append_buffer(s, ",%s=%s", ncacn_options[i].name,
-                                                                 b->localaddress);
-                       } else {
-                               s = talloc_asprintf_append_buffer(s, ",%s", ncacn_options[i].name);
-                       }
-               }
+               s = talloc_asprintf_append_buffer(s, ",%s", b->options[i]);
                if (s == NULL) {
                        talloc_free(o);
                        return NULL;
index fcefd69488dd11cb8929a8d9417c34e352ce661f..d3150e217629d619a3b19253929613fca44e8ea4 100644 (file)
@@ -82,7 +82,7 @@ static const char *test_strings[] = {
        "ncacn_ip_tcp:127.0.0.1",
        "ncacn_ip_tcp:127.0.0.1[20]",
        "ncacn_ip_tcp:127.0.0.1[20,sign]",
-       "ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
+       "ncacn_ip_tcp:127.0.0.1[20,sign,Security=Foobar]",
        "ncacn_http:127.0.0.1",
        "ncacn_http:127.0.0.1[78]",
        "ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",