[bug] volume name is not correctly display

TAKAHASHI Motonobu monyo at home.monyo.com
Sun Jun 17 07:08:28 GMT 2001


Hello,

I found two bugs around volume name.

The first one is that the default of volume name becomes 8 spaces in
Samba 2.2.0.

This is because unix_to_dos()/dos_to_unix use a static buffer as
their working area and it is easily overwritten. 

# This is poor design :-(

To fix this, simple set FLAG_DOS_STRING attribute to "volume" and
remove a poor unix_to_dos() call.

The second is the invalid truncation of a volume name in trans2.c.
In Samba 2.0.x, this problem does not occur, so I modified trans2.c in
Samba 2.2.0 same as that in Samba 2.0.9.

I do not know why, but this patch works well. And although this patch
modifies data_len, this is not necessary to work.

And also there is a similar problem in a file system type string.

Here is a patch to fix these bugs.

---- Cut Here ---- For 2.0.9 ----
diff -Nru samba-2.0.9.org/source/param/loadparm.c samba-2.0.9/source/param/loadparm.c
--- samba-2.0.9.org/source/param/loadparm.c	Sun Jun 17 10:49:45 2001
+++ samba-2.0.9/source/param/loadparm.c	Sun Jun 17 14:24:10 2001
@@ -851,7 +851,7 @@
   {"root preexec close", P_BOOL,  P_LOCAL,  &sDefault.bRootpreexecClose,NULL,   NULL,  FLAG_SHARE},
   {"root postexec",    P_STRING,  P_LOCAL,  &sDefault.szRootPostExec,   NULL,   NULL,  FLAG_SHARE|FLAG_PRINT},
   {"available",        P_BOOL,    P_LOCAL,  &sDefault.bAvailable,       NULL,   NULL,  FLAG_BASIC|FLAG_SHARE|FLAG_PRINT},
-  {"volume",           P_STRING,  P_LOCAL,  &sDefault.volume,           NULL,   NULL,  FLAG_SHARE},
+  {"volume",           P_STRING,  P_LOCAL,  &sDefault.volume,           NULL,   NULL,  FLAG_SHARE|FLAG_DOS_STRING},
   {"fstype",           P_STRING,  P_LOCAL,  &sDefault.fstype,           NULL,   NULL,  FLAG_SHARE},
   {"set directory",    P_BOOLREV, P_LOCAL,  &sDefault.bNo_set_dir,      NULL,   NULL,  FLAG_SHARE},
   {"source environment",P_STRING, P_GLOBAL, &Globals.szSourceEnv,       handle_source_env,NULL,0},
diff -Nru samba-2.0.9.org/source/smbd/trans2.c samba-2.0.9/source/smbd/trans2.c
--- samba-2.0.9.org/source/smbd/trans2.c	Tue Apr 25 02:27:31 2000
+++ samba-2.0.9/source/smbd/trans2.c	Sun Jun 17 14:25:53 2001
@@ -1160,7 +1160,6 @@
     }
     case SMB_QUERY_FS_ATTRIBUTE_INFO:
     {
-      int fstype_len;
       SIVAL(pdata,0,FILE_CASE_PRESERVED_NAMES|FILE_CASE_SENSITIVE_SEARCH|
 			FILE_DEVICE_IS_MOUNTED|
             (lp_nt_acl_support() ? FILE_PERSISTENT_ACLS : 0)); /* FS ATTRIBUTES */
@@ -1169,9 +1168,9 @@
 #endif /* Old code. */
 
       SIVAL(pdata,4,128); /* Max filename component length */
-      fstype_len = dos_PutUniCode(pdata+12,unix_to_dos(fstype,False),sizeof(pstring), False);
-      SIVAL(pdata,8,fstype_len);
-      data_len = 12 + fstype_len;
+      dos_PutUniCode(pdata+12,unix_to_dos(fstype,False),sizeof(pstring), False);
+      SIVAL(pdata,8,strlen(fstype)*2);
+      data_len = 12 + strlen(fstype)*2;
       SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS);
       break;
     }
---- Cut Here ---- For 2.0.9 ----

---- Cut Here ---- For 2.2.0 ----
diff -Nru samba-2.2.0.org/source/param/loadparm.c samba-2.2.0/source/param/loadparm.c
--- samba-2.2.0.org/source/param/loadparm.c	Fri Apr 13 13:09:37 2001
+++ samba-2.2.0/source/param/loadparm.c	Sun Jun 17 12:56:39 2001
@@ -997,7 +997,7 @@
 	{"root preexec close", P_BOOL, P_LOCAL, &sDefault.bRootpreexecClose, NULL, NULL, FLAG_SHARE},
 	{"root postexec", P_STRING, P_LOCAL, &sDefault.szRootPostExec, NULL, NULL, FLAG_SHARE | FLAG_PRINT},
 	{"available", P_BOOL, P_LOCAL, &sDefault.bAvailable, NULL, NULL, FLAG_BASIC | FLAG_SHARE | FLAG_PRINT},
-	{"volume", P_STRING, P_LOCAL, &sDefault.volume, NULL, NULL, FLAG_SHARE},
+	{"volume", P_STRING, P_LOCAL, &sDefault.volume, NULL, NULL, FLAG_SHARE | FLAG_DOS_STRING},
 	{"fstype", P_STRING, P_LOCAL, &sDefault.fstype, NULL, NULL, FLAG_SHARE},
 	{"set directory", P_BOOLREV, P_LOCAL, &sDefault.bNo_set_dir, NULL, NULL, FLAG_SHARE},
 	{"source environment", P_STRING, P_GLOBAL, &Globals.szSourceEnv, handle_source_env, NULL, 0},
@@ -3391,10 +3391,7 @@
 {
 	char *ret = lp_volume(snum);
 	if (!*ret) {
-		/* lp_volume returns a unix charset - lp_servicename returns a
-		   dos codepage - convert so volume_label() always returns UNIX.
-		*/
-		return (dos_to_unix(lp_servicename(snum), False));
+		return (lp_servicename(snum));
 	}
 	return (ret);
 }
diff -Nru samba-2.2.0.org/source/smbd/trans2.c samba-2.2.0/source/smbd/trans2.c
--- samba-2.2.0.org/source/smbd/trans2.c	Fri Apr 13 13:09:39 2001
+++ samba-2.2.0/source/smbd/trans2.c	Sun Jun 17 14:50:20 2001
@@ -1167,7 +1167,6 @@
     }
     case SMB_QUERY_FS_ATTRIBUTE_INFO:
     {
-      int fstype_len;
       SIVAL(pdata,0,FILE_CASE_PRESERVED_NAMES|FILE_CASE_SENSITIVE_SEARCH|
 			FILE_DEVICE_IS_MOUNTED|
             (lp_nt_acl_support() ? FILE_PERSISTENT_ACLS : 0)); /* FS ATTRIBUTES */
@@ -1176,9 +1175,9 @@
 #endif /* Old code. */
 
       SIVAL(pdata,4,128); /* Max filename component length */
-      fstype_len = dos_PutUniCode(pdata+12,unix_to_dos(fstype,False),sizeof(pstring), False);
-      SIVAL(pdata,8,fstype_len);
-      data_len = 12 + fstype_len;
+      dos_PutUniCode(pdata+12,unix_to_dos(fstype,False),sizeof(pstring), False);
+      SIVAL(pdata,8,strlen(fstype)*2);
+      data_len = 12 + strlen(fstype)*2;
       SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS);
       break;
     }
@@ -1204,11 +1203,9 @@
 	      SIVAL(pdata,12,strlen(vname));
 	      pstrcpy(pdata+18,vname);      
       } else {
-          int vnamelen;
-
-          vnamelen = dos_PutUniCode(pdata+18, vname, sizeof(pstring), False);
-	      data_len = 18 + vnamelen;
-	      SIVAL(pdata,12,vnamelen);
+          dos_PutUniCode(pdata+18, vname, sizeof(pstring), False);
+	      data_len = 18 + strlen(vname)*2;
+	      SIVAL(pdata,12,strlen(vname)*2);
 		  SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS);
       }
---- Cut Here ---- For 2.2.0 ----
 

-----
TAKAHASHI Motonobu                    mailto:monyo at samba.gr.jp
Samba Users Group Japan               http://www.samba.gr.jp/




More information about the samba-technical mailing list