Exemplo n.º 1
0
static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)
{
    gchar* s;
    gint port;
    gchar* host;
    gchar* value;
    gint rdpdr_num;
    gint drdynvc_num;
    gint rdpsnd_num;
    const gchar* cs;
    RemminaFile* remminafile;
    rfContext* rfi;

    rfi = GET_DATA(gp);
    remminafile = remmina_plugin_service->protocol_plugin_get_file(gp);

    s = remmina_plugin_service->protocol_plugin_start_direct_tunnel(gp, 3389, FALSE);

    if (s == NULL)
        return FALSE;

    remmina_plugin_service->get_server_port(s, 3389, &host, &port);
    rfi->settings->ServerHostname = strdup(host);
    g_free(host);
    g_free(s);
    rfi->settings->ServerPort = port;

    rfi->settings->ColorDepth = remmina_plugin_service->file_get_int(remminafile, "colordepth", 0);

    if (rfi->settings->ColorDepth == 0)
    {
        rfi->settings->RemoteFxCodec = True;
        rfi->settings->ColorDepth = 32;
    }

    rfi->settings->DesktopWidth = remmina_plugin_service->file_get_int(remminafile, "resolution_width", 1024);
    rfi->settings->DesktopHeight = remmina_plugin_service->file_get_int(remminafile, "resolution_height", 768);
    remmina_plugin_service->protocol_plugin_set_width(gp, rfi->settings->DesktopWidth);
    remmina_plugin_service->protocol_plugin_set_height(gp, rfi->settings->DesktopHeight);

    if (remmina_plugin_service->file_get_string(remminafile, "username"))
        rfi->settings->Username = strdup(remmina_plugin_service->file_get_string(remminafile, "username"));

    if (remmina_plugin_service->file_get_string(remminafile, "domain"))
        rfi->settings->Domain = strdup(remmina_plugin_service->file_get_string(remminafile, "domain"));

    THREADS_ENTER
    s = remmina_plugin_service->file_get_secret(remminafile, "password");
    THREADS_LEAVE

    if (s)
    {
        rfi->settings->Password = strdup(s);
        rfi->settings->AutoLogonEnabled = 1;
        g_free(s);
    }

    if (remmina_plugin_service->file_get_string(remminafile, "clientname"))
    {
        strncpy(rfi->settings->ClientHostname, remmina_plugin_service->file_get_string(remminafile, "clientname"),
                sizeof(rfi->settings->ClientHostname) - 1);
    }
    else
    {
        strncpy(rfi->settings->ClientHostname, g_get_host_name(), sizeof(rfi->settings->ClientHostname) - 1);
    }

    if (remmina_plugin_service->file_get_string(remminafile, "exec"))
    {
        rfi->settings->AlternateShell = strdup(remmina_plugin_service->file_get_string(remminafile, "exec"));
    }

    if (remmina_plugin_service->file_get_string(remminafile, "execpath"))
    {
        rfi->settings->ShellWorkingDirectory = strdup(remmina_plugin_service->file_get_string(remminafile, "execpath"));
    }

    s = g_strdup_printf("rdp_quality_%i", remmina_plugin_service->file_get_int(remminafile, "quality", DEFAULT_QUALITY_0));
    value = remmina_plugin_service->pref_get_value(s);
    g_free(s);

    if (value && value[0])
    {
        rfi->settings->PerformanceFlags = strtoul(value, NULL, 16);
    }
    else
    {
        switch (remmina_plugin_service->file_get_int(remminafile, "quality", DEFAULT_QUALITY_0))
        {
        case 9:
            rfi->settings->PerformanceFlags = DEFAULT_QUALITY_9;
            break;

        case 2:
            rfi->settings->PerformanceFlags = DEFAULT_QUALITY_2;
            break;

        case 1:
            rfi->settings->PerformanceFlags = DEFAULT_QUALITY_1;
            break;

        case 0:
        default:
            rfi->settings->PerformanceFlags = DEFAULT_QUALITY_0;
            break;
        }
    }
    g_free(value);

    rfi->settings->KeyboardLayout = remmina_rdp_settings_get_keyboard_layout();

    if (remmina_plugin_service->file_get_int(remminafile, "console", FALSE))
    {
        rfi->settings->ConsoleSession = True;
    }

    cs = remmina_plugin_service->file_get_string(remminafile, "security");

    if (g_strcmp0(cs, "rdp") == 0)
    {
        rfi->settings->RdpSecurity = True;
        rfi->settings->TlsSecurity = False;
        rfi->settings->NlaSecurity = False;
    }
    else if (g_strcmp0(cs, "tls") == 0)
    {
        rfi->settings->RdpSecurity = False;
        rfi->settings->TlsSecurity = True;
        rfi->settings->NlaSecurity = False;
    }
    else if (g_strcmp0(cs, "nla") == 0)
    {
        rfi->settings->RdpSecurity = False;
        rfi->settings->TlsSecurity = False;
        rfi->settings->NlaSecurity = True;
    }

    rfi->settings->CompressionEnabled = True;
    rfi->settings->FastPathInput = True;
    rfi->settings->FastPathOutput = True;

    drdynvc_num = 0;
    rdpsnd_num = 0;
    cs = remmina_plugin_service->file_get_string(remminafile, "sound");

    if (g_strcmp0(cs, "remote") == 0)
    {
        rfi->settings->RemoteConsoleAudio = 1;
    }
    else if (g_str_has_prefix(cs, "local"))
    {
        cs = strchr(cs, ',');

        if (cs)
        {
            snprintf(rfi->rdpsnd_options, sizeof(rfi->rdpsnd_options), "%s", cs + 1);
            s = strchr(rfi->rdpsnd_options, ',');

            if (s)
                *s++ = '\0';

            rfi->rdpsnd_data[rdpsnd_num].size = sizeof(RDP_PLUGIN_DATA);
            rfi->rdpsnd_data[rdpsnd_num].data[0] = "rate";
            rfi->rdpsnd_data[rdpsnd_num].data[1] = rfi->rdpsnd_options;
            rdpsnd_num++;

            if (s)
            {
                rfi->rdpsnd_data[rdpsnd_num].size = sizeof(RDP_PLUGIN_DATA);
                rfi->rdpsnd_data[rdpsnd_num].data[0] = "channel";
                rfi->rdpsnd_data[rdpsnd_num].data[1] = s;
                rdpsnd_num++;
            }
        }

        remmina_rdp_load_plugin(rfi->channels, rfi->settings, "rdpsnd", rfi->rdpsnd_data);

        rfi->drdynvc_data[drdynvc_num].size = sizeof(RDP_PLUGIN_DATA);
        rfi->drdynvc_data[drdynvc_num].data[0] = "audin";
        drdynvc_num++;
    }

    if (drdynvc_num)
    {
        remmina_rdp_load_plugin(rfi->channels, rfi->settings, "drdynvc", rfi->drdynvc_data);
    }

    if (!remmina_plugin_service->file_get_int(remminafile, "disableclipboard", FALSE))
    {
        remmina_rdp_load_plugin(rfi->channels, rfi->settings, "cliprdr", NULL);
    }

    rdpdr_num = 0;
    cs = remmina_plugin_service->file_get_string(remminafile, "sharefolder");

    if (cs && cs[0] == '/')
    {
        s = strrchr (cs, '/');
        s = (s && s[1] ? s + 1 : "root");
        rfi->rdpdr_data[rdpdr_num].size = sizeof(RDP_PLUGIN_DATA);
        rfi->rdpdr_data[rdpdr_num].data[0] = "disk";
        rfi->rdpdr_data[rdpdr_num].data[1] = s;
        rfi->rdpdr_data[rdpdr_num].data[2] = (gchar*) cs;
        rdpdr_num++;
    }

    if (remmina_plugin_service->file_get_int(remminafile, "shareprinter", FALSE))
    {
        rfi->rdpdr_data[rdpdr_num].size = sizeof(RDP_PLUGIN_DATA);
        rfi->rdpdr_data[rdpdr_num].data[0] = "printer";
        rdpdr_num++;
    }

    if (remmina_plugin_service->file_get_int(remminafile, "sharesmartcard", FALSE))
    {
        rfi->rdpdr_data[rdpdr_num].size = sizeof(RDP_PLUGIN_DATA);
        rfi->rdpdr_data[rdpdr_num].data[0] = "scard";
        rfi->rdpdr_data[rdpdr_num].data[1] = "scard";
        rdpdr_num++;
    }

    if (rdpdr_num)
    {
        remmina_rdp_load_plugin(rfi->channels, rfi->settings, "rdpdr", rfi->rdpdr_data);
    }

    if (!freerdp_connect(rfi->instance))
    {
        if (!rfi->user_cancelled)
        {
            remmina_plugin_service->protocol_plugin_set_error(gp, _("Unable to connect to RDP server %s"),
                    rfi->settings->ServerHostname);
        }

        return FALSE;
    }

    remmina_rdp_main_loop(gp);

    return TRUE;
}
Exemplo n.º 2
0
static gboolean remmina_rdp_main(RemminaProtocolWidget* gp)
{
	gchar* s;
	gint port;
	gchar* host;
	gchar* value;
	gint rdpsnd_rate;
	gint rdpsnd_channel;
	char *rdpsnd_params[3];
	int rdpsnd_nparams;
	char rdpsnd_param1[16];
	char rdpsnd_param2[16];
	const gchar* cs;
	RemminaFile* remminafile;
	rfContext* rfi;

	gchar *dest_server, *dest_host;
	gint dest_port;

	rfi = GET_DATA(gp);
	remminafile = remmina_plugin_service->protocol_plugin_get_file(gp);

	s = remmina_plugin_service->protocol_plugin_start_direct_tunnel(gp, 3389, FALSE);

	if (s == NULL)
		return FALSE;

	remmina_plugin_service->get_server_port(s, 3389, &host, &port);
	rfi->settings->ServerHostname = strdup(host);
	g_free(host);
	g_free(s);
	rfi->settings->ServerPort = port;

	// Setup rfi->settings->CertificateName when tunneled with SSH
	if (remmina_plugin_service->file_get_int(remminafile, "ssh_enabled", FALSE)) {
		dest_server = remmina_plugin_service->file_get_string(remminafile, "server");
		if ( dest_server ) {
			remmina_plugin_service->get_server_port(dest_server, 0, &dest_host, &dest_port);
			rfi->settings->CertificateName = strdup( dest_host );
			g_free(dest_host);
		}
	}

	rfi->settings->ColorDepth = remmina_plugin_service->file_get_int(remminafile, "colordepth", 0);

	if (rfi->settings->ColorDepth == 0)
	{
		rfi->settings->RemoteFxCodec = True;
		rfi->settings->ColorDepth = 32;
	}

	rfi->settings->DesktopWidth = remmina_plugin_service->file_get_int(remminafile, "resolution_width", 1024);
	rfi->settings->DesktopHeight = remmina_plugin_service->file_get_int(remminafile, "resolution_height", 768);
	remmina_plugin_service->protocol_plugin_set_width(gp, rfi->settings->DesktopWidth);
	remmina_plugin_service->protocol_plugin_set_height(gp, rfi->settings->DesktopHeight);

	if (remmina_plugin_service->file_get_string(remminafile, "username"))
		rfi->settings->Username = strdup(remmina_plugin_service->file_get_string(remminafile, "username"));

	if (remmina_plugin_service->file_get_string(remminafile, "domain"))
		rfi->settings->Domain = strdup(remmina_plugin_service->file_get_string(remminafile, "domain"));

	THREADS_ENTER
	s = remmina_plugin_service->file_get_secret(remminafile, "password");
	THREADS_LEAVE

	if (s)
	{
		rfi->settings->Password = strdup(s);
		rfi->settings->AutoLogonEnabled = 1;
		g_free(s);
	}

	if (remmina_plugin_service->file_get_string(remminafile, "clientname"))
	{
		s = remmina_plugin_service->file_get_string(remminafile, "clientname");
		if ( s ) {
			free( rfi->settings->ClientHostname );
			rfi->settings->ClientHostname = strdup(s);
			g_free(s);
		}
	}
	else
	{
		free( rfi->settings->ClientHostname );
		rfi->settings->ClientHostname = strdup( g_get_host_name() );
	}

	if (remmina_plugin_service->file_get_string(remminafile, "exec"))
	{
		rfi->settings->AlternateShell = strdup(remmina_plugin_service->file_get_string(remminafile, "exec"));
	}

	if (remmina_plugin_service->file_get_string(remminafile, "execpath"))
	{
		rfi->settings->ShellWorkingDirectory = strdup(remmina_plugin_service->file_get_string(remminafile, "execpath"));
	}

	s = g_strdup_printf("rdp_quality_%i", remmina_plugin_service->file_get_int(remminafile, "quality", DEFAULT_QUALITY_0));
	value = remmina_plugin_service->pref_get_value(s);
	g_free(s);

	if (value && value[0])
	{
		rfi->settings->PerformanceFlags = strtoul(value, NULL, 16);
	}
	else
	{
		switch (remmina_plugin_service->file_get_int(remminafile, "quality", DEFAULT_QUALITY_0))
		{
			case 9:
				rfi->settings->PerformanceFlags = DEFAULT_QUALITY_9;
				break;

			case 2:
				rfi->settings->PerformanceFlags = DEFAULT_QUALITY_2;
				break;

			case 1:
				rfi->settings->PerformanceFlags = DEFAULT_QUALITY_1;
				break;

			case 0:
			default:
				rfi->settings->PerformanceFlags = DEFAULT_QUALITY_0;
				break;
		}
	}
	g_free(value);

	rfi->settings->KeyboardLayout = remmina_rdp_settings_get_keyboard_layout();

	if (remmina_plugin_service->file_get_int(remminafile, "console", FALSE))
	{
		rfi->settings->ConsoleSession = True;
	}

	cs = remmina_plugin_service->file_get_string(remminafile, "security");

	if (g_strcmp0(cs, "rdp") == 0)
	{
		rfi->settings->RdpSecurity = True;
		rfi->settings->TlsSecurity = False;
		rfi->settings->NlaSecurity = False;
	}
	else if (g_strcmp0(cs, "tls") == 0)
	{
		rfi->settings->RdpSecurity = False;
		rfi->settings->TlsSecurity = True;
		rfi->settings->NlaSecurity = False;
	}
	else if (g_strcmp0(cs, "nla") == 0)
	{
		rfi->settings->RdpSecurity = False;
		rfi->settings->TlsSecurity = False;
		rfi->settings->NlaSecurity = True;
	}

	rfi->settings->CompressionEnabled = True;
	rfi->settings->FastPathInput = True;
	rfi->settings->FastPathOutput = True;

	cs = remmina_plugin_service->file_get_string(remminafile, "sound");

	if (g_strcmp0(cs, "remote") == 0)
	{
		rfi->settings->RemoteConsoleAudio = 1;
	}
	else if (g_str_has_prefix(cs, "local"))
	{

		rdpsnd_nparams = 0;
		rdpsnd_params[rdpsnd_nparams++] = "rdpsnd";

		cs = strchr(cs, ',');
		if (cs)
		{
			rdpsnd_rate = atoi(cs + 1);
			if (rdpsnd_rate > 1000 && rdpsnd_rate < 150000)
			{
				snprintf( rdpsnd_param1, sizeof(rdpsnd_param1), "rate:%d", rdpsnd_rate );
				rdpsnd_params[rdpsnd_nparams++] = rdpsnd_param1;
				cs = strchr(cs +1, ',');
				if (cs)
				{
					rdpsnd_channel = atoi(cs + 1);
					if (rdpsnd_channel >= 1 && rdpsnd_channel <= 2)
					{
						snprintf( rdpsnd_param2, sizeof(rdpsnd_param2), "channel:%d", rdpsnd_channel );
						rdpsnd_params[rdpsnd_nparams++] = rdpsnd_param2;
					}
				}
			}
		}

		remmina_rdp_add_static_channel(rfi->settings, rdpsnd_nparams, (char**) rdpsnd_params);

	}

	rfi->settings->RedirectClipboard = ( remmina_plugin_service->file_get_int(remminafile, "disableclipboard", FALSE) ? FALSE: TRUE );

	cs = remmina_plugin_service->file_get_string(remminafile, "sharefolder");

	if (cs && cs[0] == '/')
	{
		RDPDR_DRIVE* drive;
		gsize sz;

		drive = (RDPDR_DRIVE*) malloc(sizeof(RDPDR_DRIVE));
		ZeroMemory(drive, sizeof(RDPDR_DRIVE));

		s = strrchr( cs, '/' );
		if ( s == NULL || s[1] == 0 )
			s = remmina_rdp_plugin_default_drive_name;
		else
			s++;
		s = g_convert_with_fallback(s, -1, "ascii", "utf-8", "_", NULL, &sz, NULL);

		drive->Type = RDPDR_DTYP_FILESYSTEM;
		drive->Name = _strdup(s);
		drive->Path = _strdup(cs);
		g_free(s);

		freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) drive);
		rfi->settings->DeviceRedirection = TRUE;
	}

	if (remmina_plugin_service->file_get_int(remminafile, "shareprinter", FALSE))
	{
		RDPDR_PRINTER* printer;
		printer = (RDPDR_PRINTER*) malloc(sizeof(RDPDR_PRINTER));
		ZeroMemory(printer, sizeof(RDPDR_PRINTER));

		printer->Type = RDPDR_DTYP_PRINT;

		freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) printer);
		rfi->settings->DeviceRedirection = TRUE;

	}

	if (remmina_plugin_service->file_get_int(remminafile, "sharesmartcard", FALSE))
	{
		RDPDR_SMARTCARD* smartcard;
		smartcard = (RDPDR_SMARTCARD*) malloc(sizeof(RDPDR_SMARTCARD));
		ZeroMemory(smartcard, sizeof(RDPDR_SMARTCARD));

		smartcard->Type = RDPDR_DTYP_SMARTCARD;
		smartcard->Name = _strdup("scard");

		freerdp_device_collection_add(rfi->settings, (RDPDR_DEVICE*) smartcard);
		rfi->settings->DeviceRedirection = TRUE;
	}


	if (!freerdp_connect(rfi->instance))
	{
		if (!rfi->user_cancelled)
		{
			remmina_plugin_service->protocol_plugin_set_error(gp, _("Unable to connect to RDP server %s"), rfi->settings->ServerHostname);

		}

		return FALSE;
	}



	remmina_rdp_main_loop(gp);

	return TRUE;
}