Author: cwittich
Date: Tue Oct 13 23:09:08 2009
New Revision: 43442
URL:
http://svn.reactos.org/svn/reactos?rev=43442&view=rev
Log:
partial sync to wine 1.1.31
Modified:
trunk/reactos/dll/win32/advapi32/sec/cred.c
Modified: trunk/reactos/dll/win32/advapi32/sec/cred.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/advapi32/sec/cre…
==============================================================================
--- trunk/reactos/dll/win32/advapi32/sec/cred.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/advapi32/sec/cred.c [iso-8859-1] Tue Oct 13 23:09:08 2009
@@ -911,55 +911,63 @@
}
#endif
-static void convert_PCREDENTIALW_to_PCREDENTIALA(const CREDENTIALW *CredentialW,
PCREDENTIALA CredentialA, DWORD *len)
-{
- char *buffer = (char *)CredentialA + sizeof(CREDENTIALA);
+static INT convert_PCREDENTIALW_to_PCREDENTIALA(const CREDENTIALW *CredentialW,
PCREDENTIALA CredentialA, INT len)
+{
+ char *buffer;
INT string_len;
-
- *len += sizeof(CREDENTIALA);
+ INT needed = sizeof(CREDENTIALA);
+
if (!CredentialA)
{
- if (CredentialW->TargetName) *len += WideCharToMultiByte(CP_ACP, 0,
CredentialW->TargetName, -1, NULL, 0, NULL, NULL);
- if (CredentialW->Comment) *len += WideCharToMultiByte(CP_ACP, 0,
CredentialW->Comment, -1, NULL, 0, NULL, NULL);
- *len += CredentialW->CredentialBlobSize;
- if (CredentialW->TargetAlias) *len += WideCharToMultiByte(CP_ACP, 0,
CredentialW->TargetAlias, -1, NULL, 0, NULL, NULL);
- if (CredentialW->UserName) *len += WideCharToMultiByte(CP_ACP, 0,
CredentialW->UserName, -1, NULL, 0, NULL, NULL);
-
- return;
- }
-
+ if (CredentialW->TargetName)
+ needed += WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetName, -1,
NULL, 0, NULL, NULL);
+ if (CredentialW->Comment)
+ needed += WideCharToMultiByte(CP_ACP, 0, CredentialW->Comment, -1, NULL,
0, NULL, NULL);
+ needed += CredentialW->CredentialBlobSize;
+ if (CredentialW->TargetAlias)
+ needed += WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetAlias, -1,
NULL, 0, NULL, NULL);
+ if (CredentialW->UserName)
+ needed += WideCharToMultiByte(CP_ACP, 0, CredentialW->UserName, -1, NULL,
0, NULL, NULL);
+
+ return needed;
+ }
+
+
+ buffer = (char *)CredentialA + sizeof(CREDENTIALA);
+ len -= sizeof(CREDENTIALA);
CredentialA->Flags = CredentialW->Flags;
CredentialA->Type = CredentialW->Type;
+
if (CredentialW->TargetName)
{
CredentialA->TargetName = buffer;
-
- /* Buffer is guaranteed to be large enough */
- string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetName, -1,
CredentialA->TargetName, 0x7FFFFFFF, NULL, NULL);
-
+ string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetName, -1,
buffer, len, NULL, NULL);
buffer += string_len;
- *len += string_len;
+ needed += string_len;
+ len -= string_len;
}
else
CredentialA->TargetName = NULL;
if (CredentialW->Comment)
{
CredentialA->Comment = buffer;
- string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->Comment, -1,
CredentialA->Comment, 0x7FFFFFFF, NULL, NULL);
+ string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->Comment, -1, buffer,
len, NULL, NULL);
buffer += string_len;
- *len += string_len;
+ needed += string_len;
+ len -= string_len;
}
else
CredentialA->Comment = NULL;
CredentialA->LastWritten = CredentialW->LastWritten;
CredentialA->CredentialBlobSize = CredentialW->CredentialBlobSize;
- if (CredentialW->CredentialBlobSize)
+ if (CredentialW->CredentialBlobSize && (CredentialW->CredentialBlobSize
<= len))
{
CredentialA->CredentialBlob =(LPBYTE)buffer;
memcpy(CredentialA->CredentialBlob, CredentialW->CredentialBlob,
CredentialW->CredentialBlobSize);
buffer += CredentialW->CredentialBlobSize;
- *len += CredentialW->CredentialBlobSize;
+ needed += CredentialW->CredentialBlobSize;
+ len -= CredentialW->CredentialBlobSize;
}
else
CredentialA->CredentialBlob = NULL;
@@ -969,57 +977,67 @@
if (CredentialW->TargetAlias)
{
CredentialA->TargetAlias = buffer;
- string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetAlias, -1,
CredentialA->TargetAlias, 0x7FFFFFFF, NULL, NULL);
+ string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->TargetAlias, -1,
buffer, len, NULL, NULL);
buffer += string_len;
- *len += string_len;
+ needed += string_len;
+ len -= string_len;
}
else
CredentialA->TargetAlias = NULL;
if (CredentialW->UserName)
{
CredentialA->UserName = buffer;
- string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->UserName, -1,
CredentialA->UserName, 0x7FFFFFFF, NULL, NULL);
- buffer += string_len;
- *len += string_len;
+ string_len = WideCharToMultiByte(CP_ACP, 0, CredentialW->UserName, -1, buffer,
len, NULL, NULL);
+ needed += string_len;
}
else
CredentialA->UserName = NULL;
-}
-
-static void convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA,
PCREDENTIALW CredentialW, DWORD *len)
-{
- char *buffer = (char *)CredentialW + sizeof(CREDENTIALW);
+
+ return needed;
+}
+
+static INT convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA,
PCREDENTIALW CredentialW, INT len)
+{
+ char *buffer;
INT string_len;
-
- *len += sizeof(CREDENTIALW);
+ INT needed = sizeof(CREDENTIALW);
+
if (!CredentialW)
{
- if (CredentialA->TargetName) *len += sizeof(WCHAR) *
MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1, NULL, 0);
- if (CredentialA->Comment) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP,
0, CredentialA->Comment, -1, NULL, 0);
- *len += CredentialA->CredentialBlobSize;
- if (CredentialA->TargetAlias) *len += sizeof(WCHAR) *
MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1, NULL, 0);
- if (CredentialA->UserName) *len += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP,
0, CredentialA->UserName, -1, NULL, 0);
-
- return;
- }
-
+ if (CredentialA->TargetName)
+ needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0,
CredentialA->TargetName, -1, NULL, 0);
+ if (CredentialA->Comment)
+ needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0,
CredentialA->Comment, -1, NULL, 0);
+ needed += CredentialA->CredentialBlobSize;
+ if (CredentialA->TargetAlias)
+ needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0,
CredentialA->TargetAlias, -1, NULL, 0);
+ if (CredentialA->UserName)
+ needed += sizeof(WCHAR) * MultiByteToWideChar(CP_ACP, 0,
CredentialA->UserName, -1, NULL, 0);
+
+ return needed;
+ }
+
+ buffer = (char *)CredentialW + sizeof(CREDENTIALW);
+ len -= sizeof(CREDENTIALW);
CredentialW->Flags = CredentialA->Flags;
CredentialW->Type = CredentialA->Type;
if (CredentialA->TargetName)
{
CredentialW->TargetName = (LPWSTR)buffer;
- string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1,
CredentialW->TargetName, 0x7FFFFFFF);
+ string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetName, -1,
CredentialW->TargetName, len / sizeof(WCHAR));
buffer += sizeof(WCHAR) * string_len;
- *len += sizeof(WCHAR) * string_len;
+ needed += sizeof(WCHAR) * string_len;
+ len -= sizeof(WCHAR) * string_len;
}
else
CredentialW->TargetName = NULL;
if (CredentialA->Comment)
{
CredentialW->Comment = (LPWSTR)buffer;
- string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1,
CredentialW->Comment, 0x7FFFFFFF);
+ string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->Comment, -1,
CredentialW->Comment, len / sizeof(WCHAR));
buffer += sizeof(WCHAR) * string_len;
- *len += sizeof(WCHAR) * string_len;
+ needed += sizeof(WCHAR) * string_len;
+ len -= sizeof(WCHAR) * string_len;
}
else
CredentialW->Comment = NULL;
@@ -1031,7 +1049,8 @@
memcpy(CredentialW->CredentialBlob, CredentialA->CredentialBlob,
CredentialA->CredentialBlobSize);
buffer += CredentialA->CredentialBlobSize;
- *len += CredentialA->CredentialBlobSize;
+ needed += CredentialA->CredentialBlobSize;
+ len -= CredentialA->CredentialBlobSize;
}
else
CredentialW->CredentialBlob = NULL;
@@ -1041,21 +1060,23 @@
if (CredentialA->TargetAlias)
{
CredentialW->TargetAlias = (LPWSTR)buffer;
- string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1,
CredentialW->TargetAlias, 0x7FFFFFFF);
+ string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->TargetAlias, -1,
CredentialW->TargetAlias, len / sizeof(WCHAR));
buffer += sizeof(WCHAR) * string_len;
- *len += sizeof(WCHAR) * string_len;
+ needed += sizeof(WCHAR) * string_len;
+ len -= sizeof(WCHAR) * string_len;
}
else
CredentialW->TargetAlias = NULL;
if (CredentialA->UserName)
{
CredentialW->UserName = (LPWSTR)buffer;
- string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1,
CredentialW->UserName, 0x7FFFFFFF);
- buffer += sizeof(WCHAR) * string_len;
- *len += sizeof(WCHAR) * string_len;
+ string_len = MultiByteToWideChar(CP_ACP, 0, CredentialA->UserName, -1,
CredentialW->UserName, len / sizeof(WCHAR));
+ needed += sizeof(WCHAR) * string_len;
}
else
CredentialW->UserName = NULL;
+
+ return needed;
}
/******************************************************************************
@@ -1161,7 +1182,8 @@
LPWSTR FilterW;
PCREDENTIALW *CredentialsW;
DWORD i;
- DWORD len;
+ INT len;
+ INT needed;
char *buffer;
TRACE("(%s, 0x%x, %p, %p)\n", debugstr_a(Filter), Flags, Count,
Credentials);
@@ -1189,7 +1211,7 @@
len = *Count * sizeof(PCREDENTIALA);
for (i = 0; i < *Count; i++)
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], NULL, &len);
+ len += convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], NULL, 0);
*Credentials = HeapAlloc(GetProcessHeap(), 0, len);
if (!*Credentials)
@@ -1200,12 +1222,13 @@
}
buffer = (char *)&(*Credentials)[*Count];
+ len -= *Count * sizeof(PCREDENTIALA);
for (i = 0; i < *Count; i++)
{
- len = 0;
(*Credentials)[i] = (PCREDENTIALA)buffer;
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], (*Credentials)[i],
&len);
- buffer += len;
+ needed = convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], (*Credentials)[i],
len);
+ buffer += needed;
+ len -= needed;
}
CredFree(CredentialsW);
@@ -1334,7 +1357,7 @@
{
LPWSTR TargetNameW;
PCREDENTIALW CredentialW;
- DWORD len;
+ INT len;
TRACE("(%s, %d, 0x%x, %p)\n", debugstr_a(TargetName), Type, Flags,
Credential);
@@ -1360,16 +1383,14 @@
}
HeapFree(GetProcessHeap(), 0, TargetNameW);
- len = 0;
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialW, NULL, &len);
+ len = convert_PCREDENTIALW_to_PCREDENTIALA(CredentialW, NULL, 0);
*Credential = HeapAlloc(GetProcessHeap(), 0, len);
if (!*Credential)
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
- len = 0;
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialW, *Credential, &len);
+ convert_PCREDENTIALW_to_PCREDENTIALA(CredentialW, *Credential, len);
CredFree(CredentialW);
@@ -1540,7 +1561,7 @@
BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
{
BOOL ret;
- DWORD len;
+ INT len;
PCREDENTIALW CredentialW;
TRACE("(%p, 0x%x)\n", Credential, Flags);
@@ -1551,16 +1572,15 @@
return FALSE;
}
- len = 0;
- convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, &len);
+ len = convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, 0);
CredentialW = HeapAlloc(GetProcessHeap(), 0, len);
if (!CredentialW)
{
SetLastError(ERROR_OUTOFMEMORY);
return FALSE;
}
- len = 0;
- convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, &len);
+
+ convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, len);
ret = CredWriteW(CredentialW, Flags);
@@ -1722,7 +1742,7 @@
DWORD Flags, DWORD *Size, PCREDENTIALA
**Credentials)
{
PCREDENTIAL_TARGET_INFORMATIONW TargetInformationW;
- DWORD len, i;
+ INT len, i;
WCHAR *buffer, *end;
BOOL ret;
PCREDENTIALW* CredentialsW;
@@ -1831,10 +1851,11 @@
if (ret)
{
char *buf;
+ INT needed;
len = *Size * sizeof(PCREDENTIALA);
for (i = 0; i < *Size; i++)
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], NULL, &len);
+ len += convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], NULL, 0);
*Credentials = HeapAlloc(GetProcessHeap(), 0, len);
if (!*Credentials)
@@ -1845,12 +1866,13 @@
}
buf = (char *)&(*Credentials)[*Size];
+ len -= *Size * sizeof(PCREDENTIALA);
for (i = 0; i < *Size; i++)
{
- len = 0;
(*Credentials)[i] = (PCREDENTIALA)buf;
- convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i], (*Credentials)[i],
&len);
- buf += len;
+ needed = convert_PCREDENTIALW_to_PCREDENTIALA(CredentialsW[i],
(*Credentials)[i], len);
+ buf += needed;
+ len -= needed;
}
CredFree(CredentialsW);