kern/78110: [patch] fixed multibyte treatment of Samba FS (smb/ctx.c).

takawata at jp.freebsd.org takawata at jp.freebsd.org
Wed Apr 13 19:09:43 PDT 2005


I wrote a patch that can applied to -CURRENT at a few days ago.
Please review it. 
If anyone don't make objections in a week, I'll commit it.


Index: contrib/smbfs/lib/smb/ctx.c
===================================================================
RCS file: /home/ncvs/src/contrib/smbfs/lib/smb/ctx.c,v
retrieving revision 1.3
diff -u -r1.3 ctx.c
--- contrib/smbfs/lib/smb/ctx.c	27 Jul 2003 11:41:38 -0000	1.3
+++ contrib/smbfs/lib/smb/ctx.c	7 Apr 2005 23:30:42 -0000
@@ -473,8 +473,6 @@
 	struct sockaddr *sap;
 	struct sockaddr_nb *salocal, *saserver;
 	char *cp;
-	u_char cstbl[256];
-	u_int i;
 	int error = 0;
 	
 	ctx->ct_flags &= ~SMBCF_RESOLVED;
@@ -496,7 +494,7 @@
 	if (error)
 		return error;
 	if (ssn->ioc_localcs[0] == 0)
-		strcpy(ssn->ioc_localcs, "default");	/* XXX: locale name ? */
+		strcpy(ssn->ioc_localcs, "ISO8859-1");
 	error = smb_addiconvtbl("tolower", ssn->ioc_localcs, nls_lower);
 	if (error)
 		return error;
@@ -504,18 +502,9 @@
 	if (error)
 		return error;
 	if (ssn->ioc_servercs[0] != 0) {
-		for(i = 0; i < sizeof(cstbl); i++)
-			cstbl[i] = i;
-		nls_mem_toext(cstbl, cstbl, sizeof(cstbl));
-		error = smb_addiconvtbl(ssn->ioc_servercs, ssn->ioc_localcs, cstbl);
-		if (error)
-			return error;
-		for(i = 0; i < sizeof(cstbl); i++)
-			cstbl[i] = i;
-		nls_mem_toloc(cstbl, cstbl, sizeof(cstbl));
-		error = smb_addiconvtbl(ssn->ioc_localcs, ssn->ioc_servercs, cstbl);
-		if (error)
-			return error;
+		error = kiconv_add_xlat16_cspairs
+			(ssn->ioc_localcs, ssn->ioc_servercs);
+		if (error) return error;
 	}
 	if (ctx->ct_srvaddr) {
 		error = nb_resolvehost_in(ctx->ct_srvaddr, &sap);
Index: sys/fs/smbfs/smbfs_smb.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/smbfs/smbfs_smb.c,v
retrieving revision 1.14
diff -u -r1.14 smbfs_smb.c
--- sys/fs/smbfs/smbfs_smb.c	6 Jan 2005 18:10:41 -0000	1.14
+++ sys/fs/smbfs/smbfs_smb.c	7 Apr 2005 23:30:42 -0000
@@ -1449,8 +1449,8 @@
 			continue;
 		break;
 	}
-	smbfs_fname_tolocal(SSTOVC(ctx->f_ssp), ctx->f_name, ctx->f_nmlen,
-	    ctx->f_dnp->n_mount->sm_caseopt);
+	smbfs_fname_tolocal(SSTOVC(ctx->f_ssp), ctx->f_name, &ctx->f_nmlen,
+			    ctx->f_dnp->n_mount->sm_caseopt);
 	ctx->f_attr.fa_ino = smbfs_getino(ctx->f_dnp, ctx->f_name, ctx->f_nmlen);
 	return 0;
 }
Index: sys/fs/smbfs/smbfs_subr.c
===================================================================
RCS file: /home/ncvs/src/sys/fs/smbfs/smbfs_subr.c,v
retrieving revision 1.5
diff -u -r1.5 smbfs_subr.c
--- sys/fs/smbfs/smbfs_subr.c	6 Jan 2005 18:10:41 -0000	1.5
+++ sys/fs/smbfs/smbfs_subr.c	7 Apr 2005 23:40:24 -0000
@@ -316,13 +316,33 @@
 }
 
 int
-smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int nmlen, int caseopt)
+smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt)
 {
-/*	if (caseopt & SMB_CS_UPPER)
-		iconv_convmem(vcp->vc_toupper, name, name, nmlen);
-	else if (caseopt & SMB_CS_LOWER)
-		iconv_convmem(vcp->vc_tolower, name, name, nmlen);*/
-	if (vcp->vc_tolocal)
-		iconv_convmem(vcp->vc_tolocal, name, name, nmlen);
-	return 0;
+	int copt = (caseopt == SMB_CS_LOWER ? KICONV_FROM_LOWER : 
+		    (caseopt == SMB_CS_UPPER ? KICONV_FROM_UPPER : 0));
+	int error = 0;
+	int ilen = *nmlen;
+	int olen;
+	char *ibuf = name;
+	char outbuf[SMB_MAXFNAMELEN];
+	char *obuf = outbuf;
+
+	if (vcp->vc_tolocal) {
+		olen = sizeof(outbuf);
+		bzero(outbuf, sizeof(outbuf));
+
+		/*
+		error = iconv_conv_case
+			(vcp->vc_tolocal, NULL, NULL, &obuf, &olen, copt);
+		if (error) return error;
+		*/
+
+		error = iconv_conv_case
+			(vcp->vc_tolocal, (const char **)&ibuf, &ilen, &obuf, &olen, copt);
+		if (!error) {
+			*nmlen = sizeof(outbuf) - olen;
+			memcpy(name, outbuf, *nmlen);
+		}
+	}
+	return error;
 }
Index: sys/fs/smbfs/smbfs_subr.h
===================================================================
RCS file: /home/ncvs/src/sys/fs/smbfs/smbfs_subr.h,v
retrieving revision 1.5
diff -u -r1.5 smbfs_subr.h
--- sys/fs/smbfs/smbfs_subr.h	10 Feb 2005 12:07:02 -0000	1.5
+++ sys/fs/smbfs/smbfs_subr.h	7 Apr 2005 23:30:42 -0000
@@ -174,7 +174,7 @@
 int  smbfs_smb_lookup(struct smbnode *dnp, const char *name, int nmlen,
 	struct smbfattr *fap, struct smb_cred *scred);
 
-int  smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int nmlen, int caseopt);
+int  smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt);
 
 void  smb_time_local2server(struct timespec *tsp, int tzoff, u_long *seconds);
 void  smb_time_server2local(u_long seconds, int tzoff, struct timespec *tsp);
Index: usr.bin/smbutil/Makefile
===================================================================
RCS file: /home/ncvs/src/usr.bin/smbutil/Makefile,v
retrieving revision 1.1
diff -u -r1.1 Makefile
--- usr.bin/smbutil/Makefile	14 Dec 2001 11:41:22 -0000	1.1
+++ usr.bin/smbutil/Makefile	12 Apr 2005 04:32:52 -0000
@@ -3,8 +3,8 @@
 PROG=	smbutil
 SRCS=	smbutil.c dumptree.c login.c lookup.c view.c print.c
 
-DPADD=	${LIBSMB}
-LDADD=	-lsmb
+DPADD=	${LIBSMB} ${LIBKICONV}
+LDADD=	-lsmb -lkiconv
 
 CONTRIBDIR=	${.CURDIR}/../../contrib/smbfs
 CFLAGS+=	-I${CONTRIBDIR}/include
Index: usr.sbin/mount_smbfs/Makefile
===================================================================
RCS file: /home/ncvs/src/usr.sbin/mount_smbfs/Makefile,v
retrieving revision 1.6
diff -u -r1.6 Makefile
--- usr.sbin/mount_smbfs/Makefile	21 Dec 2004 09:59:44 -0000	1.6
+++ usr.sbin/mount_smbfs/Makefile	12 Apr 2005 04:32:26 -0000
@@ -9,8 +9,8 @@
 CONTRIBDIR=	${.CURDIR}/../../contrib/smbfs
 CFLAGS+=	-DSMBFS -I${MOUNTDIR} -I${CONTRIBDIR}/include
 
-LDADD=	-lsmb
-DPADD=	${LIBSMB}
+LDADD=	-lsmb -lkiconv
+DPADD=	${LIBSMB} ${LIBKICONV}
 
 # Needs to be dynamically linked for optional dlopen() access to
 # userland libiconv (see the -E option).




More information about the freebsd-fs mailing list