-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathhelpers.h
131 lines (107 loc) · 4.11 KB
/
helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Helper functions for copying parameters and packaging the buffer
// for GetSerialization.
#pragma once
#pragma warning(push)
#pragma warning(disable: 28251)
#include <credentialprovider.h>
#include <ntsecapi.h>
#pragma warning(pop)
#define SECURITY_WIN32
#include <security.h>
#include <intsafe.h>
#include <windows.h>
#include <strsafe.h>
#pragma warning(push)
#pragma warning(disable: 4995)
#include <shlwapi.h>
#pragma warning(pop)
#pragma warning(push)
#pragma warning(disable: 28301)
#include <wincred.h>
#pragma warning(pop)
#define LOGFILE_NAME "C:\\multiotplog.txt"
#define MAX_TIME_SIZE 250
#define ZERO(NAME) \
ZeroMemory(NAME, sizeof(NAME))
#define INIT_ZERO_WCHAR(NAME, SIZE) \
wchar_t NAME[SIZE]; \
ZERO(NAME)
#define INIT_ZERO_CHAR(NAME, SIZE) \
char NAME[SIZE]; \
ZERO(NAME)
#define DEVELOPING FALSE //display a lot of debug info
#define SKIP_OTP_CHECK FALSE //do not bother with wrong OTP PIN
void PrintLn(const wchar_t *message, const wchar_t *message2, const wchar_t *message3, const wchar_t *message4);
void PrintLn(const wchar_t *message, const wchar_t *message2, const wchar_t *message3);
void PrintLn(const wchar_t *message, const wchar_t *message2);
void PrintLn(const wchar_t *message);
void PrintLn(const char* message);
void PrintLn(const char* message, int line);
void PrintLn(const wchar_t *message, int line);
void PrintLn(int line);
void GetCurrentTimeAndDate(char(&time)[MAX_TIME_SIZE]);
void WriteLogFile(const wchar_t* szString);
void WriteLogFile(const char* szString);
//makes a copy of a field descriptor using CoTaskMemAlloc
HRESULT FieldDescriptorCoAllocCopy(
_In_ const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR &rcpfd,
_Outptr_result_nullonfailure_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR **ppcpfd
);
//makes a copy of a field descriptor on the normal heap
HRESULT FieldDescriptorCopy(
_In_ const CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR &rcpfd,
_Out_ CREDENTIAL_PROVIDER_FIELD_DESCRIPTOR *pcpfd
);
//creates a UNICODE_STRING from a NULL-terminated string
HRESULT UnicodeStringInitWithString(
_In_ PWSTR pwz,
_Out_ UNICODE_STRING *pus
);
//initializes a KERB_INTERACTIVE_UNLOCK_LOGON with weak references to the provided credentials
HRESULT KerbInteractiveUnlockLogonInit(
_In_ PWSTR pwzDomain,
_In_ PWSTR pwzUsername,
_In_ PWSTR pwzPassword,
_In_ CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
_Out_ KERB_INTERACTIVE_UNLOCK_LOGON *pkiul
);
//packages the credentials into the buffer that the system expects
HRESULT KerbInteractiveUnlockLogonPack(
_In_ const KERB_INTERACTIVE_UNLOCK_LOGON &rkiulIn,
_Outptr_result_bytebuffer_(*pcb) BYTE **prgb,
_Out_ DWORD *pcb
);
//get the authentication package that will be used for our logon attempt
HRESULT RetrieveNegotiateAuthPackage(
_Out_ ULONG *pulAuthPackage
);
//encrypt a password (if necessary) and copy it; if not, just copy it
HRESULT ProtectIfNecessaryAndCopyPassword(
_In_ PCWSTR pwzPassword,
_In_ CREDENTIAL_PROVIDER_USAGE_SCENARIO cpus,
_Outptr_result_nullonfailure_ PWSTR *ppwzProtectedPassword
);
HRESULT KerbInteractiveUnlockLogonRepackNative(
_In_reads_bytes_(cbWow) BYTE *rgbWow,
_In_ DWORD cbWow,
_Outptr_result_bytebuffer_(*pcbNative) BYTE **prgbNative,
_Out_ DWORD *pcbNative
);
void KerbInteractiveUnlockLogonUnpackInPlace(
_Inout_updates_bytes_(cb) KERB_INTERACTIVE_UNLOCK_LOGON *pkiul,
DWORD cb
);
HRESULT DomainUsernameStringAlloc(
_In_ PCWSTR pwszDomain,
_In_ PCWSTR pwszUsername,
_Outptr_result_nullonfailure_ PWSTR *ppwszDomainUsername
);
HRESULT SplitDomainAndUsername(_In_ PCWSTR pszQualifiedUserName, _Outptr_result_nullonfailure_ PWSTR *ppszDomain, _Outptr_result_nullonfailure_ PWSTR *ppszUsername);