diff options
Diffstat (limited to 'source4/torture/libnet')
-rw-r--r-- | source4/torture/libnet/domain.c | 25 | ||||
-rw-r--r-- | source4/torture/libnet/groupinfo.c | 182 | ||||
-rw-r--r-- | source4/torture/libnet/groupman.c | 93 | ||||
-rw-r--r-- | source4/torture/libnet/grouptest.h | 20 | ||||
-rw-r--r-- | source4/torture/libnet/libnet.c | 1 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_BecomeDC.c | 46 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_domain.c | 75 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_group.c | 57 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_lookup.c | 41 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_rpc.c | 59 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_share.c | 42 | ||||
-rw-r--r-- | source4/torture/libnet/libnet_user.c | 143 | ||||
-rw-r--r-- | source4/torture/libnet/userinfo.c | 231 | ||||
-rw-r--r-- | source4/torture/libnet/userman.c | 302 | ||||
-rw-r--r-- | source4/torture/libnet/utils.c | 313 | ||||
-rw-r--r-- | source4/torture/libnet/utils.h | 42 |
16 files changed, 823 insertions, 849 deletions
diff --git a/source4/torture/libnet/domain.c b/source4/torture/libnet/domain.c index 17b8a94f42..daf9012e0c 100644 --- a/source4/torture/libnet/domain.c +++ b/source4/torture/libnet/domain.c @@ -23,8 +23,9 @@ #include "lib/events/events.h" #include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" -static BOOL test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx, +static bool test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx, struct lsa_String *domname, struct policy_handle *domain_handle) { @@ -39,15 +40,15 @@ static BOOL test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx, status = libnet_DomainOpen(net_ctx, mem_ctx, &io); if (!NT_STATUS_IS_OK(status)) { printf("Composite domain open failed - %s\n", nt_errstr(status)); - return False; + return false; } *domain_handle = io.out.domain_handle; - return True; + return true; } -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle) { NTSTATUS status; @@ -62,20 +63,20 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Close(p, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("Close failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -BOOL torture_domainopen(struct torture_context *torture) +bool torture_domainopen(struct torture_context *torture) { NTSTATUS status; struct libnet_context *net_ctx; struct event_context *evt_ctx; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; struct policy_handle h; struct lsa_String name; @@ -89,21 +90,21 @@ BOOL torture_domainopen(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - name.string = lp_workgroup(); + name.string = lp_workgroup(global_loadparm); /* * Testing synchronous version */ if (!test_domainopen(net_ctx, mem_ctx, &name, &h)) { - ret = False; + ret = false; goto done; } if (!test_cleanup(net_ctx->samr.pipe, mem_ctx, &h)) { - ret = False; + ret = false; goto done; } diff --git a/source4/torture/libnet/groupinfo.c b/source4/torture/libnet/groupinfo.c index 0dca1519de..bff2f405cd 100644 --- a/source4/torture/libnet/groupinfo.c +++ b/source4/torture/libnet/groupinfo.c @@ -23,163 +23,13 @@ #include "libnet/libnet.h" #include "libcli/security/security.h" #include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" +#include "torture/libnet/utils.h" #define TEST_GROUPNAME "libnetgroupinfotest" -static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, struct lsa_String *domname, - struct dom_sid2 *sid) -{ - NTSTATUS status; - struct policy_handle h, domain_handle; - struct samr_Connect r1; - struct samr_LookupDomain r2; - struct samr_OpenDomain r3; - - printf("connecting\n"); - - r1.in.system_name = 0; - r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r1.out.connect_handle = &h; - - status = dcerpc_samr_Connect(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("Connect failed - %s\n", nt_errstr(status)); - return False; - } - - r2.in.connect_handle = &h; - r2.in.domain_name = domname; - - printf("domain lookup on %s\n", domname->string); - - status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.connect_handle = &h; - r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r3.in.sid = r2.out.sid; - r3.out.domain_handle = &domain_handle; - - printf("opening domain\n"); - - status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; - } else { - *handle = domain_handle; - } - - *sid = *r2.out.sid; - return True; -} - - -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *domain_handle, const char *groupname) -{ - NTSTATUS status; - struct samr_LookupNames r1; - struct samr_OpenGroup r2; - struct samr_DeleteDomainGroup r3; - struct lsa_String names[2]; - uint32_t rid; - struct policy_handle group_handle; - - names[0].string = groupname; - - r1.in.domain_handle = domain_handle; - r1.in.num_names = 1; - r1.in.names = names; - - printf("group account lookup '%s'\n", groupname); - - status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupNames failed - %s\n", nt_errstr(status)); - return False; - } - - rid = r1.out.rids.ids[0]; - - r2.in.domain_handle = domain_handle; - r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r2.in.rid = rid; - r2.out.group_handle = &group_handle; - - printf("opening group account\n"); - - status = dcerpc_samr_OpenGroup(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenUser failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.group_handle = &group_handle; - r3.out.group_handle = &group_handle; - - printf("deleting group account\n"); - - status = dcerpc_samr_DeleteDomainGroup(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("DeleteGroup failed - %s\n", nt_errstr(status)); - return False; - } - - return True; -} - - -static BOOL test_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, const char *name, uint32_t *rid) -{ - NTSTATUS status; - struct lsa_String groupname; - struct samr_CreateDomainGroup r; - struct policy_handle group_handle; - - groupname.string = name; - - r.in.domain_handle = handle; - r.in.name = &groupname; - r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r.out.group_handle = &group_handle; - r.out.rid = rid; - - printf("creating group account %s\n", name); - - status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateGroup failed - %s\n", nt_errstr(status)); - - if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { - printf("Group (%s) already exists - attempting to delete and recreate account again\n", name); - if (!test_cleanup(p, mem_ctx, handle, TEST_GROUPNAME)) { - return False; - } - - printf("creating group account\n"); - - status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateGroup failed - %s\n", nt_errstr(status)); - return False; - } - return True; - } - return False; - } - - return True; -} - - -static BOOL test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, struct dom_sid2 *domain_sid, const char* group_name, uint32_t *rid) @@ -199,7 +49,7 @@ static BOOL test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_groupinfo(p, mem_ctx, &group); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); - return False; + return false; } ZERO_STRUCT(group); @@ -213,19 +63,19 @@ static BOOL test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_groupinfo(p, mem_ctx, &group); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_groupinfo - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -BOOL torture_groupinfo(struct torture_context *torture) +bool torture_groupinfo(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; struct policy_handle h; struct lsa_String name; struct dom_sid2 sid; @@ -238,31 +88,31 @@ BOOL torture_groupinfo(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - name.string = lp_workgroup(); + name.string = lp_workgroup(global_loadparm); /* * Testing synchronous version */ if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) { - ret = False; + ret = false; goto done; } - if (!test_create(p, mem_ctx, &h, TEST_GROUPNAME, &rid)) { - ret = False; + if (!test_group_create(p, mem_ctx, &h, TEST_GROUPNAME, &rid)) { + ret = false; goto done; } if (!test_groupinfo(p, mem_ctx, &h, &sid, TEST_GROUPNAME, &rid)) { - ret = False; + ret = false; goto done; } - if (!test_cleanup(p, mem_ctx, &h, TEST_GROUPNAME)) { - ret = False; + if (!test_group_cleanup(p, mem_ctx, &h, TEST_GROUPNAME)) { + ret = false; goto done; } diff --git a/source4/torture/libnet/groupman.c b/source4/torture/libnet/groupman.c new file mode 100644 index 0000000000..552e02c420 --- /dev/null +++ b/source4/torture/libnet/groupman.c @@ -0,0 +1,93 @@ +/* + Unix SMB/CIFS implementation. + Test suite for libnet calls. + + Copyright (C) Rafal Szczesniak 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "torture/rpc/rpc.h" +#include "torture/libnet/grouptest.h" +#include "libnet/libnet.h" +#include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" +#include "torture/libnet/utils.h" + + +static bool test_groupadd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle, + const char *name) +{ + NTSTATUS status; + bool ret = true; + struct libnet_rpc_groupadd group; + + group.in.domain_handle = *domain_handle; + group.in.groupname = name; + + printf("Testing libnet_rpc_groupadd\n"); + + status = libnet_rpc_groupadd(p, mem_ctx, &group); + if (!NT_STATUS_IS_OK(status)) { + printf("Failed to call sync libnet_rpc_groupadd - %s\n", nt_errstr(status)); + return false; + } + + return ret; +} + + +bool torture_groupadd(struct torture_context *torture) +{ + NTSTATUS status; + struct dcerpc_pipe *p; + struct policy_handle h; + struct lsa_String domain_name; + struct dom_sid2 sid; + const char *name = TEST_GROUPNAME; + TALLOC_CTX *mem_ctx; + bool ret = true; + + mem_ctx = talloc_init("test_groupadd"); + + status = torture_rpc_connection(torture, + &p, + &ndr_table_samr); + + if (!NT_STATUS_IS_OK(status)) { + return false; + } + + domain_name.string = lp_workgroup(global_loadparm); + if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) { + ret = false; + goto done; + } + + if (!test_groupadd(p, mem_ctx, &h, name)) { + ret = false; + goto done; + } + + if (!test_group_cleanup(p, mem_ctx, &h, name)) { + ret = false; + goto done; + } + +done: + talloc_free(mem_ctx); + return ret; +} diff --git a/source4/torture/libnet/grouptest.h b/source4/torture/libnet/grouptest.h new file mode 100644 index 0000000000..9d030acd17 --- /dev/null +++ b/source4/torture/libnet/grouptest.h @@ -0,0 +1,20 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Rafal Szczesniak 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#define TEST_GROUPNAME "libnetgrptest" diff --git a/source4/torture/libnet/libnet.c b/source4/torture/libnet/libnet.c index dc0e35e102..0e5c9301f8 100644 --- a/source4/torture/libnet/libnet.c +++ b/source4/torture/libnet/libnet.c @@ -31,6 +31,7 @@ NTSTATUS torture_net_init(void) torture_suite_add_simple_test(suite, "USERMOD", torture_usermod); torture_suite_add_simple_test(suite, "DOMOPEN", torture_domainopen); torture_suite_add_simple_test(suite, "GROUPINFO", torture_groupinfo); + torture_suite_add_simple_test(suite, "GROUPADD", torture_groupadd); torture_suite_add_simple_test(suite, "API-LOOKUP", torture_lookup); torture_suite_add_simple_test(suite, "API-LOOKUPHOST", torture_lookup_host); torture_suite_add_simple_test(suite, "API-LOOKUPPDC", torture_lookup_pdc); diff --git a/source4/torture/libnet/libnet_BecomeDC.c b/source4/torture/libnet/libnet_BecomeDC.c index 9d67e093b1..edcf92b8ec 100644 --- a/source4/torture/libnet/libnet_BecomeDC.c +++ b/source4/torture/libnet/libnet_BecomeDC.c @@ -163,7 +163,7 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data, DEBUG(0,("Pathes under PRIVATEDIR[%s]\n" "SAMDB[%s] SECRETS[%s] KEYTAB[%s]\n", - lp_private_dir(), + lp_private_dir(global_loadparm), s->path.samdb_ldb, s->path.secrets_ldb, s->path.secrets_keytab)); @@ -256,7 +256,7 @@ static NTSTATUS test_become_dc_prepare_db(void *private_data, DEBUG(0,("Open the SAM LDB with system credentials: %s\n", s->path.samdb_ldb)); - s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb, + s->ldb = ldb_wrap_connect(s, global_loadparm, s->path.samdb_ldb, system_session(s), NULL, 0, NULL); if (!s->ldb) { @@ -345,7 +345,7 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s, tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid); NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); - tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); + tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); s_dsa->other_info->dns_name = tmp_dns_name; @@ -442,7 +442,7 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s, return werror_to_ntstatus(status); } - if (lp_parm_bool(-1, "become dc", "dump objects", False)) { + if (lp_parm_bool(global_loadparm, NULL, "become dc", "dump objects", false)) { for (i=0; i < objs->num_objects; i++) { struct ldb_ldif ldif; fprintf(stdout, "#\n"); @@ -484,7 +484,7 @@ static NTSTATUS test_apply_schema(struct test_become_dc_state *s, s->schema = NULL; DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", s->path.samdb_ldb)); - s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb, + s->ldb = ldb_wrap_connect(s, global_loadparm, s->path.samdb_ldb, system_session(s), NULL, 0, NULL); if (!s->ldb) { @@ -642,7 +642,7 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data, tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid); NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); - tmp_dns_name = talloc_asprintf_append(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); + tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); s_dsa->other_info->dns_name = tmp_dns_name; @@ -670,7 +670,7 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data, return werror_to_ntstatus(status); } - if (lp_parm_bool(-1, "become dc", "dump objects", False)) { + if (lp_parm_bool(global_loadparm, NULL, "become dc", "dump objects", false)) { for (i=0; i < objs->num_objects; i++) { struct ldb_ldif ldif; fprintf(stdout, "#\n"); @@ -700,7 +700,7 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data, return NT_STATUS_FOOBAR; } - if (lp_parm_bool(-1, "become dc", "dump objects", False)) { + if (lp_parm_bool(global_loadparm, NULL, "become dc", "dump objects", false)) { DEBUG(0,("# %s\n", sa->lDAPDisplayName)); NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]); dump_data(0, @@ -712,9 +712,9 @@ static NTSTATUS test_become_dc_store_chunk(void *private_data, return NT_STATUS_OK; } -BOOL torture_net_become_dc(struct torture_context *torture) +bool torture_net_become_dc(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; NTSTATUS status; struct libnet_BecomeDC b; struct libnet_UnbecomeDC u; @@ -724,9 +724,9 @@ BOOL torture_net_become_dc(struct torture_context *torture) uint32_t i; s = talloc_zero(torture, struct test_become_dc_state); - if (!s) return False; + if (!s) return false; - s->netbios_name = lp_parm_string(-1, "become dc", "smbtorture dc"); + s->netbios_name = lp_parm_string(global_loadparm, NULL, "become dc", "smbtorture dc"); if (!s->netbios_name || !s->netbios_name[0]) { s->netbios_name = "smbtorturedc"; } @@ -751,7 +751,7 @@ BOOL torture_net_become_dc(struct torture_context *torture) if (!s->tj) { DEBUG(0, ("%s failed to join domain as workstation\n", s->netbios_name)); - return False; + return false; } s->ctx = libnet_context_init(torture->ev); @@ -776,27 +776,27 @@ BOOL torture_net_become_dc(struct torture_context *torture) status = libnet_BecomeDC(s->ctx, s, &b); if (!NT_STATUS_IS_OK(status)) { printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status)); - ret = False; + ret = false; goto cleanup; } msg = ldb_msg_new(s); if (!msg) { printf("ldb_msg_new() failed\n"); - ret = False; + ret = false; goto cleanup; } msg->dn = ldb_dn_new(msg, s->ldb, "cn=ROOTDSE"); if (!msg->dn) { printf("ldb_msg_new(cn=ROOTDSE) failed\n"); - ret = False; + ret = false; goto cleanup; } ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE"); if (ldb_ret != LDB_SUCCESS) { printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret); - ret = False; + ret = false; goto cleanup; } @@ -808,7 +808,7 @@ BOOL torture_net_become_dc(struct torture_context *torture) ldb_ret = ldb_modify(s->ldb, msg); if (ldb_ret != LDB_SUCCESS) { printf("ldb_modify() failed: %d\n", ldb_ret); - ret = False; + ret = false; goto cleanup; } @@ -817,24 +817,24 @@ BOOL torture_net_become_dc(struct torture_context *torture) s->schema = NULL; DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", s->path.samdb_ldb)); - s->ldb = ldb_wrap_connect(s, s->path.samdb_ldb, + s->ldb = ldb_wrap_connect(s, global_loadparm, s->path.samdb_ldb, system_session(s), NULL, 0, NULL); if (!s->ldb) { DEBUG(0,("Failed to open '%s'\n", s->path.samdb_ldb)); - ret = False; + ret = false; goto cleanup; } s->schema = dsdb_get_schema(s->ldb); if (!s->schema) { DEBUG(0,("Failed to get loaded dsdb_schema\n")); - ret = False; + ret = false; goto cleanup; } - if (lp_parm_bool(-1, "become dc", "do not unjoin", false)) { + if (lp_parm_bool(global_loadparm, NULL, "become dc", "do not unjoin", false)) { talloc_free(s); return ret; } @@ -849,7 +849,7 @@ cleanup: status = libnet_UnbecomeDC(s->ctx, s, &u); if (!NT_STATUS_IS_OK(status)) { printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status)); - ret = False; + ret = false; } /* Leave domain. */ diff --git a/source4/torture/libnet/libnet_domain.c b/source4/torture/libnet/libnet_domain.c index 675ab9f099..379cca19be 100644 --- a/source4/torture/libnet/libnet_domain.c +++ b/source4/torture/libnet/libnet_domain.c @@ -30,9 +30,10 @@ #include "librpc/rpc/dcerpc.h" #include "torture/torture.h" #include "torture/rpc/rpc.h" +#include "param/param.h" -static BOOL test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, struct lsa_String *domname, uint32_t *access_mask, struct dom_sid **sid) { @@ -53,7 +54,7 @@ static BOOL test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Connect(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("Connect failed - %s\n", nt_errstr(status)); - return False; + return false; } r2.in.connect_handle = &h; @@ -64,7 +65,7 @@ static BOOL test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } r3.in.connect_handle = &h; @@ -77,16 +78,16 @@ static BOOL test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); if (!NT_STATUS_IS_OK(status)) { printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } else { *handle = domain_handle; } - return True; + return true; } -static BOOL test_opendomain_lsa(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_opendomain_lsa(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, struct lsa_String *domname, uint32_t *access_mask) { @@ -114,16 +115,16 @@ static BOOL test_opendomain_lsa(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &open); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - return True; + return true; } bool torture_domain_open_lsa(struct torture_context *torture) { NTSTATUS status; - BOOL ret = True; + bool ret = true; struct libnet_context *ctx; struct libnet_DomainOpen r; struct lsa_Close lsa_close; @@ -133,12 +134,12 @@ bool torture_domain_open_lsa(struct torture_context *torture) /* we're accessing domain controller so the domain name should be passed (it's going to be resolved to dc name and address) instead of specific server name. */ - domain_name = lp_workgroup(); + domain_name = lp_workgroup(global_loadparm); ctx = libnet_context_init(NULL); if (ctx == NULL) { d_printf("failed to create libnet context\n"); - return False; + return false; } ctx->cred = cmdline_credentials; @@ -151,7 +152,7 @@ bool torture_domain_open_lsa(struct torture_context *torture) status = libnet_DomainOpen(ctx, torture, &r); if (!NT_STATUS_IS_OK(status)) { d_printf("failed to open domain on lsa service: %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } @@ -162,7 +163,7 @@ bool torture_domain_open_lsa(struct torture_context *torture) status = dcerpc_lsa_Close(ctx->lsa.pipe, ctx, &lsa_close); if (!NT_STATUS_IS_OK(status)) { d_printf("failed to close domain on lsa service: %s\n", nt_errstr(status)); - ret = False; + ret = false; } done: @@ -171,9 +172,9 @@ done: } -BOOL torture_domain_close_lsa(struct torture_context *torture) +bool torture_domain_close_lsa(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx=NULL; struct libnet_context *ctx; @@ -192,7 +193,7 @@ BOOL torture_domain_close_lsa(struct torture_context *torture) ctx = libnet_context_init(NULL); if (ctx == NULL) { d_printf("failed to create libnet context\n"); - ret = False; + ret = false; goto done; } @@ -203,15 +204,15 @@ BOOL torture_domain_close_lsa(struct torture_context *torture) cmdline_credentials, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("failed to connect to server: %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); if (!test_opendomain_lsa(p, torture, &h, &domain_name, &access_mask)) { d_printf("failed to open domain on lsa service\n"); - ret = False; + ret = false; goto done; } @@ -229,7 +230,7 @@ BOOL torture_domain_close_lsa(struct torture_context *torture) status = libnet_DomainClose(ctx, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } @@ -240,7 +241,7 @@ done: } -BOOL torture_domain_open_samr(struct torture_context *torture) +bool torture_domain_open_samr(struct torture_context *torture) { NTSTATUS status; struct libnet_context *ctx; @@ -250,7 +251,7 @@ BOOL torture_domain_open_samr(struct torture_context *torture) struct libnet_DomainOpen io; struct samr_Close r; const char *domain_name; - BOOL ret = True; + bool ret = true; mem_ctx = talloc_init("test_domainopen_lsa"); @@ -260,7 +261,7 @@ BOOL torture_domain_open_samr(struct torture_context *torture) /* we're accessing domain controller so the domain name should be passed (it's going to be resolved to dc name and address) instead of specific server name. */ - domain_name = lp_workgroup(); + domain_name = lp_workgroup(global_loadparm); /* * Testing synchronous version @@ -274,7 +275,7 @@ BOOL torture_domain_open_samr(struct torture_context *torture) status = libnet_DomainOpen(ctx, mem_ctx, &io); if (!NT_STATUS_IS_OK(status)) { printf("Composite domain open failed - %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } @@ -288,7 +289,7 @@ BOOL torture_domain_open_samr(struct torture_context *torture) status = dcerpc_samr_Close(ctx->samr.pipe, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("Close failed - %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } @@ -300,9 +301,9 @@ done: } -BOOL torture_domain_close_samr(struct torture_context *torture) +bool torture_domain_close_samr(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx = NULL; struct libnet_context *ctx; @@ -322,7 +323,7 @@ BOOL torture_domain_close_samr(struct torture_context *torture) ctx = libnet_context_init(NULL); if (ctx == NULL) { d_printf("failed to create libnet context\n"); - ret = False; + ret = false; goto done; } @@ -333,15 +334,15 @@ BOOL torture_domain_close_samr(struct torture_context *torture) ctx->cred, NULL); if (!NT_STATUS_IS_OK(status)) { d_printf("failed to connect to server: %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } - domain_name.string = talloc_strdup(mem_ctx, lp_workgroup()); + domain_name.string = talloc_strdup(mem_ctx, lp_workgroup(global_loadparm)); if (!test_opendomain_samr(p, torture, &h, &domain_name, &access_mask, &sid)) { d_printf("failed to open domain on samr service\n"); - ret = False; + ret = false; goto done; } @@ -361,7 +362,7 @@ BOOL torture_domain_close_samr(struct torture_context *torture) status = libnet_DomainClose(ctx, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } @@ -372,9 +373,9 @@ done: } -BOOL torture_domain_list(struct torture_context *torture) +bool torture_domain_list(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx = NULL; struct dcerpc_binding *binding; @@ -390,7 +391,7 @@ BOOL torture_domain_list(struct torture_context *torture) ctx = libnet_context_init(NULL); if (ctx == NULL) { d_printf("failed to create libnet context\n"); - ret = False; + ret = false; goto done; } @@ -407,7 +408,7 @@ BOOL torture_domain_list(struct torture_context *torture) status = libnet_DomainList(ctx, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } @@ -428,7 +429,7 @@ BOOL torture_domain_list(struct torture_context *torture) status = libnet_DomainList(ctx, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } diff --git a/source4/torture/libnet/libnet_group.c b/source4/torture/libnet/libnet_group.c index 1f4725d6dd..a4489d376d 100644 --- a/source4/torture/libnet/libnet_group.c +++ b/source4/torture/libnet/libnet_group.c @@ -26,12 +26,13 @@ #include "librpc/gen_ndr/ndr_lsa_c.h" #include "torture/torture.h" #include "torture/rpc/rpc.h" +#include "param/param.h" #define TEST_GROUPNAME "libnetgrouptest" -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, const char *groupname) { NTSTATUS status; @@ -53,7 +54,7 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("LookupNames failed - %s\n", nt_errstr(status)); - return False; + return false; } rid = r1.out.rids.ids[0]; @@ -68,7 +69,7 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_OpenGroup(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("OpenGroup failed - %s\n", nt_errstr(status)); - return False; + return false; } r3.in.group_handle = &group_handle; @@ -79,14 +80,14 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_DeleteDomainGroup(p, mem_ctx, &r3); if (!NT_STATUS_IS_OK(status)) { printf("DeleteGroup failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -static BOOL test_creategroup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_creategroup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *name) { NTSTATUS status; @@ -112,7 +113,7 @@ static BOOL test_creategroup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_GROUP_EXISTS)) { printf("Group (%s) already exists - attempting to delete and recreate group again\n", name); if (!test_cleanup(p, mem_ctx, handle, TEST_GROUPNAME)) { - return False; + return false; } printf("creating group account\n"); @@ -120,18 +121,18 @@ static BOOL test_creategroup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("CreateGroup failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } - return False; + return false; } - return True; + return true; } -static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, struct lsa_String *domname) { NTSTATUS status; @@ -149,7 +150,7 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Connect(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("Connect failed - %s\n", nt_errstr(status)); - return False; + return false; } r2.in.connect_handle = &h; @@ -160,7 +161,7 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } r3.in.connect_handle = &h; @@ -173,16 +174,16 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); if (!NT_STATUS_IS_OK(status)) { printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } else { *handle = domain_handle; } - return True; + return true; } -static BOOL test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle) { NTSTATUS status; @@ -194,17 +195,17 @@ static BOOL test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Close(p, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("Close samr domain failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -BOOL torture_groupinfo_api(struct torture_context *torture) +bool torture_groupinfo_api(struct torture_context *torture) { const char *name = TEST_GROUPNAME; - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx; struct libnet_context *ctx; @@ -222,17 +223,17 @@ BOOL torture_groupinfo_api(struct torture_context *torture) &p, &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { - ret = False; + ret = false; goto done; } if (!test_creategroup(p, prep_mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } @@ -246,20 +247,20 @@ BOOL torture_groupinfo_api(struct torture_context *torture) status = libnet_GroupInfo(ctx, mem_ctx, &req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_GroupInfo call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; talloc_free(mem_ctx); goto done; } if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { printf("cleanup failed\n"); - ret = False; + ret = false; goto done; } if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { printf("domain close failed\n"); - ret = False; + ret = false; } talloc_free(ctx); diff --git a/source4/torture/libnet/libnet_lookup.c b/source4/torture/libnet/libnet_lookup.c index b48f7e7bac..4734ec5088 100644 --- a/source4/torture/libnet/libnet_lookup.c +++ b/source4/torture/libnet/libnet_lookup.c @@ -26,11 +26,12 @@ #include "libcli/libcli.h" #include "torture/rpc/rpc.h" #include "torture/torture.h" +#include "param/param.h" -BOOL torture_lookup(struct torture_context *torture) +bool torture_lookup(struct torture_context *torture) { - BOOL ret; + bool ret; NTSTATUS status; TALLOC_CTX *mem_ctx; struct libnet_context *ctx; @@ -58,13 +59,13 @@ BOOL torture_lookup(struct torture_context *torture) if (!NT_STATUS_IS_OK(status)) { printf("Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status)); - ret = False; + ret = false; goto done; } - ret = True; + ret = true; - printf("Name [%s] found at adrress: %s.\n", lookup.in.hostname, *lookup.out.address); + printf("Name [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address); done: talloc_free(mem_ctx); @@ -72,9 +73,9 @@ done: } -BOOL torture_lookup_host(struct torture_context *torture) +bool torture_lookup_host(struct torture_context *torture) { - BOOL ret; + bool ret; NTSTATUS status; TALLOC_CTX *mem_ctx; struct libnet_context *ctx; @@ -101,13 +102,13 @@ BOOL torture_lookup_host(struct torture_context *torture) if (!NT_STATUS_IS_OK(status)) { printf("Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status)); - ret = False; + ret = false; goto done; } - ret = True; + ret = true; - printf("Host [%s] found at adrress: %s.\n", lookup.in.hostname, *lookup.out.address); + printf("Host [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address); done: talloc_free(mem_ctx); @@ -115,9 +116,9 @@ done: } -BOOL torture_lookup_pdc(struct torture_context *torture) +bool torture_lookup_pdc(struct torture_context *torture) { - BOOL ret; + bool ret; NTSTATUS status; TALLOC_CTX *mem_ctx; struct libnet_context *ctx; @@ -133,11 +134,11 @@ BOOL torture_lookup_pdc(struct torture_context *torture) lookup = talloc(mem_ctx, struct libnet_LookupDCs); if (!lookup) { - ret = False; + ret = false; goto done; } - lookup->in.domain_name = lp_workgroup(); + lookup->in.domain_name = lp_workgroup(global_loadparm); lookup->in.name_type = NBT_NAME_PDC; status = libnet_LookupDCs(ctx, mem_ctx, lookup); @@ -145,11 +146,11 @@ BOOL torture_lookup_pdc(struct torture_context *torture) if (!NT_STATUS_IS_OK(status)) { printf("Couldn't lookup pdc %s: %s\n", lookup->in.domain_name, nt_errstr(status)); - ret = False; + ret = false; goto done; } - ret = True; + ret = true; printf("DCs of domain [%s] found.\n", lookup->in.domain_name); for (i = 0; i < lookup->out.num_dcs; i++) { @@ -163,7 +164,7 @@ done: } -BOOL torture_lookup_sam_name(struct torture_context *torture) +bool torture_lookup_sam_name(struct torture_context *torture) { NTSTATUS status; TALLOC_CTX *mem_ctx; @@ -174,15 +175,15 @@ BOOL torture_lookup_sam_name(struct torture_context *torture) ctx->cred = cmdline_credentials; mem_ctx = talloc_init("torture lookup sam name"); - if (mem_ctx == NULL) return False; + if (mem_ctx == NULL) return false; r.in.name = "Administrator"; - r.in.domain_name = lp_workgroup(); + r.in.domain_name = lp_workgroup(global_loadparm); status = libnet_LookupName(ctx, mem_ctx, &r); talloc_free(mem_ctx); talloc_free(ctx); - return True; + return true; } diff --git a/source4/torture/libnet/libnet_rpc.c b/source4/torture/libnet/libnet_rpc.c index 07c586ebf3..5ca927a1e3 100644 --- a/source4/torture/libnet/libnet_rpc.c +++ b/source4/torture/libnet/libnet_rpc.c @@ -30,14 +30,15 @@ #include "librpc/rpc/dcerpc.h" #include "torture/rpc/rpc.h" #include "torture/torture.h" +#include "param/param.h" -static BOOL test_connect_service(struct libnet_context *ctx, +static bool test_connect_service(struct libnet_context *ctx, const struct ndr_interface_table *iface, const char *binding_string, const char *hostname, const enum libnet_RpcConnect_level level, - BOOL badcreds, NTSTATUS expected_status) + bool badcreds, NTSTATUS expected_status) { NTSTATUS status; struct libnet_RpcConnect connect; @@ -61,7 +62,7 @@ static BOOL test_connect_service(struct libnet_context *ctx, connect.in.dcerpc_iface->name, connect.in.binding, nt_errstr(expected_status), nt_errstr(status)); - return False; + return false; } d_printf("PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status), @@ -78,11 +79,11 @@ static BOOL test_connect_service(struct libnet_context *ctx, d_printf("Error string: %s\n", connect.out.error_string); } - return True; + return true; } -static BOOL torture_rpc_connect(struct torture_context *torture, +static bool torture_rpc_connect(struct torture_context *torture, const enum libnet_RpcConnect_level level, const char *bindstr, const char *hostname) { @@ -93,46 +94,46 @@ static BOOL torture_rpc_connect(struct torture_context *torture, d_printf("Testing connection to LSA interface\n"); if (!test_connect_service(ctx, &ndr_table_lsarpc, bindstr, - hostname, level, False, NT_STATUS_OK)) { + hostname, level, false, NT_STATUS_OK)) { d_printf("failed to connect LSA interface\n"); - return False; + return false; } d_printf("Testing connection to SAMR interface\n"); if (!test_connect_service(ctx, &ndr_table_samr, bindstr, - hostname, level, False, NT_STATUS_OK)) { + hostname, level, false, NT_STATUS_OK)) { d_printf("failed to connect SAMR interface\n"); - return False; + return false; } d_printf("Testing connection to SRVSVC interface\n"); if (!test_connect_service(ctx, &ndr_table_srvsvc, bindstr, - hostname, level, False, NT_STATUS_OK)) { + hostname, level, false, NT_STATUS_OK)) { d_printf("failed to connect SRVSVC interface\n"); - return False; + return false; } d_printf("Testing connection to LSA interface with wrong credentials\n"); if (!test_connect_service(ctx, &ndr_table_lsarpc, bindstr, - hostname, level, True, NT_STATUS_LOGON_FAILURE)) { + hostname, level, true, NT_STATUS_LOGON_FAILURE)) { d_printf("failed to test wrong credentials on LSA interface\n"); - return False; + return false; } d_printf("Testing connection to SAMR interface with wrong credentials\n"); if (!test_connect_service(ctx, &ndr_table_samr, bindstr, - hostname, level, True, NT_STATUS_LOGON_FAILURE)) { + hostname, level, true, NT_STATUS_LOGON_FAILURE)) { d_printf("failed to test wrong credentials on SAMR interface\n"); - return False; + return false; } talloc_free(ctx); - return True; + return true; } -BOOL torture_rpc_connect_srv(struct torture_context *torture) +bool torture_rpc_connect_srv(struct torture_context *torture) { const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_SERVER; NTSTATUS status; @@ -140,14 +141,14 @@ BOOL torture_rpc_connect_srv(struct torture_context *torture) status = torture_rpc_binding(torture, &binding); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } return torture_rpc_connect(torture, level, NULL, binding->host); } -BOOL torture_rpc_connect_pdc(struct torture_context *torture) +bool torture_rpc_connect_pdc(struct torture_context *torture) { const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_PDC; NTSTATUS status; @@ -156,18 +157,18 @@ BOOL torture_rpc_connect_pdc(struct torture_context *torture) status = torture_rpc_binding(torture, &binding); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } /* we're accessing domain controller so the domain name should be passed (it's going to be resolved to dc name and address) instead of specific server name. */ - domain_name = lp_workgroup(); + domain_name = lp_workgroup(global_loadparm); return torture_rpc_connect(torture, level, NULL, domain_name); } -BOOL torture_rpc_connect_dc(struct torture_context *torture) +bool torture_rpc_connect_dc(struct torture_context *torture) { const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC; NTSTATUS status; @@ -176,18 +177,18 @@ BOOL torture_rpc_connect_dc(struct torture_context *torture) status = torture_rpc_binding(torture, &binding); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } /* we're accessing domain controller so the domain name should be passed (it's going to be resolved to dc name and address) instead of specific server name. */ - domain_name = lp_workgroup(); + domain_name = lp_workgroup(global_loadparm); return torture_rpc_connect(torture, level, NULL, domain_name); } -BOOL torture_rpc_connect_dc_info(struct torture_context *torture) +bool torture_rpc_connect_dc_info(struct torture_context *torture) { const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_DC_INFO; NTSTATUS status; @@ -196,18 +197,18 @@ BOOL torture_rpc_connect_dc_info(struct torture_context *torture) status = torture_rpc_binding(torture, &binding); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } /* we're accessing domain controller so the domain name should be passed (it's going to be resolved to dc name and address) instead of specific server name. */ - domain_name = lp_workgroup(); + domain_name = lp_workgroup(global_loadparm); return torture_rpc_connect(torture, level, NULL, domain_name); } -BOOL torture_rpc_connect_binding(struct torture_context *torture) +bool torture_rpc_connect_binding(struct torture_context *torture) { const enum libnet_RpcConnect_level level = LIBNET_RPC_CONNECT_BINDING; NTSTATUS status; @@ -216,7 +217,7 @@ BOOL torture_rpc_connect_binding(struct torture_context *torture) status = torture_rpc_binding(torture, &binding); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } bindstr = dcerpc_binding_string(torture, binding); diff --git a/source4/torture/libnet/libnet_share.c b/source4/torture/libnet/libnet_share.c index b6b0b37d01..d18e6ea9db 100644 --- a/source4/torture/libnet/libnet_share.c +++ b/source4/torture/libnet/libnet_share.c @@ -113,13 +113,13 @@ static void test_displayshares(struct libnet_ListShares s) } -BOOL torture_listshares(struct torture_context *torture) +bool torture_listshares(struct torture_context *torture) { struct libnet_ListShares share; NTSTATUS status; uint32_t levels[] = { 0, 1, 2, 501, 502 }; int i; - BOOL ret = True; + bool ret = true; struct libnet_context* libnetctx; struct dcerpc_binding *bind; TALLOC_CTX *mem_ctx; @@ -127,14 +127,14 @@ BOOL torture_listshares(struct torture_context *torture) mem_ctx = talloc_init("test_listshares"); status = torture_rpc_binding(torture, &bind); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } libnetctx = libnet_context_init(NULL); if (!libnetctx) { printf("Couldn't allocate libnet context\n"); - ret = False; + ret = false; goto done; } @@ -151,7 +151,7 @@ BOOL torture_listshares(struct torture_context *torture) status = libnet_ListShares(libnetctx, mem_ctx, &share); if (!NT_STATUS_IS_OK(status)) { printf("libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string); - ret = False; + ret = false; goto done; } @@ -165,7 +165,7 @@ done: } -static BOOL test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, const char *host, +static bool test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, const char *host, const char* share) { NTSTATUS status; @@ -187,32 +187,27 @@ static BOOL test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, con status = dcerpc_srvsvc_NetShareAdd(svc_pipe, mem_ctx, &add); if (!NT_STATUS_IS_OK(status)) { printf("Failed to add a new share\n"); - return False; + return false; } printf("share added\n"); - return True; + return true; } -BOOL torture_delshare(struct torture_context *torture) +bool torture_delshare(struct torture_context *torture) { struct dcerpc_pipe *p; struct dcerpc_binding *bind; struct libnet_context* libnetctx; const char *host; - TALLOC_CTX *mem_ctx; NTSTATUS status; - BOOL ret = True; + bool ret = true; struct libnet_DelShare share; - mem_ctx = talloc_init("test_listshares"); host = torture_setting_string(torture, "host", NULL); status = torture_rpc_binding(torture, &bind); - if (!NT_STATUS_IS_OK(status)) { - ret = False; - goto done; - } + torture_assert_ntstatus_ok(torture, status, "Failed to get binding"); libnetctx = libnet_context_init(NULL); libnetctx->cred = cmdline_credentials; @@ -221,22 +216,15 @@ BOOL torture_delshare(struct torture_context *torture) &p, &ndr_table_srvsvc); - if (!test_addshare(p, mem_ctx, host, TEST_SHARENAME)) { - ret = False; - goto done; + if (!test_addshare(p, torture, host, TEST_SHARENAME)) { + return false; } share.in.server_name = bind->host; share.in.share_name = TEST_SHARENAME; - status = libnet_DelShare(libnetctx, mem_ctx, &share); - if (!NT_STATUS_IS_OK(status)) { - ret = False; - goto done; - } + status = libnet_DelShare(libnetctx, torture, &share); + torture_assert_ntstatus_ok(torture, status, "Failed to delete share"); - -done: - talloc_free(mem_ctx); return ret; } diff --git a/source4/torture/libnet/libnet_user.c b/source4/torture/libnet/libnet_user.c index 7a3b9f19c1..b3aadc776e 100644 --- a/source4/torture/libnet/libnet_user.c +++ b/source4/torture/libnet/libnet_user.c @@ -27,9 +27,10 @@ #include "torture/torture.h" #include "torture/rpc/rpc.h" #include "torture/libnet/usertest.h" +#include "param/param.h" -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, const char *username) { NTSTATUS status; @@ -51,7 +52,7 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("LookupNames failed - %s\n", nt_errstr(status)); - return False; + return false; } rid = r1.out.rids.ids[0]; @@ -66,7 +67,7 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_OpenUser(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("OpenUser failed - %s\n", nt_errstr(status)); - return False; + return false; } r3.in.user_handle = &user_handle; @@ -77,14 +78,14 @@ static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3); if (!NT_STATUS_IS_OK(status)) { printf("DeleteUser failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, struct lsa_String *domname) { NTSTATUS status; @@ -102,7 +103,7 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Connect(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("Connect failed - %s\n", nt_errstr(status)); - return False; + return false; } r2.in.connect_handle = &h; @@ -113,7 +114,7 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } r3.in.connect_handle = &h; @@ -126,16 +127,16 @@ static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); if (!NT_STATUS_IS_OK(status)) { printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; + return false; } else { *handle = domain_handle; } - return True; + return true; } -static BOOL test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle) { NTSTATUS status; @@ -147,14 +148,14 @@ static BOOL test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Close(p, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("Close samr domain failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -static BOOL test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle) { NTSTATUS status; @@ -166,14 +167,14 @@ static BOOL test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_lsa_Close(p, mem_ctx, &r); if (!NT_STATUS_IS_OK(status)) { printf("Close lsa domain failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char* user) { NTSTATUS status; @@ -200,7 +201,7 @@ static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { printf("User (%s) already exists - attempting to delete and recreate account again\n", user); if (!test_cleanup(p, mem_ctx, handle, TEST_USERNAME)) { - return False; + return false; } printf("creating user account\n"); @@ -208,11 +209,11 @@ static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_CreateUser(p, mem_ctx, &r1); if (!NT_STATUS_IS_OK(status)) { printf("CreateUser failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } - return False; + return false; } r2.in.handle = &user_handle; @@ -223,20 +224,20 @@ static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = dcerpc_samr_Close(p, mem_ctx, &r2); if (!NT_STATUS_IS_OK(status)) { printf("Close failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -BOOL torture_createuser(struct torture_context *torture) +bool torture_createuser(struct torture_context *torture) { NTSTATUS status; TALLOC_CTX *mem_ctx; struct libnet_context *ctx; struct libnet_CreateUser req; - BOOL ret = True; + bool ret = true; mem_ctx = talloc_init("test_createuser"); @@ -244,25 +245,25 @@ BOOL torture_createuser(struct torture_context *torture) ctx->cred = cmdline_credentials; req.in.user_name = TEST_USERNAME; - req.in.domain_name = lp_workgroup(); + req.in.domain_name = lp_workgroup(global_loadparm); req.out.error_string = NULL; status = libnet_CreateUser(ctx, mem_ctx, &req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_CreateUser call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { printf("cleanup failed\n"); - ret = False; + ret = false; goto done; } if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { printf("domain close failed\n"); - ret = False; + ret = false; } done: @@ -272,7 +273,7 @@ done: } -BOOL torture_deleteuser(struct torture_context *torture) +bool torture_deleteuser(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; @@ -282,7 +283,7 @@ BOOL torture_deleteuser(struct torture_context *torture) const char *name = TEST_USERNAME; struct libnet_context *ctx; struct libnet_DeleteUser req; - BOOL ret = True; + bool ret = true; prep_mem_ctx = talloc_init("prepare test_deleteuser"); @@ -290,24 +291,24 @@ BOOL torture_deleteuser(struct torture_context *torture) ctx->cred = cmdline_credentials; req.in.user_name = TEST_USERNAME; - req.in.domain_name = lp_workgroup(); + req.in.domain_name = lp_workgroup(global_loadparm); status = torture_rpc_connection(torture, &p, &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { - ret = False; + ret = false; goto done; } if (!test_createuser(p, prep_mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } @@ -316,7 +317,7 @@ BOOL torture_deleteuser(struct torture_context *torture) status = libnet_DeleteUser(ctx, mem_ctx, &req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_DeleteUser call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; } talloc_free(mem_ctx); @@ -417,7 +418,7 @@ static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, case acct_expiry: continue_if_field_set(r->in.acct_expiry); now = timeval_add(&now, (random() % (31*24*60*60)), 0); - r->in.acct_expiry = talloc_memdup(mem_ctx, &now, sizeof(now)); + r->in.acct_expiry = (struct timeval *)talloc_memdup(mem_ctx, &now, sizeof(now)); fldname = "acct_expiry"; break; @@ -438,26 +439,26 @@ static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, #define TEST_STR_FLD(fld) \ if (!strequal(req.in.fld, user_req.out.fld)) { \ printf("failed to change '%s'\n", #fld); \ - ret = False; \ + ret = false; \ goto cleanup; \ } #define TEST_TIME_FLD(fld) \ if (timeval_compare(req.in.fld, user_req.out.fld)) { \ printf("failed to change '%s'\n", #fld); \ - ret = False; \ + ret = false; \ goto cleanup; \ } #define TEST_NUM_FLD(fld) \ if (req.in.fld != user_req.out.fld) { \ printf("failed to change '%s'\n", #fld); \ - ret = False; \ + ret = false; \ goto cleanup; \ } -BOOL torture_modifyuser(struct torture_context *torture) +bool torture_modifyuser(struct torture_context *torture) { NTSTATUS status; struct dcerpc_binding *bind; @@ -470,7 +471,7 @@ BOOL torture_modifyuser(struct torture_context *torture) struct libnet_ModifyUser req; struct libnet_UserInfo user_req; int fld; - BOOL ret = True; + bool ret = true; prep_mem_ctx = talloc_init("prepare test_deleteuser"); @@ -481,20 +482,20 @@ BOOL torture_modifyuser(struct torture_context *torture) &p, &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } name = talloc_strdup(prep_mem_ctx, TEST_USERNAME); - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { - ret = False; + ret = false; goto done; } if (!test_createuser(p, prep_mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } @@ -502,7 +503,7 @@ BOOL torture_modifyuser(struct torture_context *torture) status = torture_rpc_binding(mem_ctx, &bind); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } @@ -510,7 +511,7 @@ BOOL torture_modifyuser(struct torture_context *torture) for (fld = 1; fld < FIELDS_NUM - 1; fld++) { ZERO_STRUCT(req); - req.in.domain_name = lp_workgroup(); + req.in.domain_name = lp_workgroup(global_loadparm); req.in.user_name = name; set_test_changes(mem_ctx, &req, 1, &name, fld); @@ -518,18 +519,18 @@ BOOL torture_modifyuser(struct torture_context *torture) status = libnet_ModifyUser(ctx, mem_ctx, &req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_ModifyUser call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; continue; } ZERO_STRUCT(user_req); - user_req.in.domain_name = lp_workgroup(); + user_req.in.domain_name = lp_workgroup(global_loadparm); user_req.in.user_name = name; status = libnet_UserInfo(ctx, mem_ctx, &user_req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_UserInfo call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; continue; } @@ -562,7 +563,7 @@ BOOL torture_modifyuser(struct torture_context *torture) /* restore original testing username - it's useful when test fails because it prevents from problems with recreating account */ ZERO_STRUCT(req); - req.in.domain_name = lp_workgroup(); + req.in.domain_name = lp_workgroup(global_loadparm); req.in.user_name = name; req.in.account_name = TEST_USERNAME; @@ -570,7 +571,7 @@ BOOL torture_modifyuser(struct torture_context *torture) if (!NT_STATUS_IS_OK(status)) { printf("libnet_ModifyUser call failed: %s\n", nt_errstr(status)); talloc_free(mem_ctx); - ret = False; + ret = false; goto done; } @@ -581,13 +582,13 @@ BOOL torture_modifyuser(struct torture_context *torture) cleanup: if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, name)) { printf("cleanup failed\n"); - ret = False; + ret = false; goto done; } if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { printf("domain close failed\n"); - ret = False; + ret = false; } talloc_free(mem_ctx); @@ -599,10 +600,10 @@ done: } -BOOL torture_userinfo_api(struct torture_context *torture) +bool torture_userinfo_api(struct torture_context *torture) { const char *name = TEST_USERNAME; - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx; struct libnet_context *ctx; @@ -620,17 +621,17 @@ BOOL torture_userinfo_api(struct torture_context *torture) &p, &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { - ret = False; + ret = false; goto done; } if (!test_createuser(p, prep_mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } @@ -644,20 +645,20 @@ BOOL torture_userinfo_api(struct torture_context *torture) status = libnet_UserInfo(ctx, mem_ctx, &req); if (!NT_STATUS_IS_OK(status)) { printf("libnet_UserInfo call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; talloc_free(mem_ctx); goto done; } if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { printf("cleanup failed\n"); - ret = False; + ret = false; goto done; } if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { printf("domain close failed\n"); - ret = False; + ret = false; } talloc_free(ctx); @@ -668,9 +669,9 @@ done: } -BOOL torture_userlist(struct torture_context *torture) +bool torture_userlist(struct torture_context *torture) { - BOOL ret = True; + bool ret = true; NTSTATUS status; TALLOC_CTX *mem_ctx = NULL; struct libnet_context *ctx; @@ -681,7 +682,7 @@ BOOL torture_userlist(struct torture_context *torture) ctx = libnet_context_init(NULL); ctx->cred = cmdline_credentials; - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); mem_ctx = talloc_init("torture user list"); ZERO_STRUCT(req); @@ -706,19 +707,19 @@ BOOL torture_userlist(struct torture_context *torture) if (!(NT_STATUS_IS_OK(status) || NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) { printf("libnet_UserList call failed: %s\n", nt_errstr(status)); - ret = False; + ret = false; goto done; } if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { printf("samr domain close failed\n"); - ret = False; + ret = false; goto done; } if (!test_lsa_close(ctx->lsa.pipe, mem_ctx, &ctx->lsa.handle)) { printf("lsa domain close failed\n"); - ret = False; + ret = false; } talloc_free(ctx); diff --git a/source4/torture/libnet/userinfo.c b/source4/torture/libnet/userinfo.c index ad35e84861..46a9a6a015 100644 --- a/source4/torture/libnet/userinfo.c +++ b/source4/torture/libnet/userinfo.c @@ -23,162 +23,13 @@ #include "libnet/libnet.h" #include "libcli/security/security.h" #include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" +#include "torture/libnet/utils.h" -#define TEST_USERNAME "libnetuserinfotest" - -static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, struct lsa_String *domname, - struct dom_sid2 *sid) -{ - NTSTATUS status; - struct policy_handle h, domain_handle; - struct samr_Connect r1; - struct samr_LookupDomain r2; - struct samr_OpenDomain r3; - - printf("connecting\n"); - - r1.in.system_name = 0; - r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r1.out.connect_handle = &h; - - status = dcerpc_samr_Connect(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("Connect failed - %s\n", nt_errstr(status)); - return False; - } - - r2.in.connect_handle = &h; - r2.in.domain_name = domname; - - printf("domain lookup on %s\n", domname->string); - - status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.connect_handle = &h; - r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r3.in.sid = r2.out.sid; - r3.out.domain_handle = &domain_handle; - - printf("opening domain\n"); - - status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; - } else { - *handle = domain_handle; - } - - *sid = *r2.out.sid; - return True; -} - - -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *domain_handle, const char *username) -{ - NTSTATUS status; - struct samr_LookupNames r1; - struct samr_OpenUser r2; - struct samr_DeleteUser r3; - struct lsa_String names[2]; - uint32_t rid; - struct policy_handle user_handle; - - names[0].string = username; - - r1.in.domain_handle = domain_handle; - r1.in.num_names = 1; - r1.in.names = names; - - printf("user account lookup '%s'\n", username); - - status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupNames failed - %s\n", nt_errstr(status)); - return False; - } - - rid = r1.out.rids.ids[0]; - - r2.in.domain_handle = domain_handle; - r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r2.in.rid = rid; - r2.out.user_handle = &user_handle; - - printf("opening user account\n"); - - status = dcerpc_samr_OpenUser(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenUser failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.user_handle = &user_handle; - r3.out.user_handle = &user_handle; - - printf("deleting user account\n"); - - status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("DeleteUser failed - %s\n", nt_errstr(status)); - return False; - } - - return True; -} - - -static BOOL test_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, const char *name, uint32_t *rid) -{ - NTSTATUS status; - struct lsa_String username; - struct samr_CreateUser r; - struct policy_handle user_handle; - - username.string = name; - - r.in.domain_handle = handle; - r.in.account_name = &username; - r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r.out.user_handle = &user_handle; - r.out.rid = rid; - - printf("creating user account %s\n", name); - - status = dcerpc_samr_CreateUser(p, mem_ctx, &r); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateUser failed - %s\n", nt_errstr(status)); - - if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { - printf("User (%s) already exists - attempting to delete and recreate account again\n", name); - if (!test_cleanup(p, mem_ctx, handle, TEST_USERNAME)) { - return False; - } - - printf("creating user account\n"); - - status = dcerpc_samr_CreateUser(p, mem_ctx, &r); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateUser failed - %s\n", nt_errstr(status)); - return False; - } - return True; - } - return False; - } - - return True; -} +#define TEST_USERNAME "libnetuserinfotest" -static BOOL test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, struct dom_sid2 *domain_sid, const char* user_name, uint32_t *rid) @@ -198,7 +49,7 @@ static BOOL test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_userinfo(p, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); - return False; + return false; } ZERO_STRUCT(user); @@ -212,38 +63,14 @@ static BOOL test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_userinfo(p, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); - return False; + return false; } - return True; -} - - -static void msg_handler(struct monitor_msg *m) -{ - struct msg_rpc_open_user *msg_open; - struct msg_rpc_query_user *msg_query; - struct msg_rpc_close_user *msg_close; - - switch (m->type) { - case mon_SamrOpenUser: - msg_open = (struct msg_rpc_open_user*)m->data; - printf("monitor_msg: user opened (rid=%d, access_mask=0x%08x)\n", - msg_open->rid, msg_open->access_mask); - break; - case mon_SamrQueryUser: - msg_query = (struct msg_rpc_query_user*)m->data; - printf("monitor_msg: user queried (level=%d)\n", msg_query->level); - break; - case mon_SamrCloseUser: - msg_close = (struct msg_rpc_close_user*)m->data; - printf("monitor_msg: user closed (rid=%d)\n", msg_close->rid); - break; - } + return true; } -static BOOL test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, struct dom_sid2 *domain_sid, const char* user_name, uint32_t *rid) @@ -265,13 +92,13 @@ static BOOL test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, c = libnet_rpc_userinfo_send(p, &user, msg_handler); if (!c) { printf("Failed to call sync libnet_rpc_userinfo_send\n"); - return False; + return false; } status = libnet_rpc_userinfo_recv(c, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status)); - return False; + return false; } ZERO_STRUCT(user); @@ -286,25 +113,25 @@ static BOOL test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, c = libnet_rpc_userinfo_send(p, &user, msg_handler); if (!c) { printf("Failed to call sync libnet_rpc_userinfo_send\n"); - return False; + return false; } status = libnet_rpc_userinfo_recv(c, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -BOOL torture_userinfo(struct torture_context *torture) +bool torture_userinfo(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; struct policy_handle h; struct lsa_String name; struct dom_sid2 sid; @@ -317,31 +144,31 @@ BOOL torture_userinfo(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - name.string = lp_workgroup(); + name.string = lp_workgroup(global_loadparm); /* * Testing synchronous version */ if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) { - ret = False; + ret = false; goto done; } - if (!test_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) { - ret = False; + if (!test_user_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) { + ret = false; goto done; } if (!test_userinfo(p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) { - ret = False; + ret = false; goto done; } - if (!test_cleanup(p, mem_ctx, &h, TEST_USERNAME)) { - ret = False; + if (!test_user_cleanup(p, mem_ctx, &h, TEST_USERNAME)) { + ret = false; goto done; } @@ -349,22 +176,22 @@ BOOL torture_userinfo(struct torture_context *torture) * Testing asynchronous version and monitor messages */ if (!test_opendomain(p, mem_ctx, &h, &name, &sid)) { - ret = False; + ret = false; goto done; } - if (!test_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) { - ret = False; + if (!test_user_create(p, mem_ctx, &h, TEST_USERNAME, &rid)) { + ret = false; goto done; } if (!test_userinfo_async(p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) { - ret = False; + ret = false; goto done; } - if (!test_cleanup(p, mem_ctx, &h, TEST_USERNAME)) { - ret = False; + if (!test_user_cleanup(p, mem_ctx, &h, TEST_USERNAME)) { + ret = false; goto done; } diff --git a/source4/torture/libnet/userman.c b/source4/torture/libnet/userman.c index 90b3f41959..e834938bc5 100644 --- a/source4/torture/libnet/userman.c +++ b/source4/torture/libnet/userman.c @@ -23,65 +23,17 @@ #include "torture/libnet/usertest.h" #include "libnet/libnet.h" #include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" +#include "torture/libnet/utils.h" -static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, struct lsa_String *domname) -{ - NTSTATUS status; - struct policy_handle h, domain_handle; - struct samr_Connect r1; - struct samr_LookupDomain r2; - struct samr_OpenDomain r3; - - printf("connecting\n"); - - r1.in.system_name = 0; - r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r1.out.connect_handle = &h; - - status = dcerpc_samr_Connect(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("Connect failed - %s\n", nt_errstr(status)); - return False; - } - - r2.in.connect_handle = &h; - r2.in.domain_name = domname; - - printf("domain lookup on %s\n", domname->string); - - status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupDomain failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.connect_handle = &h; - r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r3.in.sid = r2.out.sid; - r3.out.domain_handle = &domain_handle; - - printf("opening domain\n"); - - status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenDomain failed - %s\n", nt_errstr(status)); - return False; - } else { - *handle = domain_handle; - } - - return True; -} - -static BOOL test_useradd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_useradd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, const char *name) { NTSTATUS status; - BOOL ret = True; + bool ret = true; struct libnet_rpc_useradd user; user.in.domain_handle = *domain_handle; @@ -91,28 +43,15 @@ static BOOL test_useradd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_useradd(p, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { - printf("Failed to call sync rpc_composite_userinfo - %s\n", nt_errstr(status)); - return False; + printf("Failed to call libnet_rpc_useradd - %s\n", nt_errstr(status)); + return false; } return ret; } -static void msg_handler(struct monitor_msg *m) -{ - struct msg_rpc_create_user *msg_create; - - switch (m->type) { - case mon_SamrCreateUser: - msg_create = (struct msg_rpc_create_user*)m->data; - printf("monitor_msg: user created (rid=%d)\n", msg_create->rid); - break; - } -} - - -static BOOL test_useradd_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_useradd_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char* username) { NTSTATUS status; @@ -127,133 +66,20 @@ static BOOL test_useradd_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, c = libnet_rpc_useradd_send(p, &user, msg_handler); if (!c) { printf("Failed to call async libnet_rpc_useradd\n"); - return False; + return false; } status = libnet_rpc_useradd_recv(c, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Calling async libnet_rpc_useradd failed - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } - -static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *domain_handle, const char *username) -{ - NTSTATUS status; - struct samr_LookupNames r1; - struct samr_OpenUser r2; - struct samr_DeleteUser r3; - struct lsa_String names[2]; - uint32_t rid; - struct policy_handle user_handle; - - names[0].string = username; - - r1.in.domain_handle = domain_handle; - r1.in.num_names = 1; - r1.in.names = names; - - printf("user account lookup '%s'\n", username); - - status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("LookupNames failed - %s\n", nt_errstr(status)); - return False; - } - - rid = r1.out.rids.ids[0]; - - r2.in.domain_handle = domain_handle; - r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r2.in.rid = rid; - r2.out.user_handle = &user_handle; - - printf("opening user account\n"); - - status = dcerpc_samr_OpenUser(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("OpenUser failed - %s\n", nt_errstr(status)); - return False; - } - - r3.in.user_handle = &user_handle; - r3.out.user_handle = &user_handle; - - printf("deleting user account\n"); - - status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3); - if (!NT_STATUS_IS_OK(status)) { - printf("DeleteUser failed - %s\n", nt_errstr(status)); - return False; - } - - return True; -} - - -static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, - struct policy_handle *handle, const char* user) -{ - NTSTATUS status; - struct policy_handle user_handle; - struct lsa_String username; - struct samr_CreateUser r1; - struct samr_Close r2; - uint32_t user_rid; - - username.string = user; - - r1.in.domain_handle = handle; - r1.in.account_name = &username; - r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; - r1.out.user_handle = &user_handle; - r1.out.rid = &user_rid; - - printf("creating user '%s'\n", username.string); - - status = dcerpc_samr_CreateUser(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateUser failed - %s\n", nt_errstr(status)); - - if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { - printf("User (%s) already exists - attempting to delete and recreate account again\n", user); - if (!test_cleanup(p, mem_ctx, handle, TEST_USERNAME)) { - return False; - } - - printf("creating user account\n"); - - status = dcerpc_samr_CreateUser(p, mem_ctx, &r1); - if (!NT_STATUS_IS_OK(status)) { - printf("CreateUser failed - %s\n", nt_errstr(status)); - return False; - } - return True; - } - return False; - } - - r2.in.handle = &user_handle; - r2.out.handle = &user_handle; - - printf("closing user '%s'\n", username.string); - - status = dcerpc_samr_Close(p, mem_ctx, &r2); - if (!NT_STATUS_IS_OK(status)) { - printf("Close failed - %s\n", nt_errstr(status)); - return False; - } - - return True; -} - - -static BOOL test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, int num_changes, struct libnet_rpc_usermod *mod, char **username) { @@ -356,7 +182,7 @@ static BOOL test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, case acct_expiry: continue_if_field_set(mod->in.change.acct_expiry); now = timeval_add(&now, (random() % (31*24*60*60)), 0); - mod->in.change.acct_expiry = talloc_memdup(mem_ctx, &now, sizeof(now)); + mod->in.change.acct_expiry = (struct timeval *)talloc_memdup(mem_ctx, &now, sizeof(now)); mod->in.change.fields |= USERMOD_FIELD_ACCT_EXPIRY; fldname = "acct_expiry"; break; @@ -380,14 +206,14 @@ static BOOL test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_usermod(p, mem_ctx, mod); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_usermod - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } -static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, const char *username) { NTSTATUS status; @@ -399,10 +225,10 @@ static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_userdel(p, mem_ctx, &user); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_userdel - %s\n", nt_errstr(status)); - return False; + return false; } - return True; + return true; } @@ -412,7 +238,7 @@ static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, printf("'%s' field does not match\n", #fld); \ printf("received: '%s'\n", i->fld.string); \ printf("expected: '%s'\n", mod->in.change.fld); \ - return False; \ + return false; \ } @@ -421,9 +247,12 @@ static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, nttime_to_timeval(&t, i->fld); \ if (timeval_compare(&t, mod->in.change.fld)) { \ printf("'%s' field does not match\n", #fld); \ - printf("received: '%s (+%ld us)'\n", timestring(mem_ctx, t.tv_sec), t.tv_usec); \ - printf("expected: '%s (+%ld us)'\n", timestring(mem_ctx, mod->in.change.fld->tv_sec), mod->in.change.fld->tv_usec); \ - return False; \ + printf("received: '%s (+%ld us)'\n", \ + timestring(mem_ctx, t.tv_sec), t.tv_usec); \ + printf("expected: '%s (+%ld us)'\n", \ + timestring(mem_ctx, mod->in.change.fld->tv_sec), \ + mod->in.change.fld->tv_usec); \ + return false; \ } \ } @@ -433,11 +262,11 @@ static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, printf("'%s' field does not match\n", #fld); \ printf("received: '%04x'\n", i->fld); \ printf("expected: '%04x'\n", mod->in.change.fld); \ - return False; \ + return false; \ } -static BOOL test_compare(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, +static bool test_compare(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, struct policy_handle *handle, struct libnet_rpc_usermod *mod, const char *username) { @@ -455,7 +284,7 @@ static BOOL test_compare(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, status = libnet_rpc_userinfo(p, mem_ctx, &info); if (!NT_STATUS_IS_OK(status)) { printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); - return False; + return false; } i = &info.out.info.info21; @@ -471,19 +300,20 @@ static BOOL test_compare(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, CMP_TIME_FLD(acct_expiry, USERMOD_FIELD_ACCT_EXPIRY); CMP_NUM_FLD(acct_flags, USERMOD_FIELD_ACCT_FLAGS) - return True; + return true; } -BOOL torture_useradd(struct torture_context *torture) +bool torture_useradd(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; struct policy_handle h; struct lsa_String domain_name; + struct dom_sid2 sid; const char *name = TEST_USERNAME; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; mem_ctx = talloc_init("test_useradd"); @@ -492,37 +322,37 @@ BOOL torture_useradd(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - domain_name.string = lp_workgroup(); - if (!test_opendomain(p, mem_ctx, &h, &domain_name)) { - ret = False; + domain_name.string = lp_workgroup(global_loadparm); + if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) { + ret = false; goto done; } if (!test_useradd(p, mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } - if (!test_cleanup(p, mem_ctx, &h, name)) { - ret = False; + if (!test_user_cleanup(p, mem_ctx, &h, name)) { + ret = false; goto done; } - if (!test_opendomain(p, mem_ctx, &h, &domain_name)) { - ret = False; + if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) { + ret = false; goto done; } if (!test_useradd_async(p, mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } - if (!test_cleanup(p, mem_ctx, &h, name)) { - ret = False; + if (!test_user_cleanup(p, mem_ctx, &h, name)) { + ret = false; goto done; } @@ -532,15 +362,17 @@ done: } -BOOL torture_userdel(struct torture_context *torture) +bool torture_userdel(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; struct policy_handle h; struct lsa_String domain_name; + struct dom_sid2 sid; + uint32_t rid; const char *name = TEST_USERNAME; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; mem_ctx = talloc_init("test_userdel"); @@ -549,22 +381,22 @@ BOOL torture_userdel(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - return False; + return false; } - domain_name.string = lp_workgroup(); - if (!test_opendomain(p, mem_ctx, &h, &domain_name)) { - ret = False; + domain_name.string = lp_workgroup(global_loadparm); + if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) { + ret = false; goto done; } - if (!test_createuser(p, mem_ctx, &h, name)) { - ret = False; + if (!test_user_create(p, mem_ctx, &h, name, &rid)) { + ret = false; goto done; } if (!test_userdel(p, mem_ctx, &h, name)) { - ret = False; + ret = false; goto done; } @@ -574,16 +406,18 @@ done: } -BOOL torture_usermod(struct torture_context *torture) +bool torture_usermod(struct torture_context *torture) { NTSTATUS status; struct dcerpc_pipe *p; struct policy_handle h; struct lsa_String domain_name; + struct dom_sid2 sid; + uint32_t rid; int i; char *name; TALLOC_CTX *mem_ctx; - BOOL ret = True; + bool ret = true; mem_ctx = talloc_init("test_userdel"); @@ -592,20 +426,20 @@ BOOL torture_usermod(struct torture_context *torture) &ndr_table_samr); if (!NT_STATUS_IS_OK(status)) { - ret = False; + ret = false; goto done; } - domain_name.string = lp_workgroup(); + domain_name.string = lp_workgroup(global_loadparm); name = talloc_strdup(mem_ctx, TEST_USERNAME); - if (!test_opendomain(p, mem_ctx, &h, &domain_name)) { - ret = False; + if (!test_opendomain(p, mem_ctx, &h, &domain_name, &sid)) { + ret = false; goto done; } - if (!test_createuser(p, mem_ctx, &h, name)) { - ret = False; + if (!test_user_create(p, mem_ctx, &h, name, &rid)) { + ret = false; goto done; } @@ -613,19 +447,19 @@ BOOL torture_usermod(struct torture_context *torture) struct libnet_rpc_usermod m; if (!test_usermod(p, mem_ctx, &h, i, &m, &name)) { - ret = False; + ret = false; goto cleanup; } if (!test_compare(p, mem_ctx, &h, &m, name)) { - ret = False; + ret = false; goto cleanup; } } cleanup: - if (!test_cleanup(p, mem_ctx, &h, name)) { - ret = False; + if (!test_user_cleanup(p, mem_ctx, &h, name)) { + ret = false; goto done; } diff --git a/source4/torture/libnet/utils.c b/source4/torture/libnet/utils.c new file mode 100644 index 0000000000..47bb9315c7 --- /dev/null +++ b/source4/torture/libnet/utils.c @@ -0,0 +1,313 @@ +/* + Unix SMB/CIFS implementation. + Test suite for libnet calls. + + Copyright (C) Rafal Szczesniak 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +/* + * These are more general use functions shared among the tests. + */ + +#include "includes.h" +#include "torture/rpc/rpc.h" +#include "libnet/libnet.h" +#include "librpc/gen_ndr/ndr_samr_c.h" +#include "param/param.h" + + +bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, struct lsa_String *domname, + struct dom_sid2 *sid) +{ + NTSTATUS status; + struct policy_handle h, domain_handle; + struct samr_Connect r1; + struct samr_LookupDomain r2; + struct samr_OpenDomain r3; + + printf("connecting\n"); + + r1.in.system_name = 0; + r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r1.out.connect_handle = &h; + + status = dcerpc_samr_Connect(p, mem_ctx, &r1); + if (!NT_STATUS_IS_OK(status)) { + printf("Connect failed - %s\n", nt_errstr(status)); + return false; + } + + r2.in.connect_handle = &h; + r2.in.domain_name = domname; + + printf("domain lookup on %s\n", domname->string); + + status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); + if (!NT_STATUS_IS_OK(status)) { + printf("LookupDomain failed - %s\n", nt_errstr(status)); + return false; + } + + r3.in.connect_handle = &h; + r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r3.in.sid = r2.out.sid; + r3.out.domain_handle = &domain_handle; + + printf("opening domain\n"); + + status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); + if (!NT_STATUS_IS_OK(status)) { + printf("OpenDomain failed - %s\n", nt_errstr(status)); + return false; + } else { + *handle = domain_handle; + } + + *sid = *r2.out.sid; + return true; +} + + +bool test_user_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle, + const char *name) +{ + NTSTATUS status; + struct samr_LookupNames r1; + struct samr_OpenUser r2; + struct samr_DeleteUser r3; + struct lsa_String names[2]; + uint32_t rid; + struct policy_handle user_handle; + + names[0].string = name; + + r1.in.domain_handle = domain_handle; + r1.in.num_names = 1; + r1.in.names = names; + + printf("user account lookup '%s'\n", name); + + status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); + if (!NT_STATUS_IS_OK(status)) { + printf("LookupNames failed - %s\n", nt_errstr(status)); + return false; + } + + rid = r1.out.rids.ids[0]; + + r2.in.domain_handle = domain_handle; + r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r2.in.rid = rid; + r2.out.user_handle = &user_handle; + + printf("opening user account\n"); + + status = dcerpc_samr_OpenUser(p, mem_ctx, &r2); + if (!NT_STATUS_IS_OK(status)) { + printf("OpenUser failed - %s\n", nt_errstr(status)); + return false; + } + + r3.in.user_handle = &user_handle; + r3.out.user_handle = &user_handle; + + printf("deleting user account\n"); + + status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3); + if (!NT_STATUS_IS_OK(status)) { + printf("DeleteUser failed - %s\n", nt_errstr(status)); + return false; + } + + return true; +} + + +bool test_user_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, const char *name, + uint32_t *rid) +{ + NTSTATUS status; + struct lsa_String username; + struct samr_CreateUser r; + struct policy_handle user_handle; + + username.string = name; + + r.in.domain_handle = handle; + r.in.account_name = &username; + r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r.out.user_handle = &user_handle; + r.out.rid = rid; + + printf("creating user account %s\n", name); + + status = dcerpc_samr_CreateUser(p, mem_ctx, &r); + if (!NT_STATUS_IS_OK(status)) { + printf("CreateUser failed - %s\n", nt_errstr(status)); + + if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { + printf("User (%s) already exists - attempting to delete and recreate account again\n", name); + if (!test_user_cleanup(p, mem_ctx, handle, name)) { + return false; + } + + printf("creating user account\n"); + + status = dcerpc_samr_CreateUser(p, mem_ctx, &r); + if (!NT_STATUS_IS_OK(status)) { + printf("CreateUser failed - %s\n", nt_errstr(status)); + return false; + } + return true; + } + return false; + } + + return true; +} + + +bool test_group_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle, + const char *name) +{ + NTSTATUS status; + struct samr_LookupNames r1; + struct samr_OpenGroup r2; + struct samr_DeleteDomainGroup r3; + struct lsa_String names[2]; + uint32_t rid; + struct policy_handle group_handle; + + names[0].string = name; + + r1.in.domain_handle = domain_handle; + r1.in.num_names = 1; + r1.in.names = names; + + printf("group account lookup '%s'\n", name); + + status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); + if (!NT_STATUS_IS_OK(status)) { + printf("LookupNames failed - %s\n", nt_errstr(status)); + return false; + } + + rid = r1.out.rids.ids[0]; + + r2.in.domain_handle = domain_handle; + r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r2.in.rid = rid; + r2.out.group_handle = &group_handle; + + printf("opening group account\n"); + + status = dcerpc_samr_OpenGroup(p, mem_ctx, &r2); + if (!NT_STATUS_IS_OK(status)) { + printf("OpenGroup failed - %s\n", nt_errstr(status)); + return false; + } + + r3.in.group_handle = &group_handle; + r3.out.group_handle = &group_handle; + + printf("deleting group account\n"); + + status = dcerpc_samr_DeleteDomainGroup(p, mem_ctx, &r3); + if (!NT_STATUS_IS_OK(status)) { + printf("DeleteGroup failed - %s\n", nt_errstr(status)); + return false; + } + + return true; +} + + +bool test_group_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, const char *name, + uint32_t *rid) +{ + NTSTATUS status; + struct lsa_String groupname; + struct samr_CreateDomainGroup r; + struct policy_handle group_handle; + + groupname.string = name; + + r.in.domain_handle = handle; + r.in.name = &groupname; + r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; + r.out.group_handle = &group_handle; + r.out.rid = rid; + + printf("creating group account %s\n", name); + + status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); + if (!NT_STATUS_IS_OK(status)) { + printf("CreateGroup failed - %s\n", nt_errstr(status)); + + if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { + printf("Group (%s) already exists - attempting to delete and recreate account again\n", name); + if (!test_group_cleanup(p, mem_ctx, handle, name)) { + return false; + } + + printf("creating group account\n"); + + status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); + if (!NT_STATUS_IS_OK(status)) { + printf("CreateGroup failed - %s\n", nt_errstr(status)); + return false; + } + return true; + } + return false; + } + + return true; +} + + +void msg_handler(struct monitor_msg *m) +{ + struct msg_rpc_open_user *msg_open; + struct msg_rpc_query_user *msg_query; + struct msg_rpc_close_user *msg_close; + struct msg_rpc_create_user *msg_create; + + switch (m->type) { + case mon_SamrOpenUser: + msg_open = (struct msg_rpc_open_user*)m->data; + printf("monitor_msg: user opened (rid=%d, access_mask=0x%08x)\n", + msg_open->rid, msg_open->access_mask); + break; + case mon_SamrQueryUser: + msg_query = (struct msg_rpc_query_user*)m->data; + printf("monitor_msg: user queried (level=%d)\n", msg_query->level); + break; + case mon_SamrCloseUser: + msg_close = (struct msg_rpc_close_user*)m->data; + printf("monitor_msg: user closed (rid=%d)\n", msg_close->rid); + break; + case mon_SamrCreateUser: + msg_create = (struct msg_rpc_create_user*)m->data; + printf("monitor_msg: user created (rid=%d)\n", msg_create->rid); + break; + } +} diff --git a/source4/torture/libnet/utils.h b/source4/torture/libnet/utils.h new file mode 100644 index 0000000000..ff94ec49e9 --- /dev/null +++ b/source4/torture/libnet/utils.h @@ -0,0 +1,42 @@ +/* + Unix SMB/CIFS implementation. + Test suite for libnet calls. + + Copyright (C) Rafal Szczesniak 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + + +bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, struct lsa_String *domname, + struct dom_sid2 *sid); + +bool test_user_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, const char *name, + uint32_t *rid); + +bool test_user_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle, + const char *name); + +bool test_group_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *handle, const char *name, + uint32_t *rid); + +bool test_group_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, + struct policy_handle *domain_handle, + const char *name); + +void msg_handler(struct monitor_msg *m); |