Make rump_smbfs(8) uses host iconv(3) to convert filenames
character set.
This commit is contained in:
parent
c94539ae6b
commit
fb45a1eb84
|
@ -1,41 +1,48 @@
|
|||
/* $NetBSD: iconv.c,v 1.13 2014/02/20 11:08:57 joerg Exp $ */
|
||||
/* $NetBSD: iconv.c,v 1.14 2014/11/15 18:49:04 nakayama 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.14 2014/11/15 18:49:04 nakayama 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, const char *src, size_t l)
|
|||
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, const void *src, int size)
|
|||
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;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: Makefile,v 1.4 2014/03/13 01:57:29 pooka Exp $
|
||||
# $NetBSD: Makefile,v 1.5 2014/11/15 18:49:04 nakayama 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>
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/* $NetBSD: netsmb_iconv.c,v 1.1 2014/11/15 18:49:04 nakayama 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 2014/11/15 18:49:04 nakayama 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;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
/* $NetBSD: netsmb_user.c,v 1.1 2014/11/15 18:49:04 nakayama 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 <iconv.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <rump/rumpuser_component.h>
|
||||
|
||||
#include "netsmb_user.h"
|
||||
|
||||
int
|
||||
rumpcomp_netsmb_iconv_open(const char *to, const char *from, void **handle)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
int
|
||||
rumpcomp_netsmb_iconv_close(void *handle)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (iconv_close((iconv_t)handle) == -1)
|
||||
rv = errno;
|
||||
else
|
||||
rv = 0;
|
||||
|
||||
return rumpuser_component_errtrans(rv);
|
||||
}
|
||||
|
||||
int
|
||||
rumpcomp_netsmb_iconv_conv(void *handle, const char **inbuf,
|
||||
size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (iconv((iconv_t)handle, inbuf, inbytesleft, outbuf, outbytesleft)
|
||||
== (size_t)-1)
|
||||
rv = errno;
|
||||
else
|
||||
rv = 0;
|
||||
|
||||
return rumpuser_component_errtrans(rv);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
/* $NetBSD: netsmb_user.h,v 1.1 2014/11/15 18:49:04 nakayama 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 *);
|
Loading…
Reference in New Issue