home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / C_C++ / BorlandCompiler / freecommandLinetools.exe / Include / ntdsapi.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-27  |  79.9 KB  |  2,526 lines

  1. /*++ BUILD Version: 0001    // Increment this if a change has global effects
  2.  
  3. Copyright (c) 1996-1999 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     ntdsapi.h
  8.  
  9. Abstract:
  10.  
  11.     This file contains structures, function prototypes, and definitions
  12.     for public NTDS APIs other than directory interfaces like LDAP.
  13.  
  14. Environment:
  15.  
  16.     User Mode - Win32
  17.  
  18. Notes:
  19.  
  20. --*/
  21.  
  22.  
  23. #ifndef _NTDSAPI_H_
  24. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  25. #define _NTDSAPI_H_
  26.  
  27. #if _MSC_VER > 1000
  28. #pragma once
  29. #endif
  30.  
  31. #include <schedule.h>
  32.  
  33. #if !defined(_NTDSAPI_)
  34. #define NTDSAPI DECLSPEC_IMPORT
  35. #else
  36. #define NTDSAPI
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. //////////////////////////////////////////////////////////////////////////
  44. //                                                                      //
  45. // Data definitions                                                     //
  46. //                                                                      //
  47. //////////////////////////////////////////////////////////////////////////
  48.  
  49. #ifdef MIDL_PASS
  50. typedef GUID UUID;
  51. typedef void * RPC_AUTH_IDENTITY_HANDLE;
  52. typedef void VOID;
  53. #endif
  54.  
  55. #define DS_DEFAULT_LOCALE                                           \
  56.            (MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),  \
  57.                      SORT_DEFAULT))
  58.  
  59. #define DS_DEFAULT_LOCALE_COMPARE_FLAGS    (NORM_IGNORECASE     |   \
  60.                                             NORM_IGNOREKANATYPE |   \
  61.                                             NORM_IGNORENONSPACE |   \
  62.                                             NORM_IGNOREWIDTH)
  63.  
  64. // When booted to DS mode, this event is signalled when the DS has completed
  65. // its initial sync attempts.  The period of time between system startup and
  66. // this event's state being set is indeterminate from the local service's
  67. // standpoint.  In the meantime the contents of the DS should be considered
  68. // incomplete / out-dated, and the machine will not be advertised as a domain
  69. // controller to off-machine clients.  Other local services that rely on
  70. // information published in the DS should avoid accessing (or at least
  71. // relying on) the contents of the DS until this event is set.
  72. #define DS_SYNCED_EVENT_NAME    "NTDSInitialSyncsCompleted"
  73. #define DS_SYNCED_EVENT_NAME_W L"NTDSInitialSyncsCompleted"
  74.  
  75. // Permissions bits used in security descriptors in the directory.
  76. #ifndef _DS_CONTROL_BITS_DEFINED_
  77. #define _DS_CONTROL_BITS_DEFINED_
  78. #define ACTRL_DS_OPEN                           0x00000000
  79. #define ACTRL_DS_CREATE_CHILD                   0x00000001
  80. #define ACTRL_DS_DELETE_CHILD                   0x00000002
  81. #define ACTRL_DS_LIST                           0x00000004
  82. #define ACTRL_DS_SELF                           0x00000008
  83. #define ACTRL_DS_READ_PROP                      0x00000010
  84. #define ACTRL_DS_WRITE_PROP                     0x00000020
  85. #define ACTRL_DS_DELETE_TREE                    0x00000040
  86. #define ACTRL_DS_LIST_OBJECT                    0x00000080
  87. #define ACTRL_DS_CONTROL_ACCESS                 0x00000100
  88.  
  89. // generic read
  90. #define DS_GENERIC_READ          ((STANDARD_RIGHTS_READ)     | \
  91.                                   (ACTRL_DS_LIST)            | \
  92.                                   (ACTRL_DS_READ_PROP)       | \
  93.                                   (ACTRL_DS_LIST_OBJECT))
  94.  
  95. // generic execute
  96. #define DS_GENERIC_EXECUTE       ((STANDARD_RIGHTS_EXECUTE)  | \
  97.                                   (ACTRL_DS_LIST))
  98. // generic right
  99. #define DS_GENERIC_WRITE         ((STANDARD_RIGHTS_WRITE)    | \
  100.                                   (ACTRL_DS_SELF)            | \
  101.                                   (ACTRL_DS_WRITE_PROP))
  102. // generic all
  103.  
  104. #define DS_GENERIC_ALL           ((STANDARD_RIGHTS_REQUIRED) | \
  105.                                   (ACTRL_DS_CREATE_CHILD)    | \
  106.                                   (ACTRL_DS_DELETE_CHILD)    | \
  107.                                   (ACTRL_DS_DELETE_TREE)     | \
  108.                                   (ACTRL_DS_READ_PROP)       | \
  109.                                   (ACTRL_DS_WRITE_PROP)      | \
  110.                                   (ACTRL_DS_LIST)            | \
  111.                                   (ACTRL_DS_LIST_OBJECT)     | \
  112.                                   (ACTRL_DS_CONTROL_ACCESS)  | \
  113.                                   (ACTRL_DS_SELF))
  114. #endif
  115.  
  116. typedef enum
  117. {
  118.     // unknown name type
  119.     DS_UNKNOWN_NAME = 0,
  120.  
  121.     // eg: CN=Spencer Katt,OU=Users,DC=Engineering,DC=Widget,DC=Com
  122.     DS_FQDN_1779_NAME = 1,
  123.  
  124.     // eg: Engineering\SpencerK
  125.     // Domain-only version includes trailing '\\'.
  126.     DS_NT4_ACCOUNT_NAME = 2,
  127.  
  128.     // Probably "Spencer Katt" but could be something else.  I.e. The
  129.     // display name is not necessarily the defining RDN.
  130.     DS_DISPLAY_NAME = 3,
  131.  
  132.     // obsolete - see #define later
  133.     // DS_DOMAIN_SIMPLE_NAME = 4,
  134.  
  135.     // obsolete - see #define later
  136.     // DS_ENTERPRISE_SIMPLE_NAME = 5,
  137.  
  138.     // String-ized GUID as returned by IIDFromString().
  139.     // eg: {4fa050f0-f561-11cf-bdd9-00aa003a77b6}
  140.     DS_UNIQUE_ID_NAME = 6,
  141.  
  142.     // eg: engineering.widget.com/software/spencer katt
  143.     // Domain-only version includes trailing '/'.
  144.     DS_CANONICAL_NAME = 7,
  145.  
  146.     // eg: spencerk@engineering.widget.com
  147.     DS_USER_PRINCIPAL_NAME = 8,
  148.  
  149.     // Same as DS_CANONICAL_NAME except that rightmost '/' is
  150.     // replaced with '\n' - even in domain-only case.
  151.     // eg: engineering.widget.com/software\nspencer katt
  152.     DS_CANONICAL_NAME_EX = 9,
  153.  
  154.     // eg: www/www.widget.com@widget.com - generalized service principal
  155.     // names.
  156.     DS_SERVICE_PRINCIPAL_NAME = 10,
  157.  
  158.     // This is the string representation of a SID.  Invalid for formatDesired.
  159.     // See sddl.h for SID binary <--> text conversion routines.
  160.     // eg: S-1-5-21-397955417-626881126-188441444-501
  161.     DS_SID_OR_SID_HISTORY_NAME = 11
  162.  
  163. } DS_NAME_FORMAT;
  164.  
  165. // Map old name formats to closest new format so that old code builds
  166. // against new headers w/o errors and still gets (almost) correct result.
  167.  
  168. #define DS_DOMAIN_SIMPLE_NAME       DS_USER_PRINCIPAL_NAME
  169. #define DS_ENTERPRISE_SIMPLE_NAME   DS_USER_PRINCIPAL_NAME
  170.  
  171. typedef enum
  172. {
  173.     DS_NAME_NO_FLAGS = 0x0,
  174.  
  175.     // Perform a syntactical mapping at the client (if possible) without
  176.     // going out on the wire.  Returns DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING
  177.     // if a purely syntactical mapping is not possible.
  178.     DS_NAME_FLAG_SYNTACTICAL_ONLY = 0x1,
  179.  
  180.     // Force a trip to the DC for evaluation, even if this could be
  181.     // locally cracked syntactically.
  182.     DS_NAME_FLAG_EVAL_AT_DC = 0x2
  183.  
  184. } DS_NAME_FLAGS;
  185.  
  186. typedef enum
  187. {
  188.     DS_NAME_NO_ERROR = 0,
  189.  
  190.     // Generic processing error.
  191.     DS_NAME_ERROR_RESOLVING = 1,
  192.  
  193.     // Couldn't find the name at all - or perhaps caller doesn't have
  194.     // rights to see it.
  195.     DS_NAME_ERROR_NOT_FOUND = 2,
  196.  
  197.     // Input name mapped to more than one output name.
  198.     DS_NAME_ERROR_NOT_UNIQUE = 3,
  199.  
  200.     // Input name found, but not the associated output format.
  201.     // Can happen if object doesn't have all the required attributes.
  202.     DS_NAME_ERROR_NO_MAPPING = 4,
  203.  
  204.     // Unable to resolve entire name, but was able to determine which
  205.     // domain object resides in.  Thus DS_NAME_RESULT_ITEM?.pDomain
  206.     // is valid on return.
  207.     DS_NAME_ERROR_DOMAIN_ONLY = 5,
  208.  
  209.     // Unable to perform a purely syntactical mapping at the client
  210.     // without going out on the wire.
  211.     DS_NAME_ERROR_NO_SYNTACTICAL_MAPPING = 6
  212.  
  213. } DS_NAME_ERROR;
  214.  
  215. #define DS_NAME_LEGAL_FLAGS (DS_NAME_FLAG_SYNTACTICAL_ONLY)
  216.  
  217. typedef enum {
  218.  
  219.     // "paulle-nec.ntwksta.ms.com"
  220.     DS_SPN_DNS_HOST = 0,
  221.  
  222.     // "cn=paulle-nec,ou=computers,dc=ntwksta,dc=ms,dc=com"
  223.     DS_SPN_DN_HOST = 1,
  224.  
  225.     // "paulle-nec"
  226.     DS_SPN_NB_HOST = 2,
  227.  
  228.     // "ntdev.ms.com"
  229.     DS_SPN_DOMAIN = 3,
  230.  
  231.     // "ntdev"
  232.     DS_SPN_NB_DOMAIN = 4,
  233.  
  234.     // "cn=anRpcService,cn=RPC Services,cn=system,dc=ms,dc=com"
  235.     // "cn=aWsService,cn=Winsock Services,cn=system,dc=ms,dc=com"
  236.     // "cn=aService,dc=itg,dc=ms,dc=com"
  237.     // "www.ms.com", "ftp.ms.com", "ldap.ms.com"
  238.     // "products.ms.com"
  239.     DS_SPN_SERVICE = 5
  240.  
  241. } DS_SPN_NAME_TYPE;
  242.  
  243. typedef enum {                          // example:
  244.         DS_SPN_ADD_SPN_OP = 0,          // add SPNs
  245.         DS_SPN_REPLACE_SPN_OP = 1,      // set all SPNs
  246.         DS_SPN_DELETE_SPN_OP = 2        // Delete SPNs
  247. } DS_SPN_WRITE_OP;
  248.  
  249. typedef struct
  250. {
  251.     DWORD                   status;     // DS_NAME_ERROR
  252. #ifdef MIDL_PASS
  253.     [string,unique] CHAR    *pDomain;   // DNS domain
  254.     [string,unique] CHAR    *pName;     // name in requested format
  255. #else
  256.     LPSTR                   pDomain;    // DNS domain
  257.     LPSTR                   pName;      // name in requested format
  258. #endif
  259.  
  260. } DS_NAME_RESULT_ITEMA, *PDS_NAME_RESULT_ITEMA;
  261.  
  262. typedef struct
  263. {
  264.     DWORD                   cItems;     // item count
  265. #ifdef MIDL_PASS
  266.     [size_is(cItems)] PDS_NAME_RESULT_ITEMA rItems;
  267. #else
  268.     PDS_NAME_RESULT_ITEMA    rItems;    // item array
  269. #endif
  270.  
  271. } DS_NAME_RESULTA, *PDS_NAME_RESULTA;
  272.  
  273. typedef struct
  274. {
  275.     DWORD                   status;     // DS_NAME_ERROR
  276. #ifdef MIDL_PASS
  277.     [string,unique] WCHAR   *pDomain;   // DNS domain
  278.     [string,unique] WCHAR   *pName;     // name in requested format
  279. #else
  280.     LPWSTR                  pDomain;    // DNS domain
  281.     LPWSTR                  pName;      // name in requested format
  282. #endif
  283.  
  284. } DS_NAME_RESULT_ITEMW, *PDS_NAME_RESULT_ITEMW;
  285.  
  286. typedef struct
  287. {
  288.     DWORD                   cItems;     // item count
  289. #ifdef MIDL_PASS
  290.     [size_is(cItems)] PDS_NAME_RESULT_ITEMW rItems;
  291. #else
  292.     PDS_NAME_RESULT_ITEMW    rItems;    // item array
  293. #endif
  294.  
  295. } DS_NAME_RESULTW, *PDS_NAME_RESULTW;
  296.  
  297. #ifdef UNICODE
  298. #define DS_NAME_RESULT DS_NAME_RESULTW
  299. #define PDS_NAME_RESULT PDS_NAME_RESULTW
  300. #define DS_NAME_RESULT_ITEM DS_NAME_RESULT_ITEMW
  301. #define PDS_NAME_RESULT_ITEM PDS_NAME_RESULT_ITEMW
  302. #else
  303. #define DS_NAME_RESULT DS_NAME_RESULTA
  304. #define PDS_NAME_RESULT PDS_NAME_RESULTA
  305. #define DS_NAME_RESULT_ITEM DS_NAME_RESULT_ITEMA
  306. #define PDS_NAME_RESULT_ITEM PDS_NAME_RESULT_ITEMA
  307. #endif
  308.  
  309. // Public replication option flags
  310.  
  311. // ********************
  312. // Replica Sync flags
  313. // ********************
  314.  
  315. // Perform this operation asynchronously.
  316. // Required when using DS_REPSYNC_ALL_SOURCES
  317. #define DS_REPSYNC_ASYNCHRONOUS_OPERATION 0x00000001
  318.  
  319. // Writeable replica.  Otherwise, read-only.
  320. #define DS_REPSYNC_WRITEABLE              0x00000002
  321.  
  322. // This is a periodic sync request as scheduled by the admin.
  323. #define DS_REPSYNC_PERIODIC               0x00000004
  324.  
  325. // Use inter-site messaging
  326. #define DS_REPSYNC_INTERSITE_MESSAGING    0x00000008
  327.  
  328. // Sync from all sources.
  329. #define DS_REPSYNC_ALL_SOURCES            0x00000010
  330.  
  331. // Sync starting from scratch (i.e., at the first USN).
  332. #define DS_REPSYNC_FULL                   0x00000020
  333.  
  334. // This is a notification of an update that was marked urgent.
  335. #define DS_REPSYNC_URGENT                 0x00000040
  336.  
  337. // Don't discard this synchronization request, even if a similar
  338. // sync is pending.
  339. #define DS_REPSYNC_NO_DISCARD             0x00000080
  340.  
  341. // Sync even if link is currently disabled.
  342. #define DS_REPSYNC_FORCE                  0x00000100
  343.  
  344. // Causes the source DSA to check if a reps-to is present for the local DSA
  345. // (aka the destination). If not, one is added.  This ensures that
  346. // source sends change notifications.
  347. #define DS_REPSYNC_ADD_REFERENCE          0x00000200
  348.  
  349. // A sync from this source has never completed (e.g., a new source).
  350. #define DS_REPSYNC_NEVER_COMPLETED        0x00000400
  351.  
  352. // When this sync is complete, requests a sync in the opposite direction.
  353. #define DS_REPSYNC_TWO_WAY                0x00000800
  354.  
  355.  
  356.  
  357. // ********************
  358. // Replica Add flags
  359. // ********************
  360.  
  361. // Perform this operation asynchronously.
  362. #define DS_REPADD_ASYNCHRONOUS_OPERATION  0x00000001
  363.  
  364. // Create a writeable replica.  Otherwise, read-only.
  365. #define DS_REPADD_WRITEABLE               0x00000002
  366.  
  367. // Sync the NC from this source when the DSA is started.
  368. #define DS_REPADD_INITIAL                 0x00000004
  369.  
  370. // Sync the NC from this source periodically, as defined by the
  371. // schedule passed in the preptimesSync argument.
  372. #define DS_REPADD_PERIODIC                0x00000008
  373.  
  374. // Sync from the source DSA via an Intersite Messaging Service (ISM) transport
  375. // (e.g., SMTP) rather than native DS RPC.
  376. #define DS_REPADD_INTERSITE_MESSAGING     0x00000010
  377.  
  378. // Don't replicate the NC now -- just save enough state such that we
  379. // know to replicate it later.
  380. #define DS_REPADD_ASYNCHRONOUS_REPLICA     0x00000020
  381.  
  382. // Disable notification-based synchronization for the NC from this source.
  383. // This is expected to be a temporary state; the similar flag
  384. // DS_REPADD_NEVER_NOTIFY should be used if the disable is to be more permanent.
  385. #define DS_REPADD_DISABLE_NOTIFICATION     0x00000040
  386.  
  387. // Disable periodic synchronization for the NC from this source
  388. #define DS_REPADD_DISABLE_PERIODIC         0x00000080
  389.  
  390. // Use compression when replicating.  Saves message size (e.g., network
  391. // bandwidth) at the expense of extra CPU overhead at both the source and
  392. // destination servers.
  393. #define DS_REPADD_USE_COMPRESSION          0x00000100
  394.  
  395. // Do not request change notifications from this source.  When this flag is
  396. // set, the source will not notify the destination when changes occur.
  397. // Recommended for all intersite replication, which may occur over WAN links.
  398. // This is expected to be a more or less permanent state; the similar flag
  399. // DS_REPADD_DISABLE_NOTIFICATION should be used if notifications are to be
  400. // disabled only temporarily.
  401. #define DS_REPADD_NEVER_NOTIFY             0x00000200
  402.  
  403.  
  404.  
  405.  
  406. // ********************
  407. // Replica Delete flags
  408. // ********************
  409.  
  410. // Perform this operation asynchronously.
  411. #define DS_REPDEL_ASYNCHRONOUS_OPERATION 0x00000001
  412.  
  413. // The replica being deleted is writeable.
  414. #define DS_REPDEL_WRITEABLE               0x00000002
  415.  
  416. // Replica is a mail-based replica
  417. #define DS_REPDEL_INTERSITE_MESSAGING     0x00000004
  418.  
  419. // Ignore any error generated by contacting the source to tell it to scratch
  420. // this server from its Reps-To for this NC.
  421. #define DS_REPDEL_IGNORE_ERRORS           0x00000008
  422.  
  423. // Do not contact the source telling it to scratch this server from its
  424. // Rep-To for this NC.  Otherwise, if the link is RPC-based, the source will
  425. // be contacted.
  426. #define DS_REPDEL_LOCAL_ONLY              0x00000010
  427.  
  428. // Delete all the objects in the NC
  429. // "No source" is incompatible with (and rejected for) writeable NCs.  This is
  430. // valid only for read-only NCs, and then only if the NC has no source.  This
  431. // can occur when the NC has been partially deleted (in which case the KCC
  432. // periodically calls the delete API with the "no source" flag set).
  433. #define DS_REPDEL_NO_SOURCE               0x00000020
  434.  
  435. // Allow deletion of read-only replica even if it sources
  436. // other read-only replicas.
  437. #define DS_REPDEL_REF_OK                  0x00000040
  438.  
  439. // ********************
  440. // Replica Modify flags
  441. // ********************
  442.  
  443. // Perform this operation asynchronously.
  444. #define DS_REPMOD_ASYNCHRONOUS_OPERATION  0x00000001
  445.  
  446. // The replica is writeable.
  447. #define DS_REPMOD_WRITEABLE               0x00000002
  448.  
  449.  
  450. // ********************
  451. // Replica Modify fields
  452. // ********************
  453.  
  454. #define DS_REPMOD_UPDATE_FLAGS             0x00000001
  455. #define DS_REPMOD_UPDATE_ADDRESS           0x00000002
  456. #define DS_REPMOD_UPDATE_SCHEDULE          0x00000004
  457. #define DS_REPMOD_UPDATE_RESULT            0x00000008
  458. #define DS_REPMOD_UPDATE_TRANSPORT         0x00000010
  459.  
  460. // ********************
  461. // Update Refs fields
  462. // ********************
  463.  
  464. // Perform this operation asynchronously.
  465. #define DS_REPUPD_ASYNCHRONOUS_OPERATION  0x00000001
  466.  
  467. // The replica being deleted is writeable.
  468. #define DS_REPUPD_WRITEABLE               0x00000002
  469.  
  470. // Add a reference
  471. #define DS_REPUPD_ADD_REFERENCE           0x00000004
  472.  
  473. // Remove a reference
  474. #define DS_REPUPD_DELETE_REFERENCE        0x00000008
  475.  
  476.  
  477. // ***********************
  478. // Well Known Object Guids
  479. // ***********************
  480.  
  481. #define GUID_USERS_CONTAINER_A              "a9d1ca15768811d1aded00c04fd8d5cd"
  482. #define GUID_COMPUTRS_CONTAINER_A           "aa312825768811d1aded00c04fd8d5cd"
  483. #define GUID_SYSTEMS_CONTAINER_A            "ab1d30f3768811d1aded00c04fd8d5cd"
  484. #define GUID_DOMAIN_CONTROLLERS_CONTAINER_A "a361b2ffffd211d1aa4b00c04fd7d83a"
  485. #define GUID_INFRASTRUCTURE_CONTAINER_A     "2fbac1870ade11d297c400c04fd8d5cd"
  486. #define GUID_DELETED_OBJECTS_CONTAINER_A    "18e2ea80684f11d2b9aa00c04f79f805"
  487. #define GUID_LOSTANDFOUND_CONTAINER_A       "ab8153b7768811d1aded00c04fd8d5cd"
  488.  
  489. #define GUID_USERS_CONTAINER_W              L"a9d1ca15768811d1aded00c04fd8d5cd"
  490. #define GUID_COMPUTRS_CONTAINER_W           L"aa312825768811d1aded00c04fd8d5cd"
  491. #define GUID_SYSTEMS_CONTAINER_W            L"ab1d30f3768811d1aded00c04fd8d5cd"
  492. #define GUID_DOMAIN_CONTROLLERS_CONTAINER_W L"a361b2ffffd211d1aa4b00c04fd7d83a"
  493. #define GUID_INFRASTRUCTURE_CONTAINER_W     L"2fbac1870ade11d297c400c04fd8d5cd"
  494. #define GUID_DELETED_OBJECTS_CONTAINER_W    L"18e2ea80684f11d2b9aa00c04f79f805"
  495. #define GUID_LOSTANDFOUND_CONTAINER_W       L"ab8153b7768811d1aded00c04fd8d5cd"
  496.  
  497. #define GUID_USERS_CONTAINER_BYTE              "\xa9\xd1\xca\x15\x76\x88\x11\xd1\xad\xed\x00\xc0\x4f\xd8\xd5\xcd"
  498. #define GUID_COMPUTRS_CONTAINER_BYTE           "\xaa\x31\x28\x25\x76\x88\x11\xd1\xad\xed\x00\xc0\x4f\xd8\xd5\xcd"
  499. #define GUID_SYSTEMS_CONTAINER_BYTE            "\xab\x1d\x30\xf3\x76\x88\x11\xd1\xad\xed\x00\xc0\x4f\xd8\xd5\xcd"
  500. #define GUID_DOMAIN_CONTROLLERS_CONTAINER_BYTE "\xa3\x61\xb2\xff\xff\xd2\x11\xd1\xaa\x4b\x00\xc0\x4f\xd7\xd8\x3a"
  501. #define GUID_INFRASTRUCTURE_CONTAINER_BYTE     "\x2f\xba\xc1\x87\x0a\xde\x11\xd2\x97\xc4\x00\xc0\x4f\xd8\xd5\xcd"
  502. #define GUID_DELETED_OBJECTS_CONTAINER_BYTE    "\x18\xe2\xea\x80\x68\x4f\x11\xd2\xb9\xaa\x00\xc0\x4f\x79\xf8\x05"
  503. #define GUID_LOSTANDFOUND_CONTAINER_BYTE       "\xab\x81\x53\xb7\x76\x88\x11\xd1\xad\xed\x00\xc0\x4f\xd8\xd5\xcd"
  504.  
  505.  
  506. //////////////////////////////////////////////////////////////////////////
  507. //                                                                      //
  508. // Prototypes                                                           //
  509. //                                                                      //
  510. //////////////////////////////////////////////////////////////////////////
  511.  
  512. // DSBind takes two optional input parameters which identify whether the
  513. // caller found a domain controller themselves via DsGetDcName or whether
  514. // a domain controller should be found using default parameters.
  515. // Behavior of the possible combinations are outlined below.
  516. //
  517. // DomainControllerName(value), DnsDomainName(NULL)
  518. //
  519. //      The value for DomainControllerName is assumed to have been
  520. //      obtained via DsGetDcName (i.e. Field with the same name in a
  521. //      DOMAIN_CONTROLLER_INFO struct on return from DsGetDcName call.)
  522. //      The client is bound to the domain controller at this name.
  523. //      
  524. //      Mutual authentication will be performed using an SPN of
  525. //      LDAP/DomainControllerName provided DomainControllerName
  526. //      is not a NETBIOS name or IP address - i.e. it must be a 
  527. //      DNS host name.
  528. //
  529. // DomainControllerName(value), DnsDomainName(value)
  530. //
  531. //      DsBind will connect to the server identified by DomainControllerName.
  532. //
  533. //      Mutual authentication will be performed using an SPN of
  534. //      LDAP/DomainControllerName/DnsDomainName provided neither value
  535. //      is a NETBIOS names or IP address - i.e. they must be
  536. //      valid DNS names.
  537. //
  538. // DomainControllerName(NULL), DnsDomainName(NULL)
  539. //
  540. //      DsBind will attempt to find to a global catalog and fail if one
  541. //      can not be found.  
  542. //
  543. //      Mutual authentication will be performed using an SPN of
  544. //      GC/DnsHostName/ForestName where DnsHostName and ForestName
  545. //      represent the DomainControllerName and DnsForestName fields
  546. //      respectively of the DOMAIN_CONTROLLER_INFO returned by the
  547. //      DsGetDcName call used to find a global catalog.
  548. //
  549. // DomainControllerName(NULL), DnsDomainName(value)
  550. //
  551. //      DsBind will attempt to find a domain controller for the domain
  552. //      identified by DnsDomainName and fail if one can not be found.
  553. //
  554. //      Mutual authentication will be performed using an SPN of
  555. //      LDAP/DnsHostName/DnsDomainName where DnsDomainName is that
  556. //      provided by the caller and DnsHostName is that returned by
  557. //      DsGetDcName for the domain specified - provided DnsDomainName
  558. //      is a valid DNS domain name - i.e. not a NETBIOS domain name.
  559.  
  560. NTDSAPI
  561. DWORD
  562. WINAPI
  563. DsBindW(
  564.     LPCWSTR         DomainControllerName,      // in, optional
  565.     LPCWSTR         DnsDomainName,             // in, optional
  566.     HANDLE          *phDS);
  567.  
  568. NTDSAPI
  569. DWORD
  570. WINAPI
  571. DsBindA(
  572.     LPCSTR          DomainControllerName,      // in, optional
  573.     LPCSTR          DnsDomainName,             // in, optional
  574.     HANDLE          *phDS);
  575.  
  576. #ifdef UNICODE
  577. #define DsBind DsBindW
  578. #else
  579. #define DsBind DsBindA
  580. #endif
  581.  
  582. NTDSAPI
  583. DWORD
  584. WINAPI
  585. DsBindWithCredW(
  586.     LPCWSTR         DomainControllerName,      // in, optional
  587.     LPCWSTR         DnsDomainName,             // in, optional
  588.     RPC_AUTH_IDENTITY_HANDLE AuthIdentity,     // in, optional
  589.     HANDLE          *phDS);
  590.  
  591. NTDSAPI
  592. DWORD
  593. WINAPI
  594. DsBindWithCredA(
  595.     LPCSTR          DomainControllerName,      // in, optional
  596.     LPCSTR          DnsDomainName,             // in, optional
  597.     RPC_AUTH_IDENTITY_HANDLE AuthIdentity,     // in, optional
  598.     HANDLE          *phDS);
  599.  
  600. #ifdef UNICODE
  601. #define DsBindWithCred DsBindWithCredW
  602. #else
  603. #define DsBindWithCred DsBindWithCredA
  604. #endif
  605.  
  606. //
  607. // DsBindWithSpn{A|W} allows the caller to specify the service principal
  608. // name (SPN) which will be used for mutual authentication against
  609. // the destination server.  Do not provide an SPN if you are expecting
  610. // DsBind to find a server for you as SPNs are machine specific and its
  611. // unlikely the SPN you provide matches the server DsBind finds for you.
  612. // Providing a NULL ServicePrincipalName argument results in behavior
  613. // identical to DsBindWithCred{A|W}.
  614. //
  615.  
  616. NTDSAPI
  617. DWORD
  618. WINAPI
  619. DsBindWithSpnW(
  620.     LPCWSTR         DomainControllerName,      // in, optional
  621.     LPCWSTR         DnsDomainName,             // in, optional
  622.     RPC_AUTH_IDENTITY_HANDLE AuthIdentity,     // in, optional
  623.     LPCWSTR         ServicePrincipalName,      // in, optional
  624.     HANDLE          *phDS);
  625.  
  626. NTDSAPI
  627. DWORD
  628. WINAPI
  629. DsBindWithSpnA(
  630.     LPCSTR          DomainControllerName,      // in, optional
  631.     LPCSTR          DnsDomainName,             // in, optional
  632.     RPC_AUTH_IDENTITY_HANDLE AuthIdentity,     // in, optional
  633.     LPCSTR          ServicePrincipalName,      // in, optional
  634.     HANDLE          *phDS);
  635.  
  636. #ifdef UNICODE
  637. #define DsBindWithSpn DsBindWithSpnW
  638. #else
  639. #define DsBindWithSpn DsBindWithSpnA
  640. #endif
  641.  
  642. //
  643. // DsUnBind
  644. //
  645.  
  646. NTDSAPI
  647. DWORD
  648. WINAPI
  649. DsUnBindW(
  650.     HANDLE          *phDS);             // in
  651.  
  652. NTDSAPI
  653. DWORD
  654. WINAPI
  655. DsUnBindA(
  656.     HANDLE          *phDS);             // in
  657.  
  658. #ifdef UNICODE
  659. #define DsUnBind DsUnBindW
  660. #else
  661. #define DsUnBind DsUnBindA
  662. #endif
  663.  
  664. //
  665. // DsMakePasswordCredentials
  666. //
  667. // This function constructs a credential structure which is suitable for input
  668. // to the DsBindWithCredentials function, or the ldap_open function (winldap.h)
  669. // The credential must be freed using DsFreeCredential.
  670. //
  671. // None of the input parameters may be present indicating a null, default
  672. // credential.  Otherwise the username must be present.  If the domain or
  673. // password are null, they default to empty strings.  The domain name may be
  674. // null when the username is fully qualified, for example UPN format.
  675. //
  676.  
  677. NTDSAPI
  678. DWORD
  679. WINAPI
  680. DsMakePasswordCredentialsW(
  681.     LPCWSTR User,
  682.     LPCWSTR Domain,
  683.     LPCWSTR Password,
  684.     RPC_AUTH_IDENTITY_HANDLE *pAuthIdentity
  685.     );
  686.  
  687. NTDSAPI
  688. DWORD
  689. WINAPI
  690. DsMakePasswordCredentialsA(
  691.     LPCSTR User,
  692.     LPCSTR Domain,
  693.     LPCSTR Password,
  694.     RPC_AUTH_IDENTITY_HANDLE *pAuthIdentity
  695.     );
  696.  
  697. #ifdef UNICODE
  698. #define DsMakePasswordCredentials DsMakePasswordCredentialsW
  699. #else
  700. #define DsMakePasswordCredentials DsMakePasswordCredentialsA
  701. #endif
  702.  
  703. NTDSAPI
  704. VOID
  705. WINAPI
  706. DsFreePasswordCredentials(
  707.     RPC_AUTH_IDENTITY_HANDLE AuthIdentity
  708.     );
  709.  
  710. #define DsFreePasswordCredentialsW DsFreePasswordCredentials
  711. #define DsFreePasswordCredentialsA DsFreePasswordCredentials
  712.  
  713. //
  714. // DsCrackNames
  715. //
  716.  
  717. NTDSAPI
  718. DWORD
  719. WINAPI
  720. DsCrackNamesW(
  721.     HANDLE              hDS,                // in
  722.     DS_NAME_FLAGS       flags,              // in
  723.     DS_NAME_FORMAT      formatOffered,      // in
  724.     DS_NAME_FORMAT      formatDesired,      // in
  725.     DWORD               cNames,             // in
  726.     const LPCWSTR       *rpNames,           // in
  727.     PDS_NAME_RESULTW    *ppResult);         // out
  728.  
  729. NTDSAPI
  730. DWORD
  731. WINAPI
  732. DsCrackNamesA(
  733.     HANDLE              hDS,                // in
  734.     DS_NAME_FLAGS       flags,              // in
  735.     DS_NAME_FORMAT      formatOffered,      // in
  736.     DS_NAME_FORMAT      formatDesired,      // in
  737.     DWORD               cNames,             // in
  738.     const LPCSTR        *rpNames,           // in
  739.     PDS_NAME_RESULTA    *ppResult);         // out
  740.  
  741. #ifdef UNICODE
  742. #define DsCrackNames DsCrackNamesW
  743. #else
  744. #define DsCrackNames DsCrackNamesA
  745. #endif
  746.  
  747. //
  748. // DsFreeNameResult
  749. //
  750.  
  751. NTDSAPI
  752. void
  753. WINAPI
  754. DsFreeNameResultW(
  755.     DS_NAME_RESULTW *pResult);          // in
  756.  
  757. NTDSAPI
  758. void
  759. WINAPI
  760. DsFreeNameResultA(
  761.     DS_NAME_RESULTA *pResult);          // in
  762.  
  763. #ifdef UNICODE
  764. #define DsFreeNameResult DsFreeNameResultW
  765. #else
  766. #define DsFreeNameResult DsFreeNameResultA
  767. #endif
  768.  
  769. // ==========================================================
  770. // DSMakeSpn -- client call to create SPN for a service to which it wants to
  771. // authenticate.
  772. // This name is then passed to "pszTargetName" of InitializeSecurityContext().
  773. //
  774. // Notes:
  775. // If the service name is a DNS host name, or canonical DNS service name
  776. // e.g. "www.ms.com", i.e., caller resolved with gethostbyname, then instance
  777. // name should be NULL.
  778. // Realm is host name minus first component, unless it is in the exception list
  779. //
  780. // If the service name is NetBIOS machine name, then instance name should be
  781. // NULL
  782. // Form must be <domain>\<machine>
  783. // Realm will be <domain>
  784. //
  785. // If the service name is that of a replicated service, where each replica has
  786. // its own account (e.g., with SRV records) then the caller must supply the
  787. // instance name then realm name is same as ServiceName
  788. //
  789. // If the service name is a DN, then must also supply instance name
  790. // (DN could be name of service object (incl RPC or Winsock), name of machine
  791. // account, name of domain object)
  792. // then realm name is domain part of the DN
  793. //
  794. // If the service name is NetBIOS domain name, then must also supply instance
  795. // name; realm name is domain name
  796. //
  797. // If the service is named by an IP address -- then use referring service name
  798. // as service name
  799. //
  800. //  ServiceClass - e.g. "http", "ftp", "ldap", GUID
  801. //  ServiceName - DNS or DN; assumes we can compute domain from service name
  802. //  InstanceName OPTIONAL- DNS name of host for instance of service
  803. //  InstancePort - port number for instance (0 if default)
  804. //  Referrer OPTIONAL- DNS name of host that gave this referral
  805. //  pcSpnLength - in -- max length IN CHARACTERS of principal name;
  806. //                out -- actual
  807. //                Length includes terminator
  808. //  pszSPN - server principal name
  809. //
  810. // If buffer is not large enough, ERROR_BUFFER_OVERFLOW is returned and the
  811. // needed length is returned in pcSpnLength.
  812. //
  813. //
  814.  
  815. NTDSAPI
  816. DWORD
  817. WINAPI
  818. DsMakeSpnW(
  819.     IN LPCWSTR ServiceClass,
  820.     IN LPCWSTR ServiceName,
  821.     IN LPCWSTR InstanceName,
  822.     IN USHORT InstancePort,
  823.     IN LPCWSTR Referrer,
  824.     IN OUT DWORD *pcSpnLength,
  825.     OUT LPWSTR pszSpn
  826. );
  827.  
  828. NTDSAPI
  829. DWORD
  830. WINAPI
  831. DsMakeSpnA(
  832.     IN LPCSTR ServiceClass,
  833.     IN LPCSTR ServiceName,
  834.     IN LPCSTR InstanceName,
  835.     IN USHORT InstancePort,
  836.     IN LPCSTR Referrer,
  837.     IN OUT DWORD *pcSpnLength,
  838.     OUT LPSTR pszSpn
  839. );
  840.  
  841. #ifdef UNICODE
  842. #define DsMakeSpn DsMakeSpnW
  843. #else
  844. #define DsMakeSpn DsMakeSpnA
  845. #endif
  846.  
  847. // ==========================================================
  848. // DsGetSPN -- server's call to gets SPNs for a service name by which it is
  849. // known to clients. N.B.: there may be more than one name by which clients
  850. // know it the SPNs are then passed to DsAddAccountSpn to register them in
  851. // the DS
  852. //
  853. //      IN SpnNameType eType,
  854. //      IN LPCTSTR ServiceClass,
  855. // kind of service -- "http", "ldap", "ftp", etc.
  856. //      IN LPCTSTR ServiceName OPTIONAL,
  857. // name of service -- DN or DNS; not needed for host-based
  858. //      IN USHORT InstancePort,
  859. // port number (0 => default) for instances
  860. //      IN USHORT cInstanceNames,
  861. // count of extra instance names and ports (0=>use gethostbyname)
  862. //      IN LPCTSTR InstanceNames[] OPTIONAL,
  863. // extra instance names (not used for host names)
  864. //      IN USHORT InstancePorts[] OPTIONAL,
  865. // extra instance ports (0 => default)
  866. //      IN OUT PULONG pcSpn,    // count of SPNs
  867. //      IN OUT LPTSTR * prpszSPN[]
  868. // a bunch of SPNs for this service; free with DsFreeSpnArray
  869.  
  870. NTDSAPI
  871. DWORD
  872. WINAPI
  873. DsGetSpnA(
  874.     IN DS_SPN_NAME_TYPE ServiceType,
  875.     IN LPCSTR ServiceClass,
  876.     IN LPCSTR ServiceName,
  877.     IN USHORT InstancePort,
  878.     IN USHORT cInstanceNames,
  879.     IN LPCSTR *pInstanceNames,
  880.     IN const USHORT *pInstancePorts,
  881.     OUT DWORD *pcSpn,
  882.     OUT LPSTR **prpszSpn
  883.     );
  884.  
  885. NTDSAPI
  886. DWORD
  887. WINAPI
  888. DsGetSpnW(
  889.     IN DS_SPN_NAME_TYPE ServiceType,
  890.     IN LPCWSTR ServiceClass,
  891.     IN LPCWSTR ServiceName,
  892.     IN USHORT InstancePort,
  893.     IN USHORT cInstanceNames,
  894.     IN LPCWSTR *pInstanceNames,
  895.     IN const USHORT *pInstancePorts,
  896.     OUT DWORD *pcSpn,
  897.     OUT LPWSTR **prpszSpn
  898.     );
  899.  
  900. #ifdef UNICODE
  901. #define DsGetSpn DsGetSpnW
  902. #else
  903. #define DsGetSpn DsGetSpnA
  904. #endif
  905.  
  906. // ==========================================================
  907. // DsFreeSpnArray() -- Free array returned by DsGetSpn{A,W}
  908.  
  909. NTDSAPI
  910. void
  911. WINAPI
  912. DsFreeSpnArrayA(
  913.     IN DWORD cSpn,
  914.     IN OUT LPSTR *rpszSpn
  915.     );
  916.  
  917. NTDSAPI
  918. void
  919. WINAPI
  920. DsFreeSpnArrayW(
  921.     IN DWORD cSpn,
  922.     IN OUT LPWSTR *rpszSpn
  923.     );
  924.  
  925. #ifdef UNICODE
  926. #define DsFreeSpnArray DsFreeSpnArrayW
  927. #else
  928. #define DsFreeSpnArray DsFreeSpnArrayA
  929. #endif
  930.  
  931. // ==========================================================
  932. // DsCrackSpn() -- parse an SPN into the ServiceClass,
  933. // ServiceName, and InstanceName (and InstancePort) pieces.
  934. // An SPN is passed in, along with a pointer to the maximum length
  935. // for each piece and a pointer to a buffer where each piece should go.
  936. // On exit, the maximum lengths are updated to the actual length for each piece
  937. // and the buffer contain the appropriate piece. The InstancePort is 0 if not
  938. // present.
  939. //
  940. // DWORD DsCrackSpn(
  941. //      IN LPTSTR pszSPN,               // the SPN to parse
  942. //      IN OUT PUSHORT pcServiceClass,  // input -- max length of ServiceClass;
  943. //                                         output -- actual length
  944. //      OUT LPCTSTR ServiceClass,       // the ServiceClass part of the SPN
  945. //      IN OUT PUSHORT pcServiceName,   // input -- max length of ServiceName;
  946. //                                         output -- actual length
  947. //      OUT LPCTSTR ServiceName,        // the ServiceName part of the SPN
  948. //      IN OUT PUSHORT pcInstance,      // input -- max length of ServiceClass;
  949. //                                         output -- actual length
  950. //      OUT LPCTSTR InstanceName,  // the InstanceName part of the SPN
  951. //      OUT PUSHORT InstancePort          // instance port
  952. //
  953. // Note: lengths are in characters; all string lengths include terminators
  954. // All arguments except pszSpn are optional.
  955. //
  956.  
  957. NTDSAPI
  958. DWORD
  959. WINAPI
  960. DsCrackSpnA(
  961.     IN LPCSTR pszSpn,
  962.     IN OUT LPDWORD pcServiceClass,
  963.     OUT LPSTR ServiceClass,
  964.     IN OUT LPDWORD pcServiceName,
  965.     OUT LPSTR ServiceName,
  966.     IN OUT LPDWORD pcInstanceName,
  967.     OUT LPSTR InstanceName,
  968.     OUT USHORT *pInstancePort
  969.     );
  970.  
  971. NTDSAPI
  972. DWORD
  973. WINAPI
  974. DsCrackSpnW(
  975.     IN LPCWSTR pszSpn,
  976.     IN OUT DWORD *pcServiceClass,
  977.     OUT LPWSTR ServiceClass,
  978.     IN OUT DWORD *pcServiceName,
  979.     OUT LPWSTR ServiceName,
  980.     IN OUT DWORD *pcInstanceName,
  981.     OUT LPWSTR InstanceName,
  982.     OUT USHORT *pInstancePort
  983.     );
  984.  
  985. #ifdef UNICODE
  986. #define DsCrackSpn DsCrackSpnW
  987. #else
  988. #define DsCrackSpn DsCrackSpnA
  989. #endif
  990.  
  991.  
  992. // ==========================================================
  993. // DsWriteAccountSpn -- set or add SPNs for an account object
  994. // Usually done by service itself, or perhaps by an admin.
  995. //
  996. // This call is RPC'd to the DC where the account object is stored, so it can
  997. // securely enforce policy on what SPNs are allowed on the account. Direct LDAP
  998. // writes to the SPN property are not allowed -- all writes must come through
  999. // this RPC call. (Reads via // LDAP are OK.)
  1000. //
  1001. // The account object can be a machine accout, or a service (user) account.
  1002. //
  1003. // If called by the service to register itself, it can most easily get
  1004. // the names by calling DsGetSpn with each of the names that
  1005. // clients can use to find the service.
  1006. //
  1007. // IN SpnWriteOp eOp,                   // set, add
  1008. // IN LPCTSTR   pszAccount,             // DN of account to which to add SPN
  1009. // IN int       cSPN,                   // count of SPNs to add to account
  1010. // IN LPCTSTR   rpszSPN[]               // SPNs to add to altSecID property
  1011.  
  1012. NTDSAPI
  1013. DWORD
  1014. WINAPI
  1015. DsWriteAccountSpnA(
  1016.     IN HANDLE hDS,
  1017.     IN DS_SPN_WRITE_OP Operation,
  1018.     IN LPCSTR pszAccount,
  1019.     IN DWORD cSpn,
  1020.     IN LPCSTR *rpszSpn
  1021.     );
  1022.  
  1023. NTDSAPI
  1024. DWORD
  1025. WINAPI
  1026. DsWriteAccountSpnW(
  1027.     IN HANDLE hDS,
  1028.     IN DS_SPN_WRITE_OP Operation,
  1029.     IN LPCWSTR pszAccount,
  1030.     IN DWORD cSpn,
  1031.     IN LPCWSTR *rpszSpn
  1032.     );
  1033.  
  1034. #ifdef UNICODE
  1035. #define DsWriteAccountSpn DsWriteAccountSpnW
  1036. #else
  1037. #define DsWriteAccountSpn DsWriteAccountSpnA
  1038. #endif
  1039.  
  1040. /*++
  1041.  
  1042. Routine Description:
  1043.  
  1044. Constructs a Service Principal Name suitable to identify the desired server.
  1045. The service class and part of a dns hostname must be supplied.
  1046.  
  1047. This routine is a simplified wrapper to DsMakeSpn.
  1048. The ServiceName is made canonical by resolving through DNS.
  1049. Guid-based dns names are not supported.
  1050.  
  1051. The simplified SPN constructed looks like this:
  1052.  
  1053. ServiceClass / ServiceName / ServiceName
  1054.  
  1055. The instance name portion (2nd position) is always defaulted.  The port and
  1056. referrer fields are not used.
  1057.  
  1058. Arguments:
  1059.  
  1060.     ServiceClass - Class of service, defined by the service, can be any
  1061.         string unique to the service
  1062.  
  1063.     ServiceName - dns hostname, fully qualified or not
  1064.        Stringized IP address is also resolved if necessary
  1065.  
  1066.     pcSpnLength - IN, maximum length of buffer, in chars
  1067.                   OUT, space utilized, in chars, including terminator
  1068.  
  1069.     pszSpn - Buffer, atleast of length *pcSpnLength
  1070.  
  1071. Return Value:
  1072.  
  1073.     WINAPI - Win32 error code
  1074.  
  1075. --*/
  1076.  
  1077. NTDSAPI
  1078. DWORD
  1079. WINAPI
  1080. DsClientMakeSpnForTargetServerW(
  1081.     IN LPCWSTR ServiceClass,
  1082.     IN LPCWSTR ServiceName,
  1083.     IN OUT DWORD *pcSpnLength,
  1084.     OUT LPWSTR pszSpn
  1085.     );
  1086.  
  1087. NTDSAPI
  1088. DWORD
  1089. WINAPI
  1090. DsClientMakeSpnForTargetServerA(
  1091.     IN LPCSTR ServiceClass,
  1092.     IN LPCSTR ServiceName,
  1093.     IN OUT DWORD *pcSpnLength,
  1094.     OUT LPSTR pszSpn
  1095.     );
  1096.  
  1097. #ifdef UNICODE
  1098. #define DsClientMakeSpnForTargetServer DsClientMakeSpnForTargetServerW
  1099. #else
  1100. #define DsClientMakeSpnForTargetServer DsClientMakeSpnForTargetServerA
  1101. #endif
  1102.  
  1103. /*++
  1104.  
  1105. Routine Description:
  1106.  
  1107. Register Service Principal Names for a server application.
  1108.  
  1109. This routine does the following:
  1110. 1. Enumerates a list of server SPNs using DsGetSpn and the provided class
  1111. 2. Determines the domain of the current user context
  1112. 3. Determines the DN of the current user context if not supplied
  1113. 4. Locates a domain controller
  1114. 5. Binds to the domain controller
  1115. 6. Uses DsWriteAccountSpn to write the SPNs on the named object DN
  1116. 7. Unbinds
  1117.  
  1118. Construct server SPNs for this service, and write them to the right object.
  1119.  
  1120. If the userObjectDn is specified, the SPN is written to that object.
  1121.  
  1122. Otherwise the Dn is defaulted, to the user object, then computer.
  1123.  
  1124. Now, bind to the DS, and register the name on the object for the
  1125. user this service is running as.  So, if we're running as local
  1126. system, we'll register it on the computer object itself.  If we're
  1127. running as a domain user, we'll add the SPN to the user's object.
  1128.  
  1129. Arguments:
  1130.  
  1131.     Operation - What should be done with the values: add, replace or delete
  1132.     ServiceClass - Unique string identifying service
  1133.     UserObjectDN - Optional, dn of object to write SPN to
  1134.  
  1135. Return Value:
  1136.  
  1137.     WINAPI - Win32 error code
  1138.  
  1139. --*/
  1140.  
  1141. NTDSAPI
  1142. DWORD
  1143. WINAPI
  1144. DsServerRegisterSpnA(
  1145.     IN DS_SPN_WRITE_OP Operation,
  1146.     IN LPCSTR ServiceClass,
  1147.     IN LPCSTR UserObjectDN
  1148.     );
  1149.  
  1150. NTDSAPI
  1151. DWORD
  1152. WINAPI
  1153. DsServerRegisterSpnW(
  1154.     IN DS_SPN_WRITE_OP Operation,
  1155.     IN LPCWSTR ServiceClass,
  1156.     IN LPCWSTR UserObjectDN
  1157.     );
  1158.  
  1159. #ifdef UNICODE
  1160. #define DsServerRegisterSpn DsServerRegisterSpnW
  1161. #else
  1162. #define DsServerRegisterSpn DsServerRegisterSpnA
  1163. #endif
  1164.  
  1165. // DsReplicaSync.  The server that this call is executing on is called the
  1166. // destination.  The destination's naming context will be brought up to date
  1167. // with respect to a source system.  The source system is identified by the
  1168. // uuid.  The uuid is that of the source system's "NTDS Settings" object.
  1169. // The destination system must already be configured such that the source
  1170. // system is one of the systems from which it recieves replication data
  1171. // ("replication from"). This is usually done automatically by the KCC.
  1172. //
  1173. //  PARAMETERS:
  1174. //      pNC (DSNAME *)
  1175. //          Name of the NC to synchronize.
  1176. //      puuidSourceDRA (SZ)
  1177. //          objectGuid of DSA with which to synchronize the replica.
  1178. //      ulOptions (ULONG)
  1179. //          Bitwise OR of zero or more flags
  1180. //   RETURNS: WIN32 STATUS
  1181.  
  1182. NTDSAPI
  1183. DWORD
  1184. WINAPI
  1185. DsReplicaSyncA(
  1186.     IN HANDLE hDS,
  1187.     IN LPCSTR NameContext,
  1188.     IN const UUID *pUuidDsaSrc,
  1189.     IN ULONG Options
  1190.     );
  1191.  
  1192. NTDSAPI
  1193. DWORD
  1194. WINAPI
  1195. DsReplicaSyncW(
  1196.     IN HANDLE hDS,
  1197.     IN LPCWSTR NameContext,
  1198.     IN const UUID *pUuidDsaSrc,
  1199.     IN ULONG Options
  1200.     );
  1201.  
  1202. #ifdef UNICODE
  1203. #define DsReplicaSync DsReplicaSyncW
  1204. #else
  1205. #define DsReplicaSync DsReplicaSyncA
  1206. #endif
  1207.  
  1208. // DsReplicaAdd
  1209. //
  1210. /*
  1211. Description:
  1212.    This call is executed on the destination.  It causes the destination to
  1213.    add a "replication from" reference to the indicated source system.
  1214.  
  1215. The source server is identified by string name, not uuid as with Sync.
  1216. The DsaSrcAddress parameter is the transport specific address of the source
  1217. DSA, usually its guid-based dns name.  The guid in the guid-based dns name is
  1218. the object-guid of that server's ntds-dsa (settings) object.
  1219.  
  1220. Arguments:
  1221.  
  1222.     pNC (IN) - NC for which to add the replica.  The NC record must exist
  1223.         locally as either an object (instantiated or not) or a reference
  1224.         phantom (i.e., a phantom with a guid).
  1225.  
  1226.     pSourceDsaDN (IN) - DN of the source DSA's ntdsDsa object.  Required if
  1227.         ulOptions includes DS_REPADD_ASYNCHRONOUS_REPLICA; ignored otherwise.
  1228.  
  1229.     pTransportDN (IN) - DN of the interSiteTransport object representing the
  1230.         transport by which to communicate with the source server.  Required if
  1231.         ulOptions includes INTERSITE_MESSAGING; ignored otherwise.
  1232.  
  1233.     pszSourceDsaAddress (IN) - Transport-specific address of the source DSA.
  1234.  
  1235.     pSchedule (IN) - Schedule by which to replicate the NC from this
  1236.         source in the future.
  1237.  
  1238.     ulOptions (IN) - flags
  1239.     RETURNS: WIN32 STATUS
  1240. */
  1241.  
  1242. NTDSAPI
  1243. DWORD
  1244. WINAPI
  1245. DsReplicaAddA(
  1246.     IN HANDLE hDS,
  1247.     IN LPCSTR NameContext,
  1248.     IN LPCSTR SourceDsaDn,
  1249.     IN LPCSTR TransportDn,
  1250.     IN LPCSTR SourceDsaAddress,
  1251.     IN const PSCHEDULE pSchedule,
  1252.     IN DWORD Options
  1253.     );
  1254.  
  1255. NTDSAPI
  1256. DWORD
  1257. WINAPI
  1258. DsReplicaAddW(
  1259.     IN HANDLE hDS,
  1260.     IN LPCWSTR NameContext,
  1261.     IN LPCWSTR SourceDsaDn,
  1262.     IN LPCWSTR TransportDn,
  1263.     IN LPCWSTR SourceDsaAddress,
  1264.     IN const PSCHEDULE pSchedule,
  1265.     IN DWORD Options
  1266.     );
  1267.  
  1268. #ifdef UNICODE
  1269. #define DsReplicaAdd DsReplicaAddW
  1270. #else
  1271. #define DsReplicaAdd DsReplicaAddA
  1272. #endif
  1273.  
  1274. // DsReplicaDel
  1275. //
  1276. // The server that this call is executing on is the destination.  The call
  1277. // causes the destination to remove a "replication from" reference to the
  1278. // indicated source server.
  1279. // The source server is identified by string name, not uuid as with Sync.
  1280. // The DsaSrc parameter is the transport specific address of the source DSA,
  1281. // usually its guid-based dns name.  The guid in the guid-based dns name is
  1282. // the object-guid of that server's ntds-dsa (settings) object.
  1283. //
  1284. //  PARAMETERS:
  1285. //      pNC (DSNAME *)
  1286. //          Name of the NC for which to delete a source.
  1287. //      pszSourceDRA (SZ)
  1288. //          DSA for which to delete the source.
  1289. //      ulOptions (ULONG)
  1290. //          Bitwise OR of zero or more flags
  1291. //   RETURNS: WIN32 STATUS
  1292.  
  1293. NTDSAPI
  1294. DWORD
  1295. WINAPI
  1296. DsReplicaDelA(
  1297.     IN HANDLE hDS,
  1298.     IN LPCSTR NameContext,
  1299.     IN LPCSTR DsaSrc,
  1300.     IN ULONG Options
  1301.     );
  1302.  
  1303. NTDSAPI
  1304. DWORD
  1305. WINAPI
  1306. DsReplicaDelW(
  1307.     IN HANDLE hDS,
  1308.     IN LPCWSTR NameContext,
  1309.     IN LPCWSTR DsaSrc,
  1310.     IN ULONG Options
  1311.     );
  1312.  
  1313. #ifdef UNICODE
  1314. #define DsReplicaDel DsReplicaDelW
  1315. #else
  1316. #define DsReplicaDel DsReplicaDelA
  1317. #endif
  1318.  
  1319. // DsReplicaModify
  1320. //
  1321. //
  1322. //  Modify a source for a given naming context
  1323. //
  1324. //  The value must already exist.
  1325. //
  1326. //  Either the UUID or the address may be used to identify the current value.
  1327. //  If a UUID is specified, the UUID will be used for comparison.  Otherwise,
  1328. //  the address will be used for comparison.
  1329. //
  1330. //  PARAMETERS:
  1331. //      pNC (DSNAME *)
  1332. //          Name of the NC for which the Reps-From should be modified.
  1333. //      puuidSourceDRA (UUID *)
  1334. //          Invocation-ID of the referenced DRA.  May be NULL if:
  1335. //            . ulModifyFields does not include DS_REPMOD_UPDATE_ADDRESS and
  1336. //            . pmtxSourceDRA is non-NULL.
  1337. //      puuidTransportObj (UUID *)
  1338. //          objectGuid of the transport by which replication is to be performed
  1339. //          Ignored if ulModifyFields does not include
  1340. //          DS_REPMOD_UPDATE_TRANSPORT.
  1341. //      pszSourceDRA (SZ)
  1342. //          DSA for which the reference should be added or deleted.  Ignored if
  1343. //          puuidSourceDRA is non-NULL and ulModifyFields does not include
  1344. //          DS_REPMOD_UPDATE_ADDRESS.
  1345. //      prtSchedule (REPLTIMES *)
  1346. //          Periodic replication schedule for this replica.  Ignored if
  1347. //          ulModifyFields does not include DS_REPMOD_UPDATE_SCHEDULE.
  1348. //      ulReplicaFlags (ULONG)
  1349. //          Flags to set for this replica.  Ignored if ulModifyFields does not
  1350. //          include DS_REPMOD_UPDATE_FLAGS.
  1351. //      ulModifyFields (ULONG)
  1352. //          Fields to update.  One or more of the following bit flags:
  1353. //              UPDATE_ADDRESS
  1354. //                  Update the MTX_ADDR associated with the referenced server.
  1355. //              UPDATE_SCHEDULE
  1356. //                  Update the periodic replication schedule associated with
  1357. //                  the replica.
  1358. //              UPDATE_FLAGS
  1359. //                  Update the flags associated with the replica.
  1360. //              UPDATE_TRANSPORT
  1361. //                  Update the transport associated with the replica.
  1362. //      ulOptions (ULONG)
  1363. //          Bitwise OR of zero or more of the following:
  1364. //              DS_REPMOD_ASYNCHRONOUS_OPERATION
  1365. //                  Perform this operation asynchronously.
  1366. //   RETURNS: WIN32 STATUS
  1367.  
  1368. NTDSAPI
  1369. DWORD
  1370. WINAPI
  1371. DsReplicaModifyA(
  1372.     IN HANDLE hDS,
  1373.     IN LPCSTR NameContext,
  1374.     IN const UUID *pUuidSourceDsa,
  1375.     IN LPCSTR TransportDn,
  1376.     IN LPCSTR SourceDsaAddress,
  1377.     IN const PSCHEDULE pSchedule,
  1378.     IN DWORD ReplicaFlags,
  1379.     IN DWORD ModifyFields,
  1380.     IN DWORD Options
  1381.     );
  1382.  
  1383. NTDSAPI
  1384. DWORD
  1385. WINAPI
  1386. DsReplicaModifyW(
  1387.     IN HANDLE hDS,
  1388.     IN LPCWSTR NameContext,
  1389.     IN const UUID *pUuidSourceDsa,
  1390.     IN LPCWSTR TransportDn,
  1391.     IN LPCWSTR SourceDsaAddress,
  1392.     IN const PSCHEDULE pSchedule,
  1393.     IN DWORD ReplicaFlags,
  1394.     IN DWORD ModifyFields,
  1395.     IN DWORD Options
  1396.     );
  1397.  
  1398. #ifdef UNICODE
  1399. #define DsReplicaModify DsReplicaModifyW
  1400. #else
  1401. #define DsReplicaModify DsReplicaModifyA
  1402. #endif
  1403.  
  1404. // DsReplicaUpdateRefs
  1405. //
  1406. // In this case, the RPC is being executed on the "source" of destination-sourc
  1407. // replication relationship.  This function tells the source that it no longer
  1408. // supplies replication information to the indicated destination system.
  1409. // Add or remove a target server from the Reps-To property on the given NC.
  1410. // Add/remove a reference given the DSNAME of the corresponding NTDS-DSA
  1411. // object.
  1412. //
  1413. //  PARAMETERS:
  1414. //      pNC (DSNAME *)
  1415. //          Name of the NC for which the Reps-To should be modified.
  1416. //      DsaDest (SZ)
  1417. //          Network address of DSA for which the reference should be added
  1418. //          or deleted.
  1419. //      pUuidDsaDest (UUID *)
  1420. //          Invocation-ID of DSA for which the reference should be added
  1421. //          or deleted.
  1422. //      ulOptions (ULONG)
  1423. //          Bitwise OR of zero or more of the following:
  1424. //              DS_REPUPD_ASYNC_OP
  1425. //                  Perform this operation asynchronously.
  1426. //              DS_REPUPD_ADD_REFERENCE
  1427. //                  Add the given server to the Reps-To property.
  1428. //              DS_REPUPD_DEL_REFERENCE
  1429. //                  Remove the given server from the Reps-To property.
  1430. //          Note that ADD_REF and DEL_REF may be paired to perform
  1431. //          "add or update".
  1432. //
  1433. //   RETURNS: WIN32 STATUS
  1434.  
  1435. NTDSAPI
  1436. DWORD
  1437. WINAPI
  1438. DsReplicaUpdateRefsA(
  1439.     IN HANDLE hDS,
  1440.     IN LPCSTR NameContext,
  1441.     IN LPCSTR DsaDest,
  1442.     IN const UUID *pUuidDsaDest,
  1443.     IN ULONG Options
  1444.     );
  1445.  
  1446. NTDSAPI
  1447. DWORD
  1448. WINAPI
  1449. DsReplicaUpdateRefsW(
  1450.     IN HANDLE hDS,
  1451.     IN LPCWSTR NameContext,
  1452.     IN LPCWSTR DsaDest,
  1453.     IN const UUID *pUuidDsaDest,
  1454.     IN ULONG Options
  1455.     );
  1456.  
  1457. #ifdef UNICODE
  1458. #define DsReplicaUpdateRefs DsReplicaUpdateRefsW
  1459. #else
  1460. #define DsReplicaUpdateRefs DsReplicaUpdateRefsA
  1461. #endif
  1462.  
  1463. // Friends of DsReplicaSyncAll
  1464.  
  1465. typedef enum {
  1466.  
  1467.     DS_REPSYNCALL_WIN32_ERROR_CONTACTING_SERVER    = 0,
  1468.     DS_REPSYNCALL_WIN32_ERROR_REPLICATING        = 1,
  1469.     DS_REPSYNCALL_SERVER_UNREACHABLE        = 2
  1470.  
  1471. } DS_REPSYNCALL_ERROR;
  1472.  
  1473. typedef enum {
  1474.  
  1475.     DS_REPSYNCALL_EVENT_ERROR            = 0,
  1476.     DS_REPSYNCALL_EVENT_SYNC_STARTED        = 1,
  1477.     DS_REPSYNCALL_EVENT_SYNC_COMPLETED        = 2,
  1478.     DS_REPSYNCALL_EVENT_FINISHED            = 3
  1479.  
  1480. } DS_REPSYNCALL_EVENT;
  1481.  
  1482. // Friends of DsReplicaSyncAll
  1483.  
  1484. typedef struct {
  1485.     LPSTR            pszSrcId;
  1486.     LPSTR            pszDstId;
  1487.     LPSTR                       pszNC;
  1488.     GUID *                      pguidSrc;
  1489.     GUID *                      pguidDst;
  1490. } DS_REPSYNCALL_SYNCA, * PDS_REPSYNCALL_SYNCA;
  1491.  
  1492. typedef struct {
  1493.     LPWSTR            pszSrcId;
  1494.     LPWSTR            pszDstId;
  1495.     LPWSTR                      pszNC;
  1496.     GUID *                      pguidSrc;
  1497.     GUID *                      pguidDst;
  1498. } DS_REPSYNCALL_SYNCW, * PDS_REPSYNCALL_SYNCW;
  1499.  
  1500. typedef struct {
  1501.     LPSTR            pszSvrId;
  1502.     DS_REPSYNCALL_ERROR        error;
  1503.     DWORD            dwWin32Err;
  1504.     LPSTR            pszSrcId;
  1505. } DS_REPSYNCALL_ERRINFOA, * PDS_REPSYNCALL_ERRINFOA;
  1506.  
  1507. typedef struct {
  1508.     LPWSTR            pszSvrId;
  1509.     DS_REPSYNCALL_ERROR        error;
  1510.     DWORD            dwWin32Err;
  1511.     LPWSTR            pszSrcId;
  1512. } DS_REPSYNCALL_ERRINFOW, * PDS_REPSYNCALL_ERRINFOW;
  1513.  
  1514. typedef struct {
  1515.     DS_REPSYNCALL_EVENT        event;
  1516.     DS_REPSYNCALL_ERRINFOA *    pErrInfo;
  1517.     DS_REPSYNCALL_SYNCA *    pSync;
  1518. } DS_REPSYNCALL_UPDATEA, * PDS_REPSYNCALL_UPDATEA;
  1519.  
  1520. typedef struct {
  1521.     DS_REPSYNCALL_EVENT        event;
  1522.     DS_REPSYNCALL_ERRINFOW *    pErrInfo;
  1523.     DS_REPSYNCALL_SYNCW *    pSync;
  1524. } DS_REPSYNCALL_UPDATEW, * PDS_REPSYNCALL_UPDATEW;
  1525.  
  1526. #ifdef UNICODE
  1527. #define DS_REPSYNCALL_SYNC DS_REPSYNCALL_SYNCW
  1528. #define DS_REPSYNCALL_ERRINFO DS_REPSYNCALL_ERRINFOW
  1529. #define DS_REPSYNCALL_UPDATE DS_REPSYNCALL_UPDATEW
  1530. #define PDS_REPSYNCALL_SYNC PDS_REPSYNCALL_SYNCW
  1531. #define PDS_REPSYNCALL_ERRINFO PDS_REPSYNCALL_ERRINFOW
  1532. #define PDS_REPSYNCALL_UPDATE PDS_REPSYNCALL_UPDATEW
  1533. #else
  1534. #define DS_REPSYNCALL_SYNC DS_REPSYNCALL_SYNCA
  1535. #define DS_REPSYNCALL_ERRINFO DS_REPSYNCALL_ERRINFOA
  1536. #define DS_REPSYNCALL_UPDATE DS_REPSYNCALL_UPDATEA
  1537. #define PDS_REPSYNCALL_SYNC PDS_REPSYNCALL_SYNCA
  1538. #define PDS_REPSYNCALL_ERRINFO PDS_REPSYNCALL_ERRINFOA
  1539. #define PDS_REPSYNCALL_UPDATE PDS_REPSYNCALL_UPDATEA
  1540. #endif
  1541.  
  1542. // **********************
  1543. // Replica SyncAll flags
  1544. // **********************
  1545.  
  1546. // This option has no effect.
  1547. #define DS_REPSYNCALL_NO_OPTIONS            0x00000000
  1548.  
  1549. // Ordinarily, if a server cannot be contacted, DsReplicaSyncAll tries to
  1550. // route around it and replicate from as many servers as possible.  Enabling
  1551. // this option will cause DsReplicaSyncAll to generate a fatal error if any
  1552. // server cannot be contacted, or if any server is unreachable (due to a
  1553. // disconnected or broken topology.)
  1554. #define    DS_REPSYNCALL_ABORT_IF_SERVER_UNAVAILABLE    0x00000001
  1555.  
  1556. // This option disables transitive replication; syncs will only be performed
  1557. // with adjacent servers and no DsBind calls will be made.
  1558. #define DS_REPSYNCALL_SYNC_ADJACENT_SERVERS_ONLY    0x00000002
  1559.  
  1560. // Ordinarily, when DsReplicaSyncAll encounters a non-fatal error, it returns
  1561. // the GUID DNS of the relevant server(s).  Enabling this option causes
  1562. // DsReplicaSyncAll to return the servers' DNs instead.
  1563. #define DS_REPSYNCALL_ID_SERVERS_BY_DN            0x00000004
  1564.  
  1565. // This option disables all syncing.  The topology will still be analyzed and
  1566. // unavailable / unreachable servers will still be identified.
  1567. #define DS_REPSYNCALL_DO_NOT_SYNC            0x00000008
  1568.  
  1569. // Ordinarily, DsReplicaSyncAll attempts to bind to all servers before
  1570. // generating the topology.  If a server cannot be contacted, DsReplicaSyncAll
  1571. // excludes that server from the topology and tries to route around it.  If
  1572. // this option is enabled, checking will be bypassed and DsReplicaSyncAll will
  1573. // assume all servers are responding.  This will speed operation of
  1574. // DsReplicaSyncAll, but if some servers are not responding, some transitive
  1575. // replications may be blocked.
  1576. #define DS_REPSYNCALL_SKIP_INITIAL_CHECK        0x00000010
  1577.  
  1578. // Push mode. Push changes from the home server out to all partners using
  1579. // transitive replication.  This reverses the direction of replication, and
  1580. // the order of execution of the replication sets from the usual "pulling"
  1581. // mode of execution.
  1582. #define DS_REPSYNCALL_PUSH_CHANGES_OUTWARD              0x00000020
  1583.  
  1584. // Cross site boundaries.  By default, the only servers that are considered are
  1585. // those in the same site as the home system.  With this option, all servers in
  1586. // the enterprise, across all sites, are eligible.  They must be connected by
  1587. // a synchronous (RPC) transport, however.
  1588. #define DS_REPSYNCALL_CROSS_SITE_BOUNDARIES             0x00000040
  1589.  
  1590. // DsReplicaSyncAll.  Syncs the destination server with all other servers
  1591. // in the site.
  1592. //
  1593. //  PARAMETERS:
  1594. //    hDS        (IN) - A DS connection bound to the destination server.
  1595. //    pszNameContext    (IN) - The naming context to synchronize
  1596. //    ulFlags        (IN) - Bitwise OR of zero or more flags
  1597. //    pFnCallBack    (IN, OPTIONAL) - Callback function for message-passing.
  1598. //    pCallbackData    (IN, OPTIONAL) - A pointer that will be passed to the
  1599. //                first argument of the callback function.
  1600. //    pErrors        (OUT, OPTIONAL) - Pointer to a (PDS_REPSYNCALL_ERRINFO *)
  1601. //                object that will hold an array of error structures.
  1602.  
  1603. NTDSAPI
  1604. DWORD
  1605. WINAPI
  1606. DsReplicaSyncAllA (
  1607.     HANDLE                hDS,
  1608.     LPCSTR                pszNameContext,
  1609.     ULONG                ulFlags,
  1610.     BOOL (__stdcall *            pFnCallBack) (LPVOID, PDS_REPSYNCALL_UPDATEA),
  1611.     LPVOID                pCallbackData,
  1612.     PDS_REPSYNCALL_ERRINFOA **        pErrors
  1613.     );
  1614.  
  1615. NTDSAPI
  1616. DWORD
  1617. WINAPI
  1618. DsReplicaSyncAllW (
  1619.     HANDLE                hDS,
  1620.     LPCWSTR                pszNameContext,
  1621.     ULONG                ulFlags,
  1622.     BOOL (__stdcall *            pFnCallBack) (LPVOID, PDS_REPSYNCALL_UPDATEW),
  1623.     LPVOID                pCallbackData,
  1624.     PDS_REPSYNCALL_ERRINFOW **        pErrors
  1625.     );
  1626.  
  1627. #ifdef UNICODE
  1628. #define DsReplicaSyncAll DsReplicaSyncAllW
  1629. #else
  1630. #define DsReplicaSyncAll DsReplicaSyncAllA
  1631. #endif
  1632.  
  1633. NTDSAPI
  1634. DWORD
  1635. WINAPI
  1636. DsRemoveDsServerW(
  1637.     HANDLE  hDs,             // in
  1638.     LPWSTR  ServerDN,        // in
  1639.     LPWSTR  DomainDN,        // in,  optional
  1640.     BOOL   *fLastDcInDomain, // out, optional
  1641.     BOOL    fCommit          // in
  1642.     );
  1643.  
  1644. NTDSAPI
  1645. DWORD
  1646. WINAPI
  1647. DsRemoveDsServerA(
  1648.     HANDLE  hDs,              // in
  1649.     LPSTR   ServerDN,         // in
  1650.     LPSTR   DomainDN,         // in,  optional
  1651.     BOOL   *fLastDcInDomain,  // out, optional
  1652.     BOOL    fCommit           // in
  1653.     );
  1654.  
  1655. #ifdef UNICODE
  1656. #define DsRemoveDsServer DsRemoveDsServerW
  1657. #else
  1658. #define DsRemoveDsServer DsRemoveDsServerA
  1659. #endif
  1660.  
  1661. NTDSAPI
  1662. DWORD
  1663. WINAPI
  1664. DsRemoveDsDomainW(
  1665.     HANDLE  hDs,               // in
  1666.     LPWSTR  DomainDN           // in
  1667.     );
  1668.  
  1669. NTDSAPI
  1670. DWORD
  1671. WINAPI
  1672. DsRemoveDsDomainA(
  1673.     HANDLE  hDs,               // in
  1674.     LPSTR   DomainDN           // in
  1675.     );
  1676.  
  1677. #ifdef UNICODE
  1678. #define DsRemoveDsDomain DsRemoveDsDomainW
  1679. #else
  1680. #define DsRemoveDsDomain DsRemoveDsDomainA
  1681. #endif
  1682.  
  1683. NTDSAPI
  1684. DWORD
  1685. WINAPI
  1686. DsListSitesA(
  1687.     HANDLE              hDs,            // in
  1688.     PDS_NAME_RESULTA    *ppSites);      // out
  1689.  
  1690. NTDSAPI
  1691. DWORD
  1692. WINAPI
  1693. DsListSitesW(
  1694.     HANDLE              hDs,            // in
  1695.     PDS_NAME_RESULTW    *ppSites);      // out
  1696.  
  1697. #ifdef UNICODE
  1698. #define DsListSites DsListSitesW
  1699. #else
  1700. #define DsListSites DsListSitesA
  1701. #endif
  1702.  
  1703. NTDSAPI
  1704. DWORD
  1705. WINAPI
  1706. DsListServersInSiteA(
  1707.     HANDLE              hDs,            // in
  1708.     LPCSTR              site,           // in
  1709.     PDS_NAME_RESULTA    *ppServers);    // out
  1710.  
  1711. NTDSAPI
  1712. DWORD
  1713. WINAPI
  1714. DsListServersInSiteW(
  1715.     HANDLE              hDs,            // in
  1716.     LPCWSTR             site,           // in
  1717.     PDS_NAME_RESULTW    *ppServers);    // out
  1718.  
  1719. #ifdef UNICODE
  1720. #define DsListServersInSite DsListServersInSiteW
  1721. #else
  1722. #define DsListServersInSite DsListServersInSiteA
  1723. #endif
  1724.  
  1725. NTDSAPI
  1726. DWORD
  1727. WINAPI
  1728. DsListDomainsInSiteA(
  1729.     HANDLE              hDs,            // in
  1730.     LPCSTR              site,           // in
  1731.     PDS_NAME_RESULTA    *ppDomains);    // out
  1732.  
  1733. NTDSAPI
  1734. DWORD
  1735. WINAPI
  1736. DsListDomainsInSiteW(
  1737.     HANDLE              hDs,            // in
  1738.     LPCWSTR             site,           // in
  1739.     PDS_NAME_RESULTW    *ppDomains);    // out
  1740.  
  1741. #ifdef UNICODE
  1742. #define DsListDomainsInSite DsListDomainsInSiteW
  1743. #else
  1744. #define DsListDomainsInSite DsListDomainsInSiteA
  1745. #endif
  1746.  
  1747. NTDSAPI
  1748. DWORD
  1749. WINAPI
  1750. DsListServersForDomainInSiteA(
  1751.     HANDLE              hDs,            // in
  1752.     LPCSTR              domain,         // in
  1753.     LPCSTR              site,           // in
  1754.     PDS_NAME_RESULTA    *ppServers);    // out
  1755.  
  1756. NTDSAPI
  1757. DWORD
  1758. WINAPI
  1759. DsListServersForDomainInSiteW(
  1760.     HANDLE              hDs,            // in
  1761.     LPCWSTR             domain,         // in
  1762.     LPCWSTR             site,           // in
  1763.     PDS_NAME_RESULTW    *ppServers);    // out
  1764.  
  1765. #ifdef UNICODE
  1766. #define DsListServersForDomainInSite DsListServersForDomainInSiteW
  1767. #else
  1768. #define DsListServersForDomainInSite DsListServersForDomainInSiteA
  1769. #endif
  1770.  
  1771. // Define indices for DsListInfoForServer return data.  Check status
  1772. // for each field as a given value may not be present.
  1773.  
  1774. #define DS_LIST_DSA_OBJECT_FOR_SERVER       0
  1775. #define DS_LIST_DNS_HOST_NAME_FOR_SERVER    1
  1776. #define DS_LIST_ACCOUNT_OBJECT_FOR_SERVER   2
  1777.  
  1778. NTDSAPI
  1779. DWORD
  1780. WINAPI
  1781. DsListInfoForServerA(
  1782.     HANDLE              hDs,            // in
  1783.     LPCSTR              server,         // in
  1784.     PDS_NAME_RESULTA    *ppInfo);       // out
  1785.  
  1786. NTDSAPI
  1787. DWORD
  1788. WINAPI
  1789. DsListInfoForServerW(
  1790.     HANDLE              hDs,            // in
  1791.     LPCWSTR             server,         // in
  1792.     PDS_NAME_RESULTW    *ppInfo);       // out
  1793.  
  1794. #ifdef UNICODE
  1795. #define DsListInfoForServer DsListInfoForServerW
  1796. #else
  1797. #define DsListInfoForServer DsListInfoForServerA
  1798. #endif
  1799.  
  1800. // Define indices for DsListRoles return data.  Check status for
  1801. // each field as a given value may not be present.
  1802.  
  1803. #define DS_ROLE_SCHEMA_OWNER                0
  1804. #define DS_ROLE_DOMAIN_OWNER                1
  1805. #define DS_ROLE_PDC_OWNER                   2
  1806. #define DS_ROLE_RID_OWNER                   3
  1807. #define DS_ROLE_INFRASTRUCTURE_OWNER        4
  1808.  
  1809. NTDSAPI
  1810. DWORD
  1811. WINAPI
  1812. DsListRolesA(
  1813.     HANDLE              hDs,            // in
  1814.     PDS_NAME_RESULTA    *ppRoles);      // out
  1815.  
  1816. NTDSAPI
  1817. DWORD
  1818. WINAPI
  1819. DsListRolesW(
  1820.     HANDLE              hDs,            // in
  1821.     PDS_NAME_RESULTW    *ppRoles);      // out
  1822.  
  1823. #ifdef UNICODE
  1824. #define DsListRoles DsListRolesW
  1825. #else
  1826. #define DsListRoles DsListRolesA
  1827. #endif
  1828.  
  1829. // Definitions required for DsMapSchemaGuid routines.
  1830.  
  1831. #define DS_SCHEMA_GUID_NOT_FOUND            0
  1832. #define DS_SCHEMA_GUID_ATTR                 1
  1833. #define DS_SCHEMA_GUID_ATTR_SET             2
  1834. #define DS_SCHEMA_GUID_CLASS                3
  1835. #define DS_SCHEMA_GUID_CONTROL_RIGHT        4
  1836.  
  1837. typedef struct
  1838. {
  1839.     GUID                    guid;       // mapped GUID
  1840.     DWORD                   guidType;   // DS_SCHEMA_GUID_* value
  1841. #ifdef MIDL_PASS
  1842.     [string,unique] CHAR    *pName;     // might be NULL
  1843. #else
  1844.     LPSTR                   pName;      // might be NULL
  1845. #endif
  1846.  
  1847. } DS_SCHEMA_GUID_MAPA, *PDS_SCHEMA_GUID_MAPA;
  1848.  
  1849. typedef struct
  1850. {
  1851.     GUID                    guid;       // mapped GUID
  1852.     DWORD                   guidType;   // DS_SCHEMA_GUID_* value
  1853. #ifdef MIDL_PASS
  1854.     [string,unique] WCHAR   *pName;     // might be NULL
  1855. #else
  1856.     LPWSTR                  pName;      // might be NULL
  1857. #endif
  1858.  
  1859. } DS_SCHEMA_GUID_MAPW, *PDS_SCHEMA_GUID_MAPW;
  1860.  
  1861. NTDSAPI
  1862. DWORD
  1863. WINAPI
  1864. DsMapSchemaGuidsA(
  1865.     HANDLE                  hDs,            // in
  1866.     DWORD                   cGuids,         // in
  1867.     GUID                    *rGuids,        // in
  1868.     DS_SCHEMA_GUID_MAPA     **ppGuidMap);   // out
  1869.  
  1870. NTDSAPI
  1871. VOID
  1872. WINAPI
  1873. DsFreeSchemaGuidMapA(
  1874.     PDS_SCHEMA_GUID_MAPA    pGuidMap);      // in
  1875.  
  1876. NTDSAPI
  1877. DWORD
  1878. WINAPI
  1879. DsMapSchemaGuidsW(
  1880.     HANDLE                  hDs,            // in
  1881.     DWORD                   cGuids,         // in
  1882.     GUID                    *rGuids,        // in
  1883.     DS_SCHEMA_GUID_MAPW     **ppGuidMap);   // out
  1884.  
  1885. NTDSAPI
  1886. VOID
  1887. WINAPI
  1888. DsFreeSchemaGuidMapW(
  1889.     PDS_SCHEMA_GUID_MAPW    pGuidMap);      // in
  1890.  
  1891. #ifdef UNICODE
  1892. #define DS_SCHEMA_GUID_MAP DS_SCHEMA_GUID_MAPW
  1893. #define PDS_SCHEMA_GUID_MAP PDS_SCHEMA_GUID_MAPW
  1894. #define DsMapSchemaGuids DsMapSchemaGuidsW
  1895. #define DsFreeSchemaGuidMap DsFreeSchemaGuidMapW
  1896. #else
  1897. #define DS_SCHEMA_GUID_MAP DS_SCHEMA_GUID_MAPA
  1898. #define PDS_SCHEMA_GUID_MAP PDS_SCHEMA_GUID_MAPA
  1899. #define DsMapSchemaGuids DsMapSchemaGuidsA
  1900. #define DsFreeSchemaGuidMap DsFreeSchemaGuidMapA
  1901. #endif
  1902.  
  1903. typedef struct
  1904. {
  1905. #ifdef MIDL_PASS
  1906.     [string,unique] CHAR    *NetbiosName;           // might be NULL
  1907.     [string,unique] CHAR    *DnsHostName;           // might be NULL
  1908.     [string,unique] CHAR    *SiteName;              // might be NULL
  1909.     [string,unique] CHAR    *ComputerObjectName;    // might be NULL
  1910.     [string,unique] CHAR    *ServerObjectName;      // might be NULL
  1911. #else
  1912.     LPSTR                   NetbiosName;            // might be NULL
  1913.     LPSTR                   DnsHostName;            // might be NULL
  1914.     LPSTR                   SiteName;               // might be NULL
  1915.     LPSTR                   ComputerObjectName;     // might be NULL
  1916.     LPSTR                   ServerObjectName;       // might be NULL
  1917. #endif
  1918.     BOOL                    fIsPdc;
  1919.     BOOL                    fDsEnabled;
  1920.  
  1921. } DS_DOMAIN_CONTROLLER_INFO_1A, *PDS_DOMAIN_CONTROLLER_INFO_1A;
  1922.  
  1923. typedef struct
  1924. {
  1925. #ifdef MIDL_PASS
  1926.     [string,unique] WCHAR   *NetbiosName;           // might be NULL
  1927.     [string,unique] WCHAR   *DnsHostName;           // might be NULL
  1928.     [string,unique] WCHAR   *SiteName;              // might be NULL
  1929.     [string,unique] WCHAR   *ComputerObjectName;    // might be NULL
  1930.     [string,unique] WCHAR   *ServerObjectName;      // might be NULL
  1931. #else
  1932.     LPWSTR                  NetbiosName;            // might be NULL
  1933.     LPWSTR                  DnsHostName;            // might be NULL
  1934.     LPWSTR                  SiteName;               // might be NULL
  1935.     LPWSTR                  ComputerObjectName;     // might be NULL
  1936.     LPWSTR                  ServerObjectName;       // might be NULL
  1937. #endif
  1938.     BOOL                    fIsPdc;
  1939.     BOOL                    fDsEnabled;
  1940.  
  1941. } DS_DOMAIN_CONTROLLER_INFO_1W, *PDS_DOMAIN_CONTROLLER_INFO_1W;
  1942.  
  1943. typedef struct
  1944. {
  1945. #ifdef MIDL_PASS
  1946.     [string,unique] CHAR    *NetbiosName;           // might be NULL
  1947.     [string,unique] CHAR    *DnsHostName;           // might be NULL
  1948.     [string,unique] CHAR    *SiteName;              // might be NULL
  1949.     [string,unique] CHAR    *SiteObjectName;        // might be NULL
  1950.     [string,unique] CHAR    *ComputerObjectName;    // might be NULL
  1951.     [string,unique] CHAR    *ServerObjectName;      // might be NULL
  1952.     [string,unique] CHAR    *NtdsDsaObjectName;     // might be NULL
  1953. #else
  1954.     LPSTR                   NetbiosName;            // might be NULL
  1955.     LPSTR                   DnsHostName;            // might be NULL
  1956.     LPSTR                   SiteName;               // might be NULL
  1957.     LPSTR                   SiteObjectName;         // might be NULL
  1958.     LPSTR                   ComputerObjectName;     // might be NULL
  1959.     LPSTR                   ServerObjectName;       // might be NULL
  1960.     LPSTR                   NtdsDsaObjectName;      // might be NULL
  1961. #endif
  1962.     BOOL                    fIsPdc;
  1963.     BOOL                    fDsEnabled;
  1964.     BOOL                    fIsGc;
  1965.  
  1966.     // Valid iff SiteObjectName non-NULL.
  1967.     GUID                    SiteObjectGuid;
  1968.     // Valid iff ComputerObjectName non-NULL.
  1969.     GUID                    ComputerObjectGuid;
  1970.     // Valid iff ServerObjectName non-NULL;
  1971.     GUID                    ServerObjectGuid;
  1972.     // Valid iff fDsEnabled is TRUE.
  1973.     GUID                    NtdsDsaObjectGuid;
  1974.  
  1975. } DS_DOMAIN_CONTROLLER_INFO_2A, *PDS_DOMAIN_CONTROLLER_INFO_2A;
  1976.  
  1977. typedef struct
  1978. {
  1979. #ifdef MIDL_PASS
  1980.     [string,unique] WCHAR   *NetbiosName;           // might be NULL
  1981.     [string,unique] WCHAR   *DnsHostName;           // might be NULL
  1982.     [string,unique] WCHAR   *SiteName;              // might be NULL
  1983.     [string,unique] WCHAR   *SiteObjectName;        // might be NULL
  1984.     [string,unique] WCHAR   *ComputerObjectName;    // might be NULL
  1985.     [string,unique] WCHAR   *ServerObjectName;      // might be NULL
  1986.     [string,unique] WCHAR   *NtdsDsaObjectName;     // might be NULL
  1987. #else
  1988.     LPWSTR                  NetbiosName;            // might be NULL
  1989.     LPWSTR                  DnsHostName;            // might be NULL
  1990.     LPWSTR                  SiteName;               // might be NULL
  1991.     LPWSTR                  SiteObjectName;         // might be NULL
  1992.     LPWSTR                  ComputerObjectName;     // might be NULL
  1993.     LPWSTR                  ServerObjectName;       // might be NULL
  1994.     LPWSTR                  NtdsDsaObjectName;      // might be NULL
  1995. #endif
  1996.     BOOL                    fIsPdc;
  1997.     BOOL                    fDsEnabled;
  1998.     BOOL                    fIsGc;
  1999.  
  2000.     // Valid iff SiteObjectName non-NULL.
  2001.     GUID                    SiteObjectGuid;
  2002.     // Valid iff ComputerObjectName non-NULL.
  2003.     GUID                    ComputerObjectGuid;
  2004.     // Valid iff ServerObjectName non-NULL;
  2005.     GUID                    ServerObjectGuid;
  2006.     // Valid iff fDsEnabled is TRUE.
  2007.     GUID                    NtdsDsaObjectGuid;
  2008.  
  2009. } DS_DOMAIN_CONTROLLER_INFO_2W, *PDS_DOMAIN_CONTROLLER_INFO_2W;
  2010.  
  2011. // The following APIs strictly find domain controller account objects 
  2012. // in the DS and return information associated with them.  As such, they
  2013. // may return entries which correspond to domain controllers long since
  2014. // decommissioned, etc. and there is no guarantee that there exists a 
  2015. // physical domain controller at all.  Use DsGetDcName (dsgetdc.h) to find
  2016. // live domain controllers for a domain.
  2017.  
  2018. NTDSAPI
  2019. DWORD
  2020. WINAPI
  2021. DsGetDomainControllerInfoA(
  2022.     HANDLE                          hDs,            // in
  2023.     LPCSTR                          DomainName,     // in
  2024.     DWORD                           InfoLevel,      // in
  2025.     DWORD                           *pcOut,         // out
  2026.     VOID                            **ppInfo);      // out
  2027.  
  2028. NTDSAPI
  2029. DWORD
  2030. WINAPI
  2031. DsGetDomainControllerInfoW(
  2032.     HANDLE                          hDs,            // in
  2033.     LPCWSTR                         DomainName,     // in
  2034.     DWORD                           InfoLevel,      // in
  2035.     DWORD                           *pcOut,         // out
  2036.     VOID                            **ppInfo);      // out
  2037.  
  2038. NTDSAPI
  2039. VOID
  2040. WINAPI
  2041. DsFreeDomainControllerInfoA(
  2042.     DWORD                           InfoLevel,      // in
  2043.     DWORD                           cInfo,          // in
  2044.     VOID                            *pInfo);        // in
  2045.  
  2046. NTDSAPI
  2047. VOID
  2048. WINAPI
  2049. DsFreeDomainControllerInfoW(
  2050.     DWORD                           InfoLevel,      // in
  2051.     DWORD                           cInfo,          // in
  2052.     VOID                            *pInfo);        // in
  2053.  
  2054. #ifdef UNICODE
  2055. #define DS_DOMAIN_CONTROLLER_INFO_1 DS_DOMAIN_CONTROLLER_INFO_1W
  2056. #define DS_DOMAIN_CONTROLLER_INFO_2 DS_DOMAIN_CONTROLLER_INFO_2W
  2057. #define PDS_DOMAIN_CONTROLLER_INFO_1 PDS_DOMAIN_CONTROLLER_INFO_1W
  2058. #define PDS_DOMAIN_CONTROLLER_INFO_2 PDS_DOMAIN_CONTROLLER_INFO_2W
  2059. #define DsGetDomainControllerInfo DsGetDomainControllerInfoW
  2060. #define DsFreeDomainControllerInfo DsFreeDomainControllerInfoW
  2061. #else
  2062. #define DS_DOMAIN_CONTROLLER_INFO_1 DS_DOMAIN_CONTROLLER_INFO_1A
  2063. #define DS_DOMAIN_CONTROLLER_INFO_2 DS_DOMAIN_CONTROLLER_INFO_2A
  2064. #define PDS_DOMAIN_CONTROLLER_INFO_1 PDS_DOMAIN_CONTROLLER_INFO_1A
  2065. #define PDS_DOMAIN_CONTROLLER_INFO_2 PDS_DOMAIN_CONTROLLER_INFO_2A
  2066. #define DsGetDomainControllerInfo DsGetDomainControllerInfoA
  2067. #define DsFreeDomainControllerInfo DsFreeDomainControllerInfoA
  2068. #endif
  2069.  
  2070. // Which task should be run?
  2071. typedef enum {
  2072.     DS_KCC_TASKID_UPDATE_TOPOLOGY = 0
  2073. } DS_KCC_TASKID;
  2074.  
  2075. // Don't wait for completion of the task; queue it and return.
  2076. #define DS_KCC_FLAG_ASYNC_OP    (1)
  2077.  
  2078. NTDSAPI
  2079. DWORD
  2080. WINAPI
  2081. DsReplicaConsistencyCheck(
  2082.     HANDLE          hDS,        // in
  2083.     DS_KCC_TASKID   TaskID,     // in
  2084.     DWORD           dwFlags);   // in
  2085.  
  2086.  
  2087. typedef enum _DS_REPL_INFO_TYPE {
  2088.     DS_REPL_INFO_NEIGHBORS        = 0,  // returns DS_REPL_NEIGHBORS *
  2089.     DS_REPL_INFO_CURSORS_FOR_NC   = 1,  // returns DS_REPL_CURSORS *
  2090.     DS_REPL_INFO_METADATA_FOR_OBJ = 2,  // returns DS_REPL_OBJECT_META_DATA *
  2091.     DS_REPL_INFO_KCC_DSA_CONNECT_FAILURES = 3,  // both return
  2092.     DS_REPL_INFO_KCC_DSA_LINK_FAILURES = 4,     //    DS_REPL_KCC_DSA_FAILURES *
  2093.     DS_REPL_INFO_PENDING_OPS      = 5,  // returns DS_REPL_PENDING_OPS *
  2094.     // <- insert new DS_REPL_INFO_* types here.
  2095.     DS_REPL_INFO_TYPE_MAX
  2096. } DS_REPL_INFO_TYPE;
  2097.  
  2098. // Bit values for the dwReplicaFlags field of the DS_REPL_NEIGHBOR structure.
  2099. #define DS_REPL_NBR_WRITEABLE                       (0x10)
  2100. #define DS_REPL_NBR_SYNC_ON_STARTUP                 (0x20)
  2101. #define DS_REPL_NBR_DO_SCHEDULED_SYNCS              (0x40)
  2102. #define DS_REPL_NBR_USE_ASYNC_INTERSITE_TRANSPORT   (0x80)
  2103. #define DS_REPL_NBR_TWO_WAY_SYNC                    (0x200)
  2104. #define DS_REPL_NBR_FULL_SYNC_IN_PROGRESS           (0x10000)
  2105. #define DS_REPL_NBR_FULL_SYNC_NEXT_PACKET           (0x20000)
  2106. #define DS_REPL_NBR_NEVER_SYNCED                    (0x200000)
  2107. #define DS_REPL_NBR_IGNORE_CHANGE_NOTIFICATIONS     (0x4000000)
  2108. #define DS_REPL_NBR_DISABLE_SCHEDULED_SYNC          (0x8000000)
  2109. #define DS_REPL_NBR_COMPRESS_CHANGES                (0x10000000)
  2110. #define DS_REPL_NBR_NO_CHANGE_NOTIFICATIONS         (0x20000000)
  2111.  
  2112. typedef struct _DS_REPL_NEIGHBORW {
  2113.     LPWSTR      pszNamingContext;
  2114.     LPWSTR      pszSourceDsaDN;
  2115.     LPWSTR      pszSourceDsaAddress;
  2116.     LPWSTR      pszAsyncIntersiteTransportDN;
  2117.     DWORD       dwReplicaFlags;
  2118.     DWORD       dwReserved;         // alignment
  2119.  
  2120.     UUID        uuidNamingContextObjGuid;
  2121.     UUID        uuidSourceDsaObjGuid;
  2122.     UUID        uuidSourceDsaInvocationID;
  2123.     UUID        uuidAsyncIntersiteTransportObjGuid;
  2124.  
  2125.     USN         usnLastObjChangeSynced;
  2126.     USN         usnAttributeFilter;
  2127.  
  2128.     FILETIME    ftimeLastSyncSuccess;
  2129.     FILETIME    ftimeLastSyncAttempt;
  2130.  
  2131.     DWORD       dwLastSyncResult;
  2132.     DWORD       cNumConsecutiveSyncFailures;
  2133. } DS_REPL_NEIGHBORW;
  2134.  
  2135. typedef struct _DS_REPL_NEIGHBORSW {
  2136.     DWORD       cNumNeighbors;
  2137.     DWORD       dwReserved;             // alignment
  2138. #ifdef MIDL_PASS
  2139.     [size_is(cNumNeighbors)] DS_REPL_NEIGHBORW rgNeighbor[];
  2140. #else
  2141.     DS_REPL_NEIGHBORW rgNeighbor[1];
  2142. #endif
  2143. } DS_REPL_NEIGHBORSW;
  2144.  
  2145. typedef struct _DS_REPL_CURSOR {
  2146.     UUID        uuidSourceDsaInvocationID;
  2147.     USN         usnAttributeFilter;
  2148. } DS_REPL_CURSOR;
  2149.  
  2150. typedef struct _DS_REPL_CURSORS {
  2151.     DWORD       cNumCursors;
  2152.     DWORD       dwReserved;             // alignment
  2153. #ifdef MIDL_PASS
  2154.     [size_is(cNumCursors)] DS_REPL_CURSOR rgCursor[];
  2155. #else
  2156.     DS_REPL_CURSOR rgCursor[1];
  2157. #endif
  2158. } DS_REPL_CURSORS;
  2159.  
  2160. typedef struct _DS_REPL_ATTR_META_DATA {
  2161.     LPWSTR      pszAttributeName;
  2162.     DWORD       dwVersion;
  2163.     FILETIME    ftimeLastOriginatingChange;
  2164.     UUID        uuidLastOriginatingDsaInvocationID;
  2165.     USN         usnOriginatingChange;   // in the originating DSA's USN space
  2166.     USN         usnLocalChange;         // in the local DSA's USN space
  2167. } DS_REPL_ATTR_META_DATA;
  2168.  
  2169. typedef struct _DS_REPL_OBJ_META_DATA {
  2170.     DWORD       cNumEntries;
  2171.     DWORD       dwReserved;             // alignment
  2172. #ifdef MIDL_PASS
  2173.     [size_is(cNumEntries)] DS_REPL_ATTR_META_DATA rgMetaData[];
  2174. #else
  2175.     DS_REPL_ATTR_META_DATA rgMetaData[1];
  2176. #endif
  2177. } DS_REPL_OBJ_META_DATA;
  2178.  
  2179. typedef struct _DS_REPL_KCC_DSA_FAILUREW {
  2180.     LPWSTR      pszDsaDN;
  2181.     UUID        uuidDsaObjGuid;
  2182.     FILETIME    ftimeFirstFailure;
  2183.     DWORD       cNumFailures;
  2184.     DWORD       dwLastResult;   // Win32 error code
  2185. } DS_REPL_KCC_DSA_FAILUREW;
  2186.  
  2187. typedef struct _DS_REPL_KCC_DSA_FAILURESW {
  2188.     DWORD       cNumEntries;
  2189.     DWORD       dwReserved;             // alignment
  2190. #ifdef MIDL_PASS
  2191.     [size_is(cNumEntries)] DS_REPL_KCC_DSA_FAILUREW rgDsaFailure[];
  2192. #else
  2193.     DS_REPL_KCC_DSA_FAILUREW rgDsaFailure[1];
  2194. #endif
  2195. } DS_REPL_KCC_DSA_FAILURESW;
  2196.  
  2197. typedef enum _DS_REPL_OP_TYPE {
  2198.     DS_REPL_OP_TYPE_SYNC = 0,
  2199.     DS_REPL_OP_TYPE_ADD,
  2200.     DS_REPL_OP_TYPE_DELETE,
  2201.     DS_REPL_OP_TYPE_MODIFY,
  2202.     DS_REPL_OP_TYPE_UPDATE_REFS
  2203. } DS_REPL_OP_TYPE;
  2204.  
  2205. typedef struct _DS_REPL_OPW {
  2206.     FILETIME        ftimeEnqueued;  // time at which the operation was enqueued
  2207.     ULONG           ulSerialNumber; // ID of this sync; unique per machine per boot
  2208.     ULONG           ulPriority;     // > priority, > urgency
  2209.     DS_REPL_OP_TYPE OpType;
  2210.     
  2211.     ULONG           ulOptions;      // Zero or more bits specific to OpType; e.g.,
  2212.                                     //  DS_REPADD_* for DS_REPL_OP_TYPE_ADD,
  2213.                                     //  DS_REPSYNC_* for DS_REPL_OP_TYPE_SYNC, etc.
  2214.     LPWSTR          pszNamingContext;
  2215.     LPWSTR          pszDsaDN;
  2216.     LPWSTR          pszDsaAddress;
  2217.                     
  2218.     UUID            uuidNamingContextObjGuid;
  2219.     UUID            uuidDsaObjGuid;
  2220. } DS_REPL_OPW;
  2221.  
  2222. typedef struct _DS_REPL_PENDING_OPSW {
  2223.     FILETIME            ftimeCurrentOpStarted;
  2224.     DWORD               cNumPendingOps;
  2225. #ifdef MIDL_PASS
  2226.     [size_is(cNumPendingOps)] DS_REPL_OPW rgPendingOp[];
  2227. #else
  2228.     DS_REPL_OPW         rgPendingOp[1];
  2229. #endif
  2230. } DS_REPL_PENDING_OPSW;
  2231.  
  2232.  
  2233. NTDSAPI
  2234. DWORD
  2235. WINAPI
  2236. DsReplicaGetInfoW(
  2237.     HANDLE              hDS,                        // in
  2238.     DS_REPL_INFO_TYPE   InfoType,                   // in
  2239.     LPCWSTR             pszObject,                  // in
  2240.     UUID *              puuidForSourceDsaObjGuid,   // in
  2241.     VOID **             ppInfo);                    // out
  2242.  
  2243. NTDSAPI
  2244. void
  2245. WINAPI
  2246. DsReplicaFreeInfo(
  2247.     DS_REPL_INFO_TYPE   InfoType,   // in
  2248.     VOID *              pInfo);     // in
  2249.  
  2250.  
  2251. #ifdef UNICODE
  2252. #define DsReplicaGetInfo          DsReplicaGetInfoW
  2253. #define DS_REPL_NEIGHBOR          DS_REPL_NEIGHBORW
  2254. #define DS_REPL_NEIGHBORS         DS_REPL_NEIGHBORSW
  2255. #define DS_REPL_KCC_DSA_FAILURES  DS_REPL_KCC_DSA_FAILURESW
  2256. #define DS_REPL_KCC_DSA_FAILURE   DS_REPL_KCC_DSA_FAILUREW
  2257. #define DS_REPL_OP                DS_REPL_OPW
  2258. #define DS_REPL_PENDING_OPS       DS_REPL_PENDING_OPSW
  2259. #else
  2260. // No ANSI equivalents currently supported.
  2261. #endif
  2262.  
  2263. NTDSAPI
  2264. DWORD
  2265. WINAPI
  2266. DsAddSidHistoryW(
  2267.     HANDLE                  hDS,                    // in
  2268.     DWORD                   Flags,                  // in - sbz for now
  2269.     LPCWSTR                 SrcDomain,              // in - DNS or NetBIOS
  2270.     LPCWSTR                 SrcPrincipal,           // in - SAM account name
  2271.     LPCWSTR                 SrcDomainController,    // in, optional
  2272.     RPC_AUTH_IDENTITY_HANDLE SrcDomainCreds,        // in - creds for src domain
  2273.     LPCWSTR                 DstDomain,              // in - DNS or NetBIOS
  2274.     LPCWSTR                 DstPrincipal);          // in - SAM account name
  2275.  
  2276. NTDSAPI
  2277. DWORD
  2278. WINAPI
  2279. DsAddSidHistoryA(
  2280.     HANDLE                  hDS,                    // in
  2281.     DWORD                   Flags,                  // in - sbz for now
  2282.     LPCSTR                  SrcDomain,              // in - DNS or NetBIOS
  2283.     LPCSTR                  SrcPrincipal,           // in - SAM account name
  2284.     LPCSTR                  SrcDomainController,    // in, optional
  2285.     RPC_AUTH_IDENTITY_HANDLE SrcDomainCreds,        // in - creds for src domain
  2286.     LPCSTR                  DstDomain,              // in - DNS or NetBIOS
  2287.     LPCSTR                  DstPrincipal);          // in - SAM account name
  2288.  
  2289. #ifdef UNICODE
  2290. #define DsAddSidHistory DsAddSidHistoryW
  2291. #else
  2292. #define DsAddSidHistory DsAddSidHistoryA
  2293. #endif
  2294.  
  2295. // The DsInheritSecurityIdentity API adds the source principal's SID and
  2296. // SID history to the destination principal's SID history and then DELETES
  2297. // THE SOURCE PRINCIPAL.  Source and destination principal must be in the
  2298. // same domain.
  2299.  
  2300. NTDSAPI
  2301. DWORD
  2302. WINAPI
  2303. DsInheritSecurityIdentityW(
  2304.     HANDLE                  hDS,                    // in
  2305.     DWORD                   Flags,                  // in - sbz for now
  2306.     LPCWSTR                 SrcPrincipal,           // in - distinguished name
  2307.     LPCWSTR                 DstPrincipal);          // in - distinguished name
  2308.  
  2309. NTDSAPI
  2310. DWORD
  2311. WINAPI
  2312. DsInheritSecurityIdentityA(
  2313.     HANDLE                  hDS,                    // in
  2314.     DWORD                   Flags,                  // in - sbz for now
  2315.     LPCSTR                  SrcPrincipal,           // in - distinguished name
  2316.     LPCSTR                  DstPrincipal);          // in - distinguished name
  2317.  
  2318. #ifdef UNICODE
  2319. #define DsInheritSecurityIdentity DsInheritSecurityIdentityW
  2320. #else
  2321. #define DsInheritSecurityIdentity DsInheritSecurityIdentityA
  2322. #endif
  2323.  
  2324. #ifndef MIDL_PASS
  2325. /*++
  2326. ==========================================================
  2327. NTDSAPI
  2328. DWORD
  2329. WINAPI
  2330. DsQuoteRdnValue(
  2331.     IN     DWORD    cUnquotedRdnValueLength,
  2332.     IN     LPCTCH   psUnquotedRdnValue,
  2333.     IN OUT DWORD    *pcQuotedRdnValueLength,
  2334.     OUT    LPTCH    psQuotedRdnValue
  2335.     )
  2336. /*++
  2337.  
  2338. Description
  2339.  
  2340.     This client call converts an RDN value into a quoted RDN value if
  2341.     the RDN value contains characters that require quotes. The resultant
  2342.     RDN can be submitted as part of a DN to the DS using various APIs
  2343.     such as LDAP.
  2344.  
  2345.     No quotes are added if none are needed. In this case, the
  2346.     output RDN value will be the same as the input RDN value.
  2347.  
  2348.     The RDN is quoted in accordance with the specification "Lightweight
  2349.     Directory Access Protocol (v3): UTF-8 String Representation of
  2350.     Distinguished Names", RFC 2253.
  2351.  
  2352.     The input and output RDN values are *NOT* NULL terminated.
  2353.  
  2354.     The changes made by this call can be undone by calling
  2355.     DsUnquoteRdnValue().
  2356.  
  2357. Arguments:
  2358.  
  2359.     cUnquotedRdnValueLength - The length of psUnquotedRdnValue in chars.
  2360.  
  2361.     psUnquotedRdnValue - Unquoted RDN value.
  2362.  
  2363.     pcQuotedRdnValueeLength - IN, maximum length of psQuotedRdnValue, in chars
  2364.                         OUT ERROR_SUCCESS, chars utilized in psQuotedRdnValue
  2365.                         OUT ERROR_BUFFER_OVERFLOW, chars needed in psQuotedRdnValue
  2366.  
  2367.     psQuotedRdnValue - The resultant and perhaps quoted RDN value
  2368.  
  2369. Return Value:
  2370.     ERROR_SUCCESS
  2371.         If quotes or escapes were needed, then psQuotedRdnValue contains
  2372.         the quoted, escaped version of psUnquotedRdnValue. Otherwise,
  2373.         psQuotedRdnValue contains a copy of psUnquotedRdnValue. In either
  2374.         case, pcQuotedRdnValueLength contains the space utilized, in chars.
  2375.  
  2376.     ERROR_BUFFER_OVERFLOW
  2377.         psQuotedRdnValueLength contains the space needed, in chars,
  2378.         to hold psQuotedRdnValue.
  2379.  
  2380.     ERROR_INVALID_PARAMETER
  2381.         Invalid parameter.
  2382.  
  2383.     ERROR_NOT_ENOUGH_MEMORY
  2384.         Allocation error.
  2385.  
  2386. --*/
  2387.  
  2388. NTDSAPI
  2389. DWORD
  2390. WINAPI
  2391. DsQuoteRdnValueW(
  2392.     IN     DWORD    cUnquotedRdnValueLength,
  2393.     IN     LPCWCH   psUnquotedRdnValue,
  2394.     IN OUT DWORD    *pcQuotedRdnValueLength,
  2395.     OUT    LPWCH    psQuotedRdnValue
  2396. );
  2397.  
  2398. NTDSAPI
  2399. DWORD
  2400. WINAPI
  2401. DsQuoteRdnValueA(
  2402.     IN     DWORD    cUnquotedRdnValueLength,
  2403.     IN     LPCCH    psUnquotedRdnValue,
  2404.     IN OUT DWORD    *pcQuotedRdnValueLength,
  2405.     OUT    LPCH     psQuotedRdnValue
  2406. );
  2407.  
  2408. #ifdef UNICODE
  2409. #define DsQuoteRdnValue DsQuoteRdnValueW
  2410. #else
  2411. #define DsQuoteRdnValue DsQuoteRdnValueA
  2412. #endif
  2413.  
  2414. /*++
  2415. ==========================================================
  2416. NTDSAPI
  2417. DWORD
  2418. WINAPI
  2419. DsUnquoteRdnValue(
  2420.     IN     DWORD    cQuotedRdnValueLength,
  2421.     IN     LPCTCH   psQuotedRdnValue,
  2422.     IN OUT DWORD    *pcUnquotedRdnValueLength,
  2423.     OUT    LPTCH    psUnquotedRdnValue
  2424.     )
  2425.  
  2426. Description
  2427.  
  2428.     This client call converts a quoted RDN Value into an unquoted RDN
  2429.     Value. The resultant RDN value should *NOT* be submitted as part
  2430.     of a DN to the DS using various APIs such as LDAP.
  2431.  
  2432.     When psQuotedRdnValue is quoted:
  2433.         The leading and trailing quote are removed.
  2434.  
  2435.         Whitespace before the first quote is discarded.
  2436.  
  2437.         Whitespace trailing the last quote is discarded.
  2438.  
  2439.         Escapes are removed and the char following the escape is kept.
  2440.  
  2441.     The following actions are taken when psQuotedRdnValue is unquoted:
  2442.  
  2443.         Leading whitespace is discarded.
  2444.  
  2445.         Trailing whitespace is kept.
  2446.  
  2447.         Escaped non-special chars return an error.
  2448.  
  2449.         Unescaped special chars return an error.
  2450.  
  2451.         RDN values beginning with # (ignoring leading whitespace) are
  2452.         treated as a stringized BER value and converted accordingly.
  2453.  
  2454.         Escaped hex digits (\89) are converted into a binary byte (0x89).
  2455.  
  2456.         Escapes are removed from escaped special chars.
  2457.  
  2458.     The following actions are always taken:
  2459.         Escaped special chars are unescaped.
  2460.  
  2461.     The input and output RDN values are not NULL terminated.
  2462.  
  2463. Arguments:
  2464.  
  2465.     cQuotedRdnValueLength - The length of psQuotedRdnValue in chars.
  2466.  
  2467.     psQuotedRdnValue - RDN value that may be quoted and may be escaped.
  2468.  
  2469.     pcUnquotedRdnValueLength - IN, maximum length of psUnquotedRdnValue, in chars
  2470.                           OUT ERROR_SUCCESS, chars used in psUnquotedRdnValue
  2471.                           OUT ERROR_BUFFER_OVERFLOW, chars needed for psUnquotedRdnValue
  2472.  
  2473.     psUnquotedRdnValue - The resultant unquoted RDN value.
  2474.  
  2475. Return Value:
  2476.     ERROR_SUCCESS
  2477.         psUnquotedRdnValue contains the unquoted and unescaped version
  2478.         of psQuotedRdnValue. pcUnquotedRdnValueLength contains the space
  2479.         used, in chars.
  2480.  
  2481.     ERROR_BUFFER_OVERFLOW
  2482.         psUnquotedRdnValueLength contains the space needed, in chars,
  2483.         to hold psUnquotedRdnValue.
  2484.  
  2485.     ERROR_INVALID_PARAMETER
  2486.         Invalid parameter.
  2487.  
  2488.     ERROR_NOT_ENOUGH_MEMORY
  2489.         Allocation error.
  2490.  
  2491. --*/
  2492.  
  2493. NTDSAPI
  2494. DWORD
  2495. WINAPI
  2496. DsUnquoteRdnValueW(
  2497.     IN     DWORD    cQuotedRdnValueLength,
  2498.     IN     LPCWCH   psQuotedRdnValue,
  2499.     IN OUT DWORD    *pcUnquotedRdnValueLength,
  2500.     OUT    LPWCH    psUnquotedRdnValue
  2501. );
  2502.  
  2503. NTDSAPI
  2504. DWORD
  2505. WINAPI
  2506. DsUnquoteRdnValueA(
  2507.     IN     DWORD    cQuotedRdnValueLength,
  2508.     IN     LPCCH    psQuotedRdnValue,
  2509.     IN OUT DWORD    *pcUnquotedRdnValueLength,
  2510.     OUT    LPCH     psUnquotedRdnValue
  2511. );
  2512.  
  2513. #ifdef UNICODE
  2514. #define DsUnquoteRdnValue DsUnquoteRdnValueW
  2515. #else
  2516. #define DsUnquoteRdnValue DsUnquoteRdnValueA
  2517. #endif
  2518. #ifdef __cplusplus
  2519. }
  2520. #endif
  2521. #endif !MIDL_PASS
  2522.  
  2523. #pragma option pop /*P_O_Pop*/
  2524. #endif // _NTDSAPI_H_
  2525.  
  2526.