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.

361 lines
9.9 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // File: kdcsvr.hxx
  4. //
  5. // Contents: KDC Private definitions
  6. //
  7. //
  8. // History: <whenever> RichardW Created
  9. // 16-Jan-93 WadeR Converted to C++
  10. //
  11. //------------------------------------------------------------------------
  12. #ifndef _INC_KDCSVR_HXX_
  13. #define _INC_KDCSVR_HXX_
  14. #include "krbprgma.h"
  15. #include <secpch2.hxx>
  16. extern "C"
  17. {
  18. #include <lsarpc.h>
  19. #include <samrpc.h>
  20. #include <lmsname.h>
  21. #include <samisrv.h> // SamIFree_XXX
  22. #include <logonmsv.h>
  23. #include <lsaisrv.h> // LsaIFree_XXX
  24. #include <config.h>
  25. #include <lmerr.h>
  26. #include <netlibnt.h>
  27. #include <lsaitf.h>
  28. #include <msaudite.h>
  29. #include <wintrust.h> // for WinVerifyTrust and wincrypt.h
  30. }
  31. #include <kerbcomm.h>
  32. #include <kerberr.h>
  33. #include <kdcevent.h>
  34. #include <exterr.h> // whack this soon
  35. #include <authen.hxx>
  36. #include <fileno.h>
  37. #include <malloc.h>
  38. #include <alloca.h>
  39. #include <authz.h>
  40. //
  41. // Global typedefs
  42. //
  43. typedef struct _KDC_TICKET_INFO
  44. {
  45. UNICODE_STRING AccountName;
  46. UNICODE_STRING TrustedForest;
  47. LARGE_INTEGER PasswordExpires;
  48. ULONG fTicketOpts;
  49. ULONG UserAccountControl;
  50. ULONG UserId;
  51. ULONG TrustType;
  52. ULONG TrustAttributes;
  53. PKERB_STORED_CREDENTIAL Passwords;
  54. PKERB_STORED_CREDENTIAL OldPasswords;
  55. PSID TrustSid;
  56. ULONG PasswordVersion;
  57. ULONG LockoutThreshold; // contains info if account lockout is set for this account
  58. } KDC_TICKET_INFO, *PKDC_TICKET_INFO;
  59. typedef struct _KDC_U2U_TICKET_INFO
  60. {
  61. PKERB_ENCRYPTED_TICKET Tgt; // tgt from additional ticket.
  62. PKERB_INTERNAL_NAME TgtCName;
  63. UNICODE_STRING TgtCRealm;
  64. KDC_TICKET_INFO TgtTicketInfo;
  65. PKERB_INTERNAL_NAME cName;
  66. UNICODE_STRING cRealm;
  67. ULONG Flags;
  68. } KDC_U2U_TICKET_INFO, *PKDC_U2U_TICKET_INFO;
  69. typedef struct _KDC_S4U_TICKET_INFO
  70. {
  71. PKERB_INTERNAL_NAME RequestorServiceName; // name of service making Proxy or to self request.
  72. UNICODE_STRING RequestorServiceRealm; // realm of service making proxy or toself request.
  73. KDC_TICKET_INFO RequestorTicketInfo; // Requesting service's ticket info.
  74. UNICODE_STRING TargetName; // TGS target name
  75. PKERB_INTERNAL_NAME PACCName; // Name of client in S4uSelf PA / Proxy evidence ticket
  76. UNICODE_STRING PACCRealm; // Realm of client in S4USelf PA / Proxy evidence ticket
  77. PKERB_ENCRYPTED_TICKET EvidenceTicket; // PROXY ONLY - ticket containing the PAC
  78. // S4U - TGT being used.
  79. KERB_ENCRYPTION_KEY EvidenceTicketKey; // PROXY ONLY - key used to encrypt tick. & PAC
  80. // S4U - Key used to sign tgt.
  81. ULONG Flags; // flags
  82. } KDC_S4U_TICKET_INFO, *PKDC_S4U_TICKET_INFO;
  83. //
  84. // Flags for U2U && S4U ticket info.
  85. //
  86. #define TI_INITIALIZED 0x10
  87. #define TI_FREETICKET 0x20
  88. //
  89. // S4U Flags.
  90. //
  91. #define TI_CHECK_RID 0x0001
  92. #define TI_REQUESTOR_THIS_REALM 0x0002
  93. #define TI_TARGET_OUR_REALM 0x0004
  94. #define TI_SENSITIVE_CLIENT_ACCOUNT 0x0008
  95. #define TI_PRXY_REQUESTOR_THIS_REALM 0x0100
  96. #define TI_S4USELF_INFO 0x1000
  97. #define TI_S4UPROXY_INFO 0x2000
  98. #include <events.hxx>
  99. //
  100. // Strucutures used in authz TGS && S4U access checks
  101. //
  102. typedef struct _KDC_AUTHZ_INFO
  103. {
  104. PNETLOGON_SID_AND_ATTRIBUTES SidAndAttributes;
  105. ULONG SidCount;
  106. } KDC_AUTHZ_INFO, *PKDC_AUTHZ_INFO;
  107. typedef struct _KDC_AUTHZ_GROUP_BUFFERS
  108. {
  109. PSAMPR_PSID_ARRAY ResourceGroups;
  110. SAMPR_PSID_ARRAY PacGroups;
  111. SAMPR_ULONG_ARRAY AliasGroups;
  112. PSID BuiltInSids;
  113. PNETLOGON_SID_AND_ATTRIBUTES SidAndAttributes;
  114. PNETLOGON_VALIDATION_SAM_INFO3 ValidationInfo;
  115. } KDC_AUTHZ_GROUP_BUFFERS, *PKDC_AUTHZ_GROUP_BUFFERS;
  116. //
  117. // Flag bit defines for use with the LogonRestrictionsFlag parameter
  118. // passed to the KerbCheckLogonRestrictions function
  119. //
  120. #define KDC_RESTRICT_PKINIT_USED 1
  121. #define KDC_RESTRICT_IGNORE_PW_EXPIRATION 2
  122. #define KDC_RESTRICT_SAM_CHECKS 4
  123. #define KDC_RESTRICT_S4U_CHECKS KDC_RESTRICT_PKINIT_USED | KDC_RESTRICT_IGNORE_PW_EXPIRATION | KDC_RESTRICT_SAM_CHECKS
  124. typedef enum {
  125. Unknown,
  126. Inbound,
  127. Outbound
  128. } KDC_DOMAIN_INFO_DIRECTION, *PKDC_DOMAIN_INFO_DIRECTION;
  129. //
  130. // Extra logging bits.
  131. //
  132. #define LOG_SPN_UNKNOWN 0x1
  133. #define LOG_PKI_ERRORS 0x2
  134. #define LOG_POLICY_ERROR 0x4
  135. #define LOG_S4USELF_ACCESS_ERROR 0x8
  136. #define LOG_DEFAULT LOG_PKI_ERRORS
  137. //
  138. // Auditing construct for PKI
  139. //
  140. typedef struct _KDC_PKI_AUDIT_INFO
  141. {
  142. UNICODE_STRING CertIssuerName;
  143. UNICODE_STRING CertSerialNumber;
  144. UNICODE_STRING CertThumbprint;
  145. } KDC_PKI_AUDIT_INFO, *PKDC_PKI_AUDIT_INFO;
  146. #include "debug.hxx"
  147. #include "secdata.hxx"
  148. #include "tktutil.hxx"
  149. #include "pkserv.h"
  150. //
  151. // Careful with these - the audit is the same, but not all fields are required.
  152. //
  153. // a- auditid b- ClientName c- ClientDomain d- ClientSid e- ServiceName
  154. // f- ServiceSid g- KdcOptions h- KerbStatus i- etype j- pa type
  155. // k- client address l- logon guid m- transitted services.
  156. // n- cert issuer name o - Certserial number p- Cert thumbprint.
  157. //
  158. //
  159. // TGS - No CertIssuerName, CertSerialNumber, CertThumbprint
  160. //
  161. #define KdcLsaIAuditTgsEvent( _a_, _b_, _c_, _d_, _e_, _f_, _g_, _h_, _i_, _j_, _k_, _l_, _m_) \
  162. LsaIAuditKdcEvent(_a_, _b_, _c_, _d_, _e_, _f_, _g_, _h_, _i_, _j_, _k_, _l_, _m_, 0, 0, 0)
  163. //
  164. // AS - No Transitted services, no logon guid
  165. //
  166. #define KdcLsaIAuditAsEvent(_a_, _b_, _c_, _d_, _e_, _f_, _g_, _h_, _i_, _j_, _k_, _n_, _o_, _p_) \
  167. LsaIAuditKdcEvent(_a_, _b_, _c_, _d_, _e_, _f_, _g_, _h_, _i_, _j_, _k_, 0, 0, _n_, _o_, _p_ )
  168. //
  169. // Global prototypes:
  170. //
  171. void
  172. ServiceMain(
  173. ULONG ArgC,
  174. LPSTR * ArgV
  175. );
  176. NTSTATUS
  177. ShutDown(
  178. LPTSTR String
  179. );
  180. BOOLEAN
  181. UpdateStatus(
  182. ULONG Status
  183. );
  184. extern "C"
  185. BOOLEAN
  186. InitializeChangeNotify(
  187. VOID
  188. );
  189. NTSTATUS
  190. AsNegCacheInit(
  191. VOID
  192. );
  193. KERBERR
  194. KerbCheckLogonRestrictions(
  195. IN PVOID UserHandle,
  196. IN PUNICODE_STRING Workstation,
  197. IN PUSER_ALL_INFORMATION UserAll,
  198. IN ULONG LogonRestrictionsFlags,
  199. OUT PTimeStamp LogoffTime,
  200. OUT PNTSTATUS RetStatus
  201. );
  202. //
  203. // Global data defn's
  204. //
  205. typedef enum {
  206. Stopped,
  207. Starting,
  208. Running
  209. } KDC_STATE;
  210. extern TimeStamp tsInfinity;
  211. extern KDC_STATE KdcState;
  212. extern LARGE_INTEGER SkewTime;
  213. extern BOOLEAN fStopKDC;
  214. extern HANDLE hKdcHandles[];
  215. extern CRITICAL_SECTION ApiCriticalSection;
  216. extern ULONG CurrentApiCallers;
  217. extern UNICODE_STRING GlobalDomainName;
  218. extern UNICODE_STRING GlobalKerberosName;
  219. extern UNICODE_STRING GlobalKdcName;
  220. extern BOOL KdcGlobalAvoidPdcOnWan;
  221. extern BOOL KdcGlobalGlobalSafeBoot;
  222. extern UNICODE_STRING KdcForestRootDomainName;
  223. extern LIST_ENTRY KdcReferralCache;
  224. extern PKERB_INTERNAL_NAME GlobalKpasswdName;
  225. extern PSID GlobalDomainSid;
  226. extern PSID GlobalBuiltInSid;
  227. extern PSID GlobalEveryoneSid;
  228. extern PSID GlobalAuthenticatedUserSid;
  229. extern PSID GlobalThisOrganizationSid;
  230. extern PSID GlobalOtherOrganizationSid;
  231. extern SAMPR_HANDLE GlobalAccountDomainHandle;
  232. extern SAMPR_HANDLE GlobalBuiltInDomainHandle;
  233. extern LSAPR_HANDLE GlobalPolicyHandle;
  234. extern BYTE GlobalLocalhostAddress[4];
  235. extern DWORD KdcUseClientAddresses;
  236. extern DWORD KdcIssueForwardedTickets;
  237. extern DWORD KdcDontCheckAddresses;
  238. extern DWORD KdcNewConnectionTimeout;
  239. extern DWORD KdcExistingConnectionTimeout;
  240. extern DWORD KdcGlobalMaxDatagramReplySize;
  241. extern DWORD KdcExtraLogLevel;
  242. extern DWORD KSuppInfoLevel;
  243. extern DWORD KDCInfoLevel;
  244. extern PKERB_CRYPT_LIST kdc_pPreferredCryptList;
  245. extern PKERB_CRYPT_LIST kdc_pMitPrincipalPreferredCryptList;
  246. extern AUTHZ_RESOURCE_MANAGER_HANDLE KdcAuthzRM;
  247. #define GET_CLIENT_ADDRESS(_x_) \
  248. (((_x_) != NULL ) ? \
  249. ((PBYTE) (&((struct sockaddr_in *)(_x_))->sin_addr.S_un.S_addr)) : \
  250. GlobalLocalhostAddress)
  251. //
  252. // KDC handle definitions
  253. //
  254. #define hKdcShutdownEvent hKdcHandles[0]
  255. #define MAX_KDC_HANDLE 1
  256. extern AUTHZ_RESOURCE_MANAGER_HANDLE KdcAuthzRM;
  257. // class CAuthenticatorList;
  258. extern CAuthenticatorList * Authenticators;
  259. extern CAuthenticatorList * ReplayDetect;
  260. class CSecurityData;
  261. extern CSecurityData SecData;
  262. //
  263. // Global constants
  264. //
  265. const ULONG ulInfinity = 0xFFFFFFFF;
  266. const ULONG ulTsPerSecond = 10000000L;
  267. // Number of creds supplied in DS for LM_OWF but no NT_OWF support
  268. #define CRED_ONLY_LM_OWF 1
  269. //
  270. // Global macros
  271. //
  272. #define KdcGetTime(_x_) ((_x_).QuadPart)
  273. #define MAX_SID_LEN (sizeof(SID) + sizeof(ULONG) * SID_MAX_SUB_AUTHORITIES)
  274. #define KdcMakeAccountSid( _buffer_, _rid_) \
  275. { \
  276. PSID TempSid = (PSID) _buffer_; \
  277. RtlCopyMemory( _buffer_, GlobalDomainSid, RtlLengthSid(GlobalDomainSid)); \
  278. *RtlSubAuthoritySid(TempSid, *RtlSubAuthorityCountSid(TempSid)) = _rid_; \
  279. *RtlSubAuthorityCountSid(TempSid) += 1; \
  280. }
  281. #define KdcFreeEncodedData(_x_) MIDL_user_free(_x_)
  282. //
  283. // This #define allows KDC instrumentation for rogue PACs
  284. // WE MUST NOT UNDER ANY CIRCUMSTANCES SHIP WITH THIS ACTIVE
  285. //
  286. // #define ROGUE_DC
  287. #ifdef ROGUE_DC
  288. extern HKEY hKdcRogueKey;
  289. #endif
  290. #endif // _INC_KDCSVR_HXX_