Leaked source code of windows server 2003
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.

429 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. ULONG
  162. KerbAllocateNonce(
  163. VOID
  164. );
  165. #ifndef WIN32_CHICAGO
  166. PSID
  167. KerbMakeDomainRelativeSid(
  168. IN PSID DomainId,
  169. IN ULONG RelativeId
  170. );
  171. #endif // WIN32_CHICAGO
  172. #ifdef notdef
  173. VOID
  174. KerbFree(
  175. IN PVOID Buffer
  176. );
  177. #endif
  178. PVOID
  179. KerbAllocate(
  180. IN SIZE_T BufferSize
  181. );
  182. BOOLEAN
  183. KerbRunningPersonal(
  184. VOID
  185. );
  186. #ifndef WIN32_CHICAGO
  187. NTSTATUS
  188. KerbWaitForKdc(
  189. IN ULONG Timeout
  190. );
  191. NTSTATUS
  192. KerbWaitForService(
  193. IN LPWSTR ServiceName,
  194. IN OPTIONAL LPWSTR ServiceEvent,
  195. IN ULONG Timeout
  196. );
  197. #endif // WIN32_CHICAGO
  198. ULONG
  199. KerbMapContextFlags(
  200. IN ULONG ContextFlags
  201. );
  202. BOOLEAN
  203. KerbIsIpAddress(
  204. IN PUNICODE_STRING TargetName
  205. );
  206. VOID
  207. KerbHidePassword(
  208. IN OUT PUNICODE_STRING Password
  209. );
  210. VOID
  211. KerbRevealPassword(
  212. IN OUT PUNICODE_STRING Password
  213. );
  214. NTSTATUS
  215. KerbDuplicatePassword(
  216. OUT PUNICODE_STRING DestinationString,
  217. IN OPTIONAL PUNICODE_STRING SourceString
  218. );
  219. #ifdef notdef
  220. // use this if we ever need to map errors in kerb to something else.
  221. NTSTATUS
  222. KerbMapKerbNtStatusToNtStatus(
  223. IN NTSTATUS Status
  224. );
  225. #else
  226. #ifndef WIN32_CHICAGO
  227. //#if DBG
  228. //#define KerbMapKerbNtStatusToNtStatus(x) (RtlCheckForOrphanedCriticalSections(NtCurrentThread()),x)
  229. //#else
  230. #define KerbMapKerbNtStatusToNtStatus(x) (x)
  231. //#endif
  232. #else // WIN32_CHICAGO
  233. #define KerbMapKerbNtStatusToNtStatus(x) (x)
  234. #endif
  235. #endif
  236. NTSTATUS
  237. KerbExtractDomainName(
  238. OUT PUNICODE_STRING DomainName,
  239. IN PKERB_INTERNAL_NAME PrincipalName,
  240. IN PUNICODE_STRING TicketSourceDomain
  241. );
  242. VOID
  243. KerbUtcTimeToLocalTime(
  244. OUT PTimeStamp LocalTime,
  245. IN PTimeStamp SystemTime
  246. );
  247. ULONG
  248. KerbConvertKdcOptionsToTicketFlags(
  249. IN ULONG KdcOptions
  250. );
  251. NTSTATUS
  252. KerbUnpackErrorMethodData(
  253. IN PKERB_ERROR ErrorMessage,
  254. IN OUT OPTIONAL PKERB_ERROR_METHOD_DATA * ppErrorData
  255. );
  256. NTSTATUS
  257. KerbBuildHostAddresses(
  258. IN BOOLEAN IncludeIpAddresses,
  259. IN BOOLEAN IncludeNetbiosAddresses,
  260. OUT PKERB_HOST_ADDRESSES * HostAddresses
  261. );
  262. NTSTATUS
  263. KerbReceiveErrorMessage(
  264. IN PBYTE ErrorMessage,
  265. IN ULONG ErrorMessageSize,
  266. IN PKERB_CONTEXT Context,
  267. OUT PKERB_ERROR * DecodedErrorMessage,
  268. OUT PKERB_ERROR_METHOD_DATA * ErrorData
  269. );
  270. NTSTATUS
  271. KerbBuildGssErrorMessage(
  272. IN KERBERR Error,
  273. IN PBYTE ErrorData,
  274. IN ULONG ErrorDataSize,
  275. IN PKERB_CONTEXT Context,
  276. OUT PULONG ErrorMessageSize,
  277. OUT PBYTE * ErrorMessage
  278. );
  279. NTSTATUS
  280. KerbGetDnsHostName(
  281. OUT PUNICODE_STRING DnsHostName
  282. );
  283. NTSTATUS
  284. KerbSetComputerName(
  285. VOID
  286. );
  287. NTSTATUS
  288. KerbSetDomainName(
  289. IN PUNICODE_STRING DomainName,
  290. IN PUNICODE_STRING DnsDomainName,
  291. IN PSID DomainSid,
  292. IN GUID DomainGuid
  293. );
  294. BOOLEAN
  295. KerbIsThisOurDomain(
  296. IN PUNICODE_STRING DomainName
  297. );
  298. NTSTATUS
  299. KerbGetOurDomainName(
  300. OUT PUNICODE_STRING DomainName
  301. );
  302. KERBEROS_MACHINE_ROLE
  303. KerbGetGlobalRole(
  304. VOID
  305. );
  306. #ifndef WIN32_CHICAGO
  307. NTSTATUS
  308. KerbLoadKdc(
  309. VOID
  310. );
  311. NTSTATUS
  312. KerbRegisterForDomainChange(
  313. VOID
  314. );
  315. VOID
  316. KerbUnregisterForDomainChange(
  317. VOID
  318. );
  319. NTSTATUS
  320. KerbUpdateGlobalAddresses(
  321. IN PSOCKET_ADDRESS NewAddresses,
  322. IN ULONG NewAddressCount
  323. );
  324. NTSTATUS
  325. KerbCaptureTokenRestrictions(
  326. IN HANDLE TokenHandle,
  327. OUT PKERB_AUTHORIZATION_DATA Restrictions
  328. );
  329. NTSTATUS
  330. KerbBuildEncryptedAuthData(
  331. OUT PKERB_ENCRYPTED_DATA EncryptedAuthData,
  332. IN PKERB_TICKET_CACHE_ENTRY Ticket,
  333. IN PKERB_AUTHORIZATION_DATA PlainAuthData
  334. );
  335. NTSTATUS
  336. KerbGetRestrictedTgtForCredential(
  337. IN PKERB_LOGON_SESSION LogonSession,
  338. IN PKERB_CREDENTIAL Credential
  339. );
  340. NTSTATUS
  341. KerbAddRestrictionsToCredential(
  342. IN PKERB_LOGON_SESSION LogonSession,
  343. IN PKERB_CREDENTIAL Credential
  344. );
  345. BOOLEAN
  346. KerbRunningServer(
  347. VOID
  348. );
  349. #endif // WIN32_CHICAGO
  350. #endif // __KERBUTIL_H__