<div class="content"><p align="right"><a href="https://msdn.microsoft.com/en-us/library/31fc80bd-4f4d-4512-a792-e488bb78f6a0" data-linktype="external">msdn link</a></p><p>The <b>NetrDatabaseSync2</b> method SHOULD<a id="Appendix_A_Target_220"></a><a aria-label="Product behavior note 220" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_220" data-linktype="relative-path">&lt;220&gt;</a> return a set of all changes
applied to the specified <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_00f35ba3-4dbb-4ff9-8e27-572a6aea1b15" data-linktype="relative-path">database</a>
since its creation. It provides an interface for a BDC to fully synchronize its
databases to those of the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_663cb13a-8b75-477f-b6e1-bea8f2fba64d" data-linktype="relative-path">PDC</a>.
Because returning all changes in one call might be prohibitively expensive due
to a large amount of data being returned, this method supports retrieving
portions of the database changes in a series of calls using a continuation
context until all changes are received. It is possible for the series of calls
to be terminated prematurely due to external events, such as system restarts.
For that reason, the method also supports restarting the series of calls at a
particular point specified by the caller. The caller MUST keep track of
synchronization progress during the series of calls as detailed in this
section.  </p><dl>
<dd>
<div><pre> NTSTATUS NetrDatabaseSync2(
   [in, string] LOGONSRV_HANDLE PrimaryName,
   [in, string] wchar_t* ComputerName,
   [in] PNETLOGON_AUTHENTICATOR Authenticator,
   [in, out] PNETLOGON_AUTHENTICATOR ReturnAuthenticator,
   [in] DWORD DatabaseID,
   [in] SYNC_STATE RestartState,
   [in, out] ULONG * SyncContext,
   [out] PNETLOGON_DELTA_ENUM_ARRAY* DeltaArray,
   [in] DWORD PreferredMaximumLength
 );
</pre></div>
</dd></dl><p><b>PrimaryName: </b>The custom binding handle, as
defined in section <a href="3b224201-b531-43e2-8c79-b61f6dea8640" data-linktype="relative-path">3.5.4.1</a>,
that represents the connection to the PDC. </p><p><b>ComputerName: </b>The null-terminated Unicode
string that contains the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_0334e0bd-2755-42f6-aeff-2d4a22bf4abf" data-linktype="relative-path">NetBIOS
name</a> of the BDC calling this method. </p><p><b>Authenticator: </b>A pointer to a <a href="76c93227-942a-4687-ab9d-9d972ffabdab" data-linktype="relative-path">NETLOGON_AUTHENTICATOR</a>
structure, as specified in section 2.2.1.1.5, that contains the client <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_e72a2c02-84a2-4ce3-b66f-86f725642dc3" data-linktype="relative-path">authenticator</a>. </p><p><b>ReturnAuthenticator: </b>A pointer to a
NETLOGON_AUTHENTICATOR structure, as specified in section 2.2.1.1.5, that
contains the server return authenticator. </p><p><b>DatabaseID: </b>The identifier for a specific
database for which the changes are requested. It MUST be one of the following
values.</p><dl>
<dd>
<table><thead>
  <tr>
   <th>
   <p>Value</p>
   </th>
   <th>
   <p>Meaning</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>0x00000000</p>
  </td>
  <td>
  <p>Indicates the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_6bb6ffcf-2a22-4989-89ef-6c9937f91b8b" data-linktype="relative-path">SAM database</a>.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000001</p>
  </td>
  <td>
  <p>Indicates the SAM built-in database.</p>
  </td>
 </tr><tr>
  <td>
  <p>0x00000002</p>
  </td>
  <td>
  <p>Indicates the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_48a53a9a-6c9a-4df8-9882-1eccdf32340b" data-linktype="relative-path">LSA database</a>. </p>
  </td>
 </tr></tbody></table>
</dd></dl><p><b>RestartState: </b>Specifies whether this is a
restart of the series of the synchronization calls and how to interpret <i>SyncContext</i>.
This value MUST be NormalState unless this is the restart, in which case the
value MUST be set as specified in the description of the <i>SyncContext</i>
parameter.</p><p><b>SyncContext: </b>Specifies context needed to
continue the operation. The value MUST be set to zero on the first call. The
caller MUST treat this as an opaque value, unless this call is a restart of the
series of synchronization calls. The value returned is to be used on input for
the next call in the series of synchronization calls.</p><dl>
<dd>
<p>If this call is the restart of the series, the
values of the <i>RestartState</i> and the <i>SyncContext</i> parameters are
dependent on the <b>DeltaType</b> value received on the last call before the
restart and MUST be set as follows. Find the last <a href="20e5863c-0142-40f6-a914-f352a9d66047" data-linktype="relative-path">NETLOGON_DELTA_ENUM</a>
structure in the <i>DeltaArray</i> parameter of the call. The <b>DeltaType</b>
field of this NETLOGON_DELTA_ENUM structure, as specified in section
2.2.1.5.11, is the <b>DeltaType</b> needed for the restart. The values of <i>RestartState</i>
and <i>SyncContext</i> are then determined from the following table. </p>
</dd>
<dd>
<table><thead>
  <tr>
   <th>
   <p>DeltaType</p>
   </th>
   <th>
   <p>RestartState</p>
   </th>
   <th>
   <p>SyncContext</p>
   </th>
  </tr>
 </thead><tbody><tr>
  <td>
  <p>AddOrChangeGroup</p>
  </td>
  <td>
  <p>GroupState</p>
  </td>
  <td>
  <p>The value of the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_df3d0b61-56cd-4dac-9402-982f1fedc41c" data-linktype="relative-path">RID</a> of the last element </p>
  </td>
 </tr><tr>
  <td>
  <p>AddOrChangeUser</p>
  </td>
  <td>
  <p>UserState</p>
  </td>
  <td>
  <p>The value of the RID of the last element </p>
  </td>
 </tr><tr>
  <td>
  <p>ChangeGroupMembership</p>
  </td>
  <td>
  <p>GroupMemberState</p>
  </td>
  <td>
  <p>The value of the RID of the last element </p>
  </td>
 </tr><tr>
  <td>
  <p>AddOrChangeAlias</p>
  </td>
  <td>
  <p>AliasState</p>
  </td>
  <td>
  <p>0x00000000</p>
  </td>
 </tr><tr>
  <td>
  <p>ChangeAliasMembership</p>
  </td>
  <td>
  <p>AliasMemberState</p>
  </td>
  <td>
  <p>0x00000000</p>
  </td>
 </tr><tr>
  <td>
  <p>Any other value not previously listed</p>
  </td>
  <td>
  <p>NormalState</p>
  </td>
  <td>
  <p>0x00000000</p>
  </td>
 </tr></tbody></table>
</dd></dl><p><b>DeltaArray: </b>A pointer to a <a href="82d47318-c4d8-4583-86a6-ce186504bcba" data-linktype="relative-path">NETLOGON_DELTA_ENUM_ARRAY</a>
structure, as specified in section 2.2.1.5.12, that contains an array of
enumerated changes (<a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_bac72edb-4ce9-4baa-8977-f33e331b2b5e" data-linktype="relative-path">deltas</a>)
to the specified database.</p><p><b>PreferredMaximumLength: </b>The value that
specifies the preferred maximum size, in bytes, of data referenced in the <i>DeltaArray</i>
parameter. This is not a hard upper limit but serves as a guide to the server.
The server SHOULD<a id="Appendix_A_Target_221"></a><a aria-label="Product behavior note 221" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_221" data-linktype="relative-path">&lt;221&gt;</a> stop including elements in
the returned <i>DeltaArray</i> once the size of the returned data equals or
exceeds the value of the <i>PreferredMaximumLength</i> parameter. It is up to
the client implementation to choose the value for this parameter.</p><p><b>Return Values: </b>The method returns 0x00000000
on success; otherwise, it returns a nonzero error code. </p><p>The server that receives this call MUST do the following:</p><ul><li><p><span><span> 
</span></span>Verify that the client is a <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_ce1138c6-7ab4-4c37-98b4-95599071c3c3" data-linktype="relative-path">backup domain controller (BDC)</a>,
the server is a PDC, and is enabled. If any of these conditions are false, the
server MUST return the status code STATUS_NOT_SUPPORTED.</p>
</li><li><p><span><span> 
</span></span>Apply Common Error Processing Rule B, specified in section <a href="2d776bfc-e81f-4c8f-9da8-4c2920f65413" data-linktype="relative-path">3</a>.</p>
</li><li><p><span><span> 
</span></span>Using the <i>ComputerName</i> for the <a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_08ce423c-9f9c-48ed-afa8-8b64c04ecdca" data-linktype="relative-path">secure channel</a> to find the
corresponding record in the ClientSessionInfo table, verify the <i>Authenticator</i>
parameter (section <a href="da7acaa3-030b-481e-979b-f58f89389806" data-linktype="relative-path">3.1.4.5</a>).
If the <i>Authenticator</i> parameter is valid, compute the <i>ReturnAuthenticator</i>
parameter returned (section 3.1.4.5). Otherwise, the server MUST return
STATUS_ACCESS_DENIED.</p>
</li><li><p><span><span> 
</span></span>Validate that <i>DatabaseID</i> is one of the allowed values,
0x00000000 through 0x00000002. If the <i>DatabaseID</i> is not one of these
values, the server MUST return the status code STATUS_INVALID_LEVEL.</p>
</li><li><p><span><span> 
</span></span>Given the <i>RestartState</i> parameter and the <i>SyncContext</i>
parameter, obtain database records that are missing on the BDC and return the
array of deltas, NETLOGON_DELTA_ENUM_ARRAY, for the missing records. The number
of elements returned is affected by the value of the <i>PreferredMaximumLength</i>
parameter. The server SHOULD<a id="Appendix_A_Target_222"></a><a aria-label="Product behavior note 222" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_222" data-linktype="relative-path">&lt;222&gt;</a> stop
including elements in the returned array once the size of the returned data
equals or exceeds the value of the <i>PreferredMaximumLength</i> parameter. The
server SHOULD also limit the number of elements per local configuration to
avoid large array allocations.</p>
</li><li><p><span><span> 
</span></span>The server MUST update and return the <i>SyncContext</i>
parameter (section <a href="ffce9bbc-6ae5-4478-8f45-e82c3847aaa2" data-linktype="relative-path">2.2.1.5.29</a>)
to continue the synchronization loop on the next client request.</p>
</li><li><p><span><span> 
</span></span>Compute and return the server authenticator.</p>
</li><li><p><span><span> 
</span></span>Initialize <b>SynchronizationComplete</b> by setting it to FALSE,
and when all the missing records are sent set <b>SynchronizationComplete</b> to
TRUE.</p>
</li><li><p><span><span> 
</span></span>If <b>SynchronizationComplete</b> is FALSE, the server MUST
return the status code STATUS_MORE_ENTRIES.</p>
</li></ul></div>