18#if defined(SECURITY_WIN32) || defined(SECURITY_KERNEL)
21template<
class _Traits,
class _Ax>
22static BOOLEAN GetUserNameExA(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<char, _Traits, _Ax> &sName)
27 ULONG ulSize = _countof(szStackBuffer);
30 if (::GetUserNameExA(NameFormat, szStackBuffer, &ulSize)) {
32 sName.assign(szStackBuffer, ulSize);
35 if (::GetLastError() == ERROR_MORE_DATA) {
37 sName.resize(ulSize - 1);
38 if (::GetUserNameExA(NameFormat, &ulSize[0], &ulSize))
49template<
class _Traits,
class _Ax>
50static BOOLEAN GetUserNameExW(_In_ EXTENDED_NAME_FORMAT NameFormat, _Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sName)
55 ULONG ulSize = _countof(szStackBuffer);
58 if (::GetUserNameExW(NameFormat, szStackBuffer, &ulSize)) {
60 sName.assign(szStackBuffer, ulSize);
63 if (::GetLastError() == ERROR_MORE_DATA) {
65 sName.resize(ulSize - 1);
66 if (::GetUserNameExW(NameFormat, &sName[0], &ulSize))
136 if (
this != std::addressof(
h)) {
233 if (
this != std::addressof(
h)) {
263 SECURITY_STATUS res =
InitializeSecurityContext(
phCredential,
NULL,
const_cast<LPTSTR>(
pszTargetName),
fContextReq, 0,
TargetDataRep,
pInput, 0,
h,
pOutput, &
attr, &
exp);
290 return InitializeSecurityContext(
phCredential,
m_h,
const_cast<LPTSTR>(
pszTargetName),
fContextReq, 0,
TargetDataRep,
pInput, 0,
NULL,
pOutput, &
m_attrib, &
m_expires);
Base abstract template class to support generic object handle keeping.
Definition Common.h:1024
handle_type m_h
Object handle.
Definition Common.h:1276
void attach(handle_type h) noexcept
Sets a new object handle for the class.
Definition Common.h:1239
Numerical runtime error.
Definition Common.h:1481
Helper class for returning pointers to std::unique_ptr.
Definition Common.h:863
SecBufferDesc wrapper class.
Definition Sec.h:314
virtual ~sec_buffer_desc()
Frees the security buffer descriptor.
Definition Sec.h:331
sec_buffer_desc(PSecBuffer buf, ULONG count, ULONG version=SECBUFFER_VERSION)
Initializes security buffer descriptor.
Definition Sec.h:319
PCtxtHandle wrapper class.
Definition Sec.h:192
sec_context(sec_context &&h) noexcept
Move constructor.
Definition Sec.h:209
SECURITY_STATUS process(PCredHandle phCredential, LPCTSTR pszTargetName, ULONG fContextReq, ULONG TargetDataRep, PSecBufferDesc pInput, PSecBufferDesc pOutput)
Continue security context.
Definition Sec.h:282
virtual ~sec_context()
Frees the security context.
Definition Sec.h:220
sec_context()
Initializes a new class instance with the object handle set to NULL.
Definition Sec.h:197
SECURITY_STATUS initialize(PCredHandle phCredential, LPCTSTR pszTargetName, ULONG fContextReq, ULONG TargetDataRep, PSecBufferDesc pInput, PSecBufferDesc pOutput)
Initializes security context.
Definition Sec.h:250
ULONG m_attrib
Context attributes.
Definition Sec.h:306
TimeStamp m_expires
Context expiration time.
Definition Sec.h:307
sec_context & operator=(sec_context &&h) noexcept
Move assignment.
Definition Sec.h:231
void free_internal() noexcept override
Frees the security context.
Definition Sec.h:299
PCredHandle wrapper class.
Definition Sec.h:85
sec_credentials()
Initializes a new class instance with the object handle set to NULL.
Definition Sec.h:92
void free_internal() noexcept override
Frees the security credentials.
Definition Sec.h:178
TimeStamp m_expires
Credentials expiration time.
Definition Sec.h:185
sec_credentials(sec_credentials &&h) noexcept
Move constructor.
Definition Sec.h:113
virtual ~sec_credentials()
Frees the security credentials.
Definition Sec.h:123
sec_credentials(handle_type h, const TimeStamp expires)
Initializes a new class with an already available object handle.
Definition Sec.h:103
SECURITY_STATUS acquire(LPTSTR pszPrincipal, LPTSTR pszPackage, unsigned long fCredentialUse, void *pvLogonId, void *pAuthData, SEC_GET_KEY_FN pGetKeyFn=NULL, void *pvGetKeyArgument=NULL)
Acquires the security credentials.
Definition Sec.h:152
sec_credentials & operator=(sec_credentials &&h) noexcept
Move assignment.
Definition Sec.h:134
Security runtime error.
Definition Sec.h:351
sec_runtime_error(error_type num, const char *msg=nullptr)
Constructs an exception.
Definition Sec.h:368
sec_runtime_error(const sec_runtime_error &other)
Copies an exception.
Definition Sec.h:376
sec_runtime_error(error_type num, const std::string &msg)
Constructs an exception.
Definition Sec.h:359
#define WINSTD_NONCOPYABLE(C)
Declares a class as non-copyable.
Definition Common.h:67
#define WINSTD_STACK_BUFFER_BYTES
Size of the stack buffer in bytes used for initial system function call.
Definition Common.h:94
static const PCredHandle invalid
Invalid handle value.
Definition Common.h:1034