Merge pull request #2701 from akallabeth/upn_syntax_support

Allowing UPN syntax for user argument.
This commit is contained in:
Marc-André Moreau 2015-06-22 09:31:38 -04:00
commit 86bf5a91c4
2 changed files with 69 additions and 30 deletions

View File

@ -492,8 +492,6 @@ BOOL wf_post_connect(freerdp* instance)
return TRUE; return TRUE;
} }
static const char wfTargetName[] = "TARGET";
static CREDUI_INFOA wfUiInfo = static CREDUI_INFOA wfUiInfo =
{ {
sizeof(CREDUI_INFOA), sizeof(CREDUI_INFOA),
@ -518,7 +516,9 @@ BOOL wf_authenticate(freerdp* instance, char** username, char** password, char**
ZeroMemory(Password, sizeof(Password)); ZeroMemory(Password, sizeof(Password));
dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES; dwFlags = CREDUI_FLAGS_DO_NOT_PERSIST | CREDUI_FLAGS_EXCLUDE_CERTIFICATES;
status = CredUIPromptForCredentialsA(&wfUiInfo, wfTargetName, NULL, 0, status = CredUIPromptForCredentialsA(&wfUiInfo,
instance->settings->ServerHostname,
NULL, 0,
UserName, CREDUI_MAX_USERNAME_LENGTH + 1, UserName, CREDUI_MAX_USERNAME_LENGTH + 1,
Password, CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags); Password, CREDUI_MAX_PASSWORD_LENGTH + 1, &fSave, dwFlags);
@ -537,6 +537,8 @@ BOOL wf_authenticate(freerdp* instance, char** username, char** password, char**
if (strlen(Domain) > 0) if (strlen(Domain) > 0)
*domain = _strdup(Domain); *domain = _strdup(Domain);
else
*domain = _strdup("\0");
*password = _strdup(Password); *password = _strdup(Password);

View File

@ -795,27 +795,58 @@ int freerdp_client_command_line_post_filter(void* context, COMMAND_LINE_ARGUMENT
int freerdp_parse_username(char* username, char** user, char** domain) int freerdp_parse_username(char* username, char** user, char** domain)
{ {
char* p; char* p;
int length; char* u;
int length = 0;
p = strchr(username, '\\'); p = strchr(username, '\\');
u = strrchr(username, '@');
*user = NULL;
*domain = NULL;
if (p) if (p)
{ {
length = (int) (p - username); length = (int) (p - username);
*user = _strdup(&p[1]);
if (!*user)
return -1;
*domain = (char*) calloc(length + 1UL, sizeof(char)); *domain = (char*) calloc(length + 1UL, sizeof(char));
if (!*domain)
{
free (*user);
*user = NULL;
return -1;
}
strncpy(*domain, username, length); strncpy(*domain, username, length);
(*domain)[length] = '\0'; (*domain)[length] = '\0';
*user = _strdup(&p[1]);
} }
else else if (username)
{ {
/* Do not break up the name for '@'; both credSSP and the /* Do not break up the name for '@'; both credSSP and the
* ClientInfo PDU expect 'user@corp.net' to be transmitted * ClientInfo PDU expect 'user@corp.net' to be transmitted
* as username 'user@corp.net', domain empty. * as username 'user@corp.net', domain empty (not NULL!).
*/ */
*user = _strdup(username); *user = _strdup(username);
*domain = NULL; if (!*user)
return -1;
/* If only username is given, prefix that with 'TARGET'
* otherwise set the domain to an empty string.
* NOTE: Domain NULL will result in undefined behavior.
*/
*domain = _strdup("\0");
if (!*domain)
{
free(*user);
*user = NULL;
return -1;
} }
}
else
return -1;
return 0; return 0;
} }
@ -1198,6 +1229,8 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
int argc, char** argv, BOOL allowUnknown) int argc, char** argv, BOOL allowUnknown)
{ {
char* p; char* p;
char* user = NULL;
char* gwUser = NULL;
char* str; char* str;
int length; int length;
int status; int status;
@ -1459,13 +1492,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "u") CommandLineSwitchCase(arg, "u")
{ {
char* user; user = _strdup(arg->Value);
char* domain;
freerdp_parse_username(arg->Value, &user, &domain);
settings->Username = user;
settings->Domain = domain;
} }
CommandLineSwitchCase(arg, "d") CommandLineSwitchCase(arg, "d")
{ {
@ -1506,14 +1533,7 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
CommandLineSwitchCase(arg, "gu") CommandLineSwitchCase(arg, "gu")
{ {
char* user; gwUser = _strdup(arg->Value);
char* domain;
freerdp_parse_username(arg->Value, &user, &domain);
settings->GatewayUsername = user;
settings->GatewayDomain = domain;
settings->GatewayUseSameCredentials = FALSE; settings->GatewayUseSameCredentials = FALSE;
} }
CommandLineSwitchCase(arg, "gd") CommandLineSwitchCase(arg, "gd")
@ -2018,6 +2038,23 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
} }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
if (!settings->Domain && user)
{
freerdp_parse_username(user, &settings->Username, &settings->Domain);
free(user);
}
else
settings->Username = user;
if (!settings->GatewayDomain && gwUser)
{
freerdp_parse_username(gwUser, &settings->GatewayUsername,
&settings->GatewayDomain);
free(gwUser);
}
else
settings->GatewayUsername = gwUser;
freerdp_performance_flags_make(settings); freerdp_performance_flags_make(settings);
if (settings->SupportGraphicsPipeline) if (settings->SupportGraphicsPipeline)