| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
test suite for epmapper rpc operations |
| 4 |
|
| 5 |
Copyright (C) Andrew Tridgell 2003 |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "includes.h" |
| 22 |
#include "librpc/gen_ndr/ndr_epmapper_c.h" |
| 23 |
#include "librpc/ndr/ndr_table.h" |
| 24 |
#include "librpc/rpc/dcerpc_proto.h" |
| 25 |
#include "torture/rpc/torture_rpc.h" |
| 26 |
#include "lib/util/util_net.h" |
| 27 |
#include "librpc/rpc/rpc_common.h" |
| 28 |
|
| 29 |
/* |
| 30 |
display any protocol tower |
| 31 |
*/ |
| 32 |
static void display_tower(struct torture_context *tctx, struct epm_tower *twr) |
| 33 |
{ |
| 34 |
int i; |
| 35 |
|
| 36 |
for (i = 0; i < twr->num_floors; i++) { |
| 37 |
torture_comment(tctx, |
| 38 |
" %s", |
| 39 |
epm_floor_string(tctx, &twr->floors[i])); |
| 40 |
} |
| 41 |
torture_comment(tctx, "\n"); |
| 42 |
} |
| 43 |
|
| 44 |
static bool test_Insert(struct torture_context *tctx, |
| 45 |
struct dcerpc_binding_handle *h, |
| 46 |
struct ndr_syntax_id object, |
| 47 |
const char *annotation, |
| 48 |
const struct dcerpc_binding *b) |
| 49 |
{ |
| 50 |
struct epm_Insert r; |
| 51 |
NTSTATUS status; |
| 52 |
|
| 53 |
r.in.num_ents = 1; |
| 54 |
r.in.entries = talloc_array(tctx, struct epm_entry_t, 1); |
| 55 |
|
| 56 |
if (torture_setting_bool(tctx, "samba4", false)) { |
| 57 |
torture_skip(tctx, "Skip Insert test against Samba4"); |
| 58 |
} |
| 59 |
|
| 60 |
/* FIXME zero */ |
| 61 |
ZERO_STRUCT(r.in.entries[0].object); |
| 62 |
r.in.entries[0].annotation = annotation; |
| 63 |
|
| 64 |
r.in.entries[0].tower = talloc(tctx, struct epm_twr_t); |
| 65 |
|
| 66 |
status = dcerpc_binding_build_tower(tctx, |
| 67 |
b, |
| 68 |
&r.in.entries[0].tower->tower); |
| 69 |
|
| 70 |
torture_assert_ntstatus_ok(tctx, |
| 71 |
status, |
| 72 |
"Unable to build tower from binding struct"); |
| 73 |
r.in.replace = 0; |
| 74 |
|
| 75 |
/* shoot! */ |
| 76 |
status = dcerpc_epm_Insert_r(h, tctx, &r); |
| 77 |
|
| 78 |
if (NT_STATUS_IS_ERR(status)) { |
| 79 |
torture_comment(tctx, |
| 80 |
"epm_Insert failed - %s\n", |
| 81 |
nt_errstr(status)); |
| 82 |
return false; |
| 83 |
} |
| 84 |
|
| 85 |
if (r.out.result != EPMAPPER_STATUS_OK) { |
| 86 |
torture_comment(tctx, |
| 87 |
"epm_Insert failed - internal error: 0x%.4x\n", |
| 88 |
r.out.result); |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
return true; |
| 93 |
} |
| 94 |
|
| 95 |
static bool test_Delete(struct torture_context *tctx, |
| 96 |
struct dcerpc_binding_handle *h, |
| 97 |
const char *annotation, |
| 98 |
const struct dcerpc_binding *b) |
| 99 |
{ |
| 100 |
NTSTATUS status; |
| 101 |
struct epm_Delete r; |
| 102 |
|
| 103 |
r.in.num_ents = 1; |
| 104 |
r.in.entries = talloc_array(tctx, struct epm_entry_t, 1); |
| 105 |
|
| 106 |
ZERO_STRUCT(r.in.entries[0].object); |
| 107 |
r.in.entries[0].annotation = annotation; |
| 108 |
|
| 109 |
r.in.entries[0].tower = talloc(tctx, struct epm_twr_t); |
| 110 |
|
| 111 |
status = dcerpc_binding_build_tower(tctx, |
| 112 |
b, |
| 113 |
&r.in.entries[0].tower->tower); |
| 114 |
|
| 115 |
torture_assert_ntstatus_ok(tctx, |
| 116 |
status, |
| 117 |
"Unable to build tower from binding struct"); |
| 118 |
r.in.num_ents = 1; |
| 119 |
|
| 120 |
status = dcerpc_epm_Delete_r(h, tctx, &r); |
| 121 |
if (NT_STATUS_IS_ERR(status)) { |
| 122 |
torture_comment(tctx, |
| 123 |
"epm_Delete failed - %s\n", |
| 124 |
nt_errstr(status)); |
| 125 |
return false; |
| 126 |
} |
| 127 |
|
| 128 |
if (r.out.result != EPMAPPER_STATUS_OK) { |
| 129 |
torture_comment(tctx, |
| 130 |
"epm_Delete failed - internal error: 0x%.4x\n", |
| 131 |
r.out.result); |
| 132 |
return false; |
| 133 |
} |
| 134 |
|
| 135 |
return true; |
| 136 |
} |
| 137 |
|
| 138 |
static bool test_Map_tcpip(struct torture_context *tctx, |
| 139 |
struct dcerpc_binding_handle *h, |
| 140 |
struct ndr_syntax_id map_syntax) |
| 141 |
{ |
| 142 |
struct epm_Map r; |
| 143 |
struct GUID uuid; |
| 144 |
struct policy_handle entry_handle; |
| 145 |
struct ndr_syntax_id syntax; |
| 146 |
struct dcerpc_binding *map_binding; |
| 147 |
struct epm_twr_t map_tower; |
| 148 |
struct epm_twr_p_t towers[20]; |
| 149 |
struct epm_tower t; |
| 150 |
uint32_t num_towers; |
| 151 |
uint32_t port; |
| 152 |
uint32_t i; |
| 153 |
long int p; |
| 154 |
const char *tmp; |
| 155 |
const char *ip; |
| 156 |
char *ptr; |
| 157 |
NTSTATUS status; |
| 158 |
|
| 159 |
torture_comment(tctx, "Testing epm_Map\n"); |
| 160 |
|
| 161 |
ZERO_STRUCT(uuid); |
| 162 |
ZERO_STRUCT(entry_handle); |
| 163 |
|
| 164 |
r.in.object = &uuid; |
| 165 |
r.in.map_tower = &map_tower; |
| 166 |
r.in.entry_handle = &entry_handle; |
| 167 |
r.out.entry_handle = &entry_handle; |
| 168 |
r.in.max_towers = 10; |
| 169 |
r.out.towers = towers; |
| 170 |
r.out.num_towers = &num_towers; |
| 171 |
|
| 172 |
/* Create map tower */ |
| 173 |
status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:[135]", &map_binding); |
| 174 |
torture_assert_ntstatus_ok(tctx, status, |
| 175 |
"epm_Map_tcpip failed: can't create map_binding"); |
| 176 |
|
| 177 |
status = dcerpc_binding_set_abstract_syntax(map_binding, &map_syntax); |
| 178 |
torture_assert_ntstatus_ok(tctx, status, |
| 179 |
"epm_Map_tcpip failed: set map_syntax"); |
| 180 |
|
| 181 |
status = dcerpc_binding_build_tower(tctx, map_binding, |
| 182 |
&map_tower.tower); |
| 183 |
torture_assert_ntstatus_ok(tctx, status, |
| 184 |
"epm_Map_tcpip failed: can't create map_tower"); |
| 185 |
|
| 186 |
torture_comment(tctx, |
| 187 |
"epm_Map request for '%s':\n", |
| 188 |
ndr_interface_name(&map_syntax.uuid, map_syntax.if_version)); |
| 189 |
display_tower(tctx, &r.in.map_tower->tower); |
| 190 |
|
| 191 |
status = dcerpc_epm_Map_r(h, tctx, &r); |
| 192 |
|
| 193 |
torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed"); |
| 194 |
torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, |
| 195 |
"epm_Map_tcpip failed: result is not EPMAPPER_STATUS_OK"); |
| 196 |
|
| 197 |
/* Check the result */ |
| 198 |
t = r.out.towers[0].twr->tower; |
| 199 |
|
| 200 |
/* Check if we got the correct RPC interface identifier */ |
| 201 |
dcerpc_floor_get_uuid_full(&t.floors[0], &syntax); |
| 202 |
torture_assert(tctx, ndr_syntax_id_equal(&syntax, &map_syntax), |
| 203 |
"epm_Map_tcpip failed: Interface identifier mismatch"); |
| 204 |
|
| 205 |
torture_comment(tctx, |
| 206 |
"epm_Map_tcpip response for '%s':\n", |
| 207 |
ndr_interface_name(&syntax.uuid, syntax.if_version)); |
| 208 |
|
| 209 |
dcerpc_floor_get_uuid_full(&t.floors[1], &syntax); |
| 210 |
torture_assert(tctx, ndr_syntax_id_equal(&syntax, &ndr_transfer_syntax_ndr), |
| 211 |
"epm_Map_tcpip failed: floor 2 is not NDR encoded"); |
| 212 |
|
| 213 |
torture_assert(tctx, t.floors[2].lhs.protocol == EPM_PROTOCOL_NCACN, |
| 214 |
"epm_Map_tcpip failed: floor 3 is not NCACN_IP_TCP"); |
| 215 |
|
| 216 |
tmp = dcerpc_floor_get_rhs_data(tctx, &t.floors[3]); |
| 217 |
p = strtol(tmp, &ptr, 10); |
| 218 |
port = p & 0xffff; |
| 219 |
torture_assert(tctx, port > 1024 && port < 65535, "epm_Map_tcpip failed"); |
| 220 |
|
| 221 |
ip = dcerpc_floor_get_rhs_data(tctx, &t.floors[4]); |
| 222 |
torture_assert(tctx, is_ipaddress(ip), "epm_Map_tcpip failed"); |
| 223 |
|
| 224 |
for (i = 0; i < *r.out.num_towers; i++) { |
| 225 |
if (r.out.towers[i].twr) { |
| 226 |
display_tower(tctx, &t); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
return true; |
| 231 |
} |
| 232 |
|
| 233 |
static bool test_Map_full(struct torture_context *tctx, |
| 234 |
struct dcerpc_pipe *p) |
| 235 |
{ |
| 236 |
const struct ndr_syntax_id obj = { |
| 237 |
{ 0x8a885d04, 0x1ceb, 0x11c9, {0x9f, 0xe8}, {0x08,0x00,0x2b,0x10,0x48,0x60} }, |
| 238 |
2 |
| 239 |
}; |
| 240 |
struct dcerpc_binding_handle *h = p->binding_handle; |
| 241 |
const char *annotation = "SMBTORTURE"; |
| 242 |
struct dcerpc_binding *b; |
| 243 |
NTSTATUS status; |
| 244 |
bool ok; |
| 245 |
|
| 246 |
status = dcerpc_parse_binding(tctx, "ncacn_ip_tcp:216.83.154.106[41768]", &b); |
| 247 |
torture_assert_ntstatus_ok(tctx, |
| 248 |
status, |
| 249 |
"Unable to generate dcerpc_binding struct"); |
| 250 |
status = dcerpc_binding_set_abstract_syntax(b, &obj); |
| 251 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_binding_set_abstract_syntax"); |
| 252 |
|
| 253 |
ok = test_Insert(tctx, h, obj, annotation, b); |
| 254 |
torture_assert(tctx, ok, "test_Insert failed"); |
| 255 |
|
| 256 |
ok = test_Map_tcpip(tctx, h, obj); |
| 257 |
torture_assert(tctx, ok, "test_Map_tcpip failed"); |
| 258 |
|
| 259 |
ok = test_Delete(tctx, h, annotation, b); |
| 260 |
torture_assert(tctx, ok, "test_Delete failed"); |
| 261 |
|
| 262 |
return true; |
| 263 |
} |
| 264 |
|
| 265 |
static bool test_Map_display(struct dcerpc_binding_handle *b, |
| 266 |
struct torture_context *tctx, |
| 267 |
struct epm_entry_t *entry) |
| 268 |
|
| 269 |
{ |
| 270 |
NTSTATUS status; |
| 271 |
struct epm_twr_t *twr = entry->tower; |
| 272 |
struct epm_Map r; |
| 273 |
struct GUID uuid = entry->object; |
| 274 |
struct policy_handle handle; |
| 275 |
struct ndr_syntax_id syntax; |
| 276 |
uint32_t num_towers; |
| 277 |
uint32_t i; |
| 278 |
|
| 279 |
ZERO_STRUCT(handle); |
| 280 |
|
| 281 |
r.in.object = &uuid; |
| 282 |
r.in.map_tower = twr; |
| 283 |
r.in.entry_handle = &handle; |
| 284 |
r.out.entry_handle = &handle; |
| 285 |
r.in.max_towers = 10; |
| 286 |
r.out.num_towers = &num_towers; |
| 287 |
|
| 288 |
dcerpc_floor_get_uuid_full(&twr->tower.floors[0], &syntax); |
| 289 |
|
| 290 |
torture_comment(tctx, |
| 291 |
"epm_Map results for '%s':\n", |
| 292 |
ndr_interface_name(&syntax.uuid, syntax.if_version)); |
| 293 |
|
| 294 |
status = dcerpc_epm_Map_r(b, tctx, &r); |
| 295 |
if (NT_STATUS_IS_OK(status) && r.out.result == 0) { |
| 296 |
for (i=0;i<*r.out.num_towers;i++) { |
| 297 |
if (r.out.towers[i].twr) { |
| 298 |
display_tower(tctx, &r.out.towers[i].twr->tower); |
| 299 |
} |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
/* RPC protocol identifier */ |
| 304 |
twr->tower.floors[2].lhs.protocol = EPM_PROTOCOL_NCACN; |
| 305 |
twr->tower.floors[2].lhs.lhs_data = data_blob(NULL, 0); |
| 306 |
twr->tower.floors[2].rhs.ncacn.minor_version = 0; |
| 307 |
|
| 308 |
/* Port address */ |
| 309 |
twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_TCP; |
| 310 |
twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0); |
| 311 |
twr->tower.floors[3].rhs.tcp.port = 0; |
| 312 |
|
| 313 |
/* Transport */ |
| 314 |
twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_IP; |
| 315 |
twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0); |
| 316 |
twr->tower.floors[4].rhs.ip.ipaddr = "0.0.0.0"; |
| 317 |
|
| 318 |
status = dcerpc_epm_Map_r(b, tctx, &r); |
| 319 |
if (NT_STATUS_IS_OK(status) && r.out.result == 0) { |
| 320 |
for (i=0;i<*r.out.num_towers;i++) { |
| 321 |
if (r.out.towers[i].twr) { |
| 322 |
display_tower(tctx, &r.out.towers[i].twr->tower); |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_HTTP; |
| 328 |
twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0); |
| 329 |
twr->tower.floors[3].rhs.http.port = 0; |
| 330 |
|
| 331 |
status = dcerpc_epm_Map_r(b, tctx, &r); |
| 332 |
if (NT_STATUS_IS_OK(status) && r.out.result == 0) { |
| 333 |
for (i=0;i<*r.out.num_towers;i++) { |
| 334 |
if (r.out.towers[i].twr) { |
| 335 |
display_tower(tctx, &r.out.towers[i].twr->tower); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_UDP; |
| 341 |
twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0); |
| 342 |
twr->tower.floors[3].rhs.udp.port = 0; |
| 343 |
|
| 344 |
status = dcerpc_epm_Map_r(b, tctx, &r); |
| 345 |
if (NT_STATUS_IS_OK(status) && r.out.result == 0) { |
| 346 |
for (i=0;i<*r.out.num_towers;i++) { |
| 347 |
if (r.out.towers[i].twr) { |
| 348 |
display_tower(tctx, &r.out.towers[i].twr->tower); |
| 349 |
} |
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
twr->tower.floors[3].lhs.protocol = EPM_PROTOCOL_SMB; |
| 354 |
twr->tower.floors[3].lhs.lhs_data = data_blob(NULL, 0); |
| 355 |
twr->tower.floors[3].rhs.smb.unc = ""; |
| 356 |
|
| 357 |
twr->tower.floors[4].lhs.protocol = EPM_PROTOCOL_NETBIOS; |
| 358 |
twr->tower.floors[4].lhs.lhs_data = data_blob(NULL, 0); |
| 359 |
twr->tower.floors[4].rhs.netbios.name = ""; |
| 360 |
|
| 361 |
status = dcerpc_epm_Map_r(b, tctx, &r); |
| 362 |
if (NT_STATUS_IS_OK(status) && r.out.result == 0) { |
| 363 |
for (i = 0; i < *r.out.num_towers; i++) { |
| 364 |
if (r.out.towers[i].twr) { |
| 365 |
display_tower(tctx, &r.out.towers[i].twr->tower); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
|
| 370 |
/* FIXME: Extend to do other protocols as well (ncacn_unix_stream, ncalrpc) */ |
| 371 |
|
| 372 |
return true; |
| 373 |
} |
| 374 |
|
| 375 |
static bool test_Map_simple(struct torture_context *tctx, |
| 376 |
struct dcerpc_pipe *p) |
| 377 |
{ |
| 378 |
NTSTATUS status; |
| 379 |
struct epm_Lookup r; |
| 380 |
struct policy_handle entry_handle; |
| 381 |
uint32_t num_ents = 0; |
| 382 |
struct dcerpc_binding_handle *h = p->binding_handle; |
| 383 |
|
| 384 |
ZERO_STRUCT(entry_handle); |
| 385 |
|
| 386 |
torture_comment(tctx, "Testing epm_Map\n"); |
| 387 |
|
| 388 |
/* get all elements */ |
| 389 |
r.in.inquiry_type = RPC_C_EP_ALL_ELTS; |
| 390 |
r.in.object = NULL; |
| 391 |
r.in.interface_id = NULL; |
| 392 |
r.in.vers_option = RPC_C_VERS_ALL; |
| 393 |
|
| 394 |
r.in.entry_handle = &entry_handle; |
| 395 |
r.in.max_ents = 10; |
| 396 |
|
| 397 |
r.out.entry_handle = &entry_handle; |
| 398 |
r.out.num_ents = &num_ents; |
| 399 |
|
| 400 |
do { |
| 401 |
int i; |
| 402 |
|
| 403 |
status = dcerpc_epm_Lookup_r(h, tctx, &r); |
| 404 |
if (!NT_STATUS_IS_OK(status) || |
| 405 |
r.out.result != EPMAPPER_STATUS_OK) { |
| 406 |
break; |
| 407 |
} |
| 408 |
|
| 409 |
for (i = 0; i < *r.out.num_ents; i++) { |
| 410 |
if (r.out.entries[i].tower->tower.num_floors == 5) { |
| 411 |
test_Map_display(h, tctx, &r.out.entries[i]); |
| 412 |
} |
| 413 |
} |
| 414 |
} while (NT_STATUS_IS_OK(status) && |
| 415 |
r.out.result == EPMAPPER_STATUS_OK && |
| 416 |
*r.out.num_ents == r.in.max_ents && |
| 417 |
!ndr_policy_handle_empty(&entry_handle)); |
| 418 |
|
| 419 |
torture_assert_ntstatus_ok(tctx, status, "epm_Map_simple failed"); |
| 420 |
|
| 421 |
torture_assert(tctx, |
| 422 |
ndr_policy_handle_empty(&entry_handle), |
| 423 |
"epm_Map_simple failed - The policy handle should be empty."); |
| 424 |
|
| 425 |
return true; |
| 426 |
} |
| 427 |
|
| 428 |
static bool test_LookupHandleFree(struct torture_context *tctx, |
| 429 |
struct dcerpc_binding_handle *h, |
| 430 |
struct policy_handle *entry_handle) { |
| 431 |
NTSTATUS status; |
| 432 |
struct epm_LookupHandleFree r; |
| 433 |
|
| 434 |
if (ndr_policy_handle_empty(entry_handle)) { |
| 435 |
torture_comment(tctx, |
| 436 |
"epm_LookupHandleFree failed - empty policy_handle\n"); |
| 437 |
return false; |
| 438 |
} |
| 439 |
|
| 440 |
r.in.entry_handle = entry_handle; |
| 441 |
r.out.entry_handle = entry_handle; |
| 442 |
|
| 443 |
status = dcerpc_epm_LookupHandleFree_r(h, tctx, &r); |
| 444 |
if (NT_STATUS_IS_ERR(status)) { |
| 445 |
torture_comment(tctx, |
| 446 |
"epm_LookupHandleFree failed - %s\n", |
| 447 |
nt_errstr(status)); |
| 448 |
return false; |
| 449 |
} |
| 450 |
|
| 451 |
if (r.out.result != EPMAPPER_STATUS_OK) { |
| 452 |
torture_comment(tctx, |
| 453 |
"epm_LookupHandleFree failed - internal error: " |
| 454 |
"0x%.4x\n", |
| 455 |
r.out.result); |
| 456 |
return false; |
| 457 |
} |
| 458 |
|
| 459 |
return true; |
| 460 |
} |
| 461 |
|
| 462 |
static bool test_Lookup_simple(struct torture_context *tctx, |
| 463 |
struct dcerpc_pipe *p) |
| 464 |
{ |
| 465 |
NTSTATUS status; |
| 466 |
struct epm_Lookup r; |
| 467 |
struct policy_handle entry_handle; |
| 468 |
uint32_t num_ents = 0; |
| 469 |
struct dcerpc_binding_handle *h = p->binding_handle; |
| 470 |
|
| 471 |
ZERO_STRUCT(entry_handle); |
| 472 |
|
| 473 |
torture_comment(tctx, "Testing epm_Lookup\n"); |
| 474 |
|
| 475 |
/* get all elements */ |
| 476 |
r.in.inquiry_type = RPC_C_EP_ALL_ELTS; |
| 477 |
r.in.object = NULL; |
| 478 |
r.in.interface_id = NULL; |
| 479 |
r.in.vers_option = RPC_C_VERS_ALL; |
| 480 |
|
| 481 |
r.in.entry_handle = &entry_handle; |
| 482 |
r.in.max_ents = 10; |
| 483 |
|
| 484 |
r.out.entry_handle = &entry_handle; |
| 485 |
r.out.num_ents = &num_ents; |
| 486 |
|
| 487 |
do { |
| 488 |
int i; |
| 489 |
|
| 490 |
status = dcerpc_epm_Lookup_r(h, tctx, &r); |
| 491 |
if (!NT_STATUS_IS_OK(status) || |
| 492 |
r.out.result != EPMAPPER_STATUS_OK) { |
| 493 |
break; |
| 494 |
} |
| 495 |
|
| 496 |
torture_comment(tctx, |
| 497 |
"epm_Lookup returned %d events, entry_handle: %s\n", |
| 498 |
*r.out.num_ents, |
| 499 |
GUID_string(tctx, &entry_handle.uuid)); |
| 500 |
|
| 501 |
for (i = 0; i < *r.out.num_ents; i++) { |
| 502 |
torture_comment(tctx, |
| 503 |
"\n Found '%s' Object[%s]\n", |
| 504 |
r.out.entries[i].annotation, |
| 505 |
GUID_string(tctx, &r.out.entries[i].object)); |
| 506 |
|
| 507 |
display_tower(tctx, &r.out.entries[i].tower->tower); |
| 508 |
} |
| 509 |
} while (NT_STATUS_IS_OK(status) && |
| 510 |
r.out.result == EPMAPPER_STATUS_OK && |
| 511 |
*r.out.num_ents == r.in.max_ents && |
| 512 |
!ndr_policy_handle_empty(&entry_handle)); |
| 513 |
|
| 514 |
torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed"); |
| 515 |
torture_assert(tctx, r.out.result == EPMAPPER_STATUS_NO_MORE_ENTRIES, "epm_Lookup failed"); |
| 516 |
|
| 517 |
torture_assert(tctx, |
| 518 |
ndr_policy_handle_empty(&entry_handle), |
| 519 |
"epm_Lookup failed - The policy handle should be empty."); |
| 520 |
|
| 521 |
return true; |
| 522 |
} |
| 523 |
|
| 524 |
/* |
| 525 |
* This test starts a epm_Lookup request, but doesn't finish the |
| 526 |
* call terminates the search. So it will call epm_LookupHandleFree. |
| 527 |
*/ |
| 528 |
static bool test_Lookup_terminate_search(struct torture_context *tctx, |
| 529 |
struct dcerpc_pipe *p) |
| 530 |
{ |
| 531 |
bool ok; |
| 532 |
NTSTATUS status; |
| 533 |
struct epm_Lookup r; |
| 534 |
struct policy_handle entry_handle; |
| 535 |
uint32_t i, num_ents = 0; |
| 536 |
struct dcerpc_binding_handle *h = p->binding_handle; |
| 537 |
|
| 538 |
ZERO_STRUCT(entry_handle); |
| 539 |
|
| 540 |
torture_comment(tctx, "Testing epm_Lookup and epm_LookupHandleFree\n"); |
| 541 |
|
| 542 |
/* get all elements */ |
| 543 |
r.in.inquiry_type = RPC_C_EP_ALL_ELTS; |
| 544 |
r.in.object = NULL; |
| 545 |
r.in.interface_id = NULL; |
| 546 |
r.in.vers_option = RPC_C_VERS_ALL; |
| 547 |
|
| 548 |
r.in.entry_handle = &entry_handle; |
| 549 |
r.in.max_ents = 2; |
| 550 |
|
| 551 |
r.out.entry_handle = &entry_handle; |
| 552 |
r.out.num_ents = &num_ents; |
| 553 |
|
| 554 |
status = dcerpc_epm_Lookup_r(h, tctx, &r); |
| 555 |
|
| 556 |
torture_assert_ntstatus_ok(tctx, status, "epm_Lookup failed"); |
| 557 |
torture_assert(tctx, r.out.result == EPMAPPER_STATUS_OK, "epm_Lookup failed"); |
| 558 |
|
| 559 |
torture_comment(tctx, |
| 560 |
"epm_Lookup returned %d events, entry_handle: %s\n", |
| 561 |
*r.out.num_ents, |
| 562 |
GUID_string(tctx, &entry_handle.uuid)); |
| 563 |
|
| 564 |
for (i = 0; i < *r.out.num_ents; i++) { |
| 565 |
torture_comment(tctx, |
| 566 |
"\n Found '%s'\n", |
| 567 |
r.out.entries[i].annotation); |
| 568 |
} |
| 569 |
|
| 570 |
ok = test_LookupHandleFree(tctx, |
| 571 |
h, |
| 572 |
&entry_handle); |
| 573 |
if (!ok) { |
| 574 |
return false; |
| 575 |
} |
| 576 |
|
| 577 |
return true; |
| 578 |
} |
| 579 |
|
| 580 |
static bool test_Insert_noreplace(struct torture_context *tctx, |
| 581 |
struct dcerpc_pipe *p) |
| 582 |
{ |
| 583 |
bool ok; |
| 584 |
NTSTATUS status; |
| 585 |
struct epm_Insert r; |
| 586 |
struct dcerpc_binding *b; |
| 587 |
struct dcerpc_binding_handle *h = p->binding_handle; |
| 588 |
|
| 589 |
torture_comment(tctx, "Testing epm_Insert(noreplace) and epm_Delete\n"); |
| 590 |
|
| 591 |
if (torture_setting_bool(tctx, "samba4", false)) { |
| 592 |
torture_skip(tctx, "Skip Insert test against Samba4"); |
| 593 |
} |
| 594 |
|
| 595 |
r.in.num_ents = 1; |
| 596 |
r.in.entries = talloc_array(tctx, struct epm_entry_t, 1); |
| 597 |
|
| 598 |
ZERO_STRUCT(r.in.entries[0].object); |
| 599 |
r.in.entries[0].annotation = "smbtorture endpoint"; |
| 600 |
|
| 601 |
status = dcerpc_parse_binding(tctx, "ncalrpc:[SMBTORTURE]", &b); |
| 602 |
torture_assert_ntstatus_ok(tctx, |
| 603 |
status, |
| 604 |
"Unable to generate dcerpc_binding struct"); |
| 605 |
|
| 606 |
r.in.entries[0].tower = talloc(tctx, struct epm_twr_t); |
| 607 |
|
| 608 |
status = dcerpc_binding_build_tower(tctx, |
| 609 |
b, |
| 610 |
&r.in.entries[0].tower->tower); |
| 611 |
torture_assert_ntstatus_ok(tctx, |
| 612 |
status, |
| 613 |
"Unable to build tower from binding struct"); |
| 614 |
r.in.replace = 0; |
| 615 |
|
| 616 |
status = dcerpc_epm_Insert_r(h, tctx, &r); |
| 617 |
torture_assert_ntstatus_ok(tctx, status, "epm_Insert failed"); |
| 618 |
|
| 619 |
torture_assert(tctx, r.out.result == 0, "epm_Insert failed"); |
| 620 |
|
| 621 |
ok = test_Delete(tctx, h, "smbtorture", b); |
| 622 |
if (!ok) { |
| 623 |
return false; |
| 624 |
} |
| 625 |
|
| 626 |
return true; |
| 627 |
} |
| 628 |
|
| 629 |
#if 0 |
| 630 |
/* |
| 631 |
* The MS-RPCE documentation states that this function isn't implemented and |
| 632 |
* SHOULD NOT be called by a client. |
| 633 |
*/ |
| 634 |
static bool test_InqObject(struct torture_context *tctx, struct dcerpc_pipe *p) |
| 635 |
{ |
| 636 |
NTSTATUS status; |
| 637 |
struct epm_InqObject r; |
| 638 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 639 |
|
| 640 |
r.in.epm_object = talloc(tctx, struct GUID); |
| 641 |
*r.in.epm_object = ndr_table_epmapper.syntax_id.uuid; |
| 642 |
|
| 643 |
status = dcerpc_epm_InqObject_r(b, tctx, &r); |
| 644 |
torture_assert_ntstatus_ok(tctx, status, "InqObject failed"); |
| 645 |
|
| 646 |
return true; |
| 647 |
} |
| 648 |
#endif |
| 649 |
|
| 650 |
struct torture_suite *torture_rpc_epmapper(TALLOC_CTX *mem_ctx) |
| 651 |
{ |
| 652 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "epmapper"); |
| 653 |
struct torture_rpc_tcase *tcase; |
| 654 |
|
| 655 |
tcase = torture_suite_add_rpc_iface_tcase(suite, |
| 656 |
"epmapper", |
| 657 |
&ndr_table_epmapper); |
| 658 |
|
| 659 |
/* This is a stack */ |
| 660 |
torture_rpc_tcase_add_test(tcase, |
| 661 |
"Map_simple", |
| 662 |
test_Map_simple); |
| 663 |
torture_rpc_tcase_add_test(tcase, |
| 664 |
"Map_full", |
| 665 |
test_Map_full); |
| 666 |
torture_rpc_tcase_add_test(tcase, |
| 667 |
"Lookup_simple", |
| 668 |
test_Lookup_simple); |
| 669 |
torture_rpc_tcase_add_test(tcase, |
| 670 |
"Lookup_terminate_search", |
| 671 |
test_Lookup_terminate_search); |
| 672 |
torture_rpc_tcase_add_test(tcase, |
| 673 |
"Insert_noreplace", |
| 674 |
test_Insert_noreplace); |
| 675 |
|
| 676 |
return suite; |
| 677 |
} |
| 678 |
|
| 679 |
/* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */ |