git: 6b3ad1d73732 - main - When -u option is used also set USER, HOME and SHELL variables. This is consistent with what other uid-morphing utilities do, i.e. jexec(1), su(1) etc.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 12 Aug 2022 17:08:38 UTC
The branch main has been updated by sobomax: URL: https://cgit.FreeBSD.org/src/commit/?id=6b3ad1d737321cf6a70e957fb15d5287c378373c commit 6b3ad1d737321cf6a70e957fb15d5287c378373c Author: Maxim Sobolev <sobomax@FreeBSD.org> AuthorDate: 2022-08-11 01:44:20 +0000 Commit: Maxim Sobolev <sobomax@FreeBSD.org> CommitDate: 2022-08-12 17:07:56 +0000 When -u option is used also set USER, HOME and SHELL variables. This is consistent with what other uid-morphing utilities do, i.e. jexec(1), su(1) etc. MFC after: 2 weeks Reviewed by: gbe Differential Revision: https://reviews.freebsd.org/D36148 --- usr.sbin/daemon/daemon.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c index d8a26132223b..e8cdaa230caa 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <libutil.h> #include <login_cap.h> +#include <paths.h> #include <pwd.h> #include <signal.h> #include <stdio.h> @@ -465,6 +466,10 @@ restrict_process(const char *user) if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) errx(1, "failed to set user environment"); + + setenv("USER", pw->pw_name, 1); + setenv("HOME", pw->pw_dir, 1); + setenv("SHELL", *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL, 1); } /*