2 Unix SMB/CIFS implementation.
3 test suite for lsa rpc operations
5 Copyright (C) Andrew Tridgell 2003
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 2 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.
25 these really shouldn't be here ....
27 static char *lsa_sid_string_talloc(TALLOC_CTX *mem_ctx, struct dom_sid *sid)
34 return talloc_asprintf(mem_ctx, "(NULL SID)");
37 maxlen = sid->num_auths * 11 + 25;
38 ret = talloc(mem_ctx, maxlen);
39 if (!ret) return NULL;
41 ia = (sid->id_auth[5]) +
42 (sid->id_auth[4] << 8 ) +
43 (sid->id_auth[3] << 16) +
44 (sid->id_auth[2] << 24);
46 ofs = snprintf(ret, maxlen, "S-%u-%lu",
47 (unsigned int)sid->sid_rev_num, (unsigned long)ia);
49 for (i = 0; i < sid->num_auths; i++) {
50 ofs += snprintf(ret + ofs, maxlen - ofs, "-%lu", (unsigned long)sid->sub_auths[i]);
56 static int dom_sid_compare(struct dom_sid *sid1, struct dom_sid *sid2)
60 if (sid1 == sid2) return 0;
64 /* Compare most likely different rids, first: i.e start at end */
65 if (sid1->num_auths != sid2->num_auths)
66 return sid1->num_auths - sid2->num_auths;
68 for (i = sid1->num_auths-1; i >= 0; --i)
69 if (sid1->sub_auths[i] != sid2->sub_auths[i])
70 return sid1->sub_auths[i] - sid2->sub_auths[i];
72 if (sid1->sid_rev_num != sid2->sid_rev_num)
73 return sid1->sid_rev_num - sid2->sid_rev_num;
75 for (i = 0; i < 6; i++)
76 if (sid1->id_auth[i] != sid2->id_auth[i])
77 return sid1->id_auth[i] - sid2->id_auth[i];
82 static BOOL test_OpenPolicy(struct dcerpc_pipe *p)
84 struct lsa_ObjectAttribute attr;
85 struct policy_handle handle;
86 struct lsa_QosInfo qos;
89 printf("\ntesting OpenPolicy\n");
91 qos.impersonation_level = 2;
93 qos.effective_only = 0;
96 attr.object_name = NULL;
101 status = dcerpc_lsa_OpenPolicy(p,
104 SEC_RIGHTS_MAXIMUM_ALLOWED,
106 if (!NT_STATUS_IS_OK(status)) {
107 printf("OpenPolicy failed - %s\n", nt_errstr(status));
115 static BOOL test_OpenPolicy2(struct dcerpc_pipe *p, struct policy_handle *handle)
117 struct lsa_ObjectAttribute attr;
118 struct lsa_QosInfo qos;
121 printf("\ntesting OpenPolicy2\n");
123 qos.impersonation_level = 2;
124 qos.context_mode = 1;
125 qos.effective_only = 0;
127 attr.root_dir = NULL;
128 attr.object_name = NULL;
130 attr.sec_desc = NULL;
133 status = dcerpc_lsa_OpenPolicy2(p,
136 SEC_RIGHTS_MAXIMUM_ALLOWED,
138 if (!NT_STATUS_IS_OK(status)) {
139 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
147 static BOOL test_EnumSids(struct dcerpc_pipe *p,
149 struct policy_handle *handle)
152 struct lsa_SidArray sids1, sids2;
153 uint32 resume_handle;
156 printf("\ntesting EnumSids\n");
159 status = dcerpc_lsa_EnumSids(p, mem_ctx, handle, &resume_handle, 100, &sids1);
160 if (!NT_STATUS_IS_OK(status)) {
161 printf("EnumSids failed - %s\n", nt_errstr(status));
165 printf("Got %d sids resume_handle=%u\n", sids1.num_sids, resume_handle);
167 for (i=0;i<sids1.num_sids;i++) {
168 printf("%s\n", lsa_sid_string_talloc(mem_ctx, sids1.sids[i].sid));
171 if (sids1.num_sids < 3) {
175 printf("trying partial listing (asking for 1 at 2)\n");
177 status = dcerpc_lsa_EnumSids(p, mem_ctx, handle, &resume_handle, 1, &sids2);
178 if (!NT_STATUS_IS_OK(status)) {
179 printf("EnumSids failed - %s\n", nt_errstr(status));
183 if (sids2.num_sids != 1) {
184 printf("Returned wrong number of entries (%d)\n", sids2.num_sids);
191 BOOL torture_rpc_lsa(int dummy)
194 struct dcerpc_pipe *p;
197 struct policy_handle handle;
199 mem_ctx = talloc_init("torture_rpc_lsa");
201 status = torture_rpc_connection(&p, "lsarpc");
202 if (!NT_STATUS_IS_OK(status)) {
206 if (!test_OpenPolicy(p)) {
210 if (!test_OpenPolicy2(p, &handle)) {
214 if (!test_EnumSids(p, mem_ctx, &handle)) {
218 torture_rpc_close(p);