simple prepenv function.
OK tedu@
-/* $OpenBSD: doas.c,v 1.56 2016/06/16 17:40:30 tedu Exp $ */
+/* $OpenBSD: doas.c,v 1.57 2016/06/19 19:29:43 martijn Exp $ */
/*
* Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
*
}
int
-main(int argc, char **argv, char **envp)
+main(int argc, char **argv)
{
const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
"/usr/local/bin:/usr/local/sbin";
char *shargv[] = { NULL, NULL };
char *sh;
const char *cmd;
- struct env *env;
char cmdline[LINE_MAX];
char myname[_PW_NAME_LEN + 1];
struct passwd *pw;
char cwdpath[PATH_MAX];
const char *cwd;
char *login_style = NULL;
+ char **envp;
setprogname("doas");
syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
myname, cmdline, pw->pw_name, cwd);
- env = createenv(envp);
- env = filterenv(env, rule);
- envp = flattenenv(env);
+ envp = prepenv(rule);
if (rule->cmd) {
if (setenv("PATH", safepath, 1) == -1)
-/* $OpenBSD: doas.h,v 1.7 2016/06/16 17:40:30 tedu Exp $ */
-
-#include <sys/tree.h>
-
-struct envnode {
- RB_ENTRY(envnode) node;
- const char *key;
- const char *value;
-};
-
-struct env {
- RB_HEAD(envtree, envnode) root;
- u_int count;
-};
-
-RB_PROTOTYPE(envtree, envnode, node, envcmp)
-
+/* $OpenBSD: doas.h,v 1.8 2016/06/19 19:29:43 martijn Exp $ */
struct rule {
int action;
int options;
size_t arraylen(const char **);
-struct env *createenv(char **);
-struct env *filterenv(struct env *, struct rule *);
-char **flattenenv(struct env *);
+char **prepenv(struct rule *);
#define PERMIT 1
#define DENY 2
-/* $OpenBSD: env.c,v 1.1 2016/06/16 17:40:30 tedu Exp $ */
+/* $OpenBSD: env.c,v 1.2 2016/06/19 19:29:43 martijn Exp $ */
/*
* Copyright (c) 2016 Ted Unangst <tedu@openbsd.org>
*
*/
#include <sys/types.h>
+#include <sys/tree.h>
#include <string.h>
#include <stdio.h>
#include "doas.h"
+struct envnode {
+ RB_ENTRY(envnode) node;
+ const char *key;
+ const char *value;
+};
+
+struct env {
+ RB_HEAD(envtree, envnode) root;
+ u_int count;
+};
+
int
envcmp(struct envnode *a, struct envnode *b)
{
return strcmp(a->key, b->key);
}
-RB_GENERATE(envtree, envnode, node, envcmp)
+RB_GENERATE_STATIC(envtree, envnode, node, envcmp)
+
+struct env *createenv(char **);
+struct env *filterenv(struct env *, struct rule *);
+char **flattenenv(struct env *);
struct env *
createenv(char **envp)
return copy;
}
+
+char **
+prepenv(struct rule *rule)
+{
+ extern char **environ;
+ struct env *env;
+
+ env = createenv(environ);
+ env = filterenv(env, rule);
+ return flattenenv(env);
+}