wfreerdp: added basic password prompt
This commit is contained in:
parent
421c4c86c4
commit
31417bd4b5
@ -25,6 +25,9 @@
|
||||
|
||||
#include <winpr/windows.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/credui.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -412,6 +415,59 @@ BOOL wf_post_connect(freerdp* instance)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const char wfTargetName[] = "TARGET";
|
||||
|
||||
static CREDUI_INFOA wfUiInfo =
|
||||
{
|
||||
sizeof(CREDUI_INFOA),
|
||||
NULL,
|
||||
"Enter your credentials",
|
||||
"Remote Desktop Security",
|
||||
NULL
|
||||
};
|
||||
|
||||
BOOL wf_authenticate(freerdp* instance, char** username, char** password, char** domain)
|
||||
{
|
||||
BOOL fSave;
|
||||
DWORD status;
|
||||
DWORD dwFlags;
|
||||
char UserName[CREDUI_MAX_USERNAME_LENGTH + 1];
|
||||
char Password[CREDUI_MAX_PASSWORD_LENGTH + 1];
|
||||
char User[CREDUI_MAX_USERNAME_LENGTH + 1];
|
||||
char Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1];
|
||||
|
||||
fSave = FALSE;
|
||||
ZeroMemory(UserName, sizeof(UserName));
|
||||
ZeroMemory(Password, sizeof(Password));
|
||||
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
|
||||
|
||||
status = CredUIPromptForCredentialsA(&wfUiInfo, wfTargetName, NULL, 0,
|
||||
UserName, CREDUI_MAX_USERNAME_LENGTH + 1,
|
||||
Password, CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags);
|
||||
|
||||
if (status != NO_ERROR)
|
||||
{
|
||||
printf("CredUIPromptForCredentials unexpected status: 0x%08X\n", status);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ZeroMemory(User, sizeof(User));
|
||||
ZeroMemory(Domain, sizeof(Domain));
|
||||
|
||||
status = CredUIParseUserNameA(UserName, User, sizeof(User), Domain, sizeof(Domain));
|
||||
|
||||
//printf("User: %s Domain: %s Password: %s\n", User, Domain, Password);
|
||||
|
||||
*username = _strdup(User);
|
||||
|
||||
if (strlen(Domain) > 0)
|
||||
*domain = _strdup(Domain);
|
||||
|
||||
*password = _strdup(Password);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL wf_verify_certificate(freerdp* instance, char* subject, char* issuer, char* fingerprint)
|
||||
{
|
||||
#if 0
|
||||
@ -713,6 +769,7 @@ INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
instance = freerdp_new();
|
||||
instance->PreConnect = wf_pre_connect;
|
||||
instance->PostConnect = wf_post_connect;
|
||||
instance->Authenticate = wf_authenticate;
|
||||
instance->VerifyCertificate = wf_verify_certificate;
|
||||
instance->ReceiveChannelData = wf_receive_channel_data;
|
||||
|
||||
|
@ -24,9 +24,14 @@
|
||||
#include <winpr/wtypes.h>
|
||||
|
||||
#include <winpr/sspi.h>
|
||||
#include <winpr/error.h>
|
||||
#include <winpr/credentials.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <wincred.h>
|
||||
|
||||
#else
|
||||
|
||||
#define CREDUI_MAX_MESSAGE_LENGTH 32767
|
||||
#define CREDUI_MAX_CAPTION_LENGTH 128
|
||||
|
@ -31,11 +31,19 @@ add_complex_library(MODULE ${MODULE_NAME} TYPE "OBJECT"
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION_FULL} SOVERSION ${WINPR_VERSION} PREFIX "lib")
|
||||
|
||||
if(MONOLITHIC_BUILD)
|
||||
if(WIN32)
|
||||
set(${MODULE_PREFIX}_LIBS ${${MODULE_PREFIX}_LIBS} credui)
|
||||
endif()
|
||||
|
||||
if(MONOLITHIC_BUILD)
|
||||
set(WINPR_LIBS ${WINPR_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)
|
||||
else()
|
||||
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
||||
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR")
|
||||
|
||||
if(BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
3
winpr/libwinpr/credui/test/.gitignore
vendored
Normal file
3
winpr/libwinpr/credui/test/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
TestCredUI
|
||||
TestCredUI.c
|
||||
|
34
winpr/libwinpr/credui/test/CMakeLists.txt
Normal file
34
winpr/libwinpr/credui/test/CMakeLists.txt
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
set(MODULE_NAME "TestCredUI")
|
||||
set(MODULE_PREFIX "TEST_CREDUI")
|
||||
|
||||
set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c)
|
||||
|
||||
set(${MODULE_PREFIX}_TESTS
|
||||
TestCredUIParseUserName.c
|
||||
TestCredUIConfirmCredentials.c
|
||||
TestCredUIPromptForCredentials.c
|
||||
TestCredUICmdLinePromptForCredentials.c)
|
||||
|
||||
create_test_sourcelist(${MODULE_PREFIX}_SRCS
|
||||
${${MODULE_PREFIX}_DRIVER}
|
||||
${${MODULE_PREFIX}_TESTS})
|
||||
|
||||
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
|
||||
|
||||
set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
|
||||
MONOLITHIC ${MONOLITHIC_BUILD}
|
||||
MODULE winpr
|
||||
MODULES winpr-crt winpr-credui)
|
||||
|
||||
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
|
||||
|
||||
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
|
||||
|
||||
foreach(test ${${MODULE_PREFIX}_TESTS})
|
||||
get_filename_component(TestName ${test} NAME_WE)
|
||||
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")
|
||||
|
@ -0,0 +1,37 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/credui.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
static const TCHAR testTargetName[] = _T("TARGET");
|
||||
|
||||
int TestCredUICmdLinePromptForCredentials(int argc, char* argv[])
|
||||
{
|
||||
BOOL fSave;
|
||||
DWORD status;
|
||||
DWORD dwFlags;
|
||||
TCHAR UserName[CREDUI_MAX_USERNAME_LENGTH];
|
||||
TCHAR Password[CREDUI_MAX_PASSWORD_LENGTH];
|
||||
|
||||
fSave = FALSE;
|
||||
ZeroMemory(UserName, sizeof(UserName));
|
||||
ZeroMemory(Password, sizeof(Password));
|
||||
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
|
||||
|
||||
status = CredUICmdLinePromptForCredentials(testTargetName, NULL, 0,
|
||||
UserName, CREDUI_MAX_USERNAME_LENGTH,
|
||||
Password, CREDUI_MAX_PASSWORD_LENGTH, &fSave, dwFlags);
|
||||
|
||||
if (status != NO_ERROR)
|
||||
{
|
||||
printf("CredUIPromptForCredentials unexpected status: 0x%08X\n", status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_tprintf(_T("UserName: %s Password: %s\n"), UserName, Password);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
13
winpr/libwinpr/credui/test/TestCredUIConfirmCredentials.c
Normal file
13
winpr/libwinpr/credui/test/TestCredUIConfirmCredentials.c
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/credui.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
int TestCredUIConfirmCredentials(int argc, char* argv[])
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
43
winpr/libwinpr/credui/test/TestCredUIParseUserName.c
Normal file
43
winpr/libwinpr/credui/test/TestCredUIParseUserName.c
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/credui.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
static const TCHAR testUserName1[] = _T("LAB1\\JohnDoe");
|
||||
static const TCHAR testUserName2[] = _T("JohnDoe@LAB1");
|
||||
|
||||
int TestCredUIParseUserName(int argc, char* argv[])
|
||||
{
|
||||
DWORD status;
|
||||
TCHAR User[CREDUI_MAX_USERNAME_LENGTH + 1];
|
||||
TCHAR Domain[CREDUI_MAX_DOMAIN_TARGET_LENGTH + 1];
|
||||
|
||||
/* Test LAB1\JohnDoe */
|
||||
|
||||
ZeroMemory(User, sizeof(User));
|
||||
ZeroMemory(Domain, sizeof(Domain));
|
||||
|
||||
status = CredUIParseUserName(testUserName1, User, sizeof(User) / sizeof(TCHAR),
|
||||
Domain, sizeof(Domain) / sizeof(TCHAR));
|
||||
|
||||
printf("CredUIParseUserName status: 0x%08X\n", status);
|
||||
|
||||
_tprintf(_T("UserName: %s -> Domain: %s User: %s\n"), testUserName1, Domain, User);
|
||||
|
||||
/* Test JohnDoe@LAB1 */
|
||||
|
||||
ZeroMemory(User, sizeof(User));
|
||||
ZeroMemory(Domain, sizeof(Domain));
|
||||
|
||||
status = CredUIParseUserName(testUserName2, User, sizeof(User) / sizeof(TCHAR),
|
||||
Domain, sizeof(Domain) / sizeof(TCHAR));
|
||||
|
||||
printf("CredUIParseUserName status: 0x%08X\n", status);
|
||||
|
||||
_tprintf(_T("UserName: %s -> Domain: %s User: %s\n"), testUserName2, Domain, User);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
46
winpr/libwinpr/credui/test/TestCredUIPromptForCredentials.c
Normal file
46
winpr/libwinpr/credui/test/TestCredUIPromptForCredentials.c
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/tchar.h>
|
||||
#include <winpr/credui.h>
|
||||
#include <winpr/windows.h>
|
||||
|
||||
static const TCHAR testTargetName[] = _T("TARGET");
|
||||
|
||||
static CREDUI_INFO testUiInfo =
|
||||
{
|
||||
sizeof(CREDUI_INFO),
|
||||
NULL,
|
||||
_T("Message Text"),
|
||||
_T("Caption Text"),
|
||||
NULL
|
||||
};
|
||||
|
||||
int TestCredUIPromptForCredentials(int argc, char* argv[])
|
||||
{
|
||||
BOOL fSave;
|
||||
DWORD status;
|
||||
DWORD dwFlags;
|
||||
TCHAR UserName[CREDUI_MAX_USERNAME_LENGTH];
|
||||
TCHAR Password[CREDUI_MAX_PASSWORD_LENGTH];
|
||||
|
||||
fSave = FALSE;
|
||||
ZeroMemory(UserName, sizeof(UserName));
|
||||
ZeroMemory(Password, sizeof(Password));
|
||||
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
|
||||
|
||||
status = CredUIPromptForCredentials(&testUiInfo, testTargetName, NULL, 0,
|
||||
UserName, CREDUI_MAX_USERNAME_LENGTH,
|
||||
Password, CREDUI_MAX_PASSWORD_LENGTH, &fSave, dwFlags);
|
||||
|
||||
if (status != NO_ERROR)
|
||||
{
|
||||
printf("CredUIPromptForCredentials unexpected status: 0x%08X\n", status);
|
||||
return -1;
|
||||
}
|
||||
|
||||
_tprintf(_T("UserName: %s Password: %s\n"), UserName, Password);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user