From 0ef2179d23a2f9826e17c2b858fd8f2a9634b332 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Mar 2001 01:44:05 +0000 Subject: Fixed reading of strings from big-endian RPC clients. Jeremy. (This used to be commit e7ecb9410ff2e4fcd33bca9f82e14c060590942a) --- source3/lib/util_unistr.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'source3/lib') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 5e6f6a5945..b1cb9ec410 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -161,6 +161,42 @@ char *dos_unistrn2(uint16 *src, int len) return lbuf; } +/******************************************************************* + Return a DOS codepage version of a big or little endian unicode string. + len is the filename length (ignoring any terminating zero) in uin16 + units. Always null terminates. Endian is 1 if it's big endian. + Hack alert: uses fixed buffer(s). +********************************************************************/ + +char *rpc_unistrn2(uint16 *src, int len, BOOL endian) +{ + static char lbufs[8][MAXUNI]; + static int nexti; + char *lbuf = lbufs[nexti]; + char *p; + + nexti = (nexti+1)%8; + + for (p = lbuf; (len > 0) && (p-lbuf < MAXUNI-3) && *src; len--, src++) { + uint16 ucs2_val; + uint16 cp_val; + + RW_SVAL(True,endian,src,ucs2_val,0); + + cp_val = ucs2_to_doscp[ucs2_val]; + + if (cp_val < 256) + *p++ = (char)cp_val; + else { + *p++ = (cp_val >> 8) & 0xff; + *p++ = (cp_val & 0xff); + } + } + + *p = 0; + return lbuf; +} + static char lbufs[8][MAXUNI]; static int nexti; @@ -221,6 +257,38 @@ char *dos_unistr2_to_str(UNISTR2 *str) return lbuf; } +/******************************************************************* +Return a DOS codepage version of a big or little-endian unicode string +********************************************************************/ + +char *rpc_unistr2_to_str(UNISTR2 *str, BOOL endian) +{ + char *lbuf = lbufs[nexti]; + char *p; + uint16 *src = str->buffer; + int max_size = MIN(MAXUNI-3, str->uni_str_len); + + nexti = (nexti+1)%8; + + for (p = lbuf; (p-lbuf < max_size) && *src; src++) { + uint16 ucs2_val; + uint16 cp_val; + + RW_SVAL(True,endian,src,ucs2_val,0); + cp_val = ucs2_to_doscp[ucs2_val]; + + if (cp_val < 256) + *p++ = (char)cp_val; + else { + *p++ = (cp_val >> 8) & 0xff; + *p++ = (cp_val & 0xff); + } + } + + *p = 0; + return lbuf; +} + /******************************************************************* Put an ASCII string into a UNICODE array (uint16's). use little-endian ucs2 -- cgit