Validate network related features values
Validate the syntax of net.fake-* features values. While improper values currently would lead "only" to lack of network connectivity for a VM, the scripts handling those may assume they are properly formatted already. Furthermore, this gives better error reporting to the user.
This commit is contained in:
parent
e1a2f8dcb2
commit
d95b42df16
@ -499,6 +499,30 @@ class NetVMMixin(qubes.events.Emitter):
|
|||||||
vm.fire_event(
|
vm.fire_event(
|
||||||
'property-reset:visible_gateway6', name='visible_gateway6')
|
'property-reset:visible_gateway6', name='visible_gateway6')
|
||||||
|
|
||||||
|
@qubes.events.handler('feature-pre-set:net.fake-ip')
|
||||||
|
def on_feature_pre_set_net_fake_ip(self, event, name, newvalue,
|
||||||
|
oldvalue=None):
|
||||||
|
# pylint: disable=unused-argument,no-self-use
|
||||||
|
# format validation
|
||||||
|
ipaddress.IPv4Address(newvalue)
|
||||||
|
|
||||||
|
@qubes.events.handler('feature-pre-set:net.fake-gateway')
|
||||||
|
def on_feature_pre_set_net_fake_gw(self, event, name, newvalue,
|
||||||
|
oldvalue=None):
|
||||||
|
# pylint: disable=unused-argument,no-self-use
|
||||||
|
# format validation
|
||||||
|
ipaddress.IPv4Address(newvalue)
|
||||||
|
|
||||||
|
@qubes.events.handler('feature-pre-set:net.fake-netmask')
|
||||||
|
def on_feature_pre_set_net_fake_nm(self, event, name, newvalue,
|
||||||
|
oldvalue=None):
|
||||||
|
# pylint: disable=unused-argument,no-self-use
|
||||||
|
# format validation
|
||||||
|
if not newvalue.isdigit():
|
||||||
|
ipaddress.IPv4Address(newvalue)
|
||||||
|
elif not 0 <= int(newvalue) <= 24:
|
||||||
|
raise qubes.exc.QubesValueError('Invalid netmask value')
|
||||||
|
|
||||||
@qubes.events.handler('feature-set:net.fake-ip')
|
@qubes.events.handler('feature-set:net.fake-ip')
|
||||||
def on_feature_set_net_fake_ip(self, event, name, newvalue, oldvalue=None):
|
def on_feature_set_net_fake_ip(self, event, name, newvalue, oldvalue=None):
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
Loading…
Reference in New Issue
Block a user