2017-06-14 11:47:52 +02:00
|
|
|
# -*- encoding: utf8 -*-
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, http://www.qubes-os.org
|
|
|
|
#
|
|
|
|
# Copyright (C) 2017 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2017-06-14 11:47:52 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2017-06-14 11:47:52 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-10-12 00:11:50 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2017-06-14 11:47:52 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
|
2017-06-14 11:47:52 +02:00
|
|
|
|
|
|
|
import qubes.api
|
|
|
|
import qubes.ext
|
2017-07-17 02:42:36 +02:00
|
|
|
import qubes.vm.adminvm
|
2017-06-14 11:47:52 +02:00
|
|
|
|
|
|
|
class AdminExtension(qubes.ext.Extension):
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
@qubes.ext.handler(
|
2017-07-17 02:41:42 +02:00
|
|
|
'admin-permission:admin.vm.tag.Set',
|
|
|
|
'admin-permission:admin.vm.tag.Remove')
|
2017-06-14 11:47:52 +02:00
|
|
|
def on_tag_set_or_remove(self, vm, event, arg, **kwargs):
|
|
|
|
'''Forbid changing specific tags'''
|
|
|
|
# pylint: disable=no-self-use,unused-argument
|
2017-07-17 02:42:36 +02:00
|
|
|
if arg.startswith('created-by-') and \
|
|
|
|
not isinstance(vm, qubes.vm.adminvm.AdminVM):
|
2017-06-22 13:21:37 +02:00
|
|
|
raise qubes.api.PermissionDenied(
|
|
|
|
'changing this tag is prohibited by {}.{}'.format(
|
|
|
|
__name__, type(self).__name__))
|
2017-06-14 11:47:52 +02:00
|
|
|
|
2017-06-22 13:21:37 +02:00
|
|
|
# TODO create that tag here (need to figure out how to pass mgmtvm name)
|