PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jedi/jwapi/Win32API/JwaSecExt.pas

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