From 6b3ad1d737321cf6a70e957fb15d5287c378373c Mon Sep 17 00:00:00 2001 From: Maxim Sobolev Date: Wed, 10 Aug 2022 18:44:20 -0700 Subject: [PATCH] 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 d8a26132223..e8cdaa230ca 100644 --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -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); } /* -- 2.45.2