jwalmjoin.pas 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. {******************************************************************************}
  2. { }
  3. { Lan Manager Join 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: lmjoin.h, released November 2001. The original Pascal }
  9. { code is: LmJoin.pas, released Februari 2002. 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 JwaLmJoin;
  43. {$WEAKPACKAGEUNIT}
  44. {$I jediapilib.inc}
  45. interface
  46. uses
  47. JwaLmCons, JwaWinType;
  48. {$HPPEMIT ''}
  49. {$HPPEMIT '#include "lmjoin.h"'}
  50. {$HPPEMIT ''}
  51. //
  52. // Types of name that can be validated
  53. //
  54. type
  55. _NETSETUP_NAME_TYPE = (
  56. NetSetupUnknown,
  57. NetSetupMachine,
  58. NetSetupWorkgroup,
  59. NetSetupDomain,
  60. NetSetupNonExistentDomain
  61. {$IFDEF WIN2000_UP}
  62. , NetSetupDnsMachine
  63. {$ENDIF WIN2000_UP}
  64. );
  65. {$EXTERNALSYM _NETSETUP_NAME_TYPE}
  66. NETSETUP_NAME_TYPE = _NETSETUP_NAME_TYPE;
  67. {$EXTERNALSYM NETSETUP_NAME_TYPE}
  68. PNETSETUP_NAME_TYPE = ^NETSETUP_NAME_TYPE;
  69. {$EXTERNALSYM PNETSETUP_NAME_TYPE}
  70. TNetSetupNameType = NETSETUP_NAME_TYPE;
  71. PNetSetupNameType = PNETSETUP_NAME_TYPE;
  72. //
  73. // Status of a workstation
  74. //
  75. _NETSETUP_JOIN_STATUS = (
  76. NetSetupUnknownStatus,
  77. NetSetupUnjoined,
  78. NetSetupWorkgroupName,
  79. NetSetupDomainName);
  80. {$EXTERNALSYM _NETSETUP_JOIN_STATUS}
  81. NETSETUP_JOIN_STATUS = _NETSETUP_JOIN_STATUS;
  82. {$EXTERNALSYM NETSETUP_JOIN_STATUS}
  83. PNETSETUP_JOIN_STATUS = ^NETSETUP_JOIN_STATUS;
  84. {$EXTERNALSYM PNETSETUP_JOIN_STATUS}
  85. TNetSetupJoinStatus = NETSETUP_JOIN_STATUS;
  86. PNetSetupJoinStatus = PNETSETUP_JOIN_STATUS;
  87. //
  88. // Flags to determine the behavior of the join/unjoin APIs
  89. //
  90. const
  91. NETSETUP_JOIN_DOMAIN = $00000001; // If not present, workgroup is joined
  92. {$EXTERNALSYM NETSETUP_JOIN_DOMAIN}
  93. NETSETUP_ACCT_CREATE = $00000002; // Do the server side account creation/rename
  94. {$EXTERNALSYM NETSETUP_ACCT_CREATE}
  95. NETSETUP_ACCT_DELETE = $00000004; // Delete the account when a domain is left
  96. {$EXTERNALSYM NETSETUP_ACCT_DELETE}
  97. NETSETUP_WIN9X_UPGRADE = $00000010; // Invoked during upgrade of Windows 9x to
  98. {$EXTERNALSYM NETSETUP_WIN9X_UPGRADE}
  99. // Windows NT
  100. NETSETUP_DOMAIN_JOIN_IF_JOINED = $00000020; // Allow the client to join a new domain
  101. {$EXTERNALSYM NETSETUP_DOMAIN_JOIN_IF_JOINED}
  102. // even if it is already joined to a domain
  103. NETSETUP_JOIN_UNSECURE = $00000040; // Performs an unsecure join
  104. {$EXTERNALSYM NETSETUP_JOIN_UNSECURE}
  105. NETSETUP_MACHINE_PWD_PASSED = $00000080; // Indicates that the machine (not user) password
  106. {$EXTERNALSYM NETSETUP_MACHINE_PWD_PASSED}
  107. // is passed. Valid only for unsecure joins
  108. NETSETUP_DEFER_SPN_SET = $00000100; // Specifies that writting SPN and DnsHostName
  109. {$EXTERNALSYM NETSETUP_DEFER_SPN_SET}
  110. // attributes on the computer object should be
  111. // defered until rename that will follow join
  112. NETSETUP_INSTALL_INVOCATION = $00040000; // The APIs were invoked during install
  113. {$EXTERNALSYM NETSETUP_INSTALL_INVOCATION}
  114. NETSETUP_IGNORE_UNSUPPORTED_FLAGS = $10000000; // If this bit is set, unrecognized flags
  115. // will be ignored by the NetJoin API and
  116. // the API will behave as if the flags
  117. // were not set.
  118. {$EXTERNALSYM NETSETUP_IGNORE_UNSUPPORTED_FLAGS}
  119. NETSETUP_VALID_UNJOIN_FLAGS = NETSETUP_ACCT_DELETE or NETSETUP_IGNORE_UNSUPPORTED_FLAGS;
  120. {$EXTERNALSYM NETSETUP_VALID_UNJOIN_FLAGS}
  121. //
  122. // 0x80000000 is reserved for internal use only
  123. //
  124. //
  125. // Joins a machine to the domain.
  126. //
  127. function NetJoinDomain(lpServer, lpDomain, lpAccountOU, lpAccount, lpPassword: LPCWSTR; fJoinOptions: DWORD): NET_API_STATUS; stdcall;
  128. {$EXTERNALSYM NetJoinDomain}
  129. function NetUnjoinDomain(lpServer, lpAccount, lpPassword: LPCWSTR; fUnjoinOptions: DWORD): NET_API_STATUS; stdcall;
  130. {$EXTERNALSYM NetUnjoinDomain}
  131. function NetRenameMachineInDomain(lpServer, lpNewMachineName, lpAccount, lpPassword: LPCWSTR; fRenameOptions: DWORD): NET_API_STATUS; stdcall;
  132. {$EXTERNALSYM NetRenameMachineInDomain}
  133. //
  134. // Determine the validity of a name
  135. //
  136. function NetValidateName(lpServer, lpName, lpAccount, lpPassword: LPCWSTR; NameType: NETSETUP_NAME_TYPE): NET_API_STATUS; stdcall;
  137. {$EXTERNALSYM NetValidateName}
  138. //
  139. // Determines whether a workstation is joined to a domain or not
  140. //
  141. function NetGetJoinInformation(lpServer: LPCWSTR; var lpNameBuffer: LPWSTR; BufferType: PNETSETUP_JOIN_STATUS): NET_API_STATUS; stdcall;
  142. {$EXTERNALSYM NetGetJoinInformation}
  143. //
  144. // Determines the list of OUs that the client can create a machine account in
  145. //
  146. function NetGetJoinableOUs(lpServer, lpDomain, lpAccount, lpPassword: LPCWSTR; OUCount: LPDWORD; var OUs: LPLPWSTR): NET_API_STATUS; stdcall;
  147. {$EXTERNALSYM NetGetJoinableOUs}
  148. //
  149. // Computer rename preparation APIs
  150. //
  151. const
  152. NET_IGNORE_UNSUPPORTED_FLAGS = $01;
  153. {$EXTERNALSYM NET_IGNORE_UNSUPPORTED_FLAGS}
  154. function NetAddAlternateComputerName(Server, AlternateName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  155. {$EXTERNALSYM NetAddAlternateComputerName}
  156. function NetRemoveAlternateComputerName(Server, AlternateName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  157. {$EXTERNALSYM NetRemoveAlternateComputerName}
  158. function NetSetPrimaryComputerName(Server, PrimaryName, DomainAccount, DomainAccountPassword: LPCWSTR; Reserved: ULONG): NET_API_STATUS; stdcall;
  159. {$EXTERNALSYM NetSetPrimaryComputerName}
  160. //
  161. // The following enumeration must be kept
  162. // in sync with COMPUTER_NAME_TYPE defined
  163. // in winbase.h
  164. //
  165. type
  166. _NET_COMPUTER_NAME_TYPE = (
  167. NetPrimaryComputerName,
  168. NetAlternateComputerNames,
  169. NetAllComputerNames,
  170. NetComputerNameTypeMax);
  171. {$EXTERNALSYM _NET_COMPUTER_NAME_TYPE}
  172. NET_COMPUTER_NAME_TYPE = _NET_COMPUTER_NAME_TYPE;
  173. {$EXTERNALSYM NET_COMPUTER_NAME_TYPE}
  174. PNET_COMPUTER_NAME_TYPE = ^NET_COMPUTER_NAME_TYPE;
  175. {$EXTERNALSYM PNET_COMPUTER_NAME_TYPE}
  176. TNetComputerNameType = NET_COMPUTER_NAME_TYPE;
  177. PNetComputerNameType = PNET_COMPUTER_NAME_TYPE;
  178. function NetEnumerateComputerNames(Server: LPCWSTR; NameType: NET_COMPUTER_NAME_TYPE; Reserved: ULONG; EntryCount: PDWORD; var ComputerNames: LPLPWSTR): NET_API_STATUS; stdcall;
  179. {$EXTERNALSYM NetEnumerateComputerNames}
  180. implementation
  181. {$IFDEF DYNAMIC_LINK}
  182. var
  183. _NetJoinDomain: Pointer;
  184. function NetJoinDomain;
  185. begin
  186. GetProcedureAddress(_NetJoinDomain, netapi32, 'NetJoinDomain');
  187. asm
  188. MOV ESP, EBP
  189. POP EBP
  190. JMP [_NetJoinDomain]
  191. end;
  192. end;
  193. var
  194. _NetUnjoinDomain: Pointer;
  195. function NetUnjoinDomain;
  196. begin
  197. GetProcedureAddress(_NetUnjoinDomain, netapi32, 'NetUnjoinDomain');
  198. asm
  199. MOV ESP, EBP
  200. POP EBP
  201. JMP [_NetUnjoinDomain]
  202. end;
  203. end;
  204. var
  205. _NetRenameMachineInDomain: Pointer;
  206. function NetRenameMachineInDomain;
  207. begin
  208. GetProcedureAddress(_NetRenameMachineInDomain, netapi32, 'NetRenameMachineInDomain');
  209. asm
  210. MOV ESP, EBP
  211. POP EBP
  212. JMP [_NetRenameMachineInDomain]
  213. end;
  214. end;
  215. var
  216. _NetValidateName: Pointer;
  217. function NetValidateName;
  218. begin
  219. GetProcedureAddress(_NetValidateName, netapi32, 'NetValidateName');
  220. asm
  221. MOV ESP, EBP
  222. POP EBP
  223. JMP [_NetValidateName]
  224. end;
  225. end;
  226. var
  227. _NetGetJoinInformation: Pointer;
  228. function NetGetJoinInformation;
  229. begin
  230. GetProcedureAddress(_NetGetJoinInformation, netapi32, 'NetGetJoinInformation');
  231. asm
  232. MOV ESP, EBP
  233. POP EBP
  234. JMP [_NetGetJoinInformation]
  235. end;
  236. end;
  237. var
  238. _NetGetJoinableOUs: Pointer;
  239. function NetGetJoinableOUs;
  240. begin
  241. GetProcedureAddress(_NetGetJoinableOUs, netapi32, 'NetGetJoinableOUs');
  242. asm
  243. MOV ESP, EBP
  244. POP EBP
  245. JMP [_NetGetJoinableOUs]
  246. end;
  247. end;
  248. var
  249. _NetAddAlternateComputerName: Pointer;
  250. function NetAddAlternateComputerName;
  251. begin
  252. GetProcedureAddress(_NetAddAlternateComputerName, netapi32, 'NetAddAlternateComputerName');
  253. asm
  254. MOV ESP, EBP
  255. POP EBP
  256. JMP [_NetAddAlternateComputerName]
  257. end;
  258. end;
  259. var
  260. _NetRemoveAlternateComputerName: Pointer;
  261. function NetRemoveAlternateComputerName;
  262. begin
  263. GetProcedureAddress(_NetRemoveAlternateComputerName, netapi32, 'NetRemoveAlternateComputerName');
  264. asm
  265. MOV ESP, EBP
  266. POP EBP
  267. JMP [_NetRemoveAlternateComputerName]
  268. end;
  269. end;
  270. var
  271. _NetSetPrimaryComputerName: Pointer;
  272. function NetSetPrimaryComputerName;
  273. begin
  274. GetProcedureAddress(_NetSetPrimaryComputerName, netapi32, 'NetSetPrimaryComputerName');
  275. asm
  276. MOV ESP, EBP
  277. POP EBP
  278. JMP [_NetSetPrimaryComputerName]
  279. end;
  280. end;
  281. var
  282. _NetEnumerateComputerNames: Pointer;
  283. function NetEnumerateComputerNames;
  284. begin
  285. GetProcedureAddress(_NetEnumerateComputerNames, netapi32, 'NetEnumerateComputerNames');
  286. asm
  287. MOV ESP, EBP
  288. POP EBP
  289. JMP [_NetEnumerateComputerNames]
  290. end;
  291. end;
  292. {$ELSE}
  293. function NetJoinDomain; external netapi32 name 'NetJoinDomain';
  294. function NetUnjoinDomain; external netapi32 name 'NetUnjoinDomain';
  295. function NetRenameMachineInDomain; external netapi32 name 'NetRenameMachineInDomain';
  296. function NetValidateName; external netapi32 name 'NetValidateName';
  297. function NetGetJoinInformation; external netapi32 name 'NetGetJoinInformation';
  298. function NetGetJoinableOUs; external netapi32 name 'NetGetJoinableOUs';
  299. function NetAddAlternateComputerName; external netapi32 name 'NetAddAlternateComputerName';
  300. function NetRemoveAlternateComputerName; external netapi32 name 'NetRemoveAlternateComputerName';
  301. function NetSetPrimaryComputerName; external netapi32 name 'NetSetPrimaryComputerName';
  302. function NetEnumerateComputerNames; external netapi32 name 'NetEnumerateComputerNames';
  303. {$ENDIF DYNAMIC_LINK}
  304. end.