summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-03-13 01:44:05 +0000
committerJeremy Allison <jra@samba.org>2001-03-13 01:44:05 +0000
commit0ef2179d23a2f9826e17c2b858fd8f2a9634b332 (patch)
tree7af8048480b60b9d1e044f78900a19bc93302859 /source3/lib
parent23e5cf060d282c9ba9bdf49884ce23a13b285aac (diff)
downloadsamba-0ef2179d23a2f9826e17c2b858fd8f2a9634b332.tar.gz
samba-0ef2179d23a2f9826e17c2b858fd8f2a9634b332.tar.bz2
samba-0ef2179d23a2f9826e17c2b858fd8f2a9634b332.zip
Fixed reading of strings from big-endian RPC clients.
Jeremy. (This used to be commit e7ecb9410ff2e4fcd33bca9f82e14c060590942a)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/util_unistr.c68
1 files changed, 68 insertions, 0 deletions
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;
@@ -222,6 +258,38 @@ char *dos_unistr2_to_str(UNISTR2 *str)
}
/*******************************************************************
+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
********************************************************************/