jwadsrole.pas 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. {******************************************************************************}
  2. { }
  3. { Directory Services API interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: dsrole.h, released June 2000. The original Pascal }
  9. { code is: DsRole.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaDSRole;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "dsrole.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinType;
  51. //
  52. // Domain information
  53. //
  54. type
  55. _DSROLE_MACHINE_ROLE = (
  56. DsRole_RoleStandaloneWorkstation,
  57. DsRole_RoleMemberWorkstation,
  58. DsRole_RoleStandaloneServer,
  59. DsRole_RoleMemberServer,
  60. DsRole_RoleBackupDomainController,
  61. DsRole_RolePrimaryDomainController);
  62. {$EXTERNALSYM _DSROLE_MACHINE_ROLE}
  63. DSROLE_MACHINE_ROLE = _DSROLE_MACHINE_ROLE;
  64. {$EXTERNALSYM DSROLE_MACHINE_ROLE}
  65. TDsRoleMachineRole = DSROLE_MACHINE_ROLE;
  66. //
  67. // Previous server state
  68. //
  69. _DSROLE_SERVER_STATE = (
  70. DsRoleServerUnknown,
  71. DsRoleServerPrimary,
  72. DsRoleServerBackup);
  73. {$EXTERNALSYM DSROLE_SERVER_STATE}
  74. DSROLE_SERVER_STATE = _DSROLE_SERVER_STATE;
  75. {$EXTERNALSYM DSROLE_SERVER_STATE}
  76. PDSROLE_SERVER_STATE = ^DSROLE_SERVER_STATE;
  77. {$EXTERNALSYM PDSROLE_SERVER_STATE}
  78. TDsRoleServerState = DSROLE_SERVER_STATE;
  79. _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = (
  80. DsRoleFiller0,
  81. DsRolePrimaryDomainInfoBasic,
  82. DsRoleUpgradeStatus,
  83. DsRoleOperationState);
  84. {$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
  85. DSROLE_PRIMARY_DOMAIN_INFO_LEVEL = _DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
  86. {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_LEVEL}
  87. TDsRolePrimaryDomainInfoLevel = DSROLE_PRIMARY_DOMAIN_INFO_LEVEL;
  88. //
  89. // Flags to be used with the PRIMARY_DOMAIN_INFO_LEVEL structures below
  90. //
  91. const
  92. DSROLE_PRIMARY_DS_RUNNING = $00000001;
  93. {$EXTERNALSYM DSROLE_PRIMARY_DS_RUNNING}
  94. DSROLE_PRIMARY_DS_MIXED_MODE = $00000002;
  95. {$EXTERNALSYM DSROLE_PRIMARY_DS_MIXED_MODE}
  96. DSROLE_UPGRADE_IN_PROGRESS = $00000004;
  97. {$EXTERNALSYM DSROLE_UPGRADE_IN_PROGRESS}
  98. DSROLE_PRIMARY_DOMAIN_GUID_PRESENT = $01000000;
  99. {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_GUID_PRESENT}
  100. //
  101. // Structure that correspond to the DSROLE_PRIMARY_DOMAIN_INFO_LEVEL
  102. //
  103. type
  104. PDSROLE_PRIMARY_DOMAIN_INFO_BASIC = ^DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  105. {$EXTERNALSYM PDSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  106. _DSROLE_PRIMARY_DOMAIN_INFO_BASIC = record
  107. MachineRole: DSROLE_MACHINE_ROLE;
  108. Flags: ULONG;
  109. DomainNameFlat: LPWSTR;
  110. DomainNameDns: LPWSTR;
  111. DomainForestName: LPWSTR;
  112. DomainGuid: GUID;
  113. end;
  114. {$EXTERNALSYM _DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  115. DSROLE_PRIMARY_DOMAIN_INFO_BASIC = _DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  116. {$EXTERNALSYM DSROLE_PRIMARY_DOMAIN_INFO_BASIC}
  117. TDsRolePrimaryDomainInfoBasic = DSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  118. PDsRolePrimaryDomainInfoBasic = PDSROLE_PRIMARY_DOMAIN_INFO_BASIC;
  119. PDSROLE_UPGRADE_STATUS_INFO = ^DSROLE_UPGRADE_STATUS_INFO;
  120. {$EXTERNALSYM PDSROLE_UPGRADE_STATUS_INFO}
  121. _DSROLE_UPGRADE_STATUS_INFO = record
  122. OperationState: ULONG;
  123. PreviousServerState: DSROLE_SERVER_STATE;
  124. end;
  125. {$EXTERNALSYM _DSROLE_UPGRADE_STATUS_INFO}
  126. DSROLE_UPGRADE_STATUS_INFO = _DSROLE_UPGRADE_STATUS_INFO;
  127. {$EXTERNALSYM DSROLE_UPGRADE_STATUS_INFO}
  128. TDsRoleUpgradeStatusInfo = DSROLE_UPGRADE_STATUS_INFO;
  129. PDsRoleUpgradeStatusInfo = PDSROLE_UPGRADE_STATUS_INFO;
  130. _DSROLE_OPERATION_STATE = (
  131. DsRoleOperationIdle,
  132. DsRoleOperationActive,
  133. DsRoleOperationNeedReboot);
  134. {$EXTERNALSYM _DSROLE_OPERATION_STATE}
  135. DSROLE_OPERATION_STATE = _DSROLE_OPERATION_STATE;
  136. {$EXTERNALSYM DSROLE_OPERATION_STATE}
  137. TDsRoleOperationState = DSROLE_OPERATION_STATE;
  138. PDSROLE_OPERATION_STATE_INFO = ^DSROLE_OPERATION_STATE_INFO;
  139. {$EXTERNALSYM PDSROLE_OPERATION_STATE_INFO}
  140. _DSROLE_OPERATION_STATE_INFO = record
  141. OperationState: DSROLE_OPERATION_STATE;
  142. end;
  143. {$EXTERNALSYM _DSROLE_OPERATION_STATE_INFO}
  144. DSROLE_OPERATION_STATE_INFO = _DSROLE_OPERATION_STATE_INFO;
  145. {$EXTERNALSYM DSROLE_OPERATION_STATE_INFO}
  146. TDsRoleOperationStateInfo = DSROLE_OPERATION_STATE_INFO;
  147. PDsRoleOperationStateInfo = PDSROLE_OPERATION_STATE_INFO;
  148. function DsRoleGetPrimaryDomainInformation(lpServer: LPCWSTR;
  149. InfoLevel: DSROLE_PRIMARY_DOMAIN_INFO_LEVEL; var Buffer: PVOID): DWORD; stdcall;
  150. {$EXTERNALSYM DsRoleGetPrimaryDomainInformation}
  151. procedure DsRoleFreeMemory(Buffer: PVOID); stdcall;
  152. {$EXTERNALSYM DsRoleFreeMemory}
  153. implementation
  154. const
  155. netapi32 = 'netapi32.dll';
  156. {$IFDEF DYNAMIC_LINK}
  157. var
  158. _DsRoleGetPrimaryDomainInfo: Pointer;
  159. function DsRoleGetPrimaryDomainInformation;
  160. begin
  161. GetProcedureAddress(_DsRoleGetPrimaryDomainInfo, netapi32, 'DsRoleGetPrimaryDomainInformation');
  162. asm
  163. MOV ESP, EBP
  164. POP EBP
  165. JMP [_DsRoleGetPrimaryDomainInfo]
  166. end;
  167. end;
  168. var
  169. _DsRoleFreeMemory: Pointer;
  170. procedure DsRoleFreeMemory;
  171. begin
  172. GetProcedureAddress(_DsRoleFreeMemory, netapi32, 'DsRoleFreeMemory');
  173. asm
  174. MOV ESP, EBP
  175. POP EBP
  176. JMP [_DsRoleFreeMemory]
  177. end;
  178. end;
  179. {$ELSE}
  180. function DsRoleGetPrimaryDomainInformation; external netapi32 name 'DsRoleGetPrimaryDomainInformation';
  181. procedure DsRoleFreeMemory; external netapi32 name 'DsRoleFreeMemory';
  182. {$ENDIF DYNAMIC_LINK}
  183. end.