fixes for macOS/Linux

This commit is contained in:
Günter Obiltschnig
2019-05-15 15:54:10 +02:00
parent e821a2a9f1
commit a335f6da89
2 changed files with 36 additions and 27 deletions

View File

@@ -33,7 +33,7 @@ objects = \
WebSocket WebSocketImpl \ WebSocket WebSocketImpl \
OAuth10Credentials OAuth20Credentials \ OAuth10Credentials OAuth20Credentials \
PollSet UDPClient UDPServerParams \ PollSet UDPClient UDPServerParams \
NTLMCredentials HTTPNTLMCredentials NTLMCredentials SSPINTLMCredentials HTTPNTLMCredentials
target = PocoNet target = PocoNet
target_version = $(LIBVERSION) target_version = $(LIBVERSION)

View File

@@ -30,10 +30,6 @@ namespace Poco {
namespace Net { namespace Net {
const std::string SSPINTLMCredentials::SERVICE_HTTP("HTTP");
const std::string SSPINTLMCredentials::SERVICE_SMTP("SMTP");
struct NTLMContextImpl struct NTLMContextImpl
{ {
NTLMContextImpl(): NTLMContextImpl():
@@ -73,7 +69,7 @@ public:
{ {
PSecPkgInfoW pSecPkgInfo; PSecPkgInfoW pSecPkgInfo;
SECURITY_STATUS status = _pSecFunTable->QuerySecurityPackageInfoW(L"NTLM", &pSecPkgInfo); SECURITY_STATUS status = _pSecFunTable->QuerySecurityPackageInfoW(L"NTLM", &pSecPkgInfo);
if (status == SEC_E_OK) if (status == SEC_E_OK)
{ {
_pSecFunTable->FreeContextBuffer(pSecPkgInfo); _pSecFunTable->FreeContextBuffer(pSecPkgInfo);
return true; return true;
@@ -95,14 +91,14 @@ public:
TimeStamp expiry; TimeStamp expiry;
status = _pSecFunTable->AcquireCredentialsHandleW( status = _pSecFunTable->AcquireCredentialsHandleW(
NULL, NULL,
L"NTLM", L"NTLM",
SECPKG_CRED_OUTBOUND, SECPKG_CRED_OUTBOUND,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
&pContext->_pImpl->credentials, &pContext->_pImpl->credentials,
&expiry); &expiry);
if (status != SEC_E_OK) throw Poco::SystemException("Failed to acquire NTLM credentials", status); if (status != SEC_E_OK) throw Poco::SystemException("Failed to acquire NTLM credentials", status);
@@ -132,13 +128,13 @@ public:
unsigned long attrs; unsigned long attrs;
TimeStamp expiry; TimeStamp expiry;
SECURITY_STATUS status = _pSecFunTable->InitializeSecurityContextW( SECURITY_STATUS status = _pSecFunTable->InitializeSecurityContextW(
&context._pImpl->credentials, &context._pImpl->credentials,
NULL, NULL,
const_cast<SEC_WCHAR*>(context._pImpl->spn.c_str()), const_cast<SEC_WCHAR*>(context._pImpl->spn.c_str()),
0, 0,
0, 0,
SECURITY_NETWORK_DREP, SECURITY_NETWORK_DREP,
NULL, NULL,
0, 0,
&context._pImpl->context, &context._pImpl->context,
&msgBufferDesc, &msgBufferDesc,
@@ -209,11 +205,11 @@ public:
void clearNTLMContext(NTLMContext& ctx) void clearNTLMContext(NTLMContext& ctx)
{ {
if (SecIsValidHandle(&ctx._pImpl->context)) if (SecIsValidHandle(&ctx._pImpl->context))
{ {
_pSecFunTable->DeleteSecurityContext(&ctx._pImpl->context); _pSecFunTable->DeleteSecurityContext(&ctx._pImpl->context);
} }
if (SecIsValidHandle(&ctx._pImpl->credentials)) if (SecIsValidHandle(&ctx._pImpl->credentials))
{ {
_pSecFunTable->FreeCredentialsHandle(&ctx._pImpl->credentials); _pSecFunTable->FreeCredentialsHandle(&ctx._pImpl->credentials);
} }
@@ -229,7 +225,7 @@ private:
}; };
namespace namespace
{ {
static Poco::SingletonHolder<SSPINTLMProvider> sspintlmProviderHolder; static Poco::SingletonHolder<SSPINTLMProvider> sspintlmProviderHolder;
} }
@@ -241,6 +237,20 @@ SSPINTLMProvider& SSPINTLMProvider::instance()
} }
} } // namespace Poco::Net
#endif // POCO_OS == POCO_OS_WINDOWS_NT
namespace Poco {
namespace Net {
const std::string SSPINTLMCredentials::SERVICE_HTTP("HTTP");
const std::string SSPINTLMCredentials::SERVICE_SMTP("SMTP");
NTLMContext::NTLMContext(NTLMContextImpl* pImpl): NTLMContext::NTLMContext(NTLMContextImpl* pImpl):
_pImpl(pImpl) _pImpl(pImpl)
{ {
@@ -249,14 +259,13 @@ NTLMContext::NTLMContext(NTLMContextImpl* pImpl):
NTLMContext::~NTLMContext() NTLMContext::~NTLMContext()
{ {
#if POCO_OS == POCO_OS_WINDOWS_NT
SSPINTLMProvider::instance().clearNTLMContext(*this); SSPINTLMProvider::instance().clearNTLMContext(*this);
delete _pImpl; delete _pImpl;
#endif
} }
#endif // POCO_OS == POCO_OS_WINDOWS_NT
bool SSPINTLMCredentials::available() bool SSPINTLMCredentials::available()
{ {
#if POCO_OS == POCO_OS_WINDOWS_NT #if POCO_OS == POCO_OS_WINDOWS_NT