[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch: Making su in heimdal 0.6.2 read /etc/environment




Hi all!

This patch makes "su" in heimdal 0.6.2 read /etc/environment in the
same manner as rshd/login. This is needed on AIX to set various
environment variables needed by system commands (ODMDIR being the one
that causes most confusion when missing), and albeit it can be kludged
in the shell specific setup files it seems better making heimdal su
behave :)

If this is the wrong place to post this patch, please point me in the
right direction.

------------------8<-----------------------------
--- ../dist/appl/su/su.c	Tue May  6 14:06:44 2003
+++ appl/su/su.c	Sat Jul 31 16:12:43 2004
@@ -70,6 +70,10 @@
 #define _PATH_BSHELL "/bin/sh"
 #endif

+#ifndef _PATH_ETC_ENVIRONMENT
+#define _PATH_ETC_ENVIRONMENT SYSCONFDIR "/environment"
+#endif
+
 int kerberos_flag = 1;
 int csh_f_flag;
 int full_login;
@@ -477,14 +481,30 @@
     if(!env_flag) {
 	if(full_login) {
 	    char *t = getenv ("TERM");
+            char **newenv;
+            char *p;
+            char i, j;
+
+            newenv=NULL;
+            i = read_environment(_PATH_ETC_ENVIRONMENT, &newenv);

-	    environ = malloc (10 * sizeof (char *));
+	    environ = malloc ((10+i) * sizeof (char *));
 	    if (environ == NULL)
 		err (1, "malloc");
 	    environ[0] = NULL;
 	    esetenv ("PATH", _PATH_DEFPATH, 1);
 	    if (t)
 		esetenv ("TERM", t, 1);
+
+            for (j = 0; j < i; j++) {
+                p = strchr(newenv[j], '=');
+                *p++ = 0;
+                esetenv(newenv[j], p, 1);
+                *--p = '=';
+                free(newenv[j]);
+            }
+            free(newenv);
+
 	    if (chdir (su_info->pw_dir) < 0)
 		errx (1, "no directory");
 	}
------------------8<-----------------------------


/Nikke
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 Niklas Edmundsson, Admin @ {acc,hpc2n}.umu.se      |     nikke@acc.umu.se
---------------------------------------------------------------------------
 BIGAMY: One wife too many. Monogamy: same idea.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=