cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

credentials.h (10404B)


      1/**
      2 * WinPR: Windows Portable Runtime
      3 * Credentials Management
      4 *
      5 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
      6 *
      7 * Licensed under the Apache License, Version 2.0 (the "License");
      8 * you may not use this file except in compliance with the License.
      9 * You may obtain a copy of the License at
     10 *
     11 *     http://www.apache.org/licenses/LICENSE-2.0
     12 *
     13 * Unless required by applicable law or agreed to in writing, software
     14 * distributed under the License is distributed on an "AS IS" BASIS,
     15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 * See the License for the specific language governing permissions and
     17 * limitations under the License.
     18 */
     19
     20#ifndef WINPR_CREDENTIALS_H
     21#define WINPR_CREDENTIALS_H
     22
     23#include <winpr/winpr.h>
     24#include <winpr/wtypes.h>
     25
     26#ifndef _WIN32
     27
     28#define CRED_SESSION_WILDCARD_NAME_W L"*Session"
     29#define CRED_SESSION_WILDCARD_NAME_A "*Session"
     30#define CRED_SESSION_WILDCARD_NAME_LENGTH (sizeof(CRED_SESSION_WILDCARD_NAME_A) - 1)
     31
     32#define CRED_MAX_STRING_LENGTH 256
     33#define CRED_MAX_USERNAME_LENGTH (256 + 1 + 256)
     34#define CRED_MAX_GENERIC_TARGET_NAME_LENGTH 32767
     35#define CRED_MAX_DOMAIN_TARGET_NAME_LENGTH (256 + 1 + 80)
     36#define CRED_MAX_VALUE_SIZE 256
     37#define CRED_MAX_ATTRIBUTES 64
     38
     39#define CRED_FLAGS_PASSWORD_FOR_CERT 0x0001
     40#define CRED_FLAGS_PROMPT_NOW 0x0002
     41#define CRED_FLAGS_USERNAME_TARGET 0x0004
     42#define CRED_FLAGS_OWF_CRED_BLOB 0x0008
     43#define CRED_FLAGS_VALID_FLAGS 0x000F
     44
     45#define CRED_TYPE_GENERIC 1
     46#define CRED_TYPE_DOMAIN_PASSWORD 2
     47#define CRED_TYPE_DOMAIN_CERTIFICATE 3
     48#define CRED_TYPE_DOMAIN_VISIBLE_PASSWORD 4
     49#define CRED_TYPE_MAXIMUM 5
     50#define CRED_TYPE_MAXIMUM_EX (CRED_TYPE_MAXIMUM + 1000)
     51
     52#define CRED_MAX_CREDENTIAL_BLOB_SIZE 512
     53
     54#define CRED_PERSIST_NONE 0
     55#define CRED_PERSIST_SESSION 1
     56#define CRED_PERSIST_LOCAL_MACHINE 2
     57#define CRED_PERSIST_ENTERPRISE 3
     58
     59#define CRED_PRESERVE_CREDENTIAL_BLOB 0x1
     60#define CRED_CACHE_TARGET_INFORMATION 0x1
     61#define CRED_ALLOW_NAME_RESOLUTION 0x1
     62
     63typedef struct _CREDENTIAL_ATTRIBUTEA
     64{
     65	LPSTR Keyword;
     66	DWORD Flags;
     67	DWORD ValueSize;
     68	LPBYTE Value;
     69} CREDENTIAL_ATTRIBUTEA, *PCREDENTIAL_ATTRIBUTEA;
     70
     71typedef struct _CREDENTIAL_ATTRIBUTEW
     72{
     73	LPWSTR Keyword;
     74	DWORD Flags;
     75	DWORD ValueSize;
     76	LPBYTE Value;
     77} CREDENTIAL_ATTRIBUTEW, *PCREDENTIAL_ATTRIBUTEW;
     78
     79typedef struct _CREDENTIALA
     80{
     81	DWORD Flags;
     82	DWORD Type;
     83	LPSTR TargetName;
     84	LPSTR Comment;
     85	FILETIME LastWritten;
     86	DWORD CredentialBlobSize;
     87	LPBYTE CredentialBlob;
     88	DWORD Persist;
     89	DWORD AttributeCount;
     90	PCREDENTIAL_ATTRIBUTEA Attributes;
     91	LPSTR TargetAlias;
     92	LPSTR UserName;
     93} CREDENTIALA, *PCREDENTIALA;
     94
     95typedef struct _CREDENTIALW
     96{
     97	DWORD Flags;
     98	DWORD Type;
     99	LPWSTR TargetName;
    100	LPWSTR Comment;
    101	FILETIME LastWritten;
    102	DWORD CredentialBlobSize;
    103	LPBYTE CredentialBlob;
    104	DWORD Persist;
    105	DWORD AttributeCount;
    106	PCREDENTIAL_ATTRIBUTEW Attributes;
    107	LPWSTR TargetAlias;
    108	LPWSTR UserName;
    109} CREDENTIALW, *PCREDENTIALW;
    110
    111typedef struct _CREDENTIAL_TARGET_INFORMATIONA
    112{
    113	LPSTR TargetName;
    114	LPSTR NetbiosServerName;
    115	LPSTR DnsServerName;
    116	LPSTR NetbiosDomainName;
    117	LPSTR DnsDomainName;
    118	LPSTR DnsTreeName;
    119	LPSTR PackageName;
    120	ULONG Flags;
    121	DWORD CredTypeCount;
    122	LPDWORD CredTypes;
    123} CREDENTIAL_TARGET_INFORMATIONA, *PCREDENTIAL_TARGET_INFORMATIONA;
    124
    125typedef struct _CREDENTIAL_TARGET_INFORMATIONW
    126{
    127	LPWSTR TargetName;
    128	LPWSTR NetbiosServerName;
    129	LPWSTR DnsServerName;
    130	LPWSTR NetbiosDomainName;
    131	LPWSTR DnsDomainName;
    132	LPWSTR DnsTreeName;
    133	LPWSTR PackageName;
    134	ULONG Flags;
    135	DWORD CredTypeCount;
    136	LPDWORD CredTypes;
    137} CREDENTIAL_TARGET_INFORMATIONW, *PCREDENTIAL_TARGET_INFORMATIONW;
    138
    139typedef enum _CRED_MARSHAL_TYPE
    140{
    141	CertCredential = 1,
    142	UsernameTargetCredential
    143} CRED_MARSHAL_TYPE,
    144    *PCRED_MARSHAL_TYPE;
    145
    146typedef enum _CRED_PROTECTION_TYPE
    147{
    148	CredUnprotected = 0,
    149	CredUserProtection = 1,
    150	CredTrustedProtection = 2
    151} CRED_PROTECTION_TYPE,
    152    *PCRED_PROTECTION_TYPE;
    153
    154#ifdef UNICODE
    155#define CRED_SESSION_WILDCARD_NAME CRED_SESSION_WILDCARD_NAME_W
    156#define CREDENTIAL_ATTRIBUTE CREDENTIAL_ATTRIBUTEW
    157#define PCREDENTIAL_ATTRIBUTE PCREDENTIAL_ATTRIBUTEW
    158#define CREDENTIAL CREDENTIALW
    159#define PCREDENTIAL PCREDENTIALW
    160#define CREDENTIAL_TARGET_INFORMATION CREDENTIAL_TARGET_INFORMATIONW
    161#define PCREDENTIAL_TARGET_INFORMATION PCREDENTIAL_TARGET_INFORMATIONW
    162#else
    163#define CRED_SESSION_WILDCARD_NAME CRED_SESSION_WILDCARD_NAME_A
    164#define CREDENTIAL_ATTRIBUTE CREDENTIAL_ATTRIBUTEA
    165#define PCREDENTIAL_ATTRIBUTE PCREDENTIAL_ATTRIBUTEA
    166#define CREDENTIAL CREDENTIALA
    167#define PCREDENTIAL PCREDENTIALA
    168#define CREDENTIAL_TARGET_INFORMATION CREDENTIAL_TARGET_INFORMATIONA
    169#define PCREDENTIAL_TARGET_INFORMATION PCREDENTIAL_TARGET_INFORMATIONA
    170#endif
    171
    172#ifdef __cplusplus
    173extern "C"
    174{
    175#endif
    176
    177	WINPR_API BOOL CredWriteW(PCREDENTIALW Credential, DWORD Flags);
    178	WINPR_API BOOL CredWriteA(PCREDENTIALA Credential, DWORD Flags);
    179
    180	WINPR_API BOOL CredReadW(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW* Credential);
    181	WINPR_API BOOL CredReadA(LPCSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALA* Credential);
    182
    183	WINPR_API BOOL CredEnumerateW(LPCWSTR Filter, DWORD Flags, DWORD* Count,
    184	                              PCREDENTIALW** Credential);
    185	WINPR_API BOOL CredEnumerateA(LPCSTR Filter, DWORD Flags, DWORD* Count,
    186	                              PCREDENTIALA** Credential);
    187
    188	WINPR_API BOOL CredWriteDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
    189	                                           PCREDENTIALW Credential, DWORD Flags);
    190	WINPR_API BOOL CredWriteDomainCredentialsA(PCREDENTIAL_TARGET_INFORMATIONA TargetInfo,
    191	                                           PCREDENTIALA Credential, DWORD Flags);
    192
    193	WINPR_API BOOL CredReadDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,
    194	                                          DWORD Flags, DWORD* Count, PCREDENTIALW** Credential);
    195	WINPR_API BOOL CredReadDomainCredentialsA(PCREDENTIAL_TARGET_INFORMATIONA TargetInfo,
    196	                                          DWORD Flags, DWORD* Count, PCREDENTIALA** Credential);
    197
    198	WINPR_API BOOL CredDeleteW(LPCWSTR TargetName, DWORD Type, DWORD Flags);
    199	WINPR_API BOOL CredDeleteA(LPCSTR TargetName, DWORD Type, DWORD Flags);
    200
    201	WINPR_API BOOL CredRenameW(LPCWSTR OldTargetName, LPCWSTR NewTargetName, DWORD Type,
    202	                           DWORD Flags);
    203	WINPR_API BOOL CredRenameA(LPCSTR OldTargetName, LPCSTR NewTargetName, DWORD Type, DWORD Flags);
    204
    205	WINPR_API BOOL CredGetTargetInfoW(LPCWSTR TargetName, DWORD Flags,
    206	                                  PCREDENTIAL_TARGET_INFORMATIONW* TargetInfo);
    207	WINPR_API BOOL CredGetTargetInfoA(LPCSTR TargetName, DWORD Flags,
    208	                                  PCREDENTIAL_TARGET_INFORMATIONA* TargetInfo);
    209
    210	WINPR_API BOOL CredMarshalCredentialW(CRED_MARSHAL_TYPE CredType, PVOID Credential,
    211	                                      LPWSTR* MarshaledCredential);
    212	WINPR_API BOOL CredMarshalCredentialA(CRED_MARSHAL_TYPE CredType, PVOID Credential,
    213	                                      LPSTR* MarshaledCredential);
    214
    215	WINPR_API BOOL CredUnmarshalCredentialW(LPCWSTR MarshaledCredential,
    216	                                        PCRED_MARSHAL_TYPE CredType, PVOID* Credential);
    217	WINPR_API BOOL CredUnmarshalCredentialA(LPCSTR MarshaledCredential, PCRED_MARSHAL_TYPE CredType,
    218	                                        PVOID* Credential);
    219
    220	WINPR_API BOOL CredIsMarshaledCredentialW(LPCWSTR MarshaledCredential);
    221	WINPR_API BOOL CredIsMarshaledCredentialA(LPCSTR MarshaledCredential);
    222
    223	WINPR_API BOOL CredProtectW(BOOL fAsSelf, LPWSTR pszCredentials, DWORD cchCredentials,
    224	                            LPWSTR pszProtectedCredentials, DWORD* pcchMaxChars,
    225	                            CRED_PROTECTION_TYPE* ProtectionType);
    226	WINPR_API BOOL CredProtectA(BOOL fAsSelf, LPSTR pszCredentials, DWORD cchCredentials,
    227	                            LPSTR pszProtectedCredentials, DWORD* pcchMaxChars,
    228	                            CRED_PROTECTION_TYPE* ProtectionType);
    229
    230	WINPR_API BOOL CredUnprotectW(BOOL fAsSelf, LPWSTR pszProtectedCredentials,
    231	                              DWORD cchCredentials, LPWSTR pszCredentials, DWORD* pcchMaxChars);
    232	WINPR_API BOOL CredUnprotectA(BOOL fAsSelf, LPSTR pszProtectedCredentials, DWORD cchCredentials,
    233	                              LPSTR pszCredentials, DWORD* pcchMaxChars);
    234
    235	WINPR_API BOOL CredIsProtectedW(LPWSTR pszProtectedCredentials,
    236	                                CRED_PROTECTION_TYPE* pProtectionType);
    237	WINPR_API BOOL CredIsProtectedA(LPSTR pszProtectedCredentials,
    238	                                CRED_PROTECTION_TYPE* pProtectionType);
    239
    240	WINPR_API BOOL CredFindBestCredentialW(LPCWSTR TargetName, DWORD Type, DWORD Flags,
    241	                                       PCREDENTIALW* Credential);
    242	WINPR_API BOOL CredFindBestCredentialA(LPCSTR TargetName, DWORD Type, DWORD Flags,
    243	                                       PCREDENTIALA* Credential);
    244
    245	WINPR_API BOOL CredGetSessionTypes(DWORD MaximumPersistCount, LPDWORD MaximumPersist);
    246
    247	WINPR_API VOID CredFree(PVOID Buffer);
    248
    249#ifdef __cplusplus
    250}
    251#endif
    252
    253#ifdef UNICODE
    254#define CredWrite CredWriteW
    255#define CredRead CredReadW
    256#define CredEnumerate CredEnumerateW
    257#define CredWriteDomainCredentials CredWriteDomainCredentialsW
    258#define CredReadDomainCredentials CredReadDomainCredentialsW
    259#define CredDelete CredDeleteW
    260#define CredRename CredRenameW
    261#define CredGetTargetInfo CredGetTargetInfoW
    262#define CredMarshalCredential CredMarshalCredentialW
    263#define CredUnmarshalCredential CredUnmarshalCredentialW
    264#define CredIsMarshaledCredential CredIsMarshaledCredentialW
    265#define CredProtect CredProtectW
    266#define CredUnprotect CredUnprotectW
    267#define CredIsProtected CredIsProtectedW
    268#define CredFindBestCredential CredFindBestCredentialW
    269#else
    270#define CredWrite CredWriteA
    271#define CredRead CredReadA
    272#define CredEnumerate CredEnumerateA
    273#define CredWriteDomainCredentials CredWriteDomainCredentialsA
    274#define CredReadDomainCredentials CredReadDomainCredentialsA
    275#define CredDelete CredDeleteA
    276#define CredRename CredRenameA
    277#define CredGetTargetInfo CredGetTargetInfoA
    278#define CredMarshalCredential CredMarshalCredentialA
    279#define CredUnmarshalCredential CredUnmarshalCredentialA
    280#define CredIsMarshaledCredential CredIsMarshaledCredentialA
    281#define CredProtect CredProtectA
    282#define CredUnprotect CredUnprotectA
    283#define CredIsProtected CredIsProtectedA
    284#define CredFindBestCredential CredFindBestCredentialA
    285#endif
    286
    287#endif
    288
    289#endif /* WINPR_CREDENTIALS_H */