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 
43 // $Id: JwaAdsHlp.pas,v 1.12 2007/09/06 14:57:10 marquardt Exp $
44 
45 {$IFNDEF JWA_OMIT_SECTIONS}
46 unit JwaAdsHlp;
47 
48 {$WEAKPACKAGEUNIT}
49 {$ENDIF JWA_OMIT_SECTIONS}
50 
51 {$HPPEMIT ''}
52 {$HPPEMIT '#include "adshlp.h"'}
53 {$HPPEMIT ''}
54 
55 {$IFNDEF JWA_OMIT_SECTIONS}
56 {$I jediapilib.inc}
57 
58 interface
59 
60 uses
61   JwaActiveX, JwaAdsTLB, JwaWinType, JwaWinNT;
62 
63 {$ENDIF JWA_OMIT_SECTIONS}
64 
65 {$IFNDEF JWA_IMPLEMENTATIONSECTION}
66 
67 {$IFNDEF JWA_INCLUDEMODE}
68 
ADsGetObjectnull69 function ADsGetObject(lpszPathName: LPCWSTR; const riid: TGUID; out ppObject: Pointer): HRESULT; stdcall;
70 {$EXTERNALSYM ADsGetObject}
71 
ADsBuildEnumeratornull72 function ADsBuildEnumerator(pADsContainer: IADsContainer; out ppEnumVariant: IEnumVARIANT): HRESULT; stdcall;
73 {$EXTERNALSYM ADsBuildEnumerator}
74 
ADsFreeEnumeratornull75 function ADsFreeEnumerator(pEnumVariant: IEnumVARIANT): HRESULT; stdcall;
76 {$EXTERNALSYM ADsFreeEnumerator}
77 
ADsEnumerateNextnull78 function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
79   var pvar: OleVariant; var pcElementsFetched: ULONG): HRESULT; stdcall;
80 {$EXTERNALSYM ADsEnumerateNext}
81 
ADsBuildVarArrayStrnull82 function ADsBuildVarArrayStr(lppPathNames: LPWSTR; dwPathNames: DWORD;
83   var pVar: OleVariant): HRESULT; stdcall;
84 {$EXTERNALSYM ADsBuildVarArrayStr}
85 
ADsBuildVarArrayIntnull86 function ADsBuildVarArrayInt(lpdwObjectTypes: LPDWORD; dwObjectTypes: DWORD;
87   var pVar: OleVariant): HRESULT; stdcall;
88 {$EXTERNALSYM ADsBuildVarArrayInt}
89 
ADsOpenObjectnull90 function ADsOpenObject(lpszPathName, lpszUserName, lpszPassword: LPCWSTR;
91   dwReserved: DWORD; const riid: TGUID; out ppObject: Pointer): HRESULT; stdcall;
92 {$EXTERNALSYM ADsOpenObject}
93 
94 //
95 // Helper functions for extended error support
96 //
97 
ADsGetLastErrornull98 function ADsGetLastError(var lpError: DWORD; lpErrorBuf: LPWSTR;
99   dwErrorBufLen: DWORD; lpNameBuf: LPWSTR; dwNameBufLen: DWORD): HRESULT; stdcall;
100 {$EXTERNALSYM ADsGetLastError}
101 
102 procedure ADsSetLastError(dwErr: DWORD; pszError, pszProvider: LPCWSTR); stdcall;
103 {$EXTERNALSYM ADsSetLastError}
104 
105 //procedure ADsFreeAllErrorRecords; stdcall;
106 //{$EXTERNALSYM ADsFreeAllErrorRecords}
107 
AllocADsMemnull108 function AllocADsMem(cb: DWORD): LPVOID; stdcall;
109 {$EXTERNALSYM AllocADsMem}
110 
FreeADsMemnull111 function FreeADsMem(pMem: LPVOID): BOOL; stdcall;
112 {$EXTERNALSYM FreeADsMem}
113 
ReallocADsMemnull114 function ReallocADsMem(pOldMem: LPVOID; cbOld, cbNew: DWORD): LPVOID; stdcall;
115 {$EXTERNALSYM ReallocADsMem}
116 
AllocADsStrnull117 function AllocADsStr(pStr: LPCWSTR): LPWSTR; stdcall;
118 {$EXTERNALSYM AllocADsStr}
119 
FreeADsStrnull120 function FreeADsStr(pStr: LPWSTR): BOOL; stdcall;
121 {$EXTERNALSYM FreeADsStr}
122 
ReallocADsStrnull123 function ReallocADsStr(var ppStr: LPWSTR; pStr: LPWSTR): BOOL; stdcall;
124 {$EXTERNALSYM ReallocADsStr}
125 
ADsEncodeBinaryDatanull126 function ADsEncodeBinaryData(pbSrcData: PBYTE; dwSrcLen: DWORD;
127   var ppszDestData: LPWSTR): HRESULT; stdcall;
128 {$EXTERNALSYM ADsEncodeBinaryData}
129 
ADsDecodeBinaryDatanull130 function ADsDecodeBinaryData(szSrcData: LPCWSTR; var ppbDestData: PBYTE;
131   var pdwDestLen: ULONG): HRESULT; stdcall;
132 {$EXTERNALSYM ADsDecodeBinaryData}
133 
134 type
135   // imports of a type library sometimes are missing a few decls, these are just
136   // a few of them to make this file compile at all. I really should do all of
137   // them one day.
138 
139   PADSVALUE = ^_adsvalue;
140   {$EXTERNALSYM PADSVALUE}
141   PADS_ATTR_INFO = ^_ads_attr_info;
142   {$EXTERNALSYM PADS_ATTR_INFO}
143 
PropVariantToAdsTypenull144 function PropVariantToAdsType(var pVariant: OleVariant; dwNumVariant: DWORD;
145   var ppAdsValues: PADSVALUE; pdwNumValues: PDWORD): HRESULT; stdcall;
146 {$EXTERNALSYM PropVariantToAdsType}
147 
148 
AdsTypeToPropVariantnull149 function AdsTypeToPropVariant(pAdsValues: PADSVALUE; dwNumValues: DWORD;
150   var pVariant: OleVariant): HRESULT; stdcall;
151 {$EXTERNALSYM AdsTypeToPropVariant}
152 
153 procedure AdsFreeAdsValues(pAdsValues: PADSVALUE; dwNumValues: DWORD); stdcall;
154 {$EXTERNALSYM AdsFreeAdsValues}
155 
156 //
157 // Helper routines to convert IADsSecurityDescriptor to a binary
158 // security descriptor and also to convert a binary SD to
159 // IADsSecurityDescriptor.
160 //
161 
162 // TODO VARIANT!
163 
BinarySDToSecurityDescriptornull164 function BinarySDToSecurityDescriptor(pSecurityDescriptor: PSECURITY_DESCRIPTOR;
165   var pVarsec: VARIANT; pszServerName, userName, passWord: LPCWSTR; dwFlags: DWORD): HRESULT; stdcall;
166 {$EXTERNALSYM BinarySDToSecurityDescriptor}
167 
168 {$ENDIF JWA_INCLUDEMODE}
169 
SecurityDescriptorToBinarySDnull170 function SecurityDescriptorToBinarySD(vVarSecDes: VARIANT;
171   var ppSecurityDescriptor: PSECURITY_DESCRIPTOR; pdwSDLength: PDWORD;
172   pszServerName, userName, passWord: LPCWSTR; dwFlags: DWORD): HRESULT; stdcall;
173 {$EXTERNALSYM SecurityDescriptorToBinarySD}
174 
175 {$ENDIF JWA_IMPLEMENTATIONSECTION}
176 
177 {$IFNDEF JWA_OMIT_SECTIONS}
178 implementation
179 //uses ...
180 {$ENDIF JWA_OMIT_SECTIONS}
181 
182 {$IFNDEF JWA_INTERFACESECTION}
183 
184 {$IFNDEF JWA_INCLUDEMODE}
185 const
186   adslib = 'activeds.dll';
187 {$ENDIF JWA_INCLUDEMODE}
188 
189 //procedure ADsFreeAllErrorRecords
190 
191 {$IFDEF DYNAMIC_LINK}
192 
193 {$IFNDEF JWA_INCLUDEMODE}
194 
195 var
196   _ADsGetObject: Pointer;
197 
ADsGetObjectnull198 function ADsGetObject;
199 begin
200   GetProcedureAddress(_ADsGetObject, adslib, 'ADsGetObject');
201   asm
202         MOV     ESP, EBP
203         POP     EBP
204         JMP     [_ADsGetObject]
205   end;
206 end;
207 
208 var
209   _ADsBuildEnumerator: Pointer;
210 
ADsBuildEnumeratornull211 function ADsBuildEnumerator;
212 begin
213   GetProcedureAddress(_ADsBuildEnumerator, adslib, 'ADsBuildEnumerator');
214   asm
215         MOV     ESP, EBP
216         POP     EBP
217         JMP     [_ADsBuildEnumerator]
218   end;
219 end;
220 
221 var
222   _ADsFreeEnumerator: Pointer;
223 
ADsFreeEnumeratornull224 function ADsFreeEnumerator;
225 begin
226   GetProcedureAddress(_ADsFreeEnumerator, adslib, 'ADsFreeEnumerator');
227   asm
228         MOV     ESP, EBP
229         POP     EBP
230         JMP     [_ADsFreeEnumerator]
231   end;
232 end;
233 
234 var
235   _ADsEnumerateNext: Pointer;
236 
ADsEnumerateNextnull237 function ADsEnumerateNext;
238 begin
239   GetProcedureAddress(_ADsEnumerateNext, adslib, 'ADsEnumerateNext');
240   asm
241         MOV     ESP, EBP
242         POP     EBP
243         JMP     [_ADsEnumerateNext]
244   end;
245 end;
246 
247 var
248   _ADsBuildVarArrayStr: Pointer;
249 
ADsBuildVarArrayStrnull250 function ADsBuildVarArrayStr;
251 begin
252   GetProcedureAddress(_ADsBuildVarArrayStr, adslib, 'ADsBuildVarArrayStr');
253   asm
254         MOV     ESP, EBP
255         POP     EBP
256         JMP     [_ADsBuildVarArrayStr]
257   end;
258 end;
259 
260 var
261   _ADsBuildVarArrayInt: Pointer;
262 
ADsBuildVarArrayIntnull263 function ADsBuildVarArrayInt;
264 begin
265   GetProcedureAddress(_ADsBuildVarArrayInt, adslib, 'ADsBuildVarArrayInt');
266   asm
267         MOV     ESP, EBP
268         POP     EBP
269         JMP     [_ADsBuildVarArrayInt]
270   end;
271 end;
272 
273 var
274   _ADsOpenObject: Pointer;
275 
ADsOpenObjectnull276 function ADsOpenObject;
277 begin
278   GetProcedureAddress(_ADsOpenObject, adslib, 'ADsOpenObject');
279   asm
280         MOV     ESP, EBP
281         POP     EBP
282         JMP     [_ADsOpenObject]
283   end;
284 end;
285 
286 var
287   _ADsGetLastError: Pointer;
288 
ADsGetLastErrornull289 function ADsGetLastError;
290 begin
291   GetProcedureAddress(_ADsGetLastError, adslib, 'ADsGetLastError');
292   asm
293         MOV     ESP, EBP
294         POP     EBP
295         JMP     [_ADsGetLastError]
296   end;
297 end;
298 
299 var
300   _ADsSetLastError: Pointer;
301 
302 procedure ADsSetLastError;
303 begin
304   GetProcedureAddress(_ADsSetLastError, adslib, 'ADsSetLastError');
305   asm
306         MOV     ESP, EBP
307         POP     EBP
308         JMP     [_ADsSetLastError]
309   end;
310 end;
311 
312 var
313   _AllocADsMem: Pointer;
314 
AllocADsMemnull315 function AllocADsMem;
316 begin
317   GetProcedureAddress(_AllocADsMem, adslib, 'AllocADsMem');
318   asm
319         MOV     ESP, EBP
320         POP     EBP
321         JMP     [_AllocADsMem]
322   end;
323 end;
324 
325 var
326   _FreeADsMem: Pointer;
327 
FreeADsMemnull328 function FreeADsMem;
329 begin
330   GetProcedureAddress(_FreeADsMem, adslib, 'FreeADsMem');
331   asm
332         MOV     ESP, EBP
333         POP     EBP
334         JMP     [_FreeADsMem]
335   end;
336 end;
337 
338 var
339   _ReallocADsMem: Pointer;
340 
ReallocADsMemnull341 function ReallocADsMem;
342 begin
343   GetProcedureAddress(_ReallocADsMem, adslib, 'ReallocADsMem');
344   asm
345         MOV     ESP, EBP
346         POP     EBP
347         JMP     [_ReallocADsMem]
348   end;
349 end;
350 
351 var
352   _AllocADsStr: Pointer;
353 
AllocADsStrnull354 function AllocADsStr;
355 begin
356   GetProcedureAddress(_AllocADsStr, adslib, 'AllocADsStr');
357   asm
358         MOV     ESP, EBP
359         POP     EBP
360         JMP     [_AllocADsStr]
361   end;
362 end;
363 
364 var
365   _FreeADsStr: Pointer;
366 
FreeADsStrnull367 function FreeADsStr;
368 begin
369   GetProcedureAddress(_FreeADsStr, adslib, 'FreeADsStr');
370   asm
371         MOV     ESP, EBP
372         POP     EBP
373         JMP     [_FreeADsStr]
374   end;
375 end;
376 
377 var
378   _ReallocADsStr: Pointer;
379 
ReallocADsStrnull380 function ReallocADsStr;
381 begin
382   GetProcedureAddress(_ReallocADsStr, adslib, 'ReallocADsStr');
383   asm
384         MOV     ESP, EBP
385         POP     EBP
386         JMP     [_ReallocADsStr]
387   end;
388 end;
389 
390 var
391   _ADsEncodeBinaryData: Pointer;
392 
ADsEncodeBinaryDatanull393 function ADsEncodeBinaryData;
394 begin
395   GetProcedureAddress(_ADsEncodeBinaryData, adslib, 'ADsEncodeBinaryData');
396   asm
397         MOV     ESP, EBP
398         POP     EBP
399         JMP     [_ADsEncodeBinaryData]
400   end;
401 end;
402 
403 var
404   _ADsDecodeBinaryData: Pointer;
405 
ADsDecodeBinaryDatanull406 function ADsDecodeBinaryData;
407 begin
408   GetProcedureAddress(_ADsDecodeBinaryData, adslib, 'ADsDecodeBinaryData');
409   asm
410         MOV     ESP, EBP
411         POP     EBP
412         JMP     [_ADsDecodeBinaryData]
413   end;
414 end;
415 
416 var
417   _PropVariantToAdsType: Pointer;
418 
PropVariantToAdsTypenull419 function PropVariantToAdsType;
420 begin
421   GetProcedureAddress(_PropVariantToAdsType, adslib, 'PropVariantToAdsType');
422   asm
423         MOV     ESP, EBP
424         POP     EBP
425         JMP     [_PropVariantToAdsType]
426   end;
427 end;
428 
429 var
430   _AdsTypeToPropVariant: Pointer;
431 
AdsTypeToPropVariantnull432 function AdsTypeToPropVariant;
433 begin
434   GetProcedureAddress(_AdsTypeToPropVariant, adslib, 'AdsTypeToPropVariant');
435   asm
436         MOV     ESP, EBP
437         POP     EBP
438         JMP     [_AdsTypeToPropVariant]
439   end;
440 end;
441 
442 var
443   _AdsFreeAdsValues: Pointer;
444 
445 procedure AdsFreeAdsValues;
446 begin
447   GetProcedureAddress(_AdsFreeAdsValues, adslib, 'AdsFreeAdsValues');
448   asm
449         MOV     ESP, EBP
450         POP     EBP
451         JMP     [_AdsFreeAdsValues]
452   end;
453 end;
454 
455 var
456   _BinarySDToSecurityDescriptor: Pointer;
457 
BinarySDToSecurityDescriptornull458 function BinarySDToSecurityDescriptor;
459 begin
460   GetProcedureAddress(_BinarySDToSecurityDescriptor, adslib, 'BinarySDToSecurityDescriptor');
461   asm
462         MOV     ESP, EBP
463         POP     EBP
464         JMP     [_BinarySDToSecurityDescriptor]
465   end;
466 end;
467 
468 {$ENDIF JWA_INCLUDEMODE}
469 
470 var
471   _SecurityDescriptorToBinarySD: Pointer;
472 
SecurityDescriptorToBinarySDnull473 function SecurityDescriptorToBinarySD;
474 begin
475   GetProcedureAddress(_SecurityDescriptorToBinarySD, adslib, 'SecurityDescriptorToBinarySD');
476   asm
477         MOV     ESP, EBP
478         POP     EBP
479         JMP     [_SecurityDescriptorToBinarySD]
480   end;
481 end;
482 
483 {$ELSE}
484 
485 {$IFNDEF JWA_INCLUDEMODE}
ADsGetObjectnull486 function ADsGetObject; external adslib name 'ADsGetObject';
ADsBuildEnumeratornull487 function ADsBuildEnumerator; external adslib name 'ADsBuildEnumerator';
ADsFreeEnumeratornull488 function ADsFreeEnumerator; external adslib name 'ADsFreeEnumerator';
ADsEnumerateNextnull489 function ADsEnumerateNext; external adslib name 'ADsEnumerateNext';
ADsBuildVarArrayStrnull490 function ADsBuildVarArrayStr; external adslib name 'ADsBuildVarArrayStr';
ADsBuildVarArrayIntnull491 function ADsBuildVarArrayInt; external adslib name 'ADsBuildVarArrayInt';
ADsOpenObjectnull492 function ADsOpenObject; external adslib name 'ADsOpenObject';
ADsGetLastErrornull493 function ADsGetLastError; external adslib name 'ADsGetLastError';
494 procedure ADsSetLastError; external adslib name 'ADsSetLastError';
AllocADsMemnull495 function AllocADsMem; external adslib name 'AllocADsMem';
FreeADsMemnull496 function FreeADsMem; external adslib name 'FreeADsMem';
ReallocADsMemnull497 function ReallocADsMem; external adslib name 'ReallocADsMem';
AllocADsStrnull498 function AllocADsStr; external adslib name 'AllocADsStr';
FreeADsStrnull499 function FreeADsStr; external adslib name 'FreeADsStr';
ReallocADsStrnull500 function ReallocADsStr; external adslib name 'ReallocADsStr';
ADsEncodeBinaryDatanull501 function ADsEncodeBinaryData; external adslib name 'ADsEncodeBinaryData';
ADsDecodeBinaryDatanull502 function ADsDecodeBinaryData; external adslib name 'ADsDecodeBinaryData';
PropVariantToAdsTypenull503 function PropVariantToAdsType; external adslib name 'PropVariantToAdsType';
AdsTypeToPropVariantnull504 function AdsTypeToPropVariant; external adslib name 'AdsTypeToPropVariant';
505 procedure AdsFreeAdsValues; external adslib name 'AdsFreeAdsValues';
BinarySDToSecurityDescriptornull506 function BinarySDToSecurityDescriptor; external adslib name 'BinarySDToSecurityDescriptor';
507 {$ENDIF JWA_INCLUDEMODE}
508 
SecurityDescriptorToBinarySDnull509 function SecurityDescriptorToBinarySD; external adslib name 'SecurityDescriptorToBinarySD';
510 
511 {$ENDIF DYNAMIC_LINK}
512 
513 {$ENDIF JWA_INTERFACESECTION}
514 
515 {$IFNDEF JWA_OMIT_SECTIONS}
516 end.
517 {$ENDIF JWA_OMIT_SECTIONS}
518