Merge from vendor branch BIND:
[dragonfly.git] / secure / usr.sbin / sshd / session.c.patch
1 $DragonFly: src/secure/usr.sbin/sshd/Attic/session.c.patch,v 1.1 2004/07/31 20:05:00 geekgod Exp $
2 --- session.c.orig      2004-07-23 14:26:51.000000000 +0200
3 +++ session.c   2004-07-23 14:20:00.000000000 +0200
4 @@ -748,6 +748,24 @@
5  {
6         FILE *f;
7         char buf[256];
8 +#ifdef HAVE_LOGIN_CAP
9 +       const char *fname;
10 +#endif
11 +
12 +#ifdef HAVE_LOGIN_CAP
13 +       fname = login_getcapstr(lc, "copyright", NULL, NULL);
14 +       if (fname != NULL && (f = fopen(fname, "r")) != NULL) {
15 +               while (fgets(buf, sizeof(buf), f) != NULL)
16 +                       fputs(buf, stdout);
17 +                       fclose(f);
18 +       } else
19 +#endif /* HAVE_LOGIN_CAP */
20 +               (void)printf("%s\n\t%s %s\n",
21 +       "Copyright (c) 1980, 1983, 1986, 1988, 1990, 1991, 1993, 1994",
22 +       "The Regents of the University of California. ",
23 +       "All rights reserved.");
24 +
25 +       (void)printf("\n");
26  
27         if (options.print_motd) {
28  #ifdef HAVE_LOGIN_CAP
29 @@ -972,6 +990,10 @@
30         char buf[256];
31         u_int i, envsize;
32         char **env, *laddr, *path = NULL;
33 +#ifdef HAVE_LOGIN_CAP
34 +       extern char **environ;
35 +       char **senv, **var;
36 +#endif
37         struct passwd *pw = s->pw;
38  
39         /* Initialize the environment. */
40 @@ -987,6 +1009,9 @@
41         copy_environment(environ, &env, &envsize);
42  #endif
43  
44 +       if (getenv("TZ"))
45 +               child_set_env(&env, &envsize, "TZ", getenv("TZ"));
46 +
47  #ifdef GSSAPI
48         /* Allow any GSSAPI methods that we've used to alter
49          * the childs environment as they see fit
50 @@ -1002,11 +1027,22 @@
51                 child_set_env(&env, &envsize, "LOGIN", pw->pw_name);
52  #endif
53                 child_set_env(&env, &envsize, "HOME", pw->pw_dir);
54 +               snprintf(buf, sizeof buf, "%.200s/%.50s",
55 +                        _PATH_MAILDIR, pw->pw_name);
56 +               child_set_env(&env, &envsize, "MAIL", buf);
57  #ifdef HAVE_LOGIN_CAP
58 -               if (setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH) < 0)
59 -                       child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
60 -               else
61 -                       child_set_env(&env, &envsize, "PATH", getenv("PATH"));
62 +               child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
63 +               child_set_env(&env, &envsize, "TERM", "su");
64 +               senv = environ;
65 +               environ = xmalloc(sizeof(char *));
66 +               *environ = NULL;
67 +               (void) setusercontext(lc, pw, pw->pw_uid,
68 +                   LOGIN_SETENV|LOGIN_SETPATH);
69 +               copy_environment(environ, &env, &envsize);
70 +               for (var = environ; *var != NULL; ++var)
71 +                       xfree(*var);
72 +               xfree(environ);
73 +               environ = senv;
74  #else /* HAVE_LOGIN_CAP */
75  # ifndef HAVE_CYGWIN
76                 /*
77 @@ -1027,15 +1063,9 @@
78  # endif /* HAVE_CYGWIN */
79  #endif /* HAVE_LOGIN_CAP */
80  
81 -               snprintf(buf, sizeof buf, "%.200s/%.50s",
82 -                        _PATH_MAILDIR, pw->pw_name);
83 -               child_set_env(&env, &envsize, "MAIL", buf);
84 -
85                 /* Normal systems set SHELL by default. */
86                 child_set_env(&env, &envsize, "SHELL", shell);
87         }
88 -       if (getenv("TZ"))
89 -               child_set_env(&env, &envsize, "TZ", getenv("TZ"));
90  
91         /* Set custom environment options from RSA authentication. */
92         if (!options.use_login) {
93 @@ -1255,7 +1285,7 @@
94                 }
95  # endif /* USE_PAM */
96                 if (setusercontext(lc, pw, pw->pw_uid,
97 -                   (LOGIN_SETALL & ~LOGIN_SETPATH)) < 0) {
98 +                   (LOGIN_SETALL & ~(LOGIN_SETENV|LOGIN_SETPATH))) < 0) {
99                         perror("unable to set user context");
100                         exit(1);
101                 }
102 @@ -1391,6 +1421,9 @@
103         char *argv[10];
104         const char *shell, *shell0, *hostname = NULL;
105         struct passwd *pw = s->pw;
106 +#ifdef HAVE_LOGIN_CAP
107 +       int lc_requirehome;
108 +#endif
109  
110         /* remove hostkey from the child's memory */
111         destroy_sensitive_data();
112 @@ -1461,6 +1494,10 @@
113          */
114         environ = env;
115  
116 +#ifdef HAVE_LOGIN_CAP
117 +       lc_requirehome = login_getcapbool(lc, "requirehome", 0);
118 +       login_close(lc);
119 +#endif
120  #if defined(KRB5) && defined(USE_AFS)
121         /*
122          * At this point, we check to see if AFS is active and if we have
123 @@ -1492,7 +1529,7 @@
124                 fprintf(stderr, "Could not chdir to home directory %s: %s\n",
125                     pw->pw_dir, strerror(errno));
126  #ifdef HAVE_LOGIN_CAP
127 -               if (login_getcapbool(lc, "requirehome", 0))
128 +               if (lc_requirehome)
129                         exit(1);
130  #endif
131         }