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