SspiUtils.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef SSPI_UTILS_HH
  2. #define SSPI_UTILS_HH
  3. #ifdef _WIN32
  4. #include <winsock2.h>
  5. #ifdef __GNUC__
  6. // MinGW32 requires that subauth.h be included before security.h, in order to define several things
  7. // This differs from VC++, which only needs security.h
  8. #include <subauth.h>
  9. // MinGW32 does not define NEGOSSP_NAME_W anywhere. It should.
  10. #define NEGOSSP_NAME_W L"Negotiate"
  11. #endif
  12. #ifndef SECURITY_WIN32
  13. #define SECURITY_WIN32
  14. #endif
  15. #include <security.h>
  16. #include <vector>
  17. #include "openmsx.h"
  18. //
  19. // NOTE: This file MUST be kept in sync between the openmsx and openmsx-debugger projects
  20. //
  21. namespace openmsx {
  22. namespace sspiutils {
  23. const unsigned STREAM_ERROR = 0xffffffff;
  24. class StreamWrapper
  25. {
  26. public:
  27. virtual uint32 Read(void* buffer, uint32 cb) = 0;
  28. virtual uint32 Write(void* buffer, uint32 cb) = 0;
  29. };
  30. class SspiPackageBase
  31. {
  32. protected:
  33. CredHandle hCreds;
  34. CtxtHandle hContext;
  35. StreamWrapper& stream;
  36. const unsigned int cbMaxTokenSize;
  37. SspiPackageBase(StreamWrapper& stream, const SEC_WCHAR* securityPackage);
  38. ~SspiPackageBase();
  39. };
  40. // Generic access control flags, used with AccessCheck
  41. const DWORD ACCESS_READ = 0x1;
  42. const DWORD ACCESS_WRITE = 0x2;
  43. const DWORD ACCESS_EXECUTE = 0x4;
  44. const DWORD ACCESS_ALL = ACCESS_READ | ACCESS_WRITE | ACCESS_EXECUTE;
  45. const GENERIC_MAPPING mapping = {
  46. ACCESS_READ, ACCESS_WRITE, ACCESS_EXECUTE, ACCESS_ALL };
  47. void InitTokenContextBuffer(PSecBufferDesc pSecBufferDesc, PSecBuffer pSecBuffer);
  48. void ClearContextBuffers(PSecBufferDesc pSecBufferDesc);
  49. void DebugPrintSecurityStatus(const char* context, SECURITY_STATUS ss);
  50. void DebugPrintSecurityBool(const char* context, BOOL ret);
  51. void DebugPrintSecurityPackageName(PCtxtHandle phContext);
  52. void DebugPrintSecurityPrincipalName(PCtxtHandle phContext);
  53. void DebugPrintSecurityDescriptor(PSECURITY_DESCRIPTOR psd);
  54. PSECURITY_DESCRIPTOR CreateCurrentUserSecurityDescriptor();
  55. unsigned long GetPackageMaxTokenSize(const SEC_WCHAR* package);
  56. bool SendChunk(StreamWrapper& stream, void* buffer, uint32 cb);
  57. bool RecvChunk(StreamWrapper& stream, std::vector<char>& buffer, uint32 cbMaxSize);
  58. } // namespace sspiutils
  59. } // namespace openmsx
  60. #endif // _WIN32
  61. #endif // SSPI_UTILS_HH