jwasecext.pas 10 KB

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