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