Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Apr 2013 23:18:08 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 227753 for review
Message-ID:  <201304152318.r3FNI8nn070491@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@227753?ac=10

Change 227753 by brooks@brooks_zenith on 2013/04/15 23:17:28

	Use setusercontext() to more throughly set up the terminal
	context.  The useful effect of this change is that PATH is
	set to a useful value.
	
	Reported by:	rwatson

Affected files ...

.. //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#10 edit

Differences ...

==== //depot/projects/ctsrd/cheribsd/src/ctsrd/pictview/pictview.c#10 (text+ko) ====

@@ -43,7 +43,9 @@
 #include <fcntl.h>
 #include <fnmatch.h>
 #include <libutil.h>
+#include <login_cap.h>
 #include <poll.h>
+#include <pwd.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdbool.h>
@@ -193,6 +195,8 @@
 start_keyboard_shell(void)
 {
   int pmaster, pslave;
+  login_cap_t *lcap = NULL;
+  struct passwd *pwd = NULL;
 
   if (openpty(&pmaster, &pslave, NULL, NULL, NULL) == -1)
     err(1, "openpty");
@@ -208,6 +212,15 @@
       syslog(LOG_ALERT, "login_tty failed in child: %s", strerror(errno));
       err(1, "tty_login");
     }
+
+    if ((pwd = getpwuid(getuid())) == NULL)
+      err(1, "getpwuid: %s", getuid());
+    if ((lcap = login_getpwclass(pwd)) == NULL)
+      err(1, "login_getpwclass");
+    if (setusercontext(lcap, pwd, pwd->pw_uid,
+	LOGIN_SETALL & ~LOGIN_SETGROUP & ~LOGIN_SETLOGIN) != 0)
+      err(1, "setusercontext");
+
     execl("/bin/sh", "sh", NULL);
     syslog(LOG_ALERT, "exec of /bin/sh failed: %s", strerror(errno));
     err(1, "execl()");



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201304152318.r3FNI8nn070491>