diff options
| author | Maxim Sobolev <sobomax@FreeBSD.org> | 2022-08-11 01:44:20 +0000 |
|---|---|---|
| committer | Maxim Sobolev <sobomax@FreeBSD.org> | 2022-08-12 17:07:56 +0000 |
| commit | 6b3ad1d737321cf6a70e957fb15d5287c378373c (patch) | |
| tree | 164c43abe5fd206e9f39471c85f7ed90ed8083a3 | |
| parent | 948f31d7b0ed31a834b31ac63f314aecef474dfe (diff) | |
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
| -rw-r--r-- | usr.sbin/daemon/daemon.c | 5 |
1 files changed, 5 insertions, 0 deletions
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); } /* |
