opendoas

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

commit d8e4190f9c5dda202a406c1de21a8ac860f304d7
parent 73e0aef5b2bb0bc50ca67870b02b71d77150f312
Author: Vadim Zhukov <zhuk@openbsd.org>
Date:   Tue, 28 Jul 2015 19:49:04 +0000

Rename some variables and add few comments in keepenv handling code.
Makes the code more readable.

okay tedu@

Diffstat:
doas.c | 43++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/doas.c b/doas.c @@ -1,4 +1,4 @@ -/* $OpenBSD: doas.c,v 1.28 2015/07/27 15:38:11 espie Exp $ */ +/* $OpenBSD: doas.c,v 1.29 2015/07/28 14:08:52 zhuk Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -182,6 +182,10 @@ parseconfig(const char *filename, int checkperms) exit(1); } +/* + * Copy to envp environment variables from oldenvp which names are + * in safeset. + */ static int copyenvhelper(const char **oldenvp, const char **safeset, int nsafe, char **envp, int ei) @@ -222,44 +226,45 @@ copyenv(const char **oldenvp, struct rule *rule) int nsafe, nbad; int nextras = 0; + /* if there was no envvar whitelist, pass all except badset ones */ nbad = arraylen(badset); if ((rule->options & KEEPENV) && !rule->envlist) { - size_t i, ii; + size_t iold, inew; size_t oldlen = arraylen(oldenvp); envp = reallocarray(NULL, oldlen + 1, sizeof(char *)); if (!envp) err(1, "reallocarray"); - for (ii = i = 0; i < oldlen; i++) { - size_t j; - for (j = 0; j < nbad; j++) { - size_t len = strlen(badset[j]); - if (strncmp(oldenvp[i], badset[j], len) == 0 && - oldenvp[i][len] == '=') { + for (inew = iold = 0; iold < oldlen; iold++) { + size_t ibad; + for (ibad = 0; ibad < nbad; ibad++) { + size_t len = strlen(badset[ibad]); + if (strncmp(oldenvp[iold], badset[ibad], len) == 0 && + oldenvp[iold][len] == '=') { break; } } - if (j == nbad) { - if (!(envp[ii] = strdup(oldenvp[i]))) + if (ibad == nbad) { + if (!(envp[inew] = strdup(oldenvp[iold]))) err(1, "strdup"); - ii++; + inew++; } } - envp[ii] = NULL; + envp[inew] = NULL; return envp; } nsafe = arraylen(safeset); if ((extra = rule->envlist)) { - size_t i; + size_t isafe; nextras = arraylen(extra); - for (i = 0; i < nsafe; i++) { - size_t j; - for (j = 0; j < nextras; j++) { - if (strcmp(extra[j], safeset[i]) == 0) { + for (isafe = 0; isafe < nsafe; isafe++) { + size_t iextras; + for (iextras = 0; iextras < nextras; iextras++) { + if (strcmp(extra[iextras], safeset[isafe]) == 0) { nextras--; - extra[j] = extra[nextras]; + extra[iextras] = extra[nextras]; extra[nextras] = NULL; - j--; + iextras--; } } }