Fix more Windows build errors

I did test this beforehand, but not on MinGW, and the error that showed
up on the msvc builder didn't happen for me...
This commit is contained in:
comex 2023-06-25 17:00:05 -07:00
parent 42015de49b
commit ac939f08a4
5 changed files with 36 additions and 29 deletions

View file

@ -872,7 +872,7 @@ if(ENABLE_OPENSSL)
elseif (WIN32) elseif (WIN32)
target_sources(core PRIVATE target_sources(core PRIVATE
hle/service/ssl/ssl_backend_schannel.cpp) hle/service/ssl/ssl_backend_schannel.cpp)
target_link_libraries(core PRIVATE Secur32) target_link_libraries(core PRIVATE secur32)
else() else()
target_sources(core PRIVATE target_sources(core PRIVATE
hle/service/ssl/ssl_backend_none.cpp) hle/service/ssl/ssl_backend_none.cpp)

View file

@ -149,7 +149,7 @@ static std::pair<u32, GetAddrInfoError> GetHostByNameRequestImpl(HLERequestConte
const std::string host = Common::StringFromBuffer(host_buffer); const std::string host = Common::StringFromBuffer(host_buffer);
// For now, ignore options, which are in input buffer 1 for GetHostByNameRequestWithOptions. // For now, ignore options, which are in input buffer 1 for GetHostByNameRequestWithOptions.
auto res = Network::GetAddrInfo(host, /*service*/ std::nullopt); auto res = Network::GetAddressInfo(host, /*service*/ std::nullopt);
if (!res.has_value()) { if (!res.has_value()) {
return {0, Translate(res.error())}; return {0, Translate(res.error())};
} }
@ -249,7 +249,7 @@ static std::pair<u32, GetAddrInfoError> GetAddrInfoRequestImpl(HLERequestContext
// Serialized hints are also passed in a buffer, but are ignored for now. // Serialized hints are also passed in a buffer, but are ignored for now.
auto res = Network::GetAddrInfo(host, service); auto res = Network::GetAddressInfo(host, service);
if (!res.has_value()) { if (!res.has_value()) {
return {0, Translate(res.error())}; return {0, Translate(res.error())};
} }

View file

@ -12,29 +12,31 @@
#include <mutex> #include <mutex>
#define SECURITY_WIN32
#include <Security.h>
#include <schnlsp.h>
namespace { namespace {
// These includes are inside the namespace to avoid a conflict on MinGW where
// the headers define an enum containing Network and Service as enumerators
// (which clash with the correspondingly named namespaces).
#define SECURITY_WIN32
#include <security.h>
#include <schnlsp.h>
std::once_flag one_time_init_flag; std::once_flag one_time_init_flag;
bool one_time_init_success = false; bool one_time_init_success = false;
SCHANNEL_CRED schannel_cred{ SCHANNEL_CRED schannel_cred{};
.dwVersion = SCHANNEL_CRED_VERSION, CredHandle cred_handle;
.dwFlags = SCH_USE_STRONG_CRYPTO | // don't allow insecure protocols
static void OneTimeInit() {
schannel_cred.dwVersion = SCHANNEL_CRED_VERSION;
schannel_cred.dwFlags = SCH_USE_STRONG_CRYPTO | // don't allow insecure protocols
SCH_CRED_AUTO_CRED_VALIDATION | // validate certs SCH_CRED_AUTO_CRED_VALIDATION | // validate certs
SCH_CRED_NO_DEFAULT_CREDS, // don't automatically present a client certificate SCH_CRED_NO_DEFAULT_CREDS; // don't automatically present a client certificate
// ^ I'm assuming that nobody would want to connect Yuzu to a // ^ I'm assuming that nobody would want to connect Yuzu to a
// service that requires some OS-provided corporate client // service that requires some OS-provided corporate client
// certificate, and presenting one to some arbitrary server // certificate, and presenting one to some arbitrary server
// might be a privacy concern? Who knows, though. // might be a privacy concern? Who knows, though.
};
CredHandle cred_handle;
static void OneTimeInit() {
SECURITY_STATUS ret = SECURITY_STATUS ret =
AcquireCredentialsHandle(nullptr, const_cast<LPTSTR>(UNISP_NAME), SECPKG_CRED_OUTBOUND, AcquireCredentialsHandle(nullptr, const_cast<LPTSTR>(UNISP_NAME), SECPKG_CRED_OUTBOUND,
nullptr, &schannel_cred, nullptr, nullptr, &cred_handle, nullptr); nullptr, &schannel_cred, nullptr, nullptr, &cred_handle, nullptr);
@ -179,15 +181,21 @@ public:
// [1] (will be replaced by SECBUFFER_MISSING when SEC_E_INCOMPLETE_MESSAGE is // [1] (will be replaced by SECBUFFER_MISSING when SEC_E_INCOMPLETE_MESSAGE is
// returned, or SECBUFFER_EXTRA when SEC_E_CONTINUE_NEEDED is returned if the // returned, or SECBUFFER_EXTRA when SEC_E_CONTINUE_NEEDED is returned if the
// whole buffer wasn't used) // whole buffer wasn't used)
.cbBuffer = 0,
.BufferType = SECBUFFER_EMPTY, .BufferType = SECBUFFER_EMPTY,
.pvBuffer = nullptr,
}, },
}}; }};
std::array<SecBuffer, 2> output_buffers{{ std::array<SecBuffer, 2> output_buffers{{
{ {
.cbBuffer = 0,
.BufferType = SECBUFFER_TOKEN, .BufferType = SECBUFFER_TOKEN,
.pvBuffer = nullptr,
}, // [0] }, // [0]
{ {
.cbBuffer = 0,
.BufferType = SECBUFFER_ALERT, .BufferType = SECBUFFER_ALERT,
.pvBuffer = nullptr,
}, // [1] }, // [1]
}}; }};
SecBufferDesc input_desc{ SecBufferDesc input_desc{
@ -299,21 +307,20 @@ public:
return read_size; return read_size;
} }
if (!ciphertext_read_buf_.empty()) { if (!ciphertext_read_buf_.empty()) {
SecBuffer empty{
.cbBuffer = 0,
.BufferType = SECBUFFER_EMPTY,
.pvBuffer = nullptr,
};
std::array<SecBuffer, 5> buffers{{ std::array<SecBuffer, 5> buffers{{
{ {
.cbBuffer = static_cast<unsigned long>(ciphertext_read_buf_.size()), .cbBuffer = static_cast<unsigned long>(ciphertext_read_buf_.size()),
.BufferType = SECBUFFER_DATA, .BufferType = SECBUFFER_DATA,
.pvBuffer = ciphertext_read_buf_.data(), .pvBuffer = ciphertext_read_buf_.data(),
}, },
{ empty,
.BufferType = SECBUFFER_EMPTY, empty,
}, empty,
{
.BufferType = SECBUFFER_EMPTY,
},
{
.BufferType = SECBUFFER_EMPTY,
},
}}; }};
ASSERT_OR_EXECUTE_MSG( ASSERT_OR_EXECUTE_MSG(
buffers[0].cbBuffer == ciphertext_read_buf_.size(), buffers[0].cbBuffer == ciphertext_read_buf_.size(),

View file

@ -493,9 +493,7 @@ u32 IPv4AddressToInteger(IPv4Address ip_addr) {
static_cast<u32>(ip_addr[2]) << 8 | static_cast<u32>(ip_addr[3]); static_cast<u32>(ip_addr[2]) << 8 | static_cast<u32>(ip_addr[3]);
} }
#undef GetAddrInfo // Windows defines it as a macro Common::Expected<std::vector<AddrInfo>, GetAddrInfoError> GetAddressInfo(
Common::Expected<std::vector<AddrInfo>, GetAddrInfoError> GetAddrInfo(
const std::string& host, const std::optional<std::string>& service) { const std::string& host, const std::optional<std::string>& service) {
addrinfo hints{}; addrinfo hints{};
hints.ai_family = AF_INET; // Switch only supports IPv4. hints.ai_family = AF_INET; // Switch only supports IPv4.

View file

@ -5,6 +5,7 @@
#include <array> #include <array>
#include <optional> #include <optional>
#include <vector>
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
@ -113,7 +114,8 @@ std::optional<IPv4Address> GetHostIPv4Address();
std::string IPv4AddressToString(IPv4Address ip_addr); std::string IPv4AddressToString(IPv4Address ip_addr);
u32 IPv4AddressToInteger(IPv4Address ip_addr); u32 IPv4AddressToInteger(IPv4Address ip_addr);
Common::Expected<std::vector<AddrInfo>, GetAddrInfoError> GetAddrInfo( // named to avoid name collision with Windows macro
Common::Expected<std::vector<AddrInfo>, GetAddrInfoError> GetAddressInfo(
const std::string& host, const std::optional<std::string>& service); const std::string& host, const std::optional<std::string>& service);
} // namespace Network } // namespace Network