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.
25 static BOOL test_BindingString(TALLOC_CTX *mem_ctx, const char *binding)
27 struct dcerpc_binding b, b2;
29 struct epm_tower tower;
33 status = dcerpc_parse_binding(mem_ctx, binding, &b);
34 if (NT_STATUS_IS_ERR(status)) {
35 DEBUG(0, ("Error parsing binding string '%s': %s\n", binding, nt_errstr(status)));
39 s = dcerpc_binding_string(mem_ctx, &b);
41 DEBUG(0, ("Error converting binding back to string for '%s'\n", binding));
45 if (strcasecmp(binding, s) != 0) {
46 DEBUG(0, ("Mismatch while comparing original and regenerated binding strings: '%s' <> '%s'\n", binding, s));
50 /* Generate protocol towers */
51 status = dcerpc_binding_build_tower(mem_ctx, &b, &tower);
52 if (NT_STATUS_IS_ERR(status)) {
53 DEBUG(0, ("Error generating protocol tower from '%s': %s\n", binding, nt_errstr(status)));
57 /* Convert back to binding and then back to string and compare */
59 status = dcerpc_binding_from_tower(mem_ctx, &tower, &b2);
60 if (NT_STATUS_IS_ERR(status)) {
61 DEBUG(0, ("Error generating binding from tower for original binding '%s': %s\n", binding, nt_errstr(status)));
65 /* Compare to a stripped down version of the binding string because
66 * the protocol tower doesn't contain the extra option data */
67 if (b.options && b.options[0]) {
73 s = dcerpc_binding_string(mem_ctx, &b);
75 DEBUG(0, ("Error converting binding back to string for (stripped down) '%s'\n", binding));
80 s2 = dcerpc_binding_string(mem_ctx, &b2);
82 DEBUG(0, ("Error converting binding back to string for '%s'\n", binding));
86 if (strcasecmp(s, s2) != 0) {
87 DEBUG(0, ("Mismatch while comparing original and from protocol tower generated binding strings: '%s' <> '%s'\n", s, s2));
94 static const char *test_strings[] = {
97 "ncalrpc:[,Security=Sane]",
99 "ncacn_np:127.0.0.1[rpcecho]",
100 "ncacn_ip_tcp:127.0.0.1",
101 "ncacn_np:localhost[rpcecho]",
102 "ncacn_np:[/pipe/rpcecho]",
103 "ncacn_np:localhost[/pipe/rpcecho,sign,seal]",
106 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:localhost",
107 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:127.0.0.1",
108 "ncacn_unix_stream:[/tmp/epmapper]",
109 "ncalrpc:[IDENTIFIER]",
110 "ncacn_unix_stream:[/tmp/epmapper,sign]",
113 BOOL torture_local_binding_string(int dummy)
116 TALLOC_CTX *mem_ctx = talloc_init("test_BindingString");
119 for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
120 ret &= test_BindingString(mem_ctx, test_strings[i]);
123 talloc_destroy(mem_ctx);