Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: USB Support #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libioc/Config/Jail/BaseConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,19 @@ def _get_host_domainname(self) -> str:
except KeyError:
return "local"

def _get_usb_device(self) -> typing.List[str]:
devices = self.data["usb_device"].split() # type: typing.List[str]
return devices

def _set_usb_device(
self,
value: typing.Union[typing.List[str], str]
) -> None:
if isinstance(value, list):
self.data["usb_device"] = " ".join(value)
else:
self.data["usb_device"] = value

def get_string(self, key: str) -> str:
"""Get the stringified value of a configuration property."""
return self.stringify(self.__getitem__(key))
Expand Down
2 changes: 2 additions & 0 deletions libioc/Config/Jail/Globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
"allow_mount_fdescfs": 0,
"allow_mount_zfs": 0,
"allow_mount_tmpfs": 0,
"allow_usb": 0,
"usb_device": ["ugen*"],
"allow_quotas": 0,
"allow_socket_af": 0,
"allow_vmm": False,
Expand Down
8 changes: 7 additions & 1 deletion libioc/Jail.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ def devfs_ruleset(self) -> libioc.DevfsRules.DevfsRuleset:
if self._dhcp_enabled is True:
devfs_ruleset.append("add path 'bpf*' unhide")

if self._allow_mount_zfs == "1":
if self._allow_mount_zfs is True:
devfs_ruleset.append("add path zfs unhide")

if self.config["jail_zfs"] is True:
Expand All @@ -1643,6 +1643,12 @@ def devfs_ruleset(self) -> libioc.DevfsRules.DevfsRuleset:
devfs_ruleset.append("add path vmm/* unhide")
devfs_ruleset.append("add path nmdm* unhide")

if self.config["allow_usb"] is True:
devfs_ruleset.append("add path 'usb/*' unhide")
devfs_ruleset.append("add path 'usbctl' unhide")
for usb_device in self.config["usb_device"]:
devfs_ruleset.append(f"add path '{usb_device}' unhide")

# create if the final rule combination does not exist as ruleset
if devfs_ruleset not in self.host.devfs:
self.logger.verbose("New devfs ruleset combination")
Expand Down