Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 30 Nov 1997 16:00:23 +0100 (MET)
From:      Hans Petter Bieker <hanspb@persbraten.vgs.no>
To:        ports@FreeBSD.org
Subject:   fix for ports/4865 (was: Re: xdm: doesn't run setusercontext()) properly
Message-ID:  <Pine.LNX.3.95.971130155940.15375G-100000@zerium.newmedia.no>

next in thread | raw e-mail | index | archive | help
On Sun, 30 Nov 1997, Hans Petter Bieker wrote:

> xdm now runs setusercontext with NULL for login_cap_t *lc parameter. This
> parameter should be the class of the current user so I made this patch
> against the session.c~ (not session.c.org).
> 
> This causes to use ``default'' as loginclass for all users loged inn thru
> xdm. This is obviously wrong:

This patch actually works (it's tested), but it's just a hack. However I
hope you commit this patch.

As you see the problem was that xdm doesn't use environ as a template for
the new environ, but it creates a new one from scratch.

This patch fixes PR ports/4865.

--- /usr/ports/x11/XFree86/patches/patch-ae~	Sun Sep 28 07:46:52 1997
+++ /usr/ports/x11/XFree86/patches/patch-ae	Sun Nov 30 15:32:12 1997
@@ -11,8 +11,43 @@
  SYS_LIBRARIES = $(SYS_LIBRARIES1) $(SYS_LIBRARIES2) $(SYS_LIBRARIES3)
  
  #if HasBSD44Sockets
---- programs/xdm/session.c.orig	Mon Jun  9 01:16:11 1997
-+++ programs/xdm/session.c	Mon Jun  9 01:19:30 1997
+--- programs/xdm/util.c.orig	Thu Oct  3 10:49:48 1996
++++ programs/xdm/util.c	Sun Nov 30 15:27:46 1997
+@@ -141,6 +141,32 @@
+ 	return new;
+ }
+ 
++char **
++putEnv(string, env)
++	const char *string;
++	char ** env;
++{
++	char *v, *b, *n;
++	int nl;
++
++	if ((b = strchr(string, '=')) == NULL) return NULL;
++	v = b + 1;
++
++	nl = b - string;
++	if ((n = malloc(nl + 1)) == NULL)
++	  {
++	    LogOutOfMem ("putAllEnv");
++	    return NULL;
++	  }
++
++	strncpy(n, string,nl + 1);
++	n[nl] = 0;
++
++	env = setEnv(env,n,v);
++	free(n);
++	return env;
++}
++
+ freeEnv (env)
+     char    **env;
+ {
+--- programs/xdm/session.c.orig	Mon Dec 23 08:10:57 1996
++++ programs/xdm/session.c	Sun Nov 30 15:27:46 1997
 @@ -65,6 +65,17 @@
  
  #ifdef CSRG_BASED
@@ -31,29 +66,50 @@
  #endif
  
  extern	int	PingServer();
-@@ -494,6 +505,9 @@
+@@ -81,6 +92,7 @@
+ extern	int	source();
+ extern	char	**defaultEnv();
+ extern	char	**setEnv();
++extern	char	**putEnv();
+ extern	char	**parseArgs();
+ extern	int	printEnv();
+ extern	char	**systemEnv();
+@@ -494,6 +506,13 @@
      char	**f, *home, *getEnv ();
      char	*failsafeArgv[2];
      int	pid;
 +#ifdef HAVE_SETUSERCONTEXT
++    login_cap_t *lc = NULL;
++    extern char **environ;
++    char ** e;
 +    struct passwd *pwd;
++    char *envinit[1];
 +#endif
  
      if (verify->argv) {
  	Debug ("StartSession %s: ", verify->argv[0]);
-@@ -512,6 +526,28 @@
+@@ -512,6 +531,43 @@
  
  	/* Do system-dependent login setup here */
  
 +#ifdef HAVE_SETUSERCONTEXT
 +	/*
++	 * Destroy environment unless user has requested its preservation.
++	 * We need to do this before setusercontext() because that may
++	 * set or reset some environment variables.
++	 */
++	environ = envinit;
++
++	/*
 +	 * Set the user's credentials: uid, gid, groups,
 +	 * environment variables, resource limits, and umask.
 +	 */
++	
 +	pwd = getpwnam(name);
 +	if (pwd)
 +	{
-+	    if (setusercontext(NULL, pwd, pwd->pw_uid, LOGIN_SETALL) < 0)
++	    lc = login_getpwclass(pwd);
++	    if (setusercontext(lc, pwd, pwd->pw_uid, LOGIN_SETALL) < 0)
 +	    {
 +		LogError("setusercontext for \"%s\" failed, errno=%d\n", name,
 +		    errno);
@@ -66,11 +122,17 @@
 +	    LogError("getpwnam for \"%s\" failed, errno=%d\n", name, errno);
 +	    return (0);
 +	}
++        login_close(lc);
++
++        e = environ;
++	while(*e)
++	    verify->userEnviron = putEnv(*e++, verify->userEnviron);
++
 +#else
  #ifdef AIXV3
  	/*
  	 * Set the user's credentials: uid, gid, groups,
-@@ -548,6 +584,7 @@
+@@ -548,6 +604,7 @@
  	    return (0);
  	}
  #endif /* AIXV3 */


-- 
 Linux; 64bit, multi-platform, multi-tasking, multi-user, fast and Free.
UNIX was not designed to stop you from doing stupid things, because that
would also stop you from doing clever things.
                -- Doug Gwyn




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.3.95.971130155940.15375G-100000>