diff --git a/sys/fs/smbfs/smbfs_smb.c b/sys/fs/smbfs/smbfs_smb.c index c3b65bc5363b..a9700c023ca3 100644 --- a/sys/fs/smbfs/smbfs_smb.c +++ b/sys/fs/smbfs/smbfs_smb.c @@ -1,4 +1,4 @@ -/* $NetBSD: smbfs_smb.c,v 1.45 2014/08/12 06:57:20 maxv Exp $ */ +/* $NetBSD: smbfs_smb.c,v 1.46 2014/11/15 18:52:44 nakayama Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.45 2014/08/12 06:57:20 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: smbfs_smb.c,v 1.46 2014/11/15 18:52:44 nakayama Exp $"); #include #include @@ -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, int limit) 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, int limit, struct smb_cred *scred) 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; diff --git a/sys/fs/smbfs/smbfs_subr.c b/sys/fs/smbfs/smbfs_subr.c index 79ae6662cbb5..c72f46714db9 100644 --- a/sys/fs/smbfs/smbfs_subr.c +++ b/sys/fs/smbfs/smbfs_subr.c @@ -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.17 2014/11/15 18:52:44 nakayama Exp $ */ /* * Copyright (c) 2000-2001, Boris Popov @@ -35,7 +35,7 @@ */ #include -__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.17 2014/11/15 18:52:44 nakayama Exp $"); #include #include @@ -318,14 +318,36 @@ smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, struct smbnode *dnp, } 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; } diff --git a/sys/fs/smbfs/smbfs_subr.h b/sys/fs/smbfs/smbfs_subr.h index 7532d6232766..7a80b9efb4d4 100644 --- a/sys/fs/smbfs/smbfs_subr.h +++ b/sys/fs/smbfs/smbfs_subr.h @@ -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.22 2014/11/15 18:52:44 nakayama Exp $ */ /* * Copyright (c) 2000-2001, Boris Popov @@ -176,7 +176,7 @@ int smbfs_fullpath(struct mbchain *mbp, struct smb_vc *vcp, 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); diff --git a/sys/netsmb/mchain.h b/sys/netsmb/mchain.h index c24d187c89e2..88a1e7563e74 100644 --- a/sys/netsmb/mchain.h +++ b/sys/netsmb/mchain.h @@ -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 */ diff --git a/sys/netsmb/smb_subr.c b/sys/netsmb/smb_subr.c index 536eb46ebc57..84d7e6ca398a 100644 --- a/sys/netsmb/smb_subr.c +++ b/sys/netsmb/smb_subr.c @@ -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.37 2014/11/15 18:52:45 nakayama Exp $ */ /* * Copyright (c) 2000-2001 Boris Popov @@ -35,7 +35,7 @@ */ #include -__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.37 2014/11/15 18:52:45 nakayama Exp $"); #include #include @@ -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 diff --git a/sys/netsmb/subr_mchain.c b/sys/netsmb/subr_mchain.c index cd091b989d74..ae789fc5a0b7 100644 --- a/sys/netsmb/subr_mchain.c +++ b/sys/netsmb/subr_mchain.c @@ -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.23 2014/11/15 18:52:45 nakayama Exp $ */ /* * Copyright (c) 2000, 2001 Boris Popov @@ -35,7 +35,7 @@ */ #include -__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.23 2014/11/15 18:52:45 nakayama Exp $"); #include #include @@ -251,6 +251,7 @@ mb_put_mem(struct mbchain *mbp, const char *source, size_t size, int type) 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 char *source, size_t size, int type) 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 char *source, size_t size, int type) 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;