Author: cwittich
Date: Sun Jan 3 12:20:54 2010
New Revision: 44907
URL:
http://svn.reactos.org/svn/reactos?rev=44907&view=rev
Log:
[advapi32]
reorder functions in cred.c to match wine code for easier syncing
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] Sun Jan 3 12:20:54 2010
@@ -911,6 +911,13 @@
}
#endif
+/******************************************************************************
+ * convert_PCREDENTIALW_to_PCREDENTIALA [internal]
+ *
+ * convert a Credential struct from UNICODE to ANSI and return the needed size in Bytes
+ *
+ */
+
static INT convert_PCREDENTIALW_to_PCREDENTIALA(const CREDENTIALW *CredentialW,
PCREDENTIALA CredentialA, INT len)
{
char *buffer;
@@ -996,6 +1003,12 @@
return needed;
}
+/******************************************************************************
+ * convert_PCREDENTIALA_to_PCREDENTIALW [internal]
+ *
+ * convert a Credential struct from ANSI to UNICODE and return the needed size in Bytes
+ *
+ */
static INT convert_PCREDENTIALA_to_PCREDENTIALW(const CREDENTIALA *CredentialA,
PCREDENTIALW CredentialW, INT len)
{
char *buffer;
@@ -1556,186 +1569,6 @@
}
/******************************************************************************
- * CredWriteA [ADVAPI32.@]
- */
-BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
-{
- BOOL ret;
- INT len;
- PCREDENTIALW CredentialW;
-
- TRACE("(%p, 0x%x)\n", Credential, Flags);
-
- if (!Credential || !Credential->TargetName)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- len = convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, 0);
- CredentialW = HeapAlloc(GetProcessHeap(), 0, len);
- if (!CredentialW)
- {
- SetLastError(ERROR_OUTOFMEMORY);
- return FALSE;
- }
-
- convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, len);
-
- ret = CredWriteW(CredentialW, Flags);
-
- HeapFree(GetProcessHeap(), 0, CredentialW);
-
- return ret;
-}
-
-/******************************************************************************
- * CredWriteW [ADVAPI32.@]
- */
-BOOL WINAPI CredWriteW(PCREDENTIALW Credential, DWORD Flags)
-{
- HKEY hkeyMgr;
- HKEY hkeyCred;
- DWORD ret;
- LPWSTR key_name;
- BYTE key_data[KEY_SIZE];
-
- TRACE("(%p, 0x%x)\n", Credential, Flags);
-
- if (!Credential || !Credential->TargetName)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- if (Flags & ~CRED_PRESERVE_CREDENTIAL_BLOB)
- {
- FIXME("unhandled flags 0x%x\n", Flags);
- SetLastError(ERROR_INVALID_FLAGS);
- return FALSE;
- }
-
- if (Credential->Type != CRED_TYPE_GENERIC && Credential->Type !=
CRED_TYPE_DOMAIN_PASSWORD)
- {
- FIXME("unhandled type %d\n", Credential->Type);
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- TRACE("Credential->TargetName = %s\n",
debugstr_w(Credential->TargetName));
- TRACE("Credential->UserName = %s\n",
debugstr_w(Credential->UserName));
-
- if (Credential->Type == CRED_TYPE_DOMAIN_PASSWORD)
- {
- if (!Credential->UserName ||
- (!strchrW(Credential->UserName, '\\') &&
!strchrW(Credential->UserName, '@')))
- {
- ERR("bad username %s\n", debugstr_w(Credential->UserName));
- SetLastError(ERROR_BAD_USERNAME);
- return FALSE;
- }
- }
-
-#ifdef __APPLE__
- if (!Credential->AttributeCount &&
- Credential->Type == CRED_TYPE_DOMAIN_PASSWORD &&
- (Credential->Persist == CRED_PERSIST_LOCAL_MACHINE || Credential->Persist
== CRED_PERSIST_ENTERPRISE))
- {
- ret = mac_write_credential(Credential, Flags &
CRED_PRESERVE_CREDENTIAL_BLOB);
- if (ret != ERROR_SUCCESS)
- {
- SetLastError(ret);
- return FALSE;
- }
- return TRUE;
- }
-#endif
-
- ret = open_cred_mgr_key(&hkeyMgr, FALSE);
- if (ret != ERROR_SUCCESS)
- {
- WARN("couldn't open/create manager key, error %d\n", ret);
- SetLastError(ERROR_NO_SUCH_LOGON_SESSION);
- return FALSE;
- }
-
- ret = get_cred_mgr_encryption_key(hkeyMgr, key_data);
- if (ret != ERROR_SUCCESS)
- {
- RegCloseKey(hkeyMgr);
- SetLastError(ret);
- return FALSE;
- }
-
- key_name = get_key_name_for_target(Credential->TargetName, Credential->Type);
- ret = RegCreateKeyExW(hkeyMgr, key_name, 0, NULL,
- Credential->Persist == CRED_PERSIST_SESSION ?
REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE,
- KEY_READ|KEY_WRITE, NULL, &hkeyCred, NULL);
- HeapFree(GetProcessHeap(), 0, key_name);
- if (ret != ERROR_SUCCESS)
- {
- TRACE("credentials for target name %s not found\n",
- debugstr_w(Credential->TargetName));
- SetLastError(ERROR_NOT_FOUND);
- return FALSE;
- }
-
- ret = registry_write_credential(hkeyCred, Credential, key_data,
- Flags & CRED_PRESERVE_CREDENTIAL_BLOB);
-
- RegCloseKey(hkeyCred);
- RegCloseKey(hkeyMgr);
-
- if (ret != ERROR_SUCCESS)
- {
- SetLastError(ret);
- return FALSE;
- }
- return TRUE;
-}
-
-/******************************************************************************
- * CredGetSessionTypes [ADVAPI32.@]
- */
-BOOL WINAPI CredGetSessionTypes(DWORD persistCount, LPDWORD persists)
-{
- TRACE("(%u, %p)\n", persistCount, persists);
-
- memset(persists, CRED_PERSIST_NONE, persistCount*sizeof(*persists));
- if (CRED_TYPE_GENERIC < persistCount)
- {
- persists[CRED_TYPE_GENERIC] = CRED_PERSIST_ENTERPRISE;
-
- if (CRED_TYPE_DOMAIN_PASSWORD < persistCount)
- {
- persists[CRED_TYPE_DOMAIN_PASSWORD] = CRED_PERSIST_ENTERPRISE;
- }
- }
- return TRUE;
-}
-
-/******************************************************************************
- * CredReadDomainCredentialsW [ADVAPI32.@]
- */
-BOOL WINAPI CredReadDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInformation,
DWORD Flags,
- DWORD *Size, PCREDENTIALW **Credentials)
-{
- FIXME("(%p, 0x%x, %p, %p) stub\n", TargetInformation, Flags, Size,
Credentials);
-
- /* follow Windows behavior - do not test for NULL, initialize early */
- *Size = 0;
- *Credentials = NULL;
- if (!TargetInformation)
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- SetLastError(ERROR_NOT_FOUND);
- return FALSE;
-}
-
-/******************************************************************************
* CredReadDomainCredentialsA [ADVAPI32.@]
*/
BOOL WINAPI CredReadDomainCredentialsA(PCREDENTIAL_TARGET_INFORMATIONA
TargetInformation,
@@ -1880,6 +1713,186 @@
return ret;
}
+/******************************************************************************
+ * CredReadDomainCredentialsW [ADVAPI32.@]
+ */
+BOOL WINAPI CredReadDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInformation,
DWORD Flags,
+ DWORD *Size, PCREDENTIALW **Credentials)
+{
+ FIXME("(%p, 0x%x, %p, %p) stub\n", TargetInformation, Flags, Size,
Credentials);
+
+ /* follow Windows behavior - do not test for NULL, initialize early */
+ *Size = 0;
+ *Credentials = NULL;
+ if (!TargetInformation)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ SetLastError(ERROR_NOT_FOUND);
+ return FALSE;
+}
+
+/******************************************************************************
+ * CredWriteA [ADVAPI32.@]
+ */
+BOOL WINAPI CredWriteA(PCREDENTIALA Credential, DWORD Flags)
+{
+ BOOL ret;
+ INT len;
+ PCREDENTIALW CredentialW;
+
+ TRACE("(%p, 0x%x)\n", Credential, Flags);
+
+ if (!Credential || !Credential->TargetName)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ len = convert_PCREDENTIALA_to_PCREDENTIALW(Credential, NULL, 0);
+ CredentialW = HeapAlloc(GetProcessHeap(), 0, len);
+ if (!CredentialW)
+ {
+ SetLastError(ERROR_OUTOFMEMORY);
+ return FALSE;
+ }
+
+ convert_PCREDENTIALA_to_PCREDENTIALW(Credential, CredentialW, len);
+
+ ret = CredWriteW(CredentialW, Flags);
+
+ HeapFree(GetProcessHeap(), 0, CredentialW);
+
+ return ret;
+}
+
+/******************************************************************************
+ * CredWriteW [ADVAPI32.@]
+ */
+BOOL WINAPI CredWriteW(PCREDENTIALW Credential, DWORD Flags)
+{
+ HKEY hkeyMgr;
+ HKEY hkeyCred;
+ DWORD ret;
+ LPWSTR key_name;
+ BYTE key_data[KEY_SIZE];
+
+ TRACE("(%p, 0x%x)\n", Credential, Flags);
+
+ if (!Credential || !Credential->TargetName)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ if (Flags & ~CRED_PRESERVE_CREDENTIAL_BLOB)
+ {
+ FIXME("unhandled flags 0x%x\n", Flags);
+ SetLastError(ERROR_INVALID_FLAGS);
+ return FALSE;
+ }
+
+ if (Credential->Type != CRED_TYPE_GENERIC && Credential->Type !=
CRED_TYPE_DOMAIN_PASSWORD)
+ {
+ FIXME("unhandled type %d\n", Credential->Type);
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return FALSE;
+ }
+
+ TRACE("Credential->TargetName = %s\n",
debugstr_w(Credential->TargetName));
+ TRACE("Credential->UserName = %s\n",
debugstr_w(Credential->UserName));
+
+ if (Credential->Type == CRED_TYPE_DOMAIN_PASSWORD)
+ {
+ if (!Credential->UserName ||
+ (!strchrW(Credential->UserName, '\\') &&
!strchrW(Credential->UserName, '@')))
+ {
+ ERR("bad username %s\n", debugstr_w(Credential->UserName));
+ SetLastError(ERROR_BAD_USERNAME);
+ return FALSE;
+ }
+ }
+
+#ifdef __APPLE__
+ if (!Credential->AttributeCount &&
+ Credential->Type == CRED_TYPE_DOMAIN_PASSWORD &&
+ (Credential->Persist == CRED_PERSIST_LOCAL_MACHINE || Credential->Persist
== CRED_PERSIST_ENTERPRISE))
+ {
+ ret = mac_write_credential(Credential, Flags &
CRED_PRESERVE_CREDENTIAL_BLOB);
+ if (ret != ERROR_SUCCESS)
+ {
+ SetLastError(ret);
+ return FALSE;
+ }
+ return TRUE;
+ }
+#endif
+
+ ret = open_cred_mgr_key(&hkeyMgr, FALSE);
+ if (ret != ERROR_SUCCESS)
+ {
+ WARN("couldn't open/create manager key, error %d\n", ret);
+ SetLastError(ERROR_NO_SUCH_LOGON_SESSION);
+ return FALSE;
+ }
+
+ ret = get_cred_mgr_encryption_key(hkeyMgr, key_data);
+ if (ret != ERROR_SUCCESS)
+ {
+ RegCloseKey(hkeyMgr);
+ SetLastError(ret);
+ return FALSE;
+ }
+
+ key_name = get_key_name_for_target(Credential->TargetName, Credential->Type);
+ ret = RegCreateKeyExW(hkeyMgr, key_name, 0, NULL,
+ Credential->Persist == CRED_PERSIST_SESSION ?
REG_OPTION_VOLATILE : REG_OPTION_NON_VOLATILE,
+ KEY_READ|KEY_WRITE, NULL, &hkeyCred, NULL);
+ HeapFree(GetProcessHeap(), 0, key_name);
+ if (ret != ERROR_SUCCESS)
+ {
+ TRACE("credentials for target name %s not found\n",
+ debugstr_w(Credential->TargetName));
+ SetLastError(ERROR_NOT_FOUND);
+ return FALSE;
+ }
+
+ ret = registry_write_credential(hkeyCred, Credential, key_data,
+ Flags & CRED_PRESERVE_CREDENTIAL_BLOB);
+
+ RegCloseKey(hkeyCred);
+ RegCloseKey(hkeyMgr);
+
+ if (ret != ERROR_SUCCESS)
+ {
+ SetLastError(ret);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/******************************************************************************
+ * CredGetSessionTypes [ADVAPI32.@]
+ */
+BOOL WINAPI CredGetSessionTypes(DWORD persistCount, LPDWORD persists)
+{
+ TRACE("(%u, %p)\n", persistCount, persists);
+
+ memset(persists, CRED_PERSIST_NONE, persistCount*sizeof(*persists));
+ if (CRED_TYPE_GENERIC < persistCount)
+ {
+ persists[CRED_TYPE_GENERIC] = CRED_PERSIST_ENTERPRISE;
+
+ if (CRED_TYPE_DOMAIN_PASSWORD < persistCount)
+ {
+ persists[CRED_TYPE_DOMAIN_PASSWORD] = CRED_PERSIST_ENTERPRISE;
+ }
+ }
+ return TRUE;
+}
+
BOOL
WINAPI
CredWriteDomainCredentialsW(PCREDENTIAL_TARGET_INFORMATIONW TargetInfo,