opendoas

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

commit 8a932c141276ebd1d33216e3da558308c329580c
parent e355b1d04349731687a4eb6222a91d9b2dcf7e6f
Author: Ted Unangst <tedu@openbsd.org>
Date:   Tue, 21 Jul 2015 16:12:04 +0000

cases should line up with switch, from Dimitris Papastamos

Diffstat:
doas.1 | 10++++++++--
doas.c | 12++++++++----
parse.y | 42+++++++++++++++++++++---------------------
3 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/doas.1 b/doas.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: doas.1,v 1.7 2015/07/19 17:00:22 jmc Exp $ +.\" $OpenBSD: doas.1,v 1.8 2015/07/21 11:04:06 zhuk Exp $ .\" .\"Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> .\" @@ -13,7 +13,7 @@ .\"WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN .\"ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\"OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -.Dd $Mdocdate: July 19 2015 $ +.Dd $Mdocdate: July 21 2015 $ .Dt DOAS 1 .Os .Sh NAME @@ -21,6 +21,7 @@ .Nd execute commands as another user .Sh SYNOPSIS .Nm doas +.Op Fl C Ar config .Op Fl s .Op Fl u Ar user .Ar command @@ -32,6 +33,11 @@ utility executes the given command as another user. .Pp The options are as follows: .Bl -tag -width tenletters +.It Fl C Ar config +Parse and check the configuration file +.Ar config , +then exit. +No command is executed. .It Fl s Execute the shell from .Ev SHELL diff --git a/doas.c b/doas.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doas.c,v 1.14 2015/07/20 01:04:37 tedu Exp $ */ +/* $OpenBSD: doas.c,v 1.15 2015/07/21 11:04:06 zhuk Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -294,10 +294,12 @@ main(int argc, char **argv, char **envp) int i, ch; int sflag = 0; - parseconfig("/etc/doas.conf"); - - while ((ch = getopt(argc, argv, "su:")) != -1) { + while ((ch = getopt(argc, argv, "C:su:")) != -1) { switch (ch) { + case 'C': + setuid(getuid()); + parseconfig(optarg); + exit(0); case 'u': if (parseuid(optarg, &target) != 0) errx(1, "unknown user"); @@ -316,6 +318,8 @@ main(int argc, char **argv, char **envp) if ((!sflag && !argc) || (sflag && argc)) usage(); + parseconfig("/etc/doas.conf"); + uid = getuid(); pw = getpwuid(uid); if (!pw) diff --git a/parse.y b/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.6 2015/07/19 22:11:41 benno Exp $ */ +/* $OpenBSD: parse.y,v 1.7 2015/07/21 11:04:06 zhuk Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -198,27 +198,27 @@ yylex(void) repeat: c = getc(yyfp); switch (c) { - case ' ': - case '\t': - goto repeat; /* skip spaces */ - case '\\': - next = getc(yyfp); - if (next == '\n') - goto repeat; - else - c = next; - case '\n': - case '{': - case '}': - return c; - case '#': - while ((c = getc(yyfp)) != '\n' && c != EOF) - ; /* skip comments */ - if (c == EOF) - return 0; - return c; - case EOF: + case ' ': + case '\t': + goto repeat; /* skip spaces */ + case '\\': + next = getc(yyfp); + if (next == '\n') + goto repeat; + else + c = next; + case '\n': + case '{': + case '}': + return c; + case '#': + while ((c = getc(yyfp)) != '\n' && c != EOF) + ; /* skip comments */ + if (c == EOF) return 0; + return c; + case EOF: + return 0; } while (1) { switch (c) {