1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 | Test suite for libnet calls.
|
---|
4 |
|
---|
5 | Copyright (C) Rafal Szczesniak 2005
|
---|
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 "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"
|
---|
28 |
|
---|
29 |
|
---|
30 | #define TEST_USERNAME "libnetuserinfotest"
|
---|
31 |
|
---|
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)
|
---|
37 | {
|
---|
38 | const uint16_t level = 5;
|
---|
39 | NTSTATUS status;
|
---|
40 | struct libnet_rpc_userinfo user;
|
---|
41 | struct dom_sid *user_sid;
|
---|
42 |
|
---|
43 | user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
|
---|
44 |
|
---|
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 */
|
---|
48 |
|
---|
49 | torture_comment(tctx, "Testing sync libnet_rpc_userinfo (SID argument)\n");
|
---|
50 | status = libnet_rpc_userinfo(p, mem_ctx, &user);
|
---|
51 | torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo() failed");
|
---|
52 |
|
---|
53 | ZERO_STRUCT(user);
|
---|
54 |
|
---|
55 | user.in.domain_handle = *domain_handle;
|
---|
56 | user.in.sid = NULL;
|
---|
57 | user.in.username = user_name;
|
---|
58 | user.in.level = level;
|
---|
59 |
|
---|
60 | torture_comment(tctx, "Testing sync libnet_rpc_userinfo (username argument)\n");
|
---|
61 | status = libnet_rpc_userinfo(p, mem_ctx, &user);
|
---|
62 | torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo failed");
|
---|
63 |
|
---|
64 | return true;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | static bool test_userinfo_async(struct torture_context *tctx,
|
---|
69 | struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
|
---|
70 | struct policy_handle *domain_handle,
|
---|
71 | struct dom_sid2 *domain_sid, const char* user_name,
|
---|
72 | uint32_t *rid)
|
---|
73 | {
|
---|
74 | const uint16_t level = 10;
|
---|
75 | NTSTATUS status;
|
---|
76 | struct composite_context *c;
|
---|
77 | struct libnet_rpc_userinfo user;
|
---|
78 | struct dom_sid *user_sid;
|
---|
79 |
|
---|
80 | user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
|
---|
81 |
|
---|
82 | user.in.domain_handle = *domain_handle;
|
---|
83 | user.in.sid = dom_sid_string(mem_ctx, user_sid);
|
---|
84 | user.in.level = level; /* this should be extended */
|
---|
85 |
|
---|
86 | torture_comment(tctx, "Testing async libnet_rpc_userinfo (SID argument)\n");
|
---|
87 |
|
---|
88 | c = libnet_rpc_userinfo_send(p, &user, msg_handler);
|
---|
89 | torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
|
---|
90 |
|
---|
91 | status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
|
---|
92 | torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
|
---|
93 |
|
---|
94 | ZERO_STRUCT(user);
|
---|
95 |
|
---|
96 | user.in.domain_handle = *domain_handle;
|
---|
97 | user.in.sid = NULL;
|
---|
98 | user.in.username = user_name;
|
---|
99 | user.in.level = level;
|
---|
100 |
|
---|
101 | torture_comment(tctx, "Testing async libnet_rpc_userinfo (username argument)\n");
|
---|
102 |
|
---|
103 | c = libnet_rpc_userinfo_send(p, &user, msg_handler);
|
---|
104 | torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send");
|
---|
105 |
|
---|
106 | status = libnet_rpc_userinfo_recv(c, mem_ctx, &user);
|
---|
107 | torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed");
|
---|
108 |
|
---|
109 | return true;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | bool torture_userinfo(struct torture_context *torture)
|
---|
114 | {
|
---|
115 | NTSTATUS status;
|
---|
116 | struct dcerpc_pipe *p;
|
---|
117 | TALLOC_CTX *mem_ctx;
|
---|
118 | bool ret = true;
|
---|
119 | struct policy_handle h;
|
---|
120 | struct lsa_String name;
|
---|
121 | struct dom_sid2 sid;
|
---|
122 | uint32_t rid;
|
---|
123 | struct dcerpc_binding_handle *b;
|
---|
124 |
|
---|
125 | mem_ctx = talloc_init("test_userinfo");
|
---|
126 |
|
---|
127 | status = torture_rpc_connection(torture,
|
---|
128 | &p,
|
---|
129 | &ndr_table_samr);
|
---|
130 |
|
---|
131 | if (!NT_STATUS_IS_OK(status)) {
|
---|
132 | return false;
|
---|
133 | }
|
---|
134 | b = p->binding_handle;
|
---|
135 |
|
---|
136 | name.string = lpcfg_workgroup(torture->lp_ctx);
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * Testing synchronous version
|
---|
140 | */
|
---|
141 | if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
|
---|
142 | ret = false;
|
---|
143 | goto done;
|
---|
144 | }
|
---|
145 |
|
---|
146 | if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
|
---|
147 | ret = false;
|
---|
148 | goto done;
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (!test_userinfo(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
|
---|
152 | ret = false;
|
---|
153 | goto done;
|
---|
154 | }
|
---|
155 |
|
---|
156 | if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
|
---|
157 | ret = false;
|
---|
158 | goto done;
|
---|
159 | }
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * Testing asynchronous version and monitor messages
|
---|
163 | */
|
---|
164 | if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
|
---|
165 | ret = false;
|
---|
166 | goto done;
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) {
|
---|
170 | ret = false;
|
---|
171 | goto done;
|
---|
172 | }
|
---|
173 |
|
---|
174 | if (!test_userinfo_async(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {
|
---|
175 | ret = false;
|
---|
176 | goto done;
|
---|
177 | }
|
---|
178 |
|
---|
179 | if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
|
---|
180 | ret = false;
|
---|
181 | goto done;
|
---|
182 | }
|
---|
183 |
|
---|
184 | done:
|
---|
185 | talloc_free(mem_ctx);
|
---|
186 |
|
---|
187 | return ret;
|
---|
188 | }
|
---|