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 this 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]);
57 static BOOL test_OpenPolicy(struct dcerpc_pipe *p)
59 struct lsa_ObjectAttribute attr;
60 struct policy_handle handle;
61 struct lsa_QosInfo qos;
64 printf("\ntesting OpenPolicy\n");
66 qos.impersonation_level = 2;
68 qos.effective_only = 0;
71 attr.object_name = NULL;
76 status = dcerpc_lsa_OpenPolicy(p,
79 SEC_RIGHTS_MAXIMUM_ALLOWED,
81 if (!NT_STATUS_IS_OK(status)) {
82 printf("OpenPolicy failed - %s\n", nt_errstr(status));
90 static BOOL test_OpenPolicy2(struct dcerpc_pipe *p, struct policy_handle *handle)
92 struct lsa_ObjectAttribute attr;
93 struct lsa_QosInfo qos;
96 printf("\ntesting OpenPolicy2\n");
98 qos.impersonation_level = 2;
100 qos.effective_only = 0;
102 attr.root_dir = NULL;
103 attr.object_name = NULL;
105 attr.sec_desc = NULL;
108 status = dcerpc_lsa_OpenPolicy2(p,
111 SEC_RIGHTS_MAXIMUM_ALLOWED,
113 if (!NT_STATUS_IS_OK(status)) {
114 printf("OpenPolicy2 failed - %s\n", nt_errstr(status));
122 static BOOL test_EnumSids(struct dcerpc_pipe *p,
124 struct policy_handle *handle)
127 struct dom_sid **sids;
128 uint32 num_entries = 100;
131 printf("\ntesting EnumSids\n");
133 status = dcerpc_lsa_EnumSids(p, mem_ctx, handle, 0, &num_entries, &sids);
134 if (!NT_STATUS_IS_OK(status)) {
135 printf("EnumSids failed - %s\n", nt_errstr(status));
139 printf("Got %d sids\n", num_entries);
141 for (i=0;i<num_entries;i++) {
142 printf("%s\n", lsa_sid_string_talloc(mem_ctx, sids[i]));
149 BOOL torture_rpc_lsa(int dummy)
152 struct dcerpc_pipe *p;
155 struct policy_handle handle;
157 mem_ctx = talloc_init("torture_rpc_lsa");
159 status = torture_rpc_connection(&p, "lsarpc");
160 if (!NT_STATUS_IS_OK(status)) {
164 if (!test_OpenPolicy(p)) {
168 if (!test_OpenPolicy2(p, &handle)) {
172 if (!test_EnumSids(p, mem_ctx, &handle)) {
176 torture_rpc_close(p);