From owner-freebsd-fs@FreeBSD.ORG Thu Apr 14 02:09:42 2005 Return-Path: Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EB36B16A4CE; Thu, 14 Apr 2005 02:09:42 +0000 (GMT) Received: from axe-inc.co.jp (axegw.axe-inc.co.jp [61.199.217.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7F76943D45; Thu, 14 Apr 2005 02:09:41 +0000 (GMT) (envelope-from takawata@axe-inc.co.jp) Received: from localhost (localhost [127.0.0.1]) by axe-inc.co.jp (8.9.3+3.2W/3.7W) with SMTP id LAA17486; Thu, 14 Apr 2005 11:09:40 +0900 (JST) Message-Id: <200504140209.LAA17486@axe-inc.co.jp> X-Authentication-Warning: axegw.axe-inc.co.jp: localhost [127.0.0.1] didn't use HELO protocol To: freebsd-gnats-submit@FreeBSD.org, daichi@freebsd.org From: takawata@jp.freebsd.org Date: Thu, 14 Apr 2005 11:09:39 +0900 Sender: takawata@axe-inc.co.jp cc: freebsd-fs@freebsd.org cc: takawata@freebsd.org Subject: Re: kern/78110: [patch] fixed multibyte treatment of Samba FS (smb/ctx.c). X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2005 02:09:43 -0000 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).