doas

https://man.openbsd.org/doas.1
git clone anongit@rnpnr.xyz:doas.git
Log | Files | Refs | Feed

Commit: 2dca78835434d31dca99a852bda8198275a7d489
Parent: 68469665cce53d17c88f38c7fc9259fa0e88aae5
Author: Randy Palamar
Date:   Tue,  6 Apr 2021 12:22:26 -0600

update to latest version of mforney's patch

this includes the commits from oasis:

* openbsd: doas: Use PATH=/bin when cmd is not specified
* openbsd: doas: Use == -1 for error checking for consistency

Diffstat:
Mdoas.c | 69+++------------------------------------------------------------------
Mdoas.h | 2+-
Menv.c | 17+++++------------
3 files changed, 9 insertions(+), 79 deletions(-)

diff --git a/doas.c b/doas.c @@ -264,51 +264,11 @@ good: } int -unveilcommands(const char *ipath, const char *cmd) -{ - char *path = NULL, *p; - int unveils = 0; - - if (strchr(cmd, '/') != NULL) { - if (unveil(cmd, "x") != -1) - unveils++; - goto done; - } - - if (!ipath) { - errno = ENOENT; - goto done; - } - path = strdup(ipath); - if (!path) { - errno = ENOENT; - goto done; - } - for (p = path; p && *p; ) { - char buf[PATH_MAX]; - char *cp = strsep(&p, ":"); - - if (cp) { - int r = snprintf(buf, sizeof buf, "%s/%s", cp, cmd); - if (r >= 0 && r < sizeof buf) { - if (unveil(buf, "x") != -1) - unveils++; - } - } - } -done: - free(path); - return (unveils); -} - -int main(int argc, char **argv) { - const char *safepath = "/bin"; const char *confpath = NULL; char *shargv[] = { NULL, NULL }; char *sh; - const char *p; const char *cmd; char cmdline[LINE_MAX]; char mypwbuf[1024], targpwbuf[1024]; @@ -419,35 +379,17 @@ main(int argc, char **argv) authuser(mypw->pw_name, rule->options & PERSIST); } - if ((p = getenv("PATH")) != NULL) - formerpath = strdup(p); - if (formerpath == NULL) - formerpath = ""; - - if (unveil(_PATH_LOGIN_CONF, "r") == -1 || - unveil(_PATH_LOGIN_CONF ".db", "r") == -1) - err(1, "unveil"); - if (rule->cmd) { - if (setenv("PATH", safepath, 1) == -1) - err(1, "failed to set PATH '%s'", safepath); - } - if (unveilcommands(getenv("PATH"), cmd) == 0) - goto fail; - - if (pledge("stdio rpath getpw exec id", NULL) == -1) - err(1, "pledge"); - rv = getpwuid_r(target, &targpwstore, targpwbuf, sizeof(targpwbuf), &targpw); if (rv != 0) err(1, "getpwuid_r failed"); if (targpw == NULL) errx(1, "no passwd entry for target"); - if (initgroups(targpw->pw_name, targpw->pw_gid) < 0) + if (initgroups(targpw->pw_name, targpw->pw_gid) == -1) err(1, "initgroups"); - if (setgid(targpw->pw_gid) < 0) + if (setgid(targpw->pw_gid) == -1) err(1, "setgid"); - if (setuid(targpw->pw_uid) < 0) + if (setuid(targpw->pw_uid) == -1) err(1, "setuid"); if (pledge("stdio rpath exec", NULL) == -1) @@ -468,16 +410,11 @@ main(int argc, char **argv) envp = prepenv(rule, mypw, targpw); - /* setusercontext set path for the next process, so reset it for us */ if (rule->cmd) { if (setenv("PATH", safepath, 1) == -1) err(1, "failed to set PATH '%s'", safepath); - } else { - if (setenv("PATH", formerpath, 1) == -1) - err(1, "failed to set PATH '%s'", formerpath); } execvpe(cmd, argv, envp); -fail: if (errno == ENOENT) errx(1, "%s: command not found", cmd); err(1, "%s", cmd); diff --git a/doas.h b/doas.h @@ -29,7 +29,7 @@ extern struct rule **rules; extern size_t nrules; extern int parse_errors; -extern const char *formerpath; +extern const char *safepath; struct passwd; diff --git a/env.c b/env.c @@ -28,7 +28,7 @@ #include "doas.h" -const char *formerpath; +const char *safepath = "/bin"; struct envnode { RB_ENTRY(envnode) node; @@ -103,7 +103,7 @@ createenv(const struct rule *rule, const struct passwd *mypw, addnode(env, "DOAS_USER", mypw->pw_name); addnode(env, "HOME", targpw->pw_dir); addnode(env, "LOGNAME", targpw->pw_name); - addnode(env, "PATH", getenv("PATH")); + addnode(env, "PATH", safepath); addnode(env, "SHELL", targpw->pw_shell); addnode(env, "USER", targpw->pw_name); @@ -200,17 +200,10 @@ fillenv(struct env *env, const char **envlist) /* assign value or inherit from environ */ if (eq) { val = eq + 1; - if (*val == '$') { - if (strcmp(val + 1, "PATH") == 0) - val = formerpath; - else - val = getenv(val + 1); - } + if (*val == '$') + val = getenv(val + 1); } else { - if (strcmp(name, "PATH") == 0) - val = formerpath; - else - val = getenv(name); + val = getenv(name); } /* at last, we have something to insert */ if (val) {