Skip to content

Added gettext support for pam and nslcd#64

Open
tsaarni wants to merge 1 commit intoarthurdejong:masterfrom
Nordix:gettext-support
Open

Added gettext support for pam and nslcd#64
tsaarni wants to merge 1 commit intoarthurdejong:masterfrom
Nordix:gettext-support

Conversation

@tsaarni
Copy link

@tsaarni tsaarni commented Mar 18, 2024

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.

@tsaarni tsaarni force-pushed the gettext-support branch 2 times, most recently from 9c7e445 to a4f039e Compare March 19, 2024 07:26
@tsaarni
Copy link
Author

tsaarni commented Mar 21, 2024

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.

@tsaarni tsaarni force-pushed the gettext-support branch 2 times, most recently from b5eb63f to c3e8f81 Compare March 21, 2024 09:53
@tsaarni tsaarni marked this pull request as ready for review March 21, 2024 10:00
@tsaarni tsaarni force-pushed the gettext-support branch 2 times, most recently from 3751e9c to a9768bd Compare August 7, 2024 13:15
@tsaarni tsaarni changed the title Added gettext support for pam module Added gettext support for pam and nslcd Aug 7, 2024
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
@tsaarni
Copy link
Author

tsaarni commented Aug 7, 2025

I have rebased this PR on top of master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: provide internationalization support

1 participant