diff --git a/MANIFEST b/MANIFEST index f50d03e8f..a2e43bf73 100644 --- a/MANIFEST +++ b/MANIFEST @@ -93,6 +93,7 @@ include/Makefile.in include/alloc.h include/error.h include/fileops.h +include/gettext.h include/lbuf.h include/list.h include/missing.h diff --git a/common/aix.c b/common/aix.c index 0ca732f59..875eb8cbb 100644 --- a/common/aix.c +++ b/common/aix.c @@ -28,9 +28,6 @@ # include # endif #endif /* STDC_HEADERS */ -#ifdef HAVE_LIBINTL_H -# include -#endif #include #include @@ -38,6 +35,9 @@ #include "alloc.h" #include "error.h" +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" + #ifdef HAVE_GETUSERATTR #ifndef HAVE_SETRLIMIT64 diff --git a/common/alloc.c b/common/alloc.c index b5cbd6caa..d3a251657 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -47,14 +47,14 @@ #ifdef HAVE_INTTYPES_H # include #endif -#ifdef HAVE_LIBINTL_H -# include -#endif #include "missing.h" #include "alloc.h" #include "error.h" +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" + /* * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t * could be signed (as it is on SunOS 4.x). This just means that diff --git a/compat/strsignal.c b/compat/strsignal.c index bfe05746e..a13346c10 100644 --- a/compat/strsignal.c +++ b/compat/strsignal.c @@ -20,12 +20,12 @@ #include #include -#ifdef HAVE_LIBINTL_H -# include -#endif #include "missing.h" +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" + #if defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST == 1 # define my_sys_siglist sys_siglist #elif defined(HAVE_DECL__SYS_SIGLIST) && HAVE_DECL__SYS_SIGLIST == 1 diff --git a/config.h.in b/config.h.in index 43abab0e1..ec57bfd70 100644 --- a/config.h.in +++ b/config.h.in @@ -868,23 +868,7 @@ #undef ISSET #define ISSET(t, f) ((t) & (f)) -/* - * Internationalization support. - */ -#ifdef HAVE_LIBINTL_H -# define _(String) gettext(String) -# define gettext_noop(String) String -# define N_(String) gettext_noop(String) -#else -# define _(String) String -# define N_(String) String -# define textdomain(Domain) -# define bindtextdomain(Package, Directory) -# define ngettext(String, String_Plural, N) \ - ((N) == 1 ? (String) : (String_Plural)) -#endif /* HAVE_LIBINTL_H */ - -/* New ANSI-style OS defs for HP-UX and ConvexOS. */ +/* ANSI-style OS defs for HP-UX and ConvexOS. */ #if defined(hpux) && !defined(__hpux) # define __hpux 1 #endif /* hpux */ diff --git a/configure.in b/configure.in index 82f69e8a5..b6ea098f3 100644 --- a/configure.in +++ b/configure.in @@ -3180,23 +3180,7 @@ AH_BOTTOM([/* #undef ISSET #define ISSET(t, f) ((t) & (f)) -/* - * Internationalization support. - */ -#ifdef HAVE_LIBINTL_H -# define _(String) gettext(String) -# define gettext_noop(String) String -# define N_(String) gettext_noop(String) -#else -# define _(String) String -# define N_(String) String -# define textdomain(Domain) -# define bindtextdomain(Package, Directory) -# define ngettext(String, String_Plural, N) \ - ((N) == 1 ? (String) : (String_Plural)) -#endif /* HAVE_LIBINTL_H */ - -/* New ANSI-style OS defs for HP-UX and ConvexOS. */ +/* ANSI-style OS defs for HP-UX and ConvexOS. */ #if defined(hpux) && !defined(__hpux) # define __hpux 1 #endif /* hpux */ diff --git a/doc/Makefile.in b/doc/Makefile.in index c5b53c8ba..d4fb2e644 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -25,7 +25,7 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ # Tools to use -NROFF = @NROFFPROG@ -Tascii +NROFF = @NROFFPROG@ # Our install program supports extra flags... INSTALL = $(SHELL) $(top_srcdir)/install-sh -c diff --git a/include/gettext.h b/include/gettext.h new file mode 100644 index 000000000..27f079617 --- /dev/null +++ b/include/gettext.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2011 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef _SUDO_GETTEXT_H +#define _SUDO_GETTEXT_H + +/* + * Solaris locale.h includes libintl.h which causes problems when we + * redefine the gettext functions. We include it first to avoid this. + */ +#if defined(HAVE_LOCALE_H) && defined(__sun__) && defined(__svr4__) +# include +#endif + +#ifdef HAVE_LIBINTL_H + +# include + +/* + * If DEFAULT_TEXT_DOMAIN is defined, use its value as the domain for + * gettext() and ngettext() instead of the value set by textdomain(). + * This is used by the sudoers plugin as well as the convenience libraries. + */ +# ifdef DEFAULT_TEXT_DOMAIN +# undef gettext +# define gettext(String) \ + dgettext(DEFAULT_TEXT_DOMAIN, String) +# undef ngettext +# define ngettext(String, String_Plural, N) \ + dngettext(DEFAULT_TEXT_DOMAIN, String, String_Plural, N) +# endif + +/* Gettext convenience macros */ +# define _(String) gettext(String) +# define gettext_noop(String) String +# define N_(String) gettext_noop(String) + +#else /* !HAVE_LIBINTL_H */ + +/* + * Internationalization is either unavailable or has been disabled. + * Define away the gettext functions used by sudo. + */ +# define _(String) String +# define N_(String) String +# define textdomain(Domain) +# define bindtextdomain(Package, Directory) +# define ngettext(String, String_Plural, N) \ + ((N) == 1 ? (String) : (String_Plural)) + +#endif /* HAVE_LIBINTL_H */ + +#endif /* _SUDO_GETTEXT_H */ diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index f60f64ef3..dae5952e0 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -433,9 +433,7 @@ sudoers_io_open(unsigned int version, sudo_conv_t conversation, goto done; } -#ifdef HAVE_LIBINTL_H bindtextdomain("sudoers", LOCALEDIR); -#endif sudo_setpwent(); sudo_setgrent(); diff --git a/plugins/sudoers/plugin_error.c b/plugins/sudoers/plugin_error.c index 468f1d451..3d9f84cd6 100644 --- a/plugins/sudoers/plugin_error.c +++ b/plugins/sudoers/plugin_error.c @@ -23,17 +23,15 @@ #include #include #include -#ifdef HAVE_LIBINTL_H -# include -# undef _ -# define _(String) dgettext("sudoers", String) -#endif #include "missing.h" #include "alloc.h" #include "error.h" #include "sudo_plugin.h" +#define DEFAULT_TEXT_DOMAIN "sudoers" +#include "gettext.h" + static void _warning(int, const char *, va_list); void plugin_cleanup(int); diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index f639d1e25..45dc2fe4d 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -163,9 +163,7 @@ sudoers_policy_open(unsigned int version, sudo_conv_t conversation, return -1; } -#ifdef HAVE_LIBINTL_H bindtextdomain("sudoers", LOCALEDIR); -#endif /* * Signal setup: diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index f866a496c..76e3df1bb 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -35,16 +35,13 @@ #include "sudo_nss.h" #include "sudo_plugin.h" +#define DEFAULT_TEXT_DOMAIN "sudoers" +#include "gettext.h" + #ifdef HAVE_MBR_CHECK_MEMBERSHIP # include #endif -#ifdef HAVE_LIBINTL_H -# include -# undef _ -# define _(String) dgettext("sudoers", String) -#endif - /* * Info pertaining to the invoking user. */ diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index c33a1c764..2105c9733 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -55,9 +55,6 @@ #ifndef HAVE_TIMESPEC # include "compat/timespec.h" #endif -#ifdef HAVE_LIBINTL_H -# include -#endif #include #include #include @@ -94,6 +91,7 @@ #include "missing.h" #include "alloc.h" #include "error.h" +#include "gettext.h" #ifndef LINE_MAX # define LINE_MAX 2048 @@ -245,10 +243,8 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); decimal = localeconv()->decimal_point; #endif -#ifdef HAVE_LIBINTL_H bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have sudoreplay domain */ textdomain("sudoers"); -#endif while ((ch = getopt(argc, argv, "d:f:hlm:s:V")) != -1) { switch(ch) { diff --git a/plugins/sudoers/visudo.c b/plugins/sudoers/visudo.c index a4bbeb200..522286d8e 100644 --- a/plugins/sudoers/visudo.c +++ b/plugins/sudoers/visudo.c @@ -74,14 +74,12 @@ #ifdef HAVE_SETLOCALE # include #endif -#ifdef HAVE_LIBINTL_H -# include -#endif #include "sudoers.h" #include "interfaces.h" #include "parse.h" #include "redblack.h" +#include "gettext.h" #include "sudoers_version.h" #include @@ -154,17 +152,16 @@ main(int argc, char *argv[]) malloc_options = "AFGJPR"; #endif -#ifdef HAVE_SETLOCALE - setlocale(LC_ALL, ""); -#endif -#ifdef HAVE_LIBINTL_H - bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have visudo domain */ - textdomain("sudoers"); -#endif - #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME) setprogname(argc > 0 ? argv[0] : "visudo"); #endif + +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); +#endif + bindtextdomain("sudoers", LOCALEDIR); /* XXX - should have visudo domain */ + textdomain("sudoers"); + if (argc < 1) usage(1); diff --git a/src/error.c b/src/error.c index 87a16c747..ed3ccabd1 100644 --- a/src/error.c +++ b/src/error.c @@ -22,13 +22,13 @@ #include #include #include -#ifdef HAVE_LIBINTL_H -# include -#endif #include "missing.h" #include "error.h" +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" + static void _warning(int, const char *, va_list); void cleanup(int); diff --git a/src/net_ifs.c b/src/net_ifs.c index 4c1ad765b..3dc1f4dfd 100644 --- a/src/net_ifs.c +++ b/src/net_ifs.c @@ -59,9 +59,6 @@ struct rtentry; #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ -#ifdef HAVE_LIBINTL_H -# include -#endif #include #include #ifdef _ISC @@ -87,6 +84,9 @@ struct rtentry; #include "alloc.h" #include "error.h" +#define DEFAULT_TEXT_DOMAIN "sudo" +#include "gettext.h" + /* Minix apparently lacks IFF_LOOPBACK */ #ifndef IFF_LOOPBACK # define IFF_LOOPBACK 0 diff --git a/src/sesh.c b/src/sesh.c index 00f13a145..f6818ce60 100644 --- a/src/sesh.c +++ b/src/sesh.c @@ -29,11 +29,9 @@ #ifdef HAVE_SETLOCALE # include #endif -#ifdef HAVE_LIBINTL_H -# include -#endif #include "missing.h" +#include "gettext.h" int main (int argc, char *argv[]) @@ -43,10 +41,8 @@ main (int argc, char *argv[]) #ifdef HAVE_SETLOCALE setlocale(LC_ALL, ""); #endif -#ifdef HAVE_LIBINTL_H - bindtextdomain("sudo", LOCALEDIR); - textdomain("sudo"); -#endif + bindtextdomain(PACKAGE_NAME, LOCALEDIR); + textdomain(PACKAGE_NAME); if (argc < 2) errx(EXIT_FAILURE, _("requires at least one argument")); diff --git a/src/sudo.c b/src/sudo.c index 768a8a518..7ec89f83b 100644 --- a/src/sudo.c +++ b/src/sudo.c @@ -169,19 +169,16 @@ main(int argc, char *argv[], char *envp[]) malloc_options = "AFGJPR"; #endif -#ifdef HAVE_SETLOCALE - setlocale(LC_ALL, ""); -#endif - #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME) if (argc > 0) setprogname(argv[0]); #endif -#ifdef HAVE_LIBINTL_H - bindtextdomain("sudo", LOCALEDIR); - textdomain("sudo"); +#ifdef HAVE_SETLOCALE + setlocale(LC_ALL, ""); #endif + bindtextdomain(PACKAGE_NAME, LOCALEDIR); + textdomain(PACKAGE_NAME); /* Must be done before we do any password lookups */ #if defined(HAVE_GETPRPWNAM) && defined(HAVE_SET_AUTH_PARAMETERS) diff --git a/src/sudo.h b/src/sudo.h index 1f5cc6705..64022c460 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -24,9 +24,6 @@ #ifndef _SUDO_SUDO_H #define _SUDO_SUDO_H -#ifdef HAVE_LIBINTL_H -# include -#endif #include #include @@ -35,6 +32,7 @@ #include "error.h" #include "fileops.h" #include "list.h" +#include "gettext.h" #ifdef __TANDEM # define ROOT_UID 65535