Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added gettext support for pam module #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tsaarni
Copy link

@tsaarni tsaarni commented Mar 18, 2024

This pull request adds optional support for internationalization for the PAM module. 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.

In initialization we call bindtextdomain(PACKAGE, LOCALEDIR) to instruct gettext where translation files for the domain nss-pam-ldapd are found.

Similar approaches are used by Linux PAM.

The pull request includes localization for two languages as an example: Finnish and Swedish.

Closes #63.

common/gettext.h Fixed Show fixed Hide fixed
@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.

Signed-off-by: Tero Saarni <tero.saarni@est.tech>
@tsaarni tsaarni marked this pull request as ready for review March 21, 2024 10:00
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