Adjust smbfs/netsmb for filenames byte length changes that come as
a result of iconv conversion. Most codes are taken from FreeBSD.
This commit is contained in:
parent
fb45a1eb84
commit
8c1c14022f
|
@ -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 @@ 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;
|
||||
|
|
|
@ -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 @@ 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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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 @@ 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
|
||||
|
|
|
@ -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 @@ 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;
|
||||
|
|
Loading…
Reference in New Issue