From 89af6fd745a6f49668bae5b5c2d239d3671fb299 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 15 Dec 2000 09:31:56 +0000 Subject: lib/util_unistr.c: rewrote unistr2_to_ascii() to correct a bug seen on SGI boxes. rpc_parse/parse_misc.c: rpc_parse/parse_prs.c: rewrote of BUFFER5 handling to NOT byteswap when it was already in network byte order. rpc_parse/parse_samr.c: cleanup of samr_io_q_lookup_domain(), remove the over-parsing by 2 bytes. rpc_server/srv_lsa.c: UNISTR2 strings need to be NULL terminated to pleased W2K. rpc_server/srv_spoolss_nt.c: use snprintf instead of safe_strcpy as we want the string truncated at 32 chars. That should fix SUN and SGI box not able to act as printserver and the problem with joining from a W2K wks. J.F. (This used to be commit 69fe739303b105f2c488f266f13977da1b6b201d) --- source3/lib/util_unistr.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'source3/lib/util_unistr.c') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 74ecc841d0..5e86d5db0b 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -282,38 +282,37 @@ void unistr_to_ascii(char *dest, const uint16 *src, int len) void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen) { - char *destend; - const uint16 *src; + char *p; + uint16 *src; size_t len; - register uint16 c; + int i; + + if (str == NULL) { + *dest='\0'; + return; + } src = str->buffer; len = MIN(str->uni_str_len, maxlen); - destend = dest + len; - while (dest < destend) - { - uint16 ucs2_val; - uint16 cp_val; + if (len == 0) { + *dest='\0'; + return; + } + + for (p = dest; *src && p-dest < len; src++) { + uint16 ucs2_val = SVAL(src,0); + uint16 cp_val = ucs2_to_doscp[ucs2_val]; - c = *src; - if (c == 0) - { - break; - } - - ucs2_val = SVAL(src++,0); - cp_val = ucs2_to_doscp[ucs2_val]; - if (cp_val < 256) - *(dest++) = (char)cp_val; + *p++ = (char)cp_val; else { - *dest= (cp_val >> 8) & 0xff; - *(dest++) = (cp_val & 0xff); + *p = (cp_val >> 8) & 0xff; + *p++ = (cp_val & 0xff); } } - - *dest = 0; + + *p = 0; } -- cgit