git: dc96fb072300 - stable/13 - daemon(8): when -u option is used set USER, HOME and SHELL variables.

From: Maxim Sobolev <sobomax_at_FreeBSD.org>
Date: Thu, 08 Sep 2022 11:43:05 UTC
The branch stable/13 has been updated by sobomax:

URL: https://cgit.FreeBSD.org/src/commit/?id=dc96fb072300b0d08070f0419e259d55a7c42bb6

commit dc96fb072300b0d08070f0419e259d55a7c42bb6
Author:     Maxim Sobolev <sobomax@FreeBSD.org>
AuthorDate: 2022-08-11 01:44:20 +0000
Commit:     Maxim Sobolev <sobomax@FreeBSD.org>
CommitDate: 2022-09-08 11:42:56 +0000

    daemon(8): when -u option is used set USER, HOME and SHELL variables.
    
    This is consistent with what other uid-morphing utilities
    do, i.e. jexec(1), su(1) etc.
    
    Reviewed by:    gbe
    Differential Revision:  https://reviews.freebsd.org/D36148
    
    (cherry picked from commit 6b3ad1d737321cf6a70e957fb15d5287c378373c)
---
 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);
 }
 
 /*