PATCH to Samba >= 2.2.1, accents and special chars

Pierre-Yves BONNETAIN bonnetain at acm.org
Tue Oct 23 05:15:16 GMT 2001


   Okay, I've had some fun there. Let me tell I am no samba pro, so the patch
below _should be tested and tested again_ in _your_ environment before doing
anything close to putting your patched samba into production. It can possibly
break everything. You have been warned.

   The mail is somehow longish, because sending a quick (and dirty) patch 
without any explanation seems wrong to me. And explanations may help the more 
knowledgeable find the best fix.

   My history is simple. I am french, using Linux and W2K. On the W2K systems,
I have accented file and directories names.
   Access FROM the W2K computers TO my Linux box, with Samba 2.2.1a, is ok. No
problems at all with accents and the stuff, everything is properly translated.
The reverse is, sadly, not true :

-------------------
smb: \> cd Pierre-Yves
smb: \Pierre-Yves\> ls
  .                                  DA        0  Mon Jul  2 11:41:34 2001
  ..                                 DA        0  Mon Jul  2 11:41:34 2001
  Bureau                             DA        0  Tue Oct  2 10:48:10 2001
  Menu Démarrer                      DA        0  Mon Aug 20 00:01:01 2001
  Mes documents                      DA        0  Mon Oct  1 09:19:33 2001
  Modèles                           DAH        0  Sat Jun 23 15:57:23 2001

                58627 blocks of size 524288. 52259 blocks available
smb: \Pierre-Yves\> cd Modèles
cd \Pierre-Yves\Modèles\: ERRDOS - ERRbadpath (Directory invalid.)
smb: \Pierre-Yves\> cd Bureau
smb: \Pierre-Yves\Bureau\> ls
  .                                  DA        0  Tue Oct  2 10:48:10 2001
  ..                                 DA        0  Tue Oct  2 10:48:10 2001
  Eléphant.txt                        A       11  Tue Oct  2 10:48:17 2001
  rp8-setup.exe                       R  5136384  Sun Aug 19 23:57:50 2001

                58627 blocks of size 524288. 52259 blocks available
smb: \Pierre-Yves\Bureau\> get Eléphant.txt
ERRDOS - ERRbadfile (File not found.) opening remote file \Pierre-Yves\Bureau\Eléphant.txt

smb: \Pierre-Yves\> cd "../Mes documents"
smb: \Pierre-Yves\Mes documents\> ls
  .                                  DA        0  Mon Oct  1 09:19:33 2001
  ..                                 DA        0  Mon Oct  1 09:19:33 2001
  Gestion                             D        0  Mon Oct  1 09:21:53 2001
  Perso                              DA        0  Thu Sep 13 13:12:53 2001

                58627 blocks of size 524288. 52259 blocks available
smb: \Pierre-Yves\Mes documents\> 
-------------------

   My smb.conf seems OK as code page and character set are concerned :

	client code page = 850
        character set = ISO8859-1

   The problem is easy to pinpoint (a network sniffer helped me a little there,
and then a nice debugger). At one point in processing input commands, smbclient
>= 2.2.1 thinks it has a DOS-translated name, but this is wrong. And thus
accented characters are improperly translated.
   I backpatched to Samba 2.2.0, since several people told me they did not have
this kind of problem. And it's true :-)
   The 'core' of my grudge seems to lie in the new clistr_push function, which
does not exist in release 2.2.0. A 'cd directory' command is thus processed by
cli_chkpath, which does :

	cli_setup_packet(cli);
	p = smb_buf(cli->outbuf);
	*p++ = 4;
	safe_strcpy(p,path2,strlen(path2));
	unix_to_dos(p,True);

	cli_send_smb(cli);

   It is clear the path is known to be in Unix format, and is properly 
translated to dos stuff.

   But cli_chkpath, in smbclient 2.2.1a/2.2.2, is now :

	cli_setup_packet(cli);
	p = smb_buf(cli->outbuf);
	*p++ = 4;
	p += clistr_push(cli, p, path2, -1, STR_TERMINATE | STR_CONVERT);

	cli_setup_bcc(cli, p);

	cli_send_smb(cli);

   And clistr_push says :

	/* the server likes unicode. give it the works */
	if (flags & STR_CONVERT) {
		dos_PutUniCode(dest, src, dest_len, flags & STR_TERMINATE);
	} else {
		ascii_to_unistr(dest, src, dest_len);
	}

   No such luck, src is NOT in Dos format but in Unix format. Hence all my
troubles.
   The same ting is done/not done anymore in cli_open, cli_mkdir, etc.
   My fix is easy. It's just a call to unix_to_dos in the proper place. The 
patch may be applied to samba 2.2.1a or 2.2.2.
   I'm not sure if it's the proper answer, though. So, I submit it to the
community. No flames, please :-)
-- 
-+-+ Pierre-Yves BONNETAIN
     Consultant Internet/Sécurité --- B & A Consultants
     Tel : 0 563.277.241 - Fax : 0 563.277.245

-------------- next part --------------
diff -c -r samba-2.2.1a/source/libsmb/clistr.c samba-2.2.1a-pyb/source/libsmb/clistr.c
*** samba-2.2.1a/source/libsmb/clistr.c	Fri Jul  6 02:59:35 2001
--- samba-2.2.1a-pyb/source/libsmb/clistr.c	Tue Oct 23 12:16:04 2001
***************
*** 69,76 ****
  
  	/* the server likes unicode. give it the works */
  	if (flags & STR_CONVERT) {
! 		dos_PutUniCode(dest, src, dest_len, flags & STR_TERMINATE);
  	} else {
  		ascii_to_unistr(dest, src, dest_len);
  	}
  	if (flags & STR_UPPER) {
--- 69,79 ----
  
  	/* the server likes unicode. give it the works */
  	if (flags & STR_CONVERT) {
! 		/* bonnetain at acm.org, 23-oct-2001 : added call to
! 		   unix_to_dos */
! 		dos_PutUniCode(dest, unix_to_dos(src,False), dest_len, flags & STR_TERMINATE);
  	} else {
+ 		/* bonnetain at acm.org, 23-oct-2001 : there also ??? */
  		ascii_to_unistr(dest, src, dest_len);
  	}
  	if (flags & STR_UPPER) {


More information about the samba mailing list