X-Git-Url: https://git.armaanb.net/?a=blobdiff_plain;f=env.c;h=e2286fc83b0232425f67a8cda355ef1453f7739f;hb=e8e8713b26723d2daf3de50b51d2ac209ad65716;hp=c0f38378e7947c90e77e23396921179be4d6d602;hpb=01c658f8c45cb92a343be5f32aa6da70b2032168;p=opendoas.git diff --git a/env.c b/env.c index c0f3837..e2286fc 100644 --- a/env.c +++ b/env.c @@ -15,6 +15,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include "config.h" + #include #include "sys-tree.h" @@ -26,8 +28,10 @@ #include #include +#include "openbsd.h" #include "doas.h" -#include "includes.h" + +const char *formerpath; struct envnode { RB_ENTRY(envnode) node; @@ -86,6 +90,10 @@ static struct env * createenv(const struct rule *rule, const struct passwd *mypw, const struct passwd *targpw) { + static const char *copyset[] = { + "DISPLAY", "TERM", + NULL + }; struct env *env; u_int i; @@ -96,6 +104,13 @@ createenv(const struct rule *rule, const struct passwd *mypw, env->count = 0; 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, "SHELL", targpw->pw_shell); + addnode(env, "USER", targpw->pw_name); + + fillenv(env, copyset); if (rule->options & KEEPENV) { extern char **environ; @@ -125,19 +140,6 @@ createenv(const struct rule *rule, const struct passwd *mypw, env->count++; } } - } else { - static const char *copyset[] = { - "DISPLAY", "TERM", - NULL - }; - - addnode(env, "HOME", targpw->pw_dir); - addnode(env, "LOGNAME", targpw->pw_name); - addnode(env, "PATH", getenv("PATH")); - addnode(env, "SHELL", targpw->pw_shell); - addnode(env, "USER", targpw->pw_name); - - fillenv(env, copyset); } return env; @@ -201,10 +203,17 @@ 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); + if (strcmp(name, "PATH") == 0) + val = formerpath; + else + val = getenv(name); } /* at last, we have something to insert */ if (val) {