svn commit: samba r18793 - in branches/SAMBA_3_0/source: include lib librpc/ndr smbd

jra at samba.org jra at samba.org
Thu Sep 21 18:37:09 GMT 2006


Author: jra
Date: 2006-09-21 18:37:09 +0000 (Thu, 21 Sep 2006)
New Revision: 18793

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18793

Log:
Fix BE string handling in the auto-generated
code. Should now work again with ASU.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/include/charset.h
   branches/SAMBA_3_0/source/lib/charcnv.c
   branches/SAMBA_3_0/source/lib/util_reg.c
   branches/SAMBA_3_0/source/lib/util_unistr.c
   branches/SAMBA_3_0/source/librpc/ndr/ndr_string.c
   branches/SAMBA_3_0/source/smbd/mangle_hash2.c


Changeset:
Modified: branches/SAMBA_3_0/source/include/charset.h
===================================================================
--- branches/SAMBA_3_0/source/include/charset.h	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/include/charset.h	2006-09-21 18:37:09 UTC (rev 18793)
@@ -20,20 +20,10 @@
 */
 
 /* 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 6
 
-#define NUM_CHARSETS 5
-
 /* 
  *   for each charset we have a function that pushes from that charset to a ucs2
  *   buffer, and a function that pulls from ucs2 buffer to that  charset.

Modified: branches/SAMBA_3_0/source/lib/charcnv.c
===================================================================
--- branches/SAMBA_3_0/source/lib/charcnv.c	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/lib/charcnv.c	2006-09-21 18:37:09 UTC (rev 18793)
@@ -56,7 +56,8 @@
 {
 	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 @@
 
 	/* 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 @@
 			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 @@
 	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 @@
 		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 @@
 			/* 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 @@
 			/* 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 @@
 	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 @@
 			}
 		}
 		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 @@
 			}
 		}
 		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 @@
 		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 @@
 			/* 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 @@
 			/* 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 @@
 		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 @@
 		/* 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 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 @@
 		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 @@
 	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 @@
 	/* 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 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 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 @@
 	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 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 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 @@
 
         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;

Modified: branches/SAMBA_3_0/source/lib/util_reg.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_reg.c	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/lib/util_reg.c	2006-09-21 18:37:09 UTC (rev 18793)
@@ -89,7 +89,7 @@
 		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) {

Modified: branches/SAMBA_3_0/source/lib/util_unistr.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_unistr.c	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/lib/util_unistr.c	2006-09-21 18:37:09 UTC (rev 18793)
@@ -171,11 +171,11 @@
 	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;
 	}

Modified: branches/SAMBA_3_0/source/librpc/ndr/ndr_string.c
===================================================================
--- branches/SAMBA_3_0/source/librpc/ndr/ndr_string.c	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/librpc/ndr/ndr_string.c	2006-09-21 18:37:09 UTC (rev 18793)
@@ -31,7 +31,7 @@
 	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 @@
 		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_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 @@
 		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 @@
 		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 @@
 {
 	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;
 	

Modified: branches/SAMBA_3_0/source/smbd/mangle_hash2.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/mangle_hash2.c	2006-09-21 18:22:51 UTC (rev 18792)
+++ branches/SAMBA_3_0/source/smbd/mangle_hash2.c	2006-09-21 18:37:09 UTC (rev 18793)
@@ -465,7 +465,7 @@
 			 * 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;



More information about the samba-cvs mailing list