<div class="content" name="NetrDatabaseSync2" uuid="31fc80bd-4f4d-4512-a792-e488bb78f6a0"><p>The <b>NetrDatabaseSync2</b> method SHOULD<a id="Appendix_A_Target_230"></a><a aria-label="Product behavior note 230" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_230" data-linktype="relative-path">&lt;230&gt;</a> return a set of all changes
applied to the specified <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_00f35ba3-4dbb-4ff9-8e27-572a6aea1b15" data-linktype="relative-path">database</a></span> since its
creation. It provides an interface for a BDC to fully synchronize its databases
to those of the <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_663cb13a-8b75-477f-b6e1-bea8f2fba64d" data-linktype="relative-path">PDC</a></span>. 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, range(0,256)] 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 <span><a href="3b224201-b531-43e2-8c79-b61f6dea8640" data-linktype="relative-path">3.5.4.1</a></span>, that
represents the connection to the PDC. </p><p><b>ComputerName: </b>The null-terminated Unicode
string that contains the <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_0334e0bd-2755-42f6-aeff-2d4a22bf4abf" data-linktype="relative-path">NetBIOS name</a></span> of the
BDC calling this method. </p><p><b>Authenticator: </b>A pointer to a <b>NETLOGON_AUTHENTICATOR</b>
structure, as specified in section <span><a href="76c93227-942a-4687-ab9d-9d972ffabdab" data-linktype="relative-path">2.2.1.1.5</a></span>, that
contains the client <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_e72a2c02-84a2-4ce3-b66f-86f725642dc3" data-linktype="relative-path">authenticator</a></span>. </p><p><b>ReturnAuthenticator: </b>A pointer to a <b>NETLOGON_AUTHENTICATOR</b>
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>0x00000000</td>
  <td>Indicates the SAM database.</td>
 </tr><tr>
  <td>0x00000001</td>
  <td>Indicates the SAM built-in database.</td>
 </tr><tr>
  <td>0x00000002</td>
  <td>Indicates the LSA database.</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 <span><a href="20e5863c-0142-40f6-a914-f352a9d66047" data-linktype="relative-path">NETLOGON_DELTA_ENUM</a></span>
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>AddOrChangeGroup</td>
  <td>GroupState</td>
  <td>The value of the RID of the last element</td>
 </tr><tr>
  <td>AddOrChangeUser</td>
  <td>UserState</td>
  <td>The value of the RID of the last element</td>
 </tr><tr>
  <td>ChangeGroupMembership</td>
  <td>GroupMemberState</td>
  <td>The value of the RID of the last element</td>
 </tr><tr>
  <td>AddOrChangeAlias</td>
  <td>AliasState</td>
  <td>0x00000000</td>
 </tr><tr>
  <td>ChangeAliasMembership</td>
  <td>AliasMemberState</td>
  <td>0x00000000</td>
 </tr><tr>
  <td>Any other value not previously listed</td>
  <td>NormalState</td>
  <td>0x00000000</td>
 </tr></tbody></table>
</dd></dl><p><b>DeltaArray: </b>A pointer to a <span><a href="82d47318-c4d8-4583-86a6-ce186504bcba" data-linktype="relative-path">NETLOGON_DELTA_ENUM_ARRAY</a></span>
structure, as specified in section 2.2.1.5.12, that contains an array of
enumerated changes (<span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_bac72edb-4ce9-4baa-8977-f33e331b2b5e" data-linktype="relative-path">deltas</a></span>) 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_231"></a><a aria-label="Product behavior note 231" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_231" data-linktype="relative-path">&lt;231&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 <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_ce1138c6-7ab4-4c37-98b4-95599071c3c3" data-linktype="relative-path">backup domain controller (BDC)</a></span>,
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 <span><a href="2d776bfc-e81f-4c8f-9da8-4c2920f65413" data-linktype="relative-path">3</a></span>.</p>
</li><li><p><span><span> 
</span></span>Using the <i>ComputerName</i> for the <span><a href="b5e7d25a-40b2-41c8-9611-98f53358af66#gt_08ce423c-9f9c-48ed-afa8-8b64c04ecdca" data-linktype="relative-path">secure channel</a></span> to
find the corresponding record in the ClientSessionInfo table, verify the <i>Authenticator</i>
parameter (section <span><a href="da7acaa3-030b-481e-979b-f58f89389806" data-linktype="relative-path">3.1.4.5</a></span>). 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_232"></a><a aria-label="Product behavior note 232" href="0c858a52-732a-43ec-85dd-e44b357c1898#Appendix_A_232" data-linktype="relative-path">&lt;232&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 <span><a href="ffce9bbc-6ae5-4478-8f45-e82c3847aaa2" data-linktype="relative-path">2.2.1.5.29</a></span>) 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>