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/>.
22 #include "torture/rpc/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/utils.h"
30 #define TEST_USERNAME "libnetuserinfotest"
33 static BOOL test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
34 struct policy_handle *domain_handle,
35 struct dom_sid2 *domain_sid, const char* user_name,
38 const uint16_t level = 5;
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 user.in.domain_handle = *domain_handle;
46 user.in.sid = dom_sid_string(mem_ctx, user_sid);
47 user.in.level = level; /* this should be extended */
49 printf("Testing sync libnet_rpc_userinfo (SID argument)\n");
50 status = libnet_rpc_userinfo(p, mem_ctx, &user);
51 if (!NT_STATUS_IS_OK(status)) {
52 printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status));
58 user.in.domain_handle = *domain_handle;
60 user.in.username = TEST_USERNAME;
61 user.in.level = level;
63 printf("Testing sync libnet_rpc_userinfo (username argument)\n");
64 status = libnet_rpc_userinfo(p, mem_ctx, &user);
65 if (!NT_STATUS_IS_OK(status)) {
66 printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status));
74 static BOOL test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
75 struct policy_handle *domain_handle,
76 struct dom_sid2 *domain_sid, const char* user_name,
79 const uint16_t level = 10;
81 struct composite_context *c;
82 struct libnet_rpc_userinfo user;
83 struct dom_sid *user_sid;
85 user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
87 user.in.domain_handle = *domain_handle;
88 user.in.sid = dom_sid_string(mem_ctx, user_sid);
89 user.in.level = level; /* this should be extended */
91 printf("Testing async libnet_rpc_userinfo (SID argument)\n");
93 c = libnet_rpc_userinfo_send(p, &user, msg_handler);
95 printf("Failed to call sync libnet_rpc_userinfo_send\n");
99 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
100 if (!NT_STATUS_IS_OK(status)) {
101 printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status));
107 user.in.domain_handle = *domain_handle;
109 user.in.username = TEST_USERNAME;
110 user.in.level = level;
112 printf("Testing async libnet_rpc_userinfo (username argument)\n");
114 c = libnet_rpc_userinfo_send(p, &user, msg_handler);
116 printf("Failed to call sync libnet_rpc_userinfo_send\n");
120 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
121 if (!NT_STATUS_IS_OK(status)) {
122 printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status));
130 bool torture_userinfo(struct torture_context *torture)
133 struct dcerpc_pipe *p;
136 struct policy_handle h;
137 struct lsa_String name;
141 mem_ctx = talloc_init("test_userinfo");
143 status = torture_rpc_connection(torture,
147 if (!NT_STATUS_IS_OK(status)) {
151 name.string = lp_workgroup();
154 * Testing synchronous version
156 if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) {
161 if (!test_user_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) {
166 if (!test_userinfo(p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
171 if (!test_user_cleanup(p, mem_ctx, &h, TEST_USERNAME)) {
177 * Testing asynchronous version and monitor messages
179 if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) {
184 if (!test_user_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) {
189 if (!test_userinfo_async(p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
194 if (!test_user_cleanup(p, mem_ctx, &h, TEST_USERNAME)) {
200 talloc_free(mem_ctx);