jwasecext.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. {******************************************************************************}
  2. { }
  3. { SSPI Context Management 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: secext.h, released August 2001. The original Pascal }
  9. { code is: SecExt.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: JwaSecExt.pas,v 1.9 2005/09/06 16:36:50 marquardt Exp $
  43. unit JwaSecExt;
  44. {$WEAKPACKAGEUNIT}
  45. {$HPPEMIT ''}
  46. {$HPPEMIT '#include "secext.h"'}
  47. {$HPPEMIT ''}
  48. {$I jediapilib.inc}
  49. interface
  50. uses
  51. JwaSSPI, JwaWindows;
  52. //
  53. // Extended Name APIs for ADS
  54. //
  55. const
  56. // Examples for the following formats assume a fictitous company
  57. // which hooks into the global X.500 and DNS name spaces as follows.
  58. //
  59. // Enterprise root domain in DNS is
  60. //
  61. // widget.com
  62. //
  63. // Enterprise root domain in X.500 (RFC 1779 format) is
  64. //
  65. // O=Widget, C=US
  66. //
  67. // There exists the child domain
  68. //
  69. // engineering.widget.com
  70. //
  71. // equivalent to
  72. //
  73. // OU=Engineering, O=Widget, C=US
  74. //
  75. // There exists a container within the Engineering domain
  76. //
  77. // OU=Software, OU=Engineering, O=Widget, C=US
  78. //
  79. // There exists the user
  80. //
  81. // CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
  82. //
  83. // And this user's downlevel (pre-ADS) user name is
  84. //
  85. // Engineering\JohnDoe
  86. // unknown name type
  87. NameUnknown = 0;
  88. {$EXTERNALSYM NameUnknown}
  89. // CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
  90. NameFullyQualifiedDN = 1;
  91. {$EXTERNALSYM NameFullyQualifiedDN}
  92. // Engineering\JohnDoe
  93. NameSamCompatible = 2;
  94. {$EXTERNALSYM NameSamCompatible}
  95. // Probably "John Doe" but could be something else. I.e. The
  96. // display name is not necessarily the defining RDN.
  97. NameDisplay = 3;
  98. {$EXTERNALSYM NameDisplay}
  99. // String-ized GUID as returned by IIDFromString().
  100. // eg: {4fa050f0-f561-11cf-bdd9-00aa003a77b6}
  101. NameUniqueId = 6;
  102. {$EXTERNALSYM NameUniqueId}
  103. // engineering.widget.com/software/John Doe
  104. NameCanonical = 7;
  105. {$EXTERNALSYM NameCanonical}
  106. // [email protected]
  107. NameUserPrincipal = 8;
  108. {$EXTERNALSYM NameUserPrincipal}
  109. // Same as NameCanonical except that rightmost '/' is
  110. // replaced with '\n' - even in domain-only case.
  111. // eg: engineering.widget.com/software\nJohn Doe
  112. NameCanonicalEx = 9;
  113. {$EXTERNALSYM NameCanonicalEx}
  114. // www/srv.engineering.com/engineering.com
  115. NameServicePrincipal = 10;
  116. {$EXTERNALSYM NameServicePrincipal}
  117. // DNS domain name + SAM username
  118. // eg: engineering.widget.com\JohnDoe
  119. NameDnsDomain = 12;
  120. {$EXTERNALSYM NameDnsDomain}
  121. type
  122. EXTENDED_NAME_FORMAT = DWORD;
  123. {$EXTERNALSYM EXTENDED_NAME_FORMAT}
  124. PEXTENDED_NAME_FORMAT = ^EXTENDED_NAME_FORMAT;
  125. {$EXTERNALSYM PEXTENDED_NAME_FORMAT}
  126. TExtendedNameFormat = EXTENDED_NAME_FORMAT;
  127. PExtendedNameFormat = PEXTENDED_NAME_FORMAT;
  128. function GetUserNameExA(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPSTR;
  129. var nSize: ULONG): ByteBool; stdcall;
  130. {$EXTERNALSYM GetUserNameExA}
  131. function GetUserNameExW(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPWSTR;
  132. var nSize: ULONG): ByteBool; stdcall;
  133. {$EXTERNALSYM GetUserNameExW}
  134. function GetUserNameEx(NameFormat: EXTENDED_NAME_FORMAT; lpNameBuffer: LPTSTR;
  135. var nSize: ULONG): ByteBool; stdcall;
  136. {$EXTERNALSYM GetUserNameEx}
  137. function GetComputerObjectNameA(NameFormat: EXTENDED_NAME_FORMAT;
  138. lpNameBuffer: LPSTR; var nSize: ULONG): ByteBool; stdcall;
  139. {$EXTERNALSYM GetComputerObjectNameA}
  140. function GetComputerObjectNameW(NameFormat: EXTENDED_NAME_FORMAT;
  141. lpNameBuffer: LPWSTR; var nSize: ULONG): ByteBool; stdcall;
  142. {$EXTERNALSYM GetComputerObjectNameW}
  143. function GetComputerObjectName(NameFormat: EXTENDED_NAME_FORMAT;
  144. lpNameBuffer: LPTSTR; var nSize: ULONG): ByteBool; stdcall;
  145. {$EXTERNALSYM GetComputerObjectName}
  146. function TranslateNameA(lpAccountName: LPCSTR; AccountNameFormat,
  147. DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPSTR;
  148. var nSize: ULONG): ByteBool; stdcall;
  149. {$EXTERNALSYM TranslateNameA}
  150. function TranslateNameW(lpAccountName: LPCWSTR; AccountNameFormat,
  151. DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPWSTR;
  152. var nSize: ULONG): ByteBool; stdcall;
  153. {$EXTERNALSYM TranslateNameW}
  154. function TranslateName(lpAccountName: LPCTSTR; AccountNameFormat,
  155. DesiredNameFormat: EXTENDED_NAME_FORMAT; lpTranslatedName: LPTSTR;
  156. var nSize: ULONG): ByteBool; stdcall;
  157. {$EXTERNALSYM TranslateName}
  158. implementation
  159. uses
  160. JwaWinDLLNames;
  161. {$IFDEF DYNAMIC_LINK}
  162. var
  163. _GetUserNameExA: Pointer;
  164. function GetUserNameExA;
  165. begin
  166. GetProcedureAddress(_GetUserNameExA, secur32, 'GetUserNameExA');
  167. asm
  168. MOV ESP, EBP
  169. POP EBP
  170. JMP [_GetUserNameExA]
  171. end;
  172. end;
  173. var
  174. _GetUserNameExW: Pointer;
  175. function GetUserNameExW;
  176. begin
  177. GetProcedureAddress(_GetUserNameExW, secur32, 'GetUserNameExW');
  178. asm
  179. MOV ESP, EBP
  180. POP EBP
  181. JMP [_GetUserNameExW]
  182. end;
  183. end;
  184. var
  185. _GetUserNameEx: Pointer;
  186. function GetUserNameEx;
  187. begin
  188. GetProcedureAddress(_GetUserNameEx, secur32, 'GetUserNameEx' + AWSuffix);
  189. asm
  190. MOV ESP, EBP
  191. POP EBP
  192. JMP [_GetUserNameEx]
  193. end;
  194. end;
  195. var
  196. _GetComputerObjectNameA: Pointer;
  197. function GetComputerObjectNameA;
  198. begin
  199. GetProcedureAddress(_GetComputerObjectNameA, secur32, 'GetComputerObjectNameA');
  200. asm
  201. MOV ESP, EBP
  202. POP EBP
  203. JMP [_GetComputerObjectNameA]
  204. end;
  205. end;
  206. var
  207. _GetComputerObjectNameW: Pointer;
  208. function GetComputerObjectNameW;
  209. begin
  210. GetProcedureAddress(_GetComputerObjectNameW, secur32, 'GetComputerObjectNameW');
  211. asm
  212. MOV ESP, EBP
  213. POP EBP
  214. JMP [_GetComputerObjectNameW]
  215. end;
  216. end;
  217. var
  218. _GetComputerObjectName: Pointer;
  219. function GetComputerObjectName;
  220. begin
  221. GetProcedureAddress(_GetComputerObjectName, secur32, 'GetComputerObjectName' + AWSuffix);
  222. asm
  223. MOV ESP, EBP
  224. POP EBP
  225. JMP [_GetComputerObjectName]
  226. end;
  227. end;
  228. var
  229. _TranslateNameA: Pointer;
  230. function TranslateNameA;
  231. begin
  232. GetProcedureAddress(_TranslateNameA, secur32, 'TranslateNameA');
  233. asm
  234. MOV ESP, EBP
  235. POP EBP
  236. JMP [_TranslateNameA]
  237. end;
  238. end;
  239. var
  240. _TranslateNameW: Pointer;
  241. function TranslateNameW;
  242. begin
  243. GetProcedureAddress(_TranslateNameW, secur32, 'TranslateNameW');
  244. asm
  245. MOV ESP, EBP
  246. POP EBP
  247. JMP [_TranslateNameW]
  248. end;
  249. end;
  250. var
  251. _TranslateName: Pointer;
  252. function TranslateName;
  253. begin
  254. GetProcedureAddress(_TranslateName, secur32, 'TranslateName' + AWSuffix);
  255. asm
  256. MOV ESP, EBP
  257. POP EBP
  258. JMP [_TranslateName]
  259. end;
  260. end;
  261. {$ELSE}
  262. function GetUserNameExA; external secur32 name 'GetUserNameExA';
  263. function GetUserNameExW; external secur32 name 'GetUserNameExW';
  264. function GetUserNameEx; external secur32 name 'GetUserNameEx' + AWSuffix;
  265. function GetComputerObjectNameA; external secur32 name 'GetComputerObjectNameA';
  266. function GetComputerObjectNameW; external secur32 name 'GetComputerObjectNameW';
  267. function GetComputerObjectName; external secur32 name 'GetComputerObjectName' + AWSuffix;
  268. function TranslateNameA; external secur32 name 'TranslateNameA';
  269. function TranslateNameW; external secur32 name 'TranslateNameW';
  270. function TranslateName; external secur32 name 'TranslateName' + AWSuffix;
  271. {$ENDIF DYNAMIC_LINK}
  272. end.