gitee.com/mysnapcore/mysnapd@v0.1.0/interfaces/builtin/raw_input.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2021 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package builtin 21 22 import ( 23 "gitee.com/mysnapcore/mysnapd/interfaces" 24 "gitee.com/mysnapcore/mysnapd/interfaces/udev" 25 ) 26 27 const rawInputSummary = `allows access to raw input devices` 28 29 const rawInputBaseDeclarationSlots = ` 30 raw-input: 31 allow-installation: 32 slot-snap-type: 33 - core 34 deny-auto-connection: true 35 ` 36 37 const rawInputConnectedPlugSecComp = ` 38 # Description: Allow handling input devices. 39 # for udev 40 bind 41 socket AF_NETLINK - NETLINK_KOBJECT_UEVENT 42 ` 43 44 const rawInputConnectedPlugAppArmor = ` 45 # Description: Allow reading and writing to raw input devices 46 47 /dev/input/* rw, 48 49 # Allow reading for supported event reports for all input devices. See 50 # https://www.kernel.org/doc/Documentation/input/event-codes.txt 51 /sys/devices/**/input[0-9]*/capabilities/* r, 52 53 # For using udev 54 network netlink raw, 55 /run/udev/data/c13:[0-9]* r, 56 /run/udev/data/+input:input[0-9]* r, 57 ` 58 59 var rawInputConnectedPlugUDev = []string{ 60 `KERNEL=="event[0-9]*", SUBSYSTEM=="input"`, 61 `KERNEL=="mice"`, 62 `KERNEL=="mouse[0-9]*"`, 63 `KERNEL=="ts[0-9]*"`, 64 } 65 66 type rawInputInterface struct { 67 commonInterface 68 } 69 70 func (iface *rawInputInterface) UDevConnectedPlug(spec *udev.Specification, plug *interfaces.ConnectedPlug, slot *interfaces.ConnectedSlot) error { 71 spec.TriggerSubsystem("input") 72 return iface.commonInterface.UDevConnectedPlug(spec, plug, slot) 73 } 74 75 func init() { 76 registerIface(&rawInputInterface{commonInterface{ 77 name: "raw-input", 78 summary: rawInputSummary, 79 implicitOnCore: true, 80 implicitOnClassic: true, 81 baseDeclarationSlots: rawInputBaseDeclarationSlots, 82 connectedPlugSecComp: rawInputConnectedPlugSecComp, 83 connectedPlugAppArmor: rawInputConnectedPlugAppArmor, 84 connectedPlugUDev: rawInputConnectedPlugUDev, 85 }}) 86 }