Debian Codegraph @

src/openmsx/SspiUtils.h

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