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.

359 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. simauth.h
  5. Abstract:
  6. This module contains class declarations/definitions for
  7. CSecurityCtx (some code stolen from internet server)
  8. Revision History:
  9. --*/
  10. #ifndef _SIMAUTH_H_
  11. #define _SIMAUTH_H_
  12. //
  13. // Authentication commands supported
  14. //
  15. typedef enum _AUTH_COMMAND {
  16. AuthCommandUser,
  17. AuthCommandPassword,
  18. AuthCommandReverse,
  19. AuthCommandTransact,
  20. AuthCommandInvalid
  21. } AUTH_COMMAND;
  22. //
  23. // struct for each package
  24. //
  25. typedef struct _AUTH_BLOCK
  26. {
  27. //
  28. // name of the package
  29. //
  30. LPSTR Name;
  31. } AUTH_BLOCK, *PAUTH_BLOCK;
  32. //
  33. // Response IDs for the Converse function. If the return
  34. // value is anything other than SecNull, the application
  35. // should map these IDs to that appropriate protocol specific
  36. // response string. If the value is SecNull, the application
  37. // should send the returned data from Converse to the client
  38. // with the appropriate header ( ie +OK ) and trailer ( ie \r\n )
  39. //
  40. typedef enum _REPLY_LIST {
  41. SecAuthOk,
  42. SecAuthOkAnon,
  43. SecProtOk,
  44. SecNeedPwd,
  45. SecBadCommand,
  46. SecSyntaxErr,
  47. SecPermissionDenied,
  48. SecNoUsername,
  49. SecInternalErr,
  50. SecAuthReq,
  51. SecProtNS,
  52. SecNull,
  53. NUM_SEC_REPLIES
  54. } REPLY_LIST;
  55. enum PKG_REPLY_FMT
  56. {
  57. PkgFmtSpace,
  58. PkgFmtCrLf
  59. };
  60. //
  61. // CSecurityContext - user security context class designed to work with any
  62. // ssp interface. The object have 2 sets of context handles - one for
  63. // authentication, and one for encrption. If we are using only one package,
  64. // then these handles point to the same thing. This is used to support
  65. // use of multi-ssp packages like Sicily over SSL.
  66. //
  67. class CSecurityCtx : public TCP_AUTHENT
  68. {
  69. private:
  70. //
  71. // Have we been authenticated, if so did we use the
  72. // anonymous token
  73. //
  74. BOOL m_IsAuthenticated;
  75. BOOL m_IsClearText;
  76. BOOL m_IsAnonymous;
  77. BOOL m_IsGuest;
  78. BOOL m_fBase64; // encoding flag
  79. static BOOL m_AllowGuest;
  80. static BOOL m_StartAnonymous;
  81. //
  82. // storage for login name while waiting for the pswd
  83. //
  84. LPSTR m_LoginName;
  85. //
  86. // storage for package name used
  87. //
  88. LPSTR m_PackageName;
  89. DWORD m_cProviderPackages;
  90. LPSTR m_ProviderNames;
  91. PAUTH_BLOCK m_ProviderPackages;
  92. //
  93. // Cleartext package name
  94. //
  95. char m_szCleartextPackageName[MAX_PATH];
  96. char m_szMembershipBrokerName[MAX_PATH];
  97. //
  98. // AUTHENT_INFO needed by k2
  99. //
  100. TCP_AUTHENT_INFO m_TCPAuthentInfo;
  101. DWORD m_dwInstanceAuthFlags;
  102. //
  103. // private member functions used to implement ProcessAuthInfo
  104. // after some amount of error and parameter checking
  105. //
  106. BOOL ProcessUser(
  107. IN PIIS_SERVER_INSTANCE pIisInstance,
  108. IN LPSTR pszUser,
  109. OUT REPLY_LIST* pReply
  110. );
  111. BOOL ProcessPass(
  112. IN PIIS_SERVER_INSTANCE pIisInstance,
  113. IN LPSTR pszPass,
  114. OUT REPLY_LIST* pReply
  115. );
  116. BOOL ProcessTransact(
  117. IN PIIS_SERVER_INSTANCE pIisInstance,
  118. IN LPSTR Blob,
  119. IN OUT LPBYTE ReplyString,
  120. IN OUT PDWORD ReplySize,
  121. OUT REPLY_LIST* pReply,
  122. IN DWORD BlobLength
  123. );
  124. BOOL MbsBasicLogon(
  125. IN LPSTR pszUser,
  126. IN LPSTR pszPass,
  127. OUT BOOL *pfAsGuest,
  128. OUT BOOL *pfAsAnonymous
  129. );
  130. public:
  131. CSecurityCtx(
  132. PIIS_SERVER_INSTANCE pIisInstance,
  133. DWORD AuthFlags = TCPAUTH_SERVER|TCPAUTH_UUENCODE,
  134. DWORD InstanceAuthFlags = INET_INFO_AUTH_ANONYMOUS,
  135. TCP_AUTHENT_INFO *pTcpAuthInfo = NULL
  136. );
  137. ~CSecurityCtx();
  138. //
  139. // routines used to initialize and terminate use of this class
  140. //
  141. static BOOL Initialize(
  142. BOOL fAllowGuest = TRUE,
  143. BOOL fStartAnonymous = TRUE
  144. );
  145. static VOID Terminate( VOID );
  146. BOOL SetInstanceAuthPackageNames(
  147. DWORD cProviderPackages,
  148. LPSTR ProviderNames,
  149. PAUTH_BLOCK ProviderPackages);
  150. BOOL GetInstanceAuthPackageNames(
  151. OUT LPBYTE ReplyString,
  152. IN OUT PDWORD ReplySize,
  153. IN PKG_REPLY_FMT PkgFmt = PkgFmtSpace);
  154. //
  155. // Returns the login name of the user
  156. //
  157. LPSTR QueryUserName(void) { return m_LoginName; }
  158. //
  159. // returns whether session has successfully authenticated
  160. //
  161. BOOL IsAuthenticated( void ) { return m_IsAuthenticated; }
  162. //
  163. // returns whether session was a clear text logon
  164. //
  165. BOOL IsClearText( void ) { return m_IsClearText; }
  166. //
  167. // returns whether session logged on as Guest
  168. //
  169. BOOL IsGuest( void ) { return m_IsGuest; }
  170. //
  171. // returns whether session logged on Anonymously
  172. //
  173. BOOL IsAnonymous( void ) { return m_IsAnonymous; }
  174. //
  175. // Methods for determining whether MBS should be used
  176. //
  177. BOOL ShouldUseMbs( void );
  178. //
  179. // Method to set the cleartext package name of the current security context
  180. //
  181. VOID SetCleartextPackageName(
  182. LPSTR szCleartextPackageName,
  183. LPSTR szMembershipBrokerName
  184. );
  185. //
  186. // resets the user name
  187. //
  188. void Reset( void );
  189. //
  190. // set the supported SSPI packages
  191. // Parameter is the same format as returned by RegQueryValueEx for
  192. // REG_MULTI_SZ values
  193. //
  194. static BOOL SetAuthPackageNames(
  195. IN LPSTR lpMultiSzProviders,
  196. IN DWORD cchMultiSzProviders
  197. );
  198. //
  199. // different than set in that the packages are returned separated
  200. // by spaces and only a single terminating NULL. This is done to
  201. // make the response to the client easier to format
  202. //
  203. static BOOL GetAuthPackageNames(
  204. OUT LPBYTE ReplyString,
  205. IN OUT PDWORD ReplySize,
  206. IN PKG_REPLY_FMT PkgFmt = PkgFmtSpace
  207. );
  208. //
  209. // Service Principal Name routines for Kerberos authentication.
  210. //
  211. // A SPN is a name for a server that a client and server can independantly
  212. // compute (ie, compute it without communicating with each other). Only
  213. // then is mutual auth possible.
  214. //
  215. // Here, we take the approach of using the stringized IP addrs returned by
  216. // doing a gethostbyname on the FQDN as the identifying part of SPNs.
  217. // Since the clients connecting to this server know which IP they are using,
  218. // they too can indepedently generate the SPN.
  219. //
  220. // So, the usage of the methods below is:
  221. //
  222. // 1. On service startup, call ResetServicePrincipalNames.
  223. // This cleans up all SPNs for the service registered on the local
  224. // computer account.
  225. //
  226. // 2. On each virtual server startup, call RegisterServicePrincipalNames
  227. // with the FQDN of that virtual server. This causes new SPNs to be
  228. // registered on the local computer account.
  229. //
  230. // 3. When acting as a client (eg, SMTP outbound), call
  231. // SetTargetPrincipalName, passing in the IP address of the remote server
  232. //
  233. // 4. If desired, one may call ResetServicePrincipalNames on service
  234. // (NOT virtual server!) shutdown. This will unregister the SPNs for all
  235. // virtual servers of that type.
  236. //
  237. // In all cases, szServiceClass is a service specific string, like "SMTP"
  238. //
  239. static BOOL ResetServicePrincipalNames(
  240. IN LPCSTR szServiceType);
  241. static BOOL RegisterServicePrincipalNames(
  242. IN LPCSTR szServiceType,
  243. IN LPCSTR szFQDN);
  244. BOOL SetTargetPrincipalName(
  245. IN LPCSTR szServiceType,
  246. IN LPCSTR szTargetIP);
  247. //
  248. // external interface for initiating a client-side AUTH protocol exchange.
  249. // You should use this instead of TCP_AUTHENT::Converse or
  250. // TCP_AUTHENT::ConverseEx because it gives this object a chance to map
  251. // Internet security protocol names to NT package names (eg, from GSSAPI to
  252. // Negotiate)
  253. //
  254. BOOL ClientConverse(
  255. IN VOID * pBuffIn,
  256. IN DWORD cbBuffIn,
  257. OUT BUFFER * pbuffOut,
  258. OUT DWORD * pcbBuffOut,
  259. OUT BOOL * pfNeedMoreData,
  260. IN PTCP_AUTHENT_INFO pTAI,
  261. IN CHAR * pszPackage = NULL,
  262. IN CHAR * pszUser = NULL,
  263. IN CHAR * pszPassword = NULL,
  264. IN PIIS_SERVER_INSTANCE psi = NULL );
  265. //
  266. // external interface for passing blobs received as part of AUTHINFO
  267. // or AUTH processing
  268. //
  269. BOOL ProcessAuthInfo(
  270. IN PIIS_SERVER_INSTANCE pIisInstance,
  271. IN AUTH_COMMAND Command,
  272. IN LPSTR Blob,
  273. IN OUT LPBYTE ReplyString,
  274. IN OUT PDWORD ReplySize,
  275. OUT REPLY_LIST* pReplyListID,
  276. IN OPTIONAL DWORD BlobLength = 0
  277. );
  278. }; // CSecurityCtx
  279. #endif // _SIMAUTH_H_