22 namespace jmmcg {
namespace LIBJMMCG_VER_NAMESPACE {
namespace NTUtils {
46 #if _WIN32_WINNT >= 0x0400
& defined(_ATL_FREE_THREADED)
47 const HRESULT hr=::CoInitializeEx(NULL, CoInitType);
49 const HRESULT hr=::CoInitialize(NULL);
51 JMMCG_TRACE(_T(
"COMInit::ctor: ::CoInitializeEx(..) return code: ")<<win_exception::StrFromWinErr(hr));
52 assert(SUCCEEDED(hr));
54 inline __stdcall ~
COMInit(
void)
noexcept(
true) {
58 JMMCG_TRACE(_T(
"COMInit::dtor: ::CoInitializeEx(..) failed."));
59 assert(!_T(
"COMInit::dtor: ::CoInitializeEx(..) failed."));
65 inline __stdcall COMInit(
const COMInit &)
noexcept(
true);
66 inline COMInit &
__fastcall operator=(
const COMInit &)
noexcept(
true);
73 Create(AuthnLevel,ImpersonationLevel);
77 Create(AuthnLevel,ImpersonationLevel);
81 authid.User=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(username.c_str()));
82 authid.UserLength=username.size();
83 authid.Domain=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(domain.c_str()));
84 authid.DomainLength=domain.size();
85 authid.Password=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(password.c_str()));
86 authid.PasswordLength=password.size();
89 SEC_WINNT_AUTH_IDENTITY_UNICODE;
91 SEC_WINNT_AUTH_IDENTITY_ANSI;
93 authinfo.dwAuthnSvc=ss.authinfo.dwAuthnSvc;
94 authinfo.dwAuthzSvc=ss.authinfo.dwAuthzSvc;
95 authinfo.pwszServerPrincName=ss.authinfo.pwszServerPrincName;
96 authinfo.dwAuthnLevel=ss.authinfo.dwAuthnLevel;
97 authinfo.dwImpersonationLevel=ss.authinfo.dwCapabilities;
98 authinfo.pAuthIdentityData=&authid;
99 authinfo.dwCapabilities=ss.authinfo.dwCapabilities;
100 serverinfo.dwReserved1=serverinfo.dwReserved2=0;
101 serverinfo.pwszName=
const_cast<
wchar_t *>(unc.c_str());
102 serverinfo.pAuthInfo=&authinfo;
122 const std::wstring unc;
123 const tstring username;
124 const tstring domain;
125 const tstring password;
126 COAUTHIDENTITY authid;
128 COSERVERINFO serverinfo;
130 inline void __fastcall Create(
const unsigned long AuthnLevel,
const unsigned long ImpersonationLevel) {
131 authid.User=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(username.c_str()));
132 authid.UserLength=username.size();
133 authid.Domain=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(domain.c_str()));
134 authid.DomainLength=domain.size();
135 authid.Password=
reinterpret_cast<USHORT *>(
const_cast<TCHAR *>(password.c_str()));
136 authid.PasswordLength=password.size();
139 SEC_WINNT_AUTH_IDENTITY_UNICODE;
141 SEC_WINNT_AUTH_IDENTITY_ANSI;
143 authinfo.dwAuthnSvc=RPC_C_AUTHN_WINNT;
144 authinfo.dwAuthzSvc=RPC_C_AUTHZ_NONE;
145 authinfo.pwszServerPrincName=NULL;
146 authinfo.dwAuthnLevel=AuthnLevel;
147 authinfo.dwImpersonationLevel=ImpersonationLevel;
148 authinfo.pAuthIdentityData=&authid;
149 authinfo.dwCapabilities=EOAC_NONE;
150 serverinfo.dwReserved1=serverinfo.dwReserved2=0;
151 serverinfo.pwszName=
const_cast<
wchar_t *>(unc.c_str());
152 serverinfo.pAuthInfo=&authinfo;
165 const HRESULT hr=::CoInitializeSecurity(NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_NONE,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,NULL);
166 JMMCG_TRACE(_T(
"InitCOMSecurity::InitCOMSecurity(): ::CoInitializeSecurity(..) return code: ")<<win_exception::StrFromWinErr(hr));
173 const HRESULT hr=::CoInitializeSecurity(&sd->SD(),-1,NULL,NULL,RPC_C_AUTHN_LEVEL_CONNECT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_SECURE_REFS,NULL);
174 JMMCG_TRACE(_T(
"InitCOMSecurity::InitCOMSecurity(): ::CoInitializeSecurity(..) return code: ")<<win_exception::StrFromWinErr(hr));
181 const std::auto_ptr<SecuritySettings> sd;
184 inline __stdcall InitCOMSecurity(
const InitCOMSecurity &)
noexcept(
true);