Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

433 lines
11 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1992 - 1996
  6. //
  7. // File: kerbutil.h
  8. //
  9. // Contents: prototypes for Kerberos utility functions
  10. //
  11. //
  12. // History: 16-April-1996 Created MikeSw
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef __KERBUTIL_H__
  16. #define __KERBUTIL_H__
  17. ///////////////////////////////////////////////////////////////////////////////
  18. // //
  19. // Miscellaneous macros //
  20. // //
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // RELOCATE_ONE - Relocate a single pointer in a client buffer.
  24. //
  25. // Note: this macro is dependent on parameter names as indicated in the
  26. // description below. On error, this macro goes to 'Cleanup' with
  27. // 'Status' set to the NT Status code.
  28. //
  29. // The MaximumLength is forced to be Length.
  30. //
  31. // Define a macro to relocate a pointer in the buffer the client passed in
  32. // to be relative to 'ProtocolSubmitBuffer' rather than being relative to
  33. // 'ClientBufferBase'. The result is checked to ensure the pointer and
  34. // the data pointed to is within the first 'SubmitBufferSize' of the
  35. // 'ProtocolSubmitBuffer'.
  36. //
  37. // The relocated field must be aligned to a WCHAR boundary.
  38. //
  39. // _q - Address of UNICODE_STRING structure which points to data to be
  40. // relocated
  41. //
  42. #define RELOCATE_ONE( _q ) \
  43. { \
  44. ULONG_PTR Offset; \
  45. \
  46. Offset = (((PUCHAR)((_q)->Buffer)) - ((PUCHAR)ClientBufferBase)); \
  47. if ( Offset >= SubmitBufferSize || \
  48. Offset + (_q)->Length > SubmitBufferSize || \
  49. !COUNT_IS_ALIGNED( Offset, ALIGN_WCHAR) ) { \
  50. \
  51. Status = STATUS_INVALID_PARAMETER; \
  52. goto Cleanup; \
  53. } \
  54. \
  55. (_q)->Buffer = (PWSTR)(((PUCHAR)ProtocolSubmitBuffer) + Offset); \
  56. (_q)->MaximumLength = (_q)->Length ; \
  57. }
  58. //
  59. // NULL_RELOCATE_ONE - Relocate a single (possibly NULL) pointer in a client
  60. // buffer.
  61. //
  62. // This macro special cases a NULL pointer then calls RELOCATE_ONE. Hence
  63. // it has all the restrictions of RELOCATE_ONE.
  64. //
  65. //
  66. // _q - Address of UNICODE_STRING structure which points to data to be
  67. // relocated
  68. //
  69. #define NULL_RELOCATE_ONE( _q ) \
  70. { \
  71. if ( (_q)->Buffer == NULL ) { \
  72. if ( (_q)->Length != 0 ) { \
  73. Status = STATUS_INVALID_PARAMETER; \
  74. goto Cleanup; \
  75. } \
  76. } else if ( (_q)->Length == 0 ) { \
  77. (_q)->Buffer = NULL; \
  78. } else { \
  79. RELOCATE_ONE( _q ); \
  80. } \
  81. }
  82. //
  83. // RELOCATE_ONE_ENCODED - Relocate a unicode string pointer in a client
  84. // buffer. The upper byte of the length field may be an encryption seed
  85. // and should not be used for error checking.
  86. //
  87. // Note: this macro is dependent on parameter names as indicated in the
  88. // description below. On error, this macro goes to 'Cleanup' with
  89. // 'Status' set to the NT Status code.
  90. //
  91. // The MaximumLength is forced to be Length & 0x00ff.
  92. //
  93. // Define a macro to relocate a pointer in the buffer the client passed in
  94. // to be relative to 'ProtocolSubmitBuffer' rather than being relative to
  95. // 'ClientBufferBase'. The result is checked to ensure the pointer and
  96. // the data pointed to is within the first 'SubmitBufferSize' of the
  97. // 'ProtocolSubmitBuffer'.
  98. //
  99. // The relocated field must be aligned to a WCHAR boundary.
  100. //
  101. // _q - Address of UNICODE_STRING structure which points to data to be
  102. // relocated
  103. //
  104. #define RELOCATE_ONE_ENCODED( _q ) \
  105. { \
  106. ULONG_PTR Offset; \
  107. \
  108. Offset = ((PUCHAR)((_q)->Buffer)) - ((PUCHAR)ClientBufferBase); \
  109. if ( Offset > SubmitBufferSize || \
  110. Offset + ((_q)->Length & 0x00ff) > SubmitBufferSize || \
  111. !COUNT_IS_ALIGNED( Offset, ALIGN_WCHAR) ) { \
  112. \
  113. Status = STATUS_INVALID_PARAMETER; \
  114. goto Cleanup; \
  115. } \
  116. \
  117. (_q)->Buffer = (PWSTR)(((PUCHAR)ProtocolSubmitBuffer) + Offset); \
  118. (_q)->MaximumLength = (_q)->Length & 0x00ff; \
  119. }
  120. //
  121. // Following macro is used to initialize UNICODE strings
  122. //
  123. #define CONSTANT_UNICODE_STRING(s) { sizeof( s ) - sizeof( WCHAR ), sizeof( s ), s }
  124. #define NULL_UNICODE_STRING {0 , 0, NULL }
  125. #define EMPTY_UNICODE_STRING(s) { (s)->Buffer = NULL; (s)->Length = 0; (s)->MaximumLength = 0; }
  126. ///VOID
  127. // KerbSetTime(
  128. // IN OUT PTimeStamp TimeStamp,
  129. // IN LONGLONG Time
  130. // )
  131. #ifndef WIN32_CHICAGO
  132. #define KerbSetTime(_d_, _s_) (_d_)->QuadPart = (_s_)
  133. #else // WIN32_CHICAGO
  134. #define KerbSetTime(_d_, _s_) *(_d_) = (_s_)
  135. #endif // WIN32_CHICAGO
  136. // TimeStamp
  137. // KerbGetTime(
  138. // IN TimeStamp Time
  139. // )
  140. #ifndef WIN32_CHICAGO
  141. #define KerbGetTime(_x_) ((_x_).QuadPart)
  142. #else // WIN32_CHICAGO
  143. #define KerbGetTime(_x_) (_x_)
  144. #endif // WIN32_CHICAGO
  145. // VOID
  146. // KerbSetTimeInMinutes(
  147. // IN OUT PTimeStamp Time,
  148. // IN LONG TimeInMinutes
  149. // )
  150. #ifndef WIN32_CHICAGO
  151. #define KerbSetTimeInMinutes(_x_, _m_) (_x_)->QuadPart = (LONGLONG) 10000000 * 60 * (_m_)
  152. #else // WIN32_CHICAGO
  153. #define KerbSetTimeInMinutes(_x_, _m_) *(_x_) = (LONGLONG) 10000000 * 60 * (_m_)
  154. #endif // WIN32_CHICAGO
  155. NTSTATUS
  156. KerbSplitFullServiceName(
  157. IN PUNICODE_STRING FullServiceName,
  158. OUT PUNICODE_STRING DomainName,
  159. OUT PUNICODE_STRING ServiceName
  160. );
  161. NTSTATUS
  162. KerbSplitEmailName(
  163. IN PUNICODE_STRING EmailName,
  164. OUT PUNICODE_STRING DomainName,
  165. OUT PUNICODE_STRING ServiceName
  166. );
  167. ULONG
  168. KerbAllocateNonce(
  169. VOID
  170. );
  171. #ifndef WIN32_CHICAGO
  172. PSID
  173. KerbMakeDomainRelativeSid(
  174. IN PSID DomainId,
  175. IN ULONG RelativeId
  176. );
  177. #endif // WIN32_CHICAGO
  178. #ifdef notdef
  179. VOID
  180. KerbFree(
  181. IN PVOID Buffer
  182. );
  183. #endif
  184. PVOID
  185. KerbAllocate(
  186. IN ULONG BufferSize
  187. );
  188. BOOLEAN
  189. KerbRunningPersonal(
  190. VOID
  191. );
  192. #ifndef WIN32_CHICAGO
  193. NTSTATUS
  194. KerbWaitForKdc(
  195. IN ULONG Timeout
  196. );
  197. NTSTATUS
  198. KerbWaitForService(
  199. IN LPWSTR ServiceName,
  200. IN OPTIONAL LPWSTR ServiceEvent,
  201. IN ULONG Timeout
  202. );
  203. #endif // WIN32_CHICAGO
  204. ULONG
  205. KerbMapContextFlags(
  206. IN ULONG ContextFlags
  207. );
  208. BOOLEAN
  209. KerbIsIpAddress(
  210. IN PUNICODE_STRING TargetName
  211. );
  212. VOID
  213. KerbHidePassword(
  214. IN OUT PUNICODE_STRING Password
  215. );
  216. VOID
  217. KerbRevealPassword(
  218. IN OUT PUNICODE_STRING Password
  219. );
  220. NTSTATUS
  221. KerbDuplicatePassword(
  222. OUT PUNICODE_STRING DestinationString,
  223. IN OPTIONAL PUNICODE_STRING SourceString
  224. );
  225. #ifdef notdef
  226. // use this if we ever need to map errors in kerb to something else.
  227. NTSTATUS
  228. KerbMapKerbNtStatusToNtStatus(
  229. IN NTSTATUS Status
  230. );
  231. #else
  232. #ifndef WIN32_CHICAGO
  233. //#if DBG
  234. //#define KerbMapKerbNtStatusToNtStatus(x) (RtlCheckForOrphanedCriticalSections(NtCurrentThread()),x)
  235. //#else
  236. #define KerbMapKerbNtStatusToNtStatus(x) (x)
  237. //#endif
  238. #else // WIN32_CHICAGO
  239. #define KerbMapKerbNtStatusToNtStatus(x) (x)
  240. #endif
  241. #endif
  242. NTSTATUS
  243. KerbExtractDomainName(
  244. OUT PUNICODE_STRING DomainName,
  245. IN PKERB_INTERNAL_NAME PrincipalName,
  246. IN PUNICODE_STRING TicketSourceDomain
  247. );
  248. VOID
  249. KerbUtcTimeToLocalTime(
  250. OUT PTimeStamp LocalTime,
  251. IN PTimeStamp SystemTime
  252. );
  253. ULONG
  254. KerbConvertKdcOptionsToTicketFlags(
  255. IN ULONG KdcOptions
  256. );
  257. NTSTATUS
  258. KerbUnpackErrorMethodData(
  259. IN PKERB_ERROR ErrorMessage,
  260. IN OUT OPTIONAL PKERB_ERROR_METHOD_DATA * ppErrorData
  261. );
  262. NTSTATUS
  263. KerbBuildHostAddresses(
  264. IN BOOLEAN IncludeIpAddresses,
  265. IN BOOLEAN IncludeNetbiosAddresses,
  266. OUT PKERB_HOST_ADDRESSES * HostAddresses
  267. );
  268. NTSTATUS
  269. KerbReceiveErrorMessage(
  270. IN PBYTE ErrorMessage,
  271. IN ULONG ErrorMessageSize,
  272. IN PKERB_CONTEXT Context,
  273. OUT PKERB_ERROR * DecodedErrorMessage,
  274. OUT PKERB_ERROR_METHOD_DATA * ErrorData
  275. );
  276. NTSTATUS
  277. KerbBuildGssErrorMessage(
  278. IN KERBERR Error,
  279. IN PBYTE ErrorData,
  280. IN ULONG ErrorDataSize,
  281. IN PKERB_CONTEXT Context,
  282. OUT PULONG ErrorMessageSize,
  283. OUT PBYTE * ErrorMessage
  284. );
  285. NTSTATUS
  286. KerbGetDnsHostName(
  287. OUT PUNICODE_STRING DnsHostName
  288. );
  289. NTSTATUS
  290. KerbSetComputerName(
  291. VOID
  292. );
  293. NTSTATUS
  294. KerbSetDomainName(
  295. IN PUNICODE_STRING DomainName,
  296. IN PUNICODE_STRING DnsDomainName,
  297. IN PSID DomainSid,
  298. IN GUID DomainGuid
  299. );
  300. BOOLEAN
  301. KerbIsThisOurDomain(
  302. IN PUNICODE_STRING DomainName
  303. );
  304. NTSTATUS
  305. KerbGetOurDomainName(
  306. OUT PUNICODE_STRING DomainName
  307. );
  308. KERBEROS_MACHINE_ROLE
  309. KerbGetGlobalRole(
  310. VOID
  311. );
  312. #ifndef WIN32_CHICAGO
  313. NTSTATUS
  314. KerbLoadKdc(
  315. VOID
  316. );
  317. NTSTATUS
  318. KerbRegisterForDomainChange(
  319. VOID
  320. );
  321. VOID
  322. KerbUnregisterForDomainChange(
  323. VOID
  324. );
  325. NTSTATUS
  326. KerbUpdateGlobalAddresses(
  327. IN PSOCKET_ADDRESS NewAddresses,
  328. IN ULONG NewAddressCount
  329. );
  330. ULONG
  331. KerbUpdateMachineSidWorker(
  332. PVOID Parameter
  333. );
  334. VOID
  335. KerbWaitGetMachineSid(
  336. VOID
  337. );
  338. NTSTATUS
  339. KerbCaptureTokenRestrictions(
  340. IN HANDLE TokenHandle,
  341. OUT PKERB_AUTHORIZATION_DATA Restrictions
  342. );
  343. NTSTATUS
  344. KerbBuildEncryptedAuthData(
  345. OUT PKERB_ENCRYPTED_DATA EncryptedAuthData,
  346. IN PKERB_TICKET_CACHE_ENTRY Ticket,
  347. IN PKERB_AUTHORIZATION_DATA PlainAuthData
  348. );
  349. NTSTATUS
  350. KerbGetRestrictedTgtForCredential(
  351. IN PKERB_LOGON_SESSION LogonSession,
  352. IN PKERB_CREDENTIAL Credential
  353. );
  354. NTSTATUS
  355. KerbAddRestrictionsToCredential(
  356. IN PKERB_LOGON_SESSION LogonSession,
  357. IN PKERB_CREDENTIAL Credential
  358. );
  359. BOOLEAN
  360. KerbRunningServer(
  361. VOID
  362. );
  363. #endif // WIN32_CHICAGO
  364. #endif // __KERBUTIL_H__