Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Make rump_smbfs(8) uses host iconv(3) to convert filenames



details:   https://anonhg.NetBSD.org/src/rev/97906111104c
branches:  trunk
changeset: 803887:97906111104c
user:      nakayama <nakayama%NetBSD.org@localhost>
date:      Sat Nov 15 18:49:04 2014 +0000

description:
Make rump_smbfs(8) uses host iconv(3) to convert filenames
character set.

diffstat:

 sys/netsmb/iconv.c                        |  34 +++++++++---
 sys/rump/dev/lib/libnetsmb/Makefile       |   5 +-
 sys/rump/dev/lib/libnetsmb/netsmb_iconv.c |  79 ++++++++++++++++++++++++++++++
 sys/rump/dev/lib/libnetsmb/netsmb_user.c  |  81 +++++++++++++++++++++++++++++++
 sys/rump/dev/lib/libnetsmb/netsmb_user.h  |  31 +++++++++++
 5 files changed, 219 insertions(+), 11 deletions(-)

diffs (truncated from 305 to 300 lines):

diff -r 583243e4a398 -r 97906111104c sys/netsmb/iconv.c
--- a/sys/netsmb/iconv.c        Sat Nov 15 17:49:19 2014 +0000
+++ b/sys/netsmb/iconv.c        Sat Nov 15 18:49:04 2014 +0000
@@ -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 (inbuf == NULL)
+               return(0); /* initial shift state */
+
        if (*inbytesleft > *outbytesleft)
                return(E2BIG);
 
-       if (inbuf == NULL)
-               return(0); /* initial shift state */
-
        (void)memcpy(*outbuf, *inbuf, *inbytesleft);
 
        *outbytesleft -= *inbytesleft;
@@ -59,7 +66,11 @@
                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 @@
                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;
diff -r 583243e4a398 -r 97906111104c sys/rump/dev/lib/libnetsmb/Makefile
--- a/sys/rump/dev/lib/libnetsmb/Makefile       Sat Nov 15 17:49:19 2014 +0000
+++ b/sys/rump/dev/lib/libnetsmb/Makefile       Sat Nov 15 18:49:04 2014 +0000
@@ -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 @@
 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>
diff -r 583243e4a398 -r 97906111104c sys/rump/dev/lib/libnetsmb/netsmb_iconv.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libnetsmb/netsmb_iconv.c Sat Nov 15 18:49:04 2014 +0000
@@ -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;
+}
diff -r 583243e4a398 -r 97906111104c sys/rump/dev/lib/libnetsmb/netsmb_user.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libnetsmb/netsmb_user.c  Sat Nov 15 18:49:04 2014 +0000
@@ -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
diff -r 583243e4a398 -r 97906111104c sys/rump/dev/lib/libnetsmb/netsmb_user.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/dev/lib/libnetsmb/netsmb_user.h  Sat Nov 15 18:49:04 2014 +0000
@@ -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.
+ */



Home | Main Index | Thread Index | Old Index