Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

Commit

Permalink
Expose env variables to the script
Browse files Browse the repository at this point in the history
  • Loading branch information
valpackett committed Nov 24, 2018
1 parent f5a731e commit 36ffb8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -12,8 +12,8 @@

- a recent version of FreeBSD
- [Meson] build system
- [libucl]
- [libpreopen] (that linked fork, at least for now)
- [libucl] >=0.8.1 (pkg: #[233383](https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=233383))
- [libpreopen] (that linked fork, at least for now) (pkg: someday)

[libucl]: https://github.com/vstakhov/libucl
[libpreopen]: https://github.com/myfreeweb/libpreopen
Expand All @@ -29,7 +29,7 @@ Capsicumizer profiles are written in UCL syntax (which is pretty common on FreeB
run = "/usr/local/bin/gedit";
access_path = [
"/home/greg",
"$HOME",
"/usr/local",
"/var/db/fontconfig",
"/tmp",
Expand Down
12 changes: 8 additions & 4 deletions capsicumizer.cpp
@@ -1,6 +1,7 @@
#include <ucl++.h>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>

Expand All @@ -22,10 +23,14 @@ int main(int argc, char *argv[]) {
return -1;
}

std::map<std::string, std::string> ucl_vars;
for (char **env = environ; *env != nullptr; env++) {
char *sep = strchrnul(*env, '=');
ucl_vars.emplace(std::string(*env, sep - *env), std::string(sep + 1));
}

std::string uclerr;
std::ifstream script_stream(argv[1]);
Ucl script = Ucl::parse(script_stream, uclerr);
script_stream.close();
Ucl script = Ucl::parse_from_file(argv[1], ucl_vars, uclerr);
if (!uclerr.empty()) {
std::cerr << uclerr << std::endl;
return -1;
Expand Down Expand Up @@ -54,7 +59,6 @@ int main(int argc, char *argv[]) {

caph_cache_catpages();
caph_cache_tzdata();

int rtld_fd = openat(AT_FDCWD, "/libexec/ld-elf.so.1", O_RDONLY);

if (cap_enter() != 0) {
Expand Down

0 comments on commit 36ffb8e

Please sign in to comment.