2024-10-16 01:31:23 +09:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2024-10-20 19:50:13 +09:00
|
|
|
"git.ophivana.moe/security/fortify/internal/fmsg"
|
|
|
|
"git.ophivana.moe/security/fortify/xcb"
|
2024-10-16 01:31:23 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
// ChangeHosts appends an X11 ChangeHosts command Op.
|
2024-10-23 12:34:16 +09:00
|
|
|
func (sys *I) ChangeHosts(username string) *I {
|
2024-10-16 01:31:23 +09:00
|
|
|
sys.lock.Lock()
|
|
|
|
defer sys.lock.Unlock()
|
|
|
|
|
|
|
|
sys.ops = append(sys.ops, XHost(username))
|
2024-10-23 12:34:16 +09:00
|
|
|
|
|
|
|
return sys
|
2024-10-16 01:31:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
type XHost string
|
|
|
|
|
2024-10-16 14:38:57 +09:00
|
|
|
func (x XHost) Type() Enablement {
|
|
|
|
return EX11
|
2024-10-16 01:31:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
func (x XHost) apply(_ *I) error {
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.VPrintf("inserting entry %s to X11", x)
|
2024-10-16 01:31:23 +09:00
|
|
|
return fmsg.WrapErrorSuffix(xcb.ChangeHosts(xcb.HostModeInsert, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)),
|
|
|
|
fmt.Sprintf("cannot insert entry %s to X11:", x))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x XHost) revert(_ *I, ec *Criteria) error {
|
|
|
|
if ec.hasType(x) {
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.VPrintf("deleting entry %s from X11", x)
|
2024-10-16 01:31:23 +09:00
|
|
|
return fmsg.WrapErrorSuffix(xcb.ChangeHosts(xcb.HostModeDelete, xcb.FamilyServerInterpreted, "localuser\x00"+string(x)),
|
|
|
|
fmt.Sprintf("cannot delete entry %s from X11:", x))
|
|
|
|
} else {
|
2024-10-21 20:47:02 +09:00
|
|
|
fmsg.VPrintf("skipping entry %s in X11", x)
|
2024-10-16 01:31:23 +09:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x XHost) Is(o Op) bool {
|
|
|
|
x0, ok := o.(XHost)
|
|
|
|
return ok && x == x0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x XHost) Path() string {
|
|
|
|
return string(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (x XHost) String() string {
|
|
|
|
return string("SI:localuser:" + x)
|
|
|
|
}
|