LCOV - code coverage report
Current view: top level - source3/libnet - libnet_dssync.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 0 360 0.0 %
Date: 2024-06-13 04:01:37 Functions: 0 11 0.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Copyright (C) Stefan (metze) Metzmacher 2005
       5             :    Copyright (C) Guenther Deschner 2008
       6             :    Copyright (C) Michael Adam 2008
       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             : 
      23             : #include "includes.h"
      24             : #include "libnet/libnet_dssync.h"
      25             : #include "rpc_client/cli_pipe.h"
      26             : #include "../libcli/drsuapi/drsuapi.h"
      27             : #include "../librpc/gen_ndr/ndr_drsuapi_c.h"
      28             : 
      29             : /****************************************************************
      30             : ****************************************************************/
      31             : 
      32           0 : static int libnet_dssync_free_context(struct dssync_context *ctx)
      33             : {
      34             :         WERROR result;
      35             :         struct dcerpc_binding_handle *b;
      36             : 
      37           0 :         if (!ctx) {
      38           0 :                 return 0;
      39             :         }
      40             : 
      41           0 :         if (is_valid_policy_hnd(&ctx->bind_handle) && ctx->cli) {
      42           0 :                 b = ctx->cli->binding_handle;
      43           0 :                 dcerpc_drsuapi_DsUnbind(b, ctx, &ctx->bind_handle, &result);
      44             :         }
      45             : 
      46           0 :         return 0;
      47             : }
      48             : 
      49             : /****************************************************************
      50             : ****************************************************************/
      51             : 
      52           0 : NTSTATUS libnet_dssync_init_context(TALLOC_CTX *mem_ctx,
      53             :                                     struct dssync_context **ctx_p)
      54             : {
      55             :         struct dssync_context *ctx;
      56             : 
      57           0 :         ctx = talloc_zero(mem_ctx, struct dssync_context);
      58           0 :         NT_STATUS_HAVE_NO_MEMORY(ctx);
      59             : 
      60           0 :         talloc_set_destructor(ctx, libnet_dssync_free_context);
      61           0 :         ctx->clean_old_entries = false;
      62             : 
      63           0 :         *ctx_p = ctx;
      64             : 
      65           0 :         return NT_STATUS_OK;
      66             : }
      67             : 
      68             : /****************************************************************
      69             : ****************************************************************/
      70             : 
      71           0 : static void parse_obj_identifier(struct drsuapi_DsReplicaObjectIdentifier *id,
      72             :                                  uint32_t *rid)
      73             : {
      74           0 :         if (!id || !rid) {
      75           0 :                 return;
      76             :         }
      77             : 
      78           0 :         *rid = 0;
      79             : 
      80           0 :         if (id->sid.num_auths > 0) {
      81           0 :                 *rid = id->sid.sub_auths[id->sid.num_auths - 1];
      82             :         }
      83             : }
      84             : 
      85             : /****************************************************************
      86             : ****************************************************************/
      87             : 
      88           0 : static void libnet_dssync_decrypt_attributes(TALLOC_CTX *mem_ctx,
      89             :                                              DATA_BLOB *session_key,
      90             :                                              struct drsuapi_DsReplicaObjectListItemEx *cur)
      91             : {
      92           0 :         for (; cur; cur = cur->next_object) {
      93             : 
      94             :                 uint32_t i;
      95           0 :                 uint32_t rid = 0;
      96             : 
      97           0 :                 parse_obj_identifier(cur->object.identifier, &rid);
      98             : 
      99           0 :                 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
     100             : 
     101             :                         struct drsuapi_DsReplicaAttribute *attr;
     102             : 
     103           0 :                         attr = &cur->object.attribute_ctr.attributes[i];
     104             : 
     105           0 :                         if (attr->value_ctr.num_values < 1) {
     106           0 :                                 continue;
     107             :                         }
     108             : 
     109           0 :                         if (!attr->value_ctr.values[0].blob) {
     110           0 :                                 continue;
     111             :                         }
     112             : 
     113           0 :                         drsuapi_decrypt_attribute(mem_ctx,
     114             :                                                   session_key,
     115             :                                                   rid,
     116             :                                                   0,
     117             :                                                   attr);
     118             :                 }
     119             :         }
     120           0 : }
     121             : /****************************************************************
     122             : ****************************************************************/
     123             : 
     124           0 : static NTSTATUS libnet_dssync_bind(TALLOC_CTX *mem_ctx,
     125             :                                    struct dssync_context *ctx)
     126             : {
     127             :         NTSTATUS status;
     128             :         WERROR werr;
     129             : 
     130             :         struct GUID bind_guid;
     131             :         struct drsuapi_DsBindInfoCtr bind_info;
     132             :         struct drsuapi_DsBindInfo28 info28;
     133           0 :         struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
     134             : 
     135           0 :         ZERO_STRUCT(info28);
     136             : 
     137           0 :         GUID_from_string(DRSUAPI_DS_BIND_GUID, &bind_guid);
     138             : 
     139           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
     140           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
     141           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
     142           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
     143           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
     144           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
     145           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
     146           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
     147           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
     148           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
     149           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
     150           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
     151           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
     152           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
     153           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
     154           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
     155           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
     156           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
     157           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
     158           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
     159           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
     160           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
     161           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
     162           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
     163           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
     164           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
     165           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
     166           0 :         info28.supported_extensions     |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
     167           0 :         info28.site_guid                = GUID_zero();
     168           0 :         info28.pid                      = 508;
     169           0 :         info28.repl_epoch               = 0;
     170             : 
     171           0 :         bind_info.length = 28;
     172           0 :         bind_info.info.info28 = info28;
     173             : 
     174           0 :         status = dcerpc_drsuapi_DsBind(b, mem_ctx,
     175             :                                        &bind_guid,
     176             :                                        &bind_info,
     177             :                                        &ctx->bind_handle,
     178             :                                        &werr);
     179             : 
     180           0 :         if (!NT_STATUS_IS_OK(status)) {
     181           0 :                 return status;
     182             :         }
     183             : 
     184           0 :         if (!W_ERROR_IS_OK(werr)) {
     185           0 :                 return werror_to_ntstatus(werr);
     186             :         }
     187             : 
     188           0 :         ZERO_STRUCT(ctx->remote_info28);
     189           0 :         switch (bind_info.length) {
     190           0 :         case 24: {
     191             :                 struct drsuapi_DsBindInfo24 *info24;
     192           0 :                 info24 = &bind_info.info.info24;
     193           0 :                 ctx->remote_info28.site_guid         = info24->site_guid;
     194           0 :                 ctx->remote_info28.supported_extensions      = info24->supported_extensions;
     195           0 :                 ctx->remote_info28.pid                       = info24->pid;
     196           0 :                 ctx->remote_info28.repl_epoch                = 0;
     197           0 :                 break;
     198             :         }
     199           0 :         case 28: {
     200           0 :                 ctx->remote_info28 = bind_info.info.info28;
     201           0 :                 break;
     202             :         }
     203           0 :         case 32: {
     204             :                 struct drsuapi_DsBindInfo32 *info32;
     205           0 :                 info32 = &bind_info.info.info32;
     206           0 :                 ctx->remote_info28.site_guid         = info32->site_guid;
     207           0 :                 ctx->remote_info28.supported_extensions      = info32->supported_extensions;
     208           0 :                 ctx->remote_info28.pid                       = info32->pid;
     209           0 :                 ctx->remote_info28.repl_epoch                = info32->repl_epoch;
     210           0 :                 break;
     211             :         }
     212           0 :         case 48: {
     213             :                 struct drsuapi_DsBindInfo48 *info48;
     214           0 :                 info48 = &bind_info.info.info48;
     215           0 :                 ctx->remote_info28.site_guid         = info48->site_guid;
     216           0 :                 ctx->remote_info28.supported_extensions      = info48->supported_extensions;
     217           0 :                 ctx->remote_info28.pid                       = info48->pid;
     218           0 :                 ctx->remote_info28.repl_epoch                = info48->repl_epoch;
     219           0 :                 break;
     220             :         }
     221           0 :         case 52: {
     222             :                 struct drsuapi_DsBindInfo52 *info52;
     223           0 :                 info52 = &bind_info.info.info52;
     224           0 :                 ctx->remote_info28.site_guid         = info52->site_guid;
     225           0 :                 ctx->remote_info28.supported_extensions      = info52->supported_extensions;
     226           0 :                 ctx->remote_info28.pid                       = info52->pid;
     227           0 :                 ctx->remote_info28.repl_epoch                = info52->repl_epoch;
     228           0 :                 break;
     229             :         }
     230           0 :         default:
     231           0 :                 DEBUG(1, ("Warning: invalid info length in bind info: %d\n",
     232             :                           bind_info.length));
     233           0 :                 break;
     234             :         }
     235             : 
     236           0 :         return status;
     237             : }
     238             : 
     239             : /****************************************************************
     240             : ****************************************************************/
     241             : 
     242           0 : static NTSTATUS libnet_dssync_lookup_nc(TALLOC_CTX *mem_ctx,
     243             :                                         struct dssync_context *ctx)
     244             : {
     245             :         NTSTATUS status;
     246             :         WERROR werr;
     247           0 :         uint32_t level = 1;
     248             :         union drsuapi_DsNameRequest req;
     249             :         uint32_t level_out;
     250             :         struct drsuapi_DsNameString names[1];
     251             :         union drsuapi_DsNameCtr ctr;
     252           0 :         struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
     253             : 
     254           0 :         names[0].str = talloc_asprintf(mem_ctx, "%s\\", ctx->domain_name);
     255           0 :         NT_STATUS_HAVE_NO_MEMORY(names[0].str);
     256             : 
     257           0 :         req.req1.codepage       = 1252; /* german */
     258           0 :         req.req1.language       = 0x00000407; /* german */
     259           0 :         req.req1.count          = 1;
     260           0 :         req.req1.names          = names;
     261           0 :         req.req1.format_flags   = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
     262           0 :         req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_UNKNOWN;
     263           0 :         req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
     264             : 
     265           0 :         status = dcerpc_drsuapi_DsCrackNames(b, mem_ctx,
     266             :                                              &ctx->bind_handle,
     267             :                                              level,
     268             :                                              &req,
     269             :                                              &level_out,
     270             :                                              &ctr,
     271             :                                              &werr);
     272           0 :         if (!NT_STATUS_IS_OK(status)) {
     273           0 :                 ctx->error_message = talloc_asprintf(ctx,
     274             :                         "Failed to lookup DN for domain name: %s",
     275             :                         get_friendly_nt_error_msg(status));
     276           0 :                 return status;
     277             :         }
     278             : 
     279           0 :         if (!W_ERROR_IS_OK(werr)) {
     280           0 :                 ctx->error_message = talloc_asprintf(ctx,
     281             :                         "Failed to lookup DN for domain name: %s",
     282             :                         get_friendly_werror_msg(werr));
     283           0 :                 return werror_to_ntstatus(werr);
     284             :         }
     285             : 
     286           0 :         if (ctr.ctr1->count != 1) {
     287           0 :                 return NT_STATUS_UNSUCCESSFUL;
     288             :         }
     289             : 
     290           0 :         if (ctr.ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
     291           0 :                 return NT_STATUS_UNSUCCESSFUL;
     292             :         }
     293             : 
     294           0 :         ctx->nc_dn = talloc_strdup(mem_ctx, ctr.ctr1->array[0].result_name);
     295           0 :         NT_STATUS_HAVE_NO_MEMORY(ctx->nc_dn);
     296             : 
     297           0 :         if (!ctx->dns_domain_name) {
     298           0 :                 ctx->dns_domain_name = talloc_strdup_upper(mem_ctx,
     299           0 :                         ctr.ctr1->array[0].dns_domain_name);
     300           0 :                 NT_STATUS_HAVE_NO_MEMORY(ctx->dns_domain_name);
     301             :         }
     302             : 
     303           0 :         return NT_STATUS_OK;
     304             : }
     305             : 
     306             : /****************************************************************
     307             : ****************************************************************/
     308             : 
     309           0 : static NTSTATUS libnet_dssync_init(TALLOC_CTX *mem_ctx,
     310             :                                    struct dssync_context *ctx)
     311             : {
     312             :         NTSTATUS status;
     313             : 
     314           0 :         status = libnet_dssync_bind(mem_ctx, ctx);
     315           0 :         if (!NT_STATUS_IS_OK(status)) {
     316           0 :                 return status;
     317             :         }
     318             : 
     319           0 :         if (!ctx->nc_dn) {
     320           0 :                 status = libnet_dssync_lookup_nc(mem_ctx, ctx);
     321             :         }
     322             : 
     323           0 :         return status;
     324             : }
     325             : 
     326             : /****************************************************************
     327             : ****************************************************************/
     328             : 
     329           0 : static NTSTATUS libnet_dssync_build_request(TALLOC_CTX *mem_ctx,
     330             :                                             struct dssync_context *ctx,
     331             :                                             const char *dn,
     332             :                                             struct replUpToDateVectorBlob *utdv,
     333             :                                             uint32_t *plevel,
     334             :                                             union drsuapi_DsGetNCChangesRequest *preq)
     335             : {
     336             :         NTSTATUS status;
     337             :         uint32_t count;
     338             :         uint32_t level;
     339             :         union drsuapi_DsGetNCChangesRequest req;
     340             :         enum drsuapi_DsExtendedOperation extended_op;
     341           0 :         struct drsuapi_DsReplicaObjectIdentifier *nc = NULL;
     342           0 :         struct drsuapi_DsReplicaCursorCtrEx *cursors = NULL;
     343             : 
     344           0 :         uint32_t replica_flags  = DRSUAPI_DRS_WRIT_REP |
     345             :                                   DRSUAPI_DRS_INIT_SYNC |
     346             :                                   DRSUAPI_DRS_PER_SYNC |
     347             :                                   DRSUAPI_DRS_GET_ANC |
     348             :                                   DRSUAPI_DRS_NEVER_SYNCED;
     349             : 
     350           0 :         ZERO_STRUCT(req);
     351             : 
     352           0 :         if (ctx->remote_info28.supported_extensions
     353           0 :             & DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8)
     354             :         {
     355           0 :                 level = 8;
     356             :         } else {
     357           0 :                 level = 5;
     358             :         }
     359             : 
     360           0 :         nc = talloc_zero(mem_ctx, struct drsuapi_DsReplicaObjectIdentifier);
     361           0 :         if (!nc) {
     362           0 :                 status = NT_STATUS_NO_MEMORY;
     363           0 :                 goto fail;
     364             :         }
     365           0 :         nc->dn = dn;
     366           0 :         nc->guid = GUID_zero();
     367           0 :         nc->sid = (struct dom_sid) {0};
     368             : 
     369           0 :         if (!ctx->single_object_replication &&
     370           0 :             !ctx->force_full_replication && utdv)
     371             :         {
     372           0 :                 cursors = talloc_zero(mem_ctx,
     373             :                                          struct drsuapi_DsReplicaCursorCtrEx);
     374           0 :                 if (!cursors) {
     375           0 :                         status = NT_STATUS_NO_MEMORY;
     376           0 :                         goto fail;
     377             :                 }
     378             : 
     379           0 :                 switch (utdv->version) {
     380           0 :                 case 1:
     381           0 :                         cursors->count = utdv->ctr.ctr1.count;
     382           0 :                         cursors->cursors = utdv->ctr.ctr1.cursors;
     383           0 :                         break;
     384           0 :                 case 2:
     385           0 :                         cursors->count = utdv->ctr.ctr2.count;
     386           0 :                         cursors->cursors = talloc_array(cursors,
     387             :                                                 struct drsuapi_DsReplicaCursor,
     388             :                                                 cursors->count);
     389           0 :                         if (!cursors->cursors) {
     390           0 :                                 status = NT_STATUS_NO_MEMORY;
     391           0 :                                 goto fail;
     392             :                         }
     393           0 :                         for (count = 0; count < cursors->count; count++) {
     394           0 :                                 cursors->cursors[count].source_dsa_invocation_id =
     395           0 :                                         utdv->ctr.ctr2.cursors[count].source_dsa_invocation_id;
     396           0 :                                 cursors->cursors[count].highest_usn =
     397           0 :                                         utdv->ctr.ctr2.cursors[count].highest_usn;
     398             :                         }
     399           0 :                         break;
     400             :                 }
     401             :         }
     402             : 
     403           0 :         if (ctx->single_object_replication) {
     404           0 :                 extended_op = DRSUAPI_EXOP_REPL_OBJ;
     405             :         } else {
     406           0 :                 extended_op = DRSUAPI_EXOP_NONE;
     407             :         }
     408             : 
     409           0 :         if (level == 8) {
     410           0 :                 req.req8.naming_context         = nc;
     411           0 :                 req.req8.replica_flags          = replica_flags;
     412           0 :                 req.req8.max_object_count       = 402;
     413           0 :                 req.req8.max_ndr_size           = 402116;
     414           0 :                 req.req8.uptodateness_vector    = cursors;
     415           0 :                 req.req8.extended_op            = extended_op;
     416           0 :         } else if (level == 5) {
     417           0 :                 req.req5.naming_context         = nc;
     418           0 :                 req.req5.replica_flags          = replica_flags;
     419           0 :                 req.req5.max_object_count       = 402;
     420           0 :                 req.req5.max_ndr_size           = 402116;
     421           0 :                 req.req5.uptodateness_vector    = cursors;
     422           0 :                 req.req5.extended_op            = extended_op;
     423             :         } else {
     424           0 :                 status = NT_STATUS_INVALID_PARAMETER;
     425           0 :                 goto fail;
     426             :         }
     427             : 
     428           0 :         if (plevel) {
     429           0 :                 *plevel = level;
     430             :         }
     431             : 
     432           0 :         if (preq) {
     433           0 :                 *preq = req;
     434             :         }
     435             : 
     436           0 :         return NT_STATUS_OK;
     437             : 
     438           0 : fail:
     439           0 :         TALLOC_FREE(nc);
     440           0 :         TALLOC_FREE(cursors);
     441           0 :         return status;
     442             : }
     443             : 
     444           0 : static NTSTATUS libnet_dssync_getncchanges(TALLOC_CTX *mem_ctx,
     445             :                                            struct dssync_context *ctx,
     446             :                                            uint32_t level,
     447             :                                            union drsuapi_DsGetNCChangesRequest *req,
     448             :                                            struct replUpToDateVectorBlob **pnew_utdv)
     449             : {
     450             :         NTSTATUS status;
     451             :         WERROR werr;
     452             :         union drsuapi_DsGetNCChangesCtr ctr;
     453           0 :         struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
     454           0 :         struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
     455           0 :         struct replUpToDateVectorBlob *new_utdv = NULL;
     456           0 :         uint32_t level_out = 0;
     457           0 :         uint32_t out_level = 0;
     458             :         int y;
     459             :         bool last_query;
     460           0 :         struct dcerpc_binding_handle *b = ctx->cli->binding_handle;
     461             : 
     462           0 :         if (!ctx->single_object_replication) {
     463           0 :                 new_utdv = talloc_zero(mem_ctx, struct replUpToDateVectorBlob);
     464           0 :                 if (!new_utdv) {
     465           0 :                         status = NT_STATUS_NO_MEMORY;
     466           0 :                         goto out;
     467             :                 }
     468             :         }
     469             : 
     470           0 :         for (y=0, last_query = false; !last_query; y++) {
     471           0 :                 struct drsuapi_DsReplicaObjectListItemEx *first_object = NULL;
     472           0 :                 struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr = NULL;
     473           0 :                 uint32_t linked_attributes_count = 0;
     474           0 :                 struct drsuapi_DsReplicaLinkedAttribute *linked_attributes = NULL;
     475             : 
     476           0 :                 if (level == 8) {
     477           0 :                         DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
     478             :                                 (long long)req->req8.highwatermark.tmp_highest_usn,
     479             :                                 (long long)req->req8.highwatermark.highest_usn));
     480           0 :                 } else if (level == 5) {
     481           0 :                         DEBUG(1,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
     482             :                                 (long long)req->req5.highwatermark.tmp_highest_usn,
     483             :                                 (long long)req->req5.highwatermark.highest_usn));
     484             :                 }
     485             : 
     486           0 :                 status = dcerpc_drsuapi_DsGetNCChanges(b, mem_ctx,
     487             :                                                        &ctx->bind_handle,
     488             :                                                        level,
     489             :                                                        req,
     490             :                                                        &level_out,
     491             :                                                        &ctr,
     492             :                                                        &werr);
     493           0 :                 if (!NT_STATUS_IS_OK(status)) {
     494           0 :                         ctx->error_message = talloc_asprintf(ctx,
     495             :                                 "Failed to get NC Changes: %s",
     496             :                                 get_friendly_nt_error_msg(status));
     497           0 :                         goto out;
     498             :                 }
     499             : 
     500           0 :                 if (!W_ERROR_IS_OK(werr)) {
     501           0 :                         status = werror_to_ntstatus(werr);
     502           0 :                         ctx->error_message = talloc_asprintf(ctx,
     503             :                                 "Failed to get NC Changes: %s",
     504             :                                 get_friendly_werror_msg(werr));
     505           0 :                         goto out;
     506             :                 }
     507             : 
     508           0 :                 if (level_out == 1) {
     509           0 :                         out_level = 1;
     510           0 :                         ctr1 = &ctr.ctr1;
     511           0 :                 } else if (level_out == 2 && ctr.ctr2.mszip1.ts) {
     512           0 :                         out_level = 1;
     513           0 :                         ctr1 = &ctr.ctr2.mszip1.ts->ctr1;
     514           0 :                 } else if (level_out == 6) {
     515           0 :                         out_level = 6;
     516           0 :                         ctr6 = &ctr.ctr6;
     517           0 :                 } else if (level_out == 7
     518           0 :                            && ctr.ctr7.level == 6
     519           0 :                            && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
     520           0 :                            && ctr.ctr7.ctr.mszip6.ts) {
     521           0 :                         out_level = 6;
     522           0 :                         ctr6 = &ctr.ctr7.ctr.mszip6.ts->ctr6;
     523           0 :                 } else if (level_out == 7
     524           0 :                            && ctr.ctr7.level == 6
     525           0 :                            && ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
     526           0 :                            && ctr.ctr7.ctr.xpress6.ts) {
     527           0 :                         out_level = 6;
     528           0 :                         ctr6 = &ctr.ctr7.ctr.xpress6.ts->ctr6;
     529             :                 }
     530             : 
     531           0 :                 if (out_level == 1) {
     532           0 :                         DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
     533             :                                 (long long)ctr1->new_highwatermark.tmp_highest_usn,
     534             :                                 (long long)ctr1->new_highwatermark.highest_usn));
     535             : 
     536           0 :                         first_object = ctr1->first_object;
     537           0 :                         mapping_ctr = &ctr1->mapping_ctr;
     538             : 
     539           0 :                         if (ctr1->more_data) {
     540           0 :                                 req->req5.highwatermark = ctr1->new_highwatermark;
     541             :                         } else {
     542           0 :                                 last_query = true;
     543           0 :                                 if (ctr1->uptodateness_vector &&
     544           0 :                                     !ctx->single_object_replication)
     545             :                                 {
     546           0 :                                         new_utdv->version = 1;
     547           0 :                                         new_utdv->ctr.ctr1.count =
     548           0 :                                                 ctr1->uptodateness_vector->count;
     549           0 :                                         new_utdv->ctr.ctr1.cursors =
     550           0 :                                                 ctr1->uptodateness_vector->cursors;
     551             :                                 }
     552             :                         }
     553           0 :                 } else if (out_level == 6) {
     554           0 :                         DEBUG(1,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
     555             :                                 (long long)ctr6->new_highwatermark.tmp_highest_usn,
     556             :                                 (long long)ctr6->new_highwatermark.highest_usn));
     557             : 
     558           0 :                         first_object = ctr6->first_object;
     559           0 :                         mapping_ctr = &ctr6->mapping_ctr;
     560             : 
     561           0 :                         linked_attributes = ctr6->linked_attributes;
     562           0 :                         linked_attributes_count = ctr6->linked_attributes_count;
     563             : 
     564           0 :                         if (ctr6->more_data) {
     565           0 :                                 req->req8.highwatermark = ctr6->new_highwatermark;
     566             :                         } else {
     567           0 :                                 last_query = true;
     568           0 :                                 if (ctr6->uptodateness_vector &&
     569           0 :                                     !ctx->single_object_replication)
     570             :                                 {
     571           0 :                                         new_utdv->version = 2;
     572           0 :                                         new_utdv->ctr.ctr2.count =
     573           0 :                                                 ctr6->uptodateness_vector->count;
     574           0 :                                         new_utdv->ctr.ctr2.cursors =
     575           0 :                                                 ctr6->uptodateness_vector->cursors;
     576             :                                 }
     577             :                         }
     578             :                 }
     579             : 
     580           0 :                 status = cli_get_session_key(mem_ctx, ctx->cli, &ctx->session_key);
     581           0 :                 if (!NT_STATUS_IS_OK(status)) {
     582           0 :                         ctx->error_message = talloc_asprintf(ctx,
     583             :                                 "Failed to get Session Key: %s",
     584             :                                 nt_errstr(status));
     585           0 :                         goto out;
     586             :                 }
     587             : 
     588           0 :                 libnet_dssync_decrypt_attributes(mem_ctx,
     589             :                                                  &ctx->session_key,
     590             :                                                  first_object);
     591             : 
     592           0 :                 if (ctx->ops->process_objects) {
     593           0 :                         status = ctx->ops->process_objects(ctx, mem_ctx,
     594             :                                                            first_object,
     595             :                                                            mapping_ctr);
     596           0 :                         if (!NT_STATUS_IS_OK(status)) {
     597           0 :                                 ctx->error_message = talloc_asprintf(ctx,
     598             :                                         "Failed to call processing function: %s",
     599             :                                         nt_errstr(status));
     600           0 :                                 goto out;
     601             :                         }
     602             :                 }
     603             : 
     604           0 :                 if (linked_attributes_count == 0) {
     605           0 :                         continue;
     606             :                 }
     607             : 
     608           0 :                 if (ctx->ops->process_links) {
     609           0 :                         status = ctx->ops->process_links(ctx, mem_ctx,
     610             :                                                          linked_attributes_count,
     611             :                                                          linked_attributes,
     612             :                                                          mapping_ctr);
     613           0 :                         if (!NT_STATUS_IS_OK(status)) {
     614           0 :                                 ctx->error_message = talloc_asprintf(ctx,
     615             :                                         "Failed to call processing function: %s",
     616             :                                         nt_errstr(status));
     617           0 :                                 goto out;
     618             :                         }
     619             :                 }
     620             :         }
     621             : 
     622           0 :         *pnew_utdv = new_utdv;
     623             : 
     624           0 : out:
     625           0 :         return status;
     626             : }
     627             : 
     628           0 : static NTSTATUS libnet_dssync_process(TALLOC_CTX *mem_ctx,
     629             :                                       struct dssync_context *ctx)
     630             : {
     631             :         NTSTATUS status;
     632             : 
     633           0 :         uint32_t level = 0;
     634             :         union drsuapi_DsGetNCChangesRequest req;
     635           0 :         struct replUpToDateVectorBlob *old_utdv = NULL;
     636           0 :         struct replUpToDateVectorBlob *pnew_utdv = NULL;
     637             :         const char **dns;
     638             :         uint32_t dn_count;
     639             :         uint32_t count;
     640             : 
     641           0 :         if (ctx->ops->startup) {
     642           0 :                 status = ctx->ops->startup(ctx, mem_ctx, &old_utdv);
     643           0 :                 if (!NT_STATUS_IS_OK(status)) {
     644           0 :                         ctx->error_message = talloc_asprintf(ctx,
     645             :                                 "Failed to call startup operation: %s",
     646             :                                 nt_errstr(status));
     647           0 :                         goto out;
     648             :                 }
     649             :         }
     650             : 
     651           0 :         if (ctx->single_object_replication && ctx->object_dns) {
     652           0 :                 dns = ctx->object_dns;
     653           0 :                 dn_count = ctx->object_count;
     654             :         } else {
     655           0 :                 dns = &ctx->nc_dn;
     656           0 :                 dn_count = 1;
     657             :         }
     658             : 
     659           0 :         status = NT_STATUS_OK;
     660             : 
     661           0 :         for (count=0; count < dn_count; count++) {
     662           0 :                 status = libnet_dssync_build_request(mem_ctx, ctx,
     663           0 :                                                      dns[count],
     664             :                                                      old_utdv, &level,
     665             :                                                      &req);
     666           0 :                 if (!NT_STATUS_IS_OK(status)) {
     667           0 :                         goto out;
     668             :                 }
     669             : 
     670           0 :                 status = libnet_dssync_getncchanges(mem_ctx, ctx, level, &req,
     671             :                                                     &pnew_utdv);
     672           0 :                 if (!NT_STATUS_IS_OK(status)) {
     673           0 :                         if (!ctx->error_message) {
     674           0 :                                 ctx->error_message = talloc_asprintf(ctx,
     675             :                                         "Failed to call DsGetNCCHanges: %s",
     676             :                                         nt_errstr(status));
     677             :                         }
     678           0 :                         goto out;
     679             :                 }
     680             :         }
     681             : 
     682           0 :         if (ctx->ops->finish) {
     683           0 :                 status = ctx->ops->finish(ctx, mem_ctx, pnew_utdv);
     684           0 :                 if (!NT_STATUS_IS_OK(status)) {
     685           0 :                         ctx->error_message = talloc_asprintf(ctx,
     686             :                                 "Failed to call finishing operation: %s",
     687             :                                 nt_errstr(status));
     688           0 :                         goto out;
     689             :                 }
     690             :         }
     691             : 
     692           0 :  out:
     693           0 :         return status;
     694             : }
     695             : 
     696             : /****************************************************************
     697             : ****************************************************************/
     698             : 
     699           0 : NTSTATUS libnet_dssync(TALLOC_CTX *mem_ctx,
     700             :                        struct dssync_context *ctx)
     701             : {
     702             :         NTSTATUS status;
     703             :         TALLOC_CTX *tmp_ctx;
     704             : 
     705           0 :         tmp_ctx = talloc_new(mem_ctx);
     706           0 :         if (!tmp_ctx) {
     707           0 :                 return NT_STATUS_NO_MEMORY;
     708             :         }
     709             : 
     710           0 :         status = libnet_dssync_init(tmp_ctx, ctx);
     711           0 :         if (!NT_STATUS_IS_OK(status)) {
     712           0 :                 goto out;
     713             :         }
     714             : 
     715           0 :         status = libnet_dssync_process(tmp_ctx, ctx);
     716           0 :         if (!NT_STATUS_IS_OK(status)) {
     717           0 :                 goto out;
     718             :         }
     719             : 
     720           0 :  out:
     721           0 :         TALLOC_FREE(tmp_ctx);
     722           0 :         return status;
     723             : }
     724             : 

Generated by: LCOV version 1.13