| 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 |
#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 |
#define TEST_GROUPNAME "libnetgroupinfotest" |
| 30 |
|
| 31 |
|
| 32 |
static bool test_groupinfo(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* group_name, |
| 36 |
uint32_t *rid) |
| 37 |
{ |
| 38 |
const uint16_t level = 5; |
| 39 |
NTSTATUS status; |
| 40 |
struct libnet_rpc_groupinfo group; |
| 41 |
struct dom_sid *group_sid; |
| 42 |
|
| 43 |
group_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid); |
| 44 |
|
| 45 |
ZERO_STRUCT(group); |
| 46 |
|
| 47 |
group.in.domain_handle = *domain_handle; |
| 48 |
group.in.sid = dom_sid_string(mem_ctx, group_sid); |
| 49 |
group.in.level = level; /* this should be extended */ |
| 50 |
|
| 51 |
torture_comment(tctx, "Testing sync libnet_rpc_groupinfo (SID argument)\n"); |
| 52 |
status = libnet_rpc_groupinfo(tctx->ev, p->binding_handle, mem_ctx, &group); |
| 53 |
if (!NT_STATUS_IS_OK(status)) { |
| 54 |
torture_comment(tctx, "Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); |
| 55 |
return false; |
| 56 |
} |
| 57 |
|
| 58 |
ZERO_STRUCT(group); |
| 59 |
|
| 60 |
group.in.domain_handle = *domain_handle; |
| 61 |
group.in.sid = NULL; |
| 62 |
group.in.groupname = TEST_GROUPNAME; |
| 63 |
group.in.level = level; |
| 64 |
|
| 65 |
printf("Testing sync libnet_rpc_groupinfo (groupname argument)\n"); |
| 66 |
status = libnet_rpc_groupinfo(tctx->ev, p->binding_handle, mem_ctx, &group); |
| 67 |
if (!NT_STATUS_IS_OK(status)) { |
| 68 |
torture_comment(tctx, "Failed to call sync libnet_rpc_groupinfo - %s\n", nt_errstr(status)); |
| 69 |
return false; |
| 70 |
} |
| 71 |
|
| 72 |
return true; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
bool torture_groupinfo(struct torture_context *torture) |
| 77 |
{ |
| 78 |
NTSTATUS status; |
| 79 |
struct dcerpc_pipe *p; |
| 80 |
TALLOC_CTX *mem_ctx; |
| 81 |
bool ret = true; |
| 82 |
struct policy_handle h; |
| 83 |
struct lsa_String name; |
| 84 |
struct dom_sid2 sid; |
| 85 |
uint32_t rid; |
| 86 |
struct dcerpc_binding_handle *b; |
| 87 |
|
| 88 |
mem_ctx = talloc_init("test_userinfo"); |
| 89 |
|
| 90 |
status = torture_rpc_connection(torture, |
| 91 |
&p, |
| 92 |
&ndr_table_samr); |
| 93 |
|
| 94 |
if (!NT_STATUS_IS_OK(status)) { |
| 95 |
return false; |
| 96 |
} |
| 97 |
b = p->binding_handle; |
| 98 |
|
| 99 |
name.string = lpcfg_workgroup(torture->lp_ctx); |
| 100 |
|
| 101 |
/* |
| 102 |
* Testing synchronous version |
| 103 |
*/ |
| 104 |
if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) { |
| 105 |
ret = false; |
| 106 |
goto done; |
| 107 |
} |
| 108 |
|
| 109 |
if (!test_group_create(torture, b, mem_ctx, &h, TEST_GROUPNAME, &rid)) { |
| 110 |
ret = false; |
| 111 |
goto done; |
| 112 |
} |
| 113 |
|
| 114 |
if (!test_groupinfo(torture, p, mem_ctx, &h, &sid, TEST_GROUPNAME, &rid)) { |
| 115 |
ret = false; |
| 116 |
goto done; |
| 117 |
} |
| 118 |
|
| 119 |
if (!test_group_cleanup(torture, b, mem_ctx, &h, TEST_GROUPNAME)) { |
| 120 |
ret = false; |
| 121 |
goto done; |
| 122 |
} |
| 123 |
|
| 124 |
done: |
| 125 |
talloc_free(mem_ctx); |
| 126 |
|
| 127 |
return ret; |
| 128 |
} |