home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / ntlmsp.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  10KB  |  306 lines

  1. //+-------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992-1997.
  5. //
  6. //  File:       ntlmsp.h
  7. //
  8. //  Contents:
  9. //
  10. //  Classes:
  11. //
  12. //  Functions:
  13. //
  14. //  History:    13-May-92 PeterWi       Created
  15. //
  16. //--------------------------------------------------------------------------
  17.  
  18. #ifndef _NTLMSP_H_
  19. #define _NTLMSP_H_
  20.  
  21. #include <ntmsv1_0.h>
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. ////////////////////////////////////////////////////////////////////////
  28. //
  29. // Name of the package to pass in to AcquireCredentialsHandle, etc.
  30. //
  31. ////////////////////////////////////////////////////////////////////////
  32.  
  33. #define NTLMSP_NAME_A            "NTLM"
  34. #define NTLMSP_NAME              L"NTLM"
  35. #define NTLMSP_NAME_SIZE        (sizeof(NTLMSP_NAME) - sizeof(WCHAR))
  36. #define NTLMSP_COMMENT_A         "NTLM Security Package"
  37. #define NTLMSP_COMMENT           L"NTLM Security Package"
  38. #define NTLMSP_CAPABILITIES     (SECPKG_FLAG_TOKEN_ONLY | \
  39.                                  SECPKG_FLAG_MULTI_REQUIRED | \
  40.                                  SECPKG_FLAG_CONNECTION | \
  41.                                  SECPKG_FLAG_INTEGRITY | \
  42.                                  SECPKG_FLAG_PRIVACY)
  43.  
  44. #define NTLMSP_VERSION          1
  45. #define NTLMSP_RPCID            10  // RPC_C_AUTHN_WINNT from rpcdce.h
  46. #define NTLMSP_MAX_TOKEN_SIZE 0x300
  47.  
  48. ////////////////////////////////////////////////////////////////////////
  49. //
  50. // Opaque Messages passed between client and server
  51. //
  52. ////////////////////////////////////////////////////////////////////////
  53.  
  54. #define NTLMSSP_SIGNATURE "NTLMSSP"
  55.  
  56. //
  57. // MessageType for the following messages.
  58. //
  59.  
  60. typedef enum {
  61.     NtLmNegotiate = 1,
  62.     NtLmChallenge,
  63.     NtLmAuthenticate,
  64.     NtLmUnknown
  65. } NTLM_MESSAGE_TYPE;
  66.  
  67. //
  68. // Valid values of NegotiateFlags
  69. //
  70.  
  71. #define NTLMSSP_NEGOTIATE_UNICODE       0x0001  // Text strings are in unicode
  72. #define NTLMSSP_NEGOTIATE_OEM           0x0002  // Text strings are in OEM
  73. #define NTLMSSP_REQUEST_TARGET          0x0004  // Server should return its
  74.                                                 // authentication realm
  75. #define NTLMSSP_NEGOTIATE_SIGN          0x0010  // Request signature capability
  76. #define NTLMSSP_NEGOTIATE_SEAL          0x0020  // Request confidentiality
  77. #define NTLMSSP_NEGOTIATE_DATAGRAM      0x0040  // Use datagram style authentication
  78. #define NTLMSSP_NEGOTIATE_LM_KEY        0x0080  // Use LM session key for sign/seal
  79.  
  80. #define NTLMSSP_NEGOTIATE_NETWARE       0x0100  // NetWare authentication
  81. #define NTLMSSP_NEGOTIATE_NTLM          0x0200  // NTLM authentication
  82.  
  83. #define NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED       0x1000  // Domain Name supplied on negotiate
  84. #define NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED  0x2000  // Workstation Name supplied on negotiate
  85. #define NTLMSSP_NEGOTIATE_LOCAL_CALL                0x4000 // Indicates client/server are same machine
  86. #define NTLMSSP_NEGOTIATE_ALWAYS_SIGN               0x8000 // Sign for all security levels
  87.  
  88.  
  89. //
  90. // Valid target types returned by the server in Negotiate Flags
  91. //
  92.  
  93. #define NTLMSSP_TARGET_TYPE_DOMAIN 0x10000  // TargetName is a domain name
  94. #define NTLMSSP_TARGET_TYPE_SERVER 0x20000  // TargetName is a server name
  95. #define NTLMSSP_TARGET_TYPE_SHARE  0x40000  // TargetName is a share name
  96.  
  97.  
  98. //
  99. // Valid requests for additional output buffers
  100. //
  101.  
  102. #define NTLMSSP_REQUEST_INIT_RESPONSE       0x100000    // get back session keys
  103. #define NTLMSSP_REQUEST_ACCEPT_RESPONSE     0x200000    // get back session key, LUID
  104. #define NTLMSSP_REQUEST_NON_NT_SESSION_KEY  0x400000    // request non-nt session key
  105.  
  106. //
  107. // Opaque message returned from first call to InitializeSecurityContext
  108. //
  109. typedef struct _NEGOTIATE_MESSAGE {
  110.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  111.     NTLM_MESSAGE_TYPE MessageType;
  112.     ULONG NegotiateFlags;
  113.     STRING OemDomainName;
  114.     STRING OemWorkstationName;
  115. } NEGOTIATE_MESSAGE, *PNEGOTIATE_MESSAGE;
  116.  
  117.  
  118. //
  119. // Old version of the message, for old clients
  120. //
  121.  
  122. typedef struct _OLD_NEGOTIATE_MESSAGE {
  123.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  124.     NTLM_MESSAGE_TYPE MessageType;
  125.     ULONG NegotiateFlags;
  126. } OLD_NEGOTIATE_MESSAGE, *POLD_NEGOTIATE_MESSAGE;
  127.  
  128. //
  129. // Opaque message returned from first call to AcceptSecurityContext
  130. //
  131. typedef struct _CHALLENGE_MESSAGE {
  132.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  133.     NTLM_MESSAGE_TYPE MessageType;
  134.     STRING TargetName;
  135.     ULONG NegotiateFlags;
  136.     UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH];
  137.     ULONG ServerContextHandleLower;
  138.     ULONG ServerContextHandleUpper;
  139. } CHALLENGE_MESSAGE, *PCHALLENGE_MESSAGE;
  140.  
  141. //
  142. // Old version of the challenge message
  143. //
  144.  
  145. typedef struct _OLD_CHALLENGE_MESSAGE {
  146.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  147.     NTLM_MESSAGE_TYPE MessageType;
  148.     STRING TargetName;
  149.     ULONG NegotiateFlags;
  150.     UCHAR Challenge[MSV1_0_CHALLENGE_LENGTH];
  151. } OLD_CHALLENGE_MESSAGE, *POLD_CHALLENGE_MESSAGE;
  152.  
  153. //
  154. // Opaque message returned from second call to InitializeSecurityContext
  155. //
  156. typedef struct _AUTHENTICATE_MESSAGE {
  157.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  158.     NTLM_MESSAGE_TYPE MessageType;
  159.     STRING LmChallengeResponse;
  160.     STRING NtChallengeResponse;
  161.     STRING DomainName;
  162.     STRING UserName;
  163.     STRING Workstation;
  164.     STRING SessionKey;
  165.     ULONG NegotiateFlags;
  166. } AUTHENTICATE_MESSAGE, *PAUTHENTICATE_MESSAGE;
  167.  
  168. typedef struct _OLD_AUTHENTICATE_MESSAGE {
  169.     UCHAR Signature[sizeof(NTLMSSP_SIGNATURE)];
  170.     NTLM_MESSAGE_TYPE MessageType;
  171.     STRING LmChallengeResponse;
  172.     STRING NtChallengeResponse;
  173.     STRING DomainName;
  174.     STRING UserName;
  175.     STRING Workstation;
  176. } OLD_AUTHENTICATE_MESSAGE, *POLD_AUTHENTICATE_MESSAGE;
  177.  
  178.  
  179. //
  180. // Additional input message to Initialize for clients to provide a
  181. // user-supplied password
  182. //
  183.  
  184. typedef struct _NTLM_CHALLENGE_MESSAGE {
  185.     UNICODE_STRING Password;
  186.     UNICODE_STRING UserName;
  187.     UNICODE_STRING DomainName;
  188. } NTLM_CHALLENGE_MESSAGE, *PNTLM_CHALLENGE_MESSAGE;
  189.  
  190.  
  191. //
  192. // Non-opaque message returned from second call to InitializeSecurityContext
  193. //
  194.  
  195. typedef struct _NTLM_INITIALIZE_RESPONSE {
  196.     UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  197.     UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  198. } NTLM_INITIALIZE_RESPONSE, *PNTLM_INITIALIZE_RESPONSE;
  199.  
  200. //
  201. // Additional input message to Accept for trusted client skipping the first
  202. // call to Accept and providing their own challenge
  203. //
  204.  
  205. typedef struct _NTLM_AUTHENTICATE_MESSAGE {
  206.     CHAR ChallengeToClient[MSV1_0_CHALLENGE_LENGTH];
  207.     ULONG ParameterControl;
  208. } NTLM_AUTHENTICATE_MESSAGE, *PNTLM_AUTHENTICATE_MESSAGE;
  209.  
  210.  
  211. //
  212. // Non-opaque message returned from second call to AcceptSecurityContext
  213. //
  214.  
  215. typedef struct _NTLM_ACCEPT_RESPONSE {
  216.     LUID LogonId;
  217.     LARGE_INTEGER KickoffTime;
  218.     ULONG UserFlags;
  219.     UCHAR UserSessionKey[MSV1_0_USER_SESSION_KEY_LENGTH];
  220.     UCHAR LanmanSessionKey[MSV1_0_LANMAN_SESSION_KEY_LENGTH];
  221. } NTLM_ACCEPT_RESPONSE, *PNTLM_ACCEPT_RESPONSE;
  222.  
  223.  
  224. //
  225. // Size of the largest message
  226. //  (The largest message is the AUTHENTICATE_MESSAGE)
  227. //
  228.  
  229. #define NTLMSSP_MAX_MESSAGE_SIZE (sizeof(AUTHENTICATE_MESSAGE) + \
  230.                                   LM_RESPONSE_LENGTH +           \
  231.                                   NT_RESPONSE_LENGTH +           \
  232.                                   (DNLEN + 1) * sizeof(WCHAR) +  \
  233.                                   (UNLEN + 1) * sizeof(WCHAR) +  \
  234.                                   (CNLEN + 1) * sizeof(WCHAR))
  235.  
  236.  
  237. typedef struct _NTLMSSP_MESSAGE_SIGNATURE {
  238.     ULONG   Version;
  239.     ULONG   RandomPad;
  240.     ULONG   CheckSum;
  241.     ULONG   Nonce;
  242. } NTLMSSP_MESSAGE_SIGNATURE, *PNTLMSSP_MESSAGE_SIGNATURE;
  243.  
  244. #define NTLMSSP_MESSAGE_SIGNATURE_SIZE sizeof(NTLMSSP_MESSAGE_SIGNATURE)
  245. //
  246. // Version 1 is the structure above, using stream RC4 to encrypt the trailing
  247. // 12 bytes.
  248. //
  249. #define NTLM_SIGN_VERSION   1
  250.  
  251. //////////////////////////////////////////////////////////////////////
  252. //
  253. // Control Functions
  254. //
  255. //////////////////////////////////////////////////////////////////////
  256.  
  257. #define NTLM_CHANGE_PASSWORD            0x0001
  258. #define NTLM_DUMP_CONTEXTS              0x1001
  259. #define NTLM_DUMP_CREDENTIALS           0x1002
  260. #define NTLM_DUMP_SESSIONS              0x1003
  261.  
  262.  
  263. //////////////////////////////////////////////////////////////////////
  264. //
  265. // Credential data structures
  266. //
  267. //////////////////////////////////////////////////////////////////////
  268.  
  269. typedef enum {
  270.     Share = 1,
  271.     Server,
  272.     Domain,
  273.     Default
  274. } NTLMCredentialType, *PNTLMCredentialType;
  275.  
  276. #define NTLM_CRED_REVISION 1
  277.  
  278. typedef struct _NTLMCredHeader {
  279.     ULONG       Revision;
  280.     ULONG       CredentialCount;
  281.     ULONG       Reserved[2];
  282. } NTLMCredHeader, *PNTLMCredHeader;
  283.  
  284.  
  285. typedef struct _NTLMPublicCredential {
  286.     NTLMCredentialType          CredType;
  287.     SECURITY_STRING             ssTarget;
  288.     SECURITY_STRING             ssPassword;
  289.     SECURITY_STRING OPTIONAL    ssUser;
  290.     SECURITY_STRING OPTIONAL    ssDomain;
  291.     struct _NTLMPublicCredential * pNext;
  292. } NTLMPublicCredential, *PNTLMPublicCredential;
  293.  
  294. typedef struct _NTLMPublicPrimaryCred {
  295.     SECURITY_STRING             ssUser;
  296.     SECURITY_STRING             ssDomain;
  297.     SECURITY_STRING             ssPassword;
  298. } NTLMPublicPrimaryCred, *PNTLMPublicPrimaryCred;
  299.  
  300.  
  301. #ifdef __cplusplus
  302. }
  303. #endif
  304.  
  305. #endif // _NTLMSP_H_
  306.