# HG changeset patch # User Thomas De Schampheleire # Date 1563491555 -7200 # Node ID b5b91e854308aa94cb26a47e76bbd3ce27dfd48f # Parent 719ed95c437ea99f25e817317fff9f15804ecda6 ssh: set a valid locale in the ssh-serve process In the SSH client configuration, the setting 'SendEnv' could contain variables like 'LANG', 'LC_ALL', and others. This causes these environment variables (with their values at the client-side) to be set in the server. However, not every locale setting valid in the client, is also valid on the server. This could lead to the error: 'locale.Error: unsupported locale setting' when 'from mercurial import archival, merge as hg_merge, patch, ui' is called. Fix this problem by providing an ini setting 'ssh_locale' that the user can set correctly, and which will be used to set LC_ALL and LANGUAGE in the 'kallithea-cli ssh-serve' process. If an environment variable LC_ALL is set, it takes precedence over all other 'LC_xxx' variables, as well as over LANG. So, setting LC_ALL ensures that no user setting of 'LC_xxx' or 'LANG' could influence ssh-serve badly. There is one environment variable that might overrule LC_ALL, specifically for showing messages: 'LANGUAGE'. GNU gettext lets it take precedence over LC_ALL [1]: "GNU gettext gives preference to LANGUAGE over LC_ALL and LANG for the purpose of message handling" So, also set LANGUAGE to the same value as we set LC_ALL to. The principle of setting a specific locale in the server process to fix this error, was first proposed by Dominik Ruf. [1] https://www.gnu.org/software/gettext/manual/html_node/The-LANGUAGE-variable.html#The-LANGUAGE-variable diff -r 719ed95c437e -r b5b91e854308 development.ini --- a/development.ini Mon Nov 17 14:42:45 2014 -0500 +++ b/development.ini Fri Jul 19 01:12:35 2019 +0200 @@ -238,6 +238,12 @@ ## Path to be used in ssh_authorized_keys file to invoke kallithea-cli with ssh-serve. #kallithea_cli_path = /srv/kallithea/venv/bin/kallithea-cli +## Locale to be used in the ssh-serve command. +## This is needed because an SSH client may try to use its own locale +## settings, which may not be available on the server. +## See `locale -a` for valid values on this system. +#ssh_locale = C.UTF-8 + #################################### ### CELERY CONFIG #### #################################### diff -r 719ed95c437e -r b5b91e854308 kallithea/bin/kallithea_cli_ssh.py --- a/kallithea/bin/kallithea_cli_ssh.py Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/bin/kallithea_cli_ssh.py Fri Jul 19 01:12:35 2019 +0200 @@ -45,6 +45,11 @@ sys.stderr.write("SSH access is disabled.\n") return sys.exit(1) + ssh_locale = kallithea.CONFIG.get('ssh_locale') + if ssh_locale: + os.environ['LC_ALL'] = ssh_locale # trumps everything, including LANG, except LANGUAGE + os.environ['LANGUAGE'] = ssh_locale # trumps LC_ALL for GNU gettext message handling + ssh_original_command = os.environ.get('SSH_ORIGINAL_COMMAND', '') connection = re.search('^([\d\.]+)', os.environ.get('SSH_CONNECTION', '')) client_ip = connection.group(1) if connection else '0.0.0.0' diff -r 719ed95c437e -r b5b91e854308 kallithea/lib/paster_commands/template.ini.mako --- a/kallithea/lib/paster_commands/template.ini.mako Mon Nov 17 14:42:45 2014 -0500 +++ b/kallithea/lib/paster_commands/template.ini.mako Fri Jul 19 01:12:35 2019 +0200 @@ -341,6 +341,12 @@ kallithea_cli_path = ${kallithea_cli_path} %endif +<%text>## Locale to be used in the ssh-serve command. +<%text>## This is needed because an SSH client may try to use its own locale +<%text>## settings, which may not be available on the server. +<%text>## See `locale -a` for valid values on this system. +#ssh_locale = C.UTF-8 + <%text>#################################### <%text>### CELERY CONFIG #### <%text>####################################