From 6e5a88bc7749b3fe4d9419b95a2ba2b596e3f837 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 15 Apr 2020 19:20:22 +0530 Subject: Rename func UnveilPath to Unveil UnveilPath is confusing, it's kept only for backwards compatibility & users should use Unveil & UnveilStrict instead of UnveilPath & UnveilPathStrict. --- README.org | 52 ++++++++++++++++++++++++++-------------------------- path.go | 28 ---------------------------- path_other.go | 15 --------------- unveil.go | 39 +++++++++++++++++++++++++++++++++++++++ unveil_other.go | 15 +++++++++++++++ 5 files changed, 80 insertions(+), 69 deletions(-) delete mode 100644 path.go delete mode 100644 path_other.go create mode 100644 unveil.go create mode 100644 unveil_other.go diff --git a/README.org b/README.org index 4cfe1f4..b21bc00 100644 --- a/README.org +++ b/README.org @@ -13,6 +13,32 @@ currently only /OpenBSD/ is supported. | GitHub (Mirror) | [[https://github.com/andinus/lynx][Lynx - GitHub]] | * Examples +** Unveil / UnveilStrict +Unveil takes a path, permission & unveils it, it will return an error if unveil +fails at any step. "no such file or directory" error is ignored, if you want to +get that error too then use UnveilStrict. + +#+BEGIN_SRC go +package main + +import "tildegit.org/andinus/lynx" + +func main() { + path := "/dev/null" + flags := "rw" + + err = lynx.Unveil(path, flags) + if err != nil { + log.Fatal(err) + } + + // This will return an error if the path doesn't exist. + err = lynx.UnveilStrict(path, flags) + if err != nil { + log.Fatal(err) + } +} +#+END_SRC ** UnveilCommands UnveilCommands takes a slice of commands & unveils them one by one, it will return an error if unveil fails at any step. "no such file or directory" error @@ -64,32 +90,6 @@ func main() { } } #+END_SRC -** UnveilPath / UnveilPathStrict -UnveilPath takes a path, permission & unveils it, it will return an error if -unveil fails at any step. "no such file or directory" error is ignored, if you -want to get that error too then use UnveilPathStrict. - -#+BEGIN_SRC go -package main - -import "tildegit.org/andinus/lynx" - -func main() { - path := "/dev/null" - flags := "rw" - - err = lynx.UnveilPath(path, flags) - if err != nil { - log.Fatal(err) - } - - // This will return an error if the path doesn't exist. - err = lynx.UnveilPathStrict(path, flags) - if err != nil { - log.Fatal(err) - } -} -#+END_SRC ** UnveilBlock UnveilBlock is just a wrapper around unix.UnveilBlock, it does nothing extra. You should use unix.UnveilBlock. diff --git a/path.go b/path.go deleted file mode 100644 index a04c723..0000000 --- a/path.go +++ /dev/null @@ -1,28 +0,0 @@ -// +build openbsd - -package lynx - -import "golang.org/x/sys/unix" - -// UnveilPath takes a path, permission & unveils it, returning an -// error if unveil fails. "no such file or directory" error is -// ignored. -func UnveilPath(path string, flags string) (err error) { - err = unix.Unveil(path, flags) - - // "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 -} - -// UnveilPathStrict is just a wrapper around unix.Unveil. -func UnveilPathStrict(path string, flags string) error { - return unix.Unveil(path, flags) -} diff --git a/path_other.go b/path_other.go deleted file mode 100644 index a0273c9..0000000 --- a/path_other.go +++ /dev/null @@ -1,15 +0,0 @@ -// +build !openbsd - -package lynx - -// UnveilPath takes a path, permission & unveils it, it does nothing -// on non OpenBSD systems. -func UnveilPath(_ string, _ string) error { - return nil -} - -// UnveilPathStrict is just a wrapper around unix.Unveil. It does -// nothing on non OpenBSD systems. -func UnveilPathStrict(_ string, _ string) error { - return nil -} diff --git a/unveil.go b/unveil.go new file mode 100644 index 0000000..3069ec6 --- /dev/null +++ b/unveil.go @@ -0,0 +1,39 @@ +// +build openbsd + +package lynx + +import "golang.org/x/sys/unix" + +// Unveil takes a path, permission & unveils it, returning an +// error if unveil fails. "no such file or directory" error is +// ignored. +func Unveil(path string, flags string) (err error) { + err = unix.Unveil(path, flags) + + // "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 +} + +// UnveilPath is kept for backwards compatibility, use Unveil instead. +func UnveilPath(path string, flags string) (err error) { + return Unveil(path, flags) +} + +// UnveilStrict is just a wrapper around unix.Unveil. +func UnveilStrict(path string, flags string) error { + return unix.Unveil(path, flags) +} + +// UnveilPathStrict is kept for backwards compatibility, use +// UnveilStrict instead. +func UnveilPathStrict(path string, flags string) error { + return UnveilStrict(path, flags) +} diff --git a/unveil_other.go b/unveil_other.go new file mode 100644 index 0000000..a0273c9 --- /dev/null +++ b/unveil_other.go @@ -0,0 +1,15 @@ +// +build !openbsd + +package lynx + +// UnveilPath takes a path, permission & unveils it, it does nothing +// on non OpenBSD systems. +func UnveilPath(_ string, _ string) error { + return nil +} + +// UnveilPathStrict is just a wrapper around unix.Unveil. It does +// nothing on non OpenBSD systems. +func UnveilPathStrict(_ string, _ string) error { + return nil +} -- cgit 1.4.1-2-gfad0