Fix locking multiple directories

- stop pretending we are doing anything other than ro/rw
This commit is contained in:
Aaron Bieber 2023-03-21 09:06:08 -06:00
parent e433d9038e
commit 2b9c3db652
No known key found for this signature in database

View File

@ -4,17 +4,18 @@
package protect package protect
import ( import (
"log"
"os" "os"
"github.com/landlock-lsm/go-landlock/landlock" "github.com/landlock-lsm/go-landlock/landlock"
) )
type lands []landlock.PathOpt type lands struct {
paths []landlock.PathOpt
}
var landToLock lands var landToLock lands
func (l lands) landAdd(path, flags string) error { func landAdd(path, flags string) error {
s, err := os.Stat(path) s, err := os.Stat(path)
if err != nil { if err != nil {
return err return err
@ -24,31 +25,24 @@ func (l lands) landAdd(path, flags string) error {
case mode.IsDir(): case mode.IsDir():
switch flags { switch flags {
case "r": case "r":
l = append(l, landlock.RODirs(path)) landToLock.paths = append(landToLock.paths, landlock.RODirs(path))
case "w": default:
l = append(l, landlock.RWDirs(path)) landToLock.paths = append(landToLock.paths, landlock.RWDirs(path))
case "rw":
l = append(l, landlock.RWDirs(path))
} }
default: default:
switch flags { switch flags {
case "r": case "r":
log.Println("READ ONLY") landToLock.paths = append(landToLock.paths, landlock.ROFiles(path))
l = append(l, landlock.ROFiles(path)) default:
case "w": landToLock.paths = append(landToLock.paths, landlock.RWFiles(path))
log.Println("WRITE")
l = append(l, landlock.RWFiles(path))
case "rw":
log.Println("WRITE")
l = append(l, landlock.RWFiles(path))
} }
} }
return nil return nil
} }
func (l *lands) landWalk() []landlock.PathOpt { func (l lands) landWalk() []landlock.PathOpt {
return *l return l.paths
} }
func unveil(path string, flags string) error { func unveil(path string, flags string) error {
@ -58,7 +52,7 @@ func unveil(path string, flags string) error {
return landlock.V2.BestEffort().RestrictPaths() return landlock.V2.BestEffort().RestrictPaths()
} }
} }
return landToLock.landAdd(path, flags) return landAdd(path, flags)
} }
func unveilBlock() error { func unveilBlock() error {