opendoas

A portable version of the OpenBSD `doas` command
git clone https://pi.duncano.de/git/opendoas.git
Log | Files | Refs | README | LICENSE

commit 45b991b31341fac961e4f933cb1d96de62889f7e
parent fc0380731a8b1b1e02e2319f2f992b1973526b45
Author: Nathan Holstein <nathan.holstein@gmail.com>
Date:   Sun,  9 Aug 2015 21:27:47 -0400

Add version information to doas executable.

This pulls in the dependency on version.h and adds the -v command line
option to print the version and build information.

Diffstat:
Makefile | 2++
doas.c | 19+++++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -15,6 +15,8 @@ LDFLAGS+= -lpam include bsd.prog.mk +doas.o: version.h + /etc/pam.d/doas: pam.d__doas cp $< $@ install: /etc/pam.d/doas diff --git a/doas.c b/doas.c @@ -32,11 +32,19 @@ #include "openbsd.h" #include "doas.h" +#include "version.h" + +static void __dead +version(void) +{ + fprintf(stderr, "doas: version %s built %s\n", VERSION, __DATE__); + exit(1); +} static void __dead usage(void) { - fprintf(stderr, "usage: doas [-ns] [-C config] [-u user] command [args]\n"); + fprintf(stderr, "usage: doas [-nsv] [-C config] [-u user] command [args]\n"); exit(1); } @@ -330,10 +338,11 @@ main(int argc, char **argv, char **envp) int i, ch; int sflag = 0; int nflag = 0; + int vflag = 0; uid = getuid(); - while ((ch = getopt(argc, argv, "C:nsu:")) != -1) { + while ((ch = getopt(argc, argv, "C:nsu:v")) != -1) { switch (ch) { case 'C': confpath = optarg; @@ -348,6 +357,9 @@ main(int argc, char **argv, char **envp) case 's': sflag = 1; break; + case 'v': + vflag = 1; + break; default: usage(); break; @@ -356,6 +368,9 @@ main(int argc, char **argv, char **envp) argv += optind; argc -= optind; + if (vflag) + version(); + if (confpath) { if (sflag) usage();