2 Unix SMB/CIFS implementation.
4 local testing of RPC binding string parsing
6 Copyright (C) Jelmer Vernooij 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "librpc/gen_ndr/ndr_epmapper.h"
26 static BOOL test_BindingString(TALLOC_CTX *mem_ctx, const char *binding)
28 struct dcerpc_binding b, b2;
30 struct epm_tower tower;
34 status = dcerpc_parse_binding(mem_ctx, binding, &b);
35 if (NT_STATUS_IS_ERR(status)) {
36 DEBUG(0, ("Error parsing binding string '%s': %s\n", binding, nt_errstr(status)));
40 s = dcerpc_binding_string(mem_ctx, &b);
42 DEBUG(0, ("Error converting binding back to string for '%s'\n", binding));
46 if (strcasecmp(binding, s) != 0) {
47 DEBUG(0, ("Mismatch while comparing original and regenerated binding strings: '%s' <> '%s'\n", binding, s));
51 /* Generate protocol towers */
52 status = dcerpc_binding_build_tower(mem_ctx, &b, &tower);
53 if (NT_STATUS_IS_ERR(status)) {
54 DEBUG(0, ("Error generating protocol tower from '%s': %s\n", binding, nt_errstr(status)));
58 /* Convert back to binding and then back to string and compare */
60 status = dcerpc_binding_from_tower(mem_ctx, &tower, &b2);
61 if (NT_STATUS_IS_ERR(status)) {
62 DEBUG(0, ("Error generating binding from tower for original binding '%s': %s\n", binding, nt_errstr(status)));
66 /* Compare to a stripped down version of the binding string because
67 * the protocol tower doesn't contain the extra option data */
72 s = dcerpc_binding_string(mem_ctx, &b);
74 DEBUG(0, ("Error converting binding back to string for (stripped down) '%s'\n", binding));
79 s2 = dcerpc_binding_string(mem_ctx, &b2);
81 DEBUG(0, ("Error converting binding back to string for '%s'\n", binding));
85 if (strcasecmp(s, s2) != 0) {
86 DEBUG(0, ("Mismatch while comparing original and from protocol tower generated binding strings: '%s' <> '%s'\n", s, s2));
93 static const char *test_strings[] = {
96 "ncalrpc:[,Security=Sane]",
98 "ncacn_np:127.0.0.1[rpcecho]",
99 "ncacn_ip_tcp:127.0.0.1",
100 "ncacn_ip_tcp:127.0.0.1[20]",
101 "ncacn_ip_tcp:127.0.0.1[20,sign]",
102 "ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
103 "ncacn_http:127.0.0.1",
104 "ncacn_http:127.0.0.1[78]",
105 "ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",
106 "ncacn_np:localhost[rpcecho]",
107 "ncacn_np:[/pipe/rpcecho]",
108 "ncacn_np:localhost[/pipe/rpcecho,sign,seal]",
111 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:localhost",
112 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:127.0.0.1",
113 "ncacn_unix_stream:[/tmp/epmapper]",
114 "ncalrpc:[IDENTIFIER]",
115 "ncacn_unix_stream:[/tmp/epmapper,sign]",
118 BOOL torture_local_binding_string(void)
121 TALLOC_CTX *mem_ctx = talloc_init("test_BindingString");
124 for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
125 ret &= test_BindingString(mem_ctx, test_strings[i]);
128 talloc_free(mem_ctx);