OXYGENHUB
◆ main openmsx / src / security / SspiUtils.hh
2.1 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 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
27
namespace openmsx::sspiutils {
28
29
const unsigned STREAM_ERROR = 0xffffffff;
30
31
class StreamWrapper
32
{
33
public:
34
	virtual uint32_t Read (void* buffer, uint32_t cb) = 0;
35
	virtual uint32_t Write(void* buffer, uint32_t cb) = 0;
36
};
37
38
class SspiPackageBase
39
{
40
protected:
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
52
const DWORD ACCESS_READ = 0x1;
53
const DWORD ACCESS_WRITE = 0x2;
54
const DWORD ACCESS_EXECUTE = 0x4;
55
const DWORD ACCESS_ALL = ACCESS_READ | ACCESS_WRITE | ACCESS_EXECUTE;
56
57
const GENERIC_MAPPING mapping = {
58
	ACCESS_READ, ACCESS_WRITE, ACCESS_EXECUTE, ACCESS_ALL
59
};
60
void InitTokenContextBuffer(PSecBufferDesc pSecBufferDesc, PSecBuffer pSecBuffer);
61
void ClearContextBuffers(PSecBufferDesc pSecBufferDesc);
62
void DebugPrintSecurityStatus(const char* context, SECURITY_STATUS ss);
63
void DebugPrintSecurityBool(const char* context, BOOL ret);
64
void DebugPrintSecurityPackageName(PCtxtHandle phContext);
65
void DebugPrintSecurityPrincipalName(PCtxtHandle phContext);
66
void DebugPrintSecurityDescriptor(PSECURITY_DESCRIPTOR psd);
67
PSECURITY_DESCRIPTOR CreateCurrentUserSecurityDescriptor();
68
unsigned long GetPackageMaxTokenSize(const SEC_WCHAR* package);
69
70
bool SendChunk(StreamWrapper& stream, void* buffer, uint32_t cb);
71
bool 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