[CREDUI] Sync with Wine Staging 3.17. CORE-15127
[reactos.git] / dll / win32 / credui / credui_main.c
index 00ab84f..bf9f7d1 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
-#define WIN32_NO_STATUS
-
 #include <stdarg.h>
 
-#include <windef.h>
-#include <winbase.h>
-//#include "winnt.h"
-#include <winuser.h>
-#include <wincred.h>
-#include <sspi.h>
-#include <commctrl.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winnt.h"
+#include "winuser.h"
+#include "wincred.h"
+#include "rpc.h"
+#include "sspi.h"
+#include "commctrl.h"
 
 #include "credui_resources.h"
 
-#include <wine/debug.h>
-#include <wine/unicode.h>
-#include <wine/list.h>
+#include "wine/debug.h"
+#include "wine/unicode.h"
+#include "wine/list.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(credui);
 
@@ -207,7 +206,7 @@ static void CredDialogCreateBalloonTip(HWND hwndDlg, struct cred_dialog_params *
     SetWindowPos(params->hwndBalloonTip, HWND_TOPMOST, 0, 0, 0, 0,
                  SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 
-    if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORD, wszText, sizeof(wszText)/sizeof(wszText[0])))
+    if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORD, wszText, ARRAY_SIZE(wszText)))
     {
         ERR("failed to load IDS_INCORRECTPASSWORD\n");
         return;
@@ -217,14 +216,14 @@ static void CredDialogCreateBalloonTip(HWND hwndDlg, struct cred_dialog_params *
     toolinfo.uFlags = TTF_TRACK;
     toolinfo.hwnd = hwndDlg;
     toolinfo.uId = TOOLID_INCORRECTPASSWORD;
-    memset(&toolinfo.rect, 0, sizeof(toolinfo.rect));
+    SetRectEmpty(&toolinfo.rect);
     toolinfo.hinst = NULL;
     toolinfo.lpszText = wszText;
     toolinfo.lParam = 0;
     toolinfo.lpReserved = NULL;
     SendMessageW(params->hwndBalloonTip, TTM_ADDTOOLW, 0, (LPARAM)&toolinfo);
 
-    if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKON, wszText, sizeof(wszText)/sizeof(wszText[0])))
+    if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKON, wszText, ARRAY_SIZE(wszText)))
     {
         ERR("failed to load IDS_CAPSLOCKON\n");
         return;
@@ -252,7 +251,7 @@ static void CredDialogShowIncorrectPasswordBalloon(HWND hwndDlg, struct cred_dia
     if (params->fBalloonTipActive)
         return;
 
-    if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORDTITLE, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0])))
+    if (!LoadStringW(hinstCredUI, IDS_INCORRECTPASSWORDTITLE, wszTitle, ARRAY_SIZE(wszTitle)))
     {
         ERR("failed to load IDS_INCORRECTPASSWORDTITLE\n");
         return;
@@ -290,7 +289,7 @@ static void CredDialogShowCapsLockBalloon(HWND hwndDlg, struct cred_dialog_param
     if (params->fBalloonTipActive)
         return;
 
-    if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKONTITLE, wszTitle, sizeof(wszTitle)/sizeof(wszTitle[0])))
+    if (!LoadStringW(hinstCredUI, IDS_CAPSLOCKONTITLE, wszTitle, ARRAY_SIZE(wszTitle)))
     {
         ERR("failed to load IDS_IDSCAPSLOCKONTITLE\n");
         return;
@@ -384,8 +383,8 @@ static BOOL CredDialogInit(HWND hwndDlg, struct cred_dialog_params *params)
     {
         WCHAR format[256];
         WCHAR message[256];
-        LoadStringW(hinstCredUI, IDS_MESSAGEFORMAT, format, sizeof(format)/sizeof(format[0]));
-        snprintfW(message, sizeof(message)/sizeof(message[0]), format, params->pszTargetName);
+        LoadStringW(hinstCredUI, IDS_MESSAGEFORMAT, format, ARRAY_SIZE(format));
+        snprintfW(message, ARRAY_SIZE(message), format, params->pszTargetName);
         SetDlgItemTextW(hwndDlg, IDC_MESSAGE, message);
     }
     SetWindowTextW(hwndUsername, params->pszUsername);
@@ -409,8 +408,8 @@ static BOOL CredDialogInit(HWND hwndDlg, struct cred_dialog_params *params)
     {
         WCHAR format[256];
         WCHAR title[256];
-        LoadStringW(hinstCredUI, IDS_TITLEFORMAT, format, sizeof(format)/sizeof(format[0]));
-        snprintfW(title, sizeof(title)/sizeof(title[0]), format, params->pszTargetName);
+        LoadStringW(hinstCredUI, IDS_TITLEFORMAT, format, ARRAY_SIZE(format));
+        snprintfW(title, ARRAY_SIZE(title), format, params->pszTargetName);
         SetWindowTextW(hwndDlg, title);
     }
 
@@ -868,10 +867,11 @@ ULONG SEC_ENTRY SspiPromptForCredentialsW( PCWSTR target, void *info,
     static const WCHAR negotiateW[] = {'N','e','g','o','t','i','a','t','e',0};
     WCHAR username[CREDUI_MAX_USERNAME_LENGTH + 1] = {0};
     WCHAR password[CREDUI_MAX_PASSWORD_LENGTH + 1] = {0};
-    DWORD len_username = sizeof(username) / sizeof(username[0]);
-    DWORD len_password = sizeof(password) / sizeof(password[0]);
+    DWORD len_username = ARRAY_SIZE(username);
+    DWORD len_password = ARRAY_SIZE(password);
     DWORD ret, flags;
     CREDUI_INFOW *cred_info = info;
+    SEC_WINNT_AUTH_IDENTITY_W *id = input_id;
 
     FIXME( "(%s, %p, %u, %s, %p, %p, %p, %x) stub\n", debugstr_w(target), info,
            error, debugstr_w(package), input_id, output_id, save, sspi_flags );
@@ -883,11 +883,6 @@ ULONG SEC_ENTRY SspiPromptForCredentialsW( PCWSTR target, void *info,
         FIXME( "package %s not supported\n", debugstr_w(package) );
         return ERROR_NO_SUCH_PACKAGE;
     }
-    if (input_id)
-    {
-        FIXME( "input identity not supported\n" );
-        return ERROR_CALL_NOT_IMPLEMENTED;
-    }
 
     flags = CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_GENERIC_CREDENTIALS;
 
@@ -897,29 +892,63 @@ ULONG SEC_ENTRY SspiPromptForCredentialsW( PCWSTR target, void *info,
     if (!(sspi_flags & SSPIPFC_NO_CHECKBOX))
         flags |= CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX;
 
-    find_existing_credential( target, username, len_username, password, len_password );
+    if (!id) find_existing_credential( target, username, len_username, password, len_password );
+    else
+    {
+        if (id->User && id->UserLength > 0 && id->UserLength <= CREDUI_MAX_USERNAME_LENGTH)
+        {
+            memcpy( username, id->User, id->UserLength * sizeof(WCHAR) );
+            username[id->UserLength] = 0;
+        }
+        if (id->Password && id->PasswordLength > 0 && id->PasswordLength <= CREDUI_MAX_PASSWORD_LENGTH)
+        {
+            memcpy( password, id->Password, id->PasswordLength * sizeof(WCHAR) );
+            password[id->PasswordLength] = 0;
+        }
+    }
 
     if (!(ret = CredUIPromptForCredentialsW( cred_info, target, NULL, error, username,
                                              len_username, password, len_password, save, flags )))
     {
-        SEC_WINNT_AUTH_IDENTITY_W *id;
-        DWORD size = sizeof(*id);
-        WCHAR *ptr;
+        DWORD size = sizeof(*id), len_domain = 0;
+        WCHAR *ptr, *user = username, *domain = NULL;
 
-        len_username = strlenW( username );
+        if ((ptr = strchrW( username, '\\' )))
+        {
+            user = ptr + 1;
+            len_username = strlenW( user );
+            if (!strcmpiW( package, ntlmW ) || !strcmpiW( package, negotiateW ))
+            {
+                domain = username;
+                len_domain = ptr - username;
+            }
+            *ptr = 0;
+        }
+        else len_username = strlenW( username );
         len_password = strlenW( password );
 
         size += (len_username + 1) * sizeof(WCHAR);
+        size += (len_domain + 1) * sizeof(WCHAR);
         size += (len_password + 1) * sizeof(WCHAR);
         if (!(id = HeapAlloc( GetProcessHeap(), 0, size ))) return ERROR_OUTOFMEMORY;
         ptr = (WCHAR *)(id + 1);
 
-        memcpy( ptr, username, (len_username + 1) * sizeof(WCHAR) );
+        memcpy( ptr, user, (len_username + 1) * sizeof(WCHAR) );
         id->User           = ptr;
         id->UserLength     = len_username;
         ptr += len_username + 1;
-        id->Domain         = NULL;
-        id->DomainLength   = 0;
+        if (len_domain)
+        {
+            memcpy( ptr, domain, (len_domain + 1) * sizeof(WCHAR) );
+            id->Domain         = ptr;
+            id->DomainLength   = len_domain;
+            ptr += len_domain + 1;
+        }
+        else
+        {
+            id->Domain         = NULL;
+            id->DomainLength   = 0;
+        }
         memcpy( ptr, password, (len_password + 1) * sizeof(WCHAR) );
         id->Password       = ptr;
         id->PasswordLength = len_password;
@@ -930,3 +959,37 @@ ULONG SEC_ENTRY SspiPromptForCredentialsW( PCWSTR target, void *info,
 
     return ret;
 }
+
+/******************************************************************************
+ * CredUIPromptForWindowsCredentialsW [CREDUI.@]
+ */
+DWORD WINAPI CredUIPromptForWindowsCredentialsW( CREDUI_INFOW *info, DWORD error, ULONG *package,
+                                                 const void *in_buf, ULONG in_buf_size, void **out_buf,
+                                                 ULONG *out_buf_size, BOOL *save, DWORD flags )
+{
+    FIXME( "(%p, %u, %p, %p, %u, %p, %p, %p, %08x) stub\n", info, error, package, in_buf, in_buf_size,
+           out_buf, out_buf_size, save, flags );
+    return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+/******************************************************************************
+ * CredPackAuthenticationBufferW [CREDUI.@]
+ */
+BOOL  WINAPI CredPackAuthenticationBufferW( DWORD flags, WCHAR *username, WCHAR *password, BYTE *buf,
+                                            DWORD *size )
+{
+    FIXME( "(%08x, %s, %p, %p, %p) stub\n", flags, debugstr_w(username), password, buf, size );
+    return ERROR_CALL_NOT_IMPLEMENTED;
+}
+
+/******************************************************************************
+ * CredUnPackAuthenticationBufferW [CREDUI.@]
+ */
+BOOL  WINAPI CredUnPackAuthenticationBufferW( DWORD flags, void *buf, DWORD size, WCHAR *username,
+                                              DWORD *len_username, WCHAR *domain, DWORD *len_domain,
+                                              WCHAR *password, DWORD *len_password )
+{
+    FIXME( "(%08x, %p, %u, %p, %p, %p, %p, %p, %p) stub\n", flags, buf, size, username, len_username,
+           domain, len_domain, password, len_password );
+    return ERROR_CALL_NOT_IMPLEMENTED;
+}