Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Adjust smbfs/netsmb for filenames byte length changes th...
details: https://anonhg.NetBSD.org/src/rev/20ba4c4bd567
branches: trunk
changeset: 333746:20ba4c4bd567
user: nakayama <nakayama%NetBSD.org@localhost>
date: Sat Nov 15 18:52:44 2014 +0000
description:
Adjust smbfs/netsmb for filenames byte length changes that come as
a result of iconv conversion. Most codes are taken from FreeBSD.
diffstat:
sys/fs/smbfs/smbfs_smb.c | 10 +++++-----
sys/fs/smbfs/smbfs_subr.c | 38 ++++++++++++++++++++++++++++++--------
sys/fs/smbfs/smbfs_subr.h | 4 ++--
sys/netsmb/mchain.h | 3 ++-
sys/netsmb/smb_subr.c | 19 ++++++++++++++-----
sys/netsmb/subr_mchain.c | 24 ++++++++++++++++--------
6 files changed, 69 insertions(+), 29 deletions(-)
diffs (241 lines):
diff -r b7c30a0a3b62 -r 20ba4c4bd567 sys/fs/smbfs/smbfs_smb.c
--- a/sys/fs/smbfs/smbfs_smb.c Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/fs/smbfs/smbfs_smb.c Sat Nov 15 18:52:44 2014 +0000
@@ -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 <sys/cdefs.h>
-__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 <sys/param.h>
#include <sys/systm.h>
@@ -1129,7 +1129,7 @@
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 @@
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 @@
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 -r b7c30a0a3b62 -r 20ba4c4bd567 sys/fs/smbfs/smbfs_subr.c
--- a/sys/fs/smbfs/smbfs_subr.c Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/fs/smbfs/smbfs_subr.c Sat Nov 15 18:52:44 2014 +0000
@@ -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 <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.17 2014/11/15 18:52:44 nakayama Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -318,14 +318,36 @@
}
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 -r b7c30a0a3b62 -r 20ba4c4bd567 sys/fs/smbfs/smbfs_subr.h
--- a/sys/fs/smbfs/smbfs_subr.h Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/fs/smbfs/smbfs_subr.h Sat Nov 15 18:52:44 2014 +0000
@@ -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_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 -r b7c30a0a3b62 -r 20ba4c4bd567 sys/netsmb/mchain.h
--- a/sys/netsmb/mchain.h Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/netsmb/mchain.h Sat Nov 15 18:52:44 2014 +0000
@@ -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 -r b7c30a0a3b62 -r 20ba4c4bd567 sys/netsmb/smb_subr.c
--- a/sys/netsmb/smb_subr.c Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/netsmb/smb_subr.c Sat Nov 15 18:52:44 2014 +0000
@@ -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 <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.37 2014/11/15 18:52:45 nakayama Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -307,11 +307,20 @@
}
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 -r b7c30a0a3b62 -r 20ba4c4bd567 sys/netsmb/subr_mchain.c
--- a/sys/netsmb/subr_mchain.c Sat Nov 15 18:49:04 2014 +0000
+++ b/sys/netsmb/subr_mchain.c Sat Nov 15 18:52:44 2014 +0000
@@ -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 <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.23 2014/11/15 18:52:45 nakayama Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -251,6 +251,7 @@
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 @@
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 @@
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;
Home |
Main Index |
Thread Index |
Old Index