setkey(8): add -e option to take script from the command line

Reviewed by:	ae
Sponsored by:	Nvidia networking
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D39393
This commit is contained in:
Konstantin Belousov 2023-04-03 04:03:50 +03:00
parent 04bab189b8
commit 3cb808226c
2 changed files with 26 additions and 5 deletions

View file

@ -29,7 +29,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd October 19, 2022
.Dd April 3, 2023
.Dt SETKEY 8
.Os
.\"
@ -45,6 +45,9 @@
.Op Fl v
.Fl f Ar filename
.Nm
.Op Fl v
.Fl e Ar script
.Nm
.Op Fl Pgltv
.Fl D
.Nm
@ -65,11 +68,14 @@ The
.Nm
utility takes a series of operations from the standard input
(if invoked with
.Fl c )
or the file named
.Fl c ) ,
from the file named
.Ar filename
(if invoked with
.Fl f Ar filename ) .
.Fl f Ar filename ) ,
or from the command line argument following the option
(if invoked with
.Fl e Ar script ) .
.Bl -tag -width indent
.It Fl D
Dump the SAD entries.

View file

@ -99,6 +99,7 @@ usage(void)
printf("usage: setkey [-v] -c\n");
printf(" setkey [-v] -f filename\n");
printf(" setkey [-v] -e \"<script>\"\n");
printf(" setkey [-Pagltv] -D\n");
printf(" setkey [-Pv] -F\n");
printf(" setkey [-h] -x\n");
@ -129,13 +130,27 @@ main(int ac, char **av)
thiszone = gmt2local(0);
while ((c = getopt(ac, av, "acdf:ghltvxDFP")) != -1) {
while ((c = getopt(ac, av, "acde:f:ghltvxDFP")) != -1) {
switch (c) {
case 'c':
f_mode = MODE_SCRIPT;
fp = stdin;
break;
case 'e':
if (fp != stdin) {
err(-1, "only one -f/-e option is accepted");
}
f_mode = MODE_SCRIPT;
fp = fmemopen(optarg, strlen(optarg), "r");
if (fp == NULL) {
err(-1, "fmemopen");
/*NOTREACHED*/
}
break;
case 'f':
if (fp != stdin) {
err(-1, "only one -f/-e option is accepted");
}
f_mode = MODE_SCRIPT;
if ((fp = fopen(optarg, "r")) == NULL) {
err(-1, "fopen");