policycoreutils: sandbox: Maintain the LANG environment into the sandbox

When running an app within a sandbox, the application currently
switches to no LANG.  This patch will cause the sandboxed app to use
the users LANG.

Signed-off-by: Eric Paris <eparis@redhat.com>
Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
Dan Walsh 2011-09-07 14:20:30 -04:00 committed by Eric Paris
parent 1d274aca2d
commit 5c2a0d143d

View File

@ -944,6 +944,7 @@ int main(int argc, char **argv) {
if (child == 0) {
char *display = NULL;
char *LANG = NULL;
int rc = -1;
if (unshare(CLONE_NEWNS) < 0) {
@ -969,12 +970,23 @@ int main(int argc, char **argv) {
goto childerr;
}
}
/* construct a new environment */
if ((LANG = getenv("LANG")) != NULL) {
if ((LANG = strdup(LANG)) == NULL) {
perror(_("Out of memory"));
goto childerr;
}
}
if ((rc = clearenv()) != 0) {
perror(_("Failed to clear environment"));
goto childerr;
}
if (display)
rc |= setenv("DISPLAY", display, 1);
if (LANG)
rc |= setenv("LANG", LANG, 1);
rc |= setenv("HOME", pwd->pw_dir, 1);
rc |= setenv("SHELL", pwd->pw_shell, 1);
rc |= setenv("USER", pwd->pw_name, 1);
@ -1000,6 +1012,7 @@ int main(int argc, char **argv) {
fprintf(stderr, _("Failed to execute command %s: %s\n"), argv[optind], strerror(errno));
childerr:
free(display);
free(LANG);
exit(-1);
}