From owner-freebsd-ports Sun Nov 30 07:00:33 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id HAA13205 for ports-outgoing; Sun, 30 Nov 1997 07:00:33 -0800 (PST) (envelope-from owner-freebsd-ports) Received: from zerium.idgonline.no (root@oslo-1-11.newmedia.no [194.52.244.11]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id HAA13198 for ; Sun, 30 Nov 1997 07:00:28 -0800 (PST) (envelope-from hanspb@persbraten.vgs.no) Received: from localhost (hanspbie@zerium.newmedia.no [127.0.0.1]) by zerium.idgonline.no (8.8.7/8.8.5) with SMTP id QAA15384 for ; Sun, 30 Nov 1997 16:00:23 +0100 Date: Sun, 30 Nov 1997 16:00:23 +0100 (MET) From: Hans Petter Bieker X-Sender: hanspbie@zerium.newmedia.no To: ports@FreeBSD.org Subject: fix for ports/4865 (was: Re: xdm: doesn't run setusercontext()) properly Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-ports@FreeBSD.org X-Loop: FreeBSD.org Precedence: bulk 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