Hans Leidekker : credui: Don' t show a dialog if existing credentials can be found.

Alexandre Julliard julliard at winehq.org
Thu Oct 18 14:33:12 CDT 2012


Module: wine
Branch: master
Commit: 9d95d33118dceca36252745302485d7268934c33
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9d95d33118dceca36252745302485d7268934c33

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Thu Oct 18 14:16:52 2012 +0200

credui: Don't show a dialog if existing credentials can be found.

---

 dlls/credui/credui_main.c |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/dlls/credui/credui_main.c b/dlls/credui/credui_main.c
index b470928..6e8d452 100644
--- a/dlls/credui/credui_main.c
+++ b/dlls/credui/credui_main.c
@@ -548,6 +548,38 @@ static INT_PTR CALLBACK CredDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,
     }
 }
 
+static BOOL find_existing_credential(const WCHAR *target, WCHAR *username, ULONG len_username,
+                                     WCHAR *password, ULONG len_password)
+{
+    DWORD count, i;
+    CREDENTIALW **credentials;
+
+    if (!CredEnumerateW(target, 0, &count, &credentials)) return FALSE;
+    for (i = 0; i < count; i++)
+    {
+        if (credentials[i]->Type != CRED_TYPE_DOMAIN_PASSWORD)
+        {
+            FIXME("no support for type %u credentials\n", credentials[i]->Type);
+            continue;
+        }
+        if ((!*username || !strcmpW(username, credentials[i]->UserName)) &&
+            strlenW(credentials[i]->UserName) < len_username &&
+            credentials[i]->CredentialBlobSize / sizeof(WCHAR) < len_password)
+        {
+            TRACE("found existing credential for %s\n", debugstr_w(credentials[i]->UserName));
+
+            strcpyW(username, credentials[i]->UserName);
+            memcpy(password, credentials[i]->CredentialBlob, credentials[i]->CredentialBlobSize);
+            password[credentials[i]->CredentialBlobSize / sizeof(WCHAR)] = 0;
+
+            CredFree(credentials);
+            return TRUE;
+        }
+    }
+    CredFree(credentials);
+    return FALSE;
+}
+
 /******************************************************************************
  *           CredUIPromptForCredentialsW [CREDUI.@]
  */
@@ -578,6 +610,11 @@ DWORD WINAPI CredUIPromptForCredentialsW(PCREDUI_INFOW pUIInfo,
     if ((dwFlags & CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX) && !pfSave)
         return ERROR_INVALID_PARAMETER;
 
+    if (!(dwFlags & CREDUI_FLAGS_ALWAYS_SHOW_UI) &&
+        !(dwFlags & CREDUI_FLAGS_INCORRECT_PASSWORD) &&
+        find_existing_credential(pszTargetName, pszUsername, ulUsernameMaxChars, pszPassword, ulPasswordMaxChars))
+        return ERROR_SUCCESS;
+
     params.pszTargetName = pszTargetName;
     if (pUIInfo)
     {




More information about the wine-cvs mailing list