You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unveil_openbsd.go 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package unix
  5. import (
  6. "syscall"
  7. "unsafe"
  8. )
  9. // Unveil implements the unveil syscall.
  10. // For more information see unveil(2).
  11. // Note that the special case of blocking further
  12. // unveil calls is handled by UnveilBlock.
  13. func Unveil(path string, flags string) error {
  14. pathPtr, err := syscall.BytePtrFromString(path)
  15. if err != nil {
  16. return err
  17. }
  18. flagsPtr, err := syscall.BytePtrFromString(flags)
  19. if err != nil {
  20. return err
  21. }
  22. _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(unsafe.Pointer(pathPtr)), uintptr(unsafe.Pointer(flagsPtr)), 0)
  23. if e != 0 {
  24. return e
  25. }
  26. return nil
  27. }
  28. // UnveilBlock blocks future unveil calls.
  29. // For more information see unveil(2).
  30. func UnveilBlock() error {
  31. // Both pointers must be nil.
  32. var pathUnsafe, flagsUnsafe unsafe.Pointer
  33. _, _, e := syscall.Syscall(SYS_UNVEIL, uintptr(pathUnsafe), uintptr(flagsUnsafe), 0)
  34. if e != 0 {
  35. return e
  36. }
  37. return nil
  38. }