Added better argument checks.

This commit is contained in:
Armin Novak 2016-08-03 18:44:15 +02:00
parent 3820c91b80
commit 543631ddd3

View File

@ -55,8 +55,10 @@ rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
freerdp* instance;
rdpContext* context;
pEntryPoints->GlobalInit();
if (!pEntryPoints)
return NULL;
IFCALL(pEntryPoints->GlobalInit);
instance = freerdp_new();
if (!instance)
@ -66,7 +68,8 @@ rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
instance->ContextSize = pEntryPoints->ContextSize;
instance->ContextNew = freerdp_client_common_new;
instance->ContextFree = freerdp_client_common_free;
instance->pClientEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(pEntryPoints->Size);
instance->pClientEntryPoints = (RDP_CLIENT_ENTRY_POINTS*) malloc(
pEntryPoints->Size);
if (!instance->pClientEntryPoints)
goto out_fail;
@ -79,11 +82,8 @@ rdpContext* freerdp_client_context_new(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
context = instance->context;
context->instance = instance;
context->settings = instance->settings;
freerdp_register_addin_provider(freerdp_channels_load_static_addin_entry, 0);
return context;
out_fail2:
free(instance->pClientEntryPoints);
out_fail:
@ -93,7 +93,12 @@ out_fail:
void freerdp_client_context_free(rdpContext* context)
{
freerdp* instance = context->instance;
freerdp* instance;
if (!context)
return;
instance = context->instance;
if (instance)
{
@ -105,23 +110,39 @@ void freerdp_client_context_free(rdpContext* context)
int freerdp_client_start(rdpContext* context)
{
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
if (!context || !context->instance || !context->instance->pClientEntryPoints)
return ERROR_BAD_ARGUMENTS;
pEntryPoints = context->instance->pClientEntryPoints;
return pEntryPoints->ClientStart(context);
}
int freerdp_client_stop(rdpContext* context)
{
RDP_CLIENT_ENTRY_POINTS* pEntryPoints = context->instance->pClientEntryPoints;
RDP_CLIENT_ENTRY_POINTS* pEntryPoints;
if (!context || !context->instance || !context->instance->pClientEntryPoints)
return ERROR_BAD_ARGUMENTS;
pEntryPoints = context->instance->pClientEntryPoints;
return pEntryPoints->ClientStop(context);
}
freerdp* freerdp_client_get_instance(rdpContext* context)
{
if (!context || !context->instance)
return NULL;
return context->instance;
}
HANDLE freerdp_client_get_thread(rdpContext* context)
{
if (!context)
return NULL;
return ((rdpClientContext*) context)->thread;
}
@ -141,6 +162,7 @@ static BOOL freerdp_client_settings_post_process(rdpSettings* settings)
if (!settings->GatewayUsername)
goto out_error;
}
if (settings->Domain)
{
free(settings->GatewayDomain);
@ -149,6 +171,7 @@ static BOOL freerdp_client_settings_post_process(rdpSettings* settings)
if (!settings->GatewayDomain)
goto out_error;
}
if (settings->Password)
{
free(settings->GatewayPassword);
@ -173,7 +196,6 @@ static BOOL freerdp_client_settings_post_process(rdpSettings* settings)
}
return TRUE;
out_error:
free(settings->GatewayUsername);
free(settings->GatewayDomain);
@ -183,7 +205,7 @@ out_error:
int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc,
char** argv, BOOL allowUnknown)
char** argv, BOOL allowUnknown)
{
int status;
@ -193,7 +215,8 @@ int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc,
if (!argv)
return -1;
status = freerdp_client_settings_parse_command_line_arguments(settings, argc, argv, allowUnknown);
status = freerdp_client_settings_parse_command_line_arguments(settings, argc,
argv, allowUnknown);
if (status < 0)
return status;
@ -206,16 +229,19 @@ int freerdp_client_settings_parse_command_line(rdpSettings* settings, int argc,
return status;
}
int freerdp_client_settings_parse_connection_file(rdpSettings* settings, const char* filename)
int freerdp_client_settings_parse_connection_file(rdpSettings* settings,
const char* filename)
{
rdpFile* file;
int ret = -1;
file = freerdp_client_rdp_file_new();
if (!file)
return -1;
if (!freerdp_client_parse_rdp_file(file, filename))
goto out;
if (!freerdp_client_populate_settings_from_rdp_file(file, settings))
goto out;
@ -225,32 +251,33 @@ out:
return ret;
}
int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings, const BYTE* buffer, size_t size)
int freerdp_client_settings_parse_connection_file_buffer(rdpSettings* settings,
const BYTE* buffer, size_t size)
{
rdpFile* file;
int status = -1;
file = freerdp_client_rdp_file_new();
if (!file)
return -1;
if (freerdp_client_parse_rdp_file_buffer(file, buffer, size)
&& freerdp_client_populate_settings_from_rdp_file(file, settings))
&& freerdp_client_populate_settings_from_rdp_file(file, settings))
{
status = 0;
}
freerdp_client_rdp_file_free(file);
return status;
}
int freerdp_client_settings_write_connection_file(const rdpSettings* settings, const char* filename, BOOL unicode)
int freerdp_client_settings_write_connection_file(const rdpSettings* settings,
const char* filename, BOOL unicode)
{
rdpFile* file;
int ret = -1;
file = freerdp_client_rdp_file_new();
if (!file)
return -1;
@ -263,15 +290,14 @@ int freerdp_client_settings_write_connection_file(const rdpSettings* settings, c
ret = 0;
out:
freerdp_client_rdp_file_free(file);
return ret;
}
int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, const char* filename)
int freerdp_client_settings_parse_assistance_file(rdpSettings* settings,
const char* filename)
{
int status;
rdpAssistanceFile* file;
file = freerdp_assistance_file_new();
if (!file)
@ -288,7 +314,6 @@ int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, const c
return -1;
freerdp_assistance_file_free(file);
return 0;
}
@ -304,8 +329,9 @@ int freerdp_client_settings_parse_assistance_file(rdpSettings* settings, const c
* @param domain - unused
* @return TRUE if a password was successfully entered. See freerdp_passphrase_read() for more details.
*/
static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char** username,
char** password, char** domain)
static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway,
char** username,
char** password, char** domain)
{
static const size_t password_size = 512;
const char* auth[] =
@ -329,6 +355,7 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char**
{
size_t username_size = 0;
printf("%s", prompt[0]);
if (GetLine(username, &username_size, stdin) < 0)
{
WLog_ERR(TAG, "GetLine returned %s [%d]", strerror(errno), errno);
@ -346,6 +373,7 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char**
{
size_t domain_size = 0;
printf("%s", prompt[1]);
if (GetLine(domain, &domain_size, stdin) < 0)
{
WLog_ERR(TAG, "GetLine returned %s [%d]", strerror(errno), errno);
@ -362,34 +390,34 @@ static BOOL client_cli_authenticate_raw(freerdp* instance, BOOL gateway, char**
if (!*password)
{
*password = calloc(password_size, sizeof(char));
if (!*password)
goto fail;
if (freerdp_passphrase_read(prompt[2], *password, password_size,
instance->settings->CredentialsFromStdin) == NULL)
instance->settings->CredentialsFromStdin) == NULL)
goto fail;
}
return TRUE;
fail:
free(*username);
free(*domain);
free(*password);
*username = NULL;
*domain = NULL;
*password = NULL;
return FALSE;
}
BOOL client_cli_authenticate(freerdp* instance, char** username, char** password, char** domain)
BOOL client_cli_authenticate(freerdp* instance, char** username,
char** password, char** domain)
{
return client_cli_authenticate_raw(instance, FALSE, username, password, domain);
}
BOOL client_cli_gw_authenticate(freerdp* instance, char** username, char** password, char** domain)
BOOL client_cli_gw_authenticate(freerdp* instance, char** username,
char** password, char** domain)
{
return client_cli_authenticate_raw(instance, TRUE, username, password, domain);
}
@ -409,26 +437,32 @@ static DWORD client_cli_accept_certificate(rdpSettings* settings)
if (feof(stdin))
{
printf("\nError: Could not read answer from stdin.");
if (settings->CredentialsFromStdin)
printf(" - Run without parameter \"--from-stdin\" to set trust.");
printf("\n");
return 0;
}
switch(answer)
switch (answer)
{
case 'y':
case 'Y':
return 1;
case 't':
case 'T':
return 2;
case 'n':
case 'N':
return 0;
default:
break;
}
printf("\n");
}
@ -448,17 +482,16 @@ static DWORD client_cli_accept_certificate(rdpSettings* settings)
* @return 1 if the certificate is trusted, 2 if temporary trusted, 0 otherwise.
*/
DWORD client_cli_verify_certificate(freerdp* instance, const char* common_name,
const char* subject, const char* issuer,
const char* fingerprint, BOOL host_mismatch)
const char* subject, const char* issuer,
const char* fingerprint, BOOL host_mismatch)
{
printf("Certificate details:\n");
printf("\tSubject: %s\n", subject);
printf("\tIssuer: %s\n", issuer);
printf("\tThumbprint: %s\n", fingerprint);
printf("The above X.509 certificate could not be verified, possibly because you do not have\n"
"the CA certificate in your certificate store, or the certificate has expired.\n"
"Please look at the documentation on how to create local certificate store for a private CA.\n");
"the CA certificate in your certificate store, or the certificate has expired.\n"
"Please look at the documentation on how to create local certificate store for a private CA.\n");
return client_cli_accept_certificate(instance->settings);
}
@ -476,11 +509,12 @@ DWORD client_cli_verify_certificate(freerdp* instance, const char* common_name,
* @param old_fingerprint
* @return 1 if the certificate is trusted, 2 if temporary trusted, 0 otherwise.
*/
DWORD client_cli_verify_changed_certificate(freerdp* instance, const char* common_name,
const char* subject, const char* issuer,
const char* fingerprint,
const char* old_subject, const char* old_issuer,
const char* old_fingerprint)
DWORD client_cli_verify_changed_certificate(freerdp* instance,
const char* common_name,
const char* subject, const char* issuer,
const char* fingerprint,
const char* old_subject, const char* old_issuer,
const char* old_fingerprint)
{
printf("!!! Certificate has changed !!!\n");
printf("\n");
@ -495,9 +529,8 @@ DWORD client_cli_verify_changed_certificate(freerdp* instance, const char* commo
printf("\tThumbprint: %s\n", old_fingerprint);
printf("\n");
printf("The above X.509 certificate does not match the certificate used for previous connections.\n"
"This may indicate that the certificate has been tampered with.\n"
"Please contact the administrator of the RDP server and clarify.\n");
"This may indicate that the certificate has been tampered with.\n"
"Please contact the administrator of the RDP server and clarify.\n");
return client_cli_accept_certificate(instance->settings);
}