version 1.6, 2017/04/06 21:12:06 |
version 1.7, 2019/06/16 18:16:34 |
|
|
#include <err.h> |
#include <err.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <errno.h> |
#include <errno.h> |
|
#include <pwd.h> |
|
|
#include "doas.h" |
#include "doas.h" |
|
|
|
|
u_int count; |
u_int count; |
}; |
}; |
|
|
|
static void fillenv(struct env *env, const char **envlist); |
|
|
static int |
static int |
envcmp(struct envnode *a, struct envnode *b) |
envcmp(struct envnode *a, struct envnode *b) |
{ |
{ |
|
|
free(node); |
free(node); |
} |
} |
|
|
|
static void |
|
addnode(struct env *env, const char *key, const char *value) |
|
{ |
|
struct envnode *node; |
|
|
|
node = createnode(key, value); |
|
RB_INSERT(envtree, &env->root, node); |
|
env->count++; |
|
} |
|
|
static struct env * |
static struct env * |
createenv(const struct rule *rule) |
createenv(const struct rule *rule, const struct passwd *mypw, |
|
const struct passwd *targpw) |
{ |
{ |
struct env *env; |
struct env *env; |
u_int i; |
u_int i; |
|
|
RB_INIT(&env->root); |
RB_INIT(&env->root); |
env->count = 0; |
env->count = 0; |
|
|
|
addnode(env, "DOAS_USER", mypw->pw_name); |
|
|
if (rule->options & KEEPENV) { |
if (rule->options & KEEPENV) { |
extern const char **environ; |
extern const char **environ; |
|
|
|
|
env->count++; |
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; |
return env; |
|
|
} |
} |
|
|
char ** |
char ** |
prepenv(const struct rule *rule) |
prepenv(const struct rule *rule, const struct passwd *mypw, |
|
const struct passwd *targpw) |
{ |
{ |
static const char *safeset[] = { |
|
"DISPLAY", "HOME", "LOGNAME", "MAIL", |
|
"PATH", "TERM", "USER", "USERNAME", |
|
NULL |
|
}; |
|
struct env *env; |
struct env *env; |
|
|
env = createenv(rule); |
env = createenv(rule, mypw, targpw); |
|
|
/* if we started with blank, fill some defaults then apply rules */ |
|
if (!(rule->options & KEEPENV)) |
|
fillenv(env, safeset); |
|
if (rule->envlist) |
if (rule->envlist) |
fillenv(env, rule->envlist); |
fillenv(env, rule->envlist); |
|
|