diff options
author | Andinus <andinus@nand.sh> | 2020-04-06 12:36:14 +0530 |
---|---|---|
committer | Andinus <andinus@nand.sh> | 2020-04-06 12:36:14 +0530 |
commit | 09e64a527745d86a36aa45fb5ccc1f27ac25f04d (patch) | |
tree | bc50c42fc00a634d27eb8bedf023385417c10998 /paths.go | |
download | lynx-09e64a527745d86a36aa45fb5ccc1f27ac25f04d.tar.gz |
Initial Commit v0.1.0
Diffstat (limited to 'paths.go')
-rw-r--r-- | paths.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/paths.go b/paths.go new file mode 100644 index 0000000..2a3986e --- /dev/null +++ b/paths.go @@ -0,0 +1,38 @@ +// Package lynx is a simple wrapper to unveil. +package lynx + +import "golang.org/x/sys/unix" + +// UnveilPaths takes a map of path, permission & unveils them one by +// one, it will return an error if unveil fails at any step. "no such +// file or directory" error is ignored. +func UnveilPaths(paths map[string]string) error { + for k, v := range paths { + err := unix.Unveil(k, v) + + // "no such file or directory" error is ignored. + if err != nil && err.Error() != "no such file or directory" { + // Better error message could be returned like + // one that includes the path on which unveil + // failed. + return err + } + } + // Returning nil because err can be "no such file or + // directory" which needs to be ignored. + return nil +} + +// UnveilPathsStrict takes a map of path, permission & unveils them +// one by one, it will return an error if unveil fails at any steop. +// No error is ignored. +func UnveilPathsStrict(paths map[string]string) (err error) { + for k, v := range paths { + err = unix.Unveil(k, v) + + if err != nil { + return + } + } + return +} |