| 1 |
#ifndef SSPI_UTILS_HH |
| 2 |
#define SSPI_UTILS_HH |
| 3 |
|
| 4 |
#ifdef _WIN32 |
| 5 |
|
| 6 |
#include <winsock2.h> |
| 7 |
#ifdef __GNUC__ |
| 8 |
|
| 9 |
|
| 10 |
#include <subauth.h> |
| 11 |
|
| 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 |
|
| 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 |
|
| 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 |
} |
| 74 |
|
| 75 |
#endif |
| 76 |
|
| 77 |
#endif |