source: trunk/server/source4/librpc/tests/binding_string.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 7.0 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3
4 local testing of RPC binding string parsing
5
6 Copyright (C) Jelmer Vernooij 2004
7
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 3 of the License, or
11 (at your option) any later version.
12
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.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#include "includes.h"
23#include "librpc/gen_ndr/epmapper.h"
24#include "librpc/rpc/dcerpc.h"
25#include "librpc/rpc/dcerpc_proto.h"
26#include "torture/torture.h"
27#include "lib/util/util_net.h"
28
29static bool test_BindingString(struct torture_context *tctx,
30 const void *test_data)
31{
32 const char *binding = test_data;
33 struct dcerpc_binding *b, *b2;
34 const char *s, *s2;
35 struct epm_tower tower;
36 TALLOC_CTX *mem_ctx = tctx;
37
38 /* Parse */
39 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(mem_ctx, binding, &b),
40 "Error parsing binding string");
41
42 s = dcerpc_binding_string(mem_ctx, b);
43 torture_assert(tctx, s != NULL, "Error converting binding back to string");
44
45 torture_assert_casestr_equal(tctx, binding, s,
46 "Mismatch while comparing original and regenerated binding strings");
47
48 /* Generate protocol towers */
49 torture_assert_ntstatus_ok(tctx, dcerpc_binding_build_tower(mem_ctx, b, &tower),
50 "Error generating protocol tower");
51
52 /* Convert back to binding and then back to string and compare */
53
54 torture_assert_ntstatus_ok(tctx, dcerpc_binding_from_tower(mem_ctx, &tower, &b2),
55 "Error generating binding from tower for original binding");
56
57 /* Compare to a stripped down version of the binding string because
58 * the protocol tower doesn't contain the extra option data */
59 b->options = NULL;
60
61 b->flags = 0;
62
63 s = dcerpc_binding_string(mem_ctx, b);
64 torture_assert(tctx, s != NULL, "Error converting binding back to string for (stripped down)");
65
66 s2 = dcerpc_binding_string(mem_ctx, b2);
67 torture_assert(tctx, s != NULL, "Error converting binding back to string");
68
69 if (is_ipaddress(b->host))
70 torture_assert_casestr_equal(tctx, s, s2, "Mismatch while comparing original and from protocol tower generated binding strings");
71
72 return true;
73}
74
75static const char *test_strings[] = {
76 "ncacn_np:",
77 "ncalrpc:",
78 "ncalrpc:[,Security=Sane]",
79 "ncacn_np:[rpcecho]",
80 "ncacn_np:127.0.0.1[rpcecho]",
81 "ncacn_ip_tcp:127.0.0.1",
82 "ncacn_ip_tcp:127.0.0.1[20]",
83 "ncacn_ip_tcp:127.0.0.1[20,sign]",
84 "ncacn_ip_tcp:127.0.0.1[20,Security=Foobar,sign]",
85 "ncacn_http:127.0.0.1",
86 "ncacn_http:127.0.0.1[78]",
87 "ncacn_http:127.0.0.1[78,ProxyServer=myproxy:3128]",
88 "ncacn_np:localhost[rpcecho]",
89 "ncacn_np:[/pipe/rpcecho]",
90 "ncacn_np:localhost[/pipe/rpcecho,sign,seal]",
91 "ncacn_np:[,sign]",
92 "ncadg_ip_udp:",
93 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:localhost",
94 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:127.0.0.1",
95 "ncacn_unix_stream:[/tmp/epmapper]",
96 "ncalrpc:[IDENTIFIER]",
97 "ncacn_unix_stream:[/tmp/epmapper,sign]",
98};
99
100static bool test_parse_check_results(struct torture_context *tctx)
101{
102 struct dcerpc_binding *b;
103 struct GUID uuid;
104
105 torture_assert_ntstatus_ok(tctx,
106 GUID_from_string("308FB580-1EB2-11CA-923B-08002B1075A7", &uuid),
107 "parsing uuid");
108
109 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER", &b), "parse");
110 torture_assert(tctx, b->transport == NCACN_NP, "ncacn_np expected");
111 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER", &b), "parse");
112 torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
113 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[rpcecho]", &b), "parse");
114 torture_assert_str_equal(tctx, b->endpoint, "rpcecho", "endpoint");
115 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[/pipe/rpcecho]", &b), "parse");
116 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[/pipe/rpcecho,sign,seal]", &b), "parse");
117 torture_assert(tctx, b->flags == DCERPC_SIGN+DCERPC_SEAL, "sign+seal flags");
118 torture_assert_str_equal(tctx, b->endpoint, "/pipe/rpcecho", "endpoint");
119 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_np:$SERVER[,sign]", &b), "parse");
120 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign]", &b), "parse");
121 torture_assert(tctx, b->endpoint == NULL, "endpoint");
122 torture_assert(tctx, b->flags == DCERPC_SIGN, "sign flag");
123 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncalrpc:", &b), "parse");
124 torture_assert(tctx, b->transport == NCALRPC, "ncalrpc expected");
125 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
126 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_np:$SERVER", &b), "parse");
127 torture_assert(tctx, GUID_equal(&b->object.uuid, &uuid), "object uuid");
128 torture_assert_int_equal(tctx, b->object.if_version, 0, "object version");
129 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx,
130 "308FB580-1EB2-11CA-923B-08002B1075A7@ncacn_ip_tcp:$SERVER", &b), "parse");
131 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]", &b), "parse");
132 torture_assert(tctx, b->transport == NCACN_IP_TCP, "ncacn_ip_tcp expected");
133 torture_assert(tctx, b->flags == (DCERPC_SIGN | DCERPC_LOCALADDRESS), "sign flag");
134 torture_assert_str_equal(tctx, b->localaddress, "192.168.1.1", "localaddress");
135 torture_assert_str_equal(tctx, "ncacn_ip_tcp:$SERVER[,sign,localaddress=192.168.1.1]",
136 dcerpc_binding_string(tctx, b), "back to string");
137
138 return true;
139}
140
141static bool test_no_transport(struct torture_context *tctx)
142{
143 const char *binding = "somehost";
144 struct dcerpc_binding *b;
145 const char *s;
146
147 /* Parse */
148 torture_assert_ntstatus_ok(tctx, dcerpc_parse_binding(tctx, binding, &b),
149 "Error parsing binding string");
150
151 torture_assert(tctx, b->transport == NCA_UNKNOWN, "invalid transport");
152
153 s = dcerpc_binding_string(tctx, b);
154 torture_assert(tctx, s != NULL, "Error converting binding back to string");
155
156 torture_assert_casestr_equal(tctx, binding, s,
157 "Mismatch while comparing original and regenerated binding strings");
158
159 return true;
160}
161
162struct torture_suite *torture_local_binding_string(TALLOC_CTX *mem_ctx)
163{
164 int i;
165 struct torture_suite *suite = torture_suite_create(mem_ctx, "binding");
166
167 for (i = 0; i < ARRAY_SIZE(test_strings); i++) {
168 torture_suite_add_simple_tcase_const(suite, test_strings[i],
169 test_BindingString,
170 test_strings[i]);
171 }
172
173 torture_suite_add_simple_test(suite, "no transport",test_no_transport);
174
175 torture_suite_add_simple_test(suite, "parsing results",
176 test_parse_check_results);
177
178 return suite;
179}
Note: See TracBrowser for help on using the repository browser.