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.

553 lines
11 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. secclnt.hxx
  5. Abstract:
  6. This file contains an abstraction to the security support for clients
  7. and that which is common to both servers and clients.
  8. Author:
  9. Michael Montague (mikemon) 10-Apr-1992
  10. Revision History:
  11. --*/
  12. #ifndef __SECCLNT_HXX__
  13. #define __SECCLNT_HXX__
  14. typedef SecBufferDesc SECURITY_BUFFER_DESCRIPTOR;
  15. typedef SecBuffer SECURITY_BUFFER;
  16. #define MAXIMUM_SECURITY_BLOCK_SIZE 16
  17. enum PACKAGE_LEG_COUNT
  18. {
  19. LegsUnknown,
  20. ThreeLegs,
  21. EvenNumberOfLegs
  22. };
  23. typedef struct
  24. {
  25. #ifdef UNICODE
  26. SecPkgInfoW PackageInfo;
  27. #else
  28. SecPkgInfoA PackageInfo;
  29. #endif
  30. SECURITY_CREDENTIALS *ServerSecurityCredentials;
  31. PACKAGE_LEG_COUNT LegCount;
  32. } SECURITY_PACKAGE_INFO;
  33. typedef struct
  34. {
  35. unsigned long Count;
  36. SECURITY_PACKAGE_INFO * SecurityPackages;
  37. PSecurityFunctionTable RpcSecurityInterface;
  38. void * ProviderDll;
  39. RPC_CHAR *ProviderDllName;
  40. } SECURITY_PROVIDER_INFO;
  41. extern SECURITY_PROVIDER_INFO PAPI * ProviderList;
  42. extern unsigned long NumberOfProviders;
  43. extern unsigned long LoadedProviders;
  44. extern unsigned long AvailableProviders;
  45. extern int SecuritySupportLoaded;
  46. extern int FailedToLoad;
  47. extern PSecurityFunctionTable RpcSecurityInterface;
  48. extern SecPkgInfo PAPI * SecurityPackages;
  49. extern unsigned long NumberOfSecurityPackages;
  50. extern MUTEX * SecurityCritSect;
  51. extern RPC_STATUS
  52. InsureSecuritySupportLoaded (
  53. );
  54. extern RPC_STATUS
  55. IsAuthenticationServiceSupported (
  56. IN unsigned long AuthenticationService
  57. );
  58. extern RPC_STATUS
  59. FindServerCredentials (
  60. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  61. IN void __RPC_FAR * Arg,
  62. IN unsigned long AuthenticationService,
  63. IN unsigned long AuthenticationLevel,
  64. IN RPC_CHAR __RPC_FAR * Principal,
  65. IN OUT SECURITY_CREDENTIALS ** SecurityCredentials
  66. );
  67. extern RPC_STATUS
  68. RemoveCredentialsFromCache (
  69. IN unsigned long AuthenticationService
  70. );
  71. extern PACKAGE_LEG_COUNT
  72. GetPackageLegCount(
  73. DWORD id
  74. );
  75. extern BOOL
  76. ReadPackageLegInfo();
  77. extern DWORD * FourLeggedPackages;
  78. class SECURITY_CREDENTIALS
  79. /*++
  80. Class Description:
  81. This class is an abstraction of the credential handle provided by
  82. the Security APIs.
  83. Fields:
  84. PackageIndex - Contains the index for this package in the array of
  85. packages pointed to by SecurityPackages.
  86. Credentials - Contains the credential handle used by the security
  87. package.
  88. --*/
  89. {
  90. friend RPC_STATUS
  91. FindServerCredentials (
  92. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  93. IN void __RPC_FAR * Arg,
  94. IN unsigned long AuthenticationService,
  95. IN unsigned long AuthenticationLevel,
  96. IN RPC_CHAR __RPC_FAR * Principal,
  97. IN OUT SECURITY_CREDENTIALS ** SecurityCredentials
  98. );
  99. public:
  100. unsigned AuthenticationService;
  101. private:
  102. BOOL Valid;
  103. unsigned int ProviderIndex;
  104. unsigned int PackageIndex;
  105. CredHandle CredentialsHandle;
  106. unsigned int ReferenceCount;
  107. MUTEX CredentialsMutex;
  108. SEC_CHAR __SEC_FAR * DefaultPrincName;
  109. public:
  110. SECURITY_CREDENTIALS (
  111. IN OUT RPC_STATUS PAPI * Status
  112. );
  113. ~SECURITY_CREDENTIALS ();
  114. RPC_STATUS
  115. AcquireCredentialsForServer (
  116. IN RPC_AUTH_KEY_RETRIEVAL_FN GetKeyFn,
  117. IN void __RPC_FAR * Arg,
  118. IN unsigned long AuthenticationService,
  119. IN unsigned long AuthenticationLevel,
  120. IN RPC_CHAR __RPC_FAR * Principal
  121. );
  122. RPC_STATUS
  123. AcquireCredentialsForClient (
  124. IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity,
  125. IN unsigned long AuthenticationService,
  126. IN unsigned long AuthenticationLevel
  127. );
  128. RPC_STATUS
  129. InquireDefaultPrincName (
  130. OUT SEC_CHAR __SEC_FAR **MyDefaultPrincName
  131. );
  132. void
  133. FreeCredentials (
  134. );
  135. unsigned int
  136. MaximumTokenLength (
  137. );
  138. PCredHandle
  139. InquireCredHandle (
  140. );
  141. void
  142. ReferenceCredentials(
  143. void
  144. );
  145. void
  146. DereferenceCredentials(
  147. void
  148. );
  149. PSecurityFunctionTable
  150. InquireProviderFunctionTable (
  151. );
  152. int
  153. CompareCredentials(
  154. SECURITY_CREDENTIALS PAPI * Creds
  155. );
  156. };
  157. inline
  158. int
  159. SECURITY_CREDENTIALS::CompareCredentials(
  160. SECURITY_CREDENTIALS PAPI * Creds
  161. )
  162. {
  163. CredHandle * Cookie = Creds->InquireCredHandle();
  164. if ( (CredentialsHandle.dwLower == Cookie->dwLower)
  165. &&(CredentialsHandle.dwUpper == Cookie->dwUpper) )
  166. {
  167. return 0;
  168. }
  169. return 1;
  170. }
  171. inline unsigned int
  172. SECURITY_CREDENTIALS::MaximumTokenLength (
  173. )
  174. /*++
  175. Return Value:
  176. The maximum size, in bytes, of the tokens passed around at security
  177. context initialization time.
  178. --*/
  179. {
  180. return(ProviderList[ProviderIndex].SecurityPackages[PackageIndex].PackageInfo.cbMaxToken);
  181. }
  182. inline PSecurityFunctionTable
  183. SECURITY_CREDENTIALS::InquireProviderFunctionTable(
  184. )
  185. /*++
  186. Return Value:
  187. --*/
  188. {
  189. return(ProviderList[ProviderIndex].RpcSecurityInterface);
  190. }
  191. inline PCredHandle
  192. SECURITY_CREDENTIALS::InquireCredHandle (
  193. )
  194. /*++
  195. Return Value:
  196. The credential handle for this object will be returned.
  197. --*/
  198. {
  199. return(&CredentialsHandle);
  200. }
  201. class SECURITY_CONTEXT : public CLIENT_AUTH_INFO
  202. /*++
  203. Class Description:
  204. This is an abstraction of a security context. It allows you to use
  205. it to generate signatures and then verify them, as well as, sealing
  206. and unsealing messages.
  207. Fields:
  208. DontForgetToDelete - Contains a flag indicating whether or not there
  209. is a valid security context which needs to be deleted. A value
  210. of non-zero indicates there is a valid security context.
  211. SecurityContext - Contains a handle to the security context maintained
  212. by the security package on our behalf.
  213. MaxHeaderLength - Contains the maximum size of a header for this
  214. security context.
  215. MaxSignatureLength - Contains the maximum size of a signature for
  216. this security context.
  217. --*/
  218. {
  219. public:
  220. unsigned AuthContextId;
  221. unsigned Flags;
  222. unsigned long ContextAttributes;
  223. PACKAGE_LEG_COUNT Legs;
  224. SECURITY_CONTEXT (
  225. CLIENT_AUTH_INFO *myAuthInfo,
  226. unsigned myAuthContextId,
  227. BOOL fUseDatagram,
  228. RPC_STATUS __RPC_FAR * pStatus
  229. );
  230. inline ~SECURITY_CONTEXT (
  231. void
  232. )
  233. {
  234. DeleteSecurityContext();
  235. }
  236. RPC_STATUS
  237. SetMaximumLengths (
  238. );
  239. unsigned int
  240. MaximumHeaderLength (
  241. );
  242. unsigned int
  243. MaximumSignatureLength (
  244. );
  245. unsigned int
  246. BlockSize (
  247. );
  248. RPC_STATUS
  249. CompleteSecurityToken (
  250. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  251. );
  252. RPC_STATUS
  253. SignOrSeal (
  254. IN unsigned long Sequence,
  255. IN unsigned int SignNotSealFlag,
  256. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  257. );
  258. RPC_STATUS
  259. VerifyOrUnseal (
  260. IN unsigned long Sequence,
  261. IN unsigned int VerifyNotUnsealFlag,
  262. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor
  263. );
  264. BOOL
  265. FullyConstructed()
  266. {
  267. return fFullyConstructed;
  268. }
  269. // client-side calls
  270. RPC_STATUS
  271. InitializeFirstTime(
  272. IN SECURITY_CREDENTIALS * Credentials,
  273. IN RPC_CHAR * ServerPrincipal,
  274. IN unsigned long AuthenticationLevel,
  275. IN OUT SECURITY_BUFFER_DESCRIPTOR * BufferDescriptor,
  276. IN OUT unsigned char *NewAuthType = NULL
  277. );
  278. RPC_STATUS
  279. InitializeThirdLeg(
  280. IN SECURITY_CREDENTIALS * Credentials,
  281. IN unsigned long DataRep,
  282. IN SECURITY_BUFFER_DESCRIPTOR * In,
  283. IN OUT SECURITY_BUFFER_DESCRIPTOR * Out
  284. );
  285. RPC_STATUS
  286. GetWireIdForSnego(
  287. OUT unsigned char *WireId
  288. );
  289. RPC_STATUS
  290. InqMarshalledTargetInfo (
  291. OUT unsigned long *MarshalledTargetInfoLength,
  292. OUT unsigned char **MarshalledTargetInfo
  293. );
  294. // server-side calls
  295. void
  296. DeletePac (
  297. void PAPI * Pac
  298. );
  299. RPC_STATUS
  300. AcceptFirstTime (
  301. IN SECURITY_CREDENTIALS * Credentials,
  302. IN SECURITY_BUFFER_DESCRIPTOR PAPI * InputBufferDescriptor,
  303. IN OUT SECURITY_BUFFER_DESCRIPTOR PAPI * OutputBufferDescriptor,
  304. IN unsigned long AuthenticationLevel,
  305. IN unsigned long DataRepresentation,
  306. IN unsigned long NewContextNeededFlag
  307. );
  308. RPC_STATUS
  309. AcceptThirdLeg (
  310. IN unsigned long DataRepresentation,
  311. IN SECURITY_BUFFER_DESCRIPTOR PAPI * BufferDescriptor,
  312. OUT SECURITY_BUFFER_DESCRIPTOR PAPI * OutBufferDescriptor
  313. );
  314. unsigned long
  315. InquireAuthorizationService (
  316. );
  317. RPC_AUTHZ_HANDLE
  318. InquirePrivileges (
  319. );
  320. RPC_STATUS
  321. ImpersonateClient (
  322. );
  323. void
  324. RevertToSelf (
  325. );
  326. RPC_STATUS
  327. GetAccessToken (
  328. OUT HANDLE *ImpersonationToken,
  329. OUT BOOL *fNeedToCloseToken
  330. );
  331. inline AUTHZ_CLIENT_CONTEXT_HANDLE
  332. GetAuthzContext (
  333. void
  334. )
  335. {
  336. return AuthzClientContext;
  337. }
  338. inline PAUTHZ_CLIENT_CONTEXT_HANDLE
  339. GetAuthzContextAddress (
  340. void
  341. )
  342. {
  343. return &AuthzClientContext;
  344. }
  345. RPC_STATUS
  346. GetDceInfo (
  347. RPC_AUTHZ_HANDLE __RPC_FAR * PacHandle,
  348. unsigned long __RPC_FAR * AuthzSvc
  349. );
  350. void
  351. DeleteSecurityContext (
  352. void
  353. );
  354. RPC_STATUS
  355. CheckForFailedThirdLeg (
  356. void
  357. );
  358. protected:
  359. unsigned char fFullyConstructed;
  360. unsigned char DontForgetToDelete;
  361. unsigned char fDatagram;
  362. CtxtHandle SecurityContext;
  363. unsigned int MaxHeaderLength;
  364. unsigned int MaxSignatureLength;
  365. unsigned int cbBlockSize;
  366. PSecurityFunctionTable RpcSecurityInterface;
  367. int FailedContext;
  368. ExtendedErrorInfo *FailedContextEEInfo;
  369. AUTHZ_CLIENT_CONTEXT_HANDLE AuthzClientContext;
  370. DWORD VerifyCertificate();
  371. public:
  372. CtxtHandle *
  373. InqSecurityContext ()
  374. {
  375. return &SecurityContext;
  376. }
  377. };
  378. typedef SECURITY_CONTEXT * PSECURITY_CONTEXT;
  379. inline unsigned int
  380. SECURITY_CONTEXT::MaximumHeaderLength (
  381. )
  382. /*++
  383. Return Value:
  384. The maximum size of the header used by SECURITY_CONTEXT::SealMessage
  385. will be returned. This is in bytes.
  386. --*/
  387. {
  388. return(MaxHeaderLength);
  389. }
  390. inline unsigned int
  391. SECURITY_CONTEXT::BlockSize (
  392. )
  393. /*++
  394. Return Value:
  395. For best effect, buffers to be signed or sealed should be a multiple
  396. of this length.
  397. --*/
  398. {
  399. return(cbBlockSize);
  400. }
  401. inline unsigned int
  402. SECURITY_CONTEXT::MaximumSignatureLength (
  403. )
  404. /*++
  405. Return Value:
  406. The maximum size, in bytes, of the signature used by
  407. SECURITY_CONTEXT::MakeSignature will be returned.
  408. --*/
  409. {
  410. return(MaxSignatureLength);
  411. }
  412. #endif // __SECCLNT_HXX__