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.

363 lines
10 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. static HANDLE m_hTokenAnonymous;
  82. //
  83. // storage for login name while waiting for the pswd
  84. //
  85. LPSTR m_LoginName;
  86. //
  87. // storage for package name used
  88. //
  89. LPSTR m_PackageName;
  90. DWORD m_cProviderPackages;
  91. LPSTR m_ProviderNames;
  92. PAUTH_BLOCK m_ProviderPackages;
  93. //
  94. // Cleartext package name
  95. //
  96. char m_szCleartextPackageName[MAX_PATH];
  97. char m_szMembershipBrokerName[MAX_PATH];
  98. //
  99. // AUTHENT_INFO needed by k2
  100. //
  101. TCP_AUTHENT_INFO m_TCPAuthentInfo;
  102. DWORD m_dwInstanceAuthFlags;
  103. //
  104. // private member functions used to implement ProcessAuthInfo
  105. // after some amount of error and parameter checking
  106. //
  107. BOOL ProcessUser(
  108. IN PIIS_SERVER_INSTANCE pIisInstance,
  109. IN LPSTR pszUser,
  110. OUT REPLY_LIST* pReply
  111. );
  112. BOOL ProcessPass(
  113. IN PIIS_SERVER_INSTANCE pIisInstance,
  114. IN LPSTR pszPass,
  115. OUT REPLY_LIST* pReply
  116. );
  117. BOOL ProcessTransact(
  118. IN PIIS_SERVER_INSTANCE pIisInstance,
  119. IN LPSTR Blob,
  120. IN OUT LPBYTE ReplyString,
  121. IN OUT PDWORD ReplySize,
  122. OUT REPLY_LIST* pReply,
  123. IN DWORD BlobLength
  124. );
  125. BOOL MbsBasicLogon(
  126. IN LPSTR pszUser,
  127. IN LPSTR pszPass,
  128. OUT BOOL *pfAsGuest,
  129. OUT BOOL *pfAsAnonymous
  130. );
  131. public:
  132. CSecurityCtx(
  133. PIIS_SERVER_INSTANCE pIisInstance,
  134. DWORD AuthFlags = TCPAUTH_SERVER|TCPAUTH_UUENCODE,
  135. DWORD InstanceAuthFlags = INET_INFO_AUTH_ANONYMOUS,
  136. TCP_AUTHENT_INFO *pTcpAuthInfo = NULL
  137. );
  138. ~CSecurityCtx();
  139. //
  140. // routines used to initialize and terminate use of this class
  141. //
  142. static BOOL Initialize(
  143. BOOL fAllowGuest = TRUE,
  144. BOOL fStartAnonymous = TRUE
  145. );
  146. static VOID Terminate( VOID );
  147. BOOL SetInstanceAuthPackageNames(
  148. DWORD cProviderPackages,
  149. LPSTR ProviderNames,
  150. PAUTH_BLOCK ProviderPackages);
  151. BOOL GetInstanceAuthPackageNames(
  152. OUT LPBYTE ReplyString,
  153. IN OUT PDWORD ReplySize,
  154. IN PKG_REPLY_FMT PkgFmt = PkgFmtSpace);
  155. //
  156. // Returns the login name of the user
  157. //
  158. LPSTR QueryUserName(void) { return m_LoginName; }
  159. //
  160. // returns whether session has successfully authenticated
  161. //
  162. BOOL IsAuthenticated( void ) { return m_IsAuthenticated; }
  163. //
  164. // returns whether session was a clear text logon
  165. //
  166. BOOL IsClearText( void ) { return m_IsClearText; }
  167. //
  168. // returns whether session logged on as Guest
  169. //
  170. BOOL IsGuest( void ) { return m_IsGuest; }
  171. //
  172. // returns whether session logged on Anonymously
  173. //
  174. BOOL IsAnonymous( void ) { return m_IsAnonymous; }
  175. //
  176. // Methods for determining whether MBS should be used
  177. //
  178. BOOL ShouldUseMbs( void );
  179. //
  180. // Method to set the cleartext package name of the current security context
  181. //
  182. VOID SetCleartextPackageName(
  183. LPSTR szCleartextPackageName,
  184. LPSTR szMembershipBrokerName
  185. );
  186. //
  187. // resets the user name
  188. //
  189. void Reset( void );
  190. // override base class. Use m_hTokenAnonymous if it's NNTP Anon. Otherwise call base class.
  191. HANDLE QueryImpersonationToken( VOID );
  192. //
  193. // set the supported SSPI packages
  194. // Parameter is the same format as returned by RegQueryValueEx for
  195. // REG_MULTI_SZ values
  196. //
  197. static BOOL SetAuthPackageNames(
  198. IN LPSTR lpMultiSzProviders,
  199. IN DWORD cchMultiSzProviders
  200. );
  201. //
  202. // different than set in that the packages are returned separated
  203. // by spaces and only a single terminating NULL. This is done to
  204. // make the response to the client easier to format
  205. //
  206. static BOOL GetAuthPackageNames(
  207. OUT LPBYTE ReplyString,
  208. IN OUT PDWORD ReplySize,
  209. IN PKG_REPLY_FMT PkgFmt = PkgFmtSpace
  210. );
  211. //
  212. // Service Principal Name routines for Kerberos authentication.
  213. //
  214. // A SPN is a name for a server that a client and server can independantly
  215. // compute (ie, compute it without communicating with each other). Only
  216. // then is mutual auth possible.
  217. //
  218. // Here, we take the approach of using the stringized IP addrs returned by
  219. // doing a gethostbyname on the FQDN as the identifying part of SPNs.
  220. // Since the clients connecting to this server know which IP they are using,
  221. // they too can indepedently generate the SPN.
  222. //
  223. // So, the usage of the methods below is:
  224. //
  225. // 1. On service startup, call ResetServicePrincipalNames.
  226. // This cleans up all SPNs for the service registered on the local
  227. // computer account.
  228. //
  229. // 2. On each virtual server startup, call RegisterServicePrincipalNames
  230. // with the FQDN of that virtual server. This causes new SPNs to be
  231. // registered on the local computer account.
  232. //
  233. // 3. When acting as a client (eg, SMTP outbound), call
  234. // SetTargetPrincipalName, passing in the IP address of the remote server
  235. //
  236. // 4. If desired, one may call ResetServicePrincipalNames on service
  237. // (NOT virtual server!) shutdown. This will unregister the SPNs for all
  238. // virtual servers of that type.
  239. //
  240. // In all cases, szServiceClass is a service specific string, like "SMTP"
  241. //
  242. static BOOL ResetServicePrincipalNames(
  243. IN LPCSTR szServiceType);
  244. static BOOL RegisterServicePrincipalNames(
  245. IN LPCSTR szServiceType,
  246. IN LPCSTR szFQDN);
  247. BOOL SetTargetPrincipalName(
  248. IN LPCSTR szServiceType,
  249. IN LPCSTR szTargetIP);
  250. //
  251. // external interface for initiating a client-side AUTH protocol exchange.
  252. // You should use this instead of TCP_AUTHENT::Converse or
  253. // TCP_AUTHENT::ConverseEx because it gives this object a chance to map
  254. // Internet security protocol names to NT package names (eg, from GSSAPI to
  255. // Negotiate)
  256. //
  257. BOOL ClientConverse(
  258. IN VOID * pBuffIn,
  259. IN DWORD cbBuffIn,
  260. OUT BUFFER * pbuffOut,
  261. OUT DWORD * pcbBuffOut,
  262. OUT BOOL * pfNeedMoreData,
  263. IN PTCP_AUTHENT_INFO pTAI,
  264. IN CHAR * pszPackage = NULL,
  265. IN CHAR * pszUser = NULL,
  266. IN CHAR * pszPassword = NULL,
  267. IN PIIS_SERVER_INSTANCE psi = NULL );
  268. //
  269. // external interface for passing blobs received as part of AUTHINFO
  270. // or AUTH processing
  271. //
  272. BOOL ProcessAuthInfo(
  273. IN PIIS_SERVER_INSTANCE pIisInstance,
  274. IN AUTH_COMMAND Command,
  275. IN LPSTR Blob,
  276. IN OUT LPBYTE ReplyString,
  277. IN OUT PDWORD ReplySize,
  278. OUT REPLY_LIST* pReplyListID,
  279. IN OPTIONAL DWORD BlobLength = 0
  280. );
  281. }; // CSecurityCtx
  282. #endif // _SIMAUTH_H_