mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2026-02-07 10:19:47 +08:00
fix(log): move sa_initiator struct outside get_sa() function
- src/libipc/platform/win/get_sa.h: * Move 'struct initiator' definition outside get_sa() function * Rename to 'sa_initiator' to avoid naming conflicts * Define at namespace ipc::detail scope (above get_sa function) * Keep template constructor: template <typename Logger> sa_initiator(Logger const &log) * get_sa() now simply uses: static sa_initiator handle(log); This fixes the C++ standard violation: - C++03/11/14/17/20 all prohibit local classes from having member templates - Error C2892: 'local class shall not have member templates' - Moving the struct to namespace scope resolves this issue The struct is now a proper namespace-level definition with a template constructor, which is fully compliant with C++ standards.
This commit is contained in:
parent
72eedeb6c4
commit
ab8e6c7d2c
@ -5,32 +5,31 @@
|
|||||||
namespace ipc {
|
namespace ipc {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
|
struct sa_initiator {
|
||||||
|
SECURITY_DESCRIPTOR sd_;
|
||||||
|
SECURITY_ATTRIBUTES sa_;
|
||||||
|
bool succ_ = false;
|
||||||
|
|
||||||
|
template <typename Logger>
|
||||||
|
sa_initiator(Logger const &log) {
|
||||||
|
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
||||||
|
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) {
|
||||||
|
log.error("fail SetSecurityDescriptorDacl[", static_cast<int>(::GetLastError()), "]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sa_.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||||
|
sa_.bInheritHandle = FALSE;
|
||||||
|
sa_.lpSecurityDescriptor = &sd_;
|
||||||
|
succ_ = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
inline LPSECURITY_ATTRIBUTES get_sa() {
|
inline LPSECURITY_ATTRIBUTES get_sa() {
|
||||||
LIBIPC_LOG();
|
LIBIPC_LOG();
|
||||||
|
static sa_initiator handle(log);
|
||||||
struct initiator {
|
|
||||||
SECURITY_DESCRIPTOR sd_;
|
|
||||||
SECURITY_ATTRIBUTES sa_;
|
|
||||||
bool succ_ = false;
|
|
||||||
|
|
||||||
template <typename Logger>
|
|
||||||
initiator(Logger const &log) {
|
|
||||||
if (!::InitializeSecurityDescriptor(&sd_, SECURITY_DESCRIPTOR_REVISION)) {
|
|
||||||
log.error("fail InitializeSecurityDescriptor[", static_cast<int>(::GetLastError()), "]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!::SetSecurityDescriptorDacl(&sd_, TRUE, NULL, FALSE)) {
|
|
||||||
log.error("fail SetSecurityDescriptorDacl[", static_cast<int>(::GetLastError()), "]");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sa_.nLength = sizeof(SECURITY_ATTRIBUTES);
|
|
||||||
sa_.bInheritHandle = FALSE;
|
|
||||||
sa_.lpSecurityDescriptor = &sd_;
|
|
||||||
succ_ = true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static initiator handle(log);
|
|
||||||
return handle.succ_ ? &handle.sa_ : nullptr;
|
return handle.succ_ ? &handle.sa_ : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user