Skip to content

Commit 5e54e0a

Browse files
authored
Merge pull request FreeRDP#11734 from hardening/credentials
winpr: re-introduce the credentials module
2 parents 9713a99 + 4f909a3 commit 5e54e0a

File tree

7 files changed

+545
-3
lines changed

7 files changed

+545
-3
lines changed

winpr/include/winpr/cred.h

Lines changed: 104 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222
#include <winpr/winpr.h>
2323

2424
#ifdef _WIN32
25+
#include <windows.h>
2526
#include <wincred.h>
2627
#else
2728

29+
#include <winpr/wtypes.h>
30+
2831
#define CERT_HASH_LENGTH 20
2932

3033
typedef enum
3134
{
32-
CertCredential,
35+
CertCredential = 1,
3336
UsernameTargetCredential,
3437
BinaryBlobCredential,
3538
UsernameForPackedCredentials,
@@ -43,7 +46,91 @@ typedef struct
4346
UCHAR rgbHashOfCert[CERT_HASH_LENGTH];
4447
} CERT_CREDENTIAL_INFO, *PCERT_CREDENTIAL_INFO;
4548

46-
#if 0 /* shall we implement these ? */
49+
typedef struct
50+
{
51+
LPSTR Keyword;
52+
DWORD Flags;
53+
DWORD ValueSize;
54+
LPBYTE Value;
55+
} CREDENTIAL_ATTRIBUTEA, *PCREDENTIAL_ATTRIBUTEA;
56+
57+
typedef struct
58+
{
59+
LPWSTR Keyword;
60+
DWORD Flags;
61+
DWORD ValueSize;
62+
LPBYTE Value;
63+
} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;
64+
65+
typedef struct
66+
{
67+
DWORD Flags;
68+
DWORD Type;
69+
LPSTR TargetName;
70+
LPSTR Comment;
71+
FILETIME LastWritten;
72+
DWORD CredentialBlobSize;
73+
LPBYTE CredentialBlob;
74+
DWORD Persist;
75+
DWORD AttributeCount;
76+
PCREDENTIAL_ATTRIBUTEA Attributes;
77+
LPSTR TargetAlias;
78+
LPSTR UserName;
79+
} CREDENTIALA, *PCREDENTIALA;
80+
81+
typedef struct
82+
{
83+
DWORD Flags;
84+
DWORD Type;
85+
LPWSTR TargetName;
86+
LPWSTR Comment;
87+
FILETIME LastWritten;
88+
DWORD CredentialBlobSize;
89+
LPBYTE CredentialBlob;
90+
DWORD Persist;
91+
DWORD AttributeCount;
92+
PCREDENTIAL_ATTRIBUTEA Attributes;
93+
LPWSTR TargetAlias;
94+
LPWSTR UserName;
95+
} CREDENTIALW, *PCREDENTIALW;
96+
97+
typedef struct
98+
{
99+
LPSTR TargetName;
100+
LPSTR NetbiosServerName;
101+
LPSTR DnsServerName;
102+
LPSTR NetbiosDomainName;
103+
LPSTR DnsDomainName;
104+
LPSTR DnsTreeName;
105+
LPSTR PackageName;
106+
ULONG Flags;
107+
DWORD CredTypeCount;
108+
LPDWORD CredTypes;
109+
} CREDENTIAL_TARGET_INFORMATIONA, *PCREDENTIAL_TARGET_INFORMATIONA;
110+
111+
typedef struct
112+
{
113+
LPWSTR TargetName;
114+
LPWSTR NetbiosServerName;
115+
LPWSTR DnsServerName;
116+
LPWSTR NetbiosDomainName;
117+
LPWSTR DnsDomainName;
118+
LPWSTR DnsTreeName;
119+
LPWSTR PackageName;
120+
ULONG Flags;
121+
DWORD CredTypeCount;
122+
LPDWORD CredTypes;
123+
} CREDENTIAL_TARGET_INFORMATIONW, *PCREDENTIAL_TARGET_INFORMATIONW;
124+
125+
typedef enum
126+
{
127+
CredUnprotected,
128+
CredUserProtection,
129+
CredTrustedProtection,
130+
CredForSystemProtection
131+
} CRED_PROTECTION_TYPE,
132+
*PCRED_PROTECTION_TYPE;
133+
47134
WINPR_API BOOL CredMarshalCredentialA(CRED_MARSHAL_TYPE CredType, PVOID Credential,
48135
LPSTR* MarshaledCredential);
49136
WINPR_API BOOL CredMarshalCredentialW(CRED_MARSHAL_TYPE CredType, PVOID Credential,
@@ -55,7 +142,21 @@ WINPR_API BOOL CredMarshalCredentialW(CRED_MARSHAL_TYPE CredType, PVOID Credenti
55142
#define CredMarshalCredential CredMarshalCredentialA
56143
#endif
57144

58-
#endif /* 0 */
145+
WINPR_API BOOL CredUnmarshalCredentialW(LPCWSTR cred, PCRED_MARSHAL_TYPE CredType,
146+
PVOID* Credential);
147+
148+
WINPR_API BOOL CredUnmarshalCredentialA(LPCSTR cred, PCRED_MARSHAL_TYPE CredType,
149+
PVOID* Credential);
150+
151+
#ifdef UNICODE
152+
#define CredUnmarshalCredential CredUnmarshalCredentialW
153+
#else
154+
#define CredUnmarshalCredential CredUnmarshalCredentialA
155+
#endif
156+
157+
WINPR_API BOOL CredIsMarshaledCredentialA(LPCSTR MarshaledCredential);
158+
WINPR_API BOOL CredIsMarshaledCredentialW(LPCWSTR MarshaledCredential);
159+
WINPR_API VOID CredFree(PVOID Buffer);
59160

60161
#endif /* _WIN32 */
61162

winpr/libwinpr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ set(WINPR_CORE
165165
library
166166
file
167167
comm
168+
credentials
168169
pipe
169170
interlocked
170171
security
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# WinPR: Windows Portable Runtime
2+
# libwinpr-credentials cmake build script
3+
#
4+
# Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
winpr_module_add(credentials.c)
19+
20+
if(BUILD_TESTING_INTERNAL OR BUILD_TESTING)
21+
add_subdirectory(test)
22+
endif()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(MINWIN_LAYER "1")
2+
set(MINWIN_GROUP "security")
3+
set(MINWIN_MAJOR_VERSION "1")
4+
set(MINWIN_MINOR_VERSION "0")
5+
set(MINWIN_SHORT_NAME "credentials")
6+
set(MINWIN_LONG_NAME "Credentials Management Functions")
7+
set(MODULE_LIBRARY_NAME
8+
"api-ms-win-${MINWIN_GROUP}-${MINWIN_SHORT_NAME}-l${MINWIN_LAYER}-${MINWIN_MAJOR_VERSION}-${MINWIN_MINOR_VERSION}"
9+
)

0 commit comments

Comments
 (0)