[ADVAPI32] Sync cred.c with Wine Staging 3.3. CORE-14434

This commit is contained in:
Amine Khaldi 2018-04-01 13:16:11 +01:00
parent 10517de5e6
commit abc90fa5a6
2 changed files with 74 additions and 14 deletions

View file

@ -18,9 +18,34 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifdef __REACTOS__
#include <advapi32.h>
#include <wincred.h>
#else
#include <stdarg.h>
#include <time.h>
#include <limits.h>
#ifdef __APPLE__
# include <Security/SecKeychain.h>
# include <Security/SecKeychainItem.h>
# include <Security/SecKeychainSearch.h>
#endif
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "wincred.h"
#include "winternl.h"
#include "crypt.h"
#include "wine/unicode.h"
#include "wine/debug.h"
#include "advapi32_misc.h"
#endif /* __REACTOS__ */
WINE_DEFAULT_DEBUG_CHANNEL(cred);
@ -94,14 +119,19 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
credential->TargetName = (LPWSTR)buffer;
ret = RegQueryValueExW(hkey, NULL, 0, &type, (LPVOID)credential->TargetName,
&count);
#ifdef __REACTOS__
if (ret != ERROR_SUCCESS)
return ret;
else if (type != REG_SZ)
return ERROR_REGISTRY_CORRUPT;
#else
if (ret != ERROR_SUCCESS || type != REG_SZ) return ret;
#endif
buffer += count;
}
ret = RegQueryValueExW(hkey, wszCommentValue, 0, &type, NULL, &count);
#ifdef __REACTOS__
if (ret != ERROR_FILE_NOT_FOUND)
{
if (ret != ERROR_SUCCESS)
@ -110,6 +140,13 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
return ERROR_REGISTRY_CORRUPT;
*len += count;
}
#else
if (ret != ERROR_FILE_NOT_FOUND && ret != ERROR_SUCCESS)
return ret;
else if (type != REG_SZ)
return ERROR_REGISTRY_CORRUPT;
*len += count;
#endif
if (credential)
{
credential->Comment = (LPWSTR)buffer;
@ -126,6 +163,7 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
}
ret = RegQueryValueExW(hkey, wszTargetAliasValue, 0, &type, NULL, &count);
#ifdef __REACTOS__
if (ret != ERROR_FILE_NOT_FOUND)
{
if (ret != ERROR_SUCCESS)
@ -134,6 +172,13 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
return ERROR_REGISTRY_CORRUPT;
*len += count;
}
#else
if (ret != ERROR_FILE_NOT_FOUND && ret != ERROR_SUCCESS)
return ret;
else if (type != REG_SZ)
return ERROR_REGISTRY_CORRUPT;
*len += count;
#endif
if (credential)
{
credential->TargetAlias = (LPWSTR)buffer;
@ -150,6 +195,7 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
}
ret = RegQueryValueExW(hkey, wszUserNameValue, 0, &type, NULL, &count);
#ifdef __REACTOS__
if (ret != ERROR_FILE_NOT_FOUND)
{
if (ret != ERROR_SUCCESS)
@ -158,6 +204,13 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
return ERROR_REGISTRY_CORRUPT;
*len += count;
}
#else
if (ret != ERROR_FILE_NOT_FOUND && ret != ERROR_SUCCESS)
return ret;
else if (type != REG_SZ)
return ERROR_REGISTRY_CORRUPT;
*len += count;
#endif
if (credential)
{
credential->UserName = (LPWSTR)buffer;
@ -174,12 +227,18 @@ static DWORD registry_read_credential(HKEY hkey, PCREDENTIALW credential,
}
ret = read_credential_blob(hkey, key_data, NULL, &count);
#ifdef __REACTOS__
if (ret != ERROR_FILE_NOT_FOUND)
{
if (ret != ERROR_SUCCESS)
return ret;
*len += count;
}
#else
if (ret != ERROR_FILE_NOT_FOUND && ret != ERROR_SUCCESS)
return ret;
*len += count;
#endif
if (credential)
{
credential->CredentialBlob = (LPBYTE)buffer;
@ -235,7 +294,7 @@ static DWORD mac_read_credential_from_item(SecKeychainItemRef item, BOOL require
PCREDENTIALW credential, char *buffer,
DWORD *len)
{
OSStatus status;
int status;
UInt32 i, cred_blob_len;
void *cred_blob;
WCHAR *user = NULL;
@ -256,7 +315,7 @@ static DWORD mac_read_credential_from_item(SecKeychainItemRef item, BOOL require
}
if (status != noErr)
{
WARN("SecKeychainItemCopyAttributesAndData returned status %ld\n", status);
WARN("SecKeychainItemCopyAttributesAndData returned status %d\n", status);
return ERROR_NOT_FOUND;
}
@ -353,6 +412,7 @@ static DWORD mac_read_credential_from_item(SecKeychainItemRef item, BOOL require
case kSecCreationDateItemAttr:
TRACE("kSecCreationDateItemAttr: %.*s\n", (int)attr_list->attr[i].length,
(char *)attr_list->attr[i].data);
if (!attr_list->attr[i].data) continue;
if (buffer)
{
LARGE_INTEGER win_time;
@ -367,7 +427,7 @@ static DWORD mac_read_credential_from_item(SecKeychainItemRef item, BOOL require
}
break;
default:
FIXME("unhandled attribute %lu\n", attr_list->attr[i].tag);
FIXME("unhandled attribute %u\n", (unsigned)attr_list->attr[i].tag);
break;
}
}
@ -492,7 +552,7 @@ static DWORD registry_write_credential(HKEY hkey, const CREDENTIALW *credential,
#ifdef __APPLE__
static DWORD mac_write_credential(const CREDENTIALW *credential, BOOL preserve_blob)
{
OSStatus status;
int status;
SecKeychainItemRef keychain_item;
char *username, *password, *servername;
UInt32 userlen, pwlen, serverlen;
@ -525,13 +585,13 @@ static DWORD mac_write_credential(const CREDENTIALW *credential, BOOL preserve_b
status = SecKeychainAddGenericPassword(NULL, strlen(servername), servername, strlen(username),
username, strlen(password), password, &keychain_item);
if (status != noErr)
ERR("SecKeychainAddGenericPassword returned %ld\n", status);
ERR("SecKeychainAddGenericPassword returned %d\n", status);
if (status == errSecDuplicateItem)
{
status = SecKeychainFindGenericPassword(NULL, strlen(servername), servername, strlen(username),
username, NULL, NULL, &keychain_item);
if (status != noErr)
ERR("SecKeychainFindGenericPassword returned %ld\n", status);
ERR("SecKeychainFindGenericPassword returned %d\n", status);
}
heap_free(username);
heap_free(servername);
@ -770,7 +830,7 @@ static DWORD mac_enumerate_credentials(LPCWSTR filter, PCREDENTIALW *credentials
{
SecKeychainSearchRef search;
SecKeychainItemRef item;
OSStatus status;
int status;
Boolean saved_user_interaction_allowed;
DWORD ret;
@ -793,7 +853,7 @@ static DWORD mac_enumerate_credentials(LPCWSTR filter, PCREDENTIALW *credentials
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL);
if (status != noErr)
{
WARN("SecKeychainItemCopyAttributesAndData returned status %ld\n", status);
WARN("SecKeychainItemCopyAttributesAndData returned status %d\n", status);
continue;
}
if (buffer)
@ -826,14 +886,14 @@ static DWORD mac_enumerate_credentials(LPCWSTR filter, PCREDENTIALW *credentials
CFRelease(search);
}
else
ERR("SecKeychainSearchCreateFromAttributes returned status %ld\n", status);
ERR("SecKeychainSearchCreateFromAttributes returned status %d\n", status);
SecKeychainSetUserInteractionAllowed(saved_user_interaction_allowed);
return ERROR_SUCCESS;
}
static DWORD mac_delete_credential(LPCWSTR TargetName)
{
OSStatus status;
int status;
SecKeychainSearchRef search;
status = SecKeychainSearchCreateFromAttributes(NULL, kSecGenericPasswordItemClass, NULL, &search);
if (status == noErr)
@ -852,7 +912,7 @@ static DWORD mac_delete_credential(LPCWSTR TargetName)
status = SecKeychainItemCopyAttributesAndData(item, &info, NULL, &attr_list, NULL, NULL);
if (status != noErr)
{
WARN("SecKeychainItemCopyAttributesAndData returned status %ld\n", status);
WARN("SecKeychainItemCopyAttributesAndData returned status %d\n", status);
continue;
}
if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)
@ -1421,7 +1481,7 @@ BOOL WINAPI CredReadW(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW
#ifdef __APPLE__
if (Type == CRED_TYPE_DOMAIN_PASSWORD)
{
OSStatus status;
int status;
SecKeychainSearchRef search;
status = SecKeychainSearchCreateFromAttributes(NULL, kSecGenericPasswordItemClass, NULL, &search);
if (status == noErr)
@ -1441,7 +1501,7 @@ BOOL WINAPI CredReadW(LPCWSTR TargetName, DWORD Type, DWORD Flags, PCREDENTIALW
len = sizeof(**Credential);
if (status != noErr)
{
WARN("SecKeychainItemCopyAttributesAndData returned status %ld\n", status);
WARN("SecKeychainItemCopyAttributesAndData returned status %d\n", status);
continue;
}
if (attr_list->count != 1 || attr_list->attr[0].tag != kSecServiceItemAttr)

View file

@ -257,7 +257,7 @@ reactos/sdk/lib/rtl/timerqueue.c # Partly synced with WineStaging-1.7
reactos/sdk/lib/rtl/wait.c # Partly synced with WineStaging-1.7.55
advapi32 -
reactos/dll/win32/advapi32/wine/cred.c # Synced to WineStaging-1.7.55
reactos/dll/win32/advapi32/wine/cred.c # Synced to WineStaging-3.3
reactos/dll/win32/advapi32/wine/crypt.c # Synced to WineStaging-1.7.55
reactos/dll/win32/advapi32/wine/crypt_des.c # Synced to WineStaging-1.7.55
reactos/dll/win32/advapi32/wine/crypt_lmhash.c # Synced to WineStaging-1.7.55