jwaadshlp.pas 14 KB

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