add perm/tmp indication

Signed-off-by: Hadi <hadi@example.com>
This commit is contained in:
Hadi
2026-05-04 13:13:29 +02:00
parent 6e3beb44e1
commit 1661ec4f57
3 changed files with 30 additions and 5 deletions
+20
View File
@@ -20,6 +20,7 @@ func ListDevices() ([]Device, error) {
if err != nil {
return nil, wrapExecError(err)
}
rules := listRules()
var devices []Device
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line == "" {
@@ -27,12 +28,31 @@ func ListDevices() ([]Device, error) {
}
d, err := parseLine(line)
if err == nil {
d.Permanent = rules[d.VidPid] == d.Status
devices = append(devices, d)
}
}
return devices, nil
}
func listRules() map[string]Status {
out, err := exec.Command("usbguard", "list-rules").Output()
if err != nil {
return nil
}
rules := make(map[string]Status)
for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") {
if line == "" {
continue
}
d, err := parseLine(line)
if err == nil {
rules[d.VidPid] = d.Status
}
}
return rules
}
func AllowDevice(id int, permanent bool) error { return applyPolicy("allow-device", id, permanent) }
func BlockDevice(id int, permanent bool) error { return applyPolicy("block-device", id, permanent) }
func RejectDevice(id int, permanent bool) error { return applyPolicy("reject-device", id, permanent) }