filehandler

package
v0.0.0-...-c269f4c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilePermWrite = iota + 1
	FilePermRead
	FilePermStat
)

FilePermWrite / Read / Stat are permissions

Variables

This section is empty.

Functions

func GetExtraSet

func GetExtraSet(extra, raw []string) []string

GetExtraSet evaluates the concatenated file set according to real path or raw path

Types

type FilePerm

type FilePerm int

FilePerm stores the permission apply to the file

type FileSet

type FileSet struct {
	Set        map[string]bool
	SystemRoot bool
}

FileSet stores the file permissions in the hierarchical set

func NewFileSet

func NewFileSet() FileSet

NewFileSet creates the new file set

func (*FileSet) Add

func (s *FileSet) Add(name string)

Add adds a single file path into the FileSet

func (*FileSet) AddRange

func (s *FileSet) AddRange(names []string, workPath string)

AddRange adds multiple files into the FileSet If path is relative path, add according to the workPath

func (*FileSet) IsInSetSmart

func (s *FileSet) IsInSetSmart(name string) bool

IsInSetSmart same from uoj-judger

type FileSets

type FileSets struct {
	Writable, Readable, Statable, SoftBan FileSet
}

FileSets aggregates multiple permissions including write / read / stat / soft ban

func NewFileSets

func NewFileSets() *FileSets

NewFileSets creates new FileSets struct

func (*FileSets) AddFilePermission

func (s *FileSets) AddFilePermission(name string, mode FilePerm)

AddFilePermission adds the file into fileSets according to the given permission

func (*FileSets) IsReadableFile

func (s *FileSets) IsReadableFile(name string) bool

IsReadableFile determines whether the file path inside the read / write set

func (*FileSets) IsSoftBanFile

func (s *FileSets) IsSoftBanFile(name string) bool

IsSoftBanFile determines whether the file path inside the softban set

func (*FileSets) IsStatableFile

func (s *FileSets) IsStatableFile(name string) bool

IsStatableFile determines whether the file path inside the stat / read / write set

func (*FileSets) IsWritableFile

func (s *FileSets) IsWritableFile(name string) bool

IsWritableFile determines whether the file path inside the write set

type Handler

type Handler struct {
	FileSet        *FileSets
	SyscallCounter SyscallCounter
}

Handler defines file access restricted handler to call the ptrace safe runner

func (*Handler) CheckRead

func (h *Handler) CheckRead(fn string) ptracer.TraceAction

CheckRead checks whether the file have read permission

func (*Handler) CheckStat

func (h *Handler) CheckStat(fn string) ptracer.TraceAction

CheckStat checks whether the file have stat permission

func (*Handler) CheckSyscall

func (h *Handler) CheckSyscall(syscallName string) ptracer.TraceAction

CheckSyscall checks syscalls other than allowed and traced against the SyscallCounter

func (*Handler) CheckWrite

func (h *Handler) CheckWrite(fn string) ptracer.TraceAction

CheckWrite checks whether the file have write permission

type SyscallCounter

type SyscallCounter map[string]int

SyscallCounter defines a count-down for each each syscall occurs

func NewSyscallCounter

func NewSyscallCounter() SyscallCounter

NewSyscallCounter creates a new SyscallCounter

func (SyscallCounter) Add

func (s SyscallCounter) Add(name string, count int)

Add adds single counter to SyscallCounter

func (SyscallCounter) AddRange

func (s SyscallCounter) AddRange(m map[string]int)

AddRange add multiple counter to SyscallCounter

func (SyscallCounter) Check

func (s SyscallCounter) Check(name string) (bool, bool)

Check return inside, allow

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL