Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
1 deleted
17 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/torture/libnet/domain.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/rpc/rpc.h"
    23 #include "lib/events/events.h"
     22#include "torture/rpc/torture_rpc.h"
    2423#include "libnet/libnet.h"
    2524#include "librpc/gen_ndr/ndr_samr_c.h"
    2625#include "param/param.h"
    2726
    28 static bool test_domainopen(struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
     27static bool test_domainopen(struct torture_context *tctx,
     28                            struct libnet_context *net_ctx, TALLOC_CTX *mem_ctx,
    2929                            struct lsa_String *domname,
    3030                            struct policy_handle *domain_handle)
     
    3232        NTSTATUS status;
    3333        struct libnet_DomainOpen io;
    34        
    35         printf("opening domain\n");
    36        
     34
     35        torture_comment(tctx, "opening domain\n");
     36
    3737        io.in.domain_name  = talloc_strdup(mem_ctx, domname->string);
    3838        io.in.access_mask  = SEC_FLAG_MAXIMUM_ALLOWED;
     
    4040        status = libnet_DomainOpen(net_ctx, mem_ctx, &io);
    4141        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));
    4344                return false;
    4445        }
     
    4950
    5051
    51 static bool test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     52static bool test_cleanup(struct torture_context *tctx,
     53                         struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
    5254                         struct policy_handle *domain_handle)
    5355{
    54         NTSTATUS status;
    5556        struct samr_Close r;
    5657        struct policy_handle handle;
     
    5859        r.in.handle   = domain_handle;
    5960        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
    6970        return true;
    7071}
     
    8485        net_ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    8586
    86         status = torture_rpc_connection(torture, 
     87        status = torture_rpc_connection(torture,
    8788                                        &net_ctx->samr.pipe,
    8889                                        &ndr_table_samr);
    89        
     90
    9091        if (!NT_STATUS_IS_OK(status)) {
    9192                return false;
    9293        }
    9394
    94         name.string = lp_workgroup(torture->lp_ctx);
     95        name.string = lpcfg_workgroup(torture->lp_ctx);
    9596
    9697        /*
    9798         * Testing synchronous version
    9899         */
    99         if (!test_domainopen(net_ctx, mem_ctx, &name, &h)) {
     100        if (!test_domainopen(torture, net_ctx, mem_ctx, &name, &h)) {
    100101                ret = false;
    101102                goto done;
    102103        }
    103104
    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)) {
    105106                ret = false;
    106107                goto done;
  • trunk/server/source4/torture/libnet/groupinfo.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2007
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/rpc/rpc.h"
     22#include "torture/rpc/torture_rpc.h"
    2323#include "libnet/libnet.h"
    2424#include "libcli/security/security.h"
    2525#include "librpc/gen_ndr/ndr_samr_c.h"
    2626#include "param/param.h"
    27 #include "torture/libnet/utils.h"
     27#include "torture/libnet/proto.h"
    2828
    2929#define TEST_GROUPNAME  "libnetgroupinfotest"
    3030
    3131
    32 static bool test_groupinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     32static bool test_groupinfo(struct torture_context *tctx,
     33                           struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    3334                           struct policy_handle *domain_handle,
    3435                           struct dom_sid2 *domain_sid, const char* group_name,
     
    3940        struct libnet_rpc_groupinfo group;
    4041        struct dom_sid *group_sid;
    41        
     42
    4243        group_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
    43        
     44
    4445        group.in.domain_handle = *domain_handle;
    4546        group.in.sid           = dom_sid_string(mem_ctx, group_sid);
    4647        group.in.level         = level;       /* this should be extended */
    4748
    48         printf("Testing sync libnet_rpc_groupinfo (SID argument)\n");
     49        torture_comment(tctx, "Testing sync libnet_rpc_groupinfo (SID argument)\n");
    4950        status = libnet_rpc_groupinfo(p, mem_ctx, &group);
    5051        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));
    5253                return false;
    5354        }
     
    6364        status = libnet_rpc_groupinfo(p, mem_ctx, &group);
    6465        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));
    6667                return false;
    6768        }
     
    8182        struct dom_sid2 sid;
    8283        uint32_t rid;
     84        struct dcerpc_binding_handle *b;
    8385
    8486        mem_ctx = talloc_init("test_userinfo");
    8587
    86         status = torture_rpc_connection(torture, 
     88        status = torture_rpc_connection(torture,
    8789                                        &p,
    8890                                        &ndr_table_samr);
    89        
     91
    9092        if (!NT_STATUS_IS_OK(status)) {
    9193                return false;
    9294        }
     95        b = p->binding_handle;
    9396
    94         name.string = lp_workgroup(torture->lp_ctx);
     97        name.string = lpcfg_workgroup(torture->lp_ctx);
    9598
    9699        /*
    97100         * Testing synchronous version
    98101         */
    99         if (!test_opendomain(torture, p, mem_ctx, &h, &name, &sid)) {
     102        if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
    100103                ret = false;
    101104                goto done;
    102105        }
    103106
    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)) {
    105108                ret = false;
    106109                goto done;
    107110        }
    108111
    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)) {
    110113                ret = false;
    111114                goto done;
    112115        }
    113116
    114         if (!test_group_cleanup(p, mem_ctx, &h, TEST_GROUPNAME)) {
     117        if (!test_group_cleanup(torture, b, mem_ctx, &h, TEST_GROUPNAME)) {
    115118                ret = false;
    116119                goto done;
  • trunk/server/source4/torture/libnet/groupman.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2007
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/rpc/rpc.h"
     22#include "torture/rpc/torture_rpc.h"
    2323#include "torture/libnet/grouptest.h"
    2424#include "libnet/libnet.h"
    2525#include "librpc/gen_ndr/ndr_samr_c.h"
    2626#include "param/param.h"
    27 #include "torture/libnet/utils.h"
     27#include "torture/libnet/proto.h"
    2828
    2929
     
    3838        group.in.domain_handle = *domain_handle;
    3939        group.in.groupname     = name;
    40        
     40
    4141        printf("Testing libnet_rpc_groupadd\n");
    4242
     
    4646                return false;
    4747        }
    48        
     48
    4949        return ret;
    5050}
     
    6161        TALLOC_CTX *mem_ctx;
    6262        bool ret = true;
     63        struct dcerpc_binding_handle *b;
    6364
    6465        mem_ctx = talloc_init("test_groupadd");
    6566
    66         status = torture_rpc_connection(torture, 
     67        status = torture_rpc_connection(torture,
    6768                                        &p,
    6869                                        &ndr_table_samr);
    69        
     70
    7071        torture_assert_ntstatus_ok(torture, status, "RPC connection");
     72        b = p->binding_handle;
    7173
    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)) {
    7476                ret = false;
    7577                goto done;
     
    8183        }
    8284
    83         if (!test_group_cleanup(p, mem_ctx, &h, name)) {
     85        if (!test_group_cleanup(torture, b, mem_ctx, &h, name)) {
    8486                ret = false;
    8587                goto done;
    8688        }
    87        
     89
    8890done:
    8991        talloc_free(mem_ctx);
  • trunk/server/source4/torture/libnet/grouptest.h

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33
    44   Copyright (C) Rafal Szczesniak 2007
    5    
     5
    66   This program is free software; you can redistribute it and/or modify
    77   it under the terms of the GNU General Public License as published by
    88   the Free Software Foundation; either version 3 of the License, or
    99   (at your option) any later version.
    10    
     10
    1111   This program is distributed in the hope that it will be useful,
    1212   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1313   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1414   GNU General Public License for more details.
    15    
     15
    1616   You should have received a copy of the GNU General Public License
    1717   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  • trunk/server/source4/torture/libnet/libnet.c

    r414 r745  
    2121#include "torture/smbtorture.h"
    2222#include "librpc/rpc/dcerpc.h"
    23 #include "librpc/gen_ndr/security.h"
    2423#include "librpc/gen_ndr/lsa.h"
    25 #include "libnet/composite.h"
     24#include "libnet/libnet.h"
    2625#include "torture/libnet/proto.h"
    2726
    2827NTSTATUS torture_net_init(void)
    2928{
    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");
    3131
    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);
    6464
    6565        suite->description = talloc_strdup(suite, "libnet convenience interface tests");
  • trunk/server/source4/torture/libnet/libnet_BecomeDC.c

    r414 r745  
    2222#include "includes.h"
    2323#include "lib/cmdline/popt_common.h"
    24 #include "torture/torture.h"
    25 #include "torture/rpc/rpc.h"
     24#include "torture/rpc/torture_rpc.h"
    2625#include "libnet/libnet.h"
    27 #include "lib/events/events.h"
    2826#include "dsdb/samdb/samdb.h"
    2927#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"
    3328#include "librpc/gen_ndr/ndr_drsuapi.h"
    3429#include "librpc/gen_ndr/ndr_drsblobs.h"
    35 #include "librpc/gen_ndr/ndr_misc.h"
    3630#include "system/time.h"
    37 #include "lib/ldb_wrap.h"
     31#include "ldb_wrap.h"
    3832#include "auth/auth.h"
    3933#include "param/param.h"
    40 #include "torture/util.h"
    4134#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"
    56636
    56737bool torture_net_become_dc(struct torture_context *torture)
     
    57141        struct libnet_BecomeDC b;
    57242        struct libnet_UnbecomeDC u;
    573         struct test_become_dc_state *s;
     43        struct libnet_vampire_cb_state *s;
    57444        struct ldb_message *msg;
    57545        int ldb_ret;
    57646        uint32_t i;
    57747        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;
    57857
    57958        char *location = NULL;
     
    58160                                   "torture_temp_dir should return NT_STATUS_OK" );
    58261
    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";
    59265        }
    59366
    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
    59576
    59677        /* Join domain as a member server. */
    597         s->tj = torture_join_domain(torture, s->netbios_name,
     78        tj = torture_join_domain(torture, netbios_name,
    59879                                 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));
    60584
    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");
    60891
    609         s->ldb = ldb_init(s, torture->ev);
     92        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
     93        ctx->cred = cmdline_credentials;
    61094
    61195        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;
    617101
    618102        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;
    624108
    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);
    631114
    632115        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");
    644121
    645122        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");
    651125
    652126        for (i=0; i < msg->num_elements; i++) {
     
    654128        }
    655129
    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");
    663134       
     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
    664142        /* 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);
    667144
    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));
    679153
    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");
    686160
    687161        /* 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)) {
    689163                talloc_free(s);
    690164                return ret;
     
    693167cleanup:
    694168        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;
    699173
    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));
    705178
    706         /* Leave domain. */                         
    707         torture_leave_domain(torture, s->tj);
     179        /* Leave domain. */
     180        torture_leave_domain(torture, tj);
    708181
    709182        talloc_free(s);
  • trunk/server/source4/torture/libnet/libnet_domain.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2006
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2222#include "includes.h"
    2323#include "lib/cmdline/popt_common.h"
    24 #include "lib/events/events.h"
    25 #include "auth/credentials/credentials.h"
    2624#include "libnet/libnet.h"
    2725#include "librpc/gen_ndr/ndr_samr_c.h"
    2826#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"
    3328#include "param/param.h"
    3429
    3530
    36 static bool test_opendomain_samr(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     31static bool test_opendomain_samr(struct torture_context *tctx,
     32                                 struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
    3733                                 struct policy_handle *handle, struct lsa_String *domname,
    3834                                 uint32_t *access_mask, struct dom_sid **sid_p)
    3935{
    40         NTSTATUS status;
    4136        struct policy_handle h, domain_handle;
    4237        struct samr_Connect r1;
     
    4439        struct dom_sid2 *sid = NULL;
    4540        struct samr_OpenDomain r3;
    46        
    47         printf("connecting\n");
     41
     42        torture_comment(tctx, "connecting\n");
    4843
    4944        *access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    50        
     45
    5146        r1.in.system_name = 0;
    5247        r1.in.access_mask = *access_mask;
    5348        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
    6156        r2.in.connect_handle = &h;
    6257        r2.in.domain_name = domname;
    6358        r2.out.sid = &sid;
    6459
    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");
    7267
    7368        r3.in.connect_handle = &h;
     
    7671        r3.out.domain_handle = &domain_handle;
    7772
    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;
    8782
    8883        return true;
     
    9085
    9186
    92 static bool test_opendomain_lsa(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     87static bool test_opendomain_lsa(struct torture_context *tctx,
     88                                struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx,
    9389                                struct policy_handle *handle, struct lsa_String *domname,
    9490                                uint32_t *access_mask)
    9591{
    96         NTSTATUS status;
    9792        struct lsa_OpenPolicy2 open;
    9893        struct lsa_ObjectAttribute attr;
     
    108103        qos.context_mode        = 1;
    109104        qos.effective_only      = 0;
    110        
     105
    111106        attr.sec_qos = &qos;
    112107
     
    115110        open.in.access_mask = *access_mask;
    116111        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");
    122118
    123119        return true;
     
    137133           passed (it's going to be resolved to dc name and address) instead
    138134           of specific server name. */
    139         domain_name = lp_workgroup(torture->lp_ctx);
     135        domain_name = lpcfg_workgroup(torture->lp_ctx);
    140136
    141137        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    142138        if (ctx == NULL) {
    143                 d_printf("failed to create libnet context\n");
     139                torture_comment(torture, "failed to create libnet context\n");
    144140                return false;
    145141        }
     
    154150        status = libnet_DomainOpen(ctx, torture, &r);
    155151        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));
    157153                ret = false;
    158154                goto done;
     
    162158        lsa_close.in.handle  = &ctx->lsa.handle;
    163159        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");
    170166
    171167done:
     
    195191        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    196192        if (ctx == NULL) {
    197                 d_printf("failed to create libnet context\n");
     193                torture_comment(torture, "failed to create libnet context\n");
    198194                ret = false;
    199195                goto done;
     
    206202                                     cmdline_credentials, torture->ev, torture->lp_ctx);
    207203        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
    221217        ctx->lsa.pipe        = p;
    222218        ctx->lsa.name        = domain_name.string;
     
    230226        r.in.type = DOMAIN_LSA;
    231227        r.in.domain_name = domain_name.string;
    232        
     228
    233229        status = libnet_DomainClose(ctx, mem_ctx, &r);
    234230        if (!NT_STATUS_IS_OK(status)) {
     
    263259           passed (it's going to be resolved to dc name and address) instead
    264260           of specific server name. */
    265         domain_name = lp_workgroup(torture->lp_ctx);
     261        domain_name = lpcfg_workgroup(torture->lp_ctx);
    266262
    267263        /*
    268264         * Testing synchronous version
    269265         */
    270         printf("opening domain\n");
    271        
     266        torture_comment(torture, "opening domain\n");
     267
    272268        io.in.type         = DOMAIN_SAMR;
    273269        io.in.domain_name  = domain_name;
     
    276272        status = libnet_DomainOpen(ctx, mem_ctx, &io);
    277273        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));
    279276                ret = false;
    280277                goto done;
     
    285282        r.in.handle   = &domain_handle;
    286283        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");
    296292
    297293done:
     
    324320        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    325321        if (ctx == NULL) {
    326                 d_printf("failed to create libnet context\n");
     322                torture_comment(torture, "failed to create libnet context\n");
    327323                ret = false;
    328324                goto done;
     
    335331                                     ctx->cred, torture->ev, torture->lp_ctx);
    336332        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
    350346        ctx->samr.pipe        = p;
    351347        ctx->samr.name        = talloc_steal(ctx, domain_name.string);
     
    361357        r.in.type = DOMAIN_SAMR;
    362358        r.in.domain_name = domain_name.string;
    363        
     359
    364360        status = libnet_DomainClose(ctx, mem_ctx, &r);
    365361        if (!NT_STATUS_IS_OK(status)) {
     
    392388        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    393389        if (ctx == NULL) {
    394                 d_printf("failed to create libnet context\n");
     390                torture_comment(torture, "failed to create libnet context\n");
    395391                ret = false;
    396392                goto done;
     
    398394
    399395        ctx->cred = cmdline_credentials;
    400        
     396
    401397        mem_ctx = talloc_init("torture_domain_close_samr");
    402398
     
    414410        }
    415411
    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
    418414        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);
    420416        }
    421417
     
    435431        }
    436432
    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
    439435        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);
    441437        }
    442438
    443439done:
    444         d_printf("\nStatus: %s\n", nt_errstr(status));
     440        torture_comment(torture, "\nStatus: %s\n", nt_errstr(status));
    445441
    446442        talloc_free(mem_ctx);
  • trunk/server/source4/torture/libnet/libnet_group.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak  2007
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2525#include "librpc/gen_ndr/ndr_samr_c.h"
    2626#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"
    2929#include "param/param.h"
    3030
    3131
    3232#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 }
    22733
    22834
     
    23339        NTSTATUS status;
    23440        TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
    235         struct libnet_context *ctx;
     41        struct libnet_context *ctx = NULL;
    23642        struct dcerpc_pipe *p;
    23743        struct policy_handle h;
     
    24046
    24147        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;
    24548
    24649        status = torture_rpc_connection(torture,
     
    25154        }
    25255
    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)) {
    26063                ret = false;
    26164                goto done;
     
    26366
    26467        mem_ctx = talloc_init("torture group info");
     68
     69        if (!test_libnet_context_init(torture, true, &ctx)) {
     70                return false;
     71        }
    26572
    26673        ZERO_STRUCT(req);
     
    27279        status = libnet_GroupInfo(ctx, mem_ctx, &req);
    27380        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
     99done:
    290100        talloc_free(ctx);
    291 
    292 done:
    293101        talloc_free(mem_ctx);
    294102        return ret;
     
    309117        ctx->cred = cmdline_credentials;
    310118
    311         domain_name.string = lp_workgroup(torture->lp_ctx);
     119        domain_name.string = lpcfg_workgroup(torture->lp_ctx);
    312120        mem_ctx = talloc_init("torture group list");
    313121
    314122        ZERO_STRUCT(req);
    315123
    316         printf("listing group accounts:\n");
    317        
     124        torture_comment(torture, "listing group accounts:\n");
     125
    318126        do {
    319127                req.in.domain_name  = domain_name.string;
     
    326134
    327135                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);
    330138                }
    331139
     
    334142        if (!(NT_STATUS_IS_OK(status) ||
    335143              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");
    348158                ret = false;
    349159        }
     
    371181
    372182        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);
    374184        req.out.error_string = NULL;
    375185
    376186        status = libnet_CreateGroup(ctx, mem_ctx, &req);
    377187        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");
    391203                ret = false;
    392204        }
  • trunk/server/source4/torture/libnet/libnet_lookup.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2222#include "lib/cmdline/popt_common.h"
    2323#include "libnet/libnet.h"
    24 #include "librpc/gen_ndr/nbt.h"
    25 #include "librpc/rpc/dcerpc.h"
    2624#include "libcli/libcli.h"
    27 #include "torture/rpc/rpc.h"
    28 #include "torture/torture.h"
     25#include "torture/rpc/torture_rpc.h"
    2926#include "param/param.h"
    3027
     
    5956
    6057        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));
    6259                ret = false;
    6360                goto done;
     
    6663        ret = true;
    6764
    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);
    6966
    7067done:
     
    10299
    103100        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));
    105102                ret = false;
    106103                goto done;
     
    109106        ret = true;
    110107
    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);
    112109
    113110done:
     
    139136        }
    140137
    141         lookup->in.domain_name = lp_workgroup(torture->lp_ctx);
     138        lookup->in.domain_name = lpcfg_workgroup(torture->lp_ctx);
    142139        lookup->in.name_type   = NBT_NAME_PDC;
    143140
     
    145142
    146143        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,
    148145                       nt_errstr(status));
    149146                ret = false;
     
    153150        ret = true;
    154151
    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);
    156153        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,
    158155                       lookup->out.dcs[i].address);
    159156        }
     
    179176
    180177        r.in.name = "Administrator";
    181         r.in.domain_name = lp_workgroup(torture->lp_ctx);
     178        r.in.domain_name = lpcfg_workgroup(torture->lp_ctx);
    182179
    183180        status = libnet_LookupName(ctx, mem_ctx, &r);
  • trunk/server/source4/torture/libnet/libnet_rpc.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121#include "includes.h"
    2222#include "lib/cmdline/popt_common.h"
    23 #include "auth/credentials/credentials.h"
    2423#include "libnet/libnet.h"
    2524#include "libcli/security/security.h"
    26 #include "librpc/ndr/libndr.h"
    2725#include "librpc/gen_ndr/ndr_lsa.h"
    2826#include "librpc/gen_ndr/ndr_samr.h"
    2927#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"
    3329#include "param/param.h"
    3430
    3531
    36 static bool test_connect_service(struct libnet_context *ctx,
     32static bool test_connect_service(struct torture_context *tctx,
     33                                 struct libnet_context *ctx,
    3734                                 const struct ndr_interface_table *iface,
    3835                                 const char *binding_string,
     
    6057
    6158        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."
    6360                       "Received: %s\n",
    6461                       connect_r.in.dcerpc_iface->name, connect_r.in.binding, nt_errstr(expected_status),
     
    6865        }
    6966
    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),
    7168               nt_errstr(status));
    7269
    7370        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));
    7976
    8077        } 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);
    8279        }
    8380
     
    9491        ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    9592        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,
    9997                                  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,
    106104                                  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,
    113111                                  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,
    120118                                  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,
    127125                                  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");
    129127                return false;
    130128        }
     
    157155        struct dcerpc_binding *binding;
    158156        const char *domain_name;
    159        
     157
    160158        status = torture_rpc_binding(torture, &binding);
    161159        if (!NT_STATUS_IS_OK(status)) {
     
    166164           passed (it's going to be resolved to dc name and address) instead
    167165           of specific server name. */
    168         domain_name = lp_workgroup(torture->lp_ctx);
     166        domain_name = lpcfg_workgroup(torture->lp_ctx);
    169167        return torture_rpc_connect(torture, level, NULL, domain_name);
    170168}
     
    177175        struct dcerpc_binding *binding;
    178176        const char *domain_name;
    179        
     177
    180178        status = torture_rpc_binding(torture, &binding);
    181179        if (!NT_STATUS_IS_OK(status)) {
     
    186184           passed (it's going to be resolved to dc name and address) instead
    187185           of specific server name. */
    188         domain_name = lp_workgroup(torture->lp_ctx);
     186        domain_name = lpcfg_workgroup(torture->lp_ctx);
    189187        return torture_rpc_connect(torture, level, NULL, domain_name);
    190188}
     
    197195        struct dcerpc_binding *binding;
    198196        const char *domain_name;
    199        
     197
    200198        status = torture_rpc_binding(torture, &binding);
    201199        if (!NT_STATUS_IS_OK(status)) {
     
    206204           passed (it's going to be resolved to dc name and address) instead
    207205           of specific server name. */
    208         domain_name = lp_workgroup(torture->lp_ctx);
     206        domain_name = lpcfg_workgroup(torture->lp_ctx);
    209207        return torture_rpc_connect(torture, level, NULL, domain_name);
    210208}
     
    217215        struct dcerpc_binding *binding;
    218216        const char *bindstr;
    219        
     217
    220218        status = torture_rpc_binding(torture, &binding);
    221219        if (!NT_STATUS_IS_OK(status)) {
  • trunk/server/source4/torture/libnet/libnet_share.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
     
    55   Copyright (C) Gregory LEOCADIE <gleocadie@idealx.com> 2005
    66   Copyright (C) Rafal Szczesniak  2005
    7    
     7
    88   This program is free software; you can redistribute it and/or modify
    99   it under the terms of the GNU General Public License as published by
    1010   the Free Software Foundation; either version 3 of the License, or
    1111   (at your option) any later version.
    12    
     12
    1313   This program is distributed in the hope that it will be useful,
    1414   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1515   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1616   GNU General Public License for more details.
    17    
     17
    1818   You should have received a copy of the GNU General Public License
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2121
    2222#include "includes.h"
    23 #include "torture/rpc/rpc.h"
     23#include "torture/rpc/torture_rpc.h"
    2424#include "libnet/libnet.h"
    2525#include "lib/cmdline/popt_common.h"
     
    3030
    3131
    32 static void test_displayshares(struct libnet_ListShares s)
     32static void test_displayshares(struct torture_context *tctx,
     33                               struct libnet_ListShares s)
    3334{
    3435        int i, j;
     
    5657                for (i = 0; i < s.out.ctr.ctr0->count; i++) {
    5758                        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);
    5960                }
    6061                break;
     
    6667                                if (share_types[j].type == info->type) break;
    6768                        }
    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,
    6970                               info->comment, share_types[j].desc);
    7071                }
     
    7778                                if (share_types[j].type == info->type) break;
    7879                        }
    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",
    8081                                 i, info->name, share_types[j].desc, info->comment,
    8182                                 info->permissions, info->max_users,
     
    9192                                if (share_types[j].type == info->type) break;
    9293                        }
    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,
    9495                                 share_types[j].desc, info->csc_policy,
    9596                                 info->comment);
     
    103104                                if (share_types[j].type == info->type) break;
    104105                        }
    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",
    106107                                 i, info->name, share_types[j].desc, info->comment,
    107108                                 info->permissions, info->max_users,
     
    134135        libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
    135136        if (!libnetctx) {
    136                 printf("Couldn't allocate libnet context\n");
     137                torture_comment(torture, "Couldn't allocate libnet context\n");
    137138                ret = false;
    138139                goto done;
     
    140141
    141142        libnetctx->cred = cmdline_credentials;
    142        
    143         printf("Testing libnet_ListShare\n");
    144        
     143
     144        torture_comment(torture, "Testing libnet_ListShare\n");
     145
    145146        share.in.server_name = talloc_asprintf(mem_ctx, "%s", binding->host);
    146147
    147148        for (i = 0; i < ARRAY_SIZE(levels); i++) {
    148149                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);
    150151
    151152                status = libnet_ListShares(libnetctx, mem_ctx, &share);
    152153                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);
    154155                        ret = false;
    155156                        goto done;
    156157                }
    157158
    158                 printf("listing shares:\n");
    159                 test_displayshares(share);
     159                torture_comment(torture, "listing shares:\n");
     160                test_displayshares(torture, share);
    160161        }
    161162
     
    166167
    167168
    168 static bool test_addshare(struct dcerpc_pipe *svc_pipe, TALLOC_CTX *mem_ctx, const char *host,
     169static bool test_addshare(struct torture_context *tctx,
     170                          struct dcerpc_binding_handle *b, TALLOC_CTX *mem_ctx, const char *host,
    169171                          const char* share)
    170172{
     
    173175        union srvsvc_NetShareInfo info;
    174176        struct srvsvc_NetShareInfo2 i;
    175        
     177
    176178        i.name         = share;
    177179        i.type         = STYPE_DISKTREE;
     
    189191        add.in.parm_error = NULL;
    190192
    191         status = dcerpc_srvsvc_NetShareAdd(svc_pipe, mem_ctx, &add);
     193        status = dcerpc_srvsvc_NetShareAdd_r(b, mem_ctx, &add);
    192194        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");
    194196                return false;
    195197        }
    196198
    197         printf("share added\n");
     199        torture_comment(tctx, "share added\n");
    198200        return true;
    199201}
     
    209211        bool ret = true;
    210212        struct libnet_DelShare share;
    211        
     213
    212214        host = torture_setting_string(torture, "host", NULL);
    213215        status = torture_rpc_binding(torture, &binding);
     
    223225        torture_assert_ntstatus_ok(torture, status, "Failed to get rpc connection");
    224226
    225         if (!test_addshare(p, torture, host, TEST_SHARENAME)) {
     227        if (!test_addshare(torture, p->binding_handle, torture, host, TEST_SHARENAME)) {
    226228                return false;
    227229        }
  • trunk/server/source4/torture/libnet/libnet_user.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2525#include "librpc/gen_ndr/ndr_samr_c.h"
    2626#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"
    2928#include "torture/libnet/usertest.h"
     29#include "torture/libnet/proto.h"
    3030#include "param/param.h"
    3131
    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 }
    23732
    23833
     
    24136        NTSTATUS status;
    24237        TALLOC_CTX *mem_ctx;
    243         struct libnet_context *ctx;
     38        struct libnet_context *ctx = NULL;
    24439        struct libnet_CreateUser req;
    24540        bool ret = true;
     
    24742        mem_ctx = talloc_init("test_createuser");
    24843
    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        }
    25147
    25248        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);
    25450        req.out.error_string = NULL;
    25551
    25652        status = libnet_CreateUser(ctx, mem_ctx, &req);
    25753        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");
    27169                ret = false;
    27270        }
     
    28381        NTSTATUS status;
    28482        struct dcerpc_pipe *p;
    285         TALLOC_CTX *prep_mem_ctx, *mem_ctx;
     83        TALLOC_CTX *mem_ctx;
    28684        struct policy_handle h;
    28785        struct lsa_String domain_name;
    28886        const char *name = TEST_USERNAME;
    289         struct libnet_context *ctx;
     87        struct libnet_context *ctx = NULL;
    29088        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;
    30090
    30191        status = torture_rpc_connection(torture,
    30292                                        &p,
    30393                                        &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);
    321116
    322117        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;
    329122
    330123done:
    331124        talloc_free(ctx);
    332         talloc_free(prep_mem_ctx);
     125        talloc_free(mem_ctx);
    333126        return ret;
    334127}
     
    339132*/
    340133
    341 static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r,
     134static void set_test_changes(struct torture_context *tctx,
     135                             TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r,
    342136                             int num_changes, char **user_name, enum test_fields req_change)
    343137{
     
    352146        int i, testfld;
    353147
    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++) {
    357151                const char *fldname;
    358152
    359                 testfld = (req_change == none) ? (random() % FIELDS_NUM) : req_change;
     153                testfld = (req_change == none) ? (random() % USER_FIELD_LAST) + 1 : req_change;
    360154
    361155                /* get one in case we hit time field this time */
    362156                gettimeofday(&now, NULL);
    363                
     157
    364158                switch (testfld) {
    365                 case account_name:
     159                case acct_name:
    366160                        continue_if_field_set(r->in.account_name);
    367161                        r->in.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
    368162                                                             (int)(random() % 100));
    369163                        fldname = "account_name";
    370                        
     164
    371165                        /* update the test's user name in case it's about to change */
    372166                        *user_name = talloc_strdup(mem_ctx, r->in.account_name);
    373167                        break;
    374168
    375                 case full_name:
     169                case acct_full_name:
    376170                        continue_if_field_set(r->in.full_name);
    377171                        r->in.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
     
    380174                        break;
    381175
    382                 case description:
     176                case acct_description:
    383177                        continue_if_field_set(r->in.description);
    384178                        r->in.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
     
    387181                        break;
    388182
    389                 case home_directory:
     183                case acct_home_directory:
    390184                        continue_if_field_set(r->in.home_directory);
    391185                        homedir = home_dirs[random() % ARRAY_SIZE(home_dirs)];
     
    394188                        break;
    395189
    396                 case home_drive:
     190                case acct_home_drive:
    397191                        continue_if_field_set(r->in.home_drive);
    398192                        homedrive = home_drives[random() % ARRAY_SIZE(home_drives)];
     
    401195                        break;
    402196
    403                 case comment:
     197                case acct_comment:
    404198                        continue_if_field_set(r->in.comment);
    405199                        r->in.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
     
    408202                        break;
    409203
    410                 case logon_script:
     204                case acct_logon_script:
    411205                        continue_if_field_set(r->in.logon_script);
    412206                        logonscript = logon_scripts[random() % ARRAY_SIZE(logon_scripts)];
     
    414208                        fldname = "logon_script";
    415209                        break;
    416                        
    417                 case profile_path:
     210
     211                case acct_profile_path:
    418212                        continue_if_field_set(r->in.profile_path);
    419213                        r->in.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
     
    438232                        fldname = "unknown_field";
    439233                }
    440                
    441                 printf(((i < num_changes - 1) ? "%s," : "%s"), fldname);
     234
     235                torture_comment(tctx, ((i < num_changes - 1) ? "%s," : "%s"), fldname);
    442236
    443237                /* disable requested field (it's supposed to be the only one used) */
     
    445239        }
    446240
    447         printf("]\n");
     241        torture_comment(tctx, "]\n");
    448242}
    449243
     
    451245#define TEST_STR_FLD(fld) \
    452246        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); \
    454248                ret = false; \
    455249                goto cleanup; \
     
    458252#define TEST_TIME_FLD(fld) \
    459253        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); \
    461255                ret = false; \
    462256                goto cleanup; \
     
    465259#define TEST_NUM_FLD(fld) \
    466260        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); \
    468262                ret = false; \
    469263                goto cleanup; \
     
    474268{
    475269        NTSTATUS status;
    476         struct dcerpc_binding *binding;
    477270        struct dcerpc_pipe *p;
    478271        TALLOC_CTX *prep_mem_ctx;
     
    480273        struct lsa_String domain_name;
    481274        char *name;
    482         struct libnet_context *ctx;
     275        struct libnet_context *ctx = NULL;
    483276        struct libnet_ModifyUser req;
    484277        struct libnet_UserInfo user_req;
    485278        int fld;
    486279        bool ret = true;
     280        struct dcerpc_binding_handle *b;
    487281
    488282        prep_mem_ctx = talloc_init("prepare test_deleteuser");
    489 
    490         ctx = libnet_context_init(torture->ev, torture->lp_ctx);
    491         ctx->cred = cmdline_credentials;
    492283
    493284        status = torture_rpc_connection(torture,
     
    498289                goto done;
    499290        }
     291        b = p->binding_handle;
    500292
    501293        name = talloc_strdup(prep_mem_ctx, TEST_USERNAME);
    502294
    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++) {
    523313                ZERO_STRUCT(req);
    524                 req.in.domain_name = lp_workgroup(torture->lp_ctx);
     314                req.in.domain_name = lpcfg_workgroup(torture->lp_ctx);
    525315                req.in.user_name = name;
    526316
    527                 set_test_changes(torture, &req, 1, &name, fld);
     317                set_test_changes(torture, torture, &req, 1, &name, fld);
    528318
    529319                status = libnet_ModifyUser(ctx, torture, &req);
    530320                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));
    532322                        ret = false;
    533323                        continue;
     
    535325
    536326                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);
    538328                user_req.in.data.user_name = name;
    539329                user_req.in.level = USER_INFO_BY_NAME;
     
    541331                status = libnet_UserInfo(ctx, torture, &user_req);
    542332                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));
    544334                        ret = false;
    545335                        continue;
     
    547337
    548338                switch (fld) {
    549                 case account_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);
    564354                        break;
    565355                case acct_expiry: TEST_TIME_FLD(acct_expiry);
     
    570360                        break;
    571361                }
    572 
    573                 if (fld == account_name) {
    574                         /* restore original testing username - it's useful when test fails
    575                            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                 }
    590362        }
    591363
    592364cleanup:
    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");
    601375                ret = false;
    602376        }
     
    615389        NTSTATUS status;
    616390        TALLOC_CTX *mem_ctx = NULL, *prep_mem_ctx;
    617         struct libnet_context *ctx;
     391        struct libnet_context *ctx = NULL;
    618392        struct dcerpc_pipe *p;
    619393        struct policy_handle h;
    620394        struct lsa_String domain_name;
    621395        struct libnet_UserInfo req;
     396        struct dcerpc_binding_handle *b;
    622397
    623398        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;
    627399
    628400        status = torture_rpc_connection(torture,
     
    632404                return false;
    633405        }
    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)) {
    642415                ret = false;
    643416                goto done;
     
    646419        mem_ctx = talloc_init("torture user info");
    647420
     421        if (!test_libnet_context_init(torture, true, &ctx)) {
     422                return false;
     423        }
     424
    648425        ZERO_STRUCT(req);
    649        
     426
    650427        req.in.domain_name = domain_name.string;
    651428        req.in.data.user_name   = name;
     
    654431        status = libnet_UserInfo(ctx, mem_ctx, &req);
    655432        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
     451done:
    673452        talloc_free(ctx);
    674 
    675 done:
    676453        talloc_free(mem_ctx);
    677454        return ret;
     
    692469        ctx->cred = cmdline_credentials;
    693470
    694         domain_name.string = lp_workgroup(torture->lp_ctx);
     471        domain_name.string = lpcfg_workgroup(torture->lp_ctx);
    695472        mem_ctx = talloc_init("torture user list");
    696473
    697474        ZERO_STRUCT(req);
    698475
    699         printf("listing user accounts:\n");
    700        
     476        torture_comment(torture, "listing user accounts:\n");
     477
    701478        do {
    702479
     
    710487
    711488                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);
    714491                }
    715492
     
    718495        if (!(NT_STATUS_IS_OK(status) ||
    719496              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");
    733512                ret = false;
    734513        }
  • trunk/server/source4/torture/libnet/userinfo.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/rpc/rpc.h"
     22#include "torture/rpc/torture_rpc.h"
    2323#include "libnet/libnet.h"
    2424#include "libcli/security/security.h"
    2525#include "librpc/gen_ndr/ndr_samr_c.h"
    2626#include "param/param.h"
    27 #include "torture/libnet/utils.h"
     27#include "torture/libnet/proto.h"
    2828
    2929
    3030#define TEST_USERNAME  "libnetuserinfotest"
    3131
    32 static bool test_userinfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     32static bool test_userinfo(struct torture_context *tctx,
     33                          struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    3334                          struct policy_handle *domain_handle,
    3435                          struct dom_sid2 *domain_sid, const char* user_name,
     
    3940        struct libnet_rpc_userinfo user;
    4041        struct dom_sid *user_sid;
    41        
     42
    4243        user_sid = dom_sid_add_rid(mem_ctx, domain_sid, *rid);
    43        
     44
    4445        user.in.domain_handle = *domain_handle;
    4546        user.in.sid           = dom_sid_string(mem_ctx, user_sid);
    4647        user.in.level         = level;       /* this should be extended */
    4748
    48         printf("Testing sync libnet_rpc_userinfo (SID argument)\n");
     49        torture_comment(tctx, "Testing sync libnet_rpc_userinfo (SID argument)\n");
    4950        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");
    5452
    5553        ZERO_STRUCT(user);
     
    5755        user.in.domain_handle = *domain_handle;
    5856        user.in.sid           = NULL;
    59         user.in.username      = TEST_USERNAME;
     57        user.in.username      = user_name;
    6058        user.in.level         = level;
    6159
    62         printf("Testing sync libnet_rpc_userinfo (username argument)\n");
     60        torture_comment(tctx, "Testing sync libnet_rpc_userinfo (username argument)\n");
    6361        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");
    6863
    6964        return true;
     
    7166
    7267
    73 static bool test_userinfo_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     68static bool test_userinfo_async(struct torture_context *tctx,
     69                                struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    7470                                struct policy_handle *domain_handle,
    7571                                struct dom_sid2 *domain_sid, const char* user_name,
     
    8884        user.in.level         = level;       /* this should be extended */
    8985
    90         printf("Testing async libnet_rpc_userinfo (SID argument)\n");
     86        torture_comment(tctx, "Testing async libnet_rpc_userinfo (SID argument)\n");
    9187
    9288        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");
    9790
    9891        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");
    10393
    10494        ZERO_STRUCT(user);
     
    10696        user.in.domain_handle = *domain_handle;
    10797        user.in.sid           = NULL;
    108         user.in.username      = TEST_USERNAME;
     98        user.in.username      = user_name;
    10999        user.in.level         = level;
    110100
    111         printf("Testing async libnet_rpc_userinfo (username argument)\n");
     101        torture_comment(tctx, "Testing async libnet_rpc_userinfo (username argument)\n");
    112102
    113103        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");
    118105
    119106        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");
    124108
    125109        return true;
     
    137121        struct dom_sid2 sid;
    138122        uint32_t rid;
     123        struct dcerpc_binding_handle *b;
    139124
    140125        mem_ctx = talloc_init("test_userinfo");
    141126
    142         status = torture_rpc_connection(torture, 
     127        status = torture_rpc_connection(torture,
    143128                                        &p,
    144129                                        &ndr_table_samr);
    145        
     130
    146131        if (!NT_STATUS_IS_OK(status)) {
    147132                return false;
    148133        }
     134        b = p->binding_handle;
    149135
    150         name.string = lp_workgroup(torture->lp_ctx);
     136        name.string = lpcfg_workgroup(torture->lp_ctx);
    151137
    152138        /*
    153139         * Testing synchronous version
    154140         */
    155         if (!test_opendomain(torture, p, mem_ctx, &h, &name, &sid)) {
     141        if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
    156142                ret = false;
    157143                goto done;
    158144        }
    159145
    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)) {
    161147                ret = false;
    162148                goto done;
    163149        }
    164150
    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)) {
    166152                ret = false;
    167153                goto done;
    168154        }
    169155
    170         if (!test_user_cleanup(torture, p, mem_ctx, &h, TEST_USERNAME)) {
     156        if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
    171157                ret = false;
    172158                goto done;
     
    176162         * Testing asynchronous version and monitor messages
    177163         */
    178         if (!test_opendomain(torture, p, mem_ctx, &h, &name, &sid)) {
     164        if (!test_domain_open(torture, b, &name, mem_ctx, &h, &sid)) {
    179165                ret = false;
    180166                goto done;
    181167        }
    182168
    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)) {
    184170                ret = false;
    185171                goto done;
    186172        }
    187173
    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)) {
    189175                ret = false;
    190176                goto done;
    191177        }
    192178
    193         if (!test_user_cleanup(torture, p, mem_ctx, &h, TEST_USERNAME)) {
     179        if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
    194180                ret = false;
    195181                goto done;
  • trunk/server/source4/torture/libnet/userman.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2005
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2020
    2121#include "includes.h"
    22 #include "torture/rpc/rpc.h"
     22#include "torture/rpc/torture_rpc.h"
    2323#include "torture/libnet/usertest.h"
    2424#include "libnet/libnet.h"
     
    2626#include "param/param.h"
    2727
    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
     31static bool test_useradd(struct torture_context *tctx,
     32                         struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    3233                         struct policy_handle *domain_handle,
    3334                         const char *name)
     
    3637        bool ret = true;
    3738        struct libnet_rpc_useradd user;
    38        
     39
    3940        user.in.domain_handle = *domain_handle;
    4041        user.in.username      = name;
    4142
    42         printf("Testing libnet_rpc_useradd\n");
     43        torture_comment(tctx, "Testing libnet_rpc_useradd\n");
    4344
    4445        status = libnet_rpc_useradd(p, mem_ctx, &user);
    4546        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));
    4748                return false;
    4849        }
    49        
     50
    5051        return ret;
    5152}
    5253
    5354
    54 static bool test_useradd_async(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     55static bool test_useradd_async(struct torture_context *tctx,
     56                               struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    5557                               struct policy_handle *handle, const char* username)
    5658{
     
    6163        user.in.domain_handle = *handle;
    6264        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
    6668        c = libnet_rpc_useradd_send(p, &user, msg_handler);
    6769        if (!c) {
    68                 printf("Failed to call async libnet_rpc_useradd\n");
     70                torture_comment(tctx, "Failed to call async libnet_rpc_useradd\n");
    6971                return false;
    7072        }
     
    7274        status = libnet_rpc_useradd_recv(c, mem_ctx, &user);
    7375        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));
    7577                return false;
    7678        }
     
    8082}
    8183
    82 static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p, 
     84static bool test_usermod(struct torture_context *tctx, struct dcerpc_pipe *p,
    8385                         TALLOC_CTX *mem_ctx,
    8486                         struct policy_handle *handle, int num_changes,
     
    104106        mod->in.domain_handle = *handle;
    105107
    106         torture_comment(tctx, "modifying user (%d simultaneous change(s))\n", 
     108        torture_comment(tctx, "modifying user (%d simultaneous change(s))\n",
    107109                        num_changes);
    108110
    109111        torture_comment(tctx, "fields to change: [");
    110112
    111         for (i = 0; i < num_changes && i < FIELDS_NUM - 1; i++) {
     113        for (i = 0; i < num_changes && i <= USER_FIELD_LAST; i++) {
    112114                const char *fldname;
    113115
    114                 testfld = (random() % (FIELDS_NUM - 1)) + 1;
    115 
    116                 gettimeofday(&now, NULL);
     116                testfld = (random() % USER_FIELD_LAST) + 1;
     117
     118                GetTimeOfDay(&now);
    117119
    118120                switch (testfld) {
    119                 case account_name:
     121                case acct_name:
    120122                        continue_if_field_set(mod->in.change.account_name);
    121123                        mod->in.change.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
     
    126128                        break;
    127129
    128                 case full_name:
     130                case acct_full_name:
    129131                        continue_if_field_set(mod->in.change.full_name);
    130132                        mod->in.change.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
     
    134136                        break;
    135137
    136                 case description:
     138                case acct_description:
    137139                        continue_if_field_set(mod->in.change.description);
    138140                        mod->in.change.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
     
    141143                        fldname = "description";
    142144                        break;
    143                        
    144                 case home_directory:
     145
     146                case acct_home_directory:
    145147                        continue_if_field_set(mod->in.change.home_directory);
    146148                        homedir = home_dirs[random() % (sizeof(home_dirs)/sizeof(char*))];
     
    150152                        break;
    151153
    152                 case home_drive:
     154                case acct_home_drive:
    153155                        continue_if_field_set(mod->in.change.home_drive);
    154156                        homedrive = home_drives[random() % (sizeof(home_drives)/sizeof(char*))];
     
    158160                        break;
    159161
    160                 case comment:
     162                case acct_comment:
    161163                        continue_if_field_set(mod->in.change.comment);
    162164                        mod->in.change.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
     
    166168                        break;
    167169
    168                 case logon_script:
     170                case acct_logon_script:
    169171                        continue_if_field_set(mod->in.change.logon_script);
    170172                        logonscript = logon_scripts[random() % (sizeof(logon_scripts)/sizeof(char*))];
     
    174176                        break;
    175177
    176                 case profile_path:
     178                case acct_profile_path:
    177179                        continue_if_field_set(mod->in.change.profile_path);
    178180                        mod->in.change.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
     
    213215
    214216
    215 static bool test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
     217static bool test_userdel(struct torture_context *tctx,
     218                         struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    216219                         struct policy_handle *handle, const char *username)
    217220{
    218221        NTSTATUS status;
    219222        struct libnet_rpc_userdel user;
    220        
     223
    221224        user.in.domain_handle = *handle;
    222225        user.in.username = username;
    223        
     226
    224227        status = libnet_rpc_userdel(p, mem_ctx, &user);
    225228        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));
    227230                return false;
    228231        }
     
    235238        if ((mod->in.change.fields & flags) && \
    236239            !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); \
    240243                return false; \
    241244        }
     
    246249                nttime_to_timeval(&t, i->fld); \
    247250                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", \
    250253                               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", \
    252255                               timestring(mem_ctx, mod->in.change.fld->tv_sec), \
    253256                               mod->in.change.fld->tv_usec); \
     
    259262        if ((mod->in.change.fields & flags) && \
    260263            (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); \
    264267                return false; \
    265268        }
    266269
    267270
    268 static bool test_compare(struct torture_context *tctx, 
     271static bool test_compare(struct torture_context *tctx,
    269272                         struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
    270273                         struct policy_handle *handle, struct libnet_rpc_usermod *mod,
     
    312315        TALLOC_CTX *mem_ctx;
    313316        bool ret = true;
     317        struct dcerpc_binding_handle *b;
    314318
    315319        mem_ctx = talloc_init("test_useradd");
    316320
    317         status = torture_rpc_connection(torture, 
     321        status = torture_rpc_connection(torture,
    318322                                        &p,
    319323                                        &ndr_table_samr);
    320        
     324
    321325        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)) {
    350355                ret = false;
    351356                goto done;
     
    369374        TALLOC_CTX *mem_ctx;
    370375        bool ret = true;
     376        struct dcerpc_binding_handle *b;
    371377
    372378        mem_ctx = talloc_init("test_userdel");
    373379
    374         status = torture_rpc_connection(torture, 
     380        status = torture_rpc_connection(torture,
    375381                                        &p,
    376382                                        &ndr_table_samr);
    377        
     383
    378384        if (!NT_STATUS_IS_OK(status)) {
    379385                return false;
    380386        }
    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
    398405done:
    399406        talloc_free(mem_ctx);
     
    414421        TALLOC_CTX *mem_ctx;
    415422        bool ret = true;
     423        struct dcerpc_binding_handle *b;
    416424
    417425        mem_ctx = talloc_init("test_userdel");
    418426
    419         status = torture_rpc_connection(torture, 
     427        status = torture_rpc_connection(torture,
    420428                                        &p,
    421429                                        &ndr_table_samr);
    422        
     430
    423431        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);
    426435        name = talloc_strdup(mem_ctx, TEST_USERNAME);
    427436
    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++) {
    439448                struct libnet_rpc_usermod m;
    440449
     
    449458                }
    450459        }
    451        
    452 cleanup:       
    453         if (!test_user_cleanup(torture, p, mem_ctx, &h, name)) {
     460
     461cleanup:
     462        if (!test_user_cleanup(torture, b, mem_ctx, &h, TEST_USERNAME)) {
    454463                ret = false;
    455464                goto done;
  • trunk/server/source4/torture/libnet/usertest.h

    r414 r745  
    2727
    2828
    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
     32enum 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 };
    3236
    3337
  • trunk/server/source4/torture/libnet/utils.c

    r414 r745  
    1 /* 
     1/*
    22   Unix SMB/CIFS implementation.
    33   Test suite for libnet calls.
    44
    55   Copyright (C) Rafal Szczesniak 2007
    6    
     6
    77   This program is free software; you can redistribute it and/or modify
    88   it under the terms of the GNU General Public License as published by
    99   the Free Software Foundation; either version 3 of the License, or
    1010   (at your option) any later version.
    11    
     11
    1212   This program is distributed in the hope that it will be useful,
    1313   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1414   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1515   GNU General Public License for more details.
    16    
     16
    1717   You should have received a copy of the GNU General Public License
    1818   along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    2424
    2525#include "includes.h"
    26 #include "torture/rpc/rpc.h"
     26#include "lib/cmdline/popt_common.h"
     27#include "torture/rpc/torture_rpc.h"
    2728#include "libnet/libnet.h"
    2829#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 */
     40bool 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;
    3949        struct samr_Connect r1;
    4050        struct samr_LookupDomain r2;
    4151        struct dom_sid2 *sid = NULL;
    4252        struct samr_OpenDomain r3;
    43        
     53
    4454        torture_comment(tctx, "connecting\n");
    45        
     55
    4656        r1.in.system_name = 0;
    4757        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;
    5467        r2.in.domain_name = domname;
    5568        r2.out.sid = &sid;
     
    5770        torture_comment(tctx, "domain lookup on %s\n", domname->string);
    5871
    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;
    6379        r3.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
    6480        r3.in.sid = *r2.out.sid;
    6581        r3.out.domain_handle = &domain_handle;
    6682
    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 */
     109static 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
     156done:
     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 */
     167bool 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{
    83173        struct samr_LookupNames r1;
    84174        struct samr_OpenUser r2;
     
    88178        struct policy_handle user_handle;
    89179        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;
    92189
    93190        r1.in.domain_handle  = domain_handle;
     
    96193        r1.out.rids          = &rids;
    97194        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");
    103203
    104204        rid = r1.out.rids->ids[0];
    105        
     205
    106206        r2.in.domain_handle  = domain_handle;
    107207        r2.in.access_mask    = SEC_FLAG_MAXIMUM_ALLOWED;
     
    111211        torture_comment(tctx, "opening user account\n");
    112212
    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");
    115218
    116219        r3.in.user_handle  = &user_handle;
     
    118221
    119222        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 */
     240bool 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,
    131245                      uint32_t *rid)
    132246{
    133         NTSTATUS status;
     247        struct policy_handle user_handle;
    134248        struct lsa_String username;
    135249        struct samr_CreateUser r;
    136         struct policy_handle user_handle;
    137        
     250        uint32_t user_rid;
     251
    138252        username.string = name;
    139        
    140         r.in.domain_handle = handle;
     253
     254        r.in.domain_handle = domain_handle;
    141255        r.in.account_name  = &username;
    142256        r.in.access_mask   = SEC_FLAG_MAXIMUM_ALLOWED;
    143257        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)) {
    155275                                return false;
    156276                        }
    157277
    158278                        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
    162289                        return true;
    163290                }
     
    165292        }
    166293
    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 */
     304bool test_group_cleanup(struct torture_context *tctx,
     305                        struct dcerpc_binding_handle *b,
     306                        TALLOC_CTX *mem_ctx,
    172307                        struct policy_handle *domain_handle,
    173308                        const char *name)
    174309{
    175         NTSTATUS status;
    176310        struct samr_LookupNames r1;
    177311        struct samr_OpenGroup r2;
     
    189323        r1.out.rids          = &rids;
    190324        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");
    199333
    200334        rid = r1.out.rids->ids[0];
    201        
     335
    202336        r2.in.domain_handle  = domain_handle;
    203337        r2.in.access_mask    = SEC_FLAG_MAXIMUM_ALLOWED;
     
    205339        r2.out.group_handle  = &group_handle;
    206340
    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");
    214348
    215349        r3.in.group_handle  = &group_handle;
    216350        r3.out.group_handle = &group_handle;
    217351
    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 */
     371bool 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,
    232376                       uint32_t *rid)
    233377{
    234         NTSTATUS status;
     378        uint32_t group_rid;
    235379        struct lsa_String groupname;
    236380        struct samr_CreateDomainGroup r;
    237381        struct policy_handle group_handle;
    238        
    239         groupname.string = name;
    240        
     382
     383        groupname.string = group_name;
     384
    241385        r.in.domain_handle  = handle;
    242386        r.in.name           = &groupname;
    243387        r.in.access_mask    = SEC_FLAG_MAXIMUM_ALLOWED;
    244388        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)) {
    256407                                return false;
    257408                        }
    258409
    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
    266421                        return true;
    267422                }
     
    269424        }
    270425
    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 */
     435bool 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 */
     457bool 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 */
     484bool 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
     520done:
     521        if (!bret) {
     522                /* a previous call has failed,
     523                 * clean up memory before exit */
     524                talloc_free(net_ctx);
     525        }
     526        return bret;
    272527}
    273528
Note: See TracChangeset for help on using the changeset viewer.