Changeset 745 for trunk/server/source4/torture/libnet
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 1 deleted
- 17 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/torture/libnet/domain.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 20 21 21 #include "includes.h" 22 #include "torture/rpc/rpc.h" 23 #include "lib/events/events.h" 22 #include "torture/rpc/torture_rpc.h" 24 23 #include "libnet/libnet.h" 25 24 #include "librpc/gen_ndr/ndr_samr_c.h" 26 25 #include "param/param.h" 27 26 28 static bool test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx, 27 static bool test_domainopen(struct torture_context *tctx, 28 struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx, 29 29 struct lsa_String *domname, 30 30 struct policy_handle *domain_handle) … … 32 32 NTSTATUS status; 33 33 struct libnet_DomainOpen io; 34 35 printf("opening domain\n");36 34 35 torture_comment(tctx, "opening domain\n"); 36 37 37 io.in.domain_name = talloc_strdup(mem_ctx, domname->string); 38 38 io.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; … … 40 40 status = libnet_DomainOpen(net_ctx, mem_ctx, &io); 41 41 if (!NT_STATUS_IS_OK(status)) { 42 printf("Composite domain open failed - %s\n", nt_errstr(status)); 42 torture_comment(tctx, "Composite domain open failed for domain '%s' - %s\n", 43 domname->string, nt_errstr(status)); 43 44 return false; 44 45 } … … 49 50 50 51 51 static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 52 static bool test_cleanup(struct torture_context *tctx, 53 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, 52 54 struct policy_handle *domain_handle) 53 55 { 54 NTSTATUS status;55 56 struct samr_Close r; 56 57 struct policy_handle handle; … … 58 59 r.in.handle = domain_handle; 59 60 r.out.handle = &handle; 60 61 printf("closing domain handle\n");62 63 status = dcerpc_samr_Close(p, mem_ctx, &r);64 if (!NT_STATUS_IS_OK(status)) {65 printf("Close failed - %s\n", nt_errstr(status));66 return false;67 }68 61 62 torture_comment(tctx, "closing domain handle\n"); 63 64 torture_assert_ntstatus_ok(tctx, 65 dcerpc_samr_Close_r(b, mem_ctx, &r), 66 "Close failed"); 67 torture_assert_ntstatus_ok(tctx, r.out.result, 68 "Close failed"); 69 69 70 return true; 70 71 } … … 84 85 net_ctx = libnet_context_init(torture->ev, torture->lp_ctx); 85 86 86 status = torture_rpc_connection(torture, 87 status = torture_rpc_connection(torture, 87 88 &net_ctx->samr.pipe, 88 89 &ndr_table_samr); 89 90 90 91 if (!NT_STATUS_IS_OK(status)) { 91 92 return false; 92 93 } 93 94 94 name.string = lp _workgroup(torture->lp_ctx);95 name.string = lpcfg_workgroup(torture->lp_ctx); 95 96 96 97 /* 97 98 * Testing synchronous version 98 99 */ 99 if (!test_domainopen( net_ctx, mem_ctx, &name, &h)) {100 if (!test_domainopen(torture, net_ctx, mem_ctx, &name, &h)) { 100 101 ret = false; 101 102 goto done; 102 103 } 103 104 104 if (!test_cleanup( net_ctx->samr.pipe, mem_ctx, &h)) {105 if (!test_cleanup(torture, net_ctx->samr.pipe->binding_handle, mem_ctx, &h)) { 105 106 ret = false; 106 107 goto done; -
trunk/server/source4/torture/libnet/groupinfo.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2007 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 20 21 21 #include "includes.h" 22 #include "torture/rpc/ rpc.h"22 #include "torture/rpc/torture_rpc.h" 23 23 #include "libnet/libnet.h" 24 24 #include "libcli/security/security.h" 25 25 #include "librpc/gen_ndr/ndr_samr_c.h" 26 26 #include "param/param.h" 27 #include "torture/libnet/ utils.h"27 #include "torture/libnet/proto.h" 28 28 29 29 #define TEST_GROUPNAME "libnetgroupinfotest" 30 30 31 31 32 static bool test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 32 static bool test_groupinfo(struct torture_context *tctx, 33 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 33 34 struct policy_handle *domain_handle, 34 35 struct dom_sid2 *domain_sid, const char* group_name, … … 39 40 struct libnet_rpc_groupinfo group; 40 41 struct dom_sid *group_sid; 41 42 42 43 group_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid); 43 44 44 45 group.in.domain_handle = *domain_handle; 45 46 group.in.sid = dom_sid_string(mem_ctx, group_sid); 46 47 group.in.level = level; /* this should be extended */ 47 48 48 printf("Testing sync libnet_rpc_groupinfo (SID argument)\n");49 torture_comment(tctx, "Testing sync libnet_rpc_groupinfo (SID argument)\n"); 49 50 status = libnet_rpc_groupinfo(p, mem_ctx, &group); 50 51 if (!NT_STATUS_IS_OK(status)) { 51 printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status));52 torture_comment(tctx, "Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); 52 53 return false; 53 54 } … … 63 64 status = libnet_rpc_groupinfo(p, mem_ctx, &group); 64 65 if (!NT_STATUS_IS_OK(status)) { 65 printf("Failed to call sync libnet_rpc_groupinfo - %s\n", nt_errstr(status));66 torture_comment(tctx, "Failed to call sync libnet_rpc_groupinfo - %s\n", nt_errstr(status)); 66 67 return false; 67 68 } … … 81 82 struct dom_sid2 sid; 82 83 uint32_t rid; 84 struct dcerpc_binding_handle *b; 83 85 84 86 mem_ctx = talloc_init("test_userinfo"); 85 87 86 status = torture_rpc_connection(torture, 88 status = torture_rpc_connection(torture, 87 89 &p, 88 90 &ndr_table_samr); 89 91 90 92 if (!NT_STATUS_IS_OK(status)) { 91 93 return false; 92 94 } 95 b = p->binding_handle; 93 96 94 name.string = lp _workgroup(torture->lp_ctx);97 name.string = lpcfg_workgroup(torture->lp_ctx); 95 98 96 99 /* 97 100 * Testing synchronous version 98 101 */ 99 if (!test_ opendomain(torture, p, mem_ctx, &h, &name, &sid)) {102 if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) { 100 103 ret = false; 101 104 goto done; 102 105 } 103 106 104 if (!test_group_create( p, mem_ctx, &h, TEST_GROUPNAME, &rid)) {107 if (!test_group_create(torture, b, mem_ctx, &h, TEST_GROUPNAME, &rid)) { 105 108 ret = false; 106 109 goto done; 107 110 } 108 111 109 if (!test_groupinfo( p, mem_ctx, &h, &sid, TEST_GROUPNAME, &rid)) {112 if (!test_groupinfo(torture, p, mem_ctx, &h, &sid, TEST_GROUPNAME, &rid)) { 110 113 ret = false; 111 114 goto done; 112 115 } 113 116 114 if (!test_group_cleanup( p, mem_ctx, &h, TEST_GROUPNAME)) {117 if (!test_group_cleanup(torture, b, mem_ctx, &h, TEST_GROUPNAME)) { 115 118 ret = false; 116 119 goto done; -
trunk/server/source4/torture/libnet/groupman.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2007 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 20 21 21 #include "includes.h" 22 #include "torture/rpc/ rpc.h"22 #include "torture/rpc/torture_rpc.h" 23 23 #include "torture/libnet/grouptest.h" 24 24 #include "libnet/libnet.h" 25 25 #include "librpc/gen_ndr/ndr_samr_c.h" 26 26 #include "param/param.h" 27 #include "torture/libnet/ utils.h"27 #include "torture/libnet/proto.h" 28 28 29 29 … … 38 38 group.in.domain_handle = *domain_handle; 39 39 group.in.groupname = name; 40 40 41 41 printf("Testing libnet_rpc_groupadd\n"); 42 42 … … 46 46 return false; 47 47 } 48 48 49 49 return ret; 50 50 } … … 61 61 TALLOC_CTX *mem_ctx; 62 62 bool ret = true; 63 struct dcerpc_binding_handle *b; 63 64 64 65 mem_ctx = talloc_init("test_groupadd"); 65 66 66 status = torture_rpc_connection(torture, 67 status = torture_rpc_connection(torture, 67 68 &p, 68 69 &ndr_table_samr); 69 70 70 71 torture_assert_ntstatus_ok(torture, status, "RPC connection"); 72 b = p->binding_handle; 71 73 72 domain_name.string = lp _workgroup(torture->lp_ctx);73 if (!test_ opendomain(torture, p, mem_ctx, &h, &domain_name, &sid)) {74 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 75 if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) { 74 76 ret = false; 75 77 goto done; … … 81 83 } 82 84 83 if (!test_group_cleanup( p, mem_ctx, &h, name)) {85 if (!test_group_cleanup(torture, b, mem_ctx, &h, name)) { 84 86 ret = false; 85 87 goto done; 86 88 } 87 89 88 90 done: 89 91 talloc_free(mem_ctx); -
trunk/server/source4/torture/libnet/grouptest.h
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 4 4 Copyright (C) Rafal Szczesniak 2007 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 3 of the License, or 9 9 (at your option) any later version. 10 10 11 11 This program is distributed in the hope that it will be useful, 12 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 14 GNU General Public License for more details. 15 15 16 16 You should have received a copy of the GNU General Public License 17 17 along with this program. If not, see <http://www.gnu.org/licenses/>. -
trunk/server/source4/torture/libnet/libnet.c
r414 r745 21 21 #include "torture/smbtorture.h" 22 22 #include "librpc/rpc/dcerpc.h" 23 #include "librpc/gen_ndr/security.h"24 23 #include "librpc/gen_ndr/lsa.h" 25 #include "libnet/ composite.h"24 #include "libnet/libnet.h" 26 25 #include "torture/libnet/proto.h" 27 26 28 27 NTSTATUS torture_net_init(void) 29 28 { 30 struct torture_suite *suite = torture_suite_create(talloc_autofree_context(), "NET"); 29 struct torture_suite *suite = torture_suite_create( 30 talloc_autofree_context(), "net"); 31 31 32 torture_suite_add_simple_test(suite, " USERINFO", torture_userinfo);33 torture_suite_add_simple_test(suite, " USERADD", torture_useradd);34 torture_suite_add_simple_test(suite, " USERDEL", torture_userdel);35 torture_suite_add_simple_test(suite, " USERMOD", torture_usermod);36 torture_suite_add_simple_test(suite, " DOMOPEN", torture_domainopen);37 torture_suite_add_simple_test(suite, " GROUPINFO", torture_groupinfo);38 torture_suite_add_simple_test(suite, " GROUPADD", torture_groupadd);39 torture_suite_add_simple_test(suite, " API-LOOKUP", torture_lookup);40 torture_suite_add_simple_test(suite, " API-LOOKUPHOST", torture_lookup_host);41 torture_suite_add_simple_test(suite, " API-LOOKUPPDC", torture_lookup_pdc);42 torture_suite_add_simple_test(suite, " API-LOOKUPNAME", torture_lookup_sam_name);43 torture_suite_add_simple_test(suite, " API-CREATEUSER", torture_createuser);44 torture_suite_add_simple_test(suite, " API-DELETEUSER", torture_deleteuser);45 torture_suite_add_simple_test(suite, " API-MODIFYUSER", torture_modifyuser);46 torture_suite_add_simple_test(suite, " API-USERINFO", torture_userinfo_api);47 torture_suite_add_simple_test(suite, " API-USERLIST", torture_userlist);48 torture_suite_add_simple_test(suite, " API-GROUPINFO", torture_groupinfo_api);49 torture_suite_add_simple_test(suite, " API-GROUPLIST", torture_grouplist);50 torture_suite_add_simple_test(suite, " API-CREATEGROUP", torture_creategroup);51 torture_suite_add_simple_test(suite, " API-RPCCONN-BIND", torture_rpc_connect_binding);52 torture_suite_add_simple_test(suite, " API-RPCCONN-SRV", torture_rpc_connect_srv);53 torture_suite_add_simple_test(suite, " API-RPCCONN-PDC", torture_rpc_connect_pdc);54 torture_suite_add_simple_test(suite, " API-RPCCONN-DC", torture_rpc_connect_dc);55 torture_suite_add_simple_test(suite, " API-RPCCONN-DCINFO", torture_rpc_connect_dc_info);56 torture_suite_add_simple_test(suite, " API-LISTSHARES", torture_listshares);57 torture_suite_add_simple_test(suite, " API-DELSHARE", torture_delshare);58 torture_suite_add_simple_test(suite, " API-DOMOPENLSA", torture_domain_open_lsa);59 torture_suite_add_simple_test(suite, " API-DOMCLOSELSA", torture_domain_close_lsa);60 torture_suite_add_simple_test(suite, " API-DOMOPENSAMR", torture_domain_open_samr);61 torture_suite_add_simple_test(suite, " API-DOMCLOSESAMR", torture_domain_close_samr);62 torture_suite_add_simple_test(suite, " API-BECOME-DC", torture_net_become_dc);63 torture_suite_add_simple_test(suite, " API-DOMLIST", torture_domain_list);32 torture_suite_add_simple_test(suite, "userinfo", torture_userinfo); 33 torture_suite_add_simple_test(suite, "useradd", torture_useradd); 34 torture_suite_add_simple_test(suite, "userdel", torture_userdel); 35 torture_suite_add_simple_test(suite, "usermod", torture_usermod); 36 torture_suite_add_simple_test(suite, "domopen", torture_domainopen); 37 torture_suite_add_simple_test(suite, "groupinfo", torture_groupinfo); 38 torture_suite_add_simple_test(suite, "groupadd", torture_groupadd); 39 torture_suite_add_simple_test(suite, "api.lookup", torture_lookup); 40 torture_suite_add_simple_test(suite, "api.lookuphost", torture_lookup_host); 41 torture_suite_add_simple_test(suite, "api.lookuppdc", torture_lookup_pdc); 42 torture_suite_add_simple_test(suite, "api.lookupname", torture_lookup_sam_name); 43 torture_suite_add_simple_test(suite, "api.createuser", torture_createuser); 44 torture_suite_add_simple_test(suite, "api.deleteuser", torture_deleteuser); 45 torture_suite_add_simple_test(suite, "api.modifyuser", torture_modifyuser); 46 torture_suite_add_simple_test(suite, "api.userinfo", torture_userinfo_api); 47 torture_suite_add_simple_test(suite, "api.userlist", torture_userlist); 48 torture_suite_add_simple_test(suite, "api.groupinfo", torture_groupinfo_api); 49 torture_suite_add_simple_test(suite, "api.grouplist", torture_grouplist); 50 torture_suite_add_simple_test(suite, "api.creategroup", torture_creategroup); 51 torture_suite_add_simple_test(suite, "api.rpcconn.bind", torture_rpc_connect_binding); 52 torture_suite_add_simple_test(suite, "api.rpcconn.srv", torture_rpc_connect_srv); 53 torture_suite_add_simple_test(suite, "api.rpcconn.pdc", torture_rpc_connect_pdc); 54 torture_suite_add_simple_test(suite, "api.rpcconn.dc", torture_rpc_connect_dc); 55 torture_suite_add_simple_test(suite, "api.rpcconn.dcinfo", torture_rpc_connect_dc_info); 56 torture_suite_add_simple_test(suite, "api.listshares", torture_listshares); 57 torture_suite_add_simple_test(suite, "api.delshare", torture_delshare); 58 torture_suite_add_simple_test(suite, "api.domopenlsa", torture_domain_open_lsa); 59 torture_suite_add_simple_test(suite, "api.domcloselsa", torture_domain_close_lsa); 60 torture_suite_add_simple_test(suite, "api.domopensamr", torture_domain_open_samr); 61 torture_suite_add_simple_test(suite, "api.domclosesamr", torture_domain_close_samr); 62 torture_suite_add_simple_test(suite, "api.become.dc", torture_net_become_dc); 63 torture_suite_add_simple_test(suite, "api.domlist", torture_domain_list); 64 64 65 65 suite->description = talloc_strdup(suite, "libnet convenience interface tests"); -
trunk/server/source4/torture/libnet/libnet_BecomeDC.c
r414 r745 22 22 #include "includes.h" 23 23 #include "lib/cmdline/popt_common.h" 24 #include "torture/torture.h" 25 #include "torture/rpc/rpc.h" 24 #include "torture/rpc/torture_rpc.h" 26 25 #include "libnet/libnet.h" 27 #include "lib/events/events.h"28 26 #include "dsdb/samdb/samdb.h" 29 27 #include "../lib/util/dlinklist.h" 30 #include "lib/ldb/include/ldb.h"31 #include "lib/ldb/include/ldb_errors.h"32 #include "librpc/ndr/libndr.h"33 28 #include "librpc/gen_ndr/ndr_drsuapi.h" 34 29 #include "librpc/gen_ndr/ndr_drsblobs.h" 35 #include "librpc/gen_ndr/ndr_misc.h"36 30 #include "system/time.h" 37 #include "l ib/ldb_wrap.h"31 #include "ldb_wrap.h" 38 32 #include "auth/auth.h" 39 33 #include "param/param.h" 40 #include "torture/util.h"41 34 #include "param/provision.h" 42 43 struct test_become_dc_state { 44 struct libnet_context *ctx; 45 struct torture_context *tctx; 46 const char *netbios_name; 47 struct test_join *tj; 48 struct cli_credentials *machine_account; 49 struct dsdb_schema *self_made_schema; 50 const struct dsdb_schema *schema; 51 52 struct ldb_context *ldb; 53 54 struct { 55 uint32_t object_count; 56 struct drsuapi_DsReplicaObjectListItemEx *first_object; 57 struct drsuapi_DsReplicaObjectListItemEx *last_object; 58 } schema_part; 59 60 const char *targetdir; 61 62 struct loadparm_context *lp_ctx; 63 }; 64 65 static NTSTATUS test_become_dc_prepare_db(void *private_data, 66 const struct libnet_BecomeDC_PrepareDB *p) 67 { 68 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); 69 struct provision_settings settings; 70 struct provision_result result; 71 NTSTATUS status; 72 73 settings.site_name = p->dest_dsa->site_name; 74 settings.root_dn_str = p->forest->root_dn_str; 75 settings.domain_dn_str = p->domain->dn_str; 76 settings.config_dn_str = p->forest->config_dn_str; 77 settings.schema_dn_str = p->forest->schema_dn_str; 78 settings.server_dn_str = torture_join_server_dn_str(s->tj); 79 settings.invocation_id = &p->dest_dsa->invocation_id; 80 settings.netbios_name = p->dest_dsa->netbios_name; 81 settings.host_ip = NULL; 82 settings.realm = torture_join_dom_dns_name(s->tj); 83 settings.domain = torture_join_dom_netbios_name(s->tj); 84 settings.ntds_dn_str = p->dest_dsa->ntds_dn_str; 85 settings.machine_password = cli_credentials_get_password(s->machine_account); 86 settings.targetdir = s->targetdir; 87 88 status = provision_bare(s, s->lp_ctx, &settings, &result); 89 90 s->ldb = result.samdb; 91 s->lp_ctx = result.lp_ctx; 92 return NT_STATUS_OK; 93 94 95 } 96 97 static NTSTATUS test_become_dc_check_options(void *private_data, 98 const struct libnet_BecomeDC_CheckOptions *o) 99 { 100 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); 101 102 DEBUG(0,("Become DC [%s] of Domain[%s]/[%s]\n", 103 s->netbios_name, 104 o->domain->netbios_name, o->domain->dns_name)); 105 106 DEBUG(0,("Promotion Partner is Server[%s] from Site[%s]\n", 107 o->source_dsa->dns_name, o->source_dsa->site_name)); 108 109 DEBUG(0,("Options:crossRef behavior_version[%u]\n" 110 "\tschema object_version[%u]\n" 111 "\tdomain behavior_version[%u]\n" 112 "\tdomain w2k3_update_revision[%u]\n", 113 o->forest->crossref_behavior_version, 114 o->forest->schema_object_version, 115 o->domain->behavior_version, 116 o->domain->w2k3_update_revision)); 117 118 return NT_STATUS_OK; 119 } 120 121 static NTSTATUS test_apply_schema(struct test_become_dc_state *s, 122 const struct libnet_BecomeDC_StoreChunk *c) 123 { 124 WERROR status; 125 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr; 126 uint32_t object_count; 127 struct drsuapi_DsReplicaObjectListItemEx *first_object; 128 struct drsuapi_DsReplicaObjectListItemEx *cur; 129 uint32_t linked_attributes_count; 130 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes; 131 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector; 132 struct dsdb_extended_replicated_objects *objs; 133 struct repsFromTo1 *s_dsa; 134 char *tmp_dns_name; 135 struct ldb_message *msg; 136 struct ldb_val prefixMap_val; 137 struct ldb_message_element *prefixMap_el; 138 struct ldb_val schemaInfo_val; 139 char *sam_ldb_path; 140 uint32_t i; 141 int ret; 142 bool ok; 143 uint64_t seq_num; 144 145 DEBUG(0,("Analyze and apply schema objects\n")); 146 147 s_dsa = talloc_zero(s, struct repsFromTo1); 148 NT_STATUS_HAVE_NO_MEMORY(s_dsa); 149 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo); 150 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info); 151 152 switch (c->ctr_level) { 153 case 1: 154 mapping_ctr = &c->ctr1->mapping_ctr; 155 object_count = s->schema_part.object_count; 156 first_object = s->schema_part.first_object; 157 linked_attributes_count = 0; 158 linked_attributes = NULL; 159 s_dsa->highwatermark = c->ctr1->new_highwatermark; 160 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid; 161 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id; 162 uptodateness_vector = NULL; /* TODO: map it */ 163 break; 164 case 6: 165 mapping_ctr = &c->ctr6->mapping_ctr; 166 object_count = s->schema_part.object_count; 167 first_object = s->schema_part.first_object; 168 linked_attributes_count = 0; /* TODO: ! */ 169 linked_attributes = NULL; /* TODO: ! */; 170 s_dsa->highwatermark = c->ctr6->new_highwatermark; 171 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid; 172 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id; 173 uptodateness_vector = c->ctr6->uptodateness_vector; 174 break; 175 default: 176 return NT_STATUS_INVALID_PARAMETER; 177 } 178 179 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE 180 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP 181 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS; 182 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule)); 183 184 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid); 185 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); 186 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); 187 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); 188 s_dsa->other_info->dns_name = tmp_dns_name; 189 190 for (cur = first_object; cur; cur = cur->next_object) { 191 bool is_attr = false; 192 bool is_class = false; 193 194 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) { 195 struct drsuapi_DsReplicaAttribute *a; 196 uint32_t j; 197 const char *oid = NULL; 198 199 a = &cur->object.attribute_ctr.attributes[i]; 200 status = dsdb_map_int2oid(s->self_made_schema, a->attid, s, &oid); 201 if (!W_ERROR_IS_OK(status)) { 202 return werror_to_ntstatus(status); 203 } 204 205 switch (a->attid) { 206 case DRSUAPI_ATTRIBUTE_objectClass: 207 for (j=0; j < a->value_ctr.num_values; j++) { 208 uint32_t val = 0xFFFFFFFF; 209 210 if (a->value_ctr.values[i].blob 211 && a->value_ctr.values[i].blob->length == 4) { 212 val = IVAL(a->value_ctr.values[i].blob->data,0); 213 } 214 215 if (val == DRSUAPI_OBJECTCLASS_attributeSchema) { 216 is_attr = true; 217 } 218 if (val == DRSUAPI_OBJECTCLASS_classSchema) { 219 is_class = true; 220 } 221 } 222 223 break; 224 default: 225 break; 226 } 227 } 228 229 if (is_attr) { 230 struct dsdb_attribute *sa; 231 232 sa = talloc_zero(s->self_made_schema, struct dsdb_attribute); 233 NT_STATUS_HAVE_NO_MEMORY(sa); 234 235 status = dsdb_attribute_from_drsuapi(s->ldb, s->self_made_schema, &cur->object, s, sa); 236 if (!W_ERROR_IS_OK(status)) { 237 return werror_to_ntstatus(status); 238 } 239 240 DLIST_ADD_END(s->self_made_schema->attributes, sa, struct dsdb_attribute *); 241 } 242 243 if (is_class) { 244 struct dsdb_class *sc; 245 246 sc = talloc_zero(s->self_made_schema, struct dsdb_class); 247 NT_STATUS_HAVE_NO_MEMORY(sc); 248 249 status = dsdb_class_from_drsuapi(s->self_made_schema, &cur->object, s, sc); 250 if (!W_ERROR_IS_OK(status)) { 251 return werror_to_ntstatus(status); 252 } 253 254 DLIST_ADD_END(s->self_made_schema->classes, sc, struct dsdb_class *); 255 } 256 } 257 258 /* attach the schema to the ldb */ 259 ret = dsdb_set_schema(s->ldb, s->self_made_schema); 260 if (ret != LDB_SUCCESS) { 261 return NT_STATUS_FOOBAR; 262 } 263 /* we don't want to access the self made schema anymore */ 264 s->self_made_schema = NULL; 265 s->schema = dsdb_get_schema(s->ldb); 266 267 status = dsdb_extended_replicated_objects_commit(s->ldb, 268 c->partition->nc.dn, 269 mapping_ctr, 270 object_count, 271 first_object, 272 linked_attributes_count, 273 linked_attributes, 274 s_dsa, 275 uptodateness_vector, 276 c->gensec_skey, 277 s, &objs, &seq_num); 278 if (!W_ERROR_IS_OK(status)) { 279 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status))); 280 return werror_to_ntstatus(status); 281 } 282 283 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) { 284 for (i=0; i < objs->num_objects; i++) { 285 struct ldb_ldif ldif; 286 fprintf(stdout, "#\n"); 287 ldif.changetype = LDB_CHANGETYPE_NONE; 288 ldif.msg = objs->objects[i].msg; 289 ldb_ldif_write_file(s->ldb, stdout, &ldif); 290 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data); 291 } 292 } 293 294 msg = ldb_msg_new(objs); 295 NT_STATUS_HAVE_NO_MEMORY(msg); 296 msg->dn = objs->partition_dn; 297 298 status = dsdb_get_oid_mappings_ldb(s->schema, msg, &prefixMap_val, &schemaInfo_val); 299 if (!W_ERROR_IS_OK(status)) { 300 DEBUG(0,("Failed dsdb_get_oid_mappings_ldb(%s)\n", win_errstr(status))); 301 return werror_to_ntstatus(status); 302 } 303 304 /* we only add prefixMap here, because schemaInfo is a replicated attribute and already applied */ 305 ret = ldb_msg_add_value(msg, "prefixMap", &prefixMap_val, &prefixMap_el); 306 if (ret != LDB_SUCCESS) { 307 return NT_STATUS_FOOBAR; 308 } 309 prefixMap_el->flags = LDB_FLAG_MOD_REPLACE; 310 311 ret = ldb_modify(s->ldb, msg); 312 if (ret != LDB_SUCCESS) { 313 DEBUG(0,("Failed to add prefixMap and schemaInfo %s\n", ldb_strerror(ret))); 314 return NT_STATUS_FOOBAR; 315 } 316 317 talloc_free(s_dsa); 318 talloc_free(objs); 319 320 /* reopen the ldb */ 321 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */ 322 s->schema = NULL; 323 324 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb"); 325 DEBUG(0,("Reopen the SAM LDB with system credentials and a already stored schema: %s\n", sam_ldb_path)); 326 s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->tctx->lp_ctx, sam_ldb_path, 327 system_session(s, s->tctx->lp_ctx), 328 NULL, 0, NULL); 329 if (!s->ldb) { 330 DEBUG(0,("Failed to open '%s'\n", 331 sam_ldb_path)); 332 return NT_STATUS_INTERNAL_DB_ERROR; 333 } 334 335 ok = samdb_set_ntds_invocation_id(s->ldb, &c->dest_dsa->invocation_id); 336 if (!ok) { 337 DEBUG(0,("Failed to set cached ntds invocationId\n")); 338 return NT_STATUS_FOOBAR; 339 } 340 ok = samdb_set_ntds_objectGUID(s->ldb, &c->dest_dsa->ntds_guid); 341 if (!ok) { 342 DEBUG(0,("Failed to set cached ntds objectGUID\n")); 343 return NT_STATUS_FOOBAR; 344 } 345 346 s->schema = dsdb_get_schema(s->ldb); 347 if (!s->schema) { 348 DEBUG(0,("Failed to get loaded dsdb_schema\n")); 349 return NT_STATUS_FOOBAR; 350 } 351 352 return NT_STATUS_OK; 353 } 354 355 static NTSTATUS test_become_dc_schema_chunk(void *private_data, 356 const struct libnet_BecomeDC_StoreChunk *c) 357 { 358 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); 359 WERROR status; 360 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr; 361 uint32_t nc_object_count; 362 uint32_t object_count; 363 struct drsuapi_DsReplicaObjectListItemEx *first_object; 364 struct drsuapi_DsReplicaObjectListItemEx *cur; 365 uint32_t nc_linked_attributes_count; 366 uint32_t linked_attributes_count; 367 368 switch (c->ctr_level) { 369 case 1: 370 mapping_ctr = &c->ctr1->mapping_ctr; 371 nc_object_count = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */ 372 object_count = c->ctr1->object_count; 373 first_object = c->ctr1->first_object; 374 nc_linked_attributes_count = 0; 375 linked_attributes_count = 0; 376 break; 377 case 6: 378 mapping_ctr = &c->ctr6->mapping_ctr; 379 nc_object_count = c->ctr6->nc_object_count; 380 object_count = c->ctr6->object_count; 381 first_object = c->ctr6->first_object; 382 nc_linked_attributes_count = c->ctr6->nc_linked_attributes_count; 383 linked_attributes_count = c->ctr6->linked_attributes_count; 384 break; 385 default: 386 return NT_STATUS_INVALID_PARAMETER; 387 } 388 389 if (nc_object_count) { 390 DEBUG(0,("Schema-DN[%s] objects[%u/%u] linked_values[%u/%u]\n", 391 c->partition->nc.dn, object_count, nc_object_count, 392 linked_attributes_count, nc_linked_attributes_count)); 393 } else { 394 DEBUG(0,("Schema-DN[%s] objects[%u] linked_values[%u\n", 395 c->partition->nc.dn, object_count, linked_attributes_count)); 396 } 397 398 if (!s->schema) { 399 s->self_made_schema = dsdb_new_schema(s, lp_iconv_convenience(s->lp_ctx)); 400 401 NT_STATUS_HAVE_NO_MEMORY(s->self_made_schema); 402 403 status = dsdb_load_oid_mappings_drsuapi(s->self_made_schema, mapping_ctr); 404 if (!W_ERROR_IS_OK(status)) { 405 return werror_to_ntstatus(status); 406 } 407 408 s->schema = s->self_made_schema; 409 } else { 410 status = dsdb_verify_oid_mappings_drsuapi(s->schema, mapping_ctr); 411 if (!W_ERROR_IS_OK(status)) { 412 return werror_to_ntstatus(status); 413 } 414 } 415 416 if (!s->schema_part.first_object) { 417 s->schema_part.object_count = object_count; 418 s->schema_part.first_object = talloc_steal(s, first_object); 419 } else { 420 s->schema_part.object_count += object_count; 421 s->schema_part.last_object->next_object = talloc_steal(s->schema_part.last_object, 422 first_object); 423 } 424 for (cur = first_object; cur->next_object; cur = cur->next_object) {} 425 s->schema_part.last_object = cur; 426 427 if (!c->partition->more_data) { 428 return test_apply_schema(s, c); 429 } 430 431 return NT_STATUS_OK; 432 } 433 434 static NTSTATUS test_become_dc_store_chunk(void *private_data, 435 const struct libnet_BecomeDC_StoreChunk *c) 436 { 437 struct test_become_dc_state *s = talloc_get_type(private_data, struct test_become_dc_state); 438 WERROR status; 439 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr; 440 uint32_t nc_object_count; 441 uint32_t object_count; 442 struct drsuapi_DsReplicaObjectListItemEx *first_object; 443 uint32_t nc_linked_attributes_count; 444 uint32_t linked_attributes_count; 445 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes; 446 const struct drsuapi_DsReplicaCursor2CtrEx *uptodateness_vector; 447 struct dsdb_extended_replicated_objects *objs; 448 struct repsFromTo1 *s_dsa; 449 char *tmp_dns_name; 450 uint32_t i; 451 uint64_t seq_num; 452 453 s_dsa = talloc_zero(s, struct repsFromTo1); 454 NT_STATUS_HAVE_NO_MEMORY(s_dsa); 455 s_dsa->other_info = talloc(s_dsa, struct repsFromTo1OtherInfo); 456 NT_STATUS_HAVE_NO_MEMORY(s_dsa->other_info); 457 458 switch (c->ctr_level) { 459 case 1: 460 mapping_ctr = &c->ctr1->mapping_ctr; 461 nc_object_count = c->ctr1->extended_ret; /* maybe w2k send this unexpected? */ 462 object_count = c->ctr1->object_count; 463 first_object = c->ctr1->first_object; 464 nc_linked_attributes_count = 0; 465 linked_attributes_count = 0; 466 linked_attributes = NULL; 467 s_dsa->highwatermark = c->ctr1->new_highwatermark; 468 s_dsa->source_dsa_obj_guid = c->ctr1->source_dsa_guid; 469 s_dsa->source_dsa_invocation_id = c->ctr1->source_dsa_invocation_id; 470 uptodateness_vector = NULL; /* TODO: map it */ 471 break; 472 case 6: 473 mapping_ctr = &c->ctr6->mapping_ctr; 474 nc_object_count = c->ctr6->nc_object_count; 475 object_count = c->ctr6->object_count; 476 first_object = c->ctr6->first_object; 477 nc_linked_attributes_count = c->ctr6->nc_linked_attributes_count; 478 linked_attributes_count = c->ctr6->linked_attributes_count; 479 linked_attributes = c->ctr6->linked_attributes; 480 s_dsa->highwatermark = c->ctr6->new_highwatermark; 481 s_dsa->source_dsa_obj_guid = c->ctr6->source_dsa_guid; 482 s_dsa->source_dsa_invocation_id = c->ctr6->source_dsa_invocation_id; 483 uptodateness_vector = c->ctr6->uptodateness_vector; 484 break; 485 default: 486 return NT_STATUS_INVALID_PARAMETER; 487 } 488 489 s_dsa->replica_flags = DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE 490 | DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP 491 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS; 492 memset(s_dsa->schedule, 0x11, sizeof(s_dsa->schedule)); 493 494 tmp_dns_name = GUID_string(s_dsa->other_info, &s_dsa->source_dsa_obj_guid); 495 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); 496 tmp_dns_name = talloc_asprintf_append_buffer(tmp_dns_name, "._msdcs.%s", c->forest->dns_name); 497 NT_STATUS_HAVE_NO_MEMORY(tmp_dns_name); 498 s_dsa->other_info->dns_name = tmp_dns_name; 499 500 if (nc_object_count) { 501 DEBUG(0,("Partition[%s] objects[%u/%u] linked_values[%u/%u]\n", 502 c->partition->nc.dn, object_count, nc_object_count, 503 linked_attributes_count, nc_linked_attributes_count)); 504 } else { 505 DEBUG(0,("Partition[%s] objects[%u] linked_values[%u\n", 506 c->partition->nc.dn, object_count, linked_attributes_count)); 507 } 508 509 status = dsdb_extended_replicated_objects_commit(s->ldb, 510 c->partition->nc.dn, 511 mapping_ctr, 512 object_count, 513 first_object, 514 linked_attributes_count, 515 linked_attributes, 516 s_dsa, 517 uptodateness_vector, 518 c->gensec_skey, 519 s, &objs, &seq_num); 520 if (!W_ERROR_IS_OK(status)) { 521 DEBUG(0,("Failed to commit objects: %s\n", win_errstr(status))); 522 return werror_to_ntstatus(status); 523 } 524 525 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) { 526 for (i=0; i < objs->num_objects; i++) { 527 struct ldb_ldif ldif; 528 fprintf(stdout, "#\n"); 529 ldif.changetype = LDB_CHANGETYPE_NONE; 530 ldif.msg = objs->objects[i].msg; 531 ldb_ldif_write_file(s->ldb, stdout, &ldif); 532 NDR_PRINT_DEBUG(replPropertyMetaDataBlob, objs->objects[i].meta_data); 533 } 534 } 535 talloc_free(s_dsa); 536 talloc_free(objs); 537 538 for (i=0; i < linked_attributes_count; i++) { 539 const struct dsdb_attribute *sa; 540 541 if (!linked_attributes[i].identifier) { 542 return NT_STATUS_FOOBAR; 543 } 544 545 if (!linked_attributes[i].value.blob) { 546 return NT_STATUS_FOOBAR; 547 } 548 549 sa = dsdb_attribute_by_attributeID_id(s->schema, 550 linked_attributes[i].attid); 551 if (!sa) { 552 return NT_STATUS_FOOBAR; 553 } 554 555 if (lp_parm_bool(s->tctx->lp_ctx, NULL, "become dc", "dump objects", false)) { 556 DEBUG(0,("# %s\n", sa->lDAPDisplayName)); 557 NDR_PRINT_DEBUG(drsuapi_DsReplicaLinkedAttribute, &linked_attributes[i]); 558 dump_data(0, 559 linked_attributes[i].value.blob->data, 560 linked_attributes[i].value.blob->length); 561 } 562 } 563 564 return NT_STATUS_OK; 565 } 35 #include "libcli/resolve/resolve.h" 566 36 567 37 bool torture_net_become_dc(struct torture_context *torture) … … 571 41 struct libnet_BecomeDC b; 572 42 struct libnet_UnbecomeDC u; 573 struct test_become_dc_state *s;43 struct libnet_vampire_cb_state *s; 574 44 struct ldb_message *msg; 575 45 int ldb_ret; 576 46 uint32_t i; 577 47 char *sam_ldb_path; 48 const char *address; 49 struct nbt_name name; 50 const char *netbios_name; 51 struct cli_credentials *machine_account; 52 struct test_join *tj; 53 struct loadparm_context *lp_ctx; 54 struct ldb_context *ldb; 55 struct libnet_context *ctx; 56 struct dsdb_schema *schema; 578 57 579 58 char *location = NULL; … … 581 60 "torture_temp_dir should return NT_STATUS_OK" ); 582 61 583 s = talloc_zero(torture, struct test_become_dc_state); 584 if (!s) return false; 585 586 s->tctx = torture; 587 s->lp_ctx = torture->lp_ctx; 588 589 s->netbios_name = lp_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc"); 590 if (!s->netbios_name || !s->netbios_name[0]) { 591 s->netbios_name = "smbtorturedc"; 62 netbios_name = lpcfg_parm_string(torture->lp_ctx, NULL, "become dc", "smbtorture dc"); 63 if (!netbios_name || !netbios_name[0]) { 64 netbios_name = "smbtorturedc"; 592 65 } 593 66 594 s->targetdir = location; 67 make_nbt_name_server(&name, torture_setting_string(torture, "host", NULL)); 68 69 /* do an initial name resolution to find its IP */ 70 status = resolve_name(lpcfg_resolve_context(torture->lp_ctx), 71 &name, torture, &address, torture->ev); 72 torture_assert_ntstatus_ok(torture, status, talloc_asprintf(torture, 73 "Failed to resolve %s - %s\n", 74 name.name, nt_errstr(status))); 75 595 76 596 77 /* Join domain as a member server. */ 597 s->tj = torture_join_domain(torture, s->netbios_name,78 tj = torture_join_domain(torture, netbios_name, 598 79 ACB_WSTRUST, 599 &s->machine_account); 600 if (!s->tj) { 601 DEBUG(0, ("%s failed to join domain as workstation\n", 602 s->netbios_name)); 603 return false; 604 } 80 &machine_account); 81 torture_assert(torture, tj, talloc_asprintf(torture, 82 "%s failed to join domain as workstation\n", 83 netbios_name)); 605 84 606 s->ctx = libnet_context_init(torture->ev, torture->lp_ctx); 607 s->ctx->cred = cmdline_credentials; 85 s = libnet_vampire_cb_state_init(torture, torture->lp_ctx, torture->ev, 86 netbios_name, 87 torture_join_dom_netbios_name(tj), 88 torture_join_dom_dns_name(tj), 89 location); 90 torture_assert(torture, s, "libnet_vampire_cb_state_init"); 608 91 609 s->ldb = ldb_init(s, torture->ev); 92 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 93 ctx->cred = cmdline_credentials; 610 94 611 95 ZERO_STRUCT(b); 612 b.in.domain_dns_name = torture_join_dom_dns_name( s->tj);613 b.in.domain_netbios_name = torture_join_dom_netbios_name( s->tj);614 b.in.domain_sid = torture_join_sid( s->tj);615 b.in.source_dsa_address = torture_setting_string(torture, "host", NULL);616 b.in.dest_dsa_netbios_name = s->netbios_name;96 b.in.domain_dns_name = torture_join_dom_dns_name(tj); 97 b.in.domain_netbios_name = torture_join_dom_netbios_name(tj); 98 b.in.domain_sid = torture_join_sid(tj); 99 b.in.source_dsa_address = address; 100 b.in.dest_dsa_netbios_name = netbios_name; 617 101 618 102 b.in.callbacks.private_data = s; 619 b.in.callbacks.check_options = test_become_dc_check_options;620 b.in.callbacks.prepare_db = test_become_dc_prepare_db;621 b.in.callbacks.schema_chunk = test_become_dc_schema_chunk;622 b.in.callbacks.config_chunk = test_become_dc_store_chunk;623 b.in.callbacks.domain_chunk = test_become_dc_store_chunk;103 b.in.callbacks.check_options = libnet_vampire_cb_check_options; 104 b.in.callbacks.prepare_db = libnet_vampire_cb_prepare_db; 105 b.in.callbacks.schema_chunk = libnet_vampire_cb_schema_chunk; 106 b.in.callbacks.config_chunk = libnet_vampire_cb_store_chunk; 107 b.in.callbacks.domain_chunk = libnet_vampire_cb_store_chunk; 624 108 625 status = libnet_BecomeDC(s->ctx, s, &b); 626 if (!NT_STATUS_IS_OK(status)) { 627 printf("libnet_BecomeDC() failed - %s\n", nt_errstr(status)); 628 ret = false; 629 goto cleanup; 630 } 109 status = libnet_BecomeDC(ctx, s, &b); 110 torture_assert_ntstatus_ok_goto(torture, status, ret, cleanup, talloc_asprintf(torture, 111 "libnet_BecomeDC() failed - %s %s\n", 112 nt_errstr(status), b.out.error_string)); 113 ldb = libnet_vampire_cb_ldb(s); 631 114 632 115 msg = ldb_msg_new(s); 633 if (!msg) { 634 printf("ldb_msg_new() failed\n"); 635 ret = false; 636 goto cleanup; 637 } 638 msg->dn = ldb_dn_new(msg, s->ldb, "@ROOTDSE"); 639 if (!msg->dn) { 640 printf("ldb_msg_new(@ROOTDSE) failed\n"); 641 ret = false; 642 goto cleanup; 643 } 116 torture_assert_int_equal_goto(torture, (msg?1:0), 1, ret, cleanup, 117 "ldb_msg_new() failed\n"); 118 msg->dn = ldb_dn_new(msg, ldb, "@ROOTDSE"); 119 torture_assert_int_equal_goto(torture, (msg->dn?1:0), 1, ret, cleanup, 120 "ldb_msg_new(@ROOTDSE) failed\n"); 644 121 645 122 ldb_ret = ldb_msg_add_string(msg, "isSynchronized", "TRUE"); 646 if (ldb_ret != LDB_SUCCESS) { 647 printf("ldb_msg_add_string(msg, isSynchronized, TRUE) failed: %d\n", ldb_ret); 648 ret = false; 649 goto cleanup; 650 } 123 torture_assert_int_equal_goto(torture, ldb_ret, LDB_SUCCESS, ret, cleanup, 124 "ldb_msg_add_string(msg, isSynchronized, TRUE) failed\n"); 651 125 652 126 for (i=0; i < msg->num_elements; i++) { … … 654 128 } 655 129 656 printf("mark ROOTDSE with isSynchronized=TRUE\n"); 657 ldb_ret = ldb_modify(s->ldb, msg); 658 if (ldb_ret != LDB_SUCCESS) { 659 printf("ldb_modify() failed: %d\n", ldb_ret); 660 ret = false; 661 goto cleanup; 662 } 130 torture_comment(torture, "mark ROOTDSE with isSynchronized=TRUE\n"); 131 ldb_ret = ldb_modify(libnet_vampire_cb_ldb(s), msg); 132 torture_assert_int_equal_goto(torture, ldb_ret, LDB_SUCCESS, ret, cleanup, 133 "ldb_modify() failed\n"); 663 134 135 /* commit the transaction now we know the secrets were written 136 * out properly 137 */ 138 ldb_ret = ldb_transaction_commit(ldb); 139 torture_assert_int_equal_goto(torture, ldb_ret, LDB_SUCCESS, ret, cleanup, 140 "ldb_transaction_commit() failed\n"); 141 664 142 /* reopen the ldb */ 665 talloc_free(s->ldb); /* this also free's the s->schema, because dsdb_set_schema() steals it */ 666 s->schema = NULL; 143 talloc_unlink(s, ldb); 667 144 668 sam_ldb_path = talloc_asprintf(s, "%s/%s", s->targetdir, "private/sam.ldb"); 669 DEBUG(0,("Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path)); 670 s->ldb = ldb_wrap_connect(s, s->tctx->ev, s->lp_ctx, sam_ldb_path, 671 system_session(s, s->lp_ctx), 672 NULL, 0, NULL); 673 if (!s->ldb) { 674 DEBUG(0,("Failed to open '%s'\n", 675 sam_ldb_path)); 676 ret = false; 677 goto cleanup; 678 } 145 lp_ctx = libnet_vampire_cb_lp_ctx(s); 146 sam_ldb_path = talloc_asprintf(s, "%s/%s", location, "private/sam.ldb"); 147 lpcfg_set_cmdline(lp_ctx, "sam database", sam_ldb_path); 148 torture_comment(torture, "Reopen the SAM LDB with system credentials and all replicated data: %s\n", sam_ldb_path); 149 ldb = samdb_connect(s, torture->ev, lp_ctx, system_session(lp_ctx), 0); 150 torture_assert_goto(torture, ldb != NULL, ret, cleanup, 151 talloc_asprintf(torture, 152 "Failed to open '%s'\n", sam_ldb_path)); 679 153 680 s->schema = dsdb_get_schema(s->ldb);681 if (!s->schema) {682 DEBUG(0,("Failed to get loaded dsdb_schema\n")); 683 ret = false;684 goto cleanup;685 }154 torture_assert_goto(torture, dsdb_uses_global_schema(ldb), ret, cleanup, 155 "Uses global schema"); 156 157 schema = dsdb_get_schema(ldb, s); 158 torture_assert_goto(torture, schema != NULL, ret, cleanup, 159 "Failed to get loaded dsdb_schema\n"); 686 160 687 161 /* Make sure we get this from the command line */ 688 if (lp _parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) {162 if (lpcfg_parm_bool(torture->lp_ctx, NULL, "become dc", "do not unjoin", false)) { 689 163 talloc_free(s); 690 164 return ret; … … 693 167 cleanup: 694 168 ZERO_STRUCT(u); 695 u.in.domain_dns_name = torture_join_dom_dns_name( s->tj);696 u.in.domain_netbios_name = torture_join_dom_netbios_name( s->tj);697 u.in.source_dsa_address = torture_setting_string(torture, "host", NULL);698 u.in.dest_dsa_netbios_name = s->netbios_name;169 u.in.domain_dns_name = torture_join_dom_dns_name(tj); 170 u.in.domain_netbios_name = torture_join_dom_netbios_name(tj); 171 u.in.source_dsa_address = address; 172 u.in.dest_dsa_netbios_name = netbios_name; 699 173 700 status = libnet_UnbecomeDC(s->ctx, s, &u); 701 if (!NT_STATUS_IS_OK(status)) { 702 printf("libnet_UnbecomeDC() failed - %s\n", nt_errstr(status)); 703 ret = false; 704 } 174 status = libnet_UnbecomeDC(ctx, s, &u); 175 torture_assert_ntstatus_ok(torture, status, talloc_asprintf(torture, 176 "libnet_UnbecomeDC() failed - %s %s\n", 177 nt_errstr(status), u.out.error_string)); 705 178 706 /* Leave domain. */ 707 torture_leave_domain(torture, s->tj);179 /* Leave domain. */ 180 torture_leave_domain(torture, tj); 708 181 709 182 talloc_free(s); -
trunk/server/source4/torture/libnet/libnet_domain.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2006 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 22 22 #include "includes.h" 23 23 #include "lib/cmdline/popt_common.h" 24 #include "lib/events/events.h"25 #include "auth/credentials/credentials.h"26 24 #include "libnet/libnet.h" 27 25 #include "librpc/gen_ndr/ndr_samr_c.h" 28 26 #include "librpc/gen_ndr/ndr_lsa_c.h" 29 #include "libcli/security/security.h" 30 #include "librpc/rpc/dcerpc.h" 31 #include "torture/torture.h" 32 #include "torture/rpc/rpc.h" 27 #include "torture/rpc/torture_rpc.h" 33 28 #include "param/param.h" 34 29 35 30 36 static bool test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 31 static bool test_opendomain_samr(struct torture_context *tctx, 32 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, 37 33 struct policy_handle *handle, struct lsa_String *domname, 38 34 uint32_t *access_mask, struct dom_sid **sid_p) 39 35 { 40 NTSTATUS status;41 36 struct policy_handle h, domain_handle; 42 37 struct samr_Connect r1; … … 44 39 struct dom_sid2 *sid = NULL; 45 40 struct samr_OpenDomain r3; 46 47 printf("connecting\n");41 42 torture_comment(tctx, "connecting\n"); 48 43 49 44 *access_mask = SEC_FLAG_MAXIMUM_ALLOWED; 50 45 51 46 r1.in.system_name = 0; 52 47 r1.in.access_mask = *access_mask; 53 48 r1.out.connect_handle = &h; 54 55 status = dcerpc_samr_Connect(p, mem_ctx, &r1);56 if (!NT_STATUS_IS_OK(status)) {57 printf("Connect failed - %s\n", nt_errstr(status));58 return false;59 }60 49 50 torture_assert_ntstatus_ok(tctx, 51 dcerpc_samr_Connect_r(b, mem_ctx, &r1), 52 "Connect failed"); 53 torture_assert_ntstatus_ok(tctx, r1.out.result, 54 "Connect failed"); 55 61 56 r2.in.connect_handle = &h; 62 57 r2.in.domain_name = domname; 63 58 r2.out.sid = &sid; 64 59 65 printf("domain lookup on %s\n", domname->string);66 67 status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2);68 if (!NT_STATUS_IS_OK(status)) {69 printf("LookupDomain failed - %s\n", nt_errstr(status));70 return false;71 }60 torture_comment(tctx, "domain lookup on %s\n", domname->string); 61 62 torture_assert_ntstatus_ok(tctx, 63 dcerpc_samr_LookupDomain_r(b, mem_ctx, &r2), 64 "LookupDomain failed"); 65 torture_assert_ntstatus_ok(tctx, r2.out.result, 66 "LookupDomain failed"); 72 67 73 68 r3.in.connect_handle = &h; … … 76 71 r3.out.domain_handle = &domain_handle; 77 72 78 printf("opening domain\n");79 80 status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3);81 if (!NT_STATUS_IS_OK(status)) {82 printf("OpenDomain failed - %s\n", nt_errstr(status));83 return false;84 } else {85 *handle = domain_handle; 86 }73 torture_comment(tctx, "opening domain\n"); 74 75 torture_assert_ntstatus_ok(tctx, 76 dcerpc_samr_OpenDomain_r(b, mem_ctx, &r3), 77 "OpenDomain failed"); 78 torture_assert_ntstatus_ok(tctx, r3.out.result, 79 "OpenDomain failed"); 80 81 *handle = domain_handle; 87 82 88 83 return true; … … 90 85 91 86 92 static bool test_opendomain_lsa(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 87 static bool test_opendomain_lsa(struct torture_context *tctx, 88 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, 93 89 struct policy_handle *handle, struct lsa_String *domname, 94 90 uint32_t *access_mask) 95 91 { 96 NTSTATUS status;97 92 struct lsa_OpenPolicy2 open; 98 93 struct lsa_ObjectAttribute attr; … … 108 103 qos.context_mode = 1; 109 104 qos.effective_only = 0; 110 105 111 106 attr.sec_qos = &qos; 112 107 … … 115 110 open.in.access_mask = *access_mask; 116 111 open.out.handle = handle; 117 118 status = dcerpc_lsa_OpenPolicy2(p, mem_ctx, &open); 119 if (!NT_STATUS_IS_OK(status)) { 120 return false; 121 } 112 113 torture_assert_ntstatus_ok(tctx, 114 dcerpc_lsa_OpenPolicy2_r(b, mem_ctx, &open), 115 "OpenPolicy2 failed"); 116 torture_assert_ntstatus_ok(tctx, open.out.result, 117 "OpenPolicy2 failed"); 122 118 123 119 return true; … … 137 133 passed (it's going to be resolved to dc name and address) instead 138 134 of specific server name. */ 139 domain_name = lp _workgroup(torture->lp_ctx);135 domain_name = lpcfg_workgroup(torture->lp_ctx); 140 136 141 137 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 142 138 if (ctx == NULL) { 143 d_printf("failed to create libnet context\n");139 torture_comment(torture, "failed to create libnet context\n"); 144 140 return false; 145 141 } … … 154 150 status = libnet_DomainOpen(ctx, torture, &r); 155 151 if (!NT_STATUS_IS_OK(status)) { 156 d_printf("failed to open domain on lsa service: %s\n", nt_errstr(status));152 torture_comment(torture, "failed to open domain on lsa service: %s\n", nt_errstr(status)); 157 153 ret = false; 158 154 goto done; … … 162 158 lsa_close.in.handle = &ctx->lsa.handle; 163 159 lsa_close.out.handle = &h; 164 165 status = dcerpc_lsa_Close(ctx->lsa.pipe, ctx, &lsa_close);166 if (!NT_STATUS_IS_OK(status)) {167 d_printf("failed to close domain on lsa service: %s\n", nt_errstr(status));168 ret = false;169 }160 161 torture_assert_ntstatus_ok(torture, 162 dcerpc_lsa_Close_r(ctx->lsa.pipe->binding_handle, ctx, &lsa_close), 163 "failed to close domain on lsa service"); 164 torture_assert_ntstatus_ok(torture, lsa_close.out.result, 165 "failed to close domain on lsa service"); 170 166 171 167 done: … … 195 191 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 196 192 if (ctx == NULL) { 197 d_printf("failed to create libnet context\n");193 torture_comment(torture, "failed to create libnet context\n"); 198 194 ret = false; 199 195 goto done; … … 206 202 cmdline_credentials, torture->ev, torture->lp_ctx); 207 203 if (!NT_STATUS_IS_OK(status)) { 208 d_printf("failed to connect to server: %s\n", nt_errstr(status));209 ret = false; 210 goto done; 211 } 212 213 domain_name.string = lp _workgroup(torture->lp_ctx);214 215 if (!test_opendomain_lsa( p, torture, &h, &domain_name, &access_mask)) {216 d_printf("failed to open domain on lsa service\n");217 ret = false; 218 goto done; 219 } 220 204 torture_comment(torture, "failed to connect to server: %s\n", nt_errstr(status)); 205 ret = false; 206 goto done; 207 } 208 209 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 210 211 if (!test_opendomain_lsa(torture, p->binding_handle, torture, &h, &domain_name, &access_mask)) { 212 torture_comment(torture, "failed to open domain on lsa service\n"); 213 ret = false; 214 goto done; 215 } 216 221 217 ctx->lsa.pipe = p; 222 218 ctx->lsa.name = domain_name.string; … … 230 226 r.in.type = DOMAIN_LSA; 231 227 r.in.domain_name = domain_name.string; 232 228 233 229 status = libnet_DomainClose(ctx, mem_ctx, &r); 234 230 if (!NT_STATUS_IS_OK(status)) { … … 263 259 passed (it's going to be resolved to dc name and address) instead 264 260 of specific server name. */ 265 domain_name = lp _workgroup(torture->lp_ctx);261 domain_name = lpcfg_workgroup(torture->lp_ctx); 266 262 267 263 /* 268 264 * Testing synchronous version 269 265 */ 270 printf("opening domain\n");271 266 torture_comment(torture, "opening domain\n"); 267 272 268 io.in.type = DOMAIN_SAMR; 273 269 io.in.domain_name = domain_name; … … 276 272 status = libnet_DomainOpen(ctx, mem_ctx, &io); 277 273 if (!NT_STATUS_IS_OK(status)) { 278 printf("Composite domain open failed - %s\n", nt_errstr(status)); 274 torture_comment(torture, "Composite domain open failed for domain '%s' - %s\n", 275 domain_name, nt_errstr(status)); 279 276 ret = false; 280 277 goto done; … … 285 282 r.in.handle = &domain_handle; 286 283 r.out.handle = &handle; 287 288 printf("closing domain handle\n"); 289 290 status = dcerpc_samr_Close(ctx->samr.pipe, mem_ctx, &r); 291 if (!NT_STATUS_IS_OK(status)) { 292 printf("Close failed - %s\n", nt_errstr(status)); 293 ret = false; 294 goto done; 295 } 284 285 torture_comment(torture, "closing domain handle\n"); 286 287 torture_assert_ntstatus_ok(torture, 288 dcerpc_samr_Close_r(ctx->samr.pipe->binding_handle, mem_ctx, &r), 289 "Close failed"); 290 torture_assert_ntstatus_ok(torture, r.out.result, 291 "Close failed"); 296 292 297 293 done: … … 324 320 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 325 321 if (ctx == NULL) { 326 d_printf("failed to create libnet context\n");322 torture_comment(torture, "failed to create libnet context\n"); 327 323 ret = false; 328 324 goto done; … … 335 331 ctx->cred, torture->ev, torture->lp_ctx); 336 332 if (!NT_STATUS_IS_OK(status)) { 337 d_printf("failed to connect to server: %s\n", nt_errstr(status));338 ret = false; 339 goto done; 340 } 341 342 domain_name.string = talloc_strdup(mem_ctx, lp _workgroup(torture->lp_ctx));343 344 if (!test_opendomain_samr( p, torture, &h, &domain_name, &access_mask, &sid)) {345 d_printf("failed to open domain on samr service\n");346 ret = false; 347 goto done; 348 } 349 333 torture_comment(torture, "failed to connect to server: %s\n", nt_errstr(status)); 334 ret = false; 335 goto done; 336 } 337 338 domain_name.string = talloc_strdup(mem_ctx, lpcfg_workgroup(torture->lp_ctx)); 339 340 if (!test_opendomain_samr(torture, p->binding_handle, torture, &h, &domain_name, &access_mask, &sid)) { 341 torture_comment(torture, "failed to open domain on samr service\n"); 342 ret = false; 343 goto done; 344 } 345 350 346 ctx->samr.pipe = p; 351 347 ctx->samr.name = talloc_steal(ctx, domain_name.string); … … 361 357 r.in.type = DOMAIN_SAMR; 362 358 r.in.domain_name = domain_name.string; 363 359 364 360 status = libnet_DomainClose(ctx, mem_ctx, &r); 365 361 if (!NT_STATUS_IS_OK(status)) { … … 392 388 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 393 389 if (ctx == NULL) { 394 d_printf("failed to create libnet context\n");390 torture_comment(torture, "failed to create libnet context\n"); 395 391 ret = false; 396 392 goto done; … … 398 394 399 395 ctx->cred = cmdline_credentials; 400 396 401 397 mem_ctx = talloc_init("torture_domain_close_samr"); 402 398 … … 414 410 } 415 411 416 d_printf("Received list or domains (everything in one piece):\n");417 412 torture_comment(torture, "Received list or domains (everything in one piece):\n"); 413 418 414 for (i = 0; i < r.out.count; i++) { 419 d_printf("Name[%d]: %s\n", i, r.out.domains[i].name);415 torture_comment(torture, "Name[%d]: %s\n", i, r.out.domains[i].name); 420 416 } 421 417 … … 435 431 } 436 432 437 d_printf("Received list or domains (collected in more than one round):\n");438 433 torture_comment(torture, "Received list or domains (collected in more than one round):\n"); 434 439 435 for (i = 0; i < r.out.count; i++) { 440 d_printf("Name[%d]: %s\n", i, r.out.domains[i].name);436 torture_comment(torture, "Name[%d]: %s\n", i, r.out.domains[i].name); 441 437 } 442 438 443 439 done: 444 d_printf("\nStatus: %s\n", nt_errstr(status));440 torture_comment(torture, "\nStatus: %s\n", nt_errstr(status)); 445 441 446 442 talloc_free(mem_ctx); -
trunk/server/source4/torture/libnet/libnet_group.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2007 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 25 25 #include "librpc/gen_ndr/ndr_samr_c.h" 26 26 #include "librpc/gen_ndr/ndr_lsa_c.h" 27 #include "torture/ torture.h"28 #include "torture/ rpc/rpc.h"27 #include "torture/rpc/torture_rpc.h" 28 #include "torture/libnet/proto.h" 29 29 #include "param/param.h" 30 30 31 31 32 32 #define TEST_GROUPNAME "libnetgrouptest" 33 34 35 static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,36 struct policy_handle *domain_handle, const char *groupname)37 {38 NTSTATUS status;39 struct samr_LookupNames r1;40 struct samr_OpenGroup r2;41 struct samr_DeleteDomainGroup r3;42 struct lsa_String names[2];43 uint32_t rid;44 struct policy_handle group_handle;45 struct samr_Ids rids, types;46 47 names[0].string = groupname;48 49 r1.in.domain_handle = domain_handle;50 r1.in.num_names = 1;51 r1.in.names = names;52 r1.out.rids = &rids;53 r1.out.types = &types;54 55 printf("group account lookup '%s'\n", groupname);56 57 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);58 if (!NT_STATUS_IS_OK(status)) {59 printf("LookupNames failed - %s\n", nt_errstr(status));60 return false;61 }62 63 rid = r1.out.rids->ids[0];64 65 r2.in.domain_handle = domain_handle;66 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;67 r2.in.rid = rid;68 r2.out.group_handle = &group_handle;69 70 printf("opening group account\n");71 72 status = dcerpc_samr_OpenGroup(p, mem_ctx, &r2);73 if (!NT_STATUS_IS_OK(status)) {74 printf("OpenGroup failed - %s\n", nt_errstr(status));75 return false;76 }77 78 r3.in.group_handle = &group_handle;79 r3.out.group_handle = &group_handle;80 81 printf("deleting group account\n");82 83 status = dcerpc_samr_DeleteDomainGroup(p, mem_ctx, &r3);84 if (!NT_STATUS_IS_OK(status)) {85 printf("DeleteGroup failed - %s\n", nt_errstr(status));86 return false;87 }88 89 return true;90 }91 92 93 static bool test_creategroup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,94 struct policy_handle *handle, const char *name)95 {96 NTSTATUS status;97 struct lsa_String groupname;98 struct samr_CreateDomainGroup r;99 struct policy_handle group_handle;100 uint32_t group_rid;101 102 groupname.string = name;103 104 r.in.domain_handle = handle;105 r.in.name = &groupname;106 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;107 r.out.group_handle = &group_handle;108 r.out.rid = &group_rid;109 110 printf("creating group account %s\n", name);111 112 status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r);113 if (!NT_STATUS_IS_OK(status)) {114 printf("CreateGroup failed - %s\n", nt_errstr(status));115 116 if (NT_STATUS_EQUAL(status, NT_STATUS_GROUP_EXISTS)) {117 printf("Group (%s) already exists - attempting to delete and recreate group again\n", name);118 if (!test_cleanup(p, mem_ctx, handle, TEST_GROUPNAME)) {119 return false;120 }121 122 printf("creating group account\n");123 124 status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r);125 if (!NT_STATUS_IS_OK(status)) {126 printf("CreateGroup failed - %s\n", nt_errstr(status));127 return false;128 }129 return true;130 }131 return false;132 }133 134 return true;135 }136 137 138 static bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,139 struct policy_handle *handle, struct lsa_String *domname)140 {141 NTSTATUS status;142 struct policy_handle h, domain_handle;143 struct samr_Connect r1;144 struct samr_LookupDomain r2;145 struct dom_sid2 *sid = NULL;146 struct samr_OpenDomain r3;147 148 printf("connecting\n");149 150 r1.in.system_name = 0;151 r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;152 r1.out.connect_handle = &h;153 154 status = dcerpc_samr_Connect(p, mem_ctx, &r1);155 if (!NT_STATUS_IS_OK(status)) {156 printf("Connect failed - %s\n", nt_errstr(status));157 return false;158 }159 160 r2.in.connect_handle = &h;161 r2.in.domain_name = domname;162 r2.out.sid = &sid;163 164 printf("domain lookup on %s\n", domname->string);165 166 status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2);167 if (!NT_STATUS_IS_OK(status)) {168 printf("LookupDomain failed - %s\n", nt_errstr(status));169 return false;170 }171 172 r3.in.connect_handle = &h;173 r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;174 r3.in.sid = *r2.out.sid;175 r3.out.domain_handle = &domain_handle;176 177 printf("opening domain\n");178 179 status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3);180 if (!NT_STATUS_IS_OK(status)) {181 printf("OpenDomain failed - %s\n", nt_errstr(status));182 return false;183 } else {184 *handle = domain_handle;185 }186 187 return true;188 }189 190 191 static bool test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,192 struct policy_handle *domain_handle)193 {194 NTSTATUS status;195 struct samr_Close r;196 197 r.in.handle = domain_handle;198 r.out.handle = domain_handle;199 200 status = dcerpc_samr_Close(p, mem_ctx, &r);201 if (!NT_STATUS_IS_OK(status)) {202 printf("Close samr domain failed - %s\n", nt_errstr(status));203 return false;204 }205 206 return true;207 }208 209 210 static bool test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,211 struct policy_handle *domain_handle)212 {213 NTSTATUS status;214 struct lsa_Close r;215 216 r.in.handle = domain_handle;217 r.out.handle = domain_handle;218 219 status = dcerpc_lsa_Close(p, mem_ctx, &r);220 if (!NT_STATUS_IS_OK(status)) {221 printf("Close lsa domain failed - %s\n", nt_errstr(status));222 return false;223 }224 225 return true;226 }227 33 228 34 … … 233 39 NTSTATUS status; 234 40 TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx; 235 struct libnet_context *ctx ;41 struct libnet_context *ctx = NULL; 236 42 struct dcerpc_pipe *p; 237 43 struct policy_handle h; … … 240 46 241 47 prep_mem_ctx = talloc_init("prepare torture group info"); 242 243 ctx = libnet_context_init(torture->ev, torture->lp_ctx);244 ctx->cred = cmdline_credentials;245 48 246 49 status = torture_rpc_connection(torture, … … 251 54 } 252 55 253 domain_name.string = lp _workgroup(torture->lp_ctx);254 if (!test_ opendomain(p, prep_mem_ctx, &h, &domain_name)) {255 ret = false; 256 goto done; 257 } 258 259 if (!test_ creategroup(p, prep_mem_ctx, &h, name)) {56 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 57 if (!test_domain_open(torture, p->binding_handle, &domain_name, prep_mem_ctx, &h, NULL)) { 58 ret = false; 59 goto done; 60 } 61 62 if (!test_group_create(torture, p->binding_handle, prep_mem_ctx, &h, name, NULL)) { 260 63 ret = false; 261 64 goto done; … … 263 66 264 67 mem_ctx = talloc_init("torture group info"); 68 69 if (!test_libnet_context_init(torture, true, &ctx)) { 70 return false; 71 } 265 72 266 73 ZERO_STRUCT(req); … … 272 79 status = libnet_GroupInfo(ctx, mem_ctx, &req); 273 80 if (!NT_STATUS_IS_OK(status)) { 274 printf("libnet_GroupInfo call failed: %s\n", nt_errstr(status)); 275 ret = false; 276 goto done; 277 } 278 279 if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { 280 printf("cleanup failed\n"); 281 ret = false; 282 goto done; 283 } 284 285 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 286 printf("domain close failed\n"); 287 ret = false; 288 } 289 81 torture_comment(torture, "libnet_GroupInfo call failed: %s\n", nt_errstr(status)); 82 ret = false; 83 goto done; 84 } 85 86 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, 87 mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { 88 torture_comment(torture, "cleanup failed\n"); 89 ret = false; 90 goto done; 91 } 92 93 if (!test_samr_close_handle(torture, 94 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 95 torture_comment(torture, "domain close failed\n"); 96 ret = false; 97 } 98 99 done: 290 100 talloc_free(ctx); 291 292 done:293 101 talloc_free(mem_ctx); 294 102 return ret; … … 309 117 ctx->cred = cmdline_credentials; 310 118 311 domain_name.string = lp _workgroup(torture->lp_ctx);119 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 312 120 mem_ctx = talloc_init("torture group list"); 313 121 314 122 ZERO_STRUCT(req); 315 123 316 printf("listing group accounts:\n");317 124 torture_comment(torture, "listing group accounts:\n"); 125 318 126 do { 319 127 req.in.domain_name = domain_name.string; … … 326 134 327 135 for (i = 0; i < req.out.count; i++) { 328 printf("\tgroup: %s, sid=%s\n",329 req.out.groups[i].groupname, req.out.groups[i].sid);136 torture_comment(torture, "\tgroup: %s, sid=%s\n", 137 req.out.groups[i].groupname, req.out.groups[i].sid); 330 138 } 331 139 … … 334 142 if (!(NT_STATUS_IS_OK(status) || 335 143 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) { 336 printf("libnet_GroupList call failed: %s\n", nt_errstr(status)); 337 ret = false; 338 goto done; 339 } 340 341 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 342 printf("domain close failed\n"); 343 ret = false; 344 } 345 346 if (!test_lsa_close(ctx->lsa.pipe, mem_ctx, &ctx->lsa.handle)) { 347 printf("lsa domain close failed\n"); 144 torture_comment(torture, "libnet_GroupList call failed: %s\n", nt_errstr(status)); 145 ret = false; 146 goto done; 147 } 148 149 if (!test_samr_close_handle(torture, 150 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 151 torture_comment(torture, "domain close failed\n"); 152 ret = false; 153 } 154 155 if (!test_lsa_close_handle(torture, 156 ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) { 157 torture_comment(torture, "lsa domain close failed\n"); 348 158 ret = false; 349 159 } … … 371 181 372 182 req.in.group_name = TEST_GROUPNAME; 373 req.in.domain_name = lp _workgroup(torture->lp_ctx);183 req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 374 184 req.out.error_string = NULL; 375 185 376 186 status = libnet_CreateGroup(ctx, mem_ctx, &req); 377 187 if (!NT_STATUS_IS_OK(status)) { 378 printf("libnet_CreateGroup call failed: %s\n", nt_errstr(status)); 379 ret = false; 380 goto done; 381 } 382 383 if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { 384 printf("cleanup failed\n"); 385 ret = false; 386 goto done; 387 } 388 389 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 390 printf("domain close failed\n"); 188 torture_comment(torture, "libnet_CreateGroup call failed: %s\n", nt_errstr(status)); 189 ret = false; 190 goto done; 191 } 192 193 if (!test_group_cleanup(torture, ctx->samr.pipe->binding_handle, 194 mem_ctx, &ctx->samr.handle, TEST_GROUPNAME)) { 195 torture_comment(torture, "cleanup failed\n"); 196 ret = false; 197 goto done; 198 } 199 200 if (!test_samr_close_handle(torture, 201 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 202 torture_comment(torture, "domain close failed\n"); 391 203 ret = false; 392 204 } -
trunk/server/source4/torture/libnet/libnet_lookup.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 22 22 #include "lib/cmdline/popt_common.h" 23 23 #include "libnet/libnet.h" 24 #include "librpc/gen_ndr/nbt.h"25 #include "librpc/rpc/dcerpc.h"26 24 #include "libcli/libcli.h" 27 #include "torture/rpc/rpc.h" 28 #include "torture/torture.h" 25 #include "torture/rpc/torture_rpc.h" 29 26 #include "param/param.h" 30 27 … … 59 56 60 57 if (!NT_STATUS_IS_OK(status)) { 61 printf("Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status));58 torture_comment(torture, "Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status)); 62 59 ret = false; 63 60 goto done; … … 66 63 ret = true; 67 64 68 printf("Name [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address);65 torture_comment(torture, "Name [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address); 69 66 70 67 done: … … 102 99 103 100 if (!NT_STATUS_IS_OK(status)) { 104 printf("Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status));101 torture_comment(torture, "Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status)); 105 102 ret = false; 106 103 goto done; … … 109 106 ret = true; 110 107 111 printf("Host [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address);108 torture_comment(torture, "Host [%s] found at address: %s.\n", lookup.in.hostname, *lookup.out.address); 112 109 113 110 done: … … 139 136 } 140 137 141 lookup->in.domain_name = lp _workgroup(torture->lp_ctx);138 lookup->in.domain_name = lpcfg_workgroup(torture->lp_ctx); 142 139 lookup->in.name_type = NBT_NAME_PDC; 143 140 … … 145 142 146 143 if (!NT_STATUS_IS_OK(status)) { 147 printf("Couldn't lookup pdc %s: %s\n", lookup->in.domain_name,144 torture_comment(torture, "Couldn't lookup pdc %s: %s\n", lookup->in.domain_name, 148 145 nt_errstr(status)); 149 146 ret = false; … … 153 150 ret = true; 154 151 155 printf("DCs of domain [%s] found.\n", lookup->in.domain_name);152 torture_comment(torture, "DCs of domain [%s] found.\n", lookup->in.domain_name); 156 153 for (i = 0; i < lookup->out.num_dcs; i++) { 157 printf("\tDC[%d]: name=%s, address=%s\n", i, lookup->out.dcs[i].name,154 torture_comment(torture, "\tDC[%d]: name=%s, address=%s\n", i, lookup->out.dcs[i].name, 158 155 lookup->out.dcs[i].address); 159 156 } … … 179 176 180 177 r.in.name = "Administrator"; 181 r.in.domain_name = lp _workgroup(torture->lp_ctx);178 r.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 182 179 183 180 status = libnet_LookupName(ctx, mem_ctx, &r); -
trunk/server/source4/torture/libnet/libnet_rpc.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 21 21 #include "includes.h" 22 22 #include "lib/cmdline/popt_common.h" 23 #include "auth/credentials/credentials.h"24 23 #include "libnet/libnet.h" 25 24 #include "libcli/security/security.h" 26 #include "librpc/ndr/libndr.h"27 25 #include "librpc/gen_ndr/ndr_lsa.h" 28 26 #include "librpc/gen_ndr/ndr_samr.h" 29 27 #include "librpc/gen_ndr/ndr_srvsvc.h" 30 #include "librpc/rpc/dcerpc.h" 31 #include "torture/rpc/rpc.h" 32 #include "torture/torture.h" 28 #include "torture/rpc/torture_rpc.h" 33 29 #include "param/param.h" 34 30 35 31 36 static bool test_connect_service(struct libnet_context *ctx, 32 static bool test_connect_service(struct torture_context *tctx, 33 struct libnet_context *ctx, 37 34 const struct ndr_interface_table *iface, 38 35 const char *binding_string, … … 60 57 61 58 if (!NT_STATUS_EQUAL(status, expected_status)) { 62 d_printf("Connecting to rpc service %s on %s.\n\tFAILED. Expected: %s."59 torture_comment(tctx, "Connecting to rpc service %s on %s.\n\tFAILED. Expected: %s." 63 60 "Received: %s\n", 64 61 connect_r.in.dcerpc_iface->name, connect_r.in.binding, nt_errstr(expected_status), … … 68 65 } 69 66 70 d_printf("PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status),67 torture_comment(tctx, "PASSED. Expected: %s, received: %s\n", nt_errstr(expected_status), 71 68 nt_errstr(status)); 72 69 73 70 if (connect_r.level == LIBNET_RPC_CONNECT_DC_INFO && NT_STATUS_IS_OK(status)) { 74 d_printf("Domain Controller Info:\n");75 d_printf("\tDomain Name:\t %s\n", connect_r.out.domain_name);76 d_printf("\tDomain SID:\t %s\n", dom_sid_string(ctx, connect_r.out.domain_sid));77 d_printf("\tRealm:\t\t %s\n", connect_r.out.realm);78 d_printf("\tGUID:\t\t %s\n", GUID_string(ctx, connect_r.out.guid));71 torture_comment(tctx, "Domain Controller Info:\n"); 72 torture_comment(tctx, "\tDomain Name:\t %s\n", connect_r.out.domain_name); 73 torture_comment(tctx, "\tDomain SID:\t %s\n", dom_sid_string(ctx, connect_r.out.domain_sid)); 74 torture_comment(tctx, "\tRealm:\t\t %s\n", connect_r.out.realm); 75 torture_comment(tctx, "\tGUID:\t\t %s\n", GUID_string(ctx, connect_r.out.guid)); 79 76 80 77 } else if (!NT_STATUS_IS_OK(status)) { 81 d_printf("Error string: %s\n", connect_r.out.error_string);78 torture_comment(tctx, "Error string: %s\n", connect_r.out.error_string); 82 79 } 83 80 … … 94 91 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 95 92 ctx->cred = cmdline_credentials; 96 97 d_printf("Testing connection to LSA interface\n"); 98 if (!test_connect_service(ctx, &ndr_table_lsarpc, bindstr, 93 94 torture_comment(torture, "Testing connection to LSA interface\n"); 95 96 if (!test_connect_service(torture, ctx, &ndr_table_lsarpc, bindstr, 99 97 hostname, level, false, NT_STATUS_OK)) { 100 d_printf("failed to connect LSA interface\n");101 return false; 102 } 103 104 d_printf("Testing connection to SAMR interface\n");105 if (!test_connect_service( ctx, &ndr_table_samr, bindstr,98 torture_comment(torture, "failed to connect LSA interface\n"); 99 return false; 100 } 101 102 torture_comment(torture, "Testing connection to SAMR interface\n"); 103 if (!test_connect_service(torture, ctx, &ndr_table_samr, bindstr, 106 104 hostname, level, false, NT_STATUS_OK)) { 107 d_printf("failed to connect SAMR interface\n");108 return false; 109 } 110 111 d_printf("Testing connection to SRVSVC interface\n");112 if (!test_connect_service( ctx, &ndr_table_srvsvc, bindstr,105 torture_comment(torture, "failed to connect SAMR interface\n"); 106 return false; 107 } 108 109 torture_comment(torture, "Testing connection to SRVSVC interface\n"); 110 if (!test_connect_service(torture, ctx, &ndr_table_srvsvc, bindstr, 113 111 hostname, level, false, NT_STATUS_OK)) { 114 d_printf("failed to connect SRVSVC interface\n");115 return false; 116 } 117 118 d_printf("Testing connection to LSA interface with wrong credentials\n");119 if (!test_connect_service( ctx, &ndr_table_lsarpc, bindstr,112 torture_comment(torture, "failed to connect SRVSVC interface\n"); 113 return false; 114 } 115 116 torture_comment(torture, "Testing connection to LSA interface with wrong credentials\n"); 117 if (!test_connect_service(torture, ctx, &ndr_table_lsarpc, bindstr, 120 118 hostname, level, true, NT_STATUS_LOGON_FAILURE)) { 121 d_printf("failed to test wrong credentials on LSA interface\n");122 return false; 123 } 124 125 d_printf("Testing connection to SAMR interface with wrong credentials\n");126 if (!test_connect_service( ctx, &ndr_table_samr, bindstr,119 torture_comment(torture, "failed to test wrong credentials on LSA interface\n"); 120 return false; 121 } 122 123 torture_comment(torture, "Testing connection to SAMR interface with wrong credentials\n"); 124 if (!test_connect_service(torture, ctx, &ndr_table_samr, bindstr, 127 125 hostname, level, true, NT_STATUS_LOGON_FAILURE)) { 128 d_printf("failed to test wrong credentials on SAMR interface\n");126 torture_comment(torture, "failed to test wrong credentials on SAMR interface\n"); 129 127 return false; 130 128 } … … 157 155 struct dcerpc_binding *binding; 158 156 const char *domain_name; 159 157 160 158 status = torture_rpc_binding(torture, &binding); 161 159 if (!NT_STATUS_IS_OK(status)) { … … 166 164 passed (it's going to be resolved to dc name and address) instead 167 165 of specific server name. */ 168 domain_name = lp _workgroup(torture->lp_ctx);166 domain_name = lpcfg_workgroup(torture->lp_ctx); 169 167 return torture_rpc_connect(torture, level, NULL, domain_name); 170 168 } … … 177 175 struct dcerpc_binding *binding; 178 176 const char *domain_name; 179 177 180 178 status = torture_rpc_binding(torture, &binding); 181 179 if (!NT_STATUS_IS_OK(status)) { … … 186 184 passed (it's going to be resolved to dc name and address) instead 187 185 of specific server name. */ 188 domain_name = lp _workgroup(torture->lp_ctx);186 domain_name = lpcfg_workgroup(torture->lp_ctx); 189 187 return torture_rpc_connect(torture, level, NULL, domain_name); 190 188 } … … 197 195 struct dcerpc_binding *binding; 198 196 const char *domain_name; 199 197 200 198 status = torture_rpc_binding(torture, &binding); 201 199 if (!NT_STATUS_IS_OK(status)) { … … 206 204 passed (it's going to be resolved to dc name and address) instead 207 205 of specific server name. */ 208 domain_name = lp _workgroup(torture->lp_ctx);206 domain_name = lpcfg_workgroup(torture->lp_ctx); 209 207 return torture_rpc_connect(torture, level, NULL, domain_name); 210 208 } … … 217 215 struct dcerpc_binding *binding; 218 216 const char *bindstr; 219 217 220 218 status = torture_rpc_binding(torture, &binding); 221 219 if (!NT_STATUS_IS_OK(status)) { -
trunk/server/source4/torture/libnet/libnet_share.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. … … 5 5 Copyright (C) Gregory LEOCADIE <gleocadie@idealx.com> 2005 6 6 Copyright (C) Rafal Szczesniak 2005 7 7 8 8 This program is free software; you can redistribute it and/or modify 9 9 it under the terms of the GNU General Public License as published by 10 10 the Free Software Foundation; either version 3 of the License, or 11 11 (at your option) any later version. 12 12 13 13 This program is distributed in the hope that it will be useful, 14 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 16 GNU General Public License for more details. 17 17 18 18 You should have received a copy of the GNU General Public License 19 19 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 21 21 22 22 #include "includes.h" 23 #include "torture/rpc/ rpc.h"23 #include "torture/rpc/torture_rpc.h" 24 24 #include "libnet/libnet.h" 25 25 #include "lib/cmdline/popt_common.h" … … 30 30 31 31 32 static void test_displayshares(struct libnet_ListShares s) 32 static void test_displayshares(struct torture_context *tctx, 33 struct libnet_ListShares s) 33 34 { 34 35 int i, j; … … 56 57 for (i = 0; i < s.out.ctr.ctr0->count; i++) { 57 58 struct srvsvc_NetShareInfo0 *info = &s.out.ctr.ctr0->array[i]; 58 d_printf("\t[%d] %s\n", i, info->name);59 torture_comment(tctx, "\t[%d] %s\n", i, info->name); 59 60 } 60 61 break; … … 66 67 if (share_types[j].type == info->type) break; 67 68 } 68 d_printf("\t[%d] %s (%s)\t%s\n", i, info->name,69 torture_comment(tctx, "\t[%d] %s (%s)\t%s\n", i, info->name, 69 70 info->comment, share_types[j].desc); 70 71 } … … 77 78 if (share_types[j].type == info->type) break; 78 79 } 79 d_printf("\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s]\n",80 torture_comment(tctx, "\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s]\n", 80 81 i, info->name, share_types[j].desc, info->comment, 81 82 info->permissions, info->max_users, … … 91 92 if (share_types[j].type == info->type) break; 92 93 } 93 d_printf("\t[%d] %s\t%s [csc_policy=0x%08x]\n\t %s\n", i, info->name,94 torture_comment(tctx, "\t[%d] %s\t%s [csc_policy=0x%08x]\n\t %s\n", i, info->name, 94 95 share_types[j].desc, info->csc_policy, 95 96 info->comment); … … 103 104 if (share_types[j].type == info->type) break; 104 105 } 105 d_printf("\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s]\n",106 torture_comment(tctx, "\t[%d] %s\t%s\n\t %s\n\t [perms=0x%08x, max_usr=%d, cur_usr=%d, path=%s, pass=%s]\n", 106 107 i, info->name, share_types[j].desc, info->comment, 107 108 info->permissions, info->max_users, … … 134 135 libnetctx = libnet_context_init(torture->ev, torture->lp_ctx); 135 136 if (!libnetctx) { 136 printf("Couldn't allocate libnet context\n");137 torture_comment(torture, "Couldn't allocate libnet context\n"); 137 138 ret = false; 138 139 goto done; … … 140 141 141 142 libnetctx->cred = cmdline_credentials; 142 143 printf("Testing libnet_ListShare\n");144 143 144 torture_comment(torture, "Testing libnet_ListShare\n"); 145 145 146 share.in.server_name = talloc_asprintf(mem_ctx, "%s", binding->host); 146 147 147 148 for (i = 0; i < ARRAY_SIZE(levels); i++) { 148 149 share.in.level = levels[i]; 149 printf("testing libnet_ListShare level %u\n", share.in.level);150 torture_comment(torture, "Testing libnet_ListShare level %u\n", share.in.level); 150 151 151 152 status = libnet_ListShares(libnetctx, mem_ctx, &share); 152 153 if (!NT_STATUS_IS_OK(status)) { 153 printf("libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string);154 torture_comment(torture, "libnet_ListShare level %u failed - %s\n", share.in.level, share.out.error_string); 154 155 ret = false; 155 156 goto done; 156 157 } 157 158 158 printf("listing shares:\n");159 test_displayshares( share);159 torture_comment(torture, "listing shares:\n"); 160 test_displayshares(torture, share); 160 161 } 161 162 … … 166 167 167 168 168 static bool test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, const char *host, 169 static bool test_addshare(struct torture_context *tctx, 170 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, const char *host, 169 171 const char* share) 170 172 { … … 173 175 union srvsvc_NetShareInfo info; 174 176 struct srvsvc_NetShareInfo2 i; 175 177 176 178 i.name = share; 177 179 i.type = STYPE_DISKTREE; … … 189 191 add.in.parm_error = NULL; 190 192 191 status = dcerpc_srvsvc_NetShareAdd (svc_pipe, mem_ctx, &add);193 status = dcerpc_srvsvc_NetShareAdd_r(b, mem_ctx, &add); 192 194 if (!NT_STATUS_IS_OK(status)) { 193 printf("Failed to add a new share\n");195 torture_comment(tctx, "Failed to add a new share\n"); 194 196 return false; 195 197 } 196 198 197 printf("share added\n");199 torture_comment(tctx, "share added\n"); 198 200 return true; 199 201 } … … 209 211 bool ret = true; 210 212 struct libnet_DelShare share; 211 213 212 214 host = torture_setting_string(torture, "host", NULL); 213 215 status = torture_rpc_binding(torture, &binding); … … 223 225 torture_assert_ntstatus_ok(torture, status, "Failed to get rpc connection"); 224 226 225 if (!test_addshare( p, torture, host, TEST_SHARENAME)) {227 if (!test_addshare(torture, p->binding_handle, torture, host, TEST_SHARENAME)) { 226 228 return false; 227 229 } -
trunk/server/source4/torture/libnet/libnet_user.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 25 25 #include "librpc/gen_ndr/ndr_samr_c.h" 26 26 #include "librpc/gen_ndr/ndr_lsa_c.h" 27 #include "torture/torture.h" 28 #include "torture/rpc/rpc.h" 27 #include "torture/rpc/torture_rpc.h" 29 28 #include "torture/libnet/usertest.h" 29 #include "torture/libnet/proto.h" 30 30 #include "param/param.h" 31 31 32 33 static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,34 struct policy_handle *domain_handle, const char *username)35 {36 NTSTATUS status;37 struct samr_LookupNames r1;38 struct samr_OpenUser r2;39 struct samr_DeleteUser r3;40 struct lsa_String names[2];41 uint32_t rid;42 struct policy_handle user_handle;43 struct samr_Ids rids, types;44 45 names[0].string = username;46 47 r1.in.domain_handle = domain_handle;48 r1.in.num_names = 1;49 r1.in.names = names;50 r1.out.rids = &rids;51 r1.out.types = &types;52 53 printf("user account lookup '%s'\n", username);54 55 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);56 if (!NT_STATUS_IS_OK(status)) {57 printf("LookupNames failed - %s\n", nt_errstr(status));58 return false;59 }60 61 rid = r1.out.rids->ids[0];62 63 r2.in.domain_handle = domain_handle;64 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;65 r2.in.rid = rid;66 r2.out.user_handle = &user_handle;67 68 printf("opening user account\n");69 70 status = dcerpc_samr_OpenUser(p, mem_ctx, &r2);71 if (!NT_STATUS_IS_OK(status)) {72 printf("OpenUser failed - %s\n", nt_errstr(status));73 return false;74 }75 76 r3.in.user_handle = &user_handle;77 r3.out.user_handle = &user_handle;78 79 printf("deleting user account\n");80 81 status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3);82 if (!NT_STATUS_IS_OK(status)) {83 printf("DeleteUser failed - %s\n", nt_errstr(status));84 return false;85 }86 87 return true;88 }89 90 91 static bool test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,92 struct policy_handle *handle, struct lsa_String *domname)93 {94 NTSTATUS status;95 struct policy_handle h, domain_handle;96 struct samr_Connect r1;97 struct samr_LookupDomain r2;98 struct dom_sid2 *sid = NULL;99 struct samr_OpenDomain r3;100 101 printf("connecting\n");102 103 r1.in.system_name = 0;104 r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;105 r1.out.connect_handle = &h;106 107 status = dcerpc_samr_Connect(p, mem_ctx, &r1);108 if (!NT_STATUS_IS_OK(status)) {109 printf("Connect failed - %s\n", nt_errstr(status));110 return false;111 }112 113 r2.in.connect_handle = &h;114 r2.in.domain_name = domname;115 r2.out.sid = &sid;116 117 printf("domain lookup on %s\n", domname->string);118 119 status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2);120 if (!NT_STATUS_IS_OK(status)) {121 printf("LookupDomain failed - %s\n", nt_errstr(status));122 return false;123 }124 125 r3.in.connect_handle = &h;126 r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;127 r3.in.sid = *r2.out.sid;128 r3.out.domain_handle = &domain_handle;129 130 printf("opening domain\n");131 132 status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3);133 if (!NT_STATUS_IS_OK(status)) {134 printf("OpenDomain failed - %s\n", nt_errstr(status));135 return false;136 } else {137 *handle = domain_handle;138 }139 140 return true;141 }142 143 144 static bool test_samr_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,145 struct policy_handle *domain_handle)146 {147 NTSTATUS status;148 struct samr_Close r;149 150 r.in.handle = domain_handle;151 r.out.handle = domain_handle;152 153 status = dcerpc_samr_Close(p, mem_ctx, &r);154 if (!NT_STATUS_IS_OK(status)) {155 printf("Close samr domain failed - %s\n", nt_errstr(status));156 return false;157 }158 159 return true;160 }161 162 163 static bool test_lsa_close(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,164 struct policy_handle *domain_handle)165 {166 NTSTATUS status;167 struct lsa_Close r;168 169 r.in.handle = domain_handle;170 r.out.handle = domain_handle;171 172 status = dcerpc_lsa_Close(p, mem_ctx, &r);173 if (!NT_STATUS_IS_OK(status)) {174 printf("Close lsa domain failed - %s\n", nt_errstr(status));175 return false;176 }177 178 return true;179 }180 181 182 static bool test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,183 struct policy_handle *handle, const char* user)184 {185 NTSTATUS status;186 struct policy_handle user_handle;187 struct lsa_String username;188 struct samr_CreateUser r1;189 struct samr_Close r2;190 uint32_t user_rid;191 192 username.string = user;193 194 r1.in.domain_handle = handle;195 r1.in.account_name = &username;196 r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;197 r1.out.user_handle = &user_handle;198 r1.out.rid = &user_rid;199 200 printf("creating user '%s'\n", username.string);201 202 status = dcerpc_samr_CreateUser(p, mem_ctx, &r1);203 if (!NT_STATUS_IS_OK(status)) {204 printf("CreateUser failed - %s\n", nt_errstr(status));205 206 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) {207 printf("User (%s) already exists - attempting to delete and recreate account again\n", user);208 if (!test_cleanup(p, mem_ctx, handle, TEST_USERNAME)) {209 return false;210 }211 212 printf("creating user account\n");213 214 status = dcerpc_samr_CreateUser(p, mem_ctx, &r1);215 if (!NT_STATUS_IS_OK(status)) {216 printf("CreateUser failed - %s\n", nt_errstr(status));217 return false;218 }219 return true;220 }221 return false;222 }223 224 r2.in.handle = &user_handle;225 r2.out.handle = &user_handle;226 227 printf("closing user '%s'\n", username.string);228 229 status = dcerpc_samr_Close(p, mem_ctx, &r2);230 if (!NT_STATUS_IS_OK(status)) {231 printf("Close failed - %s\n", nt_errstr(status));232 return false;233 }234 235 return true;236 }237 32 238 33 … … 241 36 NTSTATUS status; 242 37 TALLOC_CTX *mem_ctx; 243 struct libnet_context *ctx ;38 struct libnet_context *ctx = NULL; 244 39 struct libnet_CreateUser req; 245 40 bool ret = true; … … 247 42 mem_ctx = talloc_init("test_createuser"); 248 43 249 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 250 ctx->cred = cmdline_credentials; 44 if (!test_libnet_context_init(torture, true, &ctx)) { 45 return false; 46 } 251 47 252 48 req.in.user_name = TEST_USERNAME; 253 req.in.domain_name = lp _workgroup(torture->lp_ctx);49 req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 254 50 req.out.error_string = NULL; 255 51 256 52 status = libnet_CreateUser(ctx, mem_ctx, &req); 257 53 if (!NT_STATUS_IS_OK(status)) { 258 printf("libnet_CreateUser call failed: %s\n", nt_errstr(status)); 259 ret = false; 260 goto done; 261 } 262 263 if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { 264 printf("cleanup failed\n"); 265 ret = false; 266 goto done; 267 } 268 269 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 270 printf("domain close failed\n"); 54 torture_comment(torture, "libnet_CreateUser call failed: %s\n", nt_errstr(status)); 55 ret = false; 56 goto done; 57 } 58 59 if (!test_user_cleanup(torture, ctx->samr.pipe->binding_handle, 60 mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { 61 torture_comment(torture, "cleanup failed\n"); 62 ret = false; 63 goto done; 64 } 65 66 if (!test_samr_close_handle(torture, 67 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 68 torture_comment(torture, "domain close failed\n"); 271 69 ret = false; 272 70 } … … 283 81 NTSTATUS status; 284 82 struct dcerpc_pipe *p; 285 TALLOC_CTX * prep_mem_ctx, *mem_ctx;83 TALLOC_CTX *mem_ctx; 286 84 struct policy_handle h; 287 85 struct lsa_String domain_name; 288 86 const char *name = TEST_USERNAME; 289 struct libnet_context *ctx ;87 struct libnet_context *ctx = NULL; 290 88 struct libnet_DeleteUser req; 291 bool ret = true; 292 293 prep_mem_ctx = talloc_init("prepare test_deleteuser"); 294 295 ctx = libnet_context_init(torture->ev, torture->lp_ctx); 296 ctx->cred = cmdline_credentials; 297 298 req.in.user_name = TEST_USERNAME; 299 req.in.domain_name = lp_workgroup(torture->lp_ctx); 89 bool ret = false; 300 90 301 91 status = torture_rpc_connection(torture, 302 92 &p, 303 93 &ndr_table_samr); 304 if (!NT_STATUS_IS_OK(status)) { 305 ret = false; 306 goto done; 307 } 308 309 domain_name.string = lp_workgroup(torture->lp_ctx); 310 if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { 311 ret = false; 312 goto done; 313 } 314 315 if (!test_createuser(p, prep_mem_ctx, &h, name)) { 316 ret = false; 317 goto done; 318 } 319 320 mem_ctx = talloc_init("test_deleteuser"); 94 torture_assert_ntstatus_ok(torture, status, "torture_rpc_connection() failed"); 95 96 mem_ctx = talloc_init("torture_deleteuser"); 97 98 /* 99 * Pre-create a user to be deleted later 100 */ 101 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 102 ret = test_domain_open(torture, p->binding_handle, &domain_name, mem_ctx, &h, NULL); 103 torture_assert_goto(torture, ret, ret, done, "test_domain_open() failed"); 104 105 ret = test_user_create(torture, p->binding_handle, mem_ctx, &h, name, NULL); 106 torture_assert_goto(torture, ret, ret, done, "test_user_create() failed"); 107 108 /* 109 * Delete the user using libnet layer 110 */ 111 ret = test_libnet_context_init(torture, true, &ctx); 112 torture_assert_goto(torture, ret, ret, done, "test_libnet_context_init() failed"); 113 114 req.in.user_name = TEST_USERNAME; 115 req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 321 116 322 117 status = libnet_DeleteUser(ctx, mem_ctx, &req); 323 if (!NT_STATUS_IS_OK(status)) { 324 printf("libnet_DeleteUser call failed: %s\n", nt_errstr(status)); 325 ret = false; 326 } 327 328 talloc_free(mem_ctx); 118 torture_assert_ntstatus_ok_goto(torture, status, ret, done, "libnet_DeleteUser() failed"); 119 120 /* mark test as successful */ 121 ret = true; 329 122 330 123 done: 331 124 talloc_free(ctx); 332 talloc_free( prep_mem_ctx);125 talloc_free(mem_ctx); 333 126 return ret; 334 127 } … … 339 132 */ 340 133 341 static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, 134 static void set_test_changes(struct torture_context *tctx, 135 TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, 342 136 int num_changes, char **user_name, enum test_fields req_change) 343 137 { … … 352 146 int i, testfld; 353 147 354 printf("Fields to change: [");355 356 for (i = 0; i < num_changes && i < FIELDS_NUM; i++) {148 torture_comment(tctx, "Fields to change: ["); 149 150 for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) { 357 151 const char *fldname; 358 152 359 testfld = (req_change == none) ? (random() % FIELDS_NUM): req_change;153 testfld = (req_change == none) ? (random() % USER_FIELD_LAST) + 1 : req_change; 360 154 361 155 /* get one in case we hit time field this time */ 362 156 gettimeofday(&now, NULL); 363 157 364 158 switch (testfld) { 365 case acc ount_name:159 case acct_name: 366 160 continue_if_field_set(r->in.account_name); 367 161 r->in.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME, 368 162 (int)(random() % 100)); 369 163 fldname = "account_name"; 370 164 371 165 /* update the test's user name in case it's about to change */ 372 166 *user_name = talloc_strdup(mem_ctx, r->in.account_name); 373 167 break; 374 168 375 case full_name:169 case acct_full_name: 376 170 continue_if_field_set(r->in.full_name); 377 171 r->in.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME, … … 380 174 break; 381 175 382 case description:176 case acct_description: 383 177 continue_if_field_set(r->in.description); 384 178 r->in.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION, … … 387 181 break; 388 182 389 case home_directory:183 case acct_home_directory: 390 184 continue_if_field_set(r->in.home_directory); 391 185 homedir = home_dirs[random() % ARRAY_SIZE(home_dirs)]; … … 394 188 break; 395 189 396 case home_drive:190 case acct_home_drive: 397 191 continue_if_field_set(r->in.home_drive); 398 192 homedrive = home_drives[random() % ARRAY_SIZE(home_drives)]; … … 401 195 break; 402 196 403 case comment:197 case acct_comment: 404 198 continue_if_field_set(r->in.comment); 405 199 r->in.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT, … … 408 202 break; 409 203 410 case logon_script:204 case acct_logon_script: 411 205 continue_if_field_set(r->in.logon_script); 412 206 logonscript = logon_scripts[random() % ARRAY_SIZE(logon_scripts)]; … … 414 208 fldname = "logon_script"; 415 209 break; 416 417 case profile_path:210 211 case acct_profile_path: 418 212 continue_if_field_set(r->in.profile_path); 419 213 r->in.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH, … … 438 232 fldname = "unknown_field"; 439 233 } 440 441 printf(((i < num_changes - 1) ? "%s," : "%s"), fldname);234 235 torture_comment(tctx, ((i < num_changes - 1) ? "%s," : "%s"), fldname); 442 236 443 237 /* disable requested field (it's supposed to be the only one used) */ … … 445 239 } 446 240 447 printf("]\n");241 torture_comment(tctx, "]\n"); 448 242 } 449 243 … … 451 245 #define TEST_STR_FLD(fld) \ 452 246 if (!strequal(req.in.fld, user_req.out.fld)) { \ 453 printf("failed to change '%s'\n", #fld); \247 torture_comment(torture, "failed to change '%s'\n", #fld); \ 454 248 ret = false; \ 455 249 goto cleanup; \ … … 458 252 #define TEST_TIME_FLD(fld) \ 459 253 if (timeval_compare(req.in.fld, user_req.out.fld)) { \ 460 printf("failed to change '%s'\n", #fld); \254 torture_comment(torture, "failed to change '%s'\n", #fld); \ 461 255 ret = false; \ 462 256 goto cleanup; \ … … 465 259 #define TEST_NUM_FLD(fld) \ 466 260 if (req.in.fld != user_req.out.fld) { \ 467 printf("failed to change '%s'\n", #fld); \261 torture_comment(torture, "failed to change '%s'\n", #fld); \ 468 262 ret = false; \ 469 263 goto cleanup; \ … … 474 268 { 475 269 NTSTATUS status; 476 struct dcerpc_binding *binding;477 270 struct dcerpc_pipe *p; 478 271 TALLOC_CTX *prep_mem_ctx; … … 480 273 struct lsa_String domain_name; 481 274 char *name; 482 struct libnet_context *ctx ;275 struct libnet_context *ctx = NULL; 483 276 struct libnet_ModifyUser req; 484 277 struct libnet_UserInfo user_req; 485 278 int fld; 486 279 bool ret = true; 280 struct dcerpc_binding_handle *b; 487 281 488 282 prep_mem_ctx = talloc_init("prepare test_deleteuser"); 489 490 ctx = libnet_context_init(torture->ev, torture->lp_ctx);491 ctx->cred = cmdline_credentials;492 283 493 284 status = torture_rpc_connection(torture, … … 498 289 goto done; 499 290 } 291 b = p->binding_handle; 500 292 501 293 name = talloc_strdup(prep_mem_ctx, TEST_USERNAME); 502 294 503 domain_name.string = lp_workgroup(torture->lp_ctx); 504 if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { 505 ret = false; 506 goto done; 507 } 508 509 if (!test_createuser(p, prep_mem_ctx, &h, name)) { 510 ret = false; 511 goto done; 512 } 513 514 status = torture_rpc_binding(torture, &binding); 515 if (!NT_STATUS_IS_OK(status)) { 516 ret = false; 517 goto done; 518 } 519 520 printf("Testing change of all fields - each single one in turn\n"); 521 522 for (fld = 1; fld < FIELDS_NUM - 1; fld++) { 295 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 296 if (!test_domain_open(torture, b, &domain_name, prep_mem_ctx, &h, NULL)) { 297 ret = false; 298 goto done; 299 } 300 301 if (!test_user_create(torture, b, prep_mem_ctx, &h, name, NULL)) { 302 ret = false; 303 goto done; 304 } 305 306 torture_comment(torture, "Testing change of all fields - each single one in turn\n"); 307 308 if (!test_libnet_context_init(torture, true, &ctx)) { 309 return false; 310 } 311 312 for (fld = USER_FIELD_FIRST; fld <= USER_FIELD_LAST; fld++) { 523 313 ZERO_STRUCT(req); 524 req.in.domain_name = lp _workgroup(torture->lp_ctx);314 req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 525 315 req.in.user_name = name; 526 316 527 set_test_changes(torture, &req, 1, &name, fld);317 set_test_changes(torture, torture, &req, 1, &name, fld); 528 318 529 319 status = libnet_ModifyUser(ctx, torture, &req); 530 320 if (!NT_STATUS_IS_OK(status)) { 531 printf("libnet_ModifyUser call failed: %s\n", nt_errstr(status));321 torture_comment(torture, "libnet_ModifyUser call failed: %s\n", nt_errstr(status)); 532 322 ret = false; 533 323 continue; … … 535 325 536 326 ZERO_STRUCT(user_req); 537 user_req.in.domain_name = lp _workgroup(torture->lp_ctx);327 user_req.in.domain_name = lpcfg_workgroup(torture->lp_ctx); 538 328 user_req.in.data.user_name = name; 539 329 user_req.in.level = USER_INFO_BY_NAME; … … 541 331 status = libnet_UserInfo(ctx, torture, &user_req); 542 332 if (!NT_STATUS_IS_OK(status)) { 543 printf("libnet_UserInfo call failed: %s\n", nt_errstr(status));333 torture_comment(torture, "libnet_UserInfo call failed: %s\n", nt_errstr(status)); 544 334 ret = false; 545 335 continue; … … 547 337 548 338 switch (fld) { 549 case acc ount_name: TEST_STR_FLD(account_name);550 break; 551 case full_name: TEST_STR_FLD(full_name);552 break; 553 case comment: TEST_STR_FLD(comment);554 break; 555 case description: TEST_STR_FLD(description);556 break; 557 case home_directory: TEST_STR_FLD(home_directory);558 break; 559 case home_drive: TEST_STR_FLD(home_drive);560 break; 561 case logon_script: TEST_STR_FLD(logon_script);562 break; 563 case profile_path: TEST_STR_FLD(profile_path);339 case acct_name: TEST_STR_FLD(account_name); 340 break; 341 case acct_full_name: TEST_STR_FLD(full_name); 342 break; 343 case acct_comment: TEST_STR_FLD(comment); 344 break; 345 case acct_description: TEST_STR_FLD(description); 346 break; 347 case acct_home_directory: TEST_STR_FLD(home_directory); 348 break; 349 case acct_home_drive: TEST_STR_FLD(home_drive); 350 break; 351 case acct_logon_script: TEST_STR_FLD(logon_script); 352 break; 353 case acct_profile_path: TEST_STR_FLD(profile_path); 564 354 break; 565 355 case acct_expiry: TEST_TIME_FLD(acct_expiry); … … 570 360 break; 571 361 } 572 573 if (fld == account_name) {574 /* restore original testing username - it's useful when test fails575 because it prevents from problems with recreating account */576 ZERO_STRUCT(req);577 req.in.domain_name = lp_workgroup(torture->lp_ctx);578 req.in.user_name = name;579 req.in.account_name = TEST_USERNAME;580 581 status = libnet_ModifyUser(ctx, torture, &req);582 if (!NT_STATUS_IS_OK(status)) {583 printf("libnet_ModifyUser call failed: %s\n", nt_errstr(status));584 ret = false;585 goto done;586 }587 588 name = talloc_strdup(torture, TEST_USERNAME);589 }590 362 } 591 363 592 364 cleanup: 593 if (!test_cleanup(ctx->samr.pipe, torture, &ctx->samr.handle, name)) { 594 printf("cleanup failed\n"); 595 ret = false; 596 goto done; 597 } 598 599 if (!test_samr_close(ctx->samr.pipe, torture, &ctx->samr.handle)) { 600 printf("domain close failed\n"); 365 if (!test_user_cleanup(torture, ctx->samr.pipe->binding_handle, 366 torture, &ctx->samr.handle, TEST_USERNAME)) { 367 torture_comment(torture, "cleanup failed\n"); 368 ret = false; 369 goto done; 370 } 371 372 if (!test_samr_close_handle(torture, 373 ctx->samr.pipe->binding_handle, torture, &ctx->samr.handle)) { 374 torture_comment(torture, "domain close failed\n"); 601 375 ret = false; 602 376 } … … 615 389 NTSTATUS status; 616 390 TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx; 617 struct libnet_context *ctx ;391 struct libnet_context *ctx = NULL; 618 392 struct dcerpc_pipe *p; 619 393 struct policy_handle h; 620 394 struct lsa_String domain_name; 621 395 struct libnet_UserInfo req; 396 struct dcerpc_binding_handle *b; 622 397 623 398 prep_mem_ctx = talloc_init("prepare torture user info"); 624 625 ctx = libnet_context_init(torture->ev, torture->lp_ctx);626 ctx->cred = cmdline_credentials;627 399 628 400 status = torture_rpc_connection(torture, … … 632 404 return false; 633 405 } 634 635 domain_name.string = lp_workgroup(torture->lp_ctx); 636 if (!test_opendomain(p, prep_mem_ctx, &h, &domain_name)) { 637 ret = false; 638 goto done; 639 } 640 641 if (!test_createuser(p, prep_mem_ctx, &h, name)) { 406 b = p->binding_handle; 407 408 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 409 if (!test_domain_open(torture, b, &domain_name, prep_mem_ctx, &h, NULL)) { 410 ret = false; 411 goto done; 412 } 413 414 if (!test_user_create(torture, b, prep_mem_ctx, &h, name, NULL)) { 642 415 ret = false; 643 416 goto done; … … 646 419 mem_ctx = talloc_init("torture user info"); 647 420 421 if (!test_libnet_context_init(torture, true, &ctx)) { 422 return false; 423 } 424 648 425 ZERO_STRUCT(req); 649 426 650 427 req.in.domain_name = domain_name.string; 651 428 req.in.data.user_name = name; … … 654 431 status = libnet_UserInfo(ctx, mem_ctx, &req); 655 432 if (!NT_STATUS_IS_OK(status)) { 656 printf("libnet_UserInfo call failed: %s\n", nt_errstr(status)); 657 ret = false; 658 talloc_free(mem_ctx); 659 goto done; 660 } 661 662 if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { 663 printf("cleanup failed\n"); 664 ret = false; 665 goto done; 666 } 667 668 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 669 printf("domain close failed\n"); 670 ret = false; 671 } 672 433 torture_comment(torture, "libnet_UserInfo call failed: %s\n", nt_errstr(status)); 434 ret = false; 435 goto done; 436 } 437 438 if (!test_user_cleanup(torture, ctx->samr.pipe->binding_handle, 439 mem_ctx, &ctx->samr.handle, TEST_USERNAME)) { 440 torture_comment(torture, "cleanup failed\n"); 441 ret = false; 442 goto done; 443 } 444 445 if (!test_samr_close_handle(torture, 446 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 447 torture_comment(torture, "domain close failed\n"); 448 ret = false; 449 } 450 451 done: 673 452 talloc_free(ctx); 674 675 done:676 453 talloc_free(mem_ctx); 677 454 return ret; … … 692 469 ctx->cred = cmdline_credentials; 693 470 694 domain_name.string = lp _workgroup(torture->lp_ctx);471 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 695 472 mem_ctx = talloc_init("torture user list"); 696 473 697 474 ZERO_STRUCT(req); 698 475 699 printf("listing user accounts:\n");700 476 torture_comment(torture, "listing user accounts:\n"); 477 701 478 do { 702 479 … … 710 487 711 488 for (i = 0; i < req.out.count; i++) { 712 printf("\tuser: %s, sid=%s\n",713 req.out.users[i].username, req.out.users[i].sid);489 torture_comment(torture, "\tuser: %s, sid=%s\n", 490 req.out.users[i].username, req.out.users[i].sid); 714 491 } 715 492 … … 718 495 if (!(NT_STATUS_IS_OK(status) || 719 496 NT_STATUS_EQUAL(status, NT_STATUS_NO_MORE_ENTRIES))) { 720 printf("libnet_UserList call failed: %s\n", nt_errstr(status)); 721 ret = false; 722 goto done; 723 } 724 725 if (!test_samr_close(ctx->samr.pipe, mem_ctx, &ctx->samr.handle)) { 726 printf("samr domain close failed\n"); 727 ret = false; 728 goto done; 729 } 730 731 if (!test_lsa_close(ctx->lsa.pipe, mem_ctx, &ctx->lsa.handle)) { 732 printf("lsa domain close failed\n"); 497 torture_comment(torture, "libnet_UserList call failed: %s\n", nt_errstr(status)); 498 ret = false; 499 goto done; 500 } 501 502 if (!test_samr_close_handle(torture, 503 ctx->samr.pipe->binding_handle, mem_ctx, &ctx->samr.handle)) { 504 torture_comment(torture, "samr domain close failed\n"); 505 ret = false; 506 goto done; 507 } 508 509 if (!test_lsa_close_handle(torture, 510 ctx->lsa.pipe->binding_handle, mem_ctx, &ctx->lsa.handle)) { 511 torture_comment(torture, "lsa domain close failed\n"); 733 512 ret = false; 734 513 } -
trunk/server/source4/torture/libnet/userinfo.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 20 21 21 #include "includes.h" 22 #include "torture/rpc/ rpc.h"22 #include "torture/rpc/torture_rpc.h" 23 23 #include "libnet/libnet.h" 24 24 #include "libcli/security/security.h" 25 25 #include "librpc/gen_ndr/ndr_samr_c.h" 26 26 #include "param/param.h" 27 #include "torture/libnet/ utils.h"27 #include "torture/libnet/proto.h" 28 28 29 29 30 30 #define TEST_USERNAME "libnetuserinfotest" 31 31 32 static bool test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 32 static bool test_userinfo(struct torture_context *tctx, 33 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 33 34 struct policy_handle *domain_handle, 34 35 struct dom_sid2 *domain_sid, const char* user_name, … … 39 40 struct libnet_rpc_userinfo user; 40 41 struct dom_sid *user_sid; 41 42 42 43 user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid); 43 44 44 45 user.in.domain_handle = *domain_handle; 45 46 user.in.sid = dom_sid_string(mem_ctx, user_sid); 46 47 user.in.level = level; /* this should be extended */ 47 48 48 printf("Testing sync libnet_rpc_userinfo (SID argument)\n");49 torture_comment(tctx, "Testing sync libnet_rpc_userinfo (SID argument)\n"); 49 50 status = libnet_rpc_userinfo(p, mem_ctx, &user); 50 if (!NT_STATUS_IS_OK(status)) { 51 printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); 52 return false; 53 } 51 torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo() failed"); 54 52 55 53 ZERO_STRUCT(user); … … 57 55 user.in.domain_handle = *domain_handle; 58 56 user.in.sid = NULL; 59 user.in.username = TEST_USERNAME;57 user.in.username = user_name; 60 58 user.in.level = level; 61 59 62 printf("Testing sync libnet_rpc_userinfo (username argument)\n");60 torture_comment(tctx, "Testing sync libnet_rpc_userinfo (username argument)\n"); 63 61 status = libnet_rpc_userinfo(p, mem_ctx, &user); 64 if (!NT_STATUS_IS_OK(status)) { 65 printf("Failed to call sync libnet_rpc_userinfo - %s\n", nt_errstr(status)); 66 return false; 67 } 62 torture_assert_ntstatus_ok(tctx, status, "Calling sync libnet_rpc_userinfo failed"); 68 63 69 64 return true; … … 71 66 72 67 73 static bool test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 68 static bool test_userinfo_async(struct torture_context *tctx, 69 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 74 70 struct policy_handle *domain_handle, 75 71 struct dom_sid2 *domain_sid, const char* user_name, … … 88 84 user.in.level = level; /* this should be extended */ 89 85 90 printf("Testing async libnet_rpc_userinfo (SID argument)\n");86 torture_comment(tctx, "Testing async libnet_rpc_userinfo (SID argument)\n"); 91 87 92 88 c = libnet_rpc_userinfo_send(p, &user, msg_handler); 93 if (!c) { 94 printf("Failed to call sync libnet_rpc_userinfo_send\n"); 95 return false; 96 } 89 torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send"); 97 90 98 91 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user); 99 if (!NT_STATUS_IS_OK(status)) { 100 printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status)); 101 return false; 102 } 92 torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed"); 103 93 104 94 ZERO_STRUCT(user); … … 106 96 user.in.domain_handle = *domain_handle; 107 97 user.in.sid = NULL; 108 user.in.username = TEST_USERNAME;98 user.in.username = user_name; 109 99 user.in.level = level; 110 100 111 printf("Testing async libnet_rpc_userinfo (username argument)\n");101 torture_comment(tctx, "Testing async libnet_rpc_userinfo (username argument)\n"); 112 102 113 103 c = libnet_rpc_userinfo_send(p, &user, msg_handler); 114 if (!c) { 115 printf("Failed to call sync libnet_rpc_userinfo_send\n"); 116 return false; 117 } 104 torture_assert(tctx, c != NULL, "Failed to call async libnet_rpc_userinfo_send"); 118 105 119 106 status = libnet_rpc_userinfo_recv(c, mem_ctx, &user); 120 if (!NT_STATUS_IS_OK(status)) { 121 printf("Calling async libnet_rpc_userinfo failed - %s\n", nt_errstr(status)); 122 return false; 123 } 107 torture_assert_ntstatus_ok(tctx, status, "Calling async libnet_rpc_userinfo_recv failed"); 124 108 125 109 return true; … … 137 121 struct dom_sid2 sid; 138 122 uint32_t rid; 123 struct dcerpc_binding_handle *b; 139 124 140 125 mem_ctx = talloc_init("test_userinfo"); 141 126 142 status = torture_rpc_connection(torture, 127 status = torture_rpc_connection(torture, 143 128 &p, 144 129 &ndr_table_samr); 145 130 146 131 if (!NT_STATUS_IS_OK(status)) { 147 132 return false; 148 133 } 134 b = p->binding_handle; 149 135 150 name.string = lp _workgroup(torture->lp_ctx);136 name.string = lpcfg_workgroup(torture->lp_ctx); 151 137 152 138 /* 153 139 * Testing synchronous version 154 140 */ 155 if (!test_ opendomain(torture, p, mem_ctx, &h, &name, &sid)) {141 if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) { 156 142 ret = false; 157 143 goto done; 158 144 } 159 145 160 if (!test_user_create(torture, p, mem_ctx, &h, TEST_USERNAME, &rid)) {146 if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) { 161 147 ret = false; 162 148 goto done; 163 149 } 164 150 165 if (!test_userinfo( p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {151 if (!test_userinfo(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) { 166 152 ret = false; 167 153 goto done; 168 154 } 169 155 170 if (!test_user_cleanup(torture, p, mem_ctx, &h, TEST_USERNAME)) {156 if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) { 171 157 ret = false; 172 158 goto done; … … 176 162 * Testing asynchronous version and monitor messages 177 163 */ 178 if (!test_ opendomain(torture, p, mem_ctx, &h, &name, &sid)) {164 if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) { 179 165 ret = false; 180 166 goto done; 181 167 } 182 168 183 if (!test_user_create(torture, p, mem_ctx, &h, TEST_USERNAME, &rid)) {169 if (!test_user_create(torture, b, mem_ctx, &h, TEST_USERNAME, &rid)) { 184 170 ret = false; 185 171 goto done; 186 172 } 187 173 188 if (!test_userinfo_async( p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) {174 if (!test_userinfo_async(torture, p, mem_ctx, &h, &sid, TEST_USERNAME, &rid)) { 189 175 ret = false; 190 176 goto done; 191 177 } 192 178 193 if (!test_user_cleanup(torture, p, mem_ctx, &h, TEST_USERNAME)) {179 if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) { 194 180 ret = false; 195 181 goto done; -
trunk/server/source4/torture/libnet/userman.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2005 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 20 20 21 21 #include "includes.h" 22 #include "torture/rpc/ rpc.h"22 #include "torture/rpc/torture_rpc.h" 23 23 #include "torture/libnet/usertest.h" 24 24 #include "libnet/libnet.h" … … 26 26 #include "param/param.h" 27 27 28 #include "torture/libnet/utils.h" 29 30 31 static bool test_useradd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 28 #include "torture/libnet/proto.h" 29 30 31 static bool test_useradd(struct torture_context *tctx, 32 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 32 33 struct policy_handle *domain_handle, 33 34 const char *name) … … 36 37 bool ret = true; 37 38 struct libnet_rpc_useradd user; 38 39 39 40 user.in.domain_handle = *domain_handle; 40 41 user.in.username = name; 41 42 42 printf("Testing libnet_rpc_useradd\n");43 torture_comment(tctx, "Testing libnet_rpc_useradd\n"); 43 44 44 45 status = libnet_rpc_useradd(p, mem_ctx, &user); 45 46 if (!NT_STATUS_IS_OK(status)) { 46 printf("Failed to call libnet_rpc_useradd - %s\n", nt_errstr(status));47 torture_comment(tctx, "Failed to call libnet_rpc_useradd - %s\n", nt_errstr(status)); 47 48 return false; 48 49 } 49 50 50 51 return ret; 51 52 } 52 53 53 54 54 static bool test_useradd_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 55 static bool test_useradd_async(struct torture_context *tctx, 56 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 55 57 struct policy_handle *handle, const char* username) 56 58 { … … 61 63 user.in.domain_handle = *handle; 62 64 user.in.username = username; 63 64 printf("Testing async libnet_rpc_useradd\n");65 65 66 torture_comment(tctx, "Testing async libnet_rpc_useradd\n"); 67 66 68 c = libnet_rpc_useradd_send(p, &user, msg_handler); 67 69 if (!c) { 68 printf("Failed to call async libnet_rpc_useradd\n");70 torture_comment(tctx, "Failed to call async libnet_rpc_useradd\n"); 69 71 return false; 70 72 } … … 72 74 status = libnet_rpc_useradd_recv(c, mem_ctx, &user); 73 75 if (!NT_STATUS_IS_OK(status)) { 74 printf("Calling async libnet_rpc_useradd failed - %s\n", nt_errstr(status));76 torture_comment(tctx, "Calling async libnet_rpc_useradd failed - %s\n", nt_errstr(status)); 75 77 return false; 76 78 } … … 80 82 } 81 83 82 static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p, 84 static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p, 83 85 TALLOC_CTX *mem_ctx, 84 86 struct policy_handle *handle, int num_changes, … … 104 106 mod->in.domain_handle = *handle; 105 107 106 torture_comment(tctx, "modifying user (%d simultaneous change(s))\n", 108 torture_comment(tctx, "modifying user (%d simultaneous change(s))\n", 107 109 num_changes); 108 110 109 111 torture_comment(tctx, "fields to change: ["); 110 112 111 for (i = 0; i < num_changes && i < FIELDS_NUM - 1; i++) {113 for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) { 112 114 const char *fldname; 113 115 114 testfld = (random() % (FIELDS_NUM - 1)) + 1;115 116 gettimeofday(&now, NULL);116 testfld = (random() % USER_FIELD_LAST) + 1; 117 118 GetTimeOfDay(&now); 117 119 118 120 switch (testfld) { 119 case acc ount_name:121 case acct_name: 120 122 continue_if_field_set(mod->in.change.account_name); 121 123 mod->in.change.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME, … … 126 128 break; 127 129 128 case full_name:130 case acct_full_name: 129 131 continue_if_field_set(mod->in.change.full_name); 130 132 mod->in.change.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME, … … 134 136 break; 135 137 136 case description:138 case acct_description: 137 139 continue_if_field_set(mod->in.change.description); 138 140 mod->in.change.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION, … … 141 143 fldname = "description"; 142 144 break; 143 144 case home_directory:145 146 case acct_home_directory: 145 147 continue_if_field_set(mod->in.change.home_directory); 146 148 homedir = home_dirs[random() % (sizeof(home_dirs)/sizeof(char*))]; … … 150 152 break; 151 153 152 case home_drive:154 case acct_home_drive: 153 155 continue_if_field_set(mod->in.change.home_drive); 154 156 homedrive = home_drives[random() % (sizeof(home_drives)/sizeof(char*))]; … … 158 160 break; 159 161 160 case comment:162 case acct_comment: 161 163 continue_if_field_set(mod->in.change.comment); 162 164 mod->in.change.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT, … … 166 168 break; 167 169 168 case logon_script:170 case acct_logon_script: 169 171 continue_if_field_set(mod->in.change.logon_script); 170 172 logonscript = logon_scripts[random() % (sizeof(logon_scripts)/sizeof(char*))]; … … 174 176 break; 175 177 176 case profile_path:178 case acct_profile_path: 177 179 continue_if_field_set(mod->in.change.profile_path); 178 180 mod->in.change.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH, … … 213 215 214 216 215 static bool test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 217 static bool test_userdel(struct torture_context *tctx, 218 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 216 219 struct policy_handle *handle, const char *username) 217 220 { 218 221 NTSTATUS status; 219 222 struct libnet_rpc_userdel user; 220 223 221 224 user.in.domain_handle = *handle; 222 225 user.in.username = username; 223 226 224 227 status = libnet_rpc_userdel(p, mem_ctx, &user); 225 228 if (!NT_STATUS_IS_OK(status)) { 226 printf("Failed to call sync libnet_rpc_userdel - %s\n", nt_errstr(status));229 torture_comment(tctx, "Failed to call sync libnet_rpc_userdel - %s\n", nt_errstr(status)); 227 230 return false; 228 231 } … … 235 238 if ((mod->in.change.fields & flags) && \ 236 239 !strequal(i->fld.string, mod->in.change.fld)) { \ 237 printf("'%s' field does not match\n", #fld); \238 printf("received: '%s'\n", i->fld.string); \239 printf("expected: '%s'\n", mod->in.change.fld); \240 torture_comment(tctx, "'%s' field does not match\n", #fld); \ 241 torture_comment(tctx, "received: '%s'\n", i->fld.string); \ 242 torture_comment(tctx, "expected: '%s'\n", mod->in.change.fld); \ 240 243 return false; \ 241 244 } … … 246 249 nttime_to_timeval(&t, i->fld); \ 247 250 if (timeval_compare(&t, mod->in.change.fld)) { \ 248 printf("'%s' field does not match\n", #fld); \249 printf("received: '%s (+%ld us)'\n", \251 torture_comment(tctx, "'%s' field does not match\n", #fld); \ 252 torture_comment(tctx, "received: '%s (+%ld us)'\n", \ 250 253 timestring(mem_ctx, t.tv_sec), t.tv_usec); \ 251 printf("expected: '%s (+%ld us)'\n", \254 torture_comment(tctx, "expected: '%s (+%ld us)'\n", \ 252 255 timestring(mem_ctx, mod->in.change.fld->tv_sec), \ 253 256 mod->in.change.fld->tv_usec); \ … … 259 262 if ((mod->in.change.fields & flags) && \ 260 263 (i->fld != mod->in.change.fld)) { \ 261 printf("'%s' field does not match\n", #fld); \262 printf("received: '%04x'\n", i->fld); \263 printf("expected: '%04x'\n", mod->in.change.fld); \264 torture_comment(tctx, "'%s' field does not match\n", #fld); \ 265 torture_comment(tctx, "received: '%04x'\n", i->fld); \ 266 torture_comment(tctx, "expected: '%04x'\n", mod->in.change.fld); \ 264 267 return false; \ 265 268 } 266 269 267 270 268 static bool test_compare(struct torture_context *tctx, 271 static bool test_compare(struct torture_context *tctx, 269 272 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 270 273 struct policy_handle *handle, struct libnet_rpc_usermod *mod, … … 312 315 TALLOC_CTX *mem_ctx; 313 316 bool ret = true; 317 struct dcerpc_binding_handle *b; 314 318 315 319 mem_ctx = talloc_init("test_useradd"); 316 320 317 status = torture_rpc_connection(torture, 321 status = torture_rpc_connection(torture, 318 322 &p, 319 323 &ndr_table_samr); 320 324 321 325 torture_assert_ntstatus_ok(torture, status, "RPC connect failed"); 322 323 domain_name.string = lp_workgroup(torture->lp_ctx); 324 if (!test_opendomain(torture, p, mem_ctx, &h, &domain_name, &sid)) { 325 ret = false; 326 goto done; 327 } 328 329 if (!test_useradd(p, mem_ctx, &h, name)) { 330 ret = false; 331 goto done; 332 } 333 334 if (!test_user_cleanup(torture, p, mem_ctx, &h, name)) { 335 ret = false; 336 goto done; 337 } 338 339 if (!test_opendomain(torture, p, mem_ctx, &h, &domain_name, &sid)) { 340 ret = false; 341 goto done; 342 } 343 344 if (!test_useradd_async(p, mem_ctx, &h, name)) { 345 ret = false; 346 goto done; 347 } 348 349 if (!test_user_cleanup(torture, p, mem_ctx, &h, name)) { 326 b = p->binding_handle; 327 328 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 329 if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) { 330 ret = false; 331 goto done; 332 } 333 334 if (!test_useradd(torture, p, mem_ctx, &h, name)) { 335 ret = false; 336 goto done; 337 } 338 339 if (!test_user_cleanup(torture, b, mem_ctx, &h, name)) { 340 ret = false; 341 goto done; 342 } 343 344 if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) { 345 ret = false; 346 goto done; 347 } 348 349 if (!test_useradd_async(torture, p, mem_ctx, &h, name)) { 350 ret = false; 351 goto done; 352 } 353 354 if (!test_user_cleanup(torture, b, mem_ctx, &h, name)) { 350 355 ret = false; 351 356 goto done; … … 369 374 TALLOC_CTX *mem_ctx; 370 375 bool ret = true; 376 struct dcerpc_binding_handle *b; 371 377 372 378 mem_ctx = talloc_init("test_userdel"); 373 379 374 status = torture_rpc_connection(torture, 380 status = torture_rpc_connection(torture, 375 381 &p, 376 382 &ndr_table_samr); 377 383 378 384 if (!NT_STATUS_IS_OK(status)) { 379 385 return false; 380 386 } 381 382 domain_name.string = lp_workgroup(torture->lp_ctx); 383 if (!test_opendomain(torture, p, mem_ctx, &h, &domain_name, &sid)) { 384 ret = false; 385 goto done; 386 } 387 388 if (!test_user_create(torture, p, mem_ctx, &h, name, &rid)) { 389 ret = false; 390 goto done; 391 } 392 393 if (!test_userdel(p, mem_ctx, &h, name)) { 394 ret = false; 395 goto done; 396 } 397 387 b = p->binding_handle; 388 389 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 390 if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) { 391 ret = false; 392 goto done; 393 } 394 395 if (!test_user_create(torture, b, mem_ctx, &h, name, &rid)) { 396 ret = false; 397 goto done; 398 } 399 400 if (!test_userdel(torture, p, mem_ctx, &h, name)) { 401 ret = false; 402 goto done; 403 } 404 398 405 done: 399 406 talloc_free(mem_ctx); … … 414 421 TALLOC_CTX *mem_ctx; 415 422 bool ret = true; 423 struct dcerpc_binding_handle *b; 416 424 417 425 mem_ctx = talloc_init("test_userdel"); 418 426 419 status = torture_rpc_connection(torture, 427 status = torture_rpc_connection(torture, 420 428 &p, 421 429 &ndr_table_samr); 422 430 423 431 torture_assert_ntstatus_ok(torture, status, "RPC connect"); 424 425 domain_name.string = lp_workgroup(torture->lp_ctx); 432 b = p->binding_handle; 433 434 domain_name.string = lpcfg_workgroup(torture->lp_ctx); 426 435 name = talloc_strdup(mem_ctx, TEST_USERNAME); 427 436 428 if (!test_ opendomain(torture, p, mem_ctx, &h, &domain_name, &sid)) {429 ret = false; 430 goto done; 431 } 432 433 if (!test_user_create(torture, p, mem_ctx, &h, name, &rid)) {434 ret = false; 435 goto done; 436 } 437 438 for (i = 1; i < FIELDS_NUM; i++) {437 if (!test_domain_open(torture, b, &domain_name, mem_ctx, &h, &sid)) { 438 ret = false; 439 goto done; 440 } 441 442 if (!test_user_create(torture, b, mem_ctx, &h, name, &rid)) { 443 ret = false; 444 goto done; 445 } 446 447 for (i = USER_FIELD_FIRST; i <= USER_FIELD_LAST; i++) { 439 448 struct libnet_rpc_usermod m; 440 449 … … 449 458 } 450 459 } 451 452 cleanup: 453 if (!test_user_cleanup(torture, p, mem_ctx, &h, name)) {460 461 cleanup: 462 if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) { 454 463 ret = false; 455 464 goto done; -
trunk/server/source4/torture/libnet/usertest.h
r414 r745 27 27 28 28 29 #define FIELDS_NUM 11 30 enum test_fields { none = 0, account_name, full_name, description, home_directory, home_drive, 31 comment, logon_script, profile_path, acct_expiry, acct_flags }; 29 #define USER_FIELD_FIRST acct_name 30 #define USER_FIELD_LAST acct_flags 31 32 enum test_fields { none = 0, 33 acct_name, acct_full_name, acct_description, 34 acct_home_directory, acct_home_drive, acct_comment, 35 acct_logon_script, acct_profile_path, acct_expiry, acct_flags }; 32 36 33 37 -
trunk/server/source4/torture/libnet/utils.c
r414 r745 1 /* 1 /* 2 2 Unix SMB/CIFS implementation. 3 3 Test suite for libnet calls. 4 4 5 5 Copyright (C) Rafal Szczesniak 2007 6 6 7 7 This program is free software; you can redistribute it and/or modify 8 8 it under the terms of the GNU General Public License as published by 9 9 the Free Software Foundation; either version 3 of the License, or 10 10 (at your option) any later version. 11 11 12 12 This program is distributed in the hope that it will be useful, 13 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 15 GNU General Public License for more details. 16 16 17 17 You should have received a copy of the GNU General Public License 18 18 along with this program. If not, see <http://www.gnu.org/licenses/>. … … 24 24 25 25 #include "includes.h" 26 #include "torture/rpc/rpc.h" 26 #include "lib/cmdline/popt_common.h" 27 #include "torture/rpc/torture_rpc.h" 27 28 #include "libnet/libnet.h" 28 29 #include "librpc/gen_ndr/ndr_samr_c.h" 29 #include "torture/libnet/utils.h" 30 31 32 bool test_opendomain(struct torture_context *tctx, 33 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 34 struct policy_handle *handle, struct lsa_String *domname, 35 struct dom_sid2 *sid_p) 36 { 37 NTSTATUS status; 38 struct policy_handle h, domain_handle; 30 #include "librpc/gen_ndr/ndr_lsa_c.h" 31 #include "torture/libnet/proto.h" 32 #include "ldb_wrap.h" 33 34 /** 35 * Opens handle on Domain using SAMR 36 * 37 * @param _domain_handle [out] Ptr to storage to store Domain handle 38 * @param _dom_sid [out] If NULL, Domain SID won't be returned 39 */ 40 bool test_domain_open(struct torture_context *tctx, 41 struct dcerpc_binding_handle *b, 42 struct lsa_String *domname, 43 TALLOC_CTX *mem_ctx, 44 struct policy_handle *_domain_handle, 45 struct dom_sid2 *_dom_sid) 46 { 47 struct policy_handle connect_handle; 48 struct policy_handle domain_handle; 39 49 struct samr_Connect r1; 40 50 struct samr_LookupDomain r2; 41 51 struct dom_sid2 *sid = NULL; 42 52 struct samr_OpenDomain r3; 43 53 44 54 torture_comment(tctx, "connecting\n"); 45 55 46 56 r1.in.system_name = 0; 47 57 r1.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; 48 r1.out.connect_handle = &h; 49 50 status = dcerpc_samr_Connect(p, mem_ctx, &r1); 51 torture_assert_ntstatus_ok(tctx, status, "Connect failed"); 52 53 r2.in.connect_handle = &h; 58 r1.out.connect_handle = &connect_handle; 59 60 torture_assert_ntstatus_ok(tctx, 61 dcerpc_samr_Connect_r(b, mem_ctx, &r1), 62 "Connect failed"); 63 torture_assert_ntstatus_ok(tctx, r1.out.result, 64 "Connect failed"); 65 66 r2.in.connect_handle = &connect_handle; 54 67 r2.in.domain_name = domname; 55 68 r2.out.sid = &sid; … … 57 70 torture_comment(tctx, "domain lookup on %s\n", domname->string); 58 71 59 status = dcerpc_samr_LookupDomain(p, mem_ctx, &r2); 60 torture_assert_ntstatus_ok(tctx, status, "LookupDomain failed"); 61 62 r3.in.connect_handle = &h; 72 torture_assert_ntstatus_ok(tctx, 73 dcerpc_samr_LookupDomain_r(b, mem_ctx, &r2), 74 "LookupDomain failed"); 75 torture_assert_ntstatus_ok(tctx, r2.out.result, 76 "LookupDomain failed"); 77 78 r3.in.connect_handle = &connect_handle; 63 79 r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; 64 80 r3.in.sid = *r2.out.sid; 65 81 r3.out.domain_handle = &domain_handle; 66 82 67 torture_comment(tctx, "opening domain\n"); 68 69 status = dcerpc_samr_OpenDomain(p, mem_ctx, &r3); 70 torture_assert_ntstatus_ok(tctx, status, "OpenDomain failed"); 71 *handle = domain_handle; 72 73 *sid_p = **r2.out.sid; 74 return true; 75 } 76 77 78 bool test_user_cleanup(struct torture_context *tctx, struct dcerpc_pipe *p, 79 TALLOC_CTX *mem_ctx, struct policy_handle *domain_handle, 80 const char *name) 81 { 82 NTSTATUS status; 83 torture_comment(tctx, "opening domain %s\n", domname->string); 84 85 torture_assert_ntstatus_ok(tctx, 86 dcerpc_samr_OpenDomain_r(b, mem_ctx, &r3), 87 "OpenDomain failed"); 88 torture_assert_ntstatus_ok(tctx, r3.out.result, 89 "OpenDomain failed"); 90 91 *_domain_handle = domain_handle; 92 93 if (_dom_sid) { 94 *_dom_sid = **r2.out.sid; 95 } 96 97 /* Close connect_handle, we don't need it anymore */ 98 test_samr_close_handle(tctx, b, mem_ctx, &connect_handle); 99 100 return true; 101 } 102 103 104 /** 105 * Find out user's samAccountName for given 106 * user RDN. We need samAccountName value 107 * when deleting users. 108 */ 109 static bool _get_account_name_for_user_rdn(struct torture_context *tctx, 110 const char *user_rdn, 111 TALLOC_CTX *mem_ctx, 112 const char **_account_name) 113 { 114 const char *url; 115 struct ldb_context *ldb; 116 TALLOC_CTX *tmp_ctx; 117 bool test_res = true; 118 const char *hostname = torture_setting_string(tctx, "host", NULL); 119 int ldb_ret; 120 struct ldb_result *ldb_res; 121 const char *account_name = NULL; 122 static const char *attrs[] = { 123 "samAccountName", 124 NULL 125 }; 126 127 torture_assert(tctx, hostname != NULL, "Failed to get hostname"); 128 129 tmp_ctx = talloc_new(tctx); 130 torture_assert(tctx, tmp_ctx != NULL, "Failed to create temporary mem context"); 131 132 url = talloc_asprintf(tmp_ctx, "ldap://%s/", hostname); 133 torture_assert_goto(tctx, url != NULL, test_res, done, "Failed to allocate URL for ldb"); 134 135 ldb = ldb_wrap_connect(tmp_ctx, 136 tctx->ev, tctx->lp_ctx, 137 url, NULL, cmdline_credentials, 0); 138 torture_assert_goto(tctx, ldb != NULL, test_res, done, "Failed to make LDB connection"); 139 140 ldb_ret = ldb_search(ldb, tmp_ctx, &ldb_res, 141 ldb_get_default_basedn(ldb), LDB_SCOPE_SUBTREE, 142 attrs, 143 "(&(objectClass=user)(name=%s))", user_rdn); 144 if (LDB_SUCCESS == ldb_ret && 1 == ldb_res->count) { 145 account_name = ldb_msg_find_attr_as_string(ldb_res->msgs[0], "samAccountName", NULL); 146 } 147 148 /* return user_rdn by default */ 149 if (!account_name) { 150 account_name = user_rdn; 151 } 152 153 /* duplicate memory in parent context */ 154 *_account_name = talloc_strdup(mem_ctx, account_name); 155 156 done: 157 talloc_free(tmp_ctx); 158 return test_res; 159 } 160 161 /** 162 * Removes user by RDN through SAMR interface. 163 * 164 * @param domain_handle [in] Domain handle 165 * @param user_rdn [in] User's RDN in ldap database 166 */ 167 bool test_user_cleanup(struct torture_context *tctx, 168 struct dcerpc_binding_handle *b, 169 TALLOC_CTX *mem_ctx, 170 struct policy_handle *domain_handle, 171 const char *user_rdn) 172 { 83 173 struct samr_LookupNames r1; 84 174 struct samr_OpenUser r2; … … 88 178 struct policy_handle user_handle; 89 179 struct samr_Ids rids, types; 90 91 names[0].string = name; 180 const char *account_name; 181 182 if (!_get_account_name_for_user_rdn(tctx, user_rdn, mem_ctx, &account_name)) { 183 torture_result(tctx, TORTURE_FAIL, 184 __location__": Failed to find samAccountName for %s", user_rdn); 185 return false; 186 } 187 188 names[0].string = account_name; 92 189 93 190 r1.in.domain_handle = domain_handle; … … 96 193 r1.out.rids = &rids; 97 194 r1.out.types = &types; 98 99 torture_comment(tctx, "user account lookup '%s'\n", name); 100 101 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1); 102 torture_assert_ntstatus_ok(tctx, status, "LookupNames failed"); 195 196 torture_comment(tctx, "user account lookup '%s'\n", account_name); 197 198 torture_assert_ntstatus_ok(tctx, 199 dcerpc_samr_LookupNames_r(b, mem_ctx, &r1), 200 "LookupNames failed"); 201 torture_assert_ntstatus_ok(tctx, r1.out.result, 202 "LookupNames failed"); 103 203 104 204 rid = r1.out.rids->ids[0]; 105 205 106 206 r2.in.domain_handle = domain_handle; 107 207 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; … … 111 211 torture_comment(tctx, "opening user account\n"); 112 212 113 status = dcerpc_samr_OpenUser(p, mem_ctx, &r2); 114 torture_assert_ntstatus_ok(tctx, status, "OpenUser failed"); 213 torture_assert_ntstatus_ok(tctx, 214 dcerpc_samr_OpenUser_r(b, mem_ctx, &r2), 215 "OpenUser failed"); 216 torture_assert_ntstatus_ok(tctx, r2.out.result, 217 "OpenUser failed"); 115 218 116 219 r3.in.user_handle = &user_handle; … … 118 221 119 222 torture_comment(tctx, "deleting user account\n"); 120 121 status = dcerpc_samr_DeleteUser(p, mem_ctx, &r3); 122 torture_assert_ntstatus_ok(tctx, status, "DeleteUser failed"); 123 124 return true; 125 } 126 127 128 bool test_user_create(struct torture_context *tctx, 129 struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 130 struct policy_handle *handle, const char *name, 223 224 torture_assert_ntstatus_ok(tctx, 225 dcerpc_samr_DeleteUser_r(b, mem_ctx, &r3), 226 "DeleteUser failed"); 227 torture_assert_ntstatus_ok(tctx, r3.out.result, 228 "DeleteUser failed"); 229 230 return true; 231 } 232 233 234 /** 235 * Creates new user using SAMR 236 * 237 * @param name [in] Username for user to create 238 * @param rid [out] If NULL, User's RID is not returned 239 */ 240 bool test_user_create(struct torture_context *tctx, 241 struct dcerpc_binding_handle *b, 242 TALLOC_CTX *mem_ctx, 243 struct policy_handle *domain_handle, 244 const char *name, 131 245 uint32_t *rid) 132 246 { 133 NTSTATUS status;247 struct policy_handle user_handle; 134 248 struct lsa_String username; 135 249 struct samr_CreateUser r; 136 struct policy_handle user_handle;137 250 uint32_t user_rid; 251 138 252 username.string = name; 139 140 r.in.domain_handle = handle;253 254 r.in.domain_handle = domain_handle; 141 255 r.in.account_name = &username; 142 256 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; 143 257 r.out.user_handle = &user_handle; 144 r.out.rid = rid; 145 146 torture_comment(tctx, "creating user account %s\n", name); 147 148 status = dcerpc_samr_CreateUser(p, mem_ctx, &r); 149 if (!NT_STATUS_IS_OK(status)) { 150 printf("CreateUser failed - %s\n", nt_errstr(status)); 151 152 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { 153 torture_comment(tctx, "User (%s) already exists - attempting to delete and recreate account again\n", name); 154 if (!test_user_cleanup(tctx, p, mem_ctx, handle, name)) { 258 /* return user's RID only if requested */ 259 r.out.rid = rid ? rid : &user_rid; 260 261 torture_comment(tctx, "creating user '%s'\n", username.string); 262 263 torture_assert_ntstatus_ok(tctx, 264 dcerpc_samr_CreateUser_r(b, mem_ctx, &r), 265 "CreateUser RPC call failed"); 266 if (!NT_STATUS_IS_OK(r.out.result)) { 267 torture_comment(tctx, "CreateUser failed - %s\n", nt_errstr(r.out.result)); 268 269 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_USER_EXISTS)) { 270 torture_comment(tctx, 271 "User (%s) already exists - " 272 "attempting to delete and recreate account again\n", 273 username.string); 274 if (!test_user_cleanup(tctx, b, mem_ctx, domain_handle, username.string)) { 155 275 return false; 156 276 } 157 277 158 278 torture_comment(tctx, "creating user account\n"); 159 160 status = dcerpc_samr_CreateUser(p, mem_ctx, &r); 161 torture_assert_ntstatus_ok(tctx, status, "CreateUser failed"); 279 280 torture_assert_ntstatus_ok(tctx, 281 dcerpc_samr_CreateUser_r(b, mem_ctx, &r), 282 "CreateUser RPC call failed"); 283 torture_assert_ntstatus_ok(tctx, r.out.result, 284 "CreateUser failed"); 285 286 /* be nice and close opened handles */ 287 test_samr_close_handle(tctx, b, mem_ctx, &user_handle); 288 162 289 return true; 163 290 } … … 165 292 } 166 293 167 return true; 168 } 169 170 171 bool test_group_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 294 /* be nice and close opened handles */ 295 test_samr_close_handle(tctx, b, mem_ctx, &user_handle); 296 297 return true; 298 } 299 300 301 /** 302 * Deletes a Group using SAMR interface 303 */ 304 bool test_group_cleanup(struct torture_context *tctx, 305 struct dcerpc_binding_handle *b, 306 TALLOC_CTX *mem_ctx, 172 307 struct policy_handle *domain_handle, 173 308 const char *name) 174 309 { 175 NTSTATUS status;176 310 struct samr_LookupNames r1; 177 311 struct samr_OpenGroup r2; … … 189 323 r1.out.rids = &rids; 190 324 r1.out.types = &types; 191 192 printf("group account lookup '%s'\n", name);193 194 status = dcerpc_samr_LookupNames(p, mem_ctx, &r1);195 if (!NT_STATUS_IS_OK(status)) {196 printf("LookupNames failed - %s\n", nt_errstr(status));197 return false;198 }325 326 torture_comment(tctx, "group account lookup '%s'\n", name); 327 328 torture_assert_ntstatus_ok(tctx, 329 dcerpc_samr_LookupNames_r(b, mem_ctx, &r1), 330 "LookupNames failed"); 331 torture_assert_ntstatus_ok(tctx, r1.out.result, 332 "LookupNames failed"); 199 333 200 334 rid = r1.out.rids->ids[0]; 201 335 202 336 r2.in.domain_handle = domain_handle; 203 337 r2.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; … … 205 339 r2.out.group_handle = &group_handle; 206 340 207 printf("opening group account\n");208 209 status = dcerpc_samr_OpenGroup(p, mem_ctx, &r2);210 if (!NT_STATUS_IS_OK(status)) {211 printf("OpenGroup failed - %s\n", nt_errstr(status));212 return false;213 }341 torture_comment(tctx, "opening group account\n"); 342 343 torture_assert_ntstatus_ok(tctx, 344 dcerpc_samr_OpenGroup_r(b, mem_ctx, &r2), 345 "OpenGroup failed"); 346 torture_assert_ntstatus_ok(tctx, r2.out.result, 347 "OpenGroup failed"); 214 348 215 349 r3.in.group_handle = &group_handle; 216 350 r3.out.group_handle = &group_handle; 217 351 218 printf("deleting group account\n"); 219 220 status = dcerpc_samr_DeleteDomainGroup(p, mem_ctx, &r3); 221 if (!NT_STATUS_IS_OK(status)) { 222 printf("DeleteGroup failed - %s\n", nt_errstr(status)); 223 return false; 224 } 225 226 return true; 227 } 228 229 230 bool test_group_create(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, 231 struct policy_handle *handle, const char *name, 352 torture_comment(tctx, "deleting group account\n"); 353 354 torture_assert_ntstatus_ok(tctx, 355 dcerpc_samr_DeleteDomainGroup_r(b, mem_ctx, &r3), 356 "DeleteGroup failed"); 357 torture_assert_ntstatus_ok(tctx, r3.out.result, 358 "DeleteGroup failed"); 359 360 return true; 361 } 362 363 364 /** 365 * Creates a Group object using SAMR interface 366 * 367 * @param group_name [in] Name of the group to create 368 * @param rid [out] RID of group created. May be NULL in 369 * which case RID is not required by caller 370 */ 371 bool test_group_create(struct torture_context *tctx, 372 struct dcerpc_binding_handle *b, 373 TALLOC_CTX *mem_ctx, 374 struct policy_handle *handle, 375 const char *group_name, 232 376 uint32_t *rid) 233 377 { 234 NTSTATUS status;378 uint32_t group_rid; 235 379 struct lsa_String groupname; 236 380 struct samr_CreateDomainGroup r; 237 381 struct policy_handle group_handle; 238 239 groupname.string = name;240 382 383 groupname.string = group_name; 384 241 385 r.in.domain_handle = handle; 242 386 r.in.name = &groupname; 243 387 r.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; 244 388 r.out.group_handle = &group_handle; 245 r.out.rid = rid; 246 247 printf("creating group account %s\n", name); 248 249 status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); 250 if (!NT_STATUS_IS_OK(status)) { 251 printf("CreateGroup failed - %s\n", nt_errstr(status)); 252 253 if (NT_STATUS_EQUAL(status, NT_STATUS_USER_EXISTS)) { 254 printf("Group (%s) already exists - attempting to delete and recreate account again\n", name); 255 if (!test_group_cleanup(p, mem_ctx, handle, name)) { 389 /* use local variable in case caller 390 * don't care about the group RID */ 391 r.out.rid = rid ? rid : &group_rid; 392 393 torture_comment(tctx, "creating group account %s\n", group_name); 394 395 torture_assert_ntstatus_ok(tctx, 396 dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r), 397 "CreateGroup failed"); 398 if (!NT_STATUS_IS_OK(r.out.result)) { 399 torture_comment(tctx, "CreateGroup failed - %s\n", nt_errstr(r.out.result)); 400 401 if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_GROUP_EXISTS)) { 402 torture_comment(tctx, 403 "Group (%s) already exists - " 404 "attempting to delete and recreate group again\n", 405 group_name); 406 if (!test_group_cleanup(tctx, b, mem_ctx, handle, group_name)) { 256 407 return false; 257 408 } 258 409 259 printf("creating group account\n"); 260 261 status = dcerpc_samr_CreateDomainGroup(p, mem_ctx, &r); 262 if (!NT_STATUS_IS_OK(status)) { 263 printf("CreateGroup failed - %s\n", nt_errstr(status)); 264 return false; 265 } 410 torture_comment(tctx, "creating group account\n"); 411 412 torture_assert_ntstatus_ok(tctx, 413 dcerpc_samr_CreateDomainGroup_r(b, mem_ctx, &r), 414 "CreateGroup failed"); 415 torture_assert_ntstatus_ok(tctx, r.out.result, 416 "CreateGroup failed"); 417 418 /* be nice and close opened handles */ 419 test_samr_close_handle(tctx, b, mem_ctx, &group_handle); 420 266 421 return true; 267 422 } … … 269 424 } 270 425 271 return true; 426 /* be nice and close opened handles */ 427 test_samr_close_handle(tctx, b, mem_ctx, &group_handle); 428 429 return true; 430 } 431 432 /** 433 * Closes SAMR handle obtained from Connect, Open User/Domain, etc 434 */ 435 bool test_samr_close_handle(struct torture_context *tctx, 436 struct dcerpc_binding_handle *b, 437 TALLOC_CTX *mem_ctx, 438 struct policy_handle *samr_handle) 439 { 440 struct samr_Close r; 441 442 r.in.handle = samr_handle; 443 r.out.handle = samr_handle; 444 445 torture_assert_ntstatus_ok(tctx, 446 dcerpc_samr_Close_r(b, mem_ctx, &r), 447 "Close SAMR handle RPC call failed"); 448 torture_assert_ntstatus_ok(tctx, r.out.result, 449 "Close SAMR handle failed"); 450 451 return true; 452 } 453 454 /** 455 * Closes LSA handle obtained from Connect, Open Group, etc 456 */ 457 bool test_lsa_close_handle(struct torture_context *tctx, 458 struct dcerpc_binding_handle *b, 459 TALLOC_CTX *mem_ctx, 460 struct policy_handle *lsa_handle) 461 { 462 struct lsa_Close r; 463 464 r.in.handle = lsa_handle; 465 r.out.handle = lsa_handle; 466 467 torture_assert_ntstatus_ok(tctx, 468 dcerpc_lsa_Close_r(b, mem_ctx, &r), 469 "Close LSA handle RPC call failed"); 470 torture_assert_ntstatus_ok(tctx, r.out.result, 471 "Close LSA handle failed"); 472 473 return true; 474 } 475 476 /** 477 * Create and initialize libnet_context Context. 478 * Use this function in cases where we need to have SAMR and LSA pipes 479 * of libnet_context to be connected before executing any other 480 * libnet call 481 * 482 * @param rpc_connect [in] Connects SAMR and LSA pipes 483 */ 484 bool test_libnet_context_init(struct torture_context *tctx, 485 bool rpc_connect, 486 struct libnet_context **_net_ctx) 487 { 488 NTSTATUS status; 489 bool bret = true; 490 struct libnet_context *net_ctx; 491 492 net_ctx = libnet_context_init(tctx->ev, tctx->lp_ctx); 493 torture_assert(tctx, net_ctx != NULL, "Failed to create libnet_context"); 494 495 /* Use command line credentials for testing */ 496 net_ctx->cred = cmdline_credentials; 497 498 if (rpc_connect) { 499 /* connect SAMR pipe */ 500 status = torture_rpc_connection(tctx, 501 &net_ctx->samr.pipe, 502 &ndr_table_samr); 503 torture_assert_ntstatus_ok_goto(tctx, status, bret, done, 504 "Failed to connect SAMR pipe"); 505 506 net_ctx->samr.samr_handle = net_ctx->samr.pipe->binding_handle; 507 508 /* connect LSARPC pipe */ 509 status = torture_rpc_connection(tctx, 510 &net_ctx->lsa.pipe, 511 &ndr_table_lsarpc); 512 torture_assert_ntstatus_ok_goto(tctx, status, bret, done, 513 "Failed to connect LSA pipe"); 514 515 net_ctx->lsa.lsa_handle = net_ctx->lsa.pipe->binding_handle; 516 } 517 518 *_net_ctx = net_ctx; 519 520 done: 521 if (!bret) { 522 /* a previous call has failed, 523 * clean up memory before exit */ 524 talloc_free(net_ctx); 525 } 526 return bret; 272 527 } 273 528
Note:
See TracChangeset
for help on using the changeset viewer.