summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2003-09-16 11:52:19 +1000
committerDarren Tucker <dtucker@zip.com.au>2003-09-16 11:52:19 +1000
commite1a790d0d165ff70acb502fbfc72bd55cd2b8fb1 (patch)
tree8d946f4cc2d9b550dfae1543dbc3b817f041e03a
parent7b6cb5c5ef9ddd12e7cb695357209f1c08a57fc5 (diff)
- (dtucker) [acconfig.h configure.ac defines.h session.c] Bug #252: Retrieve
PATH (or SUPATH) and UMASK from /etc/default/login on platforms that have it (eg Solaris, Reliant Unix). Patch from Robert.Dahlem at siemens.com. ok djm@
-rw-r--r--ChangeLog7
-rw-r--r--acconfig.h5
-rw-r--r--configure.ac45
-rw-r--r--defines.h6
-rw-r--r--session.c80
5 files changed, 123 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 3f1a4cfec..6a32bc1a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
120030916
2 - (dtucker) [acconfig.h configure.ac defines.h session.c] Bug #252: Retrieve
3 PATH (or SUPATH) and UMASK from /etc/default/login on platforms that have it
4 (eg Solaris, Reliant Unix). Patch from Robert.Dahlem at siemens.com. ok djm@
5
120030914 620030914
2 - (dtucker) [Makefile regress/Makefile] Fix portability issues preventing 7 - (dtucker) [Makefile regress/Makefile] Fix portability issues preventing
3 the regression tests from running with Solaris' make. Patch from Brian 8 the regression tests from running with Solaris' make. Patch from Brian
@@ -1093,4 +1098,4 @@
1093 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo. 1098 - Fix sshd BindAddress and -b options for systems using fake-getaddrinfo.
1094 Report from murple@murple.net, diagnosis from dtucker@zip.com.au 1099 Report from murple@murple.net, diagnosis from dtucker@zip.com.au
1095 1100
1096$Id: ChangeLog,v 1.2991 2003/09/14 03:16:55 dtucker Exp $ 1101$Id: ChangeLog,v 1.2992 2003/09/16 01:52:19 dtucker Exp $
diff --git a/acconfig.h b/acconfig.h
index ea8fcb0b4..9bfb9b6c9 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -1,4 +1,4 @@
1/* $Id: acconfig.h,v 1.165 2003/09/08 21:35:17 tim Exp $ */ 1/* $Id: acconfig.h,v 1.166 2003/09/16 01:52:19 dtucker Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -359,6 +359,9 @@
359/* Define in your struct dirent expects you to allocate extra space for d_name */ 359/* Define in your struct dirent expects you to allocate extra space for d_name */
360#undef BROKEN_ONE_BYTE_DIRENT_D_NAME 360#undef BROKEN_ONE_BYTE_DIRENT_D_NAME
361 361
362/* Define if your system has /etc/default/login */
363#undef HAVE_ETC_DEFAULT_LOGIN
364
362/* Define if your getopt(3) defines and uses optreset */ 365/* Define if your getopt(3) defines and uses optreset */
363#undef HAVE_GETOPT_OPTRESET 366#undef HAVE_GETOPT_OPTRESET
364 367
diff --git a/configure.ac b/configure.ac
index 3d5389cce..ab630115b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.153 2003/09/13 01:15:15 tim Exp $ 1# $Id: configure.ac,v 1.154 2003/09/16 01:52:19 dtucker Exp $
2 2
3AC_INIT 3AC_INIT
4AC_CONFIG_SRCDIR([ssh.c]) 4AC_CONFIG_SRCDIR([ssh.c])
@@ -250,6 +250,7 @@ mips-sony-bsd|mips-sony-newsos4)
250 AC_DEFINE(LOCKED_PASSWD_STRING, "*LK*") 250 AC_DEFINE(LOCKED_PASSWD_STRING, "*LK*")
251 # Pushing STREAMS modules will cause sshd to acquire a controlling tty. 251 # Pushing STREAMS modules will cause sshd to acquire a controlling tty.
252 AC_DEFINE(SSHD_ACQUIRES_CTTY) 252 AC_DEFINE(SSHD_ACQUIRES_CTTY)
253 external_path_file=/etc/default/login
253 # hardwire lastlog location (can't detect it on some versions) 254 # hardwire lastlog location (can't detect it on some versions)
254 conf_lastlog_location="/var/adm/lastlog" 255 conf_lastlog_location="/var/adm/lastlog"
255 AC_MSG_CHECKING(for obsolete utmp and wtmp in solaris2.x) 256 AC_MSG_CHECKING(for obsolete utmp and wtmp in solaris2.x)
@@ -286,6 +287,7 @@ mips-sony-bsd|mips-sony-newsos4)
286 AC_DEFINE(USE_PIPES) 287 AC_DEFINE(USE_PIPES)
287 AC_DEFINE(IP_TOS_IS_BROKEN) 288 AC_DEFINE(IP_TOS_IS_BROKEN)
288 AC_DEFINE(SSHD_ACQUIRES_CTTY) 289 AC_DEFINE(SSHD_ACQUIRES_CTTY)
290 external_path_file=/etc/default/login
289 # /usr/ucblib/libucb.a no longer needed on ReliantUNIX 291 # /usr/ucblib/libucb.a no longer needed on ReliantUNIX
290 # Attention: always take care to bind libsocket and libnsl before libc, 292 # Attention: always take care to bind libsocket and libnsl before libc,
291 # otherwise you will find lots of "SIOCGPGRP errno 22" on syslog 293 # otherwise you will find lots of "SIOCGPGRP errno 22" on syslog
@@ -2180,30 +2182,48 @@ else
2180 ) 2182 )
2181fi 2183fi
2182 2184
2185# check for /etc/default/login and use it if present.
2186AC_CHECK_FILE("/etc/default/login", [ external_path_file=/etc/default/login ])
2187
2188if test "x$external_path_file" = "x/etc/default/login"; then
2189 AC_DEFINE(HAVE_ETC_DEFAULT_LOGIN)
2190fi
2191
2183dnl BSD systems use /etc/login.conf so --with-default-path= has no effect 2192dnl BSD systems use /etc/login.conf so --with-default-path= has no effect
2184if test $ac_cv_func_login_getcapbool = "yes" -a \ 2193if test $ac_cv_func_login_getcapbool = "yes" -a \
2185 $ac_cv_header_login_cap_h = "yes" ; then 2194 $ac_cv_header_login_cap_h = "yes" ; then
2186 USES_LOGIN_CONF=yes 2195 external_path_file=/etc/login.conf
2187fi 2196fi
2197
2188# Whether to mess with the default path 2198# Whether to mess with the default path
2189SERVER_PATH_MSG="(default)" 2199SERVER_PATH_MSG="(default)"
2190AC_ARG_WITH(default-path, 2200AC_ARG_WITH(default-path,
2191 [ --with-default-path= Specify default \$PATH environment for server], 2201 [ --with-default-path= Specify default \$PATH environment for server],
2192 [ 2202 [
2193 if test "$USES_LOGIN_CONF" = "yes" ; then 2203 if test "x$external_path_file" = "x/etc/login.conf" ; then
2194 AC_MSG_WARN([ 2204 AC_MSG_WARN([
2195--with-default-path=PATH has no effect on this system. 2205--with-default-path=PATH has no effect on this system.
2196Edit /etc/login.conf instead.]) 2206Edit /etc/login.conf instead.])
2197 elif test "x$withval" != "xno" ; then 2207 elif test "x$withval" != "xno" ; then
2208 if ! test -z "$external_path_file" ; then
2209 AC_MSG_WARN([
2210--with-default-path=PATH will only be used if PATH is not defined in
2211$external_path_file .])
2212 fi
2198 user_path="$withval" 2213 user_path="$withval"
2199 SERVER_PATH_MSG="$withval" 2214 SERVER_PATH_MSG="$withval"
2200 fi 2215 fi
2201 ], 2216 ],
2202 [ if test "$USES_LOGIN_CONF" = "yes" ; then 2217 [ if test "x$external_path_file" = "x/etc/login.conf" ; then
2203 AC_MSG_WARN([Make sure the path to scp is in /etc/login.conf]) 2218 AC_MSG_WARN([Make sure the path to scp is in /etc/login.conf])
2204 else 2219 else
2205 AC_TRY_RUN( 2220 if ! test -z "$external_path_file" ; then
2206 [ 2221 AC_MSG_WARN([
2222If PATH is defined in $external_path_file, ensure the path to scp is included,
2223otherwise scp will not work.])
2224 fi
2225 AC_TRY_RUN(
2226 [
2207/* find out what STDPATH is */ 2227/* find out what STDPATH is */
2208#include <stdio.h> 2228#include <stdio.h>
2209#ifdef HAVE_PATHS_H 2229#ifdef HAVE_PATHS_H
@@ -2257,7 +2277,7 @@ main()
2257 fi 2277 fi
2258 fi ] 2278 fi ]
2259) 2279)
2260if test "$USES_LOGIN_CONF" != "yes" ; then 2280if test "x$external_path_file" != "x/etc/login.conf" ; then
2261 AC_DEFINE_UNQUOTED(USER_PATH, "$user_path") 2281 AC_DEFINE_UNQUOTED(USER_PATH, "$user_path")
2262 AC_SUBST(user_path) 2282 AC_SUBST(user_path)
2263fi 2283fi
@@ -2627,10 +2647,15 @@ echo " Askpass program: $E"
2627echo " Manual pages: $F" 2647echo " Manual pages: $F"
2628echo " PID file: $G" 2648echo " PID file: $G"
2629echo " Privilege separation chroot path: $H" 2649echo " Privilege separation chroot path: $H"
2630if test "$USES_LOGIN_CONF" = "yes" ; then 2650if test "x$external_path_file" = "x/etc/login.conf" ; then
2631echo " At runtime, sshd will use the path defined in /etc/login.conf" 2651echo " At runtime, sshd will use the path defined in $external_path_file"
2652echo " Make sure the path to scp is present, otherwise scp will not work"
2632else 2653else
2633echo " sshd default user PATH: $I" 2654echo " sshd default user PATH: $I"
2655 if ! test -z "$external_path_file"; then
2656echo " (If PATH is set in $external_path_file it will be used instead. If"
2657echo " used, ensure the path to scp is present, otherwise scp will not work.)"
2658 fi
2634fi 2659fi
2635if test ! -z "$superuser_path" ; then 2660if test ! -z "$superuser_path" ; then
2636echo " sshd superuser user PATH: $J" 2661echo " sshd superuser user PATH: $J"
diff --git a/defines.h b/defines.h
index 7bff839cc..e662966fb 100644
--- a/defines.h
+++ b/defines.h
@@ -25,7 +25,7 @@
25#ifndef _DEFINES_H 25#ifndef _DEFINES_H
26#define _DEFINES_H 26#define _DEFINES_H
27 27
28/* $Id: defines.h,v 1.102 2003/08/26 01:58:16 dtucker Exp $ */ 28/* $Id: defines.h,v 1.103 2003/09/16 01:52:19 dtucker Exp $ */
29 29
30 30
31/* Constants */ 31/* Constants */
@@ -321,6 +321,10 @@ struct winsize {
321# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" 321# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
322#endif 322#endif
323 323
324#ifndef SUPERUSER_PATH
325# define SUPERUSER_PATH _PATH_STDPATH
326#endif
327
324#ifndef _PATH_DEVNULL 328#ifndef _PATH_DEVNULL
325# define _PATH_DEVNULL "/dev/null" 329# define _PATH_DEVNULL "/dev/null"
326#endif 330#endif
diff --git a/session.c b/session.c
index 35328ecbb..4497f5c0b 100644
--- a/session.c
+++ b/session.c
@@ -802,6 +802,16 @@ child_set_env(char ***envp, u_int *envsizep, const char *name,
802 char **env; 802 char **env;
803 803
804 /* 804 /*
805 * If we're passed an uninitialized list, allocate a single null
806 * entry before continuing.
807 */
808 if (*envp == NULL && *envsizep == 0) {
809 *envp = xmalloc(sizeof(char *));
810 *envp[0] = NULL;
811 *envsizep = 1;
812 }
813
814 /*
805 * Find the slot where the value should be stored. If the variable 815 * Find the slot where the value should be stored. If the variable
806 * already exists, we reuse the slot; otherwise we append a new slot 816 * already exists, we reuse the slot; otherwise we append a new slot
807 * at the end of the array, expanding if necessary. 817 * at the end of the array, expanding if necessary.
@@ -877,6 +887,59 @@ read_environment_file(char ***env, u_int *envsize,
877 fclose(f); 887 fclose(f);
878} 888}
879 889
890#ifdef HAVE_ETC_DEFAULT_LOGIN
891/*
892 * Return named variable from specified environment, or NULL if not present.
893 */
894static char *
895child_get_env(char **env, const char *name)
896{
897 int i;
898 size_t len;
899
900 len = strlen(name);
901 for (i=0; env[i] != NULL; i++)
902 if (strncmp(name, env[i], len) == 0 && env[i][len] == '=')
903 return(env[i] + len + 1);
904 return NULL;
905}
906
907/*
908 * Read /etc/default/login.
909 * We pick up the PATH (or SUPATH for root) and UMASK.
910 */
911static void
912read_etc_default_login(char ***env, u_int *envsize, uid_t uid)
913{
914 char **tmpenv = NULL, *var;
915 u_int i;
916 size_t tmpenvsize = 0;
917 mode_t mask;
918
919 /*
920 * We don't want to copy the whole file to the child's environment,
921 * so we use a temporary environment and copy the variables we're
922 * interested in.
923 */
924 read_environment_file(&tmpenv, &tmpenvsize, "/etc/default/login");
925
926 if (uid == 0)
927 var = child_get_env(tmpenv, "SUPATH");
928 else
929 var = child_get_env(tmpenv, "PATH");
930 if (var != NULL)
931 child_set_env(env, envsize, "PATH", var);
932
933 if ((var = child_get_env(tmpenv, "UMASK")) != NULL)
934 if (sscanf(var, "%5lo", &mask) == 1)
935 umask(mask);
936
937 for (i = 0; tmpenv[i] != NULL; i++)
938 xfree(tmpenv[i]);
939 xfree(tmpenv);
940}
941#endif /* HAVE_ETC_DEFAULT_LOGIN */
942
880void copy_environment(char **source, char ***env, u_int *envsize) 943void copy_environment(char **source, char ***env, u_int *envsize)
881{ 944{
882 char *var_name, *var_val; 945 char *var_name, *var_val;
@@ -905,7 +968,7 @@ do_setup_env(Session *s, const char *shell)
905{ 968{
906 char buf[256]; 969 char buf[256];
907 u_int i, envsize; 970 u_int i, envsize;
908 char **env, *laddr; 971 char **env, *laddr, *path = NULL;
909 struct passwd *pw = s->pw; 972 struct passwd *pw = s->pw;
910 973
911 /* Initialize the environment. */ 974 /* Initialize the environment. */
@@ -949,12 +1012,15 @@ do_setup_env(Session *s, const char *shell)
949 * needed for loading shared libraries. So the path better 1012 * needed for loading shared libraries. So the path better
950 * remains intact here. 1013 * remains intact here.
951 */ 1014 */
952# ifdef SUPERUSER_PATH 1015# ifdef HAVE_ETC_DEFAULT_LOGIN
953 child_set_env(&env, &envsize, "PATH", 1016 read_etc_default_login(&env, &envsize, pw->pw_uid);
954 s->pw->pw_uid == 0 ? SUPERUSER_PATH : _PATH_STDPATH); 1017 path = child_get_env(env, "PATH");
955# else 1018# endif /* HAVE_ETC_DEFAULT_LOGIN */
956 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); 1019 if (path == NULL || *path == '\0') {
957# endif /* SUPERUSER_PATH */ 1020 child_set_env(&env, &envsize, "PATH",
1021 s->pw->pw_uid == 0 ?
1022 SUPERUSER_PATH : _PATH_STDPATH);
1023 }
958# endif /* HAVE_CYGWIN */ 1024# endif /* HAVE_CYGWIN */
959#endif /* HAVE_LOGIN_CAP */ 1025#endif /* HAVE_LOGIN_CAP */
960 1026