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.

216 lines
4.6 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. CSSPI.H
  5. Abstract:
  6. SSPI wrapper implementation
  7. History:
  8. raymcc 15-Jul-97 Created
  9. --*/
  10. #ifndef _CSSPI_H_
  11. #define _CSSPI_H_
  12. #define SECURITY_WIN32
  13. //#include "corepol.h"
  14. extern "C"
  15. {
  16. #include <sspi.h>
  17. };
  18. class CSSPIClient;
  19. class CSSPIServer;
  20. //***************************************************************************
  21. //
  22. // CSSPI is the basic 'utility' class.
  23. //
  24. //***************************************************************************
  25. class CSSPI
  26. {
  27. static ULONG m_uNumPackages;
  28. static PSecPkgInfo m_pEnumPkgInfo;
  29. public:
  30. enum { NoError, InvalidPackage, Idle, Busy, Failed, Continue };
  31. static PSecurityFunctionTable pVtbl;
  32. // Used by client classes to access the SSPI v-table.
  33. static BOOL Initialize();
  34. // Called by all clients to initialize SSPI.
  35. // Helpers.
  36. // ========
  37. static const LPTSTR TranslateError(
  38. ULONG uCode
  39. );
  40. static void DisplayContextAttributes(
  41. ULONG uAttrib
  42. );
  43. static void DisplayPkgInfo(
  44. PSecPkgInfo pPkg
  45. );
  46. // To enumerate through the packages.
  47. // ==================================
  48. static ULONG GetNumPkgs();
  49. // Returns 0 if none available or an error occurred.
  50. static const PSecPkgInfo GetPkgInfo(ULONG lPkgNum);
  51. // Returns NULL on error
  52. static BOOL DumpSecurityPackages(); // Debug dump of packages
  53. // Query for support
  54. // =================
  55. static BOOL ServerSupport(LPTSTR pszPkgName);
  56. static BOOL ClientSupport(LPTSTR pszPkgName);
  57. };
  58. //***************************************************************************
  59. //
  60. // CSSPIClient
  61. //
  62. // Used for client-side authentication.
  63. //
  64. //***************************************************************************
  65. class CSSPIClient
  66. {
  67. DWORD m_dwStatus;
  68. ULONG m_cbMaxToken;
  69. PSecPkgInfo m_pPkgInfo;
  70. LPTSTR m_pszPkgName;
  71. BOOL m_bValidCredHandle;
  72. CredHandle m_ClientCredential;
  73. CtxtHandle m_ClientContext;
  74. BOOL m_bValidContextHandle;
  75. public:
  76. enum
  77. {
  78. NoError = 0,
  79. LoginCompleted,
  80. LoginContinue,
  81. InvalidUser,
  82. InternalError,
  83. AccessDenied = 5, // don't change
  84. InvalidPackage,
  85. Waiting,
  86. InvalidParameter,
  87. LoginCompleteNeeded,
  88. LoginCompleteAndContinue,
  89. Failed
  90. };
  91. CSSPIClient(LPTSTR pszPkgName);
  92. ~CSSPIClient();
  93. DWORD GetStatus() { return m_dwStatus; }
  94. ULONG MaxTokenSize() { return m_cbMaxToken; }
  95. DWORD SetLoginInfo(
  96. IN LPTSTR pszUser,
  97. IN LPTSTR pszDomain,
  98. IN LPTSTR pszPassword,
  99. IN DWORD dwFlags = 0
  100. );
  101. // Returns LoginContinue, AccessDenied, InvalidUser, InternalError
  102. // InvalidParameter
  103. DWORD SetDefaultLogin(DWORD dwFlags = 0);
  104. DWORD ContinueLogin(
  105. IN LPBYTE pInToken,
  106. IN DWORD dwInTokenSize,
  107. OUT LPBYTE *pToken,
  108. OUT DWORD *pdwTokenSize
  109. );
  110. // Returns LoginContinue, LoginCompleted, AccessDenied, InternalError
  111. DWORD BuildLoginToken(
  112. OUT LPBYTE *pToken,
  113. OUT DWORD *pdwToken
  114. );
  115. };
  116. //***************************************************************************
  117. //
  118. // CSSPIClient
  119. //
  120. // Used for client-side authentication.
  121. //
  122. //***************************************************************************
  123. class CSSPIServer
  124. {
  125. DWORD m_dwStatus;
  126. ULONG m_cbMaxToken;
  127. PSecPkgInfo m_pPkgInfo;
  128. LPTSTR m_pszPkgName;
  129. CredHandle m_ServerCredential;
  130. BOOL m_bValidCredHandle;
  131. CtxtHandle m_ServerContext;
  132. BOOL m_bValidContextHandle;
  133. public:
  134. enum
  135. {
  136. NoError = 0,
  137. LoginCompleted,
  138. InvalidPackage,
  139. Failed,
  140. Waiting,
  141. AccessDenied = 5, // don't change
  142. LoginCompleteNeeded,
  143. LoginCompleteAndContinue,
  144. LoginContinue
  145. };
  146. CSSPIServer(LPTSTR pszPkgName);
  147. ~CSSPIServer();
  148. DWORD GetStatus() { return m_dwStatus; }
  149. ULONG MaxTokenSize() { return m_cbMaxToken; }
  150. DWORD ContinueClientLogin(
  151. IN LPBYTE pInToken,
  152. IN DWORD dwInTokenSize,
  153. OUT LPBYTE *pToken,
  154. OUT DWORD *pdwTokenSize
  155. );
  156. DWORD IssueLoginToken(
  157. OUT CLSID &ClsId
  158. );
  159. BOOL QueryUserInfo(
  160. OUT LPTSTR *pszUser // Use operator delete
  161. );
  162. };
  163. #endif