Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Jun 2002 01:17:52 +0400
From:      "Andrey A. Chernov" <ache@nagual.pp.ru>
To:        des@freebsd.org
Cc:        current@freebsd.org
Subject:   openssh-portable fix for setusercontext env.
Message-ID:  <20020625211749.GA21219@nagual.pp.ru>

next in thread | raw e-mail | index | archive | help
Current variant not set all needed env. vars correctly. Please note that
TZ, PATH, MAIL and TERM variables may be (or may be not) modified by 
setusercontext() so they must be set _before_ setusercontext() call.

And now I keep silence about the place from where I take this code.

--- session.c.bak	Tue Jun 25 22:33:58 2002
+++ session.c	Wed Jun 26 01:09:03 2002
@@ -957,6 +957,17 @@
 		child_set_env(&env, &envsize, "LOGNAME", pw->pw_name);
 		child_set_env(&env, &envsize, "HOME", pw->pw_dir);
 #ifdef HAVE_LOGIN_CAP
+		if (getenv("TZ"))
+			child_set_env(&env, &envsize, "TZ", getenv("TZ"));
+		child_set_env(&env, &envsize, "PATH",
+			      (pw->pw_uid == 0) ?
+			      _PATH_STDPATH : _PATH_DEFPATH);
+		snprintf(buf, sizeof buf, "%.200s/%.50s",
+			 _PATH_MAILDIR, pw->pw_name);
+		child_set_env(&env, &envsize, "MAIL", buf);
+		if (s->term)
+			child_set_env(&env, &envsize, "TERM", s->term);
+
 		senv = environ;
 		environ = xmalloc(sizeof(char *));
 		*environ = NULL;
@@ -965,7 +976,6 @@
 		copy_environment(environ, &env, &envsize);
 		xfree(environ);
 		environ = senv;
-		child_set_env(&env, &envsize, "PATH", getenv("PATH"));
 #else /* HAVE_LOGIN_CAP */
 # ifndef HAVE_CYGWIN
 		/*
@@ -981,16 +991,19 @@
 		child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
 #  endif /* SUPERUSER_PATH */
 # endif /* HAVE_CYGWIN */
-#endif /* HAVE_LOGIN_CAP */
 
 		snprintf(buf, sizeof buf, "%.200s/%.50s",
 			 _PATH_MAILDIR, pw->pw_name);
 		child_set_env(&env, &envsize, "MAIL", buf);
+#endif /* HAVE_LOGIN_CAP */
 
 		/* Normal systems set SHELL by default. */
 		child_set_env(&env, &envsize, "SHELL", shell);
 	}
 	if (getenv("TZ"))
+#ifdef HAVE_LOGIN_CAP
+	    if (options.use_login)
+#endif /* HAVE_LOGIN_CAP */
 		child_set_env(&env, &envsize, "TZ", getenv("TZ"));
 
 	/* Set custom environment options from RSA authentication. */
@@ -1018,6 +1031,9 @@
 	if (s->ttyfd != -1)
 		child_set_env(&env, &envsize, "SSH_TTY", s->tty);
 	if (s->term)
+#ifdef HAVE_LOGIN_CAP
+	    if (options.use_login)
+#endif /* HAVE_LOGIN_CAP */
 		child_set_env(&env, &envsize, "TERM", s->term);
 	if (s->display)
 		child_set_env(&env, &envsize, "DISPLAY", s->display);
-- 
Andrey A. Chernov
http://ache.pp.ru/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020625211749.GA21219>