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.

355 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1993 Microsoft Corporation
  3. Module Name:
  4. ntlmsspi.h
  5. Abstract:
  6. Header file describing the interface to code common to the
  7. NT Lanman Security Support Provider (NtLmSsp) Service and the DLL.
  8. Author:
  9. Cliff Van Dyke (CliffV) 17-Sep-1993
  10. Revision History:
  11. --*/
  12. #ifndef _NTLMSSPI_INCLUDED_
  13. #define _NTLMSSPI_INCLUDED_
  14. #ifdef MAC
  15. #define SEC_FAR
  16. #define FAR
  17. #define _fmemcpy memcpy
  18. #define _fmemcmp memcmp
  19. #define _fmemset memset
  20. #define _fstrcmp strcmp
  21. #define _fstrcpy strcpy
  22. #define _fstrlen strlen
  23. #define _fstrncmp strncmp
  24. #endif
  25. #ifdef DOS
  26. #ifndef FAR
  27. #define FAR far
  28. #endif
  29. #ifndef SEC_FAR
  30. #define SEC_FAR FAR
  31. #endif
  32. #endif
  33. //#include <sysinc.h>
  34. #define MSV1_0_CHALLENGE_LENGTH 8
  35. #ifndef IN
  36. #define IN
  37. #define OUT
  38. #define OPTIONAL
  39. #endif
  40. #define ARGUMENT_PRESENT(ArgumentPointer) (\
  41. (CHAR *)(ArgumentPointer) != (CHAR *)(NULL) )
  42. #define UNREFERENCED_PARAMETER(P)
  43. #ifdef MAC
  44. #define swaplong(Value) \
  45. Value = ( (((Value) & 0xFF000000) >> 24) \
  46. | (((Value) & 0x00FF0000) >> 8) \
  47. | (((Value) & 0x0000FF00) << 8) \
  48. | (((Value) & 0x000000FF) << 24))
  49. #else
  50. #define swaplong(Value)
  51. #endif
  52. #ifdef MAC
  53. #define swapshort(Value) \
  54. Value = ( (((Value) & 0x00FF) << 8) \
  55. | (((Value) & 0xFF00) >> 8))
  56. #else
  57. #define swapshort(Value)
  58. #endif
  59. #ifndef TRUE
  60. typedef int BOOL;
  61. #define FALSE 0
  62. #define TRUE 1
  63. #endif
  64. typedef unsigned long ULONG, DWORD, *PULONG;
  65. typedef unsigned long SEC_FAR *LPULONG;
  66. typedef unsigned short USHORT, WORD;
  67. typedef char CHAR, *PCHAR;
  68. typedef unsigned char UCHAR, *PUCHAR;
  69. typedef unsigned char SEC_FAR *LPUCHAR;
  70. typedef void SEC_FAR *PVOID, *LPVOID;
  71. typedef unsigned char BOOLEAN;
  72. #ifndef BLDR_KERNEL_RUNTIME
  73. typedef long LUID, *PLUID;
  74. #endif
  75. //
  76. // Calculate the address of the base of the structure given its type, and an
  77. // address of a field within the structure.
  78. //
  79. #define CONTAINING_RECORD(address, type, field) ((type *)( \
  80. (PCHAR)(address) - \
  81. (PCHAR)(&((type *)0)->field)))
  82. //
  83. // Counted String
  84. //
  85. typedef struct _STRING {
  86. USHORT Length;
  87. USHORT MaximumLength;
  88. ULONG Buffer;
  89. } STRING, *PSTRING;
  90. #ifndef BLDR_KERNEL_RUNTIME
  91. typedef struct _LIST_ENTRY {
  92. struct _LIST_ENTRY *Flink;
  93. struct _LIST_ENTRY *Blink;
  94. } LIST_ENTRY, *PLIST_ENTRY;
  95. #endif
  96. //
  97. // VOID
  98. // InitializeListHead(
  99. // PLIST_ENTRY ListHead
  100. // );
  101. //
  102. #define InitializeListHead(ListHead) (\
  103. (ListHead)->Flink = (ListHead)->Blink = (ListHead))
  104. //
  105. // VOID
  106. // RemoveEntryList(
  107. // PLIST_ENTRY Entry
  108. // );
  109. //
  110. #define RemoveEntryList(Entry) {\
  111. PLIST_ENTRY _EX_Blink;\
  112. PLIST_ENTRY _EX_Flink;\
  113. _EX_Flink = (Entry)->Flink;\
  114. _EX_Blink = (Entry)->Blink;\
  115. _EX_Blink->Flink = _EX_Flink;\
  116. _EX_Flink->Blink = _EX_Blink;\
  117. }
  118. //
  119. // VOID
  120. // InsertHeadList(
  121. // PLIST_ENTRY ListHead,
  122. // PLIST_ENTRY Entry
  123. // );
  124. //
  125. #define InsertHeadList(ListHead,Entry) {\
  126. PLIST_ENTRY _EX_Flink;\
  127. PLIST_ENTRY _EX_ListHead;\
  128. _EX_ListHead = (ListHead);\
  129. _EX_Flink = _EX_ListHead->Flink;\
  130. (Entry)->Flink = _EX_Flink;\
  131. (Entry)->Blink = _EX_ListHead;\
  132. _EX_Flink->Blink = (Entry);\
  133. _EX_ListHead->Flink = (Entry);\
  134. }
  135. //
  136. // BOOLEAN
  137. // IsListEmpty(
  138. // PLIST_ENTRY ListHead
  139. // );
  140. //
  141. #define IsListEmpty(ListHead) \
  142. ((ListHead)->Flink == (ListHead))
  143. //
  144. // Maximum lifetime of a context
  145. //
  146. //#define NTLMSSP_MAX_LIFETIME (2*60*1000)L // 2 minutes
  147. #define NTLMSSP_MAX_LIFETIME 120000L // 2 minutes
  148. ////////////////////////////////////////////////////////////////////////
  149. //
  150. // Opaque Messages passed between client and server
  151. //
  152. ////////////////////////////////////////////////////////////////////////
  153. #define NTLMSSP_SIGNATURE "NTLMSSP"
  154. //
  155. // MessageType for the following messages.
  156. //
  157. typedef enum {
  158. NtLmNegotiate = 1,
  159. NtLmChallenge,
  160. NtLmAuthenticate
  161. } NTLM_MESSAGE_TYPE;
  162. //
  163. // Valid values of NegotiateFlags
  164. //
  165. #define NTLMSSP_NEGOTIATE_UNICODE 0x01 // Text strings are in unicode
  166. #define NTLMSSP_NEGOTIATE_OEM 0x02 // Text strings are in OEM
  167. #define NTLMSSP_REQUEST_TARGET 0x04 // Server should return its
  168. // authentication realm
  169. #define NTLMSSP_NEGOTIATE_SIGN 0x10 // request message signing
  170. #define NTLMSSP_NEGOTIATE_SEAL 0x20 // request message encrypting
  171. #define NTLMSSP_RESERVED 0x40 // reserved for past use
  172. #define NTLMSSP_NEGOTIATE_LM_KEY 0x80 // use LM session key
  173. #define NTLMSSP_NEGOTIATE_NETWARE 0x100 // NetWare authentication
  174. #define NTLMSSP_NEGOTIATE_NTLM 0x200 // NTLM authentication
  175. #define NTLMSSP_NEGOTIATE_NT_ONLY 0x400 // NT authentication only (no LM)
  176. #define NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED 0x1000 // Domain name supplied
  177. #define NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED 0x2000 // Workstation name supplied
  178. #define NTLMSSP_NEGOTIATE_LOCAL_CALL 0x4000 // Indicates client/server are same machine
  179. #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN 0x8000 // Sign for all security leveles
  180. #define NTLMSSP_NEGOTIATE_56 0x10000000 // negotiate 56 bit encryption
  181. #define NTLMSSP_NEGOTIATE_128 0x20000000 // negotiate 128 bit encryption
  182. //
  183. // Valid target types returned by the server in Negotiate Flags
  184. //
  185. #define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000 // TargetName is a domain name
  186. #define NTLMSSP_TARGET_TYPE_SERVER 0x20000 // TargetName is a server name
  187. #define NTLMSSP_TARGET_TYPE_SHARE 0x40000 // TargetName is a share name
  188. //
  189. // Opaque message returned from first call to InitializeSecurityContext
  190. //
  191. typedef struct _NEGOTIATE_MESSAGE {
  192. UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  193. ULONG MessageType;
  194. ULONG NegotiateFlags;
  195. } NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
  196. //
  197. // Opaque message returned from first call to AcceptSecurityContext
  198. //
  199. typedef struct _CHALLENGE_MESSAGE {
  200. UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  201. ULONG MessageType;
  202. STRING TargetName;
  203. ULONG NegotiateFlags;
  204. UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH];
  205. } CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
  206. //
  207. // Opaque message returned from second call to InitializeSecurityContext
  208. //
  209. typedef struct _AUTHENTICATE_MESSAGE {
  210. UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  211. ULONG MessageType;
  212. STRING LmChallengeResponse;
  213. STRING NtChallengeResponse;
  214. STRING DomainName;
  215. STRING UserName;
  216. STRING Workstation;
  217. } AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
  218. //
  219. // Size of the largest message
  220. // (The largest message is the AUTHENTICATE_MESSAGE)
  221. //
  222. #define NTLMSSP_MAX_MESSAGE_SIZE (sizeof(AUTHENTICATE_MESSAGE) + \
  223. 8 + \
  224. (15 + 1) + \
  225. (20 + 1) + \
  226. (15 + 1) )
  227. //
  228. // Signature structure
  229. //
  230. typedef struct _NTLMSSP_MESSAGE_SIGNATURE {
  231. ULONG Version;
  232. ULONG RandomPad;
  233. ULONG CheckSum;
  234. ULONG Nonce;
  235. } NTLMSSP_MESSAGE_SIGNATURE, * PNTLMSSP_MESSAGE_SIGNATURE;
  236. #define NTLMSSP_MESSAGE_SIGNATURE_SIZE sizeof(NTLMSSP_MESSAGE_SIGNATURE)
  237. #define NTLMSSP_SIGN_VERSION 1
  238. #define NTLMSSP_KEY_SALT 0xbd
  239. ////////////////////////////////////////////////////////////////////////
  240. //
  241. // Procedure Forwards
  242. //
  243. ////////////////////////////////////////////////////////////////////////
  244. PVOID
  245. SspAlloc(
  246. int Size
  247. );
  248. void
  249. SspFree(
  250. PVOID Buffer
  251. );
  252. PSTRING
  253. SspAllocateString(
  254. PVOID Value
  255. );
  256. PSTRING
  257. SspAllocateStringBlock(
  258. PVOID Value,
  259. int Length
  260. );
  261. void
  262. SspFreeString(
  263. PSTRING * String
  264. );
  265. void
  266. SspCopyString(
  267. IN PVOID MessageBuffer,
  268. OUT PSTRING OutString,
  269. IN PSTRING InString,
  270. IN OUT PCHAR *Where,
  271. IN BOOLEAN Absolute
  272. );
  273. void
  274. SspCopyStringFromRaw(
  275. IN PVOID MessageBuffer,
  276. OUT PSTRING OutString,
  277. IN PCHAR InString,
  278. IN int InStringLength,
  279. IN OUT PCHAR *Where
  280. );
  281. DWORD
  282. SspTicks(
  283. );
  284. #endif // ifndef _NTLMSSPI_INCLUDED_