svn commit: r357791 - in stable: 11/usr.bin/env 12/usr.bin/env

2020-02-11 Thread Kyle Evans
Author: kevans
Date: Wed Feb 12 02:09:12 2020
New Revision: 357791
URL: https://svnweb.freebsd.org/changeset/base/357791

Log:
  MFC r357563: env(1): grow -L user/class and -U user/class options
  
  This allows one to set the environment of the specified user either from
  login.conf alone (-L) or both login.conf and ~/.login_conf if present (-U).
  
  This is a supporting feature to allow service(8) to pull in the environment
  of the "daemon" class before invoking the rc script.

Modified:
  stable/11/usr.bin/env/Makefile
  stable/11/usr.bin/env/env.1
  stable/11/usr.bin/env/env.c
Directory Properties:
  stable/11/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/12/usr.bin/env/Makefile
  stable/12/usr.bin/env/env.1
  stable/12/usr.bin/env/env.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/11/usr.bin/env/Makefile
==
--- stable/11/usr.bin/env/Makefile  Wed Feb 12 02:07:37 2020
(r357790)
+++ stable/11/usr.bin/env/Makefile  Wed Feb 12 02:09:12 2020
(r357791)
@@ -4,4 +4,6 @@
 PROG=  env
 SRCS=  env.c envopts.c
 
+LIBADD=util
+
 .include 

Modified: stable/11/usr.bin/env/env.1
==
--- stable/11/usr.bin/env/env.1 Wed Feb 12 02:07:37 2020(r357790)
+++ stable/11/usr.bin/env/env.1 Wed Feb 12 02:09:12 2020(r357791)
@@ -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 7, 2019
+.Dd January 19, 2020
 .Dt ENV 1
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 0iv
+.Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
 .Op Fl P Ar altpath
 .Op Fl S Ar string
 .Op Fl u Ar name
@@ -76,6 +77,28 @@ The environment inherited
 by
 .Nm
 is ignored completely.
+.\"-L | -U
+.It Fl L | Fl U Ar user Ns Op / Ns Ar class
+Add the environment variable definitions from
+.Xr login.conf 5
+for the specified user and login class to the environment, after
+processing any
+.Fl i
+or
+.Fl u
+options, but before processing any
+.Ar name Ns = Ns Ar value
+options.
+If
+.Fl L
+is used, only the system-wide
+.Pa /etc/login.conf.db
+file is read; if
+.Fl U
+is used, then the specified user's
+.Pa ~/.login_conf
+is read as well.
+The user may be specified by name or by uid.
 .\"-P
 .It Fl P Ar altpath
 Search the set of directories as specified by
@@ -450,6 +473,7 @@ option as a synonym for
 .Xr printenv 1 ,
 .Xr sh 1 ,
 .Xr execvp 3 ,
+.Xr login.conf 5 ,
 .Xr environ 7
 .Sh STANDARDS
 The
@@ -457,7 +481,7 @@ The
 utility conforms to
 .St -p1003.1-2001 .
 The
-.Fl P , S , u
+.Fl 0 , L , P , S , U , u
 and
 .Fl v
 options are non-standard extensions supported by
@@ -474,6 +498,12 @@ and
 .Fl v
 options were added in
 .Fx 6.0 .
+The
+.Fl 0 , L
+and
+.Fl U
+options were added in
+.Fx 13.0 .
 .Sh BUGS
 The
 .Nm

Modified: stable/11/usr.bin/env/env.c
==
--- stable/11/usr.bin/env/env.c Wed Feb 12 02:07:37 2020(r357790)
+++ stable/11/usr.bin/env/env.c Wed Feb 12 02:09:12 2020(r357791)
@@ -42,11 +42,16 @@ static char sccsid[] = "@(#)env.c   8.3 (Berkeley) 4/2/9
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
+
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
-#include 
 #include 
+#include 
 #include 
 
 #include "envopts.h"
@@ -69,13 +74,23 @@ main(int argc, char **argv)
 {
char *altpath, **ep, *p, **parg, term;
char *cleanenv[1];
+   char *login_class, *login_name;
+   struct passwd *pw;
+   login_cap_t *lc;
+   bool login_as_user;
+   uid_t uid;
int ch, want_clear;
int rtrn;
 
altpath = NULL;
+   login_class = NULL;
+   login_name = NULL;
+   pw = NULL;
+   lc = NULL;
+   login_as_user = false;
want_clear = 0;
term = '\n';
-   while ((ch = getopt(argc, argv, "-0iP:S:u:v")) != -1)
+   while ((ch = getopt(argc, argv, "-0iL:P:S:U:u:v")) != -1)
switch(ch) {
case '-':
case 'i':
@@ -84,6 +99,12 @@ main(int argc, char **argv)
case '0':
term = '\0';
break;
+   case 'U':
+   login_as_user = true;
+   /* FALLTHROUGH */
+   case 'L':
+   login_name = optarg;
+   break;
case 'P':
altpath = strdup(optarg);
break;
@@ -117,6 +138,48 @@ main(int argc, char **argv)
if (env_verbosity)
fprintf(stderr, "#env clearing environ\n");
}
+   if (login_name != NULL) {
+   login_class = strchr(login_name, '/');
+   if (login_class)
+   *login_cla

svn commit: r357791 - in stable: 11/usr.bin/env 12/usr.bin/env

2020-02-11 Thread Kyle Evans
Author: kevans
Date: Wed Feb 12 02:09:12 2020
New Revision: 357791
URL: https://svnweb.freebsd.org/changeset/base/357791

Log:
  MFC r357563: env(1): grow -L user/class and -U user/class options
  
  This allows one to set the environment of the specified user either from
  login.conf alone (-L) or both login.conf and ~/.login_conf if present (-U).
  
  This is a supporting feature to allow service(8) to pull in the environment
  of the "daemon" class before invoking the rc script.

Modified:
  stable/12/usr.bin/env/Makefile
  stable/12/usr.bin/env/env.1
  stable/12/usr.bin/env/env.c
Directory Properties:
  stable/12/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/usr.bin/env/Makefile
  stable/11/usr.bin/env/env.1
  stable/11/usr.bin/env/env.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/12/usr.bin/env/Makefile
==
--- stable/12/usr.bin/env/Makefile  Wed Feb 12 02:07:37 2020
(r357790)
+++ stable/12/usr.bin/env/Makefile  Wed Feb 12 02:09:12 2020
(r357791)
@@ -4,4 +4,6 @@
 PROG=  env
 SRCS=  env.c envopts.c
 
+LIBADD=util
+
 .include 

Modified: stable/12/usr.bin/env/env.1
==
--- stable/12/usr.bin/env/env.1 Wed Feb 12 02:07:37 2020(r357790)
+++ stable/12/usr.bin/env/env.1 Wed Feb 12 02:09:12 2020(r357791)
@@ -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 7, 2019
+.Dd January 19, 2020
 .Dt ENV 1
 .Os
 .Sh NAME
@@ -40,6 +40,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl 0iv
+.Op Fl L Ns | Ns Fl U Ar user Ns Op / Ns Ar class
 .Op Fl P Ar altpath
 .Op Fl S Ar string
 .Op Fl u Ar name
@@ -76,6 +77,28 @@ The environment inherited
 by
 .Nm
 is ignored completely.
+.\"-L | -U
+.It Fl L | Fl U Ar user Ns Op / Ns Ar class
+Add the environment variable definitions from
+.Xr login.conf 5
+for the specified user and login class to the environment, after
+processing any
+.Fl i
+or
+.Fl u
+options, but before processing any
+.Ar name Ns = Ns Ar value
+options.
+If
+.Fl L
+is used, only the system-wide
+.Pa /etc/login.conf.db
+file is read; if
+.Fl U
+is used, then the specified user's
+.Pa ~/.login_conf
+is read as well.
+The user may be specified by name or by uid.
 .\"-P
 .It Fl P Ar altpath
 Search the set of directories as specified by
@@ -450,6 +473,7 @@ option as a synonym for
 .Xr printenv 1 ,
 .Xr sh 1 ,
 .Xr execvp 3 ,
+.Xr login.conf 5 ,
 .Xr environ 7
 .Sh STANDARDS
 The
@@ -457,7 +481,7 @@ The
 utility conforms to
 .St -p1003.1-2001 .
 The
-.Fl P , S , u
+.Fl 0 , L , P , S , U , u
 and
 .Fl v
 options are non-standard extensions supported by
@@ -474,6 +498,12 @@ and
 .Fl v
 options were added in
 .Fx 6.0 .
+The
+.Fl 0 , L
+and
+.Fl U
+options were added in
+.Fx 13.0 .
 .Sh BUGS
 The
 .Nm

Modified: stable/12/usr.bin/env/env.c
==
--- stable/12/usr.bin/env/env.c Wed Feb 12 02:07:37 2020(r357790)
+++ stable/12/usr.bin/env/env.c Wed Feb 12 02:09:12 2020(r357791)
@@ -44,11 +44,16 @@ static char sccsid[] = "@(#)env.c   8.3 (Berkeley) 4/2/9
 #include 
 __FBSDID("$FreeBSD$");
 
+#include 
+
 #include 
 #include 
+#include 
+#include 
+#include 
 #include 
-#include 
 #include 
+#include 
 #include 
 
 #include "envopts.h"
@@ -71,13 +76,23 @@ main(int argc, char **argv)
 {
char *altpath, **ep, *p, **parg, term;
char *cleanenv[1];
+   char *login_class, *login_name;
+   struct passwd *pw;
+   login_cap_t *lc;
+   bool login_as_user;
+   uid_t uid;
int ch, want_clear;
int rtrn;
 
altpath = NULL;
+   login_class = NULL;
+   login_name = NULL;
+   pw = NULL;
+   lc = NULL;
+   login_as_user = false;
want_clear = 0;
term = '\n';
-   while ((ch = getopt(argc, argv, "-0iP:S:u:v")) != -1)
+   while ((ch = getopt(argc, argv, "-0iL:P:S:U:u:v")) != -1)
switch(ch) {
case '-':
case 'i':
@@ -86,6 +101,12 @@ main(int argc, char **argv)
case '0':
term = '\0';
break;
+   case 'U':
+   login_as_user = true;
+   /* FALLTHROUGH */
+   case 'L':
+   login_name = optarg;
+   break;
case 'P':
altpath = strdup(optarg);
break;
@@ -119,6 +140,48 @@ main(int argc, char **argv)
if (env_verbosity)
fprintf(stderr, "#env clearing environ\n");
}
+   if (login_name != NULL) {
+   login_class = strchr(login_name, '/');
+   if (login_class)
+   *login_cl