summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-09-21 18:37:09 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:00:58 -0500
commit3a60a6743262ab2ab221e0fe13ef6b510424ca3f (patch)
tree7029367395949ad4ce03813c2a7361e934a1cf4d
parentc8ef27a3c3db3f04d592652fd6103c5b5cf83d03 (diff)
downloadsamba-3a60a6743262ab2ab221e0fe13ef6b510424ca3f.tar.gz
samba-3a60a6743262ab2ab221e0fe13ef6b510424ca3f.tar.bz2
samba-3a60a6743262ab2ab221e0fe13ef6b510424ca3f.zip
r18793: Fix BE string handling in the auto-generated
code. Should now work again with ASU. Jeremy. (This used to be commit 53e97bf92817b6cfc3f93c999a81ef8ad49a1609)
-rw-r--r--source3/include/charset.h14
-rw-r--r--source3/lib/charcnv.c85
-rw-r--r--source3/lib/util_reg.c2
-rw-r--r--source3/lib/util_unistr.c4
-rw-r--r--source3/librpc/ndr/ndr_string.c20
-rw-r--r--source3/smbd/mangle_hash2.c2
6 files changed, 69 insertions, 58 deletions
diff --git a/source3/include/charset.h b/source3/include/charset.h
index 8a51a1876e..5983fcdd4f 100644
--- a/source3/include/charset.h
+++ b/source3/include/charset.h
@@ -20,19 +20,9 @@
*/
/* this defines the charset types used in samba */
-typedef enum {CH_UCS2=0, CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4} charset_t;
+typedef enum {CH_UTF16LE=0, CH_UTF16=0, CH_UNIX=1, CH_DISPLAY=2, CH_DOS=3, CH_UTF8=4, CH_UTF16BE=5} charset_t;
-#if 0
-/* FIXME!!! Hack job for now to get the lsa ndr code compiling */
-#ifndef strlen_m
-#define strlen_m strlen
-#endif
-#ifndef strlen_m_term
-#define strlen_m_term strlen
-#endif
-#endif
-
-#define NUM_CHARSETS 5
+#define NUM_CHARSETS 6
/*
* for each charset we have a function that pushes from that charset to a ucs2
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index c5ce3ca8c7..ebc97033ac 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -56,7 +56,8 @@ static const char *charset_name(charset_t ch)
{
const char *ret = NULL;
- if (ch == CH_UCS2) ret = "UTF-16LE";
+ if (ch == CH_UTF16LE) ret = "UTF-16LE";
+ else if (ch == CH_UTF16BE) ret = "UTF-16BE";
else if (ch == CH_UNIX) ret = lp_unix_charset();
else if (ch == CH_DOS) ret = lp_dos_charset();
else if (ch == CH_DISPLAY) ret = lp_display_charset();
@@ -132,11 +133,11 @@ void init_iconv(void)
/* so that charset_name() works we need to get the UNIX<->UCS2 going
first */
- if (!conv_handles[CH_UNIX][CH_UCS2])
- conv_handles[CH_UNIX][CH_UCS2] = smb_iconv_open(charset_name(CH_UCS2), "ASCII");
+ if (!conv_handles[CH_UNIX][CH_UTF16LE])
+ conv_handles[CH_UNIX][CH_UTF16LE] = smb_iconv_open(charset_name(CH_UTF16LE), "ASCII");
- if (!conv_handles[CH_UCS2][CH_UNIX])
- conv_handles[CH_UCS2][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UCS2));
+ if (!conv_handles[CH_UTF16LE][CH_UNIX])
+ conv_handles[CH_UTF16LE][CH_UNIX] = smb_iconv_open("ASCII", charset_name(CH_UTF16LE));
for (c1=0;c1<NUM_CHARSETS;c1++) {
for (c2=0;c2<NUM_CHARSETS;c2++) {
@@ -156,10 +157,10 @@ void init_iconv(void)
if (conv_handles[c1][c2] == (smb_iconv_t)-1) {
DEBUG(0,("init_iconv: Conversion from %s to %s not supported\n",
charset_name((charset_t)c1), charset_name((charset_t)c2)));
- if (c1 != CH_UCS2) {
+ if (c1 != CH_UTF16LE && c1 != CH_UTF16BE) {
n1 = "ASCII";
}
- if (c2 != CH_UCS2) {
+ if (c2 != CH_UTF16LE && c2 != CH_UTF16BE) {
n2 = "ASCII";
}
DEBUG(0,("init_iconv: Attempting to replace with conversion from %s to %s\n",
@@ -214,7 +215,7 @@ static size_t convert_string_internal(charset_t from, charset_t to,
descriptor = conv_handles[from][to];
if (srclen == (size_t)-1) {
- if (from == CH_UCS2) {
+ if (from == CH_UTF16LE || from == CH_UTF16BE) {
srclen = (strlen_w((const smb_ucs2_t *)src)+1) * 2;
} else {
srclen = strlen((const char *)src)+1;
@@ -286,8 +287,11 @@ static size_t convert_string_internal(charset_t from, charset_t to,
if (o_len == 0 || i_len == 0)
return destlen - o_len;
- if (from == CH_UCS2 && to != CH_UCS2) {
- /* Can't convert from ucs2 to multibyte. Replace with the default fail char. */
+ if (((from == CH_UTF16LE)||(from == CH_UTF16BE)) &&
+ ((to != CH_UTF16LE)||(to != CH_UTF16BE))) {
+ /* Can't convert from utf16 any endian to multibyte.
+ Replace with the default fail char.
+ */
if (i_len < 2)
return destlen - o_len;
if (i_len >= 2) {
@@ -306,8 +310,10 @@ static size_t convert_string_internal(charset_t from, charset_t to,
/* Keep trying with the next char... */
goto again;
- } else if (from != CH_UCS2 && to == CH_UCS2) {
- /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */
+ } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
+ /* Can't convert to UTF16LE - just widen by adding the
+ default fail char then zero.
+ */
if (o_len < 2)
return destlen - o_len;
@@ -326,7 +332,8 @@ static size_t convert_string_internal(charset_t from, charset_t to,
/* Keep trying with the next char... */
goto again;
- } else if (from != CH_UCS2 && to != CH_UCS2) {
+ } else if (from != CH_UTF16LE && from != CH_UTF16BE &&
+ to != CH_UTF16LE && to != CH_UTF16BE) {
/* Failed multibyte to multibyte. Just copy the default fail char and
try again. */
outbuf[0] = lp_failed_convert_char();
@@ -384,7 +391,7 @@ size_t convert_string(charset_t from, charset_t to,
if (srclen == 0)
return 0;
- if (from != CH_UCS2 && to != CH_UCS2) {
+ if (from != CH_UTF16LE && from != CH_UTF16BE && to != CH_UTF16LE && to != CH_UTF16BE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
size_t slen = srclen;
@@ -419,7 +426,7 @@ size_t convert_string(charset_t from, charset_t to,
}
}
return retval;
- } else if (from == CH_UCS2 && to != CH_UCS2) {
+ } else if (from == CH_UTF16LE && to != CH_UTF16LE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
size_t retval = 0;
@@ -455,7 +462,7 @@ size_t convert_string(charset_t from, charset_t to,
}
}
return retval;
- } else if (from != CH_UCS2 && to == CH_UCS2) {
+ } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
const unsigned char *p = (const unsigned char *)src;
unsigned char *q = (unsigned char *)dest;
size_t retval = 0;
@@ -629,8 +636,12 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
if (o_len == 0 || i_len == 0)
goto out;
- if (from == CH_UCS2 && to != CH_UCS2) {
- /* Can't convert from ucs2 to multibyte. Just use the default fail char. */
+ if (((from == CH_UTF16LE)||(from == CH_UTF16BE)) &&
+ ((to != CH_UTF16LE)||(to != CH_UTF16BE))) {
+ /* Can't convert from utf16 any endian to multibyte.
+ Replace with the default fail char.
+ */
+
if (i_len < 2)
goto out;
@@ -650,8 +661,10 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
/* Keep trying with the next char... */
goto again;
- } else if (from != CH_UCS2 && to == CH_UCS2) {
- /* Can't convert to ucs2 - just widen by adding the default fail char then zero. */
+ } else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
+ /* Can't convert to UTF16LE - just widen by adding the
+ default fail char then zero.
+ */
if (o_len < 2)
goto out;
@@ -670,9 +683,10 @@ size_t convert_string_allocate(TALLOC_CTX *ctx, charset_t from, charset_t to,
/* Keep trying with the next char... */
goto again;
- } else if (from != CH_UCS2 && to != CH_UCS2) {
+ } else if (from != CH_UTF16LE && from != CH_UTF16BE &&
+ to != CH_UTF16LE && to != CH_UTF16BE) {
/* Failed multibyte to multibyte. Just copy the default fail char and
- try again. */
+ try again. */
outbuf[0] = lp_failed_convert_char();
inbuf++;
@@ -733,7 +747,7 @@ size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen)
return srclen;
}
- size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True);
+ size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
free(buffer);
return size;
}
@@ -769,14 +783,14 @@ char *strdup_upper(const char *s)
/* MB case. */
size_t size;
wpstring buffer;
- size = convert_string(CH_UNIX, CH_UCS2, s, -1, buffer, sizeof(buffer), True);
+ size = convert_string(CH_UNIX, CH_UTF16LE, s, -1, buffer, sizeof(buffer), True);
if (size == (size_t)-1) {
return NULL;
}
strupper_w(buffer);
- size = convert_string(CH_UCS2, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True);
+ size = convert_string(CH_UTF16LE, CH_UNIX, buffer, -1, out_buffer, sizeof(out_buffer), True);
if (size == (size_t)-1) {
return NULL;
}
@@ -790,7 +804,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
size_t size;
smb_ucs2_t *buffer = NULL;
- size = convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, srclen,
+ size = convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, srclen,
(void **)(void *)&buffer, True);
if (size == (size_t)-1 || !buffer) {
smb_panic("failed to create UCS2 buffer");
@@ -799,7 +813,7 @@ size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen)
SAFE_FREE(buffer);
return srclen;
}
- size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen, True);
+ size = convert_string(CH_UTF16LE, CH_UNIX, buffer, size, dest, destlen, True);
SAFE_FREE(buffer);
return size;
}
@@ -907,7 +921,7 @@ size_t push_ascii_nstring(void *dest, const char *src)
for (i = 0; buffer[i] != 0 && (i < buffer_len); i++) {
unsigned char mb[10];
/* Convert one smb_ucs2_t character at a time. */
- size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False);
+ size_t mb_len = convert_string(CH_UTF16LE, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False);
if ((mb_len != (size_t)-1) && (dest_len + mb_len <= MAX_NETBIOSNAME_LEN - 1)) {
memcpy((char *)dest + dest_len, mb, mb_len);
dest_len += mb_len;
@@ -1029,7 +1043,7 @@ size_t push_ucs2(const void *base_ptr, void *dest, const char *src, size_t dest_
/* ucs2 is always a multiple of 2 bytes */
dest_len &= ~1;
- ret = convert_string(CH_UNIX, CH_UCS2, src, src_len, dest, dest_len, True);
+ ret = convert_string(CH_UNIX, CH_UTF16LE, src, src_len, dest, dest_len, True);
if (ret == (size_t)-1) {
return 0;
}
@@ -1065,7 +1079,7 @@ size_t push_ucs2_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src)
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_talloc(ctx, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True);
}
@@ -1083,7 +1097,7 @@ size_t push_ucs2_allocate(smb_ucs2_t **dest, const char *src)
size_t src_len = strlen(src)+1;
*dest = NULL;
- return convert_string_allocate(NULL, CH_UNIX, CH_UCS2, src, src_len, (void **)dest, True);
+ return convert_string_allocate(NULL, CH_UNIX, CH_UTF16LE, src, src_len, (void **)dest, True);
}
/**
@@ -1193,7 +1207,7 @@ size_t pull_ucs2(const void *base_ptr, char *dest, const void *src, size_t dest_
if (src_len != (size_t)-1)
src_len &= ~1;
- ret = convert_string(CH_UCS2, CH_UNIX, src, src_len, dest, dest_len, True);
+ ret = convert_string(CH_UTF16LE, CH_UNIX, src, src_len, dest, dest_len, True);
if (ret == (size_t)-1) {
return 0;
}
@@ -1231,7 +1245,7 @@ size_t pull_ucs2_talloc(TALLOC_CTX *ctx, char **dest, const smb_ucs2_t *src)
{
size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
*dest = NULL;
- return convert_string_talloc(ctx, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True);
+ return convert_string_talloc(ctx, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True);
}
/**
@@ -1246,7 +1260,7 @@ size_t pull_ucs2_allocate(char **dest, const smb_ucs2_t *src)
{
size_t src_len = (strlen_w(src)+1) * sizeof(smb_ucs2_t);
*dest = NULL;
- return convert_string_allocate(NULL, CH_UCS2, CH_UNIX, src, src_len, (void **)dest, True);
+ return convert_string_allocate(NULL, CH_UTF16LE, CH_UNIX, src, src_len, (void **)dest, True);
}
/**
@@ -1408,8 +1422,7 @@ codepoint_t next_codepoint(const char *str, size_t *size)
lazy_initialize_conv();
- /* CH_UCS2 == UTF16-LE. */
- descriptor = conv_handles[CH_UNIX][CH_UCS2];
+ descriptor = conv_handles[CH_UNIX][CH_UTF16LE];
if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
*size = 1;
return INVALID_CODEPOINT;
diff --git a/source3/lib/util_reg.c b/source3/lib/util_reg.c
index 3f0b2d6a42..9fd8c13077 100644
--- a/source3/lib/util_reg.c
+++ b/source3/lib/util_reg.c
@@ -89,7 +89,7 @@ NTSTATUS reg_pull_multi_sz(TALLOC_CTX *mem_ctx, const void *buf, size_t len,
size_t dstlen, thislen;
thislen = strnlen_w(p, len) + 1;
- dstlen = convert_string_allocate(*values, CH_UCS2, CH_UNIX,
+ dstlen = convert_string_allocate(*values, CH_UTF16LE, CH_UNIX,
p, thislen*2, (void *)&val,
True);
if (dstlen == (size_t)-1) {
diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c
index 31114feb92..84e4cf3f83 100644
--- a/source3/lib/util_unistr.c
+++ b/source3/lib/util_unistr.c
@@ -171,11 +171,11 @@ static int check_dos_char_slowly(smb_ucs2_t c)
smb_ucs2_t c2 = 0;
int len1, len2;
- len1 = convert_string(CH_UCS2, CH_DOS, &c, 2, buf, sizeof(buf),False);
+ len1 = convert_string(CH_UTF16LE, CH_DOS, &c, 2, buf, sizeof(buf),False);
if (len1 == 0) {
return 0;
}
- len2 = convert_string(CH_DOS, CH_UCS2, buf, len1, &c2, 2,False);
+ len2 = convert_string(CH_DOS, CH_UTF16LE, buf, len1, &c2, 2,False);
if (len2 != 2) {
return 0;
}
diff --git a/source3/librpc/ndr/ndr_string.c b/source3/librpc/ndr/ndr_string.c
index 8f2ec10a59..2aa86de0bb 100644
--- a/source3/librpc/ndr/ndr_string.c
+++ b/source3/librpc/ndr/ndr_string.c
@@ -31,7 +31,7 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
uint32_t len1, ofs, len2;
uint16_t len3;
int ret;
- charset_t chset = CH_UCS2;
+ charset_t chset = CH_UTF16LE;
unsigned byte_mul = 2;
unsigned flags = ndr->flags;
unsigned c_len_term = 0;
@@ -40,7 +40,9 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
return NT_STATUS_OK;
}
- SMB_ASSERT(!NDR_BE(ndr));
+ if (NDR_BE(ndr)) {
+ chset = CH_UTF16BE;
+ }
if (flags & LIBNDR_FLAG_STR_ASCII) {
chset = CH_DOS;
@@ -282,7 +284,7 @@ NTSTATUS ndr_pull_string(struct ndr_pull *ndr, int ndr_flags, const char **s)
NTSTATUS ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s)
{
ssize_t s_len, c_len, d_len;
- charset_t chset = CH_UCS2;
+ charset_t chset = CH_UTF16LE;
unsigned flags = ndr->flags;
unsigned byte_mul = 2;
uint8_t *dest = NULL;
@@ -291,7 +293,9 @@ NTSTATUS ndr_push_string(struct ndr_push *ndr, int ndr_flags, const char *s)
return NT_STATUS_OK;
}
- SMB_ASSERT(!NDR_BE(ndr));
+ if (NDR_BE(ndr)) {
+ chset = CH_UTF16BE;
+ }
s_len = s?strlen(s):0;
@@ -557,7 +561,9 @@ NTSTATUS ndr_pull_charset(struct ndr_pull *ndr, int ndr_flags, const char **var,
return NT_STATUS_OK;
}
- SMB_ASSERT (!NDR_BE(ndr) || chset != CH_UCS2);
+ if (NDR_BE(ndr) && chset == CH_UTF16) {
+ chset = CH_UTF16BE;
+ }
NDR_PULL_NEED_BYTES(ndr, length*byte_mul);
@@ -580,7 +586,9 @@ NTSTATUS ndr_push_charset(struct ndr_push *ndr, int ndr_flags, const char *var,
{
ssize_t ret, required;
- SMB_ASSERT(!NDR_BE(ndr) || chset != CH_UCS2);
+ if (NDR_BE(ndr) && chset == CH_UTF16) {
+ chset = CH_UTF16BE;
+ }
required = byte_mul * length;
diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c
index d1ce1af9ea..a39f49ec79 100644
--- a/source3/smbd/mangle_hash2.c
+++ b/source3/smbd/mangle_hash2.c
@@ -465,7 +465,7 @@ static BOOL is_legal_name(const char *name)
* for mb UNIX asian characters like Japanese (SJIS) here.
* JRA.
*/
- if (convert_string(CH_UNIX, CH_UCS2, name, 2, mbc, 2, False) == 2) {
+ if (convert_string(CH_UNIX, CH_UTF16LE, name, 2, mbc, 2, False) == 2) {
/* Was a good mb string. */
name += 2;
continue;