]> git.armaanb.net Git - opendoas.git/blobdiff - env.c
Merge pull request #8 from frgm/master
[opendoas.git] / env.c
diff --git a/env.c b/env.c
index cf51e674788806db4f41f4d403c073fb805b0561..f25d21f7abc9f0d8b73ca1f2f4ccde926fcfcc2a 100644 (file)
--- a/env.c
+++ b/env.c
@@ -16,6 +16,7 @@
  */
 
 #include <sys/types.h>
+#include "sys-tree.h"
 
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
 
 #include "doas.h"
+#include "includes.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)
@@ -151,3 +168,14 @@ filterenv(struct env *orig, struct rule *rule)
 
        return copy;
 }
+
+char **
+prepenv(struct rule *rule)
+{
+       extern char **environ;
+       struct env *env;
+       
+       env = createenv(environ);
+       env = filterenv(env, rule);
+       return flattenenv(env);
+}