s4:lib/messaging: terminate the irpc_servers_byname() result with server_id_set_disco...
[Samba/gebeck_regimport.git] / source4 / torture / rpc / bind.c
blob457dbd95754c2dc3618c83d342ee4c7fcfd166c0
1 /*
2 Unix SMB/CIFS implementation.
3 test suite for rpc bind operations
5 Copyright (C) Guenther Deschner 2010
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "torture/rpc/torture_rpc.h"
24 #include "librpc/gen_ndr/ndr_lsa_c.h"
25 #include "lib/cmdline/popt_common.h"
27 static bool test_openpolicy(struct torture_context *tctx,
28 struct dcerpc_pipe *p)
30 struct dcerpc_binding_handle *b = p->binding_handle;
31 struct policy_handle *handle;
33 torture_assert(tctx,
34 test_lsa_OpenPolicy2(b, tctx, &handle),
35 "failed to open policy");
37 torture_assert(tctx,
38 test_lsa_Close(b, tctx, handle),
39 "failed to close policy");
41 return true;
44 static bool test_bind(struct torture_context *tctx,
45 const void *private_data)
47 struct dcerpc_binding *binding;
48 struct dcerpc_pipe *p;
49 const uint32_t *flags = (const uint32_t *)private_data;
51 torture_assert_ntstatus_ok(tctx,
52 torture_rpc_binding(tctx, &binding),
53 "failed to parse binding string");
55 binding->flags &= ~DCERPC_AUTH_OPTIONS;
56 binding->flags |= *flags;
58 torture_assert_ntstatus_ok(tctx,
59 dcerpc_pipe_connect_b(tctx, &p, binding,
60 &ndr_table_lsarpc,
61 cmdline_credentials,
62 tctx->ev,
63 tctx->lp_ctx),
64 "failed to connect pipe");
66 torture_assert(tctx,
67 test_openpolicy(tctx, p),
68 "failed to test openpolicy");
70 talloc_free(p);
72 return true;
75 static void test_bind_op(struct torture_suite *suite,
76 const char *name,
77 uint32_t flags)
79 uint32_t *flags_p = talloc(suite, uint32_t);
81 *flags_p = flags;
83 torture_suite_add_simple_tcase_const(suite, name, test_bind, flags_p);
87 struct torture_suite *torture_rpc_bind(TALLOC_CTX *mem_ctx)
89 struct torture_suite *suite = torture_suite_create(mem_ctx, "bind");
90 struct {
91 const char *test_name;
92 uint32_t flags;
93 } tests[] = {
95 .test_name = "ntlm,sign",
96 .flags = DCERPC_AUTH_NTLM | DCERPC_SIGN
97 },{
98 .test_name = "ntlm,sign,seal",
99 .flags = DCERPC_AUTH_NTLM | DCERPC_SIGN | DCERPC_SEAL
101 .test_name = "spnego,sign",
102 .flags = DCERPC_AUTH_SPNEGO | DCERPC_SIGN
104 .test_name = "spnego,sign,seal",
105 .flags = DCERPC_AUTH_SPNEGO | DCERPC_SIGN | DCERPC_SEAL
108 int i;
110 for (i=0; i < ARRAY_SIZE(tests); i++) {
111 test_bind_op(suite, tests[i].test_name, tests[i].flags);
113 for (i=0; i < ARRAY_SIZE(tests); i++) {
114 test_bind_op(suite, talloc_asprintf(suite, "bigendian,%s", tests[i].test_name), tests[i].flags | DCERPC_PUSH_BIGENDIAN);
117 return suite;