s4-smbtorture: Make it simpler to specify number of trusted domains to create in
[ira/wip.git] / source4 / torture / rpc / lsa.c
index dbea8b1768cb4345dfe68149ba011840dfc6fbb7..e4a6a8422c9f4f55e7473e63824d5807dc62b7e3 100644 (file)
@@ -202,12 +202,22 @@ static bool test_LookupNames(struct dcerpc_pipe *p,
        }
 
        for (i=0;i< tnames->count;i++) {
-               if (i < count && sids.sids[i].sid_type != tnames->names[i].sid_type) {
-                       torture_comment(tctx, "LookupName of %s got unexpected name type: %s\n",
-                              tnames->names[i].name.string, sid_type_lookup(sids.sids[i].sid_type));
+               if (i < count) {
+                       if (sids.sids[i].sid_type != tnames->names[i].sid_type) {
+                               torture_comment(tctx, "LookupName of %s got unexpected name type: %s\n",
+                                      tnames->names[i].name.string, sid_type_lookup(sids.sids[i].sid_type));
+                               return false;
+                       }
+                       if ((sids.sids[i].sid_type == SID_NAME_DOMAIN) &&
+                           (sids.sids[i].rid != (uint32_t)-1)) {
+                               torture_comment(tctx, "LookupName of %s got unexpected rid: %d\n",
+                                       tnames->names[i].name.string, sids.sids[i].rid);
+                               return false;
+                       }
                } else if (i >=count) {
                        torture_comment(tctx, "LookupName of %s failed to return a result\n",
                               tnames->names[i].name.string);
+                       return false;
                }
        }
        torture_comment(tctx, "\n");
@@ -543,8 +553,8 @@ static bool test_LookupSids2(struct dcerpc_pipe *p,
        r.in.names = &names;
        r.in.level = 1;
        r.in.count = &count;
-       r.in.unknown1 = 0;
-       r.in.unknown2 = 0;
+       r.in.lookup_options = 0;
+       r.in.client_revision = 0;
        r.out.count = &count;
        r.out.names = &names;
        r.out.domains = &domains;
@@ -587,8 +597,8 @@ static bool test_LookupSids3(struct dcerpc_pipe *p,
        r.in.names = &names;
        r.in.level = 1;
        r.in.count = &count;
-       r.in.unknown1 = 0;
-       r.in.unknown2 = 0;
+       r.in.lookup_options = 0;
+       r.in.client_revision = 0;
        r.out.domains = &domains;
        r.out.count = &count;
        r.out.names = &names;
@@ -678,8 +688,8 @@ bool test_many_LookupSids(struct dcerpc_pipe *p,
                r.in.names = &names;
                r.in.level = 1;
                r.in.count = &count;
-               r.in.unknown1 = 0;
-               r.in.unknown2 = 0;
+               r.in.lookup_options = 0;
+               r.in.client_revision = 0;
                r.out.count = &count;
                r.out.names = &names;
                r.out.domains = &domains;
@@ -1985,11 +1995,9 @@ static bool test_EnumTrustDom(struct dcerpc_pipe *p,
                              struct policy_handle *handle)
 {
        struct lsa_EnumTrustDom r;
-       struct lsa_EnumTrustedDomainsEx r_ex;
        NTSTATUS enum_status;
        uint32_t resume_handle = 0;
        struct lsa_DomainList domains;
-       struct lsa_DomainListEx domains_ex;
        bool ret = true;
 
        torture_comment(tctx, "\nTesting EnumTrustDom\n");
@@ -2054,6 +2062,19 @@ static bool test_EnumTrustDom(struct dcerpc_pipe *p,
 
        } while ((NT_STATUS_EQUAL(enum_status, STATUS_MORE_ENTRIES)));
 
+       return ret;
+}
+
+static bool test_EnumTrustDomEx(struct dcerpc_pipe *p,
+                               struct torture_context *tctx,
+                               struct policy_handle *handle)
+{
+       struct lsa_EnumTrustedDomainsEx r_ex;
+       NTSTATUS enum_status;
+       uint32_t resume_handle = 0;
+       struct lsa_DomainListEx domains_ex;
+       bool ret = true;
+
        torture_comment(tctx, "\nTesting EnumTrustedDomainsEx\n");
 
        r_ex.in.handle = handle;
@@ -2113,27 +2134,36 @@ static bool test_EnumTrustDom(struct dcerpc_pipe *p,
        return ret;
 }
 
+
 static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
                                     struct torture_context *tctx,
-                                    struct policy_handle *handle)
+                                    struct policy_handle *handle,
+                                    uint32_t num_trusts)
 {
        NTSTATUS status;
        bool ret = true;
        struct lsa_CreateTrustedDomain r;
        struct lsa_DomainInfo trustinfo;
-       struct dom_sid *domsid[12];
-       struct policy_handle trustdom_handle[12];
+       struct dom_sid **domsid;
+       struct policy_handle *trustdom_handle;
        struct lsa_QueryTrustedDomainInfo q;
        union lsa_TrustedDomainInfo *info = NULL;
        int i;
 
-       torture_comment(tctx, "\nTesting CreateTrustedDomain for 12 domains\n");
+       torture_comment(tctx, "\nTesting CreateTrustedDomain for %d domains\n", num_trusts);
 
        if (!test_EnumTrustDom(p, tctx, handle)) {
                ret = false;
        }
 
-       for (i=0; i< 12; i++) {
+       if (!test_EnumTrustDomEx(p, tctx, handle)) {
+               ret = false;
+       }
+
+       domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
+       trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
+
+       for (i=0; i< num_trusts; i++) {
                char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
                char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
 
@@ -2162,7 +2192,7 @@ static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
                        q.out.info = &info;
                        status = dcerpc_lsa_QueryTrustedDomainInfo(p, tctx, &q);
                        if (!NT_STATUS_IS_OK(status)) {
-                               torture_comment(tctx, "QueryTrustedDomainInfo level 1 failed - %s\n", nt_errstr(status));
+                               torture_comment(tctx, "QueryTrustedDomainInfo level %d failed - %s\n", q.in.level, nt_errstr(status));
                                ret = false;
                        } else if (!q.out.info) {
                                ret = false;
@@ -2196,7 +2226,11 @@ static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
                ret = false;
        }
 
-       for (i=0; i<12; i++) {
+       if (!test_EnumTrustDomEx(p, tctx, handle)) {
+               ret = false;
+       }
+
+       for (i=0; i<num_trusts; i++) {
                if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
                        ret = false;
                }
@@ -2207,7 +2241,8 @@ static bool test_CreateTrustedDomain(struct dcerpc_pipe *p,
 
 static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
                                        struct torture_context *tctx,
-                                       struct policy_handle *handle)
+                                       struct policy_handle *handle,
+                                       uint32_t num_trusts)
 {
        NTSTATUS status;
        bool ret = true;
@@ -2216,15 +2251,18 @@ static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
        struct lsa_TrustDomainInfoAuthInfoInternal authinfo;
        struct trustDomainPasswords auth_struct;
        DATA_BLOB auth_blob;
-       struct dom_sid *domsid[12];
-       struct policy_handle trustdom_handle[12];
+       struct dom_sid **domsid;
+       struct policy_handle *trustdom_handle;
        struct lsa_QueryTrustedDomainInfo q;
        union lsa_TrustedDomainInfo *info = NULL;
        DATA_BLOB session_key;
        enum ndr_err_code ndr_err;
        int i;
 
-       torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for 12 domains\n");
+       torture_comment(tctx, "\nTesting CreateTrustedDomainEx2 for %d domains\n", num_trusts);
+
+       domsid = talloc_array(tctx, struct dom_sid *, num_trusts);
+       trustdom_handle = talloc_array(tctx, struct policy_handle, num_trusts);
 
        status = dcerpc_fetch_session_key(p, &session_key);
        if (!NT_STATUS_IS_OK(status)) {
@@ -2232,7 +2270,7 @@ static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
                return false;
        }
 
-       for (i=0; i< 12; i++) {
+       for (i=0; i< num_trusts; i++) {
                char *trust_name = talloc_asprintf(tctx, "torturedom%02d", i);
                char *trust_name_dns = talloc_asprintf(tctx, "torturedom%02d.samba.example.com", i);
                char *trust_sid = talloc_asprintf(tctx, "S-1-5-21-97398-379795-100%02d", i);
@@ -2331,7 +2369,12 @@ static bool test_CreateTrustedDomainEx2(struct dcerpc_pipe *p,
                ret = false;
        }
 
-       for (i=0; i<12; i++) {
+       if (!test_EnumTrustDomEx(p, tctx, handle)) {
+               torture_comment(tctx, "test_EnumTrustDomEx failed\n");
+               ret = false;
+       }
+
+       for (i=0; i<num_trusts; i++) {
                if (!test_DeleteTrustedDomainBySid(p, tctx, handle, domsid[i])) {
                        torture_comment(tctx, "test_DeleteTrustedDomainBySid failed\n");
                        ret = false;
@@ -2611,13 +2654,6 @@ bool torture_rpc_lsa(struct torture_context *tctx)
                if (!join) {
                        ret = false;
                }
-               if (!test_LookupNames_wellknown(p, tctx, handle)) {
-                       ret = false;
-               }
-
-               if (!test_LookupNames_bogus(p, tctx, handle)) {
-                       ret = false;
-               }
 
                if (!test_LookupSids_async(p, tctx, handle)) {
                        ret = false;
@@ -2728,6 +2764,14 @@ static bool testcase_LookupNames(struct torture_context *tctx,
                ret = false;
        }
 
+       if (!test_LookupNames_wellknown(p, tctx, handle)) {
+               ret = false;
+       }
+
+       if (!test_LookupNames_bogus(p, tctx, handle)) {
+               ret = false;
+       }
+
        if (!test_lsa_Close(p, tctx, handle)) {
                ret = false;
        }
@@ -2750,11 +2794,20 @@ struct torture_suite *torture_rpc_lsa_lookup_names(TALLOC_CTX *mem_ctx)
        return suite;
 }
 
+struct lsa_trustdom_state {
+       uint32_t num_trusts;
+};
+
 static bool testcase_TrustedDomains(struct torture_context *tctx,
-                                   struct dcerpc_pipe *p)
+                                   struct dcerpc_pipe *p,
+                                   void *data)
 {
        bool ret = true;
        struct policy_handle *handle;
+       struct lsa_trustdom_state *state =
+               talloc_get_type_abort(data, struct lsa_trustdom_state);
+
+       torture_comment(tctx, "testing %d domains\n", state->num_trusts);
 
        if (!test_OpenPolicy(p, tctx)) {
                ret = false;
@@ -2768,11 +2821,11 @@ static bool testcase_TrustedDomains(struct torture_context *tctx,
                ret = false;
        }
 
-       if (!test_CreateTrustedDomain(p, tctx, handle)) {
+       if (!test_CreateTrustedDomain(p, tctx, handle, state->num_trusts)) {
                ret = false;
        }
 
-       if (!test_CreateTrustedDomainEx2(p, tctx, handle)) {
+       if (!test_CreateTrustedDomainEx2(p, tctx, handle, state->num_trusts)) {
                ret = false;
        }
 
@@ -2787,13 +2840,19 @@ struct torture_suite *torture_rpc_lsa_trusted_domains(TALLOC_CTX *mem_ctx)
 {
        struct torture_suite *suite;
        struct torture_rpc_tcase *tcase;
+       struct lsa_trustdom_state *state;
+
+       state = talloc(mem_ctx, struct lsa_trustdom_state);
+
+       state->num_trusts = 12;
 
        suite = torture_suite_create(mem_ctx, "LSA-TRUSTED-DOMAINS");
 
        tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
                                                  &ndr_table_lsarpc);
-       torture_rpc_tcase_add_test(tcase, "TrustedDomains",
-                                  testcase_TrustedDomains);
+       torture_rpc_tcase_add_test_ex(tcase, "TrustedDomains",
+                                     testcase_TrustedDomains,
+                                     state);
 
        return suite;
 }
@@ -2843,9 +2902,8 @@ struct torture_suite *torture_rpc_lsa_privileges(TALLOC_CTX *mem_ctx)
 
        suite = torture_suite_create(mem_ctx, "LSA-PRIVILEGES");
 
-       tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "lsa",
-                                                                     &ndr_table_lsarpc,
-                                                                     TEST_MACHINENAME);
+       tcase = torture_suite_add_rpc_iface_tcase(suite, "lsa",
+                                                 &ndr_table_lsarpc);
        torture_rpc_tcase_add_test(tcase, "Privileges",
                                   testcase_Privileges);