utf8 and one character code pages in SAMBA_2_2

TAKAHASHI Motonobu monyo at samba.gr.jp
Mon Jul 30 18:18:27 GMT 2001


>Hi all,
>
>I had some problems using samba 2.2.x with utf8 coding system and code
>page 862.
>It seem that when utf8 is converted into the code page string, it is
>assumed that the code page always consists of two character. In the
>862 (Hebrew) code page this is not true, therefore a null character is
>inserted instead of putting just one character. This obviously ends
>the null terminated string.

Sorry this is a bug for our contributed code and already fixed in
Samba Japanese Edition.

In Samba Japanese Edition, here is a patch for it:

=====
diff -u -r1.15 -r1.16
--- kanji.c     2000/10/07 09:09:00     1.15
+++ kanji.c     2000/10/07 09:16:21     1.16
@@ -1418,20 +1418,22 @@
   while (*src && ((char *)dst - cvtbuf < sizeof(cvtbuf)-4)) {
     val = (*src++ & 0xff);
     if (val < 0x80) {
-      *dst++ = (char)(val & 0x7f); 
+      w = ucs2doscp(val & 0x7f); 
     } else if ((0xc0 <= val) && (val <= 0xdf) 
               && (0x80 <= *src) && (*src <= 0xbf)) {
       w = ucs2doscp( ((val & 31) << 6)  | ((*src++) & 63 ));
-      *dst++ = (char)((w >> 8) & 0xff);
-      *dst++ = (char)(w & 0xff);
     } else {
       val  = (val & 0x0f) << 12;
       val |= ((*src++ & 0x3f) << 6);
       val |= (*src++ & 0x3f);
       w = ucs2doscp(val);
-      *dst++ = (char)((w >> 8) & 0xff);
-      *dst++ = (char)(w & 0xff);
     }
+  }
+  if (w <= 0xff) {
+    *dst++ = (char)(w & 0xff);
+  } else {
+    *dst++ = (char)((w >> 8) & 0xff);
+    *dst++ = (char)(w & 0xff);
   }
   *dst++='\0';
   if (overwrite) {

=====

>I've changed the code to selectively add characters to the string, and
>the diff is below.
>
>Michael Adda,
>Disksites R&D <http://www.disksites.com>

Your patch will be also welcome.

Index: kanji.c
===================================================================
RCS file: /cvsroot/samba/source/lib/Attic/kanji.c,v
retrieving revision 1.23.4.4
diff -c -r1.23.4.4 kanji.c
*** kanji.c     26 Mar 2001 23:12:35 -0000      1.23.4.4
--- kanji.c     24 Jul 2001 09:37:39 -0000
***************
*** 1413,1426 ****
      } else if ((0xc0 <= val) && (val <= 0xdf) 
               && (0x80 <= *src) && (*src <= 0xbf)) {
        w = ucs2doscp( ((val & 31) << 6)  | ((*src++) & 63 ));
!       *dst++ = (char)((w >> 8) & 0xff);
        *dst++ = (char)(w & 0xff);
      } else {
        val  = (val & 0x0f) << 12;
        val |= ((*src++ & 0x3f) << 6);
        val |= (*src++ & 0x3f);
        w = ucs2doscp(val);
!       *dst++ = (char)((w >> 8) & 0xff);
        *dst++ = (char)(w & 0xff);
      }
    }
--- 1413,1428 ----
      } else if ((0xc0 <= val) && (val <= 0xdf) 
               && (0x80 <= *src) && (*src <= 0xbf)) {
        w = ucs2doscp( ((val & 31) << 6)  | ((*src++) & 63 ));
!       if ((w >> 8) & 0xff)
!         *dst++ = (char)((w >> 8) & 0xff);
        *dst++ = (char)(w & 0xff);
      } else {
        val  = (val & 0x0f) << 12;
        val |= ((*src++ & 0x3f) << 6);
        val |= (*src++ & 0x3f);
        w = ucs2doscp(val);
!       if ((w >> 8) & 0xff)
!         *dst++ = (char)((w >> 8) & 0xff);
        *dst++ = (char)(w & 0xff);
      }
    }

-----
TAKAHASHI, Motonobu(monyo)         monyo at samba.org
Personal - http://home.monyo.com/
Samba Team - http://samba.org/     Samba-JP - http://www.samba.gr.jp/  
JWNTUG - http://www.jwntug.or.jp/  Analog-JP - http://www.jp.analog.cx/
MCSE+I, SCNA, CCNA, Turbo-CI




More information about the samba-technical mailing list