summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/doas/doas.c8
-rw-r--r--usr.bin/doas/doas.h4
-rw-r--r--usr.bin/doas/env.c12
3 files changed, 19 insertions, 5 deletions
diff --git a/usr.bin/doas/doas.c b/usr.bin/doas/doas.c
index d77bda917f4..ec21a61ffb4 100644
--- a/usr.bin/doas/doas.c
+++ b/usr.bin/doas/doas.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.c,v 1.77 2019/06/16 18:16:34 tedu Exp $ */
+/* $OpenBSD: doas.c,v 1.78 2019/06/17 19:51:23 tedu Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
@@ -286,6 +286,7 @@ main(int argc, char **argv)
const char *confpath = NULL;
char *shargv[] = { NULL, NULL };
char *sh;
+ const char *p;
const char *cmd;
char cmdline[LINE_MAX];
char mypwbuf[_PW_BUF_LEN], targpwbuf[_PW_BUF_LEN];
@@ -402,6 +403,11 @@ main(int argc, char **argv)
authuser(mypw->pw_name, login_style, rule->options & PERSIST);
}
+ if ((p = getenv("PATH")) != NULL)
+ formerpath = strdup(p);
+ if (formerpath == NULL)
+ formerpath = "";
+
if (unveil(_PATH_LOGIN_CONF, "r") == -1)
err(1, "unveil");
if (rule->cmd) {
diff --git a/usr.bin/doas/doas.h b/usr.bin/doas/doas.h
index eec0b0759c4..6f50fc22869 100644
--- a/usr.bin/doas/doas.h
+++ b/usr.bin/doas/doas.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: doas.h,v 1.14 2019/06/16 18:16:34 tedu Exp $ */
+/* $OpenBSD: doas.h,v 1.15 2019/06/17 19:51:23 tedu Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
@@ -29,6 +29,8 @@ extern struct rule **rules;
extern int nrules;
extern int parse_errors;
+extern const char *formerpath;
+
struct passwd;
char **prepenv(const struct rule *, const struct passwd *,
diff --git a/usr.bin/doas/env.c b/usr.bin/doas/env.c
index 7e419b8924f..88be5bbf698 100644
--- a/usr.bin/doas/env.c
+++ b/usr.bin/doas/env.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: env.c,v 1.8 2019/06/17 16:01:26 tedu Exp $ */
+/* $OpenBSD: env.c,v 1.9 2019/06/17 19:51:23 tedu Exp $ */
/*
* Copyright (c) 2016 Ted Unangst <tedu@openbsd.org>
*
@@ -28,6 +28,8 @@
#include "doas.h"
+const char *formerpath;
+
struct envnode {
RB_ENTRY(envnode) node;
const char *key;
@@ -198,8 +200,12 @@ fillenv(struct env *env, const char **envlist)
/* assign value or inherit from environ */
if (eq) {
val = eq + 1;
- if (*val == '$')
- val = getenv(val + 1);
+ if (*val == '$') {
+ if (strcmp(val + 1, "PATH") == 0)
+ val = formerpath;
+ else
+ val = getenv(val + 1);
+ }
} else {
val = getenv(name);
}