ldb: Fix ldb public library header files being unusable
[Samba.git] / source4 / torture / libnet / userinfo.c
blob897273bcc2b64288df3c2c7dd5538ee9a3e23a7f
1 /*
2 Unix SMB/CIFS implementation.
3 Test suite for libnet calls.
5 Copyright (C) Rafal Szczesniak 2005
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, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "torture/rpc/torture_rpc.h"
23 #include "libnet/libnet.h"
24 #include "libcli/security/security.h"
25 #include "librpc/gen_ndr/ndr_samr_c.h"
26 #include "param/param.h"
27 #include "torture/libnet/proto.h"
30 #define TEST_USERNAME "libnetuserinfotest"
32 static bool test_userinfo(struct torture_context *tctx,
33 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34 struct policy_handle *domain_handle,
35 struct dom_sid2 *domain_sid, const char* user_name,
36 uint32_t *rid)
38 const uint16_t level = 5;
39 NTSTATUS status;
40 struct libnet_rpc_userinfo user;
41 struct dom_sid *user_sid;
43 user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
45 ZERO_STRUCT(user);
47 user.in.domain_handle = *domain_handle;
48 user.in.sid = dom_sid_string(mem_ctx, user_sid);
49 user.in.level = level; /* this should be extended */
51 torture_comment(tctx, "Testing sync libnet_rpc_userinfo (SID argument)\n");
52 status = libnet_rpc_userinfo(tctx->ev, p->binding_handle, mem_ctx, &user);
53 torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo() failed");
55 ZERO_STRUCT(user);
57 user.in.domain_handle = *domain_handle;
58 user.in.sid = NULL;
59 user.in.username = user_name;
60 user.in.level = level;
62 torture_comment(tctx, "Testing sync libnet_rpc_userinfo (username argument)\n");
63 status = libnet_rpc_userinfo(tctx->ev, p->binding_handle, mem_ctx, &user);
64 torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo failed");
66 return true;
70 static bool test_userinfo_async(struct torture_context *tctx,
71 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
72 struct policy_handle *domain_handle,
73 struct dom_sid2 *domain_sid, const char* user_name,
74 uint32_t *rid)
76 const uint16_t level = 10;
77 NTSTATUS status;
78 struct composite_context *c;
79 struct libnet_rpc_userinfo user;
80 struct dom_sid *user_sid;
82 user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
84 ZERO_STRUCT(user);
86 user.in.domain_handle = *domain_handle;
87 user.in.sid = dom_sid_string(mem_ctx, user_sid);
88 user.in.level = level; /* this should be extended */
90 torture_comment(tctx, "Testing async libnet_rpc_userinfo (SID argument)\n");
92 c = libnet_rpc_userinfo_send(mem_ctx, tctx->ev, p->binding_handle, &user, msg_handler);
93 torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
95 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
96 torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
98 ZERO_STRUCT(user);
100 user.in.domain_handle = *domain_handle;
101 user.in.sid = NULL;
102 user.in.username = user_name;
103 user.in.level = level;
105 torture_comment(tctx, "Testing async libnet_rpc_userinfo (username argument)\n");
107 c = libnet_rpc_userinfo_send(mem_ctx, tctx->ev, p->binding_handle, &user, msg_handler);
108 torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
110 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
111 torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
113 return true;
117 bool torture_userinfo(struct torture_context *torture)
119 NTSTATUS status;
120 struct dcerpc_pipe *p;
121 TALLOC_CTX *mem_ctx;
122 bool ret = true;
123 struct policy_handle h;
124 struct lsa_String name;
125 struct dom_sid2 sid;
126 uint32_t rid;
127 struct dcerpc_binding_handle *b;
129 mem_ctx = talloc_init("test_userinfo");
131 status = torture_rpc_connection(torture,
133 &ndr_table_samr);
135 if (!NT_STATUS_IS_OK(status)) {
136 return false;
138 b = p->binding_handle;
140 name.string = lpcfg_workgroup(torture->lp_ctx);
143 * Testing synchronous version
145 if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
146 ret = false;
147 goto done;
150 if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
151 ret = false;
152 goto done;
155 if (!test_userinfo(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
156 ret = false;
157 goto done;
160 if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
161 ret = false;
162 goto done;
166 * Testing asynchronous version and monitor messages
168 if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
169 ret = false;
170 goto done;
173 if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
174 ret = false;
175 goto done;
178 if (!test_userinfo_async(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
179 ret = false;
180 goto done;
183 if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
184 ret = false;
185 goto done;
188 done:
189 talloc_free(mem_ctx);
191 return ret;