nss-pam-ldapd
nss-pam-ldapd copied to clipboard
Added gettext support for pam and nslcd
This pull request adds optional support for internationalization for the PAM module and nslcd. The feature is enabled by new flag ./configure --enable-nls
. The feature is disabled by default. When disabled the change no-op - the function calls to translate strings _("my message")
evaluates to simply "my message"
.
Detailed notes for reviewers:
Gnu gettext comes with tool gettextize to prepare a project for internationalization, but I propose NOT using this tool in this case. If running gettextize, it will generate many scripts and modify quite many files in the project (see here: "Some of this infrastructure, namely ca. 20 Autoconf macro files and the config.rpath file, is also contained in Gnulib and may be imported by gnulib-tool.") adding overhead to the project. In my view is avoidable. Therefore, in this change I propose manually written po/Makefile.am
that conceptually mimics "gettextized" project but with very simplistic approach.
Call _(msgid)
will forward to char * dgettext (const char * domainname, const char * msgid)
which is a version of gettext()
that request lookup from specific domainname (in this case PACKAGE
i.e. nss-pam-ldapd
) and not from the default domain in the currently running process.
The program that runs the PAM modules might have set up default domain to something else, and we should not depend on, or change that. Therefore at initialization there is a call bindtextdomain(PACKAGE, LOCALEDIR)
to instruct gettext where translation files for the domain nss-pam-ldapd
are found. Similar approach is used by Linux PAM.
Nslcd as a standalone program requires setting locales.
The pull request includes localization for two languages as an example: Finnish and Swedish.
Closes #63.
I'm dropping gettext.h wrapper that GNU gettext project offers to be included in projects (link). CodeQL reported critical finding which I'm not 100% sure about it ("May return stack-allocated memory from msg_ctxt_id" here), the header is relatively complicated, and I'm not sure why it would be needed in the first place. Are there real portability or other problems it addresses? For now, I replace it with simple macro that directly maps _()
to dgettext()
, see common/gettext.h
.