+/*
+ convert from one udv format to the other
+ */
+static WERROR udv_convert(TALLOC_CTX *mem_ctx,
+ const struct replUpToDateVectorCtr2 *udv,
+ struct drsuapi_DsReplicaCursorCtrEx *udv_ex)
+{
+ int i;
+
+ udv_ex->version = 2;
+ udv_ex->reserved1 = 0;
+ udv_ex->reserved2 = 0;
+ udv_ex->count = udv->count;
+ udv_ex->cursors = talloc_array(mem_ctx, struct drsuapi_DsReplicaCursor, udv->count);
+ W_ERROR_HAVE_NO_MEMORY(udv_ex->cursors);
+
+ for (i=0; i<udv->count; i++) {
+ udv_ex->cursors[i].source_dsa_invocation_id = udv->cursors[i].source_dsa_invocation_id;
+ udv_ex->cursors[i].highest_usn = udv->cursors[i].highest_usn;
+ }
+
+ return WERR_OK;
+}
+
+/*
+ add our local UDV element for the partition
+ */
+static WERROR add_local_udv(struct dreplsrv_service *s,
+ struct dreplsrv_partition *p,
+ const struct GUID *our_invocation_id,
+ struct drsuapi_DsReplicaCursorCtrEx *udv)
+{
+ int ret;
+ uint64_t highest_usn;
+ int i;
+
+ ret = dsdb_load_partition_usn(s->samdb, p->dn, &highest_usn);
+ if (ret != LDB_SUCCESS) {
+ /* nothing to add */
+ return WERR_OK;
+ }
+
+ for (i=0; i<udv->count; i++) {
+ if (GUID_equal(our_invocation_id, &udv->cursors[i].source_dsa_invocation_id)) {
+ udv->cursors[i].highest_usn = highest_usn;
+ return WERR_OK;
+ }
+ }
+
+ udv->cursors = talloc_realloc(p, udv->cursors, struct drsuapi_DsReplicaCursor, udv->count+1);
+ W_ERROR_HAVE_NO_MEMORY(udv->cursors);
+
+ udv->cursors[udv->count].source_dsa_invocation_id = *our_invocation_id;
+ udv->cursors[udv->count].highest_usn = highest_usn;
+ udv->count++;
+
+ return WERR_OK;
+}
+