Index: etc/defaults/rc.conf =================================================================== RCS file: /home/ncvs/src/etc/defaults/rc.conf,v retrieving revision 1.254 diff -u -r1.254 rc.conf --- etc/defaults/rc.conf 22 Jul 2005 00:38:55 -0000 1.254 +++ etc/defaults/rc.conf 20 Aug 2005 12:16:27 -0000 @@ -492,6 +492,9 @@ # ruleset file. newsyslog_enable="YES" # Run newsyslog at startup. newsyslog_flags="-CN" # Newsyslog flags to create marked files +kiconv_load="NO" # Load kiconv tables at startup. +#kiconv_locale="ja_JP.UTF-8" # Locale names to be loaded. +#kiconv_encoding="CP932" # Encoding names to be loaded. ############################################################## ### Jail Configuration ####################################### Index: etc/rc.d/Makefile =================================================================== RCS file: /home/ncvs/src/etc/rc.d/Makefile,v retrieving revision 1.53 diff -u -r1.53 Makefile --- etc/rc.d/Makefile 30 Jun 2005 04:52:47 -0000 1.53 +++ etc/rc.d/Makefile 20 Aug 2005 11:55:20 -0000 @@ -17,7 +17,7 @@ ip6addrctl ip6fw ipfilter ipfs ipfw ipmon \ ipnat ipsec ipxrouted isdnd \ jail \ - kadmind kerberos keyserv kldxref kpasswdd \ + kadmind kerberos keyserv kiconv kldxref kpasswdd \ ldconfig local localpkg lpd \ mixer motd mountcritlocal mountcritremote \ mountd moused mroute6d mrouted msgs \ Index: etc/rc.d/kiconv =================================================================== RCS file: etc/rc.d/kiconv diff -N etc/rc.d/kiconv --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ etc/rc.d/kiconv 20 Aug 2005 12:16:41 -0000 @@ -0,0 +1,56 @@ +#!/bin/sh +# +# Copyright (c) 2005 Ryuichiro Imura +# 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. +# +# $FreeBSD$ +# + +# PROVIDE: kiconv +# REQUIRE: ldconfig +# KEYWORD: nojail + +. /etc/rc.subr + +name="kiconv" +kiconv_command="/usr/sbin/kiconvctl" +rcvar="kiconv_load" +start_cmd="kiconv_load" +stop_cmd=":" + +kiconv_load() { + kiconv=${kiconv_command} + kldstat -m iconv >/dev/null 2>&1 || ${kiconv} load || exit + echo -n 'Loading kiconv tables' + for i in ${kiconv_locale}; do + ${kiconv} add -l ${i} + done + for i in ${kiconv_encoding}; do + ${kiconv} add ${i} + done + echo '.' +} + +load_rc_config $name +run_rc_command "$1" Index: share/man/man5/rc.conf.5 =================================================================== RCS file: /home/ncvs/src/share/man/man5/rc.conf.5,v retrieving revision 1.256 diff -u -r1.256 rc.conf.5 --- share/man/man5/rc.conf.5 30 Jun 2005 13:10:37 -0000 1.256 +++ share/man/man5/rc.conf.5 20 Aug 2005 15:33:56 -0000 @@ -3173,6 +3173,36 @@ which causes log files flagged with a .Cm C to be created. +.\" ----- kiconv settings --------------------------------------- +.It Va kiconv_load +.Pq Vt bool +If set to +.Dq Li YES , +load +.Xr kiconv 3 +tables at startup. +If no plan to use +.Va vfs.usermount +.Xr sysctl 8 +feature, you need not to set to +.Dq Li YES +this variable. +.It Va kiconv_locale +.Pq Vt str +Specify locale names to be loaded, when +.Va kiconv_load +is set to +.Dq Li YES . +Character conversion tables of encoding of this locale +and tolower/toupper tables are loaded. +.It Va kiconv_encoding +.Pq Vt str +Specify encoding names to be loaded, when +.Va kiconv_load +is set to +.Dq Li YES . +Character conversion tables of this encoding are loaded. +.\" ------------------------------------------------------------- .It Va ramdisk_units .Pq Vt str A list of one or more ramdisk units to configure with Index: usr.sbin/Makefile =================================================================== RCS file: /home/ncvs/src/usr.sbin/Makefile,v retrieving revision 1.333 diff -u -r1.333 Makefile --- usr.sbin/Makefile 20 Jul 2005 22:53:57 -0000 1.333 +++ usr.sbin/Makefile 20 Aug 2005 11:53:54 -0000 @@ -68,6 +68,7 @@ ${_keyserv} \ ${_kgmon} \ ${_kgzip} \ + kiconvctl \ kldxref \ lastlogin \ ${_lpr} \ Index: usr.sbin/kiconvctl/Makefile =================================================================== RCS file: usr.sbin/kiconvctl/Makefile diff -N usr.sbin/kiconvctl/Makefile --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ usr.sbin/kiconvctl/Makefile 20 Aug 2005 11:50:49 -0000 @@ -0,0 +1,14 @@ +# +# $FreeBSD$ +# + +PROG= kiconvctl +SRCS= kiconvctl.c +MAN= kiconvctl.8 +DPADD= ${LIBKICONV} +LDADD= -lkiconv +CFLAGS+= -I../../sys + +WARNS?= 2 + +.include Index: usr.sbin/kiconvctl/kiconvctl.8 =================================================================== RCS file: usr.sbin/kiconvctl/kiconvctl.8 diff -N usr.sbin/kiconvctl/kiconvctl.8 --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ usr.sbin/kiconvctl/kiconvctl.8 23 Aug 2005 12:27:51 -0000 @@ -0,0 +1,97 @@ +.\" +.\" Copyright (c) 2003, 2005 Ryuichiro Imura +.\" 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. +.\" +.\" $FreeBSD$ +.\" +.Dd Aug 23, 2005 +.Dt KICONVCTL 8 +.Os +.Sh NAME +.Nm kiconvctl +.Nd kiconv conversion table control program +.Sh SYNOPSIS +.Nm +.Ic add +.Op Fl v +.Ar encoding +.Nm +.Ic add +.Op Fl v +.Fl l Ar locale-name +.Nm +.Ic drvlist +.Nm +.Ic list +.Op Fl u +.Nm +.Ic load +.Nm +.Ic unload +.Op Fl f +.Sh DESCRIPTION +The +.Nm +utility provides a way to maintain +.Xr kiconv 3 +conversion tables. +.Pp +The following commands are supported: +.Bl -tag -width "remove" +.It Ic add +Add conversion tables to the kernel. +If you specify +.Ar locale-name +with +.Fl l +option, tolower/toupper table is additionally registered. +.It Ic drvlist +List all available kiconv drivers. +.It Ic list +Show info about all conversion tables in the kernel. +.It Ic load +Load LIBICONV kernel module. +.It Ic unload +Unload LIBICONV kernel module. +If you specify +.Fl f +option, all related kernel modules will be also unloaded before +unloading LIBICONV kernel module. +.El +.Sh DIAGNOSTICS +The +.Nm +utility exits with a status of 0 on success +and with a nonzero status if an error occurs. +.Sh SEE ALSO +.Xr iconv 3 , +.Xr kiconv 3 +.Sh HISTORY +The +.Nm +utility first appeared in +.Fx 6.1 . +.Sh AUTHORS +.An Ryuichiro Imura +.Aq imura@ryu16.org . Index: usr.sbin/kiconvctl/kiconvctl.c =================================================================== RCS file: usr.sbin/kiconvctl/kiconvctl.c diff -N usr.sbin/kiconvctl/kiconvctl.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ usr.sbin/kiconvctl/kiconvctl.c 23 Aug 2005 12:21:20 -0000 @@ -0,0 +1,420 @@ +/*- + * Copyright (c) 2003, 2005 Ryuichiro Imura + * 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 AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +static int cspair_add(int, char **); +#if has_remove_mib +static int cspair_flush(void); +#endif +static int driver_list(void); +static int cspair_list(int, char **); +#if has_remove_mib +static int cspair_remove(int); +#endif +static int load_libiconv(void); +static int unload_libiconv(int, char **); +static void usage(void); + +static const char *iconv_klds[] = { + "cd9660_iconv", + "msdosfs_iconv", + "ntfs_iconv", + "smbfs", + "udf_iconv" +}; + +static int +cspair_add(int argc, char **argv) +{ + int ch, error, verbose; + char *locale, *csp; + + error = verbose = 0; + locale = NULL; + while ((ch = getopt(argc, argv, "l:v")) != -1) + switch (ch) { + case 'l': + locale = optarg; + break; + case 'v': + verbose = 1; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (locale) { + if (argc) + usage(); + + if (setlocale(LC_CTYPE, locale) == NULL) { + warnx("wrong locale name: %s", locale); + return (-1); + } + csp = strchr(locale, '.'); + if (!csp++) + return (-1); + } else { + csp = *argv; + + if (--argc) + usage(); + } + + if (verbose) + printf("Adding tables \"%s\" <-> \"%s\"\n", ENCODING_UNICODE, csp); + + error = kiconv_add_xlat16_cspairs(ENCODING_UNICODE, + kiconv_quirkcs(csp, KICONV_VENDOR_MICSFT)); + if (error) + return (error); + error = kiconv_add_xlat16_cspairs(ENCODING_UNICODE, csp); + if (error) + return (error); + + return (error); +} + +#if has_remove_mib +static int +cspair_flush(void) +{ + struct iconv_cspair_info *csi; + size_t i, size; + int rval = 0, error; + + if (sysctlbyname("kern.iconv.cslist", NULL, &size, NULL, 0) == -1) + return (-1); + if (size > 0) { + csi = malloc(size); + if (csi == NULL) { + warnc(EX_OSERR, "malloc()"); + return (-1); + } + if (sysctlbyname("kern.iconv.cslist", csi, &size, NULL, 0) == -1) { + free(csi); + return (-1); + } + for (i = 0; i < (size/sizeof(*csi)); i++, csi++) + error = cspair_remove(csi->cs_id); + if (error) + rval = 1; + } + + return (rval); +} +#endif + +static int +driver_list(void) +{ + char *name; + size_t size; + + if (sysctlbyname("kern.iconv.drvlist", NULL, &size, NULL, 0) == -1) + return (-1); + if (size > 0) { + name = malloc(size); + if (name == NULL) { + warnc(EX_OSERR, "malloc()"); + return (-1); + } + if (sysctlbyname("kern.iconv.drvlist", name, &size, NULL, 0) == -1) { + free(name); + return (-1); + } + while (*name != '\0') { + printf("%s\n",name); + name += strlen(name) + 1; + } + } + + return (0); +} + +static int +cspair_list(int argc, char **argv) +{ + struct iconv_cspair_info *csi; + size_t i, size; + int ch, reg = 1, list = 0; + char **fromlist, **tolist, **fp, **tp; + char unicode[] = ENCODING_UNICODE; + + while ((ch = getopt(argc, argv, "u")) != -1) + switch (ch) { + case 'u': + if (kiconv_lookupconv(unicode) != 0) { + printf("Unicode converter doesn't exist\n"); + exit(0); + } + reg = 0; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc) + usage(); + + if (sysctlbyname("kern.iconv.cslist", NULL, &size, NULL, 0) == -1) + return (-1); + if (size > 0) { + csi = malloc(size); + if (csi == NULL) { + warnc(EX_OSERR, "malloc()"); + return (-1); + } + if (sysctlbyname("kern.iconv.cslist", csi, &size, NULL, 0) == -1) { + free(csi); + return (-1); + } + if (reg) { + printf("Loaded Tables\n"); + printf("Id Refs %-16s %-16s\n", "From","To"); + } else { + printf("Non Unicode Conversion Tables\n"); + printf(" %-16s|%-16s\n", "From","To"); + printf(" ----------------+----------------\n"); + fromlist = malloc(sizeof(*fromlist) * size/sizeof(*csi)); + if (fromlist == NULL) { + warnc(EX_OSERR, "malloc()"); + return (-1); + } + tolist = malloc(sizeof(*tolist) * size/sizeof(*csi)); + if (tolist == NULL) { + warnc(EX_OSERR, "malloc()"); + return (-1); + } + fp = fromlist; + tp = tolist; + *fp++ = unicode; + *tp++ = unicode; + } + for (i = 0; i < (size/sizeof(*csi)); i++, csi++) { + if (reg) { + printf("%2d %4d %-16s %-16s\n", + csi->cs_id, csi->cs_refcount, csi->cs_from, + csi->cs_to); + } else { + if (strcmp(csi->cs_to, unicode) == 0) { + *fp++ = csi->cs_from; + } else if (strcmp(csi->cs_from, unicode) == 0) { + *tp++ = csi->cs_to; + } else { + if (strcmp(csi->cs_to, KICONV_WCTYPE_NAME) == 0) + printf(" %-16s|%-16s\n", csi->cs_from, "[de]capitalize"); + else + printf(" %-16s|%-16s\n", csi->cs_from, csi->cs_to); + list = 1; + } + } + } + } + if (!reg) { + if (!list) + printf("None\n"); + fp = fromlist; + tp = tolist; + printf("\n"); + printf("Possible Conversions using Unicode Converter\n"); + printf(" %-16s|%-16s\n", "From","To"); + printf(" ----------------+----------------\n"); + while (*fp || *tp) { + if (*fp) + printf(" %-16s|",*fp++); + else + printf(" %-16s|"," "); + if (*tp) + printf("%-16s\n",*tp++); + else + printf("%-16s"," "); + } + free(fromlist); + free(tolist); + } + + return (0); +} + +#if has_remove_mib +static int +cspair_remove(int id) +{ + if (sysctlbyname("kern.iconv.remove", NULL, 0, &id, sizeof(id)) == -1) { + warn("Can't remove id %d", id); + return (-1); + } + return (0); +} +#endif + +static int +load_libiconv(void) +{ + int fileid; + + fileid = kldload("libiconv"); + if (fileid < 0) + return (-1); + else + return (0); +} + +static int +unload_libiconv(int argc, char **argv) +{ + int ch, i, error = 0, fileid, force = 0; + + while ((ch = getopt(argc, argv, "f")) != -1) + switch (ch) { + case 'f': + force = 1; + break; + default: + usage(); + } + argc -= optind; + argv += optind; + + if (argc) + usage(); + + if ((fileid = kldfind("libiconv")) < 0) + return (0); + + if (force) { + for (i = 0; i < sizeof(iconv_klds)/sizeof(iconv_klds[0]); i++) { + if ((fileid = kldfind(iconv_klds[i])) < 0) + continue; + if (kldunload(fileid) < 0) { + warn("Unloading %s failed.", iconv_klds[i]); + error = 1; + } + } + if (error) + return (-1); + } + + if ((fileid = kldfind("libiconv")) < 0) + return (0); + if (kldunload(fileid) < 0) { + warn("Unloading libiconv failed."); + return (-1); + } + return (0); +} + +int +main(int argc, char **argv) +{ + int error; + + if (argc < 2) + usage(); + + if (!strcmp(argv[1], "list") && argc >= 2) { + error = cspair_list(argc - 1, argv + 1); + if (error) + err(1, "list failed"); + } else if (!strcmp(argv[1], "add") && argc >= 3) { + error = cspair_add(argc - 1, argv + 1); + if (error) + err(1, "register failed"); +#if has_remove_mib + } else if (!strcmp(argv[1], "flush") && argc == 2) { + error = cspair_flush(); + if (error) + err(1, "flush failed"); + } else if (!strcmp(argv[1], "remove") && argc == 3) { + int id; + if ((id = (int)strtol(argv[2], (char **)NULL, 10)) == 0) + err(1, "%s", argv[2]); + error = cspair_remove(id); + if (error) + err(1, "unregister failed"); +#endif + } else if (!strcmp(argv[1], "load") && argc == 2) { + error = load_libiconv(); + if (error) + err(1, "can't load libiconv"); + } else if (!strcmp(argv[1], "unload") && argc >= 2) { + error = unload_libiconv(argc - 1, argv + 1); + if (error) + err(1, "unload failed"); + } else if (!strcmp(argv[1], "drvlist") && argc == 2) { + error = driver_list(); + if (error) + err(1, "list failed"); + } else + usage(); + + exit (0); +} + +static void +usage(void) +{ +#if has_remove_mib + fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", + "usage: kiconvctl add [-v] encoding", + " kiconvctl add [-v] -l locale-name", + " kiconvctl drvlist", + " kiconvctl flush", + " kiconvctl list [-u]", + " kiconvctl load", + " kiconvctl remove id", + " kiconvctl unload [-f]"); +#else + fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n", + "usage: kiconvctl add [-v] encoding", + " kiconvctl add [-v] -l locale-name", + " kiconvctl drvlist", + " kiconvctl list [-u]", + " kiconvctl load", + " kiconvctl unload [-f]"); +#endif + exit(EX_USAGE); +}