1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/*
* Remmina - The GTK+ Remote Desktop Client
* Copyright (C) 2010-2011 Vic Lee
* Copyright (C) 2014-2015 Antenore Gatta, Fabio Castelli, Giovanni Panozzo
* Copyright (C) 2016-2019 Antenore Gatta, Giovanni Panozzo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations
* including the two.
* You must obey the GNU General Public License in all respects
* for all of the code used other than OpenSSL. * If you modify
* file(s) with this exception, you may extend this exception to your
* version of the file(s), but you are not obligated to do so. * If you
* do not wish to do so, delete this exception statement from your
* version. * If you delete this exception statement from all source
* files in the program, then also delete it here.
*
*/
#include "common/remmina_plugin.h"
#include "rdp_plugin.h"
#include "rdp_file.h"
gboolean remmina_rdp_file_import_test(const gchar* from_file)
{
TRACE_CALL(__func__);
gchar* ext;
ext = strrchr(from_file, '.');
if (!ext)
return FALSE;
ext++;
if (g_strcmp0(ext, "RDP") == 0)
return TRUE;
if (g_strcmp0(ext, "rdp") == 0)
return TRUE;
return FALSE;
}
static void remmina_rdp_file_import_field(RemminaFile* remminafile, const gchar* key, const gchar* value)
{
TRACE_CALL(__func__);
if (g_strcmp0(key, "desktopwidth") == 0) {
remmina_plugin_service->file_set_string(remminafile, "resolution_width", value);
}else if (g_strcmp0(key, "desktopheight") == 0) {
remmina_plugin_service->file_set_string(remminafile, "resolution_height", value);
}else if (g_strcmp0(key, "session bpp") == 0) {
remmina_plugin_service->file_set_string(remminafile, "colordepth", value);
}else if (g_strcmp0(key, "keyboardhook") == 0) {
remmina_plugin_service->file_set_int(remminafile, "keyboard_grab", (atoi(value) == 1));
}else if (g_strcmp0(key, "full address") == 0) {
remmina_plugin_service->file_set_string(remminafile, "server", value);
}else if (g_strcmp0(key, "audiomode") == 0) {
switch (atoi(value)) {
case 0:
remmina_plugin_service->file_set_string(remminafile, "sound", "local");
break;
case 1:
remmina_plugin_service->file_set_string(remminafile, "sound", "remote");
break;
}
}else if (g_strcmp0(key, "microphone") == 0) {
remmina_plugin_service->file_set_int(remminafile, "microphone", (atoi(value) == 1));
}else if (g_strcmp0(key, "redirectprinters") == 0) {
remmina_plugin_service->file_set_int(remminafile, "shareprinter", (atoi(value) == 1));
}else if (g_strcmp0(key, "redirectsmartcard") == 0) {
remmina_plugin_service->file_set_int(remminafile, "sharesmartcard", (atoi(value) == 1));
}else if (g_strcmp0(key, "redirectclipboard") == 0) {
remmina_plugin_service->file_set_int(remminafile, "disableclipboard", (atoi(value) != 1));
}else if (g_strcmp0(key, "alternate shell") == 0) {
remmina_plugin_service->file_set_string(remminafile, "exec", value);
}else if (g_strcmp0(key, "shell working directory") == 0) {
remmina_plugin_service->file_set_string(remminafile, "execpath", value);
}else if (g_strcmp0(key, "loadbalanceinfo") == 0) {
remmina_plugin_service->file_set_string(remminafile, "loadbalanceinfo", value);
}else if (g_strcmp0(key, "gatewayhostname") == 0) {
remmina_plugin_service->file_set_string(remminafile, "gateway_server", value);
}else if (g_strcmp0(key, "gatewayusagemethod") == 0) {
remmina_plugin_service->file_set_int(remminafile, "gateway_usage", (atoi(value) == TSC_PROXY_MODE_DETECT));
} else if (g_strcmp0(key, "gatewayaccesstoken") == 0) {
remmina_plugin_service->file_set_string(remminafile, "gatewayaccesstoken", value);
} else if (g_strcmp0(key, "authentication level") == 0) {
remmina_plugin_service->file_set_int(remminafile, "authentication level", atoi(value));
}
/* tsclient fields, import only */
else if (g_strcmp0(key, "client hostname") == 0) {
remmina_plugin_service->file_set_string(remminafile, "clientname", value);
}else if (g_strcmp0(key, "domain") == 0) {
remmina_plugin_service->file_set_string(remminafile, "domain", value);
}else if (g_strcmp0(key, "username") == 0) {
remmina_plugin_service->file_set_string(remminafile, "username", value);
}else if (g_strcmp0(key, "password") == 0) {
remmina_plugin_service->file_set_string(remminafile, "password", value);
}
}
static RemminaFile* remmina_rdp_file_import_channel(GIOChannel* channel)
{
TRACE_CALL(__func__);
gchar* p;
const gchar* enc;
gchar* line = NULL;
GError* error = NULL;
gsize bytes_read = 0;
RemminaFile* remminafile;
guchar magic[2] = { 0 };
if (g_io_channel_set_encoding(channel, NULL, &error) != G_IO_STATUS_NORMAL) {
g_print("g_io_channel_set_encoding: %s\n", error->message);
return NULL;
}
/* Try to detect the UTF-16 encoding */
if (g_io_channel_read_chars(channel, (gchar*)magic, 2, &bytes_read, &error) != G_IO_STATUS_NORMAL) {
g_print("g_io_channel_read_chars: %s\n", error->message);
return NULL;
}
if (magic[0] == 0xFF && magic[1] == 0xFE) {
enc = "UTF-16LE";
}else if (magic[0] == 0xFE && magic[1] == 0xFF) {
enc = "UTF-16BE";
}else {
enc = "UTF-8";
if (g_io_channel_seek_position(channel, 0, G_SEEK_SET, &error) != G_IO_STATUS_NORMAL) {
g_print("g_io_channel_seek: failed\n");
return NULL;
}
}
if (g_io_channel_set_encoding(channel, enc, &error) != G_IO_STATUS_NORMAL) {
g_print("g_io_channel_set_encoding: %s\n", error->message);
return NULL;
}
remminafile = remmina_plugin_service->file_new();
while (g_io_channel_read_line(channel, &line, NULL, &bytes_read, &error) == G_IO_STATUS_NORMAL) {
if (line == NULL)
break;
line[bytes_read] = '\0';
p = strchr(line, ':');
if (p) {
*p++ = '\0';
p = strchr(p, ':');
if (p) {
p++;
remmina_rdp_file_import_field(remminafile, line, p);
}
}
g_free(line);
}
remmina_plugin_service->file_set_string(remminafile, "name",
remmina_plugin_service->file_get_string(remminafile, "server"));
remmina_plugin_service->file_set_string(remminafile, "protocol", "RDP");
return remminafile;
}
RemminaFile* remmina_rdp_file_import(const gchar* from_file)
{
TRACE_CALL(__func__);
GIOChannel* channel;
GError* error = NULL;
RemminaFile* remminafile;
channel = g_io_channel_new_file(from_file, "r", &error);
if (channel == NULL) {
g_print("Failed to import %s: %s\n", from_file, error->message);
return NULL;
}
remminafile = remmina_rdp_file_import_channel(channel);
g_io_channel_shutdown(channel, TRUE, &error);
return remminafile;
}
gboolean remmina_rdp_file_export_test(RemminaFile* remminafile)
{
TRACE_CALL(__func__);
if (g_strcmp0(remmina_plugin_service->file_get_string(remminafile, "protocol"), "RDP") == 0)
return TRUE;
return FALSE;
}
gboolean remmina_rdp_file_export_channel(RemminaFile* remminafile, FILE* fp)
{
TRACE_CALL(__func__);
const gchar* cs;
int w, h;
fprintf(fp, "screen mode id:i:2\r\n");
w = remmina_plugin_service->file_get_int(remminafile, "resolution_width", -1);
h = remmina_plugin_service->file_get_int(remminafile, "resolution_height", -1);
if ( w > 0 && h > 0 ) {
fprintf(fp, "desktopwidth:i:%d\r\n", w);
fprintf(fp, "desktopheight:i:%d\r\n", h);
}
fprintf(fp, "session bpp:i:%i\r\n", remmina_plugin_service->file_get_int(remminafile, "colordepth", 8));
//fprintf(fp, "winposstr:s:0,1,123,34,931,661\r\n");
fprintf(fp, "compression:i:1\r\n");
fprintf(fp, "keyboardhook:i:2\r\n");
fprintf(fp, "displayconnectionbar:i:1\r\n");
fprintf(fp, "disable wallpaper:i:1\r\n");
fprintf(fp, "disable full window drag:i:1\r\n");
fprintf(fp, "allow desktop composition:i:0\r\n");
fprintf(fp, "allow font smoothing:i:0\r\n");
fprintf(fp, "disable menu anims:i:1\r\n");
fprintf(fp, "disable themes:i:0\r\n");
fprintf(fp, "disable cursor setting:i:0\r\n");
fprintf(fp, "bitmapcachepersistenable:i:1\r\n");
cs = remmina_plugin_service->file_get_string(remminafile, "server");
fprintf(fp, "full address:s:%s\r\n", cs ? cs : "" );
if (g_strcmp0(remmina_plugin_service->file_get_string(remminafile, "sound"), "local") == 0)
fprintf(fp, "audiomode:i:0\r\n");
else if (g_strcmp0(remmina_plugin_service->file_get_string(remminafile, "sound"), "remote") == 0)
fprintf(fp, "audiomode:i:1\r\n");
else
fprintf(fp, "audiomode:i:2\r\n");
fprintf(fp, "microphone:i:%i\r\n", remmina_plugin_service->file_get_int(remminafile, "microphone", FALSE) ? 1 : 0);
fprintf(fp, "redirectprinters:i:%i\r\n", remmina_plugin_service->file_get_int(remminafile, "shareprinter", FALSE) ? 1 : 0);
fprintf(fp, "redirectsmartcard:i:%i\r\n", remmina_plugin_service->file_get_int(remminafile, "sharesmartcard", FALSE) ? 1 : 0);
fprintf(fp, "redirectcomports:i:0\r\n");
fprintf(fp, "redirectsmartcards:i:0\r\n");
fprintf(fp, "redirectclipboard:i:1\r\n");
fprintf(fp, "redirectposdevices:i:0\r\n");
fprintf(fp, "autoreconnection enabled:i:1\r\n");
fprintf(fp, "authentication level:i:0\r\n");
fprintf(fp, "prompt for credentials:i:1\r\n");
fprintf(fp, "negotiate security layer:i:1\r\n");
fprintf(fp, "remoteapplicationmode:i:0\r\n");
cs = remmina_plugin_service->file_get_string(remminafile, "exec");
fprintf(fp, "alternate shell:s:%s\r\n", cs ? cs : "");
cs = remmina_plugin_service->file_get_string(remminafile, "execpath");
fprintf(fp, "shell working directory:s:%s\r\n", cs ? cs : "");
fprintf(fp, "gatewayhostname:s:\r\n");
fprintf(fp, "gatewayusagemethod:i:4\r\n");
fprintf(fp, "gatewaycredentialssource:i:4\r\n");
fprintf(fp, "gatewayprofileusagemethod:i:0\r\n");
fprintf(fp, "precommand:s:\r\n");
fprintf(fp, "promptcredentialonce:i:1\r\n");
fprintf(fp, "drivestoredirect:s:\r\n");
return TRUE;
}
gboolean remmina_rdp_file_export(RemminaFile* remminafile, const gchar* to_file)
{
TRACE_CALL(__func__);
FILE* fp;
gchar* p;
gboolean ret;
p = strrchr(to_file, '.');
if (p && (g_strcmp0(p + 1, "rdp") == 0 || g_strcmp0(p + 1, "RDP") == 0)) {
p = g_strdup(to_file);
}else {
p = g_strdup_printf("%s.rdp", to_file);
}
fp = g_fopen(p, "w+");
if (fp == NULL) {
g_print("Failed to export %s\n", p);
g_free(p);
return FALSE;
}
g_free(p);
ret = remmina_rdp_file_export_channel(remminafile, fp);
fclose(fp);
return ret;
}
|