LCOV - code coverage report
Current view: top level - source4/torture/drs/rpc - msds_intid.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 207 321 64.5 %
Date: 2024-02-28 12:06:22 Functions: 12 13 92.3 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    msDS-IntId attribute replication test.
       5             : 
       6             :    Copyright (C) Kamen Mazdrashki <kamenim@samba.org> 2010
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "lib/cmdline/cmdline.h"
      24             : #include "librpc/gen_ndr/ndr_drsuapi_c.h"
      25             : #include "librpc/gen_ndr/ndr_drsblobs.h"
      26             : #include "libcli/cldap/cldap.h"
      27             : #include "torture/torture.h"
      28             : #include "../libcli/drsuapi/drsuapi.h"
      29             : #include "auth/gensec/gensec.h"
      30             : #include "param/param.h"
      31             : #include "dsdb/samdb/samdb.h"
      32             : #include "torture/rpc/torture_rpc.h"
      33             : #include "torture/drs/proto.h"
      34             : #include "lib/tsocket/tsocket.h"
      35             : #include "libcli/resolve/resolve.h"
      36             : #include "lib/util/util_paths.h"
      37             : 
      38             : struct DsSyncBindInfo {
      39             :         struct dcerpc_pipe *drs_pipe;
      40             :         struct dcerpc_binding_handle *drs_handle;
      41             :         struct drsuapi_DsBind req;
      42             :         struct GUID bind_guid;
      43             :         struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
      44             :         struct drsuapi_DsBindInfo28 our_bind_info28;
      45             :         struct drsuapi_DsBindInfo28 peer_bind_info28;
      46             :         struct policy_handle bind_handle;
      47             : };
      48             : 
      49             : struct DsaBindInfo {
      50             :         struct dcerpc_binding           *server_binding;
      51             : 
      52             :         struct dcerpc_pipe              *drs_pipe;
      53             :         struct dcerpc_binding_handle    *drs_handle;
      54             : 
      55             :         DATA_BLOB                       gensec_skey;
      56             :         struct drsuapi_DsBindInfo48     srv_info48;
      57             :         struct policy_handle            rpc_handle;
      58             : };
      59             : 
      60             : struct DsIntIdTestCtx {
      61             :         const char *ldap_url;
      62             :         const char *domain_dn;
      63             :         const char *config_dn;
      64             :         const char *schema_dn;
      65             : 
      66             :         /* what we need to do as 'Administrator' */
      67             :         struct cli_credentials  *creds;
      68             :         struct DsaBindInfo      dsa_bind;
      69             :         struct ldb_context      *ldb;
      70             : 
      71             : };
      72             : 
      73             : /* Format string to create provision LDIF with */
      74             : #define PROVISION_LDIF_FMT \
      75             :                 "###########################################################\n" \
      76             :                 "# Format string with positional params:\n" \
      77             :                 "#  1 - (int) Unique ID between 1 and 2^16\n" \
      78             :                 "#  2 - (string) Domain DN\n" \
      79             :                 "###########################################################\n" \
      80             :                 "\n" \
      81             :                 "###########################################################\n" \
      82             :                 "# Update schema\n" \
      83             :                 "###########################################################\n" \
      84             :                 "dn: CN=msds-intid-%1$d,CN=Schema,CN=Configuration,%2$s\n" \
      85             :                 "changetype: add\n" \
      86             :                 "objectClass: top\n" \
      87             :                 "objectClass: attributeSchema\n" \
      88             :                 "cn: msds-intid-%1$d\n" \
      89             :                 "attributeID: 1.3.6.1.4.1.7165.4.6.1.%1$d.1.5.9940\n" \
      90             :                 "attributeSyntax: 2.5.5.10\n" \
      91             :                 "omSyntax: 4\n" \
      92             :                 "instanceType: 4\n" \
      93             :                 "isSingleValued: TRUE\n" \
      94             :                 "systemOnly: FALSE\n" \
      95             :                 "\n" \
      96             :                 "# schemaUpdateNow\n" \
      97             :                 "DN:\n" \
      98             :                 "changeType: modify\n" \
      99             :                 "add: schemaUpdateNow\n" \
     100             :                 "schemaUpdateNow: 1\n" \
     101             :                 "-\n" \
     102             :                 "\n" \
     103             :                 "###########################################################\n" \
     104             :                 "# Update schema (with linked attribute)\n" \
     105             :                 "###########################################################\n" \
     106             :                 "dn: CN=msds-intid-link-%1$d,CN=Schema,CN=Configuration,%2$s\n" \
     107             :                 "changetype: add\n" \
     108             :                 "objectClass: top\n" \
     109             :                 "objectClass: attributeSchema\n" \
     110             :                 "cn: msds-intid-link-%1$d\n" \
     111             :                 "attributeID: 1.3.6.1.4.1.7165.4.6.1.%1$d.1.5.9941\n" \
     112             :                 "attributeSyntax: 2.5.5.1\n" \
     113             :                 "omSyntax: 127\n" \
     114             :                 "instanceType: 4\n" \
     115             :                 "isSingleValued: TRUE\n" \
     116             :                 "systemOnly: FALSE\n" \
     117             :                 "linkID: 1.2.840.113556.1.2.50\n" \
     118             :                 "\n" \
     119             :                 "# schemaUpdateNow\n" \
     120             :                 "DN:\n" \
     121             :                 "changeType: modify\n" \
     122             :                 "add: schemaUpdateNow\n" \
     123             :                 "schemaUpdateNow: 1\n" \
     124             :                 "-\n" \
     125             :                 "\n" \
     126             :                 "###########################################################\n" \
     127             :                 "# Update User class\n" \
     128             :                 "###########################################################\n" \
     129             :                 "dn: CN=User,CN=Schema,CN=Configuration,%2$s\n" \
     130             :                 "changetype: modify\n" \
     131             :                 "add: mayContain\n" \
     132             :                 "mayContain: msdsIntid%1$d\n" \
     133             :                 "mayContain: msdsIntidLink%1$d\n" \
     134             :                 "-\n" \
     135             :                 "\n" \
     136             :                 "# schemaUpdateNow\n" \
     137             :                 "DN:\n" \
     138             :                 "changeType: modify\n" \
     139             :                 "add: schemaUpdateNow\n" \
     140             :                 "schemaUpdateNow: 1\n" \
     141             :                 "-\n" \
     142             :                 "\n" \
     143             :                 "###########################################################\n" \
     144             :                 "# create user to test with\n" \
     145             :                 "###########################################################\n" \
     146             :                 "dn: CN=dsIntId_usr_%1$d,CN=Users,%2$s\n" \
     147             :                 "changetype: add\n" \
     148             :                 "objectClass: user\n" \
     149             :                 "cn: dsIntId_usr_%1$d\n" \
     150             :                 "name: dsIntId_usr_%1$d\n" \
     151             :                 "displayName: dsIntId_usr_%1$d\n" \
     152             :                 "sAMAccountName: dsIntId_usr_%1$d\n" \
     153             :                 "msdsIntid%1$d: msDS-IntId-%1$d attribute value\n" \
     154             :                 "msdsIntidLink%1$d: %2$s\n" \
     155             :                 "\n"
     156             : 
     157             : 
     158           3 : static struct DsIntIdTestCtx *_dsintid_create_context(struct torture_context *tctx)
     159             : {
     160           0 :         NTSTATUS status;
     161           0 :         struct DsIntIdTestCtx *ctx;
     162           0 :         struct dcerpc_binding *server_binding;
     163           3 :         const char *binding = torture_setting_string(tctx, "binding", NULL);
     164             : 
     165             :         /* Create test suite context */
     166           3 :         ctx = talloc_zero(tctx, struct DsIntIdTestCtx);
     167           3 :         if (!ctx) {
     168           0 :                 torture_result(tctx, TORTURE_FAIL, "Not enough memory!");
     169           0 :                 return NULL;
     170             :         }
     171             : 
     172             :         /* parse binding object */
     173           3 :         status = dcerpc_parse_binding(ctx, binding, &server_binding);
     174           3 :         if (!NT_STATUS_IS_OK(status)) {
     175           0 :                 torture_result(tctx, TORTURE_FAIL,
     176             :                                "Bad binding string '%s': %s", binding, nt_errstr(status));
     177           0 :                 return NULL;
     178             :         }
     179             : 
     180           3 :         status = dcerpc_binding_set_flags(server_binding,
     181             :                                           DCERPC_SIGN | DCERPC_SEAL, 0);
     182           3 :         if (!NT_STATUS_IS_OK(status)) {
     183           0 :                 torture_result(tctx, TORTURE_FAIL,
     184             :                                "dcerpc_binding_set_flags: %s", nt_errstr(status));
     185           0 :                 return NULL;
     186             :         }
     187             : 
     188             :         /* populate test suite context */
     189           3 :         ctx->creds = samba_cmdline_get_creds();
     190           3 :         ctx->dsa_bind.server_binding = server_binding;
     191             : 
     192           3 :         ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s",
     193             :                         dcerpc_binding_get_string_option(server_binding, "host"));
     194             : 
     195           3 :         return ctx;
     196             : }
     197             : 
     198           3 : static bool _test_DsaBind(struct torture_context *tctx,
     199             :                          TALLOC_CTX *mem_ctx,
     200             :                          struct cli_credentials *credentials,
     201             :                          uint32_t req_extensions,
     202             :                          struct DsaBindInfo *bi)
     203             : {
     204           0 :         NTSTATUS status;
     205           0 :         struct GUID bind_guid;
     206           0 :         struct drsuapi_DsBind r;
     207           0 :         struct drsuapi_DsBindInfoCtr bind_info_ctr;
     208           0 :         uint32_t supported_extensions;
     209             : 
     210             :         /* make DCE RPC connection */
     211           3 :         status = dcerpc_pipe_connect_b(mem_ctx,
     212             :                                        &bi->drs_pipe,
     213           3 :                                        bi->server_binding,
     214             :                                        &ndr_table_drsuapi,
     215             :                                        credentials, tctx->ev, tctx->lp_ctx);
     216           3 :         torture_assert_ntstatus_ok(tctx, status, "Failed to connect to server");
     217             : 
     218           3 :         bi->drs_handle = bi->drs_pipe->binding_handle;
     219             : 
     220           3 :         status = gensec_session_key(bi->drs_pipe->conn->security_state.generic_state,
     221             :                                     mem_ctx, &bi->gensec_skey);
     222           3 :         torture_assert_ntstatus_ok(tctx, status, "failed to get gensec session key");
     223             : 
     224             :         /* Bind to DRSUAPI interface */
     225           3 :         GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &bind_guid);
     226             : 
     227             :         /*
     228             :          * Add flags that should be 1, according to MS docs.
     229             :          * It turns out DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
     230             :          * is actually required in order for GetNCChanges() to
     231             :          * return schemaInfo entry in the prefixMap returned.
     232             :          * Use DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION so
     233             :          * we are able to fetch sensitive data.
     234             :          */
     235           3 :         supported_extensions = req_extensions
     236             :                              | DRSUAPI_SUPPORTED_EXTENSION_BASE
     237             :                              | DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
     238             :                              | DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
     239             :                              | DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
     240             :                              | DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
     241             : 
     242           3 :         ZERO_STRUCT(bind_info_ctr);
     243           3 :         bind_info_ctr.length = 28;
     244           3 :         bind_info_ctr.info.info28.supported_extensions = supported_extensions;
     245             : 
     246           3 :         r.in.bind_guid = &bind_guid;
     247           3 :         r.in.bind_info = &bind_info_ctr;
     248           3 :         r.out.bind_handle = &bi->rpc_handle;
     249             : 
     250           3 :         status = dcerpc_drsuapi_DsBind_r(bi->drs_handle, mem_ctx, &r);
     251           3 :         torture_drsuapi_assert_call(tctx, bi->drs_pipe, status,
     252             :                                     &r, "dcerpc_drsuapi_DsBind_r");
     253             : 
     254             : 
     255           3 :         switch (r.out.bind_info->length) {
     256           0 :         case 24: {
     257           0 :                 struct drsuapi_DsBindInfo24 *info24;
     258           0 :                 info24 = &r.out.bind_info->info.info24;
     259           0 :                 bi->srv_info48.supported_extensions  = info24->supported_extensions;
     260           0 :                 bi->srv_info48.site_guid             = info24->site_guid;
     261           0 :                 bi->srv_info48.pid                   = info24->pid;
     262           0 :                 break;
     263             :         }
     264           3 :         case 28: {
     265           0 :                 struct drsuapi_DsBindInfo28 *info28;
     266           3 :                 info28 = &r.out.bind_info->info.info28;
     267           3 :                 bi->srv_info48.supported_extensions  = info28->supported_extensions;
     268           3 :                 bi->srv_info48.site_guid             = info28->site_guid;
     269           3 :                 bi->srv_info48.pid                   = info28->pid;
     270           3 :                 bi->srv_info48.repl_epoch            = info28->repl_epoch;
     271           3 :                 break;
     272             :         }
     273           0 :         case 32: {
     274           0 :                 struct drsuapi_DsBindInfo32 *info32;
     275           0 :                 info32 = &r.out.bind_info->info.info32;
     276           0 :                 bi->srv_info48.supported_extensions  = info32->supported_extensions;
     277           0 :                 bi->srv_info48.site_guid             = info32->site_guid;
     278           0 :                 bi->srv_info48.pid                   = info32->pid;
     279           0 :                 bi->srv_info48.repl_epoch            = info32->repl_epoch;
     280           0 :                 break;
     281             :         }
     282           0 :         case 48: {
     283           0 :                 bi->srv_info48 = r.out.bind_info->info.info48;
     284           0 :                 break;
     285             :         }
     286           0 :         case 52: {
     287           0 :                 struct drsuapi_DsBindInfo52 *info52;
     288           0 :                 info52 = &r.out.bind_info->info.info52;
     289           0 :                 bi->srv_info48.supported_extensions  = info52->supported_extensions;
     290           0 :                 bi->srv_info48.site_guid             = info52->site_guid;
     291           0 :                 bi->srv_info48.pid                   = info52->pid;
     292           0 :                 bi->srv_info48.repl_epoch            = info52->repl_epoch;
     293           0 :                 break;
     294             :         }
     295           0 :         default:
     296           0 :                 torture_result(tctx, TORTURE_FAIL,
     297             :                                "DsBind: unknown BindInfo length: %u",
     298           0 :                                r.out.bind_info->length);
     299           0 :                 return false;
     300             :         }
     301             : 
     302             :         /* check if server supports extensions we've requested */
     303           3 :         if ((bi->srv_info48.supported_extensions & req_extensions) != req_extensions) {
     304           0 :                 torture_result(tctx, TORTURE_FAIL,
     305             :                                "Server does not support requested extensions. "
     306             :                                "Requested: 0x%08X, Supported: 0x%08X",
     307             :                                req_extensions, bi->srv_info48.supported_extensions);
     308           0 :                 return false;
     309             :         }
     310             : 
     311           3 :         return true;
     312             : }
     313             : 
     314           3 : static bool _test_LDAPBind(struct torture_context *tctx,
     315             :                            TALLOC_CTX *mem_ctx,
     316             :                            struct cli_credentials *credentials,
     317             :                            const char *ldap_url,
     318             :                            struct ldb_context **_ldb)
     319             : {
     320           3 :         bool ret = true;
     321             : 
     322           0 :         struct ldb_context *ldb;
     323             : 
     324           3 :         const char *modules_option[] = { "modules:paged_searches", NULL };
     325           3 :         ldb = ldb_init(mem_ctx, tctx->ev);
     326           3 :         if (ldb == NULL) {
     327           0 :                 return false;
     328             :         }
     329             : 
     330             :         /* Despite us loading the schema from the AD server, we need
     331             :          * the samba handlers to get the extended DN syntax stuff */
     332           3 :         ret = ldb_register_samba_handlers(ldb);
     333           3 :         if (ret != LDB_SUCCESS) {
     334           0 :                 talloc_free(ldb);
     335           0 :                 return NULL;
     336             :         }
     337             : 
     338           3 :         ldb_set_modules_dir(ldb, modules_path(ldb, "ldb"));
     339             : 
     340           3 :         if (ldb_set_opaque(ldb, "credentials", credentials) != LDB_SUCCESS) {
     341           0 :                 talloc_free(ldb);
     342           0 :                 return NULL;
     343             :         }
     344             : 
     345           3 :         if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx) != LDB_SUCCESS) {
     346           0 :                 talloc_free(ldb);
     347           0 :                 return NULL;
     348             :         }
     349             : 
     350           3 :         ret = ldb_connect(ldb, ldap_url, 0, modules_option);
     351           3 :         if (ret != LDB_SUCCESS) {
     352           0 :                 talloc_free(ldb);
     353           0 :                 torture_assert_int_equal(tctx, ret, LDB_SUCCESS, "Failed to make LDB connection to target");
     354             :         }
     355             : 
     356           3 :         *_ldb = ldb;
     357             : 
     358           3 :         return true;
     359             : }
     360             : 
     361           3 : static bool _test_provision(struct torture_context *tctx, struct DsIntIdTestCtx *ctx)
     362             : {
     363           0 :         int ret;
     364           0 :         char *ldif_str;
     365           0 :         const char *pstr;
     366           0 :         struct ldb_ldif *ldif;
     367           0 :         uint32_t attr_id;
     368           3 :         struct ldb_context *ldb = ctx->ldb;
     369             : 
     370             :         /* We must have LDB connection ready by this time */
     371           3 :         SMB_ASSERT(ldb != NULL);
     372             : 
     373           3 :         ctx->domain_dn = ldb_dn_get_linearized(ldb_get_default_basedn(ldb));
     374           3 :         torture_assert(tctx, ctx->domain_dn != NULL, "Failed to get Domain DN");
     375             : 
     376           3 :         ctx->config_dn = ldb_dn_get_linearized(ldb_get_config_basedn(ldb));
     377           3 :         torture_assert(tctx, ctx->config_dn != NULL, "Failed to get Domain DN");
     378             : 
     379           3 :         ctx->schema_dn = ldb_dn_get_linearized(ldb_get_schema_basedn(ldb));
     380           3 :         torture_assert(tctx, ctx->schema_dn != NULL, "Failed to get Domain DN");
     381             : 
     382             :         /* prepare LDIF to provision with */
     383           3 :         attr_id = generate_random() % 0xFFFF;
     384           3 :         pstr = ldif_str = talloc_asprintf(ctx, PROVISION_LDIF_FMT,
     385             :                                           attr_id, ctx->domain_dn);
     386             : 
     387             :         /* Provision test data */
     388          24 :         while ((ldif = ldb_ldif_read_string(ldb, &pstr)) != NULL) {
     389          21 :                 switch (ldif->changetype) {
     390           0 :                 case LDB_CHANGETYPE_DELETE:
     391           0 :                         ret = ldb_delete(ldb, ldif->msg->dn);
     392           0 :                         break;
     393          12 :                 case LDB_CHANGETYPE_MODIFY:
     394          12 :                         ret = ldb_modify(ldb, ldif->msg);
     395          12 :                         break;
     396           9 :                 case LDB_CHANGETYPE_ADD:
     397             :                 default:
     398           9 :                         ret = ldb_add(ldb, ldif->msg);
     399           9 :                         break;
     400             :                 }
     401          21 :                 if (ret != LDB_SUCCESS) {
     402           0 :                         char *msg = talloc_asprintf(ctx,
     403             :                                                     "Failed to apply ldif - %s (%s): \n%s",
     404             :                                                     ldb_errstring(ldb),
     405             :                                                     ldb_strerror(ret),
     406             :                                                     ldb_ldif_write_string(ldb, ctx, ldif));
     407           0 :                         torture_fail(tctx, msg);
     408             : 
     409             :                 }
     410          21 :                 ldb_ldif_read_free(ldb, ldif);
     411             :         }
     412             : 
     413           3 :         return true;
     414             : }
     415             : 
     416             : 
     417           9 : static bool _test_GetNCChanges(struct torture_context *tctx,
     418             :                                struct DsaBindInfo *bi,
     419             :                                const char *nc_dn_str,
     420             :                                TALLOC_CTX *mem_ctx,
     421             :                                struct drsuapi_DsGetNCChangesCtr6 **_ctr6)
     422             : {
     423           0 :         NTSTATUS status;
     424           0 :         struct drsuapi_DsGetNCChanges r;
     425           0 :         union drsuapi_DsGetNCChangesRequest req;
     426           0 :         struct drsuapi_DsReplicaObjectIdentifier nc;
     427           9 :         struct drsuapi_DsGetNCChangesCtr6 *ctr6_chunk = NULL;
     428           0 :         struct drsuapi_DsGetNCChangesCtr6 ctr6;
     429           9 :         uint32_t _level = 0;
     430           0 :         union drsuapi_DsGetNCChangesCtr ctr;
     431             : 
     432           0 :         struct dom_sid null_sid;
     433             : 
     434           9 :         ZERO_STRUCT(null_sid);
     435             : 
     436             :         /* fill-in Naming Context */
     437           9 :         nc.guid = GUID_zero();
     438           9 :         nc.sid  = null_sid;
     439           9 :         nc.dn   = nc_dn_str;
     440             : 
     441             :         /* fill-in request fields */
     442           9 :         req.req8.destination_dsa_guid           = GUID_random();
     443           9 :         req.req8.source_dsa_invocation_id       = GUID_zero();
     444           9 :         req.req8.naming_context                 = &nc;
     445           9 :         req.req8.highwatermark.tmp_highest_usn  = 0;
     446           9 :         req.req8.highwatermark.reserved_usn     = 0;
     447           9 :         req.req8.highwatermark.highest_usn      = 0;
     448           9 :         req.req8.uptodateness_vector            = NULL;
     449           9 :         req.req8.replica_flags                  = DRSUAPI_DRS_WRIT_REP
     450             :                                                 | DRSUAPI_DRS_INIT_SYNC
     451             :                                                 | DRSUAPI_DRS_PER_SYNC
     452             :                                                 | DRSUAPI_DRS_GET_ANC
     453             :                                                 | DRSUAPI_DRS_NEVER_SYNCED
     454             :                                                 ;
     455           9 :         req.req8.max_object_count               = 402;
     456           9 :         req.req8.max_ndr_size                   = 402116;
     457             : 
     458           9 :         req.req8.extended_op                    = DRSUAPI_EXOP_NONE;
     459           9 :         req.req8.fsmo_info                      = 0;
     460           9 :         req.req8.partial_attribute_set          = NULL;
     461           9 :         req.req8.partial_attribute_set_ex       = NULL;
     462           9 :         req.req8.mapping_ctr.num_mappings       = 0;
     463           9 :         req.req8.mapping_ctr.mappings           = NULL;
     464             : 
     465           9 :         r.in.bind_handle        = &bi->rpc_handle;
     466           9 :         r.in.level              = 8;
     467           9 :         r.in.req                = &req;
     468             : 
     469           9 :         ZERO_STRUCT(r.out);
     470           9 :         r.out.level_out         = &_level;
     471           9 :         r.out.ctr               = &ctr;
     472             : 
     473           9 :         ZERO_STRUCT(ctr6);
     474           0 :         do {
     475          30 :                 ZERO_STRUCT(ctr);
     476             : 
     477          30 :                 status = dcerpc_drsuapi_DsGetNCChanges_r(bi->drs_handle, mem_ctx, &r);
     478          30 :                 torture_drsuapi_assert_call(tctx, bi->drs_pipe, status,
     479             :                                             &r, "dcerpc_drsuapi_DsGetNCChanges_r");
     480             : 
     481             :                 /* we expect to get level 6 reply */
     482          30 :                 torture_assert_int_equal(tctx, _level, 6, "Expected level 6 reply");
     483             : 
     484             :                 /* store this chunk for later use */
     485          30 :                 ctr6_chunk = &r.out.ctr->ctr6;
     486             : 
     487          30 :                 if (!ctr6.first_object) {
     488           9 :                         ctr6 = *ctr6_chunk;
     489             :                 } else {
     490           0 :                         struct drsuapi_DsReplicaObjectListItemEx *cur;
     491             : 
     492          21 :                         ctr6.object_count += ctr6_chunk->object_count;
     493       19296 :                         for (cur = ctr6.first_object; cur->next_object; cur = cur->next_object) {}
     494          21 :                         cur->next_object = ctr6_chunk->first_object;
     495             : 
     496          21 :                         if (ctr6_chunk->linked_attributes_count != 0) {
     497           0 :                                 uint32_t i;
     498           3 :                                 ctr6.linked_attributes = talloc_realloc(mem_ctx, ctr6.linked_attributes,
     499             :                                                                        struct drsuapi_DsReplicaLinkedAttribute,
     500             :                                                                        ctr6.linked_attributes_count + ctr6_chunk->linked_attributes_count);
     501          57 :                                 for (i = 0; i < ctr6_chunk->linked_attributes_count; i++) {
     502          54 :                                         ctr6.linked_attributes[ctr6.linked_attributes_count++] = ctr6_chunk->linked_attributes[i];
     503             :                                 }
     504             :                         }
     505             :                 }
     506             : 
     507             :                 /* prepare for next request */
     508          30 :                 r.in.req->req8.highwatermark = ctr6_chunk->new_highwatermark;
     509             : 
     510          30 :         } while (ctr6_chunk->more_data);
     511             : 
     512           9 :         *_ctr6 = talloc(mem_ctx, struct drsuapi_DsGetNCChangesCtr6);
     513           9 :         torture_assert(mem_ctx, *_ctr6, "Not enough memory");
     514           9 :         **_ctr6 = ctr6;
     515             : 
     516           9 :         return true;
     517             : }
     518             : 
     519           0 : static char * _make_error_message(TALLOC_CTX *mem_ctx,
     520             :                                   enum drsuapi_DsAttributeId drs_attid,
     521             :                                   const struct dsdb_attribute *dsdb_attr,
     522             :                                   const struct drsuapi_DsReplicaObjectIdentifier *identifier)
     523             : {
     524           0 :         return talloc_asprintf(mem_ctx, "\nInvalid ATTID for %1$s (%2$s)\n"
     525             :                                " drs_attid:      %3$11d (0x%3$08X)\n"
     526             :                                " msDS_IntId:     %4$11d (0x%4$08X)\n"
     527             :                                " attributeId_id: %5$11d (0x%5$08X)",
     528           0 :                                dsdb_attr->lDAPDisplayName,
     529           0 :                                identifier->dn,
     530             :                                drs_attid,
     531           0 :                                dsdb_attr->msDS_IntId,
     532           0 :                                dsdb_attr->attributeID_id);
     533             : }
     534             : 
     535             : /**
     536             :  * Fetch Schema NC and check ATTID values returned.
     537             :  * When Schema partition is replicated, ATTID
     538             :  * should always be made using prefixMap
     539             :  */
     540           3 : static bool test_dsintid_schema(struct torture_context *tctx, struct DsIntIdTestCtx *ctx)
     541             : {
     542           0 :         uint32_t i;
     543           0 :         const struct dsdb_schema *ldap_schema;
     544           3 :         struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
     545           0 :         const struct dsdb_attribute *dsdb_attr;
     546           0 :         const struct drsuapi_DsReplicaAttribute *drs_attr;
     547           0 :         const struct drsuapi_DsReplicaAttributeCtr *attr_ctr;
     548           0 :         const struct drsuapi_DsReplicaObjectListItemEx *cur;
     549           0 :         const struct drsuapi_DsReplicaLinkedAttribute *la;
     550           0 :         TALLOC_CTX *mem_ctx;
     551             : 
     552           3 :         mem_ctx = talloc_new(ctx);
     553           3 :         torture_assert(tctx, mem_ctx, "Not enough memory");
     554             : 
     555             :         /* fetch whole Schema partition */
     556           3 :         torture_comment(tctx, "Fetch partition: %s\n", ctx->schema_dn);
     557           3 :         if (!_test_GetNCChanges(tctx, &ctx->dsa_bind, ctx->schema_dn, mem_ctx, &ctr6)) {
     558           0 :                 torture_fail(tctx, "_test_GetNCChanges() failed");
     559             :         }
     560             : 
     561             :         /* load schema if not loaded yet */
     562           3 :         torture_comment(tctx, "Loading schema...\n");
     563           3 :         if (!drs_util_dsdb_schema_load_ldb(tctx, ctx->ldb, &ctr6->mapping_ctr, false)) {
     564           0 :                 torture_fail(tctx, "drs_util_dsdb_schema_load_ldb() failed");
     565             :         }
     566           3 :         ldap_schema = dsdb_get_schema(ctx->ldb, NULL);
     567             : 
     568             :         /* verify ATTIDs fetched */
     569           3 :         torture_comment(tctx, "Verify ATTIDs fetched\n");
     570        4665 :         for (cur = ctr6->first_object; cur; cur = cur->next_object) {
     571        4662 :                 attr_ctr = &cur->object.attribute_ctr;
     572       96075 :                 for (i = 0; i < attr_ctr->num_attributes; i++) {
     573       91413 :                         drs_attr = &attr_ctr->attributes[i];
     574       91413 :                         dsdb_attr = dsdb_attribute_by_attributeID_id(ldap_schema,
     575       91413 :                                                                      drs_attr->attid);
     576             : 
     577       91413 :                         torture_assert(tctx,
     578             :                                        drs_attr->attid == dsdb_attr->attributeID_id,
     579             :                                        _make_error_message(ctx, drs_attr->attid,
     580             :                                                            dsdb_attr,
     581             :                                                            cur->object.identifier));
     582       91413 :                         if (dsdb_attr->msDS_IntId) {
     583           0 :                                 torture_assert(tctx,
     584             :                                                drs_attr->attid != dsdb_attr->msDS_IntId,
     585             :                                                _make_error_message(ctx, drs_attr->attid,
     586             :                                                                    dsdb_attr,
     587             :                                                                    cur->object.identifier));
     588             :                         }
     589             :                 }
     590             :         }
     591             : 
     592             :         /* verify ATTIDs for Linked Attributes */
     593           3 :         torture_comment(tctx, "Verify ATTIDs for Linked Attributes (%u)\n",
     594           3 :                         ctr6->linked_attributes_count);
     595           3 :         for (i = 0; i < ctr6->linked_attributes_count; i++) {
     596           0 :                 la = &ctr6->linked_attributes[i];
     597           0 :                 dsdb_attr = dsdb_attribute_by_attributeID_id(ldap_schema, la->attid);
     598             : 
     599           0 :                 torture_assert(tctx,
     600             :                                la->attid == dsdb_attr->attributeID_id,
     601             :                                _make_error_message(ctx, la->attid,
     602             :                                                    dsdb_attr,
     603             :                                                    la->identifier));
     604           0 :                 if (dsdb_attr->msDS_IntId) {
     605           0 :                         torture_assert(tctx,
     606             :                                        la->attid != dsdb_attr->msDS_IntId,
     607             :                                        _make_error_message(ctx, la->attid,
     608             :                                                            dsdb_attr,
     609             :                                                            la->identifier));
     610             :                 }
     611             :         }
     612             : 
     613           3 :         talloc_free(mem_ctx);
     614             : 
     615           3 :         return true;
     616             : }
     617             : 
     618             : /**
     619             :  * Fetch non-Schema NC and check ATTID values returned.
     620             :  * When non-Schema partition is replicated, ATTID
     621             :  * should be msDS-IntId value for the attribute
     622             :  * if this value exists
     623             :  */
     624           6 : static bool _test_dsintid(struct torture_context *tctx,
     625             :                           struct DsIntIdTestCtx *ctx,
     626             :                           const char *nc_dn_str)
     627             : {
     628           0 :         uint32_t i;
     629           0 :         const struct dsdb_schema *ldap_schema;
     630           6 :         struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
     631           0 :         const struct dsdb_attribute *dsdb_attr;
     632           0 :         const struct drsuapi_DsReplicaAttribute *drs_attr;
     633           0 :         const struct drsuapi_DsReplicaAttributeCtr *attr_ctr;
     634           0 :         const struct drsuapi_DsReplicaObjectListItemEx *cur;
     635           0 :         const struct drsuapi_DsReplicaLinkedAttribute *la;
     636           0 :         TALLOC_CTX *mem_ctx;
     637             : 
     638           6 :         mem_ctx = talloc_new(ctx);
     639           6 :         torture_assert(tctx, mem_ctx, "Not enough memory");
     640             : 
     641             :         /* fetch whole Schema partition */
     642           6 :         torture_comment(tctx, "Fetch partition: %s\n", nc_dn_str);
     643           6 :         if (!_test_GetNCChanges(tctx, &ctx->dsa_bind, nc_dn_str, mem_ctx, &ctr6)) {
     644           0 :                 torture_fail(tctx, "_test_GetNCChanges() failed");
     645             :         }
     646             : 
     647             :         /* load schema if not loaded yet */
     648           6 :         torture_comment(tctx, "Loading schema...\n");
     649           6 :         if (!drs_util_dsdb_schema_load_ldb(tctx, ctx->ldb, &ctr6->mapping_ctr, false)) {
     650           0 :                 torture_fail(tctx, "drs_util_dsdb_schema_load_ldb() failed");
     651             :         }
     652           6 :         ldap_schema = dsdb_get_schema(ctx->ldb, NULL);
     653             : 
     654             :         /* verify ATTIDs fetched */
     655           6 :         torture_comment(tctx, "Verify ATTIDs fetched\n");
     656        5655 :         for (cur = ctr6->first_object; cur; cur = cur->next_object) {
     657        5649 :                 attr_ctr = &cur->object.attribute_ctr;
     658       68724 :                 for (i = 0; i < attr_ctr->num_attributes; i++) {
     659       63075 :                         drs_attr = &attr_ctr->attributes[i];
     660       63075 :                         dsdb_attr = dsdb_attribute_by_attributeID_id(ldap_schema,
     661       63075 :                                                                      drs_attr->attid);
     662       63075 :                         if (dsdb_attr->msDS_IntId) {
     663           6 :                                 torture_assert(tctx,
     664             :                                                drs_attr->attid == dsdb_attr->msDS_IntId,
     665             :                                                _make_error_message(ctx, drs_attr->attid,
     666             :                                                                    dsdb_attr,
     667             :                                                                    cur->object.identifier));
     668             :                         } else {
     669       63069 :                                 torture_assert(tctx,
     670             :                                                drs_attr->attid == dsdb_attr->attributeID_id,
     671             :                                                _make_error_message(ctx, drs_attr->attid,
     672             :                                                                    dsdb_attr,
     673             :                                                                    cur->object.identifier));
     674             :                         }
     675             :                 }
     676             :         }
     677             : 
     678             :         /* verify ATTIDs for Linked Attributes */
     679           6 :         torture_comment(tctx, "Verify ATTIDs for Linked Attributes (%u)\n",
     680           6 :                         ctr6->linked_attributes_count);
     681         144 :         for (i = 0; i < ctr6->linked_attributes_count; i++) {
     682         138 :                 la = &ctr6->linked_attributes[i];
     683         138 :                 dsdb_attr = dsdb_attribute_by_attributeID_id(ldap_schema, la->attid);
     684             : 
     685         138 :                 if (dsdb_attr->msDS_IntId) {
     686           6 :                         torture_assert(tctx,
     687             :                                        la->attid == dsdb_attr->msDS_IntId,
     688             :                                        _make_error_message(ctx, la->attid,
     689             :                                                            dsdb_attr,
     690             :                                                            la->identifier));
     691             :                 } else {
     692         132 :                         torture_assert(tctx,
     693             :                                        la->attid == dsdb_attr->attributeID_id,
     694             :                                        _make_error_message(ctx, la->attid,
     695             :                                                            dsdb_attr,
     696             :                                                            la->identifier));
     697             :                 }
     698             :         }
     699             : 
     700           6 :         talloc_free(mem_ctx);
     701             : 
     702           6 :         return true;
     703             : }
     704             : 
     705             : /**
     706             :  * Fetch Domain NC and check ATTID values returned.
     707             :  * When Domain partition is replicated, ATTID
     708             :  * should be msDS-IntId value for the attribute
     709             :  * if this value exists
     710             :  */
     711           3 : static bool test_dsintid_configuration(struct torture_context *tctx, struct DsIntIdTestCtx *ctx)
     712             : {
     713           3 :         return _test_dsintid(tctx, ctx, ctx->config_dn);
     714             : }
     715             : 
     716             : /**
     717             :  * Fetch Configuration NC and check ATTID values returned.
     718             :  * When Configuration partition is replicated, ATTID
     719             :  * should be msDS-IntId value for the attribute
     720             :  * if this value exists
     721             :  */
     722           3 : static bool test_dsintid_domain(struct torture_context *tctx, struct DsIntIdTestCtx *ctx)
     723             : {
     724           3 :         return _test_dsintid(tctx, ctx, ctx->domain_dn);
     725             : }
     726             : 
     727             : 
     728             : /**
     729             :  * DSSYNC test case setup
     730             :  */
     731           3 : static bool torture_dsintid_tcase_setup(struct torture_context *tctx, void **data)
     732             : {
     733           0 :         bool bret;
     734           0 :         struct DsIntIdTestCtx *ctx;
     735             : 
     736           3 :         *data = ctx = _dsintid_create_context(tctx);
     737           3 :         torture_assert(tctx, ctx, "test_create_context() failed");
     738             : 
     739           3 :         bret = _test_DsaBind(tctx, ctx, ctx->creds,
     740             :                              DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8 |
     741             :                              DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6,
     742             :                              &ctx->dsa_bind);
     743           3 :         torture_assert(tctx, bret, "_test_DsaBind() failed");
     744             : 
     745           3 :         bret = _test_LDAPBind(tctx, ctx, ctx->creds, ctx->ldap_url, &ctx->ldb);
     746           3 :         torture_assert(tctx, bret, "_test_LDAPBind() failed");
     747             : 
     748           3 :         bret = _test_provision(tctx, ctx);
     749           3 :         torture_assert(tctx, bret, "_test_provision() failed");
     750             : 
     751           3 :         return true;
     752             : }
     753             : 
     754             : /**
     755             :  * DSSYNC test case cleanup
     756             :  */
     757           3 : static bool torture_dsintid_tcase_teardown(struct torture_context *tctx, void *data)
     758             : {
     759           0 :         struct DsIntIdTestCtx *ctx;
     760           0 :         struct drsuapi_DsUnbind r;
     761           0 :         struct policy_handle bind_handle;
     762             : 
     763           3 :         ctx = talloc_get_type(data, struct DsIntIdTestCtx);
     764             : 
     765           3 :         ZERO_STRUCT(r);
     766           3 :         r.out.bind_handle = &bind_handle;
     767             : 
     768             :         /* Release DRSUAPI handle */
     769           3 :         r.in.bind_handle = &ctx->dsa_bind.rpc_handle;
     770           3 :         dcerpc_drsuapi_DsUnbind_r(ctx->dsa_bind.drs_handle, ctx, &r);
     771             : 
     772           3 :         talloc_free(ctx);
     773             : 
     774           3 :         return true;
     775             : }
     776             : 
     777             : /**
     778             :  * DSSYNC test case implementation
     779             :  */
     780        2379 : void torture_drs_rpc_dsintid_tcase(struct torture_suite *suite)
     781             : {
     782         125 :         typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
     783        2379 :         struct torture_tcase *tcase = torture_suite_add_tcase(suite, "msDSIntId");
     784             : 
     785        2379 :         torture_tcase_set_fixture(tcase,
     786             :                                   torture_dsintid_tcase_setup,
     787             :                                   torture_dsintid_tcase_teardown);
     788             : 
     789        2379 :         torture_tcase_add_simple_test(tcase, "Schema", (run_func)test_dsintid_schema);
     790        2379 :         torture_tcase_add_simple_test(tcase, "Configuration", (run_func)test_dsintid_configuration);
     791        2379 :         torture_tcase_add_simple_test(tcase, "Domain", (run_func)test_dsintid_domain);
     792        2379 : }

Generated by: LCOV version 1.14