}
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;
int vflag = 0;
char cwdpath[PATH_MAX];
const char *cwd;
+ char **envp;
#ifdef HAVE_BSD_AUTH_H
char *login_style = NULL;
#endif
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.3 2015/07/21 11:04:06 zhuk 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$ */
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
*/
#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);
+}