== OPTIONS
*-p*::
-Used by *getty*(8) to tell *login* to preserve the environment.
+Used by *getty*(8) to tell *login* to preserve the environment. See also *LOGIN_ENV_SAFELIST* config file item.
*-f*::
Used to skip a login authentication. This option is usually used by the *getty*(8) autologin feature.
Forces *login* to stop display content specified by *MOTD_FILE* after the first accessible item in the list. Note that a directory is one item in this case. This option allows *login* semantics to be configured to be more compatible with pam_motd. The default value is _no_.
+*LOGIN_ENV_SAFELIST* (string)::
+
+Forces *login* to protect the specified environment variables if *-p* is not used. The string value is a comma-separated list of variable names. For example: "LANG,LC_MESSAGES,LC_COLLATE". The safelist is ignored for the environment variables HOME, SHELL and USER.
+
*LOGIN_PLAIN_PROMPT* (boolean)::
Tell *login* that printing the hostname should be suppressed in the login: prompt. This is an alternative to the *-H* command line option. The default value is _no_.
static void init_environ(struct login_context *cxt)
{
struct passwd *pwd = cxt->pwd;
- char *termenv, **env;
+ struct ul_env_list *saved;
+ char **env;
char tmp[PATH_MAX];
int len, i;
- termenv = getenv("TERM");
- if (termenv)
- termenv = xstrdup(termenv);
+ saved = env_list_add_getenv(NULL, "TERM", "dumb");
/* destroy environment unless user has requested preservation (-p) */
- if (!cxt->keep_env)
+ if (!cxt->keep_env) {
+ const char *str = getlogindefs_str("LOGIN_ENV_SAFELIST", NULL);
+
+ saved = env_list_add_getenvs(saved, str);
environ = xcalloc(1, sizeof(char *));
+ }
+
+ if (env_list_setenv(saved, 1) != 0)
+ err(EXIT_FAILURE, _("failed to set the environment variables"));
+
+ env_list_free(saved);
xsetenv("HOME", pwd->pw_dir, 0); /* legal to override */
xsetenv("USER", pwd->pw_name, 1);
xsetenv("SHELL", pwd->pw_shell, 1);
- xsetenv("TERM", termenv ? termenv : "dumb", 1);
- free(termenv);
if (pwd->pw_uid) {
if (logindefs_setenv("PATH", "ENV_PATH", _PATH_DEFPATH) != 0)