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.

276 lines
6.9 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. // Response IDs for the Converse function. If the return
  24. // value is anything other than SecNull, the application
  25. // should map these IDs to that appropriate protocol specific
  26. // response string. If the value is SecNull, the application
  27. // should send the returned data from Converse to the client
  28. // with the appropriate header ( ie +OK ) and trailer ( ie \r\n )
  29. //
  30. typedef enum _REPLY_LIST {
  31. SecAuthOk,
  32. SecAuthOkAnon,
  33. SecProtOk,
  34. SecNeedPwd,
  35. SecBadCommand,
  36. SecSyntaxErr,
  37. SecPermissionDenied,
  38. SecNoUsername,
  39. SecInternalErr,
  40. SecAuthReq,
  41. SecProtNS,
  42. SecNull,
  43. NUM_SEC_REPLIES
  44. } REPLY_LIST;
  45. enum PKG_REPLY_FMT
  46. {
  47. PkgFmtSpace,
  48. PkgFmtCrLf
  49. };
  50. //
  51. // CSecurityContext - user security context class designed to work with any
  52. // ssp interface. The object have 2 sets of context handles - one for
  53. // authentication, and one for encrption. If we are using only one package,
  54. // then these handles point to the same thing. This is used to support
  55. // use of multi-ssp packages like Sicily over SSL.
  56. //
  57. class CSecurityCtx : public TCP_AUTHENT
  58. {
  59. private:
  60. //
  61. // Have we been authenticated, if so did we use the
  62. // anonymous token
  63. //
  64. BOOL m_IsAuthenticated;
  65. BOOL m_IsClearText;
  66. BOOL m_IsAnonymous;
  67. BOOL m_IsGuest;
  68. static BOOL m_AllowGuest;
  69. static BOOL m_StartAnonymous;
  70. //
  71. // storage for login name while waiting for the pswd
  72. //
  73. LPSTR m_LoginName;
  74. //
  75. // storage for package name used
  76. //
  77. LPSTR m_PackageName;
  78. //
  79. // static variables used by all class instances
  80. //
  81. static LPTSVC_INFO m_pTsvcInfo;
  82. //
  83. // private member functions used to implement ProcessAuthInfo
  84. // after some amount of error and parameter checking
  85. //
  86. BOOL ProcessUser(
  87. IN LPSTR pszUser,
  88. OUT REPLY_LIST* pReply
  89. );
  90. BOOL ProcessPass(
  91. IN LPSTR pszPass,
  92. OUT REPLY_LIST* pReply
  93. );
  94. BOOL ProcessTransact(
  95. IN LPSTR Blob,
  96. IN OUT LPBYTE ReplyString,
  97. IN OUT PDWORD ReplySize,
  98. OUT REPLY_LIST* pReply,
  99. IN DWORD BlobLength
  100. );
  101. public:
  102. CSecurityCtx(
  103. DWORD AuthFlags = TCPAUTH_SERVER|TCPAUTH_UUENCODE
  104. );
  105. ~CSecurityCtx();
  106. //
  107. // routines used to initialize and terminate use of this class
  108. //
  109. static BOOL Initialize(
  110. LPTSVC_INFO pTsvcInfo,
  111. BOOL fAllowGuest = TRUE,
  112. BOOL fStartAnonymous = TRUE
  113. );
  114. static VOID Terminate( VOID );
  115. //
  116. // Returns the login name of the user
  117. //
  118. LPSTR QueryUserName(void) { return m_LoginName; }
  119. //
  120. // returns whether session has successfully authenticated
  121. //
  122. BOOL IsAuthenticated( void ) { return m_IsAuthenticated; }
  123. //
  124. // returns whether session was a clear text logon
  125. //
  126. BOOL IsClearText( void ) { return m_IsClearText; }
  127. //
  128. // returns whether session logged on as Guest
  129. //
  130. BOOL IsGuest( void ) { return m_IsGuest; }
  131. //
  132. // returns whether session logged on Anonymously
  133. //
  134. BOOL IsAnonymous( void ) { return m_IsAnonymous; }
  135. //
  136. // resets the user name
  137. //
  138. void Reset( void );
  139. //
  140. // set the supported SSPI packages
  141. // Parameter is the same format as returned by RegQueryValueEx for
  142. // REG_MULTI_SZ values
  143. //
  144. static BOOL SetAuthPackageNames(
  145. IN LPSTR lpMultiSzProviders,
  146. IN DWORD cchMultiSzProviders
  147. );
  148. //
  149. // different than set in that the packages are returned separated
  150. // by spaces and only a single terminating NULL. This is done to
  151. // make the response to the client easier to format
  152. //
  153. static BOOL GetAuthPackageNames(
  154. OUT LPBYTE ReplyString,
  155. IN OUT PDWORD ReplySize,
  156. IN PKG_REPLY_FMT PkgFmt = PkgFmtSpace
  157. );
  158. //
  159. // Service Principal Name routines for Kerberos authentication.
  160. //
  161. // A SPN is a name for a server that a client and server can independantly
  162. // compute (ie, compute it without communicating with each other). Only
  163. // then is mutual auth possible.
  164. //
  165. // Here, we take the approach of using the stringized IP addrs returned by
  166. // doing a gethostbyname on the FQDN as the identifying part of SPNs.
  167. // Since the clients connecting to this server know which IP they are using,
  168. // they too can indepedently generate the SPN.
  169. //
  170. // So, the usage of the methods below is:
  171. //
  172. // 1. On service startup, call ResetServicePrincipalNames.
  173. // This cleans up all SPNs for the service registered on the local
  174. // computer account.
  175. //
  176. // 2. On each virtual server startup, call RegisterServicePrincipalNames
  177. // with the FQDN of that virtual server. This causes new SPNs to be
  178. // registered on the local computer account.
  179. //
  180. // 3. When acting as a client (eg, SMTP outbound), call
  181. // SetTargetPrincipalName, passing in the IP address of the remote server
  182. //
  183. // 4. If desired, one may call ResetServicePrincipalNames on service
  184. // (NOT virtual server!) shutdown. This will unregister the SPNs for all
  185. // virtual servers of that type.
  186. //
  187. // In all cases, szServiceClass is a service specific string, like "SMTP"
  188. //
  189. static BOOL ResetServicePrincipalNames(
  190. IN LPCSTR szServiceType);
  191. static BOOL RegisterServicePrincipalNames(
  192. IN LPCSTR szServiceType,
  193. IN LPCSTR szFQDN);
  194. BOOL SetTargetPrincipalName(
  195. IN LPCSTR szServiceType,
  196. IN LPCSTR szTargetIP);
  197. //
  198. // external interface for passing blobs received as part of AUTHINFO
  199. // or AUTH processing
  200. //
  201. BOOL ProcessAuthInfo(
  202. IN AUTH_COMMAND Command,
  203. IN LPSTR Blob,
  204. IN OUT LPBYTE ReplyString,
  205. IN OUT PDWORD ReplySize,
  206. OUT REPLY_LIST* pReplyListID,
  207. IN OPTIONAL DWORD BlobLength = 0
  208. );
  209. }; // CSecurityCtx
  210. #endif // _SIMAUTH_H_