Merge branch 'vendor/OPENSSH'
[dragonfly.git] / crypto / openssh / session.c
index f2549e0..3a0443a 100644 (file)
@@ -889,6 +889,24 @@ do_motd(void)
 {
        FILE *f;
        char buf[256];
+#ifdef HAVE_LOGIN_CAP
+       const char *fname;
+#endif
+
+#ifdef HAVE_LOGIN_CAP
+       fname = login_getcapstr(lc, "copyright", NULL, NULL);
+       if (fname != NULL && (f = fopen(fname, "r")) != NULL) {
+               while (fgets(buf, sizeof(buf), f) != NULL)
+                       fputs(buf, stdout);
+                       fclose(f);
+       } else
+#endif /* HAVE_LOGIN_CAP */
+               (void)printf("%s\n\t%s %s\n",
+       "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994",
+       "The Regents of the University of California. ",
+       "All rights reserved.");
+
+       (void)printf("\n");
 
        if (options.print_motd) {
 #ifdef HAVE_LOGIN_CAP
@@ -1118,6 +1136,9 @@ do_setup_env(Session *s, const char *shell)
        struct passwd *pw = s->pw;
 #ifndef HAVE_LOGIN_CAP
        char *path = NULL;
+#else
+       extern char **environ;
+       char **senv, **var;
 #endif
 
        /* Initialize the environment. */
@@ -1139,6 +1160,9 @@ do_setup_env(Session *s, const char *shell)
        }
 #endif
 
+       if (getenv("TZ"))
+               child_set_env(&env, &envsize, "TZ", getenv("TZ"));
+
 #ifdef GSSAPI
        /* Allow any GSSAPI methods that we've used to alter
         * the childs environment as they see fit
@@ -1158,11 +1182,22 @@ do_setup_env(Session *s, const char *shell)
                child_set_env(&env, &envsize, "LOGIN", pw->pw_name);
 #endif
                child_set_env(&env, &envsize, "HOME", pw->pw_dir);
+               snprintf(buf, sizeof buf, "%.200s/%.50s",
+                        _PATH_MAILDIR, pw->pw_name);
+               child_set_env(&env, &envsize, "MAIL", buf);
 #ifdef HAVE_LOGIN_CAP
-               if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0)
-                       child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
-               else
-                       child_set_env(&env, &envsize, "PATH", getenv("PATH"));
+               child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
+               child_set_env(&env, &envsize, "TERM", "su");
+               senv = environ;
+               environ = xmalloc(sizeof(char *));
+               *environ = NULL;
+               (void) setusercontext(lc, pw, pw->pw_uid,
+                   LOGIN_SETENV|LOGIN_SETPATH);
+               copy_environment(environ, &env, &envsize);
+               for (var = environ; *var != NULL; ++var)
+                       xfree(*var);
+               xfree(environ);
+               environ = senv;
 #else /* HAVE_LOGIN_CAP */
 # ifndef HAVE_CYGWIN
                /*
@@ -1183,15 +1218,9 @@ do_setup_env(Session *s, const char *shell)
 # 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);
-
                /* Normal systems set SHELL by default. */
                child_set_env(&env, &envsize, "SHELL", shell);
        }
-       if (getenv("TZ"))
-               child_set_env(&env, &envsize, "TZ", getenv("TZ"));
 
        /* Set custom environment options from RSA authentication. */
        if (!options.use_login) {