aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Zhukov <zhuk@openbsd.org>2015-07-28 19:49:04 +0000
committerVadim Zhukov <zhuk@openbsd.org>2015-07-28 19:49:04 +0000
commitd8e4190f9c5dda202a406c1de21a8ac860f304d7 (patch)
tree5c131c85e50e0418e58de0cac4332d6ca38894af
parent73e0aef5b2bb0bc50ca67870b02b71d77150f312 (diff)
downloadopendoas-d8e4190f9c5dda202a406c1de21a8ac860f304d7.tar.gz
Rename some variables and add few comments in keepenv handling code.
Makes the code more readable. okay tedu@
-rw-r--r--doas.c43
1 files changed, 24 insertions, 19 deletions
diff --git a/doas.c b/doas.c
index 91b3f68..a4d7984 100644
--- 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--;
}
}
}