jwaadshlp.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. {******************************************************************************}
  2. { }
  3. { Active Directory Helper Functions 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: adshlp.h, released June 2000. The original Pascal }
  9. { code is: AdsHlp.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 JwaAdsHlp;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "adshlp.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. ActiveX {TODO}, JwaAdsTLB, JwaWinType, JwaWinNT;
  51. function ADsGetObject(lpszPathName: LPCWSTR; const riid: TGUID; out ppObject: Pointer): HRESULT; stdcall;
  52. {$EXTERNALSYM ADsGetObject}
  53. function ADsBuildEnumerator(pADsContainer: IADsContainer; out ppEnumVariant: IEnumVARIANT): HRESULT; stdcall;
  54. {$EXTERNALSYM ADsBuildEnumerator}
  55. function ADsFreeEnumerator(pEnumVariant: IEnumVARIANT): HRESULT; stdcall;
  56. {$EXTERNALSYM ADsFreeEnumerator}
  57. function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
  58. var pvar: OleVariant; var pcElementsFetched: ULONG): HRESULT; stdcall;
  59. {$EXTERNALSYM ADsEnumerateNext}
  60. function ADsBuildVarArrayStr(lppPathNames: LPWSTR; dwPathNames: DWORD;
  61. var pVar: OleVariant): HRESULT; stdcall;
  62. {$EXTERNALSYM ADsBuildVarArrayStr}
  63. function ADsBuildVarArrayInt(lpdwObjectTypes: LPDWORD; dwObjectTypes: DWORD;
  64. var pVar: OleVariant): HRESULT; stdcall;
  65. {$EXTERNALSYM ADsBuildVarArrayInt}
  66. function ADsOpenObject(lpszPathName, lpszUserName, lpszPassword: LPCWSTR;
  67. dwReserved: DWORD; const riid: TGUID; out ppObject: Pointer): HRESULT; stdcall;
  68. {$EXTERNALSYM ADsOpenObject}
  69. //
  70. // Helper functions for extended error support
  71. //
  72. function ADsGetLastError(var lpError: DWORD; lpErrorBuf: LPWSTR;
  73. dwErrorBufLen: DWORD; lpNameBuf: LPWSTR; dwNameBufLen: DWORD): HRESULT; stdcall;
  74. {$EXTERNALSYM ADsGetLastError}
  75. procedure ADsSetLastError(dwErr: DWORD; pszError, pszProvider: LPCWSTR); stdcall;
  76. {$EXTERNALSYM ADsSetLastError}
  77. //procedure ADsFreeAllErrorRecords; stdcall;
  78. //{$EXTERNALSYM ADsFreeAllErrorRecords}
  79. function AllocADsMem(cb: DWORD): LPVOID; stdcall;
  80. {$EXTERNALSYM AllocADsMem}
  81. function FreeADsMem(pMem: LPVOID): BOOL; stdcall;
  82. {$EXTERNALSYM FreeADsMem}
  83. function ReallocADsMem(pOldMem: LPVOID; cbOld, cbNew: DWORD): LPVOID; stdcall;
  84. {$EXTERNALSYM ReallocADsMem}
  85. function AllocADsStr(pStr: LPCWSTR): LPWSTR; stdcall;
  86. {$EXTERNALSYM AllocADsStr}
  87. function FreeADsStr(pStr: LPWSTR): BOOL; stdcall;
  88. {$EXTERNALSYM FreeADsStr}
  89. function ReallocADsStr(var ppStr: LPWSTR; pStr: LPWSTR): BOOL; stdcall;
  90. {$EXTERNALSYM ReallocADsStr}
  91. function ADsEncodeBinaryData(pbSrcData: PBYTE; dwSrcLen: DWORD;
  92. var ppszDestData: LPWSTR): HRESULT; stdcall;
  93. {$EXTERNALSYM ADsEncodeBinaryData}
  94. function ADsDecodeBinaryData(szSrcData: LPCWSTR; var ppbDestData: PBYTE;
  95. var pdwDestLen: ULONG): HRESULT; stdcall;
  96. {$EXTERNALSYM ADsDecodeBinaryData}
  97. type
  98. // imports of a type library sometimes are missing a few decls, these are just
  99. // a few of them to make this file compile at all. I really should do all of
  100. // them one day.
  101. PADSVALUE = ^_adsvalue;
  102. {$EXTERNALSYM PADSVALUE}
  103. PADS_ATTR_INFO = ^_ads_attr_info;
  104. {$EXTERNALSYM PADS_ATTR_INFO}
  105. function PropVariantToAdsType(var pVariant: OleVariant; dwNumVariant: DWORD;
  106. var ppAdsValues: PADSVALUE; pdwNumValues: PDWORD): HRESULT; stdcall;
  107. {$EXTERNALSYM PropVariantToAdsType}
  108. function AdsTypeToPropVariant(pAdsValues: PADSVALUE; dwNumValues: DWORD;
  109. var pVariant: OleVariant): HRESULT; stdcall;
  110. {$EXTERNALSYM AdsTypeToPropVariant}
  111. procedure AdsFreeAdsValues(pAdsValues: PADSVALUE; dwNumValues: DWORD); stdcall;
  112. {$EXTERNALSYM AdsFreeAdsValues}
  113. //
  114. // Helper routines to convert IADsSecurityDescriptor to a binary
  115. // security descriptor and also to convert a binary SD to
  116. // IADsSecurityDescriptor.
  117. //
  118. // TODO VARIANT!
  119. function BinarySDToSecurityDescriptor(pSecurityDescriptor: PSECURITY_DESCRIPTOR;
  120. var pVarsec: VARIANT; pszServerName, userName, passWord: LPCWSTR; dwFlags: DWORD): HRESULT; stdcall;
  121. {$EXTERNALSYM BinarySDToSecurityDescriptor}
  122. function SecurityDescriptorToBinarySD(vVarSecDes: VARIANT;
  123. var ppSecurityDescriptor: PSECURITY_DESCRIPTOR; pdwSDLength: PDWORD;
  124. pszServerName, userName, passWord: LPCWSTR; dwFlags: DWORD): HRESULT; stdcall;
  125. {$EXTERNALSYM SecurityDescriptorToBinarySD}
  126. implementation
  127. const
  128. adslib = 'activeds.dll';
  129. //procedure ADsFreeAllErrorRecords
  130. {$IFDEF DYNAMIC_LINK}
  131. var
  132. _ADsGetObject: Pointer;
  133. function ADsGetObject;
  134. begin
  135. GetProcedureAddress(_ADsGetObject, adslib, 'ADsGetObject');
  136. asm
  137. MOV ESP, EBP
  138. POP EBP
  139. JMP [_ADsGetObject]
  140. end;
  141. end;
  142. var
  143. _ADsBuildEnumerator: Pointer;
  144. function ADsBuildEnumerator;
  145. begin
  146. GetProcedureAddress(_ADsBuildEnumerator, adslib, 'ADsBuildEnumerator');
  147. asm
  148. MOV ESP, EBP
  149. POP EBP
  150. JMP [_ADsBuildEnumerator]
  151. end;
  152. end;
  153. var
  154. _ADsFreeEnumerator: Pointer;
  155. function ADsFreeEnumerator;
  156. begin
  157. GetProcedureAddress(_ADsFreeEnumerator, adslib, 'ADsFreeEnumerator');
  158. asm
  159. MOV ESP, EBP
  160. POP EBP
  161. JMP [_ADsFreeEnumerator]
  162. end;
  163. end;
  164. var
  165. _ADsEnumerateNext: Pointer;
  166. function ADsEnumerateNext;
  167. begin
  168. GetProcedureAddress(_ADsEnumerateNext, adslib, 'ADsEnumerateNext');
  169. asm
  170. MOV ESP, EBP
  171. POP EBP
  172. JMP [_ADsEnumerateNext]
  173. end;
  174. end;
  175. var
  176. _ADsBuildVarArrayStr: Pointer;
  177. function ADsBuildVarArrayStr;
  178. begin
  179. GetProcedureAddress(_ADsBuildVarArrayStr, adslib, 'ADsBuildVarArrayStr');
  180. asm
  181. MOV ESP, EBP
  182. POP EBP
  183. JMP [_ADsBuildVarArrayStr]
  184. end;
  185. end;
  186. var
  187. _ADsBuildVarArrayInt: Pointer;
  188. function ADsBuildVarArrayInt;
  189. begin
  190. GetProcedureAddress(_ADsBuildVarArrayInt, adslib, 'ADsBuildVarArrayInt');
  191. asm
  192. MOV ESP, EBP
  193. POP EBP
  194. JMP [_ADsBuildVarArrayInt]
  195. end;
  196. end;
  197. var
  198. _ADsOpenObject: Pointer;
  199. function ADsOpenObject;
  200. begin
  201. GetProcedureAddress(_ADsOpenObject, adslib, 'ADsOpenObject');
  202. asm
  203. MOV ESP, EBP
  204. POP EBP
  205. JMP [_ADsOpenObject]
  206. end;
  207. end;
  208. var
  209. _ADsGetLastError: Pointer;
  210. function ADsGetLastError;
  211. begin
  212. GetProcedureAddress(_ADsGetLastError, adslib, 'ADsGetLastError');
  213. asm
  214. MOV ESP, EBP
  215. POP EBP
  216. JMP [_ADsGetLastError]
  217. end;
  218. end;
  219. var
  220. _ADsSetLastError: Pointer;
  221. procedure ADsSetLastError;
  222. begin
  223. GetProcedureAddress(_ADsSetLastError, adslib, 'ADsSetLastError');
  224. asm
  225. MOV ESP, EBP
  226. POP EBP
  227. JMP [_ADsSetLastError]
  228. end;
  229. end;
  230. var
  231. _AllocADsMem: Pointer;
  232. function AllocADsMem;
  233. begin
  234. GetProcedureAddress(_AllocADsMem, adslib, 'AllocADsMem');
  235. asm
  236. MOV ESP, EBP
  237. POP EBP
  238. JMP [_AllocADsMem]
  239. end;
  240. end;
  241. var
  242. _FreeADsMem: Pointer;
  243. function FreeADsMem;
  244. begin
  245. GetProcedureAddress(_FreeADsMem, adslib, 'FreeADsMem');
  246. asm
  247. MOV ESP, EBP
  248. POP EBP
  249. JMP [_FreeADsMem]
  250. end;
  251. end;
  252. var
  253. _ReallocADsMem: Pointer;
  254. function ReallocADsMem;
  255. begin
  256. GetProcedureAddress(_ReallocADsMem, adslib, 'ReallocADsMem');
  257. asm
  258. MOV ESP, EBP
  259. POP EBP
  260. JMP [_ReallocADsMem]
  261. end;
  262. end;
  263. var
  264. _AllocADsStr: Pointer;
  265. function AllocADsStr;
  266. begin
  267. GetProcedureAddress(_AllocADsStr, adslib, 'AllocADsStr');
  268. asm
  269. MOV ESP, EBP
  270. POP EBP
  271. JMP [_AllocADsStr]
  272. end;
  273. end;
  274. var
  275. _FreeADsStr: Pointer;
  276. function FreeADsStr;
  277. begin
  278. GetProcedureAddress(_FreeADsStr, adslib, 'FreeADsStr');
  279. asm
  280. MOV ESP, EBP
  281. POP EBP
  282. JMP [_FreeADsStr]
  283. end;
  284. end;
  285. var
  286. _ReallocADsStr: Pointer;
  287. function ReallocADsStr;
  288. begin
  289. GetProcedureAddress(_ReallocADsStr, adslib, 'ReallocADsStr');
  290. asm
  291. MOV ESP, EBP
  292. POP EBP
  293. JMP [_ReallocADsStr]
  294. end;
  295. end;
  296. var
  297. _ADsEncodeBinaryData: Pointer;
  298. function ADsEncodeBinaryData;
  299. begin
  300. GetProcedureAddress(_ADsEncodeBinaryData, adslib, 'ADsEncodeBinaryData');
  301. asm
  302. MOV ESP, EBP
  303. POP EBP
  304. JMP [_ADsEncodeBinaryData]
  305. end;
  306. end;
  307. var
  308. _ADsDecodeBinaryData: Pointer;
  309. function ADsDecodeBinaryData;
  310. begin
  311. GetProcedureAddress(_ADsDecodeBinaryData, adslib, 'ADsDecodeBinaryData');
  312. asm
  313. MOV ESP, EBP
  314. POP EBP
  315. JMP [_ADsDecodeBinaryData]
  316. end;
  317. end;
  318. var
  319. _PropVariantToAdsType: Pointer;
  320. function PropVariantToAdsType;
  321. begin
  322. GetProcedureAddress(_PropVariantToAdsType, adslib, 'PropVariantToAdsType');
  323. asm
  324. MOV ESP, EBP
  325. POP EBP
  326. JMP [_PropVariantToAdsType]
  327. end;
  328. end;
  329. var
  330. _AdsTypeToPropVariant: Pointer;
  331. function AdsTypeToPropVariant;
  332. begin
  333. GetProcedureAddress(_AdsTypeToPropVariant, adslib, 'AdsTypeToPropVariant');
  334. asm
  335. MOV ESP, EBP
  336. POP EBP
  337. JMP [_AdsTypeToPropVariant]
  338. end;
  339. end;
  340. var
  341. _AdsFreeAdsValues: Pointer;
  342. procedure AdsFreeAdsValues;
  343. begin
  344. GetProcedureAddress(_AdsFreeAdsValues, adslib, 'AdsFreeAdsValues');
  345. asm
  346. MOV ESP, EBP
  347. POP EBP
  348. JMP [_AdsFreeAdsValues]
  349. end;
  350. end;
  351. var
  352. _BinarySDToSecurityDescriptor: Pointer;
  353. function BinarySDToSecurityDescriptor;
  354. begin
  355. GetProcedureAddress(_BinarySDToSecurityDescriptor, adslib, 'BinarySDToSecurityDescriptor');
  356. asm
  357. MOV ESP, EBP
  358. POP EBP
  359. JMP [_BinarySDToSecurityDescriptor]
  360. end;
  361. end;
  362. var
  363. _SecurityDescriptorToBinarySD: Pointer;
  364. function SecurityDescriptorToBinarySD;
  365. begin
  366. GetProcedureAddress(_SecurityDescriptorToBinarySD, adslib, 'SecurityDescriptorToBinarySD');
  367. asm
  368. MOV ESP, EBP
  369. POP EBP
  370. JMP [_SecurityDescriptorToBinarySD]
  371. end;
  372. end;
  373. {$ELSE}
  374. function ADsGetObject; external adslib name 'ADsGetObject';
  375. function ADsBuildEnumerator; external adslib name 'ADsBuildEnumerator';
  376. function ADsFreeEnumerator; external adslib name 'ADsFreeEnumerator';
  377. function ADsEnumerateNext; external adslib name 'ADsEnumerateNext';
  378. function ADsBuildVarArrayStr; external adslib name 'ADsBuildVarArrayStr';
  379. function ADsBuildVarArrayInt; external adslib name 'ADsBuildVarArrayInt';
  380. function ADsOpenObject; external adslib name 'ADsOpenObject';
  381. function ADsGetLastError; external adslib name 'ADsGetLastError';
  382. procedure ADsSetLastError; external adslib name 'ADsSetLastError';
  383. function AllocADsMem; external adslib name 'AllocADsMem';
  384. function FreeADsMem; external adslib name 'FreeADsMem';
  385. function ReallocADsMem; external adslib name 'ReallocADsMem';
  386. function AllocADsStr; external adslib name 'AllocADsStr';
  387. function FreeADsStr; external adslib name 'FreeADsStr';
  388. function ReallocADsStr; external adslib name 'ReallocADsStr';
  389. function ADsEncodeBinaryData; external adslib name 'ADsEncodeBinaryData';
  390. function ADsDecodeBinaryData; external adslib name 'ADsDecodeBinaryData';
  391. function PropVariantToAdsType; external adslib name 'PropVariantToAdsType';
  392. function AdsTypeToPropVariant; external adslib name 'AdsTypeToPropVariant';
  393. procedure AdsFreeAdsValues; external adslib name 'AdsFreeAdsValues';
  394. function BinarySDToSecurityDescriptor; external adslib name 'BinarySDToSecurityDescriptor';
  395. function SecurityDescriptorToBinarySD; external adslib name 'SecurityDescriptorToBinarySD';
  396. {$ENDIF DYNAMIC_LINK}
  397. end.