1
0
mirror of https://github.com/slicer69/doas synced 2024-06-29 05:54:20 +00:00

Make sure LANG environment variable is copied over to the target

user from the original, if it is defined. Avoids switching languages
on the original user by surprise.
This commit is contained in:
Jesse Smith 2021-06-01 14:09:28 -03:00
parent ab3ae5ad41
commit 2299d4967d
2 changed files with 9 additions and 1 deletions

3
doas.h
View File

@ -65,3 +65,6 @@ struct passwd *copyenvpw(struct passwd *original);
#define SAFE_PATH "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
#endif
#ifndef MAX_ENV_LENGTH
#define MAX_ENV_LENGTH 1024
#endif

7
env.c
View File

@ -117,6 +117,7 @@ createenv(struct rule *rule, struct passwd *original, struct passwd *target)
{
struct env *env;
u_int i;
char *language = NULL;
env = malloc(sizeof(*env));
if (!env)
@ -133,6 +134,10 @@ createenv(struct rule *rule, struct passwd *original, struct passwd *target)
addnode(env, "PATH", GLOBAL_PATH);
addnode(env, "SHELL", target->pw_shell);
addnode(env, "USER", target->pw_name);
/* avoid dropping language of original user */
language = getenv("LANG");
if (language)
addnode(env, "LANG", language);
if (rule->options & KEEPENV) {
#ifndef linux
@ -143,7 +148,7 @@ createenv(struct rule *rule, struct passwd *original, struct passwd *target)
struct envnode *node;
const char *e, *eq;
size_t len;
char name[1024];
char name[MAX_ENV_LENGTH];
e = environ[i];