| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
Test suite for libnet calls. |
| 4 |
|
| 5 |
Copyright (C) Rafal Szczesniak 2007 |
| 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 |
|
| 22 |
#include "includes.h" |
| 23 |
#include "lib/cmdline/cmdline.h" |
| 24 |
#include "libnet/libnet.h" |
| 25 |
#include "librpc/gen_ndr/ndr_samr_c.h" |
| 26 |
#include "librpc/gen_ndr/ndr_lsa_c.h" |
| 27 |
#include "torture/rpc/torture_rpc.h" |
| 28 |
#include "torture/libnet/proto.h" |
| 29 |
#include "param/param.h" |
| 30 |
|
| 31 |
|
| 32 |
#define TEST_GROUPNAME "libnetgrouptest" |
| 33 |
|
| 34 |
|
| 35 |
bool torture_groupinfo_api(struct torture_context *torture) |
| 36 |
{ |
| 37 |
const char *name = TEST_GROUPNAME; |
| 38 |
bool ret = true; |
| 39 |
NTSTATUS status; |
| 40 |
TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx; |
| 41 |
struct libnet_context *ctx = NULL; |
| 42 |
struct dcerpc_pipe *p; |
| 43 |
struct policy_handle h; |
| 44 |
struct lsa_String domain_name; |
| 45 |
struct libnet_GroupInfo req; |
| 46 |
|
| 47 |
prep_mem_ctx = talloc_init("prepare torture group info"); |
| 48 |
|
| 49 |
status = torture_rpc_connection(torture, |
| 50 |
&p, |
| 51 |
&ndr_table_samr); |
| 52 |
if (!NT_STATUS_IS_OK(status)) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
|
| 56 |
domain_name.string = lpcfg_workgroup(torture->lp_ctx); |
| 57 |
if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) { |
| 58 |
ret = false; |
| 59 |
goto done; |
| 60 |
} |
| 61 |
|
| 62 |
if (!test_group_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) { |
| 63 |
ret = false; |
| 64 |
goto done; |
| 65 |
} |
| 66 |
|
| 67 |
mem_ctx = talloc_init("torture group info"); |
| 68 |
|
| 69 |
if (!test_libnet_context_init(torture, true, &ctx)) { |
| 70 |
return false; |
| 71 |
} |
| 72 |
|
| 73 |
ZERO_STRUCT(req); |
| 74 |
|
| 75 |
req.in.domain_name = domain_name.string; |
| 76 |
req.in.level = GROUP_INFO_BY_NAME; |
| 77 |
req.in.data.group_name = name; |
| 78 |
|
| 79 |
status = libnet_GroupInfo(ctx, mem_ctx, &req); |
| 80 |
if (!NT_STATUS_IS_OK(status)) { |
| 81 |
torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status)); |
| 82 |
ret = false; |
| 83 |
goto done; |
| 84 |
} |
| 85 |
|
| 86 |
if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, |
| 87 |
mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { |
| 88 |
torture_comment(torture, "cleanup failed\n"); |
| 89 |
ret = false; |
| 90 |
goto done; |
| 91 |
} |
| 92 |
|
| 93 |
if (!test_samr_close_handle(torture, |
| 94 |
ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { |
| 95 |
torture_comment(torture, "domain close failed\n"); |
| 96 |
ret = false; |
| 97 |
} |
| 98 |
|
| 99 |
done: |
| 100 |
talloc_free(ctx); |
| 101 |
talloc_free(mem_ctx); |
| 102 |
return ret; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
bool torture_grouplist(struct torture_context *torture) |
| 107 |
{ |
| 108 |
bool ret = true; |
| 109 |
NTSTATUS status; |
| 110 |
TALLOC_CTX *mem_ctx = NULL; |
| 111 |
struct libnet_context *ctx; |
| 112 |
struct lsa_String domain_name; |
| 113 |
struct libnet_GroupList req; |
| 114 |
int i; |
| 115 |
|
| 116 |
ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx); |
| 117 |
ctx->cred = samba_cmdline_get_creds(); |
| 118 |
|
| 119 |
domain_name.string = lpcfg_workgroup(torture->lp_ctx); |
| 120 |
mem_ctx = talloc_init("torture group list"); |
| 121 |
|
| 122 |
ZERO_STRUCT(req); |
| 123 |
|
| 124 |
torture_comment(torture, "listing group accounts:\n"); |
| 125 |
|
| 126 |
do { |
| 127 |
req.in.domain_name = domain_name.string; |
| 128 |
req.in.page_size = 128; |
| 129 |
req.in.resume_index = req.out.resume_index; |
| 130 |
|
| 131 |
status = libnet_GroupList(ctx, mem_ctx, &req); |
| 132 |
if (!NT_STATUS_IS_OK(status) && |
| 133 |
!NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) break; |
| 134 |
|
| 135 |
for (i = 0; i < req.out.count; i++) { |
| 136 |
torture_comment(torture, "\tgroup: %s, sid=%s\n", |
| 137 |
req.out.groups[i].groupname, req.out.groups[i].sid); |
| 138 |
} |
| 139 |
|
| 140 |
} while (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)); |
| 141 |
|
| 142 |
if (!(NT_STATUS_IS_OK(status) || |
| 143 |
NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) { |
| 144 |
torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status)); |
| 145 |
ret = false; |
| 146 |
goto done; |
| 147 |
} |
| 148 |
|
| 149 |
if (!test_samr_close_handle(torture, |
| 150 |
ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { |
| 151 |
torture_comment(torture, "domain close failed\n"); |
| 152 |
ret = false; |
| 153 |
} |
| 154 |
|
| 155 |
if (!test_lsa_close_handle(torture, |
| 156 |
ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) { |
| 157 |
torture_comment(torture, "lsa domain close failed\n"); |
| 158 |
ret = false; |
| 159 |
} |
| 160 |
|
| 161 |
talloc_free(ctx); |
| 162 |
|
| 163 |
done: |
| 164 |
talloc_free(mem_ctx); |
| 165 |
return ret; |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
bool torture_creategroup(struct torture_context *torture) |
| 170 |
{ |
| 171 |
bool ret = true; |
| 172 |
NTSTATUS status; |
| 173 |
TALLOC_CTX *mem_ctx = NULL; |
| 174 |
struct libnet_context *ctx; |
| 175 |
struct libnet_CreateGroup req; |
| 176 |
|
| 177 |
mem_ctx = talloc_init("test_creategroup"); |
| 178 |
|
| 179 |
ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx); |
| 180 |
ctx->cred = samba_cmdline_get_creds(); |
| 181 |
|
| 182 |
req.in.group_name = TEST_GROUPNAME; |
| 183 |
req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); |
| 184 |
req.out.error_string = NULL; |
| 185 |
|
| 186 |
status = libnet_CreateGroup(ctx, mem_ctx, &req); |
| 187 |
if (!NT_STATUS_IS_OK(status)) { |
| 188 |
torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status)); |
| 189 |
ret = false; |
| 190 |
goto done; |
| 191 |
} |
| 192 |
|
| 193 |
if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, |
| 194 |
mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { |
| 195 |
torture_comment(torture, "cleanup failed\n"); |
| 196 |
ret = false; |
| 197 |
goto done; |
| 198 |
} |
| 199 |
|
| 200 |
if (!test_samr_close_handle(torture, |
| 201 |
ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { |
| 202 |
torture_comment(torture, "domain close failed\n"); |
| 203 |
ret = false; |
| 204 |
} |
| 205 |
|
| 206 |
done: |
| 207 |
talloc_free(ctx); |
| 208 |
talloc_free(mem_ctx); |
| 209 |
return ret; |
| 210 |
} |