243 |
* Returns str_len of string |
* Returns str_len of string |
244 |
*/ |
*/ |
245 |
int |
int |
246 |
rdp_in_unistr(STREAM s, char *string, int uni_len) |
rdp_in_unistr(STREAM s, char *string, int str_size, int in_len) |
247 |
{ |
{ |
248 |
#ifdef HAVE_ICONV |
#ifdef HAVE_ICONV |
249 |
size_t ibl = uni_len, obl = uni_len; |
size_t ibl = in_len, obl = str_size-1; |
250 |
char *pin = (char *) s->p, *pout = string; |
char *pin = (char *) s->p, *pout = string; |
251 |
static iconv_t iconv_h = (iconv_t) - 1; |
static iconv_t iconv_h = (iconv_t) - 1; |
252 |
|
|
260 |
WINDOWS_CODEPAGE, g_codepage, iconv_h); |
WINDOWS_CODEPAGE, g_codepage, iconv_h); |
261 |
|
|
262 |
g_iconv_works = False; |
g_iconv_works = False; |
263 |
return rdp_in_unistr(s, string, uni_len); |
return rdp_in_unistr(s, string, str_size, in_len); |
264 |
} |
} |
265 |
} |
} |
266 |
|
|
267 |
if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1) |
if (iconv(iconv_h, (ICONV_CONST char **) &pin, &ibl, &pout, &obl) == (size_t) - 1) |
268 |
{ |
{ |
269 |
iconv_close(iconv_h); |
if (errno == E2BIG) |
270 |
iconv_h = (iconv_t) - 1; |
{ |
271 |
warning("rdp_in_unistr: iconv fail, errno %d\n", errno); |
warning("server sent an unexpectedly long string, truncating\n"); |
272 |
|
} |
273 |
|
else |
274 |
|
{ |
275 |
|
iconv_close(iconv_h); |
276 |
|
iconv_h = (iconv_t) - 1; |
277 |
|
warning("rdp_in_unistr: iconv fail, errno %d\n", errno); |
278 |
|
|
279 |
g_iconv_works = False; |
g_iconv_works = False; |
280 |
return rdp_in_unistr(s, string, uni_len); |
return rdp_in_unistr(s, string, str_size, in_len); |
281 |
|
} |
282 |
} |
} |
283 |
|
|
284 |
/* we must update the location of the current STREAM for future reads of s->p */ |
/* we must update the location of the current STREAM for future reads of s->p */ |
285 |
s->p += uni_len; |
s->p += in_len; |
286 |
|
|
287 |
|
*pout = 0; |
288 |
return pout - string; |
return pout - string; |
289 |
} |
} |
290 |
else |
else |
291 |
#endif |
#endif |
292 |
{ |
{ |
293 |
int i = 0; |
int i = 0; |
294 |
|
int len = in_len/2; |
295 |
|
int rem = 0; |
296 |
|
|
297 |
|
if (len > str_size-1) |
298 |
|
{ |
299 |
|
warning("server sent an unexpectedly long string, truncating\n"); |
300 |
|
len = str_size-1; |
301 |
|
rem = in_len - 2*len; |
302 |
|
} |
303 |
|
|
304 |
while (i < uni_len / 2) |
while (i < len) |
305 |
{ |
{ |
306 |
in_uint8a(s, &string[i++], 1); |
in_uint8a(s, &string[i++], 1); |
307 |
in_uint8s(s, 1); |
in_uint8s(s, 1); |
308 |
} |
} |
309 |
|
|
310 |
return i - 1; |
in_uint8s(s, rem); |
311 |
|
string[len] = 0; |
312 |
|
return len; |
313 |
} |
} |
314 |
} |
} |
315 |
|
|
1344 |
in_uint32_le(s, len); |
in_uint32_le(s, len); |
1345 |
|
|
1346 |
/* read ip string */ |
/* read ip string */ |
1347 |
rdp_in_unistr(s, g_redirect_server, len); |
rdp_in_unistr(s, g_redirect_server, sizeof(g_redirect_server), len); |
1348 |
|
|
1349 |
/* read length of cookie string */ |
/* read length of cookie string */ |
1350 |
in_uint32_le(s, len); |
in_uint32_le(s, len); |
1351 |
|
|
1352 |
/* read cookie string (plain ASCII) */ |
/* read cookie string (plain ASCII) */ |
1353 |
in_uint8a(s, g_redirect_cookie, len); |
if (len > sizeof(g_redirect_cookie)-1) |
1354 |
|
{ |
1355 |
|
uint32 rem = len - (sizeof(g_redirect_cookie)-1); |
1356 |
|
len = sizeof(g_redirect_cookie)-1; |
1357 |
|
|
1358 |
|
warning("Unexpectedly large redirection cookie\n"); |
1359 |
|
in_uint8a(s, g_redirect_cookie, len); |
1360 |
|
in_uint8s(s, rem); |
1361 |
|
} |
1362 |
|
else |
1363 |
|
{ |
1364 |
|
in_uint8a(s, g_redirect_cookie, len); |
1365 |
|
} |
1366 |
g_redirect_cookie[len] = 0; |
g_redirect_cookie[len] = 0; |
1367 |
|
|
1368 |
/* read length of username string */ |
/* read length of username string */ |
1369 |
in_uint32_le(s, len); |
in_uint32_le(s, len); |
1370 |
|
|
1371 |
/* read username string */ |
/* read username string */ |
1372 |
rdp_in_unistr(s, g_redirect_username, len); |
rdp_in_unistr(s, g_redirect_username, sizeof(g_redirect_username), len); |
1373 |
|
|
1374 |
/* read length of domain string */ |
/* read length of domain string */ |
1375 |
in_uint32_le(s, len); |
in_uint32_le(s, len); |
1376 |
|
|
1377 |
/* read domain string */ |
/* read domain string */ |
1378 |
rdp_in_unistr(s, g_redirect_domain, len); |
rdp_in_unistr(s, g_redirect_domain, sizeof(g_redirect_domain), len); |
1379 |
|
|
1380 |
/* read length of password string */ |
/* read length of password string */ |
1381 |
in_uint32_le(s, len); |
in_uint32_le(s, len); |
1382 |
|
|
1383 |
/* read password string */ |
/* read password string */ |
1384 |
rdp_in_unistr(s, g_redirect_password, len); |
rdp_in_unistr(s, g_redirect_password, sizeof(g_redirect_password), len); |
1385 |
|
|
1386 |
g_redirect = True; |
g_redirect = True; |
1387 |
|
|