--- b/usr.bin/env/env.1 +++ b/usr.bin/env/env.1 @@ -31,7 +31,7 @@ .\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp .\" $FreeBSD$ .\" -.Dd November 11, 2020 +.Dd March 3, 2021 .Dt ENV 1 .Os .Sh NAME @@ -104,6 +104,11 @@ is used, then the specified user's .Pa ~/.login_conf is read as well. The user may be specified by name or by uid. +If a username of +.Sq Li \&- +is given, then no user lookup will be done, the login class will default to +.Sq Li default +if not explicitly given, and no substitutions will be done on the values. .\" -P .It Fl P Ar altpath Search the set of directories as specified by --- b/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -144,16 +144,23 @@ main(int argc, char **argv) login_class = strchr(login_name, '/'); if (login_class) *login_class++ = '\0'; - pw = getpwnam(login_name); - if (pw == NULL) { - char *endp = NULL; - errno = 0; - uid = strtoul(login_name, &endp, 10); - if (errno == 0 && *endp == '\0') - pw = getpwuid(uid); + if (*login_name != '\0' && strcmp(login_name,"-") != 0) { + pw = getpwnam(login_name); + if (pw == NULL) { + char *endp = NULL; + errno = 0; + uid = strtoul(login_name, &endp, 10); + if (errno == 0 && *endp == '\0') + pw = getpwuid(uid); + } + if (pw == NULL) + errx(EXIT_FAILURE, "no such user: %s", login_name); } - if (pw == NULL) - errx(EXIT_FAILURE, "no such user: %s", login_name); + /* + * Note that it is safe for pw to be null here; the libutil + * code handles that, bypassing substitution of $ and using + * the class "default" if no class name is given either. + */ if (login_class != NULL) { lc = login_getclass(login_class); if (lc == NULL) --- b/usr.sbin/service/service.sh +++ b/usr.sbin/service/service.sh @@ -171,7 +171,7 @@ cd / for dir in /etc/rc.d $local_startup; do if [ -x "$dir/$script" ]; then [ -n "$VERBOSE" ] && echo "$script is located in $dir" - exec env -i -L 0/daemon HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin "$dir/$script" "$@" + exec env -i -L -/daemon HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin "$dir/$script" "$@" fi done