Module Name: src Committed By: martin Date: Mon Dec 1 09:31:40 UTC 2014
Modified Files: src/external/bsd/smbfs/dist/lib/smb [netbsd-7]: ctx.c src/external/bsd/smbfs/dist/mount_smbfs [netbsd-7]: mount_smbfs.8 src/external/bsd/smbfs/dist/smbutil [netbsd-7]: smbutil.1 src/sys/fs/smbfs [netbsd-7]: smbfs_node.c smbfs_smb.c smbfs_subr.c smbfs_subr.h src/sys/netsmb [netbsd-7]: iconv.c mchain.h smb_subr.c subr_mchain.c src/sys/rump/dev/lib/libnetsmb [netbsd-7]: Makefile Added Files: src/sys/rump/dev/lib/libnetsmb [netbsd-7]: netsmb_iconv.c netsmb_user.c netsmb_user.h Log Message: Pull up following revision(s) (requested by nakayama in ticket #275): sys/rump/dev/lib/libnetsmb/netsmb_iconv.c: revision 1.1 external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8: revision 1.3 sys/netsmb/smb_subr.c: revision 1.37 external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8: revision 1.4 sys/fs/smbfs/smbfs_subr.c: revision 1.17 sys/rump/dev/lib/libnetsmb/Makefile: revision 1.5 sys/fs/smbfs/smbfs_smb.c: revision 1.46 sys/fs/smbfs/smbfs_node.c: revision 1.52 sys/netsmb/mchain.h: revision 1.10 external/bsd/smbfs/dist/lib/smb/ctx.c: revision 1.3 sys/netsmb/subr_mchain.c: revision 1.23 sys/rump/dev/lib/libnetsmb/netsmb_user.c: revision 1.1 sys/rump/dev/lib/libnetsmb/netsmb_user.c: revision 1.2 sys/rump/dev/lib/libnetsmb/netsmb_user.c: revision 1.3 sys/rump/dev/lib/libnetsmb/netsmb_user.h: revision 1.1 sys/netsmb/iconv.c: revision 1.14 external/bsd/smbfs/dist/smbutil/smbutil.1: revision 1.3 sys/fs/smbfs/smbfs_subr.h: revision 1.22 Make rump_smbfs(8) uses host iconv(3) to convert filenames character set on NetBSD hosts. Adjust smbfs/netsmb for filenames byte length changes that come as a result of iconv conversion. Most codes are taken from FreeBSD. Disable unused codes that causes SIGBUS or SIGSEGV if character sets option (-E) is specified to mount_smbfs/rump_smbfs. Adjust man page accordingly. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.2.6.1 src/external/bsd/smbfs/dist/lib/smb/ctx.c cvs rdiff -u -r1.2 -r1.2.6.1 \ src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8 cvs rdiff -u -r1.2 -r1.2.6.1 src/external/bsd/smbfs/dist/smbutil/smbutil.1 cvs rdiff -u -r1.51 -r1.51.4.1 src/sys/fs/smbfs/smbfs_node.c cvs rdiff -u -r1.44.12.1 -r1.44.12.2 src/sys/fs/smbfs/smbfs_smb.c cvs rdiff -u -r1.16 -r1.16.12.1 src/sys/fs/smbfs/smbfs_subr.c cvs rdiff -u -r1.21 -r1.21.12.1 src/sys/fs/smbfs/smbfs_subr.h cvs rdiff -u -r1.13 -r1.13.4.1 src/sys/netsmb/iconv.c cvs rdiff -u -r1.9 -r1.9.34.1 src/sys/netsmb/mchain.h cvs rdiff -u -r1.36 -r1.36.28.1 src/sys/netsmb/smb_subr.c cvs rdiff -u -r1.22 -r1.22.14.1 src/sys/netsmb/subr_mchain.c cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/rump/dev/lib/libnetsmb/Makefile cvs rdiff -u -r0 -r1.1.4.2 src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c \ src/sys/rump/dev/lib/libnetsmb/netsmb_user.h cvs rdiff -u -r0 -r1.3.4.2 src/sys/rump/dev/lib/libnetsmb/netsmb_user.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/smbfs/dist/lib/smb/ctx.c diff -u src/external/bsd/smbfs/dist/lib/smb/ctx.c:1.2 src/external/bsd/smbfs/dist/lib/smb/ctx.c:1.2.6.1 --- src/external/bsd/smbfs/dist/lib/smb/ctx.c:1.2 Wed Dec 25 22:03:15 2013 +++ src/external/bsd/smbfs/dist/lib/smb/ctx.c Mon Dec 1 09:31:40 2014 @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: ctx.c,v 1.2 2013/12/25 22:03:15 christos Exp $"); +__RCSID("$NetBSD: ctx.c,v 1.2.6.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/sysctl.h> @@ -501,8 +501,10 @@ smb_ctx_resolve(struct smb_ctx *ctx) struct sockaddr *sap; struct sockaddr_nb *salocal, *saserver; char *cp; +#ifdef notyet u_char cstbl[256]; u_int i; +#endif int error = 0; ctx->ct_flags &= ~SMBCF_RESOLVED; @@ -531,6 +533,7 @@ smb_ctx_resolve(struct smb_ctx *ctx) error = smb_addiconvtbl("toupper", ssn->ioc_localcs, nls_upper); if (error) return error; +#ifdef notyet if (ssn->ioc_servercs[0] != 0) { for(i = 0; i < sizeof(cstbl); i++) cstbl[i] = i; @@ -545,6 +548,7 @@ smb_ctx_resolve(struct smb_ctx *ctx) if (error) return error; } +#endif if (ctx->ct_srvaddr) { error = nb_resolvehost_in(ctx->ct_srvaddr, &sap); } else { Index: src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8 diff -u src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8:1.2 src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8:1.2.6.1 --- src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8:1.2 Wed Dec 25 22:03:15 2013 +++ src/external/bsd/smbfs/dist/mount_smbfs/mount_smbfs.8 Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -.\" $NetBSD: mount_smbfs.8,v 1.2 2013/12/25 22:03:15 christos Exp $ +.\" $NetBSD: mount_smbfs.8,v 1.2.6.1 2014/12/01 09:31:40 martin Exp $ .\" Id: mount_smbfs.8,v 1.8 2000/06/09 13:52:56 bp Exp .\" .\" Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -25,7 +25,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 9, 2003 +.Dd November 17, 2014 .Dt MOUNT_SMBFS 8 .Os .Sh NAME @@ -189,6 +189,7 @@ for smbfs mounts: .Pp .Dl "//guest@samba/public /smb/public smbfs rw,noauto 0 0" .Sh SEE ALSO +.Xr smbutil 1 , .Xr mount 8 .Sh HISTORY Support for SMBFS first appeared in @@ -207,3 +208,15 @@ port done by and .An Jaromir Dolecek .Aq jdole...@netbsd.org . +.Sh BUGS +The +.Fl E +option works only if you mount with +.Xr rump_smbfs 8 +instead of +.Nm . +.Pp +The +.Fl c +option is not implemented yet. +It is silently ignored for now. Index: src/external/bsd/smbfs/dist/smbutil/smbutil.1 diff -u src/external/bsd/smbfs/dist/smbutil/smbutil.1:1.2 src/external/bsd/smbfs/dist/smbutil/smbutil.1:1.2.6.1 --- src/external/bsd/smbfs/dist/smbutil/smbutil.1:1.2 Wed Dec 25 22:03:15 2013 +++ src/external/bsd/smbfs/dist/smbutil/smbutil.1 Mon Dec 1 09:31:40 2014 @@ -124,9 +124,11 @@ for the user .It Pa ~/.nsmbrc Keeps description for each connection. See -.Pa ./examples/dot.nsmbrc +.Pa /usr/share/examples/smbfs/dot.nsmbrc for details. .El +.Sh SEE ALSO +.Xr mount_smbfs 8 .Sh AUTHORS .An Boris Popov Aq Mt b...@butya.kz , .Aq b...@freebsd.org Index: src/sys/fs/smbfs/smbfs_node.c diff -u src/sys/fs/smbfs/smbfs_node.c:1.51 src/sys/fs/smbfs/smbfs_node.c:1.51.4.1 --- src/sys/fs/smbfs/smbfs_node.c:1.51 Tue Jan 28 13:23:49 2014 +++ src/sys/fs/smbfs/smbfs_node.c Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: smbfs_node.c,v 1.51 2014/01/28 13:23:49 martin Exp $ */ +/* $NetBSD: smbfs_node.c,v 1.51.4.1 2014/12/01 09:31:40 martin Exp $ */ /* * Copyright (c) 2000-2001 Boris Popov @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: smbfs_node.c,v 1.51 2014/01/28 13:23:49 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smbfs_node.c,v 1.51.4.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -197,10 +197,10 @@ allocnew: || memcmp(name, np2->n_name, nmlen) != 0) continue; mutex_exit(&smp->sm_hashlock); - pool_put(&smbfs_node_pool, np); - ungetnewvnode(vp); if ((np->n_flag & NREFPARENT) != 0) vrele(dvp); + ungetnewvnode(vp); + pool_put(&smbfs_node_pool, np); goto retry; } Index: src/sys/fs/smbfs/smbfs_smb.c diff -u src/sys/fs/smbfs/smbfs_smb.c:1.44.12.1 src/sys/fs/smbfs/smbfs_smb.c:1.44.12.2 --- src/sys/fs/smbfs/smbfs_smb.c:1.44.12.1 Mon Oct 20 09:55:54 2014 +++ src/sys/fs/smbfs/smbfs_smb.c Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: smbfs_smb.c,v 1.44.12.1 2014/10/20 09:55:54 martin Exp $ */ +/* $NetBSD: smbfs_smb.c,v 1.44.12.2 2014/12/01 09:31:40 martin Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.44.12.1 2014/10/20 09:55:54 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.44.12.2 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -1129,7 +1129,7 @@ static int smbfs_findopenLM2(struct smbfs_fctx *ctx, struct smbnode *dnp, const char *wildcard, int wclen, int attr, struct smb_cred *scred) { - ctx->f_name = malloc(SMB_MAXNAMLEN, M_SMBFSDATA, M_WAITOK); + ctx->f_name = malloc(SMB_MAXNAMLEN * 2, M_SMBFSDATA, M_WAITOK); if (ctx->f_name == NULL) return ENOMEM; ctx->f_infolevel = SMB_DIALECT(SSTOVC(ctx->f_ssp)) < SMB_DIALECT_NTLM0_12 ? @@ -1212,7 +1212,7 @@ smbfs_findnextLM2(struct smbfs_fctx *ctx return EINVAL; #endif } - nmlen = min(size, SMB_MAXNAMLEN); + nmlen = min(size, SMB_MAXNAMLEN * 2); cp = ctx->f_name; error = md_get_mem(mbp, cp, nmlen, MB_MSYSTEM); if (error) @@ -1316,7 +1316,7 @@ smbfs_findnext(struct smbfs_fctx *ctx, i continue; break; } - smbfs_fname_tolocal(SSTOVC(ctx->f_ssp), ctx->f_name, ctx->f_nmlen, + 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: src/sys/fs/smbfs/smbfs_subr.c diff -u src/sys/fs/smbfs/smbfs_subr.c:1.16 src/sys/fs/smbfs/smbfs_subr.c:1.16.12.1 --- src/sys/fs/smbfs/smbfs_subr.c:1.16 Fri Nov 30 23:24:21 2012 +++ src/sys/fs/smbfs/smbfs_subr.c Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: smbfs_subr.c,v 1.16 2012/11/30 23:24:21 nakayama Exp $ */ +/* $NetBSD: smbfs_subr.c,v 1.16.12.1 2014/12/01 09:31:40 martin Exp $ */ /* * Copyright (c) 2000-2001, Boris Popov @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: smbfs_subr.c,v 1.16 2012/11/30 23:24:21 nakayama Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smbfs_subr.c,v 1.16.12.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -318,14 +318,36 @@ smbfs_fullpath(struct mbchain *mbp, stru } int -smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int nmlen, +smbfs_fname_tolocal(struct smb_vc *vcp, char *name, int *nmlen, int caseopt) { -/* if (caseopt & SMB_CS_UPPER) + int error = 0; + size_t ilen, olen; + const char *ibuf; + char *obuf, *outbuf; + +#ifdef notyet + 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; + iconv_convmem(vcp->vc_tolower, name, name, nmlen); +#endif + if (vcp->vc_tolocal) { + const size_t buflen = SMB_MAXNAMLEN * 2; + + outbuf = malloc(buflen, M_SMBTEMP, M_WAITOK); + if (outbuf == NULL) + return ENOMEM; + ilen = *nmlen; + olen = buflen; + ibuf = name; + obuf = outbuf; + error = iconv_conv(vcp->vc_tolocal, &ibuf, &ilen, &obuf, &olen); + if (!error) { + *nmlen = buflen - olen; + memcpy(name, outbuf, *nmlen); + } + free(outbuf, M_SMBTEMP); + } + return error; } Index: src/sys/fs/smbfs/smbfs_subr.h diff -u src/sys/fs/smbfs/smbfs_subr.h:1.21 src/sys/fs/smbfs/smbfs_subr.h:1.21.12.1 --- src/sys/fs/smbfs/smbfs_subr.h:1.21 Fri Nov 30 23:24:21 2012 +++ src/sys/fs/smbfs/smbfs_subr.h Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: smbfs_subr.h,v 1.21 2012/11/30 23:24:21 nakayama Exp $ */ +/* $NetBSD: smbfs_subr.h,v 1.21.12.1 2014/12/01 09:31:40 martin Exp $ */ /* * Copyright (c) 2000-2001, Boris Popov @@ -176,7 +176,7 @@ int smbfs_fullpath(struct mbchain *mbp, 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: src/sys/netsmb/iconv.c diff -u src/sys/netsmb/iconv.c:1.13 src/sys/netsmb/iconv.c:1.13.4.1 --- src/sys/netsmb/iconv.c:1.13 Thu Feb 20 11:08:57 2014 +++ src/sys/netsmb/iconv.c Mon Dec 1 09:31:40 2014 @@ -1,41 +1,48 @@ -/* $NetBSD: iconv.c,v 1.13 2014/02/20 11:08:57 joerg Exp $ */ +/* $NetBSD: iconv.c,v 1.13.4.1 2014/12/01 09:31:40 martin Exp $ */ /* Public domain */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.13 2014/02/20 11:08:57 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: iconv.c,v 1.13.4.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/kernel.h> #include <sys/systm.h> #include <sys/errno.h> -#include <sys/malloc.h> #include <netsmb/iconv.h> +/* stubs for iconv functions */ +int iconv_open_stub(const char *, const char *, void **); +int iconv_close_stub(void *); +int iconv_conv_stub(void *, const char **, size_t *, char **, size_t *); +__weak_alias(iconv_open, iconv_open_stub); +__weak_alias(iconv_close, iconv_close_stub); +__weak_alias(iconv_conv, iconv_conv_stub); + int -iconv_open(const char *to, const char *from, +iconv_open_stub(const char *to, const char *from, void **handle) { return 0; } int -iconv_close(void *handle) +iconv_close_stub(void *handle) { return 0; } int -iconv_conv(void *handle, const char **inbuf, +iconv_conv_stub(void *handle, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft) { - if (*inbytesleft > *outbytesleft) - return(E2BIG); - if (inbuf == NULL) return(0); /* initial shift state */ + if (*inbytesleft > *outbytesleft) + return(E2BIG); + (void)memcpy(*outbuf, *inbuf, *inbytesleft); *outbytesleft -= *inbytesleft; @@ -59,7 +66,11 @@ iconv_convstr(void *handle, char *dst, c strlcpy(dst, src, l); return dst; } - inlen = outlen = strlen(src); + inlen = strlen(src); + outlen = l - 1; + error = iconv_conv(handle, NULL, NULL, &p, &outlen); + if (error) + return NULL; error = iconv_conv(handle, &src, &inlen, &p, &outlen); if (error) return NULL; @@ -82,6 +93,9 @@ iconv_convmem(void *handle, void *dst, c return dst; } inlen = outlen = size; + error = iconv_conv(handle, NULL, NULL, &d, &outlen); + if (error) + return NULL; error = iconv_conv(handle, &s, &inlen, &d, &outlen); if (error) return NULL; Index: src/sys/netsmb/mchain.h diff -u src/sys/netsmb/mchain.h:1.9 src/sys/netsmb/mchain.h:1.9.34.1 --- src/sys/netsmb/mchain.h:1.9 Mon Jul 12 02:58:01 2010 +++ src/sys/netsmb/mchain.h Mon Dec 1 09:31:40 2014 @@ -54,7 +54,8 @@ struct mbuf; struct mbchain; -typedef int mb_copy_t(struct mbchain *, const char *, char *, size_t); +typedef int mb_copy_t(struct mbchain *, const char *, char *, + size_t *, size_t *); struct mbchain { struct mbuf * mb_top; /* head of mbufs chain */ Index: src/sys/netsmb/smb_subr.c diff -u src/sys/netsmb/smb_subr.c:1.36 src/sys/netsmb/smb_subr.c:1.36.28.1 --- src/sys/netsmb/smb_subr.c:1.36 Sun Sep 25 13:42:30 2011 +++ src/sys/netsmb/smb_subr.c Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: smb_subr.c,v 1.36 2011/09/25 13:42:30 chs Exp $ */ +/* $NetBSD: smb_subr.c,v 1.36.28.1 2014/12/01 09:31:40 martin Exp $ */ /* * Copyright (c) 2000-2001 Boris Popov @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: smb_subr.c,v 1.36 2011/09/25 13:42:30 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smb_subr.c,v 1.36.28.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -307,11 +307,20 @@ smb_maperror(int eclass, int eno) } static int -smb_copy_iconv(struct mbchain *mbp, const char *src, char *dst, size_t len) +smb_copy_iconv(struct mbchain *mbp, const char *src, char *dst, + size_t *srclen, size_t *dstlen) { - size_t outlen = len; + int error; + size_t inlen = *srclen, outlen = *dstlen; - return iconv_conv((struct iconv_drv*)mbp->mb_udata, &src, &len, &dst, &outlen); + error = iconv_conv((struct iconv_drv*)mbp->mb_udata, &src, &inlen, + &dst, &outlen); + if (inlen != *srclen || outlen != *dstlen) { + *srclen -= inlen; + *dstlen -= outlen; + return 0; + } else + return error; } int Index: src/sys/netsmb/subr_mchain.c diff -u src/sys/netsmb/subr_mchain.c:1.22 src/sys/netsmb/subr_mchain.c:1.22.14.1 --- src/sys/netsmb/subr_mchain.c:1.22 Sat May 12 01:40:37 2012 +++ src/sys/netsmb/subr_mchain.c Mon Dec 1 09:31:40 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_mchain.c,v 1.22 2012/05/12 01:40:37 nakayama Exp $ */ +/* $NetBSD: subr_mchain.c,v 1.22.14.1 2014/12/01 09:31:40 martin Exp $ */ /* * Copyright (c) 2000, 2001 Boris Popov @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_mchain.c,v 1.22 2012/05/12 01:40:37 nakayama Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_mchain.c,v 1.22.14.1 2014/12/01 09:31:40 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -251,6 +251,7 @@ mb_put_mem(struct mbchain *mbp, const ch const char *src; int error; size_t cplen, mleft, count; + size_t srclen, dstlen; m = mbp->mb_cur; mleft = mbp->mb_mleft; @@ -267,10 +268,17 @@ mb_put_mem(struct mbchain *mbp, const ch continue; } cplen = mleft > size ? size : mleft; + srclen = dstlen = cplen; dst = mtod(m, char *) + m->m_len; switch (type) { case MB_MCUSTOM: - error = mbp->mb_copy(mbp, source, dst, cplen); + srclen = size; + dstlen = mleft; + error = mbp->mb_copy(mbp, source, dst, &srclen, &dstlen); + if (error == E2BIG) { + mleft = 0; + continue; + } if (error) return error; break; @@ -290,11 +298,11 @@ mb_put_mem(struct mbchain *mbp, const ch memset(dst, 0, cplen); break; } - size -= cplen; - source += cplen; - m->m_len += cplen; - mleft -= cplen; - mbp->mb_count += cplen; + size -= srclen; + source += srclen; + m->m_len += dstlen; + mleft -= dstlen; + mbp->mb_count += dstlen; } mbp->mb_cur = m; mbp->mb_mleft = mleft; Index: src/sys/rump/dev/lib/libnetsmb/Makefile diff -u src/sys/rump/dev/lib/libnetsmb/Makefile:1.4 src/sys/rump/dev/lib/libnetsmb/Makefile:1.4.4.1 --- src/sys/rump/dev/lib/libnetsmb/Makefile:1.4 Thu Mar 13 01:57:29 2014 +++ src/sys/rump/dev/lib/libnetsmb/Makefile Mon Dec 1 09:31:39 2014 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2014/03/13 01:57:29 pooka Exp $ +# $NetBSD: Makefile,v 1.4.4.1 2014/12/01 09:31:39 martin Exp $ # .PATH: ${.CURDIR}/../../../../netsmb @@ -13,5 +13,8 @@ SRCS+= netsmb_component.c CPPFLAGS+= -I${RUMPTOP}/librump/rumpvfs #CPPFLAGS+= -DSMB_SOCKET_DEBUG -DSMB_IOD_DEBUG +SRCS+= netsmb_iconv.c +RUMPCOMP_USER_SRCS= netsmb_user.c + .include <bsd.lib.mk> .include <bsd.klinks.mk> Added files: Index: src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c:1.1.4.2 --- /dev/null Mon Dec 1 09:31:40 2014 +++ src/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c Mon Dec 1 09:31:39 2014 @@ -0,0 +1,79 @@ +/* $NetBSD: netsmb_iconv.c,v 1.1.4.2 2014/12/01 09:31:39 martin Exp $ */ + +/* + * Copyright (c) 2014 Takeshi Nakayama. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: netsmb_iconv.c,v 1.1.4.2 2014/12/01 09:31:39 martin Exp $"); + +#include <sys/param.h> +#include <sys/kernel.h> +#include <sys/systm.h> +#include <sys/errno.h> + +#include <netsmb/iconv.h> + +#include "netsmb_user.h" + +int +iconv_open(const char *to, const char *from, void **handle) +{ + if (strcmp(to, "tolower") && strcmp(to, "toupper")) + return rumpcomp_netsmb_iconv_open(to, from, handle); + return 0; +} + +int +iconv_close(void *handle) +{ + if (handle != NULL) + return rumpcomp_netsmb_iconv_close(handle); + return 0; +} + +int +iconv_conv(void *handle, const char **inbuf, size_t *inbytesleft, + char **outbuf, size_t *outbytesleft) +{ + size_t len; + + if (handle != NULL) + return rumpcomp_netsmb_iconv_conv(handle, inbuf, inbytesleft, + outbuf, outbytesleft); + + if (inbuf == NULL) + return 0; + + if (*inbytesleft > *outbytesleft) + return E2BIG; + + len = *inbytesleft; + memcpy(*outbuf, *inbuf, len); + *inbuf += len; + *inbytesleft = 0; + *outbuf += len; + *outbytesleft -= len; + return 0; +} Index: src/sys/rump/dev/lib/libnetsmb/netsmb_user.h diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_user.h:1.1.4.2 --- /dev/null Mon Dec 1 09:31:40 2014 +++ src/sys/rump/dev/lib/libnetsmb/netsmb_user.h Mon Dec 1 09:31:39 2014 @@ -0,0 +1,31 @@ +/* $NetBSD: netsmb_user.h,v 1.1.4.2 2014/12/01 09:31:39 martin Exp $ */ + +/* + * Copyright (c) 2014 Takeshi Nakayama. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +int rumpcomp_netsmb_iconv_open(const char *, const char *, void **); +int rumpcomp_netsmb_iconv_close(void *); +int rumpcomp_netsmb_iconv_conv(void *, const char **, size_t *, char **, + size_t *); Index: src/sys/rump/dev/lib/libnetsmb/netsmb_user.c diff -u /dev/null src/sys/rump/dev/lib/libnetsmb/netsmb_user.c:1.3.4.2 --- /dev/null Mon Dec 1 09:31:40 2014 +++ src/sys/rump/dev/lib/libnetsmb/netsmb_user.c Mon Dec 1 09:31:39 2014 @@ -0,0 +1,98 @@ +/* $NetBSD: netsmb_user.c,v 1.3.4.2 2014/12/01 09:31:39 martin Exp $ */ + +/* + * Copyright (c) 2014 Takeshi Nakayama. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _KERNEL +#include <stddef.h> +#include <errno.h> +#ifdef __NetBSD__ +#include <iconv.h> +#endif + +#include <rump/rumpuser_component.h> + +#include "netsmb_user.h" + +int +rumpcomp_netsmb_iconv_open(const char *to, const char *from, void **handle) +{ +#ifdef __NetBSD__ + iconv_t cd; + int rv; + + cd = iconv_open(to, from); + if (cd == (iconv_t)-1) + rv = errno; + else { + if (handle != NULL) + *handle = (void *)cd; + rv = 0; + } + + return rumpuser_component_errtrans(rv); +#else + /* fallback to use dumb copy function */ + return 0; +#endif +} + +int +rumpcomp_netsmb_iconv_close(void *handle) +{ +#ifdef __NetBSD__ + int rv; + + if (iconv_close((iconv_t)handle) == -1) + rv = errno; + else + rv = 0; + + return rumpuser_component_errtrans(rv); +#else + /* do nothing */ + return 0; +#endif +} + +int +rumpcomp_netsmb_iconv_conv(void *handle, const char **inbuf, + size_t *inbytesleft, char **outbuf, size_t *outbytesleft) +{ +#ifdef __NetBSD__ + int rv; + + if (iconv((iconv_t)handle, inbuf, inbytesleft, outbuf, outbytesleft) + == (size_t)-1) + rv = errno; + else + rv = 0; + + return rumpuser_component_errtrans(rv); +#else + /* do nothing */ + return 0; +#endif +} +#endif