Ejemplo n.º 1
0
/** Callback set in the rdp_freerdp structure, and used to get the user's password,
 *  if required to establish the connection.
 *  This function is actually called in credssp_ntlmssp_client_init()
 *  @see rdp_server_accept_nego() and rdp_check_fds()
 *  @param instance - pointer to the rdp_freerdp structure that contains the connection settings
 *  @param username - unused
 *  @param password - on return: pointer to a character string that will be filled by the password entered by the user.
 *  				  Note that this character string will be allocated inside the function, and needs to be deallocated by the caller
 *  				  using free(), even in case this function fails.
 *  @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 const size_t password_size = 512;
	const char* auth[] =
	{
		"Username: "******"Domain:   ",
		"Password: "******"GatewayUsername: "******"GatewayDomain:   ",
		"GatewayPassword: "******"%s", prompt[0]);

		if (GetLine(username, &username_size, stdin) < 0)
		{
			WLog_ERR(TAG, "GetLine returned %s [%d]", strerror(errno), errno);
			goto fail;
		}

		if (*username)
		{
			*username = StrSep(username, "\r");
			*username = StrSep(username, "\n");
		}
	}

	if (!*domain)
	{
		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);
			goto fail;
		}

		if (*domain)
		{
			*domain = StrSep(domain, "\r");
			*domain = StrSep(domain, "\n");
		}
	}

	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)
			goto fail;
	}

	return TRUE;
fail:
	free(*username);
	free(*domain);
	free(*password);
	*username = NULL;
	*domain = NULL;
	*password = NULL;
	return FALSE;
}
Ejemplo n.º 2
0
int main(int argc, char* argv[])
{
	WSADATA wsaData;
	freerdp_listener* instance;
	char* file;
	char name[MAX_PATH];
	long port = 3389, i;
	BOOL localOnly = FALSE;
	errno = 0;

	for (i = 1; i < argc; i++)
	{
		char* arg = argv[i];

		if (strncmp(arg, "--fast", 7) == 0)
			test_dump_rfx_realtime = FALSE;
		else if (strncmp(arg, "--port=", 7) == 0)
		{
			StrSep(&arg, "=");

			if (!arg)
				return -1;

			port = strtol(arg, NULL, 10);

			if ((port < 1) || (port > 0xFFFF) || (errno != 0))
				return -1;
		}
		else if (strcmp(arg, "--local-only"))
			localOnly = TRUE;
		else if (strncmp(arg, "--", 2))
			test_pcap_file = arg;
	}

	WTSRegisterWtsApiFunctionTable(FreeRDP_InitWtsApi());
	winpr_InitializeSSL(WINPR_SSL_INIT_DEFAULT);
	instance = freerdp_listener_new();

	if (!instance)
		return -1;

	instance->PeerAccepted = test_peer_accepted;

	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		freerdp_listener_free(instance);
		return -1;
	}

	/* Open the server socket and start listening. */
	sprintf_s(name, sizeof(name), "tfreerdp-server.%ld", port);
	file = GetKnownSubPath(KNOWN_PATH_TEMP, name);

	if (!file)
	{
		freerdp_listener_free(instance);
		WSACleanup();
		return -1;
	}

	if ((localOnly || instance->Open(instance, NULL, port)) &&
	    instance->OpenLocal(instance, file))
	{
		/* Entering the server main loop. In a real server the listener can be run in its own thread. */
		test_server_mainloop(instance);
	}

	free(file);
	freerdp_listener_free(instance);
	WSACleanup();
	return 0;
}